Bug 50 - First pass at event export functionality.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1418 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan
2005-05-17 21:51:39 +00:00
parent f063792893
commit 0ef4e65eb5
7 changed files with 536 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ web_DATA = \
zm_config.php \
zm_control_funcs.php \
zm_db.php \
zm_export_funcs.php \
zm_funcs.php \
zm_html.php \
zm_html_styles.css \
@@ -34,6 +35,7 @@ web_DATA = \
zm_html_view_event.php \
zm_html_view_eventdetail.php \
zm_html_view_events.php \
zm_html_view_export.php \
zm_html_view_filter.php \
zm_html_view_filtersave.php \
zm_html_view_frame.php \
@@ -108,6 +110,7 @@ EXTRA_DIST = \
zm_config.php.z \
zm_control_funcs.php \
zm_db.php \
zm_export_funcs.php \
zm_funcs.php \
zm_html.php \
zm_html_styles.css \
@@ -125,6 +128,7 @@ EXTRA_DIST = \
zm_html_view_event.php \
zm_html_view_eventdetail.php \
zm_html_view_events.php \
zm_html_view_export.php \
zm_html_view_filter.php \
zm_html_view_filtersave.php \
zm_html_view_frame.php \

View File

@@ -162,6 +162,7 @@ $jws = array(
'event' => array( 'w'=>96, 'h'=>168 ),
'eventdetail' => array( 'w'=>400, 'h'=>220 ),
'events' => array( 'w'=>720, 'h'=>480 ),
'export' => array( 'w'=>400, 'h'=>340 ),
'filter' => array( 'w'=>560, 'h'=>250 ),
'filtersave' => array( 'w'=>560, 'h'=>220 ),
'frames' => array( 'w'=>500, 'h'=>300 ),

342
web/zm_export_funcs.php Normal file
View File

@@ -0,0 +1,342 @@
<?php
//
// ZoneMinder web export function library, $Date$, $Revision$
// Copyright (C) 2003, 2004, 2005 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
function exportHeader( $title )
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?= $title ?></title>
<style type="text/css">
<!--
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
color: #333333;
font-weight: normal
}
a:link {
color: #7F7FB2;
text-decoration: none
}
a:visited {
color: #7F7FB2;
text-decoration: none
}
a:hover {
color: #666699;
text-decoration: underline
}
-->
</style>
</head>
<?php
}
function exportEventDetail( $event )
{
global $export_detail, $export_frames, $export_images, $export_video, $export_misc;
global $zmSlangEvent, $zmSlangId, $zmSlangName, $zmSlangMonitor, $zmSlangCause, $zmSlangNotes, $zmSlangTime, $zmSlangDuration;
global $zmSlangFrames, $zmSlangAttrAlarmFrames, $zmSlangAttrTotalScore, $zmSlangAttrAvgScore, $zmSlangAttrMaxScore, $zmSlangArchived;
global $zmSlangYes, $zmSlangNo;
ob_start();
exportHeader( $zmSlangEvent." ".$event['Id'] );
?>
<body>
<table>
<tr><td><?= $zmSlangId ?></td><td><?= $event['Id'] ?></td></tr>
<tr><td><?= $zmSlangName ?></td><td><?= $event['Name'] ?></td></tr>
<tr><td><?= $zmSlangMonitor ?></td><td><?= $event['MonitorName'] ?> (<?= $event['MonitorId'] ?>)</td></tr>
<tr><td><?= $zmSlangCause ?></td><td><?= $event['Cause'] ?></td></tr>
<tr><td><?= $zmSlangNotes ?></td><td><?= $event['Notes'] ?></td></tr>
<tr><td><?= $zmSlangTime ?></td><td><?= strftime( "%m/%d %H:%M:%S", strtotime($event['StartTime']) ) ?></td></tr>
<tr><td><?= $zmSlangDuration ?></td><td><?= $event['Length'] ?></td></tr>
<tr><td><?= $zmSlangFrames ?></td><td><?= $event['Frames'] ?></td></tr>
<tr><td><?= $zmSlangAttrAlarmFrames ?></td><td><?= $event['AlarmFrames'] ?></td></tr>
<tr><td><?= $zmSlangAttrTotalScore ?></td><td><?= $event['TotScore'] ?></td></tr>
<tr><td><?= $zmSlangAttrAvgScore ?></td><td><?= $event['AvgScore'] ?></td></tr>
<tr><td><?= $zmSlangAttrMaxScore ?></td><td><?= $event['MaxScore'] ?></td></tr>
<tr><td><?= $zmSlangArchived ?></td><td><?= $event['Archived']?$zmSlangYes:$zmSlangNo ?></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<?php
if ( $export_frames )
{
?>
<tr><td colspan="2"><a href="zmEventFrames.html"><?= $zmSlangFrames ?></a></td></tr>
<?php
}
?>
</table>
</body>
</html>
<?php
return( ob_get_clean() );
}
function exportEventFrames( $event )
{
global $export_detail, $export_frames, $export_images, $export_video, $export_misc;
global $zmSlangFrames, $zmSlangFrameId, $zmSlangAlarmFrame, $zmSlangTimeStamp, $zmSlangTimeDelta, $zmSlangScore, $zmSlangImage;
global $zmSlangYes, $zmSlangNo, $zmSlangNoFramesRecorded;
$sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '".$event['Id']."' order by FrameId";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
$frames[] = $row;
}
ob_start();
exportHeader( $zmSlangFrames." ".$event['Id'] );
?>
<body>
<table width="100%" border="0" bgcolor="#7F7FB2" cellpadding="3" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td align="center"><?= $zmSlangFrameId ?></td>
<td align="center"><?= $zmSlangAlarmFrame ?></td>
<td align="center"><?= $zmSlangTimeStamp ?></td>
<td align="center"><?= $zmSlangTimeDelta ?></td>
<td align="center"><?= $zmSlangScore ?></td>
<?php
if ( $export_images )
{
?>
<td align="center"><?= $zmSlangImage ?></td>
<?php
}
?>
</tr>
<?php
if ( count($frames) )
{
$event_path = ZM_DIR_EVENTS.'/'.$event['MonitorId'].'/'.$event['Id'];
foreach ( $frames as $frame )
{
$image_file = sprintf( "%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $frame['FrameId'] );
$image_path = $event_path."/".$image_file;
$anal_image = preg_replace( "/capture/", "analyse", $image_path );
if ( file_exists( $anal_image ) )
{
$image_file = preg_replace( "/capture/", "analyse", $image_file );
}
$alarm_frame = $frame['Type']=='Alarm';
$bgcolor = $alarm_frame?'#FA8072':($frame['Type']=='Bulk'?'#CCCCCC':'#FFFFFF');
?>
<tr bgcolor="<?= $bgcolor ?>">
<td align="center"><?= $frame['FrameId'] ?></td>
<td align="center"><?= $alarm_frame?$zmSlangYes:$zmSlangNo ?></td>
<td align="center"><?= date( "H:i:s", $frame['UnixTimeStamp'] ) ?></td>
<td align="center"><?= number_format( $frame['Delta'], 2 ) ?></td>
<td align="center"><?= $frame['Score'] ?></td>
<?php
if ( $export_images )
{
?>
<td align="center"><a href="<?= $image_file ?>"><img src="<?= $image_file ?>" border="0" width="40" alt="Frame <?= $frame['FrameId'] ?>"></a></td>
<?php
}
?>
</tr>
<?php
}
}
else
{
?>
<tr bgcolor="#FFFFFF">
<td class="text" colspan="<?= $export_images?6:5 ?>" align="center"><br><?= $zmSlangNoFramesRecorded ?><br><br></td>
</tr>
<?php
}
?>
</table></td>
</tr>
</table>
</body>
</html>
<?php
return( ob_get_clean() );
}
function exportFileList( $eid )
{
global $export_detail, $export_frames, $export_images, $export_video, $export_misc;
if ( canView( 'Events' ) && $eid )
{
$sql = "select E.Id,E.MonitorId,M.Name As MonitorName,M.Width,M.Height,E.Name,E.Cause,E.Notes,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where E.Id = '$eid'";
if ( !($result = mysql_query( $sql )) )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
$event_path = sprintf( "%s/%s/%d", ZM_DIR_EVENTS, $event['MonitorName'], $event['Id'] );
$files = array();
if ( $dir = opendir( $event_path ) )
{
while ( ($file = readdir( $dir )) !== false )
{
if ( is_file( $event_path."/".$file ) )
{
$files[$file] = $file;
}
}
closedir( $dir );
}
$export_file_list = array();
if ( $export_detail )
{
$file = "zmEventDetail.html";
if ( !($fp = fopen( $event_path."/".$file, "w" )) )
{
die( "Can't open event detail export file '$file'" );
}
fwrite( $fp, exportEventDetail( $event ) );
fclose( $fp );
$export_file_list[$file] = $event_path."/".$file;
}
if ( $export_frames )
{
$file = "zmEventFrames.html";
if ( !($fp = fopen( $event_path."/".$file, "w" )) )
{
die( "Can't open event frames export file '$file'" );
}
fwrite( $fp, exportEventFrames( $event ) );
fclose( $fp );
$export_file_list[$file] = $event_path."/".$file;
}
if ( $export_images )
{
$files_left = array();
foreach ( $files as $file )
{
if ( preg_match( "/-(?:capture|analyse).jpg$/", $file ) )
{
$export_file_list[$file] = $event_path."/".$file;
}
else
{
$files_left[$file] = $file;
}
}
$files = $files_left;
}
if ( $export_video )
{
$files_left = array();
foreach ( $files as $file )
{
if ( preg_match( "/\.(?:mpg|mpeg|avi|asf|3gp)$/", $file ) )
{
$export_file_list[$file] = $event_path."/".$file;
}
else
{
$files_left[$file] = $file;
}
}
$files = $files_left;
}
if ( $export_misc )
{
foreach ( $files as $file )
{
$export_file_list[$file] = $event_path."/".$file;
}
$files = array();
}
}
return( array_values( $export_file_list ) );
}
function exportEvents( $eids )
{
global $export_format;
if ( canView( 'Events' ) && $eids )
{
$export_root = "zmExport";
$export_list_file = "zmFileList.txt";
$export_file_list = array();
if ( is_array( $eids ) )
{
foreach ( $eids as $eid )
{
$export_file_list = array_merge( $export_file_list, exportFileList( $eid ) );
}
}
else
{
$eid = $eids;
$export_file_list = exportFileList( $eid );
}
$list_file = "temp/".$export_list_file;
if ( !($fp = fopen( $list_file, "w" )) )
{
die( "Can't open event export list file '$list_file'" );
}
foreach ( $export_file_list as $export_file )
{
fwrite( $fp, "$export_file\n" );
}
fclose( $fp );
$archive = "not-specified";
if ( $export_format == "tar" )
{
$archive = "temp/".$export_root.".tar.gz";
@unlink( $archive );
$command = "tar --create --gzip --file=$archive --files-from=$list_file";
exec( $command, $output, $status );
if ( $status )
{
error_log( "Command '$command' returned with status $status" );
if ( $output[0] )
error_log( "First line of output is '".$output[0]."'" );
return( false );
}
}
elseif ( $export_format == "zip" )
{
$archive = "temp/zm_export.zip";
$archive = "temp/".$export_root.".zip";
@unlink( $archive );
$command = "cat $list_file | zip -q $archive -@";
exec( $command, $output, $status );
if ( $status )
{
error_log( "Command '$command' returned with status $status" );
if ( $output[0] )
error_log( "First line of output is '".$output[0]."'" );
return( false );
}
}
}
return( $archive );
}

View File

@@ -127,6 +127,7 @@ switch( $view )
case "filtersave" :
case "event" :
case "eventdetail" :
case "export" :
case "frame" :
case "frames" :
case "stats" :

View File

@@ -141,6 +141,7 @@ function checkAll(form,name)
form.edit_btn.disabled = false;
form.archive_btn.disabled = <?= $unarchived?"false":"true" ?>;
form.unarchive_btn.disabled = <?= $archived?"false":"true" ?>;
form.export_btn.disabled = false;
form.delete_btn.disabled = false;
<?php if ( LEARN_MODE ) { ?>
form.learn_btn.disabled = false;
@@ -165,6 +166,7 @@ function configureButton(form,name)
form.edit_btn.disabled = !checked;
form.archive_btn.disabled = (!checked)||<?= $unarchived?"false":"true" ?>;
form.unarchive_btn.disabled = (!checked)||<?= $archived?"false":"true" ?>;
form.export_btn.disabled = !checked;
form.delete_btn.disabled = !checked;
<?php if ( LEARN_MODE ) { ?>
form.learn_btn.disabled = !checked;
@@ -186,6 +188,21 @@ function editEvents( form, name )
}
var Name = newWindow( '<?= $PHP_SELF ?>?view=eventdetail&'+eids.join( '&' ), 'zmEventDetail', <?= $jws['eventdetail']['w'] ?>, <?= $jws['eventdetail']['h'] ?> );
}
function exportEvents( form, name )
{
var eids = new Array();
for (var i = 0; i < form.elements.length; i++)
{
if (form.elements[i].name.indexOf(name) == 0)
{
if ( form.elements[i].checked )
{
eids[eids.length] = 'eids[]='+form.elements[i].value;
}
}
}
var Name = newWindow( '<?= $PHP_SELF ?>?view=export&'+eids.join( '&' ), 'zmExport', <?= $jws['export']['w'] ?>, <?= $jws['export']['h'] ?> );
}
function viewEvents( form, name )
{
var events = new Array();
@@ -401,6 +418,7 @@ function viewEvents( form, name )
&nbsp;&nbsp;<input type="button" name="archive_btn" value="<?= $zmSlangArchive ?>" class="form" onClick="document.event_form.action.value = 'archive'; document.event_form.submit();" disabled>
&nbsp;&nbsp;<input type="button" name="unarchive_btn" value="<?= $zmSlangUnarchive ?>" class="form" onClick="document.event_form.action.value = 'unarchive'; document.event_form.submit();" disabled>
&nbsp;&nbsp;<input type="button" name="edit_btn" value="<?= $zmSlangEdit ?>" class="form" onClick="editEvents( document.event_form, 'mark_eids' )" disabled>
&nbsp;&nbsp;<input type="button" name="export_btn" value="<?= $zmSlangExport ?>" class="form" onClick="exportEvents( document.event_form, 'mark_eids' )" disabled>
&nbsp;&nbsp;<input type="button" name="delete_btn" value="<?= $zmSlangDelete ?>" class="form" onClick="document.event_form.action.value = 'delete'; document.event_form.submit();" disabled>
</td></tr>
<?php } ?>

157
web/zm_html_view_export.php Normal file
View File

@@ -0,0 +1,157 @@
<?php
//
// ZoneMinder web export view file, $Date$, $Revision$
// Copyright (C) 2003, 2004, 2005 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
if ( !canView( 'Events' ) )
{
$view = "error";
return;
}
if ( $generate )
{
$_SESSION['export']['detail'] = $export_detail;
$_SESSION['export']['frames'] = $export_frames;
$_SESSION['export']['images'] = $export_images;
$_SESSION['export']['video'] = $export_video;
$_SESSION['export']['misc'] = $export_misc;
$_SESSION['export']['format'] = $export_format;
}
else
{
$export_detail = $_SESSION['export']['detail'];
$export_frames = $_SESSION['export']['frames'];
$export_images = $_SESSION['export']['images'];
$export_video = $_SESSION['export']['video'];
$export_misc = $_SESSION['export']['misc'];
$export_format = $_SESSION['export']['format'];
}
if ( !(($export_detail || $export_frames || $export_images || $export_video || $export_misc) && $export_format) )
{
$generate = 0;
}
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?= ZM_WEB_TITLE_PREFIX ?> - <?= $zmSlangExport ?></title>
<link rel="stylesheet" href="zm_html_styles.css" type="text/css">
<script type="text/javascript">
window.focus();
function closeWindow()
{
window.close();
}
</script>
</head>
<body>
<form name="export_form" method="post" action="<?= $PHP_SELF ?>">
<input type="hidden" name="view" value="<?= $view ?>">
<input type="hidden" name="action" value="<?= $action ?>">
<?php
if ( isset($eid) )
{
?>
<input type="hidden" name="eid" value="<?= $eid ?>">
<?php
}
elseif ( isset($eids) )
{
foreach ( $eids as $eid )
{
?>
<input type="hidden" name="eids[]" value="<?= $eid ?>">
<?php
}
unset( $eid );
}
?>
<input type="hidden" name="generate" value="1">
<table align="center" border="0" cellspacing="0" cellpadding="2" width="96%">
<tr><td width="50">&nbsp;</td><td class="head" align="center"><?= $zmSlangExportOptions ?></td><td width="50" class="text" align="right"><a href="javascript: window.close();"><?= $zmSlangClose ?></a></tr>
</table>
<table align="center" border="0" cellspacing="0" cellpadding="2" width="96%">
<tr><td width="60%">&nbsp;</td><td width="40%">&nbsp;</td></tr>
<tr><td class="text" align="right"><?= $zmSlangExportDetails ?></td><td><input type="checkbox" class="form-noborder" name="export_detail" value="1"<?php if ( isset($export_detail) ) { ?> checked<?php } ?>></td></tr>
<tr><td class="text" align="right"><?= $zmSlangExportFrames ?></td><td><input type="checkbox" class="form-noborder" name="export_frames" value="1"<?php if ( isset($export_frames) ) { ?> checked<?php } ?>></td></tr>
<tr><td class="text" align="right"><?= $zmSlangExportImageFiles ?></td><td><input type="checkbox" class="form-noborder" name="export_images" value="1"<?php if ( isset($export_images) ) { ?> checked<?php } ?>></td></tr>
<tr><td class="text" align="right"><?= $zmSlangExportVideoFiles ?></td><td><input type="checkbox" class="form-noborder" name="export_video" value="1"<?php if ( isset($export_video) ) { ?> checked<?php } ?>></td></tr>
<tr><td class="text" align="right"><?= $zmSlangExportMiscFiles ?></td><td><input type="checkbox" class="form-noborder" name="export_misc" value="1"<?php if ( isset($export_misc) ) { ?> checked<?php } ?>></td></tr>
<tr><td class="text" align="right"><?= $zmSlangExportFormat ?></td><td class="text"><input type="radio" class="form-noborder" name="export_format" value="tar"<?php if ( $export_format == "tar" ) { ?> checked<?php } ?>>&nbsp;<?= $zmSlangExportFormatTar ?>&nbsp;&nbsp;<input type="radio" class="form-noborder" name="export_format" value="zip"<?php if ( $export_format == "zip" ) { ?> checked<?php } ?>>&nbsp;<?= $zmSlangExportFormatZip ?></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2" align="center"><input type="submit" class="form" value="<?= $zmSlangExport ?>">&nbsp;&nbsp;<input type="button" value="<?= $zmSlangCancel ?>" class="form" onClick="closeWindow()"></td></tr>
</table>
</form>
<?php
if ( !empty($generate) )
{
require_once( 'zm_export_funcs.php' );
?>
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr>
<td align="center" class="head"><?= $zmSlangExporting ?></td>
</tr>
</table>
</body>
</html>
<?php
$buffer_string = "<!-- This is some long buffer text to ensure that IE flushes correctly -->";
for ( $i = 0; $i < 4096/strlen($buffer_string); $i++ )
{
echo $buffer_string."\n";
}
?>
<?php
ob_end_flush();
if ( $export_file = exportEvents( $eid?$eid:$eids ) )
{
?>
<html>
<head>
<script type="text/javascript">
location.replace('<?= $export_file ?>');
</script>
</head>
</html>
<?php
}
else
{
ob_end_flush();
?>
<html>
<head>
<link rel="stylesheet" href="zm_html_styles.css" type="text/css">
</head>
<body>
<p class="head" align="center"><font color="red"><br><?= $zmSlangExportFailed ?><br></font></p>
<?php
}
}
else
{
ob_end_flush();
}
?>
</body>
</html>

View File

@@ -89,6 +89,7 @@ $zmSlangApply = 'Apply';
$zmSlangApplyingStateChange = 'Applying State Change';
$zmSlangArchArchived = 'Archived Only';
$zmSlangArchive = 'Archive';
$zmSlangArchived = 'Archived';
$zmSlangArchUnarchived = 'Unarchived Only';
$zmSlangAttrAlarmFrames = 'Alarm Frames';
$zmSlangAttrArchiveStatus = 'Archive Status';
@@ -218,6 +219,18 @@ $zmSlangEventName = 'Event Name';
$zmSlangEventPrefix = 'Event Prefix';
$zmSlangEvents = 'Events';
$zmSlangExclude = 'Exclude';
$zmSlangExport = 'Export';
$zmSlangExportOptions = 'Export Options';
$zmSlangExportDetails = 'Export Event Details';
$zmSlangExportFailed = 'Export Failed';
$zmSlangExportFormat = 'Export File Format';
$zmSlangExportFormatTar = 'Tar';
$zmSlangExportFormatZip = 'Zip';
$zmSlangExportFrames = 'Export Frame Details';
$zmSlangExportImageFiles = 'Export Image Files';
$zmSlangExporting = 'Exporting';
$zmSlangExportVideoFiles = 'Export Video Files (if present)';
$zmSlangExportMiscFiles = 'Export Other Files (if present)';
$zmSlangFar = 'Far';
$zmSlangFeed = 'Feed';
$zmSlangFilterPx = 'Filter Px';