Cleanups, add video viewing

This commit is contained in:
Isaac Connor 2018-07-09 11:58:30 -04:00
parent 639f916156
commit e85c16aba6
1 changed files with 335 additions and 306 deletions

View File

@ -18,18 +18,16 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
function exportHeader( $title )
{
function exportHeader($title) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $title ?></title>
<style type="text/css">
<!--
<?php include(ZM_SKIN_PATH.'/css/'.ZM_SKIN_NAME.'/export.css'); ?>
ul.tabs {
margin: 0;
margin-bottom: -1px;
@ -71,10 +69,9 @@ html ul.tabs li.active, html ul.tabs li.active a:hover {
}
-->
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="video.js"></script>
<script type="text/javascript">
<?php include(ZM_SKIN_PATH.'/js/jquery.js') ?>
</script>
<script type="text/javascript" language="javascript" charset="utf-8">
/*==========[tab code]==========*/
$(document).ready(function() {
@ -103,17 +100,14 @@ html ul.tabs li.active, html ul.tabs li.active a:hover {
<?php
}
function exportEventDetail( $event, $exportFrames, $exportImages )
{
function exportEventDetail($event, $exportFrames, $exportImages) {
ob_start();
exportHeader( translate('Event')." ".$event->Id() );
exportHeader(translate('Event').' '.$event->Id());
$otherlinks = '';
if( $exportFrames ) $otherlinks .= '<a href="zmEventFrames.html">'.translate('Frames').'</a>,';
if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.translate('Images').'</a>,';
$otherlinks = substr($otherlinks,0,-1);
?>
<body>
<div id="page">
@ -139,22 +133,20 @@ function exportEventDetail( $event, $exportFrames, $exportImages )
</body>
</html>
<?php
return( ob_get_clean() );
return ob_get_clean();
}
function exportEventFrames( $event, $exportDetail, $exportImages )
{
$sql = "SELECT *, unix_timestamp( TimeStamp ) AS UnixTimeStamp FROM Frames WHERE EventID = ? ORDER BY FrameId";
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() );
exportHeader(translate('Frames').' '.$event->Id());
$otherlinks = '';
if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.translate('Event').'</a>,';
if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.translate('Images').'</a>,';
$otherlinks = substr($otherlinks,0,-1);
?>
<body>
<div id="page">
@ -168,8 +160,7 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
<th><?php echo translate('TimeDelta') ?></th>
<th><?php echo translate('Score') ?></th>
<?php
if ( $exportImages )
{
if ( $exportImages ) {
?>
<th><?php echo translate('Image') ?></th>
<?php
@ -177,17 +168,14 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
?>
</tr>
<?php
if ( count($frames) )
{
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 );
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']);
@ -199,25 +187,22 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
<td><?php echo number_format($frame['Delta'], 2) ?></td>
<td><?php echo $frame['Score'] ?></td>
<?php
if ( $exportImages )
{
if ( $exportImages ) {
?>
<td><a href="<?php echo $imageFile ?>" target="zmExportImage"><img src="<?php echo $imageFile ?>" border="0" class="thumb" alt="Frame <?php echo $frame['FrameId'] ?>"/></a></td>
<td><a href="<?php echo $imageFile ?>" target="zmExportImage"><img src="<?php echo $imageFile ?>" class="thumb" alt="Frame <?php echo $frame['FrameId'] ?>"/></a></td>
<?php
}
?>
</tr>
<?php
}
}
else
{
} # end foreach frame
} else {
?>
<tr>
<td class="monoRow" colspan="<?php echo $exportImages?6:5 ?>"><?php echo translate('NoFramesRecorded') ?></td>
</tr>
<?php
}
} # end if count($frames)
?>
</table>
</div>
@ -225,13 +210,12 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
</body>
</html>
<?php
return( ob_get_clean() );
return ob_get_clean();
}
function exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist )
{
function exportEventImages($event, $exportDetail, $exportFrames, $myfilelist) {
ob_start();
exportHeader( translate('Images')." ".$event->Id() );
exportHeader(translate('Images').' '.$event->Id());
$otherlinks = '';
if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.translate('Event').'</a>,';
@ -257,28 +241,53 @@ function exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist )
<h2><?php echo translate('Images') ?>: <?php echo validHtmlStr($event->Name()) ?><?php if(!empty($otherlinks)) { ?> (<?php echo$otherlinks?>) <?php } ?></h2>
<?php
if ( $event->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();
}
?>
<div id="videoFeed">
<video id="videoobj" class="video-js vjs-default-skin" style="transform: matrix(1, 0, 0, 1, 0, 0)"
width="<?php echo $event->Width() ?>"
height="<?php echo $event->Height() ?>"
data-setup='{ "controls": true, "autoplay": true, "preload": "auto", "plugins": { "zoomrotate": { "zoom": "<?php echo $Zoom ?>"}}}'>
<source src="<?php echo $Event->getStreamSrc(array('mode'=>'mpeg','format'=>'h264')); ?>" type="video/mp4">
<track id="monitorCaption" kind="captions" label="English" srclang="en" src='data:plain/text;charset=utf-8,"WEBVTT\n\n 00:00:00.000 --> 00:00:01.000 ZoneMinder"' default>
Your browser does not support the video tag.
</video>
</div><!--videoFeed-->
<?php
} else { // end if DefaultVideo
?>
<ilayer id="slidensmain" width=&{slidewidth}; height=&{slideheight}; bgColor=&{slidebgcolor}; visibility=hide>
<layer id="slidenssub" width=&{slidewidth}; left=auto top=auto></layer>
</ilayer>
<div id="imagevideo" align="center"></div>
<br>
<div align="center">
<button onclick="stepbackward()">< Step</button><button
id="btnrwd" onclick="rewind()" >Rwd</button><button
id="btnplay" onclick="playstop()">Stop</button><button
onclick="stepforward()">Step ></button><button
id="btnspeedup" onclick="speedup()">speedup</button><button
id="btnspeeddown" onclick="speeddown()">slowdown</button>
<button onclick="stepbackward()">&lt; Step</button>
<button id="btnrwd" onclick="rewind()" >Rwd</button>
<button id="btnplay" onclick="playstop()">Stop</button>
<button onclick="stepforward()">Step &gt;</button>
<button id="btnspeedup" onclick="speedup()">speedup</button>
<button id="btnspeeddown" onclick="speeddown()">slowdown</button>
</div>
<div align="center"><div class="horizontal_track" >
<div class="horizontal_slit" >&nbsp;</div>
<div class="horizontal_slider" id="imageslider_id" style="left: 0px;"
onmousedown="slide(event,'horizontal', <?php echo($event->Width()-20)?>, 1, <?php echo$listcount?>, <?php echo$listcount?>,0, 'imageslider_display_id');">&nbsp;</div>
</div></div>
</div>
</div>
<div align="center"><div class="display_holder"><input id="imageslider_display_id" class="value_display" type="text" value="0" onfocus="blur(this);"/></div></div>
<script language="JavaScript1.2">
<script type="text/javascript">
/***********************************************
* Flexi Slideshow- © Dynamic Drive (www.dynamicdrive.com)
@ -292,9 +301,9 @@ var variableslide=[<?php echo$slides?>];
//configure the below 3 variables to set the dimension/background color of the slideshow
var slidewidth=eventWidth+'px' //set to width of LARGEST image in your slideshow
var slideheight=eventHeight+'px' //set to height of LARGEST iamge in your slideshow, plus any text description
var slidebgcolor='#ffffff'
var slidewidth=eventWidth+'px'; //set to width of LARGEST image in your slideshow
var slideheight=eventHeight+'px'; //set to height of LARGEST iamge in your slideshow, plus any text description
var slidebgcolor='#ffffff';
//configure the below variable to determine the delay between image rotations (in miliseconds)
var origslidedelay=100;
@ -306,11 +315,11 @@ var ie=document.all;
var dom=document.getElementById;
for (i=0;i<variableslide.length;i++){
var cacheimage=new Image()
cacheimage.src=variableslide[i]
var cacheimage = new Image();
cacheimage.src = variableslide[i];
}
var currentslide=-1
var currentslide = -1;
var mytimer = null;
//if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+'px;height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>');
@ -337,14 +346,12 @@ function changeimage() {
slideManual(currentslide+1,eventWidth-20, 1, variableslide.length);
}
function start_slider(){
crossrotateobj = dom ? document.getElementById("slidedom") : ie ? document.all.slidedom : document.slidensmain.document.slidenssub;
if (document.layers) document.slidensmain.visibility="show";
rotateimages();
}
// seyi_code
function rotateimagesrewind(){
if (currentslide==0) currentslide=variableslide.length-1;
@ -372,6 +379,7 @@ function stepforward() {
changeimage();
}
function stepbackward() {
clearTimeout(mytimer);
// document.getElementById('btnrwd').style.borderTop='2px solid #ffffff';
@ -387,7 +395,6 @@ function stepbackward() {
else currentslide--;
changeimage();
}
function speedup() { slidedelay = slidedelay/2; }
function speeddown() { slidedelay = slidedelay*2; }
@ -430,7 +437,6 @@ function rewind() {
document.getElementById('btnspeedup').disabled = true;
document.getElementById('btnspeeddown').disabled = true;
}
}
//---------------------------------+
@ -501,54 +507,52 @@ function moveSlider(evnt) {
// seyi_code
currentslide = v-1;
changeimage();
return false
return false;
}
return
}
// moveSlider: Handles the start of a slider move.
function slide(evnt, orientation, length, from, to, count, decimals, display) {
if (!evnt) evnt = window.event;
sliderObj = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element.
sliderObj.pxLen = length // The allowed slider movement in pixels.
sliderObj.valCount = count ? count - 1 : length // Allowed number of values in the interval.
displayObj = carpeGetElementById(display) // Get the associated display element.\
displayObj.dec = decimals // Number of decimals to be displayed.
sliderObj.scale = (to - from) / length // Slider-display scale [value-change per pixel of movement].
sliderObj.pxLen = length; // The allowed slider movement in pixels.
sliderObj.valCount = count ? count - 1 : length; // Allowed number of values in the interval.
displayObj = carpeGetElementById(display); // Get the associated display element.\
displayObj.dec = decimals; // Number of decimals to be displayed.
sliderObj.scale = (to - from) / length; // Slider-display scale [value-change per pixel of movement].
if (orientation == 'horizontal') { // Set limits for horizontal sliders.
sliderObj.fromVal = from
xMax = length
yMax = 0
sliderObj.fromVal = from;
xMax = length;
yMax = 0;
} else if (orientation == 'vertical') { // Set limits and scale for vertical sliders.
sliderObj.fromVal = to;
xMax = 0;
yMax = length;
sliderObj.scale = -sliderObj.scale; // Invert scale for vertical sliders. "Higher is more."
}
if (orientation == 'vertical') { // Set limits and scale for vertical sliders.
sliderObj.fromVal = to
xMax = 0
yMax = length
sliderObj.scale = -sliderObj.scale // Invert scale for vertical sliders. "Higher is more."
}
pxLeft = carpeLeft(sliderObj.id) // Sliders horizontal position at start of slide.
pxTop = carpeTop(sliderObj.id) // Sliders vertical position at start of slide.
xCoord = evnt.screenX // Horizontal mouse position at start of slide.
yCoord = evnt.screenY // Vertical mouse position at start of slide.
mouseover = true
document.onmousemove = moveSlider // Start the action if the mouse is dragged.
document.onmouseup = sliderMouseUp // Stop sliding.
pxLeft = carpeLeft(sliderObj.id); // Sliders horizontal position at start of slide.
pxTop = carpeTop(sliderObj.id); // Sliders vertical position at start of slide.
xCoord = evnt.screenX; // Horizontal mouse position at start of slide.
yCoord = evnt.screenY; // Vertical mouse position at start of slide.
mouseover = true;
document.onmousemove = moveSlider; // Start the action if the mouse is dragged.
document.onmouseup = sliderMouseUp; // Stop sliding.
}
// sliderMouseup: Handles the mouseup event after moving a slider.
// Snaps the slider position to allowed/displayed value.
function sliderMouseUp() {
mouseover = false // Stop the sliding.
v = (displayObj.value) ? displayObj.value : 0 // Find last display value.
pos = (v - sliderObj.fromVal)/(sliderObj.scale) // Calculate slider position (regardless of orientation).
if (yMax == 0) carpeLeft(sliderObj.id, pos) // Snap horizontal slider to corresponding display position.
if (xMax == 0) carpeTop(sliderObj.id, pos) // Snap vertical slider to corresponding display position.
mouseover = false; // Stop the sliding.
v = (displayObj.value) ? displayObj.value : 0; // Find last display value.
pos = (v - sliderObj.fromVal)/(sliderObj.scale); // Calculate slider position (regardless of orientation).
if (yMax == 0) carpeLeft(sliderObj.id, pos); // Snap horizontal slider to corresponding display position.
if (xMax == 0) carpeTop(sliderObj.id, pos); // Snap vertical slider to corresponding display position.
if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
document.removeEventListener('mousemove', moveSlider)
document.removeEventListener('mouseup', sliderMouseUp)
document.removeEventListener('mousemove', moveSlider);
document.removeEventListener('mouseup', sliderMouseUp);
}
else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
document.detachEvent('onmousemove', moveSlider)
document.detachEvent('onmouseup', sliderMouseUp)
document.detachEvent('onmousemove', moveSlider);
document.detachEvent('onmouseup', sliderMouseUp);
}
}
@ -556,10 +560,10 @@ function sliderMouseUp() {
//slide(event,'horizontal', 300, 1, 22, 22,0, 'imageslider_display_id');
//slide(evnt, orientation, length, from, to, count, decimals, display) {
function slideManual(val,length,from,to) {
scale = (to - from) / length // Slider-display scale [value-change per pixel of movement].
fromVal = from
xMax = length
yMax = 0
scale = (to - from) / length; // Slider-display scale [value-change per pixel of movement].
fromVal = from;
xMax = length;
yMax = 0;
sliderid = 'imageslider_id';
@ -574,11 +578,13 @@ if (ie||dom) start_slider();
else if (document.layers) window.onload=start_slider;
</script>
<?php
} # end if defaultvideo
?>
</body>
</html>
<?php
return( ob_get_clean() );
return ob_get_clean();
}
function exportEventImagesMaster($eids) {
@ -588,7 +594,7 @@ function exportEventImagesMaster( $eids ) {
<body>
<h2><?php echo translate('Images') ?> Master</h2>
<?php
// TODO: SHould use find to make this 1 db query
// TODO: Should use find to make this 1 db query
foreach ($eids as $eid) {
//get monitor id and event id
$event = new Event( $eid );
@ -601,69 +607,65 @@ function exportEventImagesMaster( $eids ) {
//*
if(!empty($monitors)) {
$tmp = dbFetchAll("SELECT Id,Name FROM Monitors WHERE Id IN (".implode(',', $monitors).") ");
$tmp = dbFetchAll('SELECT Id,Name FROM Monitors WHERE Id IN ('.implode(',', $monitors).') ');
foreach ( $tmp as $row ) { $monitorNames[$row['Id']] = $row['Name']; }
}
//*/
//trigger_error(print_r($monitorNames,1));
?>
<div id="tabs">
<ul class="tabs">
<li class="active"><a href="#all"> All </a></li>
<?php
foreach ($monitors as $monitor) {
# code...
echo "<li><a href='#tab$monitor'>" . $monitorNames[$monitor] . '</a></li>';
echo "<li><a href=\"#tab$monitor\">" . $monitorNames[$monitor] . '</a></li>';
}
?>
</ul>
</div>
<table width="100%" height="100%" ><tr>
<table width="100%" height="100%">
<tr>
<td valign="top" bgcolor="#dddddd" style="padding:10px;">
<div class='tab_content' id='all'>
<div class="tab_content" id="all">
<h2> All </h2>
<?php
if (!is_array($eids)) {
echo "<div><a href=\"javascript:switchevent('$eids/zm/EventImages.html');\"> $eids </div>";
}
foreach($eids as $eid) {
$Event = new Event($eid);
if ( $Event->SaveJPEGs() ) {
?>
<?php foreach($eids as $eid) {
?>
<div><a href="javascript:switchevent('<?php echo $eventPath[$eid]; ?>/zmEventImages.html');"><?php echo$eid?></a></div>
<div><a href="#" onclick="switchevent('<?php echo $eid; ?>/zmEventImages.html');return false;"><?php echo $eid; ?></a></div>
<?php
}
} # end if saveJPEGs
} # end foreach event id
?>
</div>
<?php
foreach ($monitors as $monitor) {
echo "<div class='tab_content' id='tab$monitor'>";
echo "<h2>Monitor: " . $monitorNames[$monitor] . " </h2>";
echo "<div class=\"tab_content\" id=\"tab$monitor\">";
echo '<h2>Monitor: ' . $monitorNames[$monitor] . ' </h2>';
foreach ( $eids as $eid ) {
if ( $eventMonitorId[$eid] == $monitor ) {
?>
<div><a href="javascript:switchevent('<?php echo $eventPath[$eid]; ?>/zmEventImages.html');"><?php echo$eid?></a></div>
<div><a href="#" onclick="switchevent('<?php echo $eid; ?>/zmEventImages.html');return false;"><?php echo $eid; ?></a></div>
<?php
}
}
echo '</div>';
}
} # end foreach monitor
?>
</td><td>
<iframe id="myframe" onload="resizeCaller();" name="myframe" src="#"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0"
vspace="0" hspace="0" style="overflow:visible; width:100%; display:none">
</iframe>
</td>
</tr></table>
</tr>
</table>
<script type="text/javascript">
function switchevent(src) {
if(document.all) document.all.myframe.src = src;
else window.frames['myframe'].location.href = src;
$('#myframe').attr('src',src);
$('#myframe').show();
}
/***********************************************
@ -674,45 +676,47 @@ function switchevent(src) {
//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]
var iframeids=["myframe"];
//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"
var iframehide="yes";
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers
function resizeCaller() {
var dyniframe=new Array()
var dyniframe=new Array();
for (i=0; i<iframeids.length; i++){
if (document.getElementById) resizeIframe(iframeids[i]);
//reveal iframe for lower end browsers? (see var above):
if ( (document.all || document.getElementById) && iframehide=="no" ) {
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]);
tempobj.style.display="block";
}
}
}
function resizeIframe(frameid) {
var currentfr=document.getElementById(frameid)
var currentfr = document.getElementById(frameid);
if ( currentfr && !window.opera ) {
currentfr.style.display="block"
currentfr.style.display = "block";
if ( currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight ) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if ( currentfr.Document && currentfr.Document.body.scrollHeight ) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener) currentfr.addEventListener("load", readjustIframe, false);
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
if ( currentfr.addEventListener ) {
currentfr.addEventListener("load", readjustIframe, false);
} else if ( currentfr.attachEvent ) {
currentfr.detachEvent("onload", readjustIframe); // Bug fix line
currentfr.attachEvent("onload", readjustIframe);
}
}
}
function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt;
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
var crossevt = window.event ? event : loadevt;
var iframeroot = crossevt.currentTarget ? crossevt.currentTarget : crossevt.srcElement;
if (iframeroot) resizeIframe(iframeroot.id);
}
@ -723,23 +727,21 @@ function loadintoIframe(iframeid, url){
//if (window.addEventListener) window.addEventListener("load", resizeCaller, false)
//else if (window.attachEvent) window.attachEvent("onload", resizeCaller)
//else window.onload=resizeCaller
</script>
</body>
</html>
<?php
return( ob_get_clean() );
return ob_get_clean();
}
function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc ) {
function exportFileList($event, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc) {
if ( (!canView('Events')) or ! $eid ) {
if ( !canView('Events') or !$event ) {
return;
}
$event = new Event($eid);
$eventPath = $event->Path();
$eventRelativePath = $event->Relative_Path();
$files = array();
if ( $dir = opendir($eventPath) ) {
while ( ($file = readdir($dir)) !== false ) {
@ -759,7 +761,7 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
}
fwrite($fp, exportEventDetail($event, $exportFrames, $exportImages));
fclose($fp);
$exportFileList[$file] = $eventPath."/".$file;
$exportFileList[$file] = $event->Id().'/'.$file;
}
if ( $exportFrames ) {
$file = 'zmEventFrames.html';
@ -768,15 +770,15 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
}
fwrite($fp, exportEventFrames($event, $exportDetail, $exportImages));
fclose($fp);
$exportFileList[$file] = $eventPath."/".$file;
$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;
$myfilelist[$file] = $exportFileList[$file] = $event->Id().'/'.$file;
} else {
$filesLeft[$file] = $file;
}
@ -786,10 +788,11 @@ 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'" );
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] = $eventPath."/".$file;
$exportFileList[$file] = $event->Id().'/'.$file;
}
} # end if exportImages
@ -797,7 +800,7 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
$filesLeft = array();
foreach ( $files as $file ) {
if ( preg_match('/\.(?:mpg|mpeg|mov|swf|mp4|mkv|avi|asf|3gp)$/', $file) ) {
$exportFileList[$file] = $eventPath.'/'.$file;
$exportFileList[$file] = $event->Id().'/'.$file;
} else {
$filesLeft[$file] = $file;
}
@ -807,84 +810,111 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
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'");
}
foreach ( $exportFileList as $exportFile ) {
$exportFile = 'zmExport'.$connkey.'/'.$exportFile;
fwrite($fp, "$exportFile\n");
}
fwrite($fp, "$listFile\n");
fclose($fp);
$archive = '';
if ( $exportFormat == 'tar' ) {
$archive = ZM_DIR_EXPORTS.'/'.$export_root.'.tar.gz';
$archive = ZM_DIR_EXPORTS.'/'.$export_root.'_'.$connkey.'.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 );
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';
$archive = $export_dir.'/'.$export_root.'.zip';
@unlink($archive);
if ( $exportStructure == 'flat' ) {
$command = "cat ".escapeshellarg($listFile)." | nice -10 zip -q -j ".escapeshellarg($archive)." -@";
$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 ) {
@ -893,12 +923,11 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
Error("First line of output is '".$output[0]."'");
return false;
}
}
//clean up temporary files
if ( !empty($html_eventMaster) ) {
unlink($monitorPath.'/'.$html_eventMaster);
}
return '?view=archive%26type='.$exportFormat;
return '?view=archive%26type='.$exportFormat.'%26connkey='.$connkey;
}