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,17 +18,15 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // 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 lang="en">
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<head> <meta charset="utf-8">
<title><?php echo $title ?></title> <title><?php echo $title ?></title>
<style type="text/css"> <style type="text/css">
<!-- <!--
<?php include( ZM_SKIN_PATH.'/css/'.ZM_SKIN_NAME.'/export.css' ); ?> <?php include(ZM_SKIN_PATH.'/css/'.ZM_SKIN_NAME.'/export.css'); ?>
ul.tabs { ul.tabs {
margin: 0; margin: 0;
@ -71,10 +69,9 @@ html ul.tabs li.active, html ul.tabs li.active a:hover {
} }
--> -->
</style> </style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="video.js"></script>
<script type="text/javascript"> <script type="text/javascript">
<?php include(ZM_SKIN_PATH.'/js/jquery.js') ?>
</script>
<script type="text/javascript" language="javascript" charset="utf-8">
/*==========[tab code]==========*/ /*==========[tab code]==========*/
$(document).ready(function() { $(document).ready(function() {
@ -96,24 +93,21 @@ html ul.tabs li.active, html ul.tabs li.active a:hover {
return false; return false;
}); });
}); });
// ]]> // ]]>
</script> </script>
</head> </head>
<?php <?php
} }
function exportEventDetail( $event, $exportFrames, $exportImages ) function exportEventDetail($event, $exportFrames, $exportImages) {
{
ob_start(); ob_start();
exportHeader( translate('Event')." ".$event->Id() ); exportHeader(translate('Event').' '.$event->Id());
$otherlinks = ''; $otherlinks = '';
if( $exportFrames ) $otherlinks .= '<a href="zmEventFrames.html">'.translate('Frames').'</a>,'; if( $exportFrames ) $otherlinks .= '<a href="zmEventFrames.html">'.translate('Frames').'</a>,';
if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.translate('Images').'</a>,'; if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.translate('Images').'</a>,';
$otherlinks = substr($otherlinks,0,-1); $otherlinks = substr($otherlinks,0,-1);
?> ?>
<body> <body>
<div id="page"> <div id="page">
@ -139,22 +133,20 @@ function exportEventDetail( $event, $exportFrames, $exportImages )
</body> </body>
</html> </html>
<?php <?php
return( ob_get_clean() ); return ob_get_clean();
} }
function exportEventFrames( $event, $exportDetail, $exportImages ) function exportEventFrames($event, $exportDetail, $exportImages) {
{ $sql = 'SELECT *, unix_timestamp( TimeStamp ) AS UnixTimeStamp FROM Frames WHERE EventID = ? ORDER BY FrameId';
$sql = "SELECT *, unix_timestamp( TimeStamp ) AS UnixTimeStamp FROM Frames WHERE EventID = ? ORDER BY FrameId"; $frames = dbFetchAll($sql, NULL, array($event->Id()));
$frames = dbFetchAll( $sql, NULL, array( $event->Id() ) );
ob_start(); ob_start();
exportHeader( translate('Frames')." ".$event->Id() ); exportHeader(translate('Frames').' '.$event->Id());
$otherlinks = ''; $otherlinks = '';
if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.translate('Event').'</a>,'; if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.translate('Event').'</a>,';
if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.translate('Images').'</a>,'; if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.translate('Images').'</a>,';
$otherlinks = substr($otherlinks,0,-1); $otherlinks = substr($otherlinks,0,-1);
?> ?>
<body> <body>
<div id="page"> <div id="page">
@ -168,8 +160,7 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
<th><?php echo translate('TimeDelta') ?></th> <th><?php echo translate('TimeDelta') ?></th>
<th><?php echo translate('Score') ?></th> <th><?php echo translate('Score') ?></th>
<?php <?php
if ( $exportImages ) if ( $exportImages ) {
{
?> ?>
<th><?php echo translate('Image') ?></th> <th><?php echo translate('Image') ?></th>
<?php <?php
@ -177,17 +168,14 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
?> ?>
</tr> </tr>
<?php <?php
if ( count($frames) ) if ( count($frames) ) {
{
$eventPath = $event->Path(); $eventPath = $event->Path();
foreach ( $frames as $frame ) foreach ( $frames as $frame ) {
{ $imageFile = sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d-capture.jpg', $frame['FrameId']);
$imageFile = sprintf( "%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $frame['FrameId'] ); $imagePath = $eventPath.'/'.$imageFile;
$imagePath = $eventPath."/".$imageFile; $analImage = preg_replace('/capture/', 'analyse', $imagePath);
$analImage = preg_replace( "/capture/", "analyse", $imagePath ); if ( file_exists($analImage) ) {
if ( file_exists( $analImage ) ) $imageFile = preg_replace('/capture/', 'analyse', $imageFile);
{
$imageFile = preg_replace( "/capture/", "analyse", $imageFile );
} }
$class = strtolower($frame['Type']); $class = strtolower($frame['Type']);
@ -195,29 +183,26 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
<tr class="<?php echo $class ?>"> <tr class="<?php echo $class ?>">
<td><?php echo $frame['FrameId'] ?></td> <td><?php echo $frame['FrameId'] ?></td>
<td><?php echo $frame['Type'] ?></td> <td><?php echo $frame['Type'] ?></td>
<td><?php echo strftime( STRF_FMT_TIME, $frame['UnixTimeStamp'] ) ?></td> <td><?php echo strftime(STRF_FMT_TIME, $frame['UnixTimeStamp']) ?></td>
<td><?php echo number_format( $frame['Delta'], 2 ) ?></td> <td><?php echo number_format($frame['Delta'], 2) ?></td>
<td><?php echo $frame['Score'] ?></td> <td><?php echo $frame['Score'] ?></td>
<?php <?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 <?php
} }
?> ?>
</tr> </tr>
<?php <?php
} } # end foreach frame
} } else {
else
{
?> ?>
<tr> <tr>
<td class="monoRow" colspan="<?php echo $exportImages?6:5 ?>"><?php echo translate('NoFramesRecorded') ?></td> <td class="monoRow" colspan="<?php echo $exportImages?6:5 ?>"><?php echo translate('NoFramesRecorded') ?></td>
</tr> </tr>
<?php <?php
} } # end if count($frames)
?> ?>
</table> </table>
</div> </div>
@ -225,13 +210,12 @@ function exportEventFrames( $event, $exportDetail, $exportImages )
</body> </body>
</html> </html>
<?php <?php
return( ob_get_clean() ); return ob_get_clean();
} }
function exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist ) function exportEventImages($event, $exportDetail, $exportFrames, $myfilelist) {
{
ob_start(); ob_start();
exportHeader( translate('Images')." ".$event->Id() ); exportHeader(translate('Images').' '.$event->Id());
$otherlinks = ''; $otherlinks = '';
if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.translate('Event').'</a>,'; 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> <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> <ilayer id="slidensmain" width=&{slidewidth}; height=&{slideheight}; bgColor=&{slidebgcolor}; visibility=hide>
<layer id="slidenssub" width=&{slidewidth}; left=auto top=auto></layer> <layer id="slidenssub" width=&{slidewidth}; left=auto top=auto></layer>
</ilayer> </ilayer>
<div id="imagevideo" align="center"></div> <div id="imagevideo" align="center"></div>
<br> <br>
<div align="center"> <div align="center">
<button onclick="stepbackward()">< Step</button><button <button onclick="stepbackward()">&lt; Step</button>
id="btnrwd" onclick="rewind()" >Rwd</button><button <button id="btnrwd" onclick="rewind()" >Rwd</button>
id="btnplay" onclick="playstop()">Stop</button><button <button id="btnplay" onclick="playstop()">Stop</button>
onclick="stepforward()">Step ></button><button <button onclick="stepforward()">Step &gt;</button>
id="btnspeedup" onclick="speedup()">speedup</button><button <button id="btnspeedup" onclick="speedup()">speedup</button>
id="btnspeeddown" onclick="speeddown()">slowdown</button> <button id="btnspeeddown" onclick="speeddown()">slowdown</button>
</div> </div>
<div align="center"><div class="horizontal_track" > <div align="center"><div class="horizontal_track" >
<div class="horizontal_slit" >&nbsp;</div> <div class="horizontal_slit" >&nbsp;</div>
<div class="horizontal_slider" id="imageslider_id" style="left: 0px;" <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> 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 align="center"><div class="display_holder" ><input id="imageslider_display_id" class="value_display" type="text" value="0" onfocus="blur(this);" /></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 type="text/javascript">
<script language="JavaScript1.2">
/*********************************************** /***********************************************
* Flexi Slideshow- © Dynamic Drive (www.dynamicdrive.com) * Flexi Slideshow- © Dynamic Drive (www.dynamicdrive.com)
@ -286,15 +295,15 @@ function exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist )
* Visit http://www.dynamicdrive.com/ for full source code * Visit http://www.dynamicdrive.com/ for full source code
***********************************************/ ***********************************************/
var eventWidth = <?php echo$event->Width()?>; var eventWidth = <?php echo $event->Width()?>;
var eventHeight = <?php echo$event->Height()?>; var eventHeight = <?php echo $event->Height()?>;
var variableslide=[<?php echo$slides?>]; var variableslide=[<?php echo $slides?>];
//configure the below 3 variables to set the dimension/background color of the slideshow //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 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 slideheight=eventHeight+'px'; //set to height of LARGEST iamge in your slideshow, plus any text description
var slidebgcolor='#ffffff' var slidebgcolor='#ffffff';
//configure the below variable to determine the delay between image rotations (in miliseconds) //configure the below variable to determine the delay between image rotations (in miliseconds)
var origslidedelay=100; var origslidedelay=100;
@ -306,11 +315,11 @@ var ie=document.all;
var dom=document.getElementById; var dom=document.getElementById;
for (i=0;i<variableslide.length;i++){ for (i=0;i<variableslide.length;i++){
var cacheimage=new Image() var cacheimage = new Image();
cacheimage.src=variableslide[i] cacheimage.src = variableslide[i];
} }
var currentslide=-1 var currentslide = -1;
var mytimer = null; var mytimer = null;
//if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+'px;height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>'); //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); slideManual(currentslide+1,eventWidth-20, 1, variableslide.length);
} }
function start_slider(){ function start_slider(){
crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub; crossrotateobj = dom ? document.getElementById("slidedom") : ie ? document.all.slidedom : document.slidensmain.document.slidenssub;
if (document.layers) document.slidensmain.visibility="show"; if (document.layers) document.slidensmain.visibility="show";
rotateimages(); rotateimages();
} }
// seyi_code // seyi_code
function rotateimagesrewind(){ function rotateimagesrewind(){
if (currentslide==0) currentslide=variableslide.length-1; if (currentslide==0) currentslide=variableslide.length-1;
@ -366,12 +373,13 @@ function stepforward() {
document.getElementById('btnspeedup').disabled = true; document.getElementById('btnspeedup').disabled = true;
document.getElementById('btnspeeddown').disabled = true; document.getElementById('btnspeeddown').disabled = true;
if (currentslide==variableslide.length-1) currentslide=0; if ( currentslide == variableslide.length-1 ) currentslide=0;
else currentslide++; else currentslide++;
changeimage(); changeimage();
} }
function stepbackward() { function stepbackward() {
clearTimeout(mytimer); clearTimeout(mytimer);
// document.getElementById('btnrwd').style.borderTop='2px solid #ffffff'; // document.getElementById('btnrwd').style.borderTop='2px solid #ffffff';
@ -383,11 +391,10 @@ function stepbackward() {
document.getElementById('btnspeedup').disabled = true; document.getElementById('btnspeedup').disabled = true;
document.getElementById('btnspeeddown').disabled = true; document.getElementById('btnspeeddown').disabled = true;
if (currentslide==0) currentslide=variableslide.length-1; if ( currentslide == 0 ) currentslide = variableslide.length-1;
else currentslide--; else currentslide--;
changeimage(); changeimage();
} }
function speedup() { slidedelay = slidedelay/2; } function speedup() { slidedelay = slidedelay/2; }
function speeddown() { slidedelay = slidedelay*2; } function speeddown() { slidedelay = slidedelay*2; }
@ -430,7 +437,6 @@ function rewind() {
document.getElementById('btnspeedup').disabled = true; document.getElementById('btnspeedup').disabled = true;
document.getElementById('btnspeeddown').disabled = true; document.getElementById('btnspeeddown').disabled = true;
} }
} }
//---------------------------------+ //---------------------------------+
@ -501,65 +507,63 @@ function moveSlider(evnt) {
// seyi_code // seyi_code
currentslide = v-1; currentslide = v-1;
changeimage(); changeimage();
return false return false;
} }
return
} }
// moveSlider: Handles the start of a slider move. // moveSlider: Handles the start of a slider move.
function slide(evnt, orientation, length, from, to, count, decimals, display) { function slide(evnt, orientation, length, from, to, count, decimals, display) {
if (!evnt) evnt = window.event; if (!evnt) evnt = window.event;
sliderObj = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element. sliderObj = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element.
sliderObj.pxLen = length // The allowed slider movement in pixels. sliderObj.pxLen = length; // The allowed slider movement in pixels.
sliderObj.valCount = count ? count - 1 : length // Allowed number of values in the interval. sliderObj.valCount = count ? count - 1 : length; // Allowed number of values in the interval.
displayObj = carpeGetElementById(display) // Get the associated display element.\ displayObj = carpeGetElementById(display); // Get the associated display element.\
displayObj.dec = decimals // Number of decimals to be displayed. displayObj.dec = decimals; // Number of decimals to be displayed.
sliderObj.scale = (to - from) / length // Slider-display scale [value-change per pixel of movement]. sliderObj.scale = (to - from) / length; // Slider-display scale [value-change per pixel of movement].
if (orientation == 'horizontal') { // Set limits for horizontal sliders. if (orientation == 'horizontal') { // Set limits for horizontal sliders.
sliderObj.fromVal = from sliderObj.fromVal = from;
xMax = length xMax = length;
yMax = 0 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. pxLeft = carpeLeft(sliderObj.id); // Sliders horizontal position at start of slide.
sliderObj.fromVal = to pxTop = carpeTop(sliderObj.id); // Sliders vertical position at start of slide.
xMax = 0 xCoord = evnt.screenX; // Horizontal mouse position at start of slide.
yMax = length yCoord = evnt.screenY; // Vertical mouse position at start of slide.
sliderObj.scale = -sliderObj.scale // Invert scale for vertical sliders. "Higher is more." mouseover = true;
} document.onmousemove = moveSlider; // Start the action if the mouse is dragged.
pxLeft = carpeLeft(sliderObj.id) // Sliders horizontal position at start of slide. document.onmouseup = sliderMouseUp; // Stop sliding.
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. // sliderMouseup: Handles the mouseup event after moving a slider.
// Snaps the slider position to allowed/displayed value. // Snaps the slider position to allowed/displayed value.
function sliderMouseUp() { function sliderMouseUp() {
mouseover = false // Stop the sliding. mouseover = false; // Stop the sliding.
v = (displayObj.value) ? displayObj.value : 0 // Find last display value. v = (displayObj.value) ? displayObj.value : 0; // Find last display value.
pos = (v - sliderObj.fromVal)/(sliderObj.scale) // Calculate slider position (regardless of orientation). 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 (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 (xMax == 0) carpeTop(sliderObj.id, pos); // Snap vertical slider to corresponding display position.
if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co). if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
document.removeEventListener('mousemove', moveSlider) document.removeEventListener('mousemove', moveSlider);
document.removeEventListener('mouseup', sliderMouseUp) document.removeEventListener('mouseup', sliderMouseUp);
} }
else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co). else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
document.detachEvent('onmousemove', moveSlider) document.detachEvent('onmousemove', moveSlider);
document.detachEvent('onmouseup', sliderMouseUp) document.detachEvent('onmouseup', sliderMouseUp);
} }
} }
//seyi_code // seyi_code
//slide(event,'horizontal', 300, 1, 22, 22,0, 'imageslider_display_id'); //slide(event,'horizontal', 300, 1, 22, 22,0, 'imageslider_display_id');
//slide(evnt, orientation, length, from, to, count, decimals, display) { //slide(evnt, orientation, length, from, to, count, decimals, display) {
function slideManual(val,length,from,to) { function slideManual(val,length,from,to) {
scale = (to - from) / length // Slider-display scale [value-change per pixel of movement]. scale = (to - from) / length; // Slider-display scale [value-change per pixel of movement].
fromVal = from fromVal = from;
xMax = length xMax = length;
yMax = 0 yMax = 0;
sliderid = 'imageslider_id'; sliderid = 'imageslider_id';
@ -574,21 +578,23 @@ if (ie||dom) start_slider();
else if (document.layers) window.onload=start_slider; else if (document.layers) window.onload=start_slider;
</script> </script>
<?php
} # end if defaultvideo
?>
</body> </body>
</html> </html>
<?php <?php
return( ob_get_clean() ); return ob_get_clean();
} }
function exportEventImagesMaster( $eids ) { function exportEventImagesMaster($eids) {
ob_start(); ob_start();
exportHeader( translate('Images').' Master' ); exportHeader(translate('Images').' Master');
?> ?>
<body> <body>
<h2><?php echo translate('Images') ?> Master</h2> <h2><?php echo translate('Images') ?> Master</h2>
<?php <?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) { foreach ($eids as $eid) {
//get monitor id and event id //get monitor id and event id
$event = new Event( $eid ); $event = new Event( $eid );
@ -601,69 +607,65 @@ function exportEventImagesMaster( $eids ) {
//* //*
if(!empty($monitors)) { 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']; } foreach ( $tmp as $row ) { $monitorNames[$row['Id']] = $row['Name']; }
} }
//*/ //*/
//trigger_error(print_r($monitorNames,1)); //trigger_error(print_r($monitorNames,1));
?> ?>
<div id="tabs"> <div id="tabs">
<ul class="tabs"> <ul class="tabs">
<li class="active"><a href="#all"> All </a></li> <li class="active"><a href="#all"> All </a></li>
<?php <?php
foreach ($monitors as $monitor) { 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> </ul>
</div> </div>
<table width="100%" height="100%" ><tr> <table width="100%" height="100%">
<td valign="top" bgcolor="#dddddd" style="padding:10px;"> <tr>
<div class='tab_content' id='all'> <td valign="top" bgcolor="#dddddd" style="padding:10px;">
<div class="tab_content" id="all">
<h2> All </h2> <h2> All </h2>
<?php <?php
if (!is_array($eids)) { foreach($eids as $eid) {
echo "<div><a href=\"javascript:switchevent('$eids/zm/EventImages.html');\"> $eids </div>"; $Event = new Event($eid);
} if ( $Event->SaveJPEGs() ) {
?> ?>
<?php foreach($eids as $eid) { <div><a href="#" onclick="switchevent('<?php echo $eid; ?>/zmEventImages.html');return false;"><?php echo $eid; ?></a></div>
?> <?php
<div><a href="javascript:switchevent('<?php echo $eventPath[$eid]; ?>/zmEventImages.html');"><?php echo$eid?></a></div> } # end if saveJPEGs
<?php } # end foreach event id
} ?>
?>
</div> </div>
<?php <?php
foreach ($monitors as $monitor) { foreach ($monitors as $monitor) {
echo "<div class='tab_content' id='tab$monitor'>"; echo "<div class=\"tab_content\" id=\"tab$monitor\">";
echo "<h2>Monitor: " . $monitorNames[$monitor] . " </h2>"; echo '<h2>Monitor: ' . $monitorNames[$monitor] . ' </h2>';
foreach ($eids as $eid) { foreach ( $eids as $eid ) {
if ($eventMonitorId[$eid] == $monitor) { 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 <?php
} }
} }
echo'</div>'; echo '</div>';
} } # end foreach monitor
?> ?>
</td><td>
</td><td>
<iframe id="myframe" onload="resizeCaller();" name="myframe" src="#" <iframe id="myframe" onload="resizeCaller();" name="myframe" src="#"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"
vspace="0" hspace="0" style="overflow:visible; width:100%; display:none"> vspace="0" hspace="0" style="overflow:visible; width:100%; display:none">
</iframe> </iframe>
</td>
</td> </tr>
</tr></table> </table>
<script type="text/javascript"> <script type="text/javascript">
function switchevent(src) { function switchevent(src) {
if(document.all) document.all.myframe.src = src; $('#myframe').attr('src',src);
else window.frames['myframe'].location.href = src; $('#myframe').show();
} }
/*********************************************** /***********************************************
@ -674,72 +676,72 @@ function switchevent(src) {
//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height: //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: //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): //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 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 FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers
function resizeCaller() { function resizeCaller() {
var dyniframe=new Array() var dyniframe=new Array();
for (i=0; i<iframeids.length; i++){ for (i=0; i<iframeids.length; i++){
if (document.getElementById) resizeIframe(iframeids[i]); if (document.getElementById) resizeIframe(iframeids[i]);
//reveal iframe for lower end browsers? (see var above): //reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){ if ( (document.all || document.getElementById) && iframehide=="no" ) {
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]) var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]);
tempobj.style.display="block" tempobj.style.display="block";
} }
} }
} }
function resizeIframe(frameid){ function resizeIframe(frameid) {
var currentfr=document.getElementById(frameid) var currentfr = document.getElementById(frameid);
if (currentfr && !window.opera){ if ( currentfr && !window.opera ) {
currentfr.style.display="block" currentfr.style.display = "block";
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax if ( currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight ) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax else if ( currentfr.Document && currentfr.Document.body.scrollHeight ) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight; currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener) currentfr.addEventListener("load", readjustIframe, false);
else if (currentfr.attachEvent){ if ( currentfr.addEventListener ) {
currentfr.detachEvent("onload", readjustIframe) // Bug fix line currentfr.addEventListener("load", readjustIframe, false);
currentfr.attachEvent("onload", readjustIframe) } else if ( currentfr.attachEvent ) {
currentfr.detachEvent("onload", readjustIframe); // Bug fix line
currentfr.attachEvent("onload", readjustIframe);
} }
} }
} }
function readjustIframe(loadevt) { function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt; var crossevt = window.event ? event : loadevt;
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement var iframeroot = crossevt.currentTarget ? crossevt.currentTarget : crossevt.srcElement;
if (iframeroot) resizeIframe(iframeroot.id); if (iframeroot) resizeIframe(iframeroot.id);
} }
function loadintoIframe(iframeid, url){ function loadintoIframe(iframeid, url) {
if (document.getElementById) document.getElementById(iframeid).src=url; if (document.getElementById) document.getElementById(iframeid).src=url;
} }
//if (window.addEventListener) window.addEventListener("load", resizeCaller, false) //if (window.addEventListener) window.addEventListener("load", resizeCaller, false)
//else if (window.attachEvent) window.attachEvent("onload", resizeCaller) //else if (window.attachEvent) window.attachEvent("onload", resizeCaller)
//else window.onload=resizeCaller //else window.onload=resizeCaller
</script>
</script> </body>
</body>
</html> </html>
<?php <?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; return;
} }
$event = new Event($eid);
$eventPath = $event->Path(); $eventPath = $event->Path();
$eventRelativePath = $event->Relative_Path();
$files = array(); $files = array();
if ( $dir = opendir($eventPath) ) { if ( $dir = opendir($eventPath) ) {
while ( ($file = readdir($dir)) !== false ) { while ( ($file = readdir($dir)) !== false ) {
@ -754,29 +756,29 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
if ( $exportDetail ) { if ( $exportDetail ) {
$file = 'zmEventDetail.html'; $file = 'zmEventDetail.html';
if ( !($fp = fopen( $eventPath.'/'.$file, 'w' )) ) { if ( !($fp = fopen($eventPath.'/'.$file, 'w')) ) {
Fatal( "Can't open event detail export file '$file'" ); Fatal("Can't open event detail export file '$file'");
} }
fwrite( $fp, exportEventDetail( $event, $exportFrames, $exportImages ) ); fwrite($fp, exportEventDetail($event, $exportFrames, $exportImages));
fclose( $fp ); fclose($fp);
$exportFileList[$file] = $eventPath."/".$file; $exportFileList[$file] = $event->Id().'/'.$file;
} }
if ( $exportFrames ) { if ( $exportFrames ) {
$file = 'zmEventFrames.html'; $file = 'zmEventFrames.html';
if ( !($fp = fopen( $eventPath.'/'.$file, 'w' )) ) { if ( !($fp = fopen($eventPath.'/'.$file, 'w')) ) {
Fatal( "Can't open event frames export file '$file'" ); Fatal("Can't open event frames export file '$file'");
} }
fwrite( $fp, exportEventFrames( $event, $exportDetail, $exportImages ) ); fwrite($fp, exportEventFrames($event, $exportDetail, $exportImages));
fclose( $fp ); fclose($fp);
$exportFileList[$file] = $eventPath."/".$file; $exportFileList[$file] = $event->Id().'/'.$file;
} }
if ( $exportImages ) { if ( $exportImages ) {
$filesLeft = array(); $filesLeft = array();
$myfilelist = array(); $myfilelist = array();
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( preg_match( '/-(?:capture|analyse).jpg$/', $file ) ) { if ( preg_match('/-(?:capture|analyse).jpg$/', $file ) ) {
$exportFileList[$file] = $eventPath."/".$file; $myfilelist[$file] = $exportFileList[$file] = $event->Id().'/'.$file;
$myfilelist[$file] = $eventPath."/".$file;
} else { } else {
$filesLeft[$file] = $file; $filesLeft[$file] = $file;
} }
@ -786,18 +788,19 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
// create an image slider // create an image slider
if ( !empty($myfilelist) ) { if ( !empty($myfilelist) ) {
$file = 'zmEventImages.html'; $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')) )
fwrite( $fp, exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist ) ); Fatal("Can't open event images export file '$file'");
fclose( $fp ); fwrite($fp, exportEventImages($event, $exportDetail, $exportFrames, $myfilelist));
$exportFileList[$file] = $eventPath."/".$file; fclose($fp);
$exportFileList[$file] = $event->Id().'/'.$file;
} }
} # end if exportImages } # end if exportImages
if ( $exportVideo ) { if ( $exportVideo ) {
$filesLeft = array(); $filesLeft = array();
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( preg_match( '/\.(?:mpg|mpeg|mov|swf|mp4|mkv|avi|asf|3gp)$/', $file ) ) { if ( preg_match('/\.(?:mpg|mpeg|mov|swf|mp4|mkv|avi|asf|3gp)$/', $file) ) {
$exportFileList[$file] = $eventPath.'/'.$file; $exportFileList[$file] = $event->Id().'/'.$file;
} else { } else {
$filesLeft[$file] = $file; $filesLeft[$file] = $file;
} }
@ -807,98 +810,124 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
if ( $exportMisc ) { if ( $exportMisc ) {
foreach ( $files as $file ) { foreach ( $files as $file ) {
$exportFileList[$file] = $eventPath.'/'.$file; $exportFileList[$file] = $event->Id().'/'.$file;
} }
$files = array(); $files = array();
} }
return array_values($exportFileList); 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; 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 ( ! file_exists(ZM_DIR_EXPORTS) ) {
if ( ! mkdir(ZM_DIR_EXPORTS) ) { if ( ! mkdir(ZM_DIR_EXPORTS) ) {
Fatal("Can't create exports dir at '".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')) ) { 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 ) { 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 = ''; $archive = '';
if ( $exportFormat == 'tar' ) { if ( $exportFormat == 'tar' ) {
$archive = ZM_DIR_EXPORTS.'/'.$export_root.'.tar.gz'; $archive = ZM_DIR_EXPORTS.'/'.$export_root.'_'.$connkey.'.tar.gz';
@unlink( $archive ); @unlink($archive);
if ( $exportStructure == 'flat' ) { //strip file paths if we choose chdir(ZM_DIR_EXPORTS);
$command = "nice -10 tar --create --gzip --file=".escapeshellarg($archive)." --files-from=".escapeshellarg($listFile)." --xform='s#^.+/##x'"; $command = 'nice -10 tar --create --gzip --dereference --file='.escapeshellarg($archive).' zmExport' . $connkey;
} else { #$command = 'nice -10 tar --create --gzip --file='.escapeshellarg($archive).' --files-from='.escapeshellarg($listFile);
$command = "nice -10 tar --create --gzip --file=".escapeshellarg($archive)." --files-from=".escapeshellarg($listFile); if ( $exportStructure == 'flat' ) {
} //strip file paths if we
exec( $command, $output, $status ); $command .= " --xform='s#^.+/##x'";
if ( $status ) {
Error( "Command '$command' returned with status $status" );
if ( $output[0] )
Error( "First line of output is '".$output[0]."'" );
return( false );
} }
} elseif ( $exportFormat == 'zip' ) { } elseif ( $exportFormat == 'zip' ) {
$archive = ZM_DIR_EXPORTS.'/'.$export_root.'.zip'; $archive = $export_dir.'/'.$export_root.'.zip';
@unlink( $archive ); @unlink($archive);
if ($exportStructure == 'flat') { 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 { } 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 -@ } // if $exportFormat
//-bash: zip: command not found
exec( $command, $output, $status ); exec($command, $output, $status);
if ( $status ) { if ( $status ) {
Error("Command '$command' returned with status $status"); Error("Command '$command' returned with status $status");
if ( $output[0] ) if ( $output[0] )
Error("First line of output is '".$output[0]."'"); Error("First line of output is '".$output[0]."'");
return false; return false;
} }
}
//clean up temporary files //clean up temporary files
if ( !empty($html_eventMaster) ) { if ( !empty($html_eventMaster) ) {
unlink($monitorPath.'/'.$html_eventMaster); unlink($monitorPath.'/'.$html_eventMaster);
} }
return '?view=archive%26type='.$exportFormat; return '?view=archive%26type='.$exportFormat.'%26connkey='.$connkey;
} }