From e85c16aba6459b83c78bb560243074d9ecd89fa7 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 9 Jul 2018 11:58:30 -0400 Subject: [PATCH] Cleanups, add video viewing --- .../classic/includes/export_functions.php | 641 +++++++++--------- 1 file changed, 335 insertions(+), 306 deletions(-) diff --git a/web/skins/classic/includes/export_functions.php b/web/skins/classic/includes/export_functions.php index 7750f165b..a5cc8f9dd 100644 --- a/web/skins/classic/includes/export_functions.php +++ b/web/skins/classic/includes/export_functions.php @@ -18,21 +18,19 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -function exportHeader( $title ) -{ +function exportHeader($title) { ?> - - - - <?php echo $title ?> - - - + + - + }); + // ]]> + + Id() ); +function exportEventDetail($event, $exportFrames, $exportImages) { + ob_start(); + exportHeader(translate('Event').' '.$event->Id()); $otherlinks = ''; if( $exportFrames ) $otherlinks .= ''.translate('Frames').','; if( $exportImages ) $otherlinks .= ''.translate('Images').','; $otherlinks = substr($otherlinks,0,-1); - - ?>
@@ -139,22 +133,20 @@ function exportEventDetail( $event, $exportFrames, $exportImages ) Id() ) ); +function exportEventFrames($event, $exportDetail, $exportImages) { + $sql = 'SELECT *, unix_timestamp( TimeStamp ) AS UnixTimeStamp FROM Frames WHERE EventID = ? ORDER BY FrameId'; + $frames = dbFetchAll($sql, NULL, array($event->Id())); - ob_start(); - exportHeader( translate('Frames')." ".$event->Id() ); + ob_start(); + exportHeader(translate('Frames').' '.$event->Id()); $otherlinks = ''; if( $exportDetail ) $otherlinks .= ''.translate('Event').','; if( $exportImages ) $otherlinks .= ''.translate('Images').','; $otherlinks = substr($otherlinks,0,-1); - ?>
@@ -168,56 +160,49 @@ function exportEventFrames( $event, $exportDetail, $exportImages ) Path(); - foreach ( $frames as $frame ) - { - $imageFile = sprintf( "%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $frame['FrameId'] ); - $imagePath = $eventPath."/".$imageFile; - $analImage = preg_replace( "/capture/", "analyse", $imagePath ); - if ( file_exists( $analImage ) ) - { - $imageFile = preg_replace( "/capture/", "analyse", $imageFile ); - } + if ( count($frames) ) { + $eventPath = $event->Path(); + foreach ( $frames as $frame ) { + $imageFile = sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d-capture.jpg', $frame['FrameId']); + $imagePath = $eventPath.'/'.$imageFile; + $analImage = preg_replace('/capture/', 'analyse', $imagePath); + if ( file_exists($analImage) ) { + $imageFile = preg_replace('/capture/', 'analyse', $imageFile); + } - $class = strtolower($frame['Type']); + $class = strtolower($frame['Type']); ?> - - + + - Frame <?php echo $frame['FrameId'] ?> + Frame <?php echo $frame['FrameId'] ?>
@@ -225,13 +210,12 @@ function exportEventFrames( $event, $exportDetail, $exportImages ) Id() ); +function exportEventImages($event, $exportDetail, $exportFrames, $myfilelist) { + ob_start(); + exportHeader(translate('Images').' '.$event->Id()); $otherlinks = ''; if( $exportDetail ) $otherlinks .= ''.translate('Event').','; @@ -257,28 +241,53 @@ function exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist )

: Name()) ?> ()

+DefaultVideo() ) { + // videojs zoomrotate only when direct recording + $Zoom = 1; + $Rotation = 0; + if ( $Monitor->VideoWriter() == '2' ) { + # Passthrough + $Rotation = $Event->Orientation(); + if ( in_array($Event->Orientation(),array('90','270')) ) + $Zoom = $Event->Height()/$Event->Width(); + } +?> +
+ +
+ - +

- + + + + + +
 
 
-
-
+ onmousedown="slide(event,'horizontal', Width()-20)?>, 1, , ,0, 'imageslider_display_id');"> 
+ + +
- - - +

Master

- - + +
-
-

All

- $eids
"; - } - ?> - -
- + + + -
+
+

All

+SaveJPEGs() ) { +?> +
+
- "; - echo "

Monitor: " . $monitorNames[$monitor] . "

"; - foreach ($eids as $eid) { - if ($eventMonitorId[$eid] == $monitor) { - ?> -
- "; + echo '

Monitor: ' . $monitorNames[$monitor] . '

'; + foreach ( $eids as $eid ) { + if ( $eventMonitorId[$eid] == $monitor ) { +?> +
+'; } - ?> - -
- - - -
+ echo ''; + } # end foreach monitor +?> +
+ +
- - + + Path(); + $eventPath = $event->Path(); + $eventRelativePath = $event->Relative_Path(); $files = array(); if ( $dir = opendir($eventPath) ) { while ( ($file = readdir($dir)) !== false ) { @@ -754,29 +756,29 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp if ( $exportDetail ) { $file = 'zmEventDetail.html'; - if ( !($fp = fopen( $eventPath.'/'.$file, 'w' )) ) { - Fatal( "Can't open event detail export file '$file'" ); + if ( !($fp = fopen($eventPath.'/'.$file, 'w')) ) { + Fatal("Can't open event detail export file '$file'"); } - fwrite( $fp, exportEventDetail( $event, $exportFrames, $exportImages ) ); - fclose( $fp ); - $exportFileList[$file] = $eventPath."/".$file; + fwrite($fp, exportEventDetail($event, $exportFrames, $exportImages)); + fclose($fp); + $exportFileList[$file] = $event->Id().'/'.$file; } if ( $exportFrames ) { $file = 'zmEventFrames.html'; - if ( !($fp = fopen( $eventPath.'/'.$file, 'w' )) ) { - Fatal( "Can't open event frames export file '$file'" ); + if ( !($fp = fopen($eventPath.'/'.$file, 'w')) ) { + Fatal("Can't open event frames export file '$file'"); } - fwrite( $fp, exportEventFrames( $event, $exportDetail, $exportImages ) ); - fclose( $fp ); - $exportFileList[$file] = $eventPath."/".$file; + fwrite($fp, exportEventFrames($event, $exportDetail, $exportImages)); + fclose($fp); + $exportFileList[$file] = $event->Id().'/'.$file; } + if ( $exportImages ) { $filesLeft = array(); $myfilelist = array(); foreach ( $files as $file ) { - if ( preg_match( '/-(?:capture|analyse).jpg$/', $file ) ) { - $exportFileList[$file] = $eventPath."/".$file; - $myfilelist[$file] = $eventPath."/".$file; + if ( preg_match('/-(?:capture|analyse).jpg$/', $file ) ) { + $myfilelist[$file] = $exportFileList[$file] = $event->Id().'/'.$file; } else { $filesLeft[$file] = $file; } @@ -786,113 +788,140 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp // create an image slider if ( !empty($myfilelist) ) { $file = 'zmEventImages.html'; - if ( !($fp = fopen($eventPath.'/'.$file, 'w')) ) Fatal( "Can't open event images export file '$file'" ); - fwrite( $fp, exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist ) ); - fclose( $fp ); - $exportFileList[$file] = $eventPath."/".$file; + if ( !($fp = fopen($event->Id().'/'.$file, 'w')) ) + Fatal("Can't open event images export file '$file'"); + fwrite($fp, exportEventImages($event, $exportDetail, $exportFrames, $myfilelist)); + fclose($fp); + $exportFileList[$file] = $event->Id().'/'.$file; } } # end if exportImages if ( $exportVideo ) { $filesLeft = array(); foreach ( $files as $file ) { - if ( preg_match( '/\.(?:mpg|mpeg|mov|swf|mp4|mkv|avi|asf|3gp)$/', $file ) ) { - $exportFileList[$file] = $eventPath.'/'.$file; + if ( preg_match('/\.(?:mpg|mpeg|mov|swf|mp4|mkv|avi|asf|3gp)$/', $file) ) { + $exportFileList[$file] = $event->Id().'/'.$file; } else { $filesLeft[$file] = $file; } } $files = $filesLeft; - } # end if exportVideo + } # end if exportVideo if ( $exportMisc ) { foreach ( $files as $file ) { - $exportFileList[$file] = $eventPath.'/'.$file; + $exportFileList[$file] = $event->Id().'/'.$file; } $files = array(); } return array_values($exportFileList); -} +} # end exportFileList() -function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc, $exportFormat, $exportStructure = false ) { +function exportEvents( + $eids, + $connkey, + $exportDetail, + $exportFrames, + $exportImages, + $exportVideo, + $exportMisc, + $exportFormat, + $exportStructure = false +) { - if ( (!canView('Events')) || empty($eids) ) { + if ( !canView('Events') ) { + Error("You do not have permission to view events."); + return false; + } else if ( empty($eids) ) { + Error("Attempt to export an empty list of events."); return false; } - $export_root = 'zmExport'; - $export_listFile = 'zmFileList.txt'; - $exportFileList = array(); - $html_eventMaster = ''; - - if ( is_array($eids) ) { - foreach ( $eids as $eid ) { - $exportFileList = array_merge( $exportFileList, exportFileList( $eid , $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc ) ); - } - } else { - $eid = $eids; - $exportFileList = exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc ); - } - - // create an master image slider - if ( $exportImages ) { - if ( !is_array($eids) ) { - $eids = array($eids); - } - $monitorPath = ZM_DIR_EVENTS.'/'; - $html_eventMaster = 'zmEventImagesMaster_'.date('Ymd_His'). '.html'; - if ( !($fp = fopen( $monitorPath.'/'.$html_eventMaster, 'w' )) ) Fatal( "Can't open event images export file '$html_eventMaster'" ); - fwrite($fp, exportEventImagesMaster($eids)); - fclose($fp); - $exportFileList[] = $monitorPath.'/'.$html_eventMaster; - } + # Ensure that we are going to be able to do this. if ( ! file_exists(ZM_DIR_EXPORTS) ) { if ( ! mkdir(ZM_DIR_EXPORTS) ) { Fatal("Can't create exports dir at '".ZM_DIR_EXPORTS."'"); } } - $listFile = ZM_DIR_EXPORTS.'/'.$export_listFile; + $export_dir = ZM_DIR_EXPORTS.'/zmExport'.$connkey; + + # Ensure that we are going to be able to do this. + if ( ! file_exists($export_dir) ) { + if ( ! mkdir($export_dir) ) { + Fatal("Can't create exports dir at '$export_dir'"); + } else { + Logger::Debug("Successfully created '$export_dir'"); + } + } + + $export_root = 'zmExport'; + $export_listFile = 'zmFileList.txt'; + $exportFileList = array(); + $html_eventMaster = ''; + + if ( !is_array($eids) ) { + $eids = array($eids); + } + foreach ( $eids as $eid ) { + $event = new Event($eid); + $exportFileList = array_merge($exportFileList, exportFileList($event, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc)); + exec("cp -as ".$event->Path()." $export_dir/"); + } + if ( !symlink(ZM_PATH_WEB.'/'.ZM_SKIN_PATH.'/js/jquery.js', $export_dir.'/jquery.js') ) + Error("Failed linking jquery.js"); + if ( !symlink(ZM_PATH_WEB.'/'.ZM_SKIN_PATH.'/js/video.js', $export_dir.'/video.js') ) + Error("Failed linking video.js"); + + // create an master image + if ( $exportImages ) { + $html_eventMaster_file = 'zmEventImagesMaster_'.date('Ymd_His'). '.html'; + $html_eventMaster_path = $export_dir.'/'.$html_eventMaster_file; + + if ( !($fp = fopen($html_eventMaster_path, 'w')) ) + Fatal("Can't open event images export file '$html_eventMaster_path'"); + fwrite($fp, exportEventImagesMaster($eids)); + fclose($fp); + $exportFileList[] = $html_eventMaster_file; + } + + $listFile = $export_dir.'/'.$export_listFile; if ( !($fp = fopen($listFile, 'w')) ) { - Fatal( "Can't open event export list file '$listFile'" ); + Fatal("Can't open event export list file '$listFile'"); } foreach ( $exportFileList as $exportFile ) { - fwrite( $fp, "$exportFile\n" ); + $exportFile = 'zmExport'.$connkey.'/'.$exportFile; + fwrite($fp, "$exportFile\n"); } - fclose( $fp ); + fwrite($fp, "$listFile\n"); + fclose($fp); + $archive = ''; if ( $exportFormat == 'tar' ) { - $archive = ZM_DIR_EXPORTS.'/'.$export_root.'.tar.gz'; - @unlink( $archive ); - if ( $exportStructure == 'flat' ) { //strip file paths if we choose - $command = "nice -10 tar --create --gzip --file=".escapeshellarg($archive)." --files-from=".escapeshellarg($listFile)." --xform='s#^.+/##x'"; - } else { - $command = "nice -10 tar --create --gzip --file=".escapeshellarg($archive)." --files-from=".escapeshellarg($listFile); - } - exec( $command, $output, $status ); - if ( $status ) { - Error( "Command '$command' returned with status $status" ); - if ( $output[0] ) - Error( "First line of output is '".$output[0]."'" ); - return( false ); + $archive = ZM_DIR_EXPORTS.'/'.$export_root.'_'.$connkey.'.tar.gz'; + @unlink($archive); + chdir(ZM_DIR_EXPORTS); + $command = 'nice -10 tar --create --gzip --dereference --file='.escapeshellarg($archive).' zmExport' . $connkey; + #$command = 'nice -10 tar --create --gzip --file='.escapeshellarg($archive).' --files-from='.escapeshellarg($listFile); + if ( $exportStructure == 'flat' ) { + //strip file paths if we + $command .= " --xform='s#^.+/##x'"; } } elseif ( $exportFormat == 'zip' ) { - $archive = ZM_DIR_EXPORTS.'/'.$export_root.'.zip'; - @unlink( $archive ); - if ($exportStructure == 'flat') { - $command = "cat ".escapeshellarg($listFile)." | nice -10 zip -q -j ".escapeshellarg($archive)." -@"; + $archive = $export_dir.'/'.$export_root.'.zip'; + @unlink($archive); + if ( $exportStructure == 'flat' ) { + $command = 'cat '.escapeshellarg($listFile).' | nice -10 zip -q -j '.escapeshellarg($archive).' -@'; } else { - $command = "cat ".escapeshellarg($listFile)." | nice -10 zip -q ".escapeshellarg($archive)." -@"; + $command = 'cat '.escapeshellarg($listFile).' | nice -10 zip -q '.escapeshellarg($archive).' -@'; } - //cat zmFileList.txt | zip -q zm_export.zip -@ - //-bash: zip: command not found + } // if $exportFormat - exec( $command, $output, $status ); - if ( $status ) { - Error("Command '$command' returned with status $status"); - if ( $output[0] ) - Error("First line of output is '".$output[0]."'"); - return false; - } + exec($command, $output, $status); + if ( $status ) { + Error("Command '$command' returned with status $status"); + if ( $output[0] ) + Error("First line of output is '".$output[0]."'"); + return false; } //clean up temporary files @@ -900,5 +929,5 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo unlink($monitorPath.'/'.$html_eventMaster); } - return '?view=archive%26type='.$exportFormat; + return '?view=archive%26type='.$exportFormat.'%26connkey='.$connkey; }