Add download video option to events view

Creates a new popup window for downloading event video files with no directory structure in the archive
This commit is contained in:
digital-gnome 2017-12-03 14:04:33 -05:00
parent 7a188a84f7
commit 3e7c573da5
9 changed files with 209 additions and 4 deletions

View File

@ -76,6 +76,19 @@ if ( canView( 'Events' ) ) {
ajaxError( 'Export Failed' );
break;
}
case 'download' :
{
require_once( ZM_SKIN_PATH.'/includes/export_functions.php' );
$exportVideo = 1;
$exportFormat = $_REQUEST['exportFormat'];
$exportStructure = 'flat';
$exportIds = !empty($_REQUEST['eids'])?$_REQUEST['eids']:$_REQUEST['id'];
if ( $exportFile = exportEvents( $exportIds, false, false, false, $exportVideo, false, $exportFormat, $exportStructure ) )
ajaxResponse( array( 'exportFile'=>$exportFile ) );
else
ajaxError( 'Export Failed' );
break;
}
}
}

View File

@ -322,6 +322,8 @@ $SLANG = array(
'ExportDetails' => 'Export Event Details',
'Exif' => 'Embed EXIF data into image',
'Export' => 'Export',
'DownloadVideo' => 'Download Video',
'GenerateDownload' => 'Generate Download',
'ExportFailed' => 'Export Failed',
'ExportFormat' => 'Export File Format',
'ExportFormatTar' => 'Tar',

View File

@ -853,7 +853,7 @@ function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exp
return( array_values( $exportFileList ) );
}
function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc, $exportFormat )
function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc, $exportFormat, $exportStructure = false )
{
if ( canView( 'Events' ) && !empty($eids) )
@ -907,8 +907,12 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
{
$archive = ZM_DIR_EXPORTS."/".$export_root.".tar.gz";
@unlink( $archive );
$command = "tar --create --gzip --file=$archive --files-from=$listFile";
exec( escapeshellcmd( $command ), $output, $status );
if ($exportStructure == 'flat') { //strip file paths if we choose
$command = "tar --create --gzip --file=".escapeshellarg($archive)." --files-from=".escapeshellarg($listFile)." --xform='s#^.+/##x'";
} else {
$command = "tar --create --gzip --file=".escapeshellarg($archive)." --files-from=".escapeshellarg($listFile);
}
exec( $command, $output, $status );
if ( $status )
{
Error( "Command '$command' returned with status $status" );
@ -921,7 +925,11 @@ function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $expo
{
$archive = ZM_DIR_EXPORTS."/".$export_root.".zip";
@unlink( $archive );
$command = "cat ".escapeshellarg($listFile)." | zip -q ".escapeshellarg($archive)." -@";
if ($exportStructure == 'flat') {
$command = "cat ".escapeshellarg($listFile)." | zip -q -j ".escapeshellarg($archive)." -@";
} else {
$command = "cat ".escapeshellarg($listFile)." | zip -q ".escapeshellarg($archive)." -@";
}
//cat zmFileList.txt | zip -q zm_export.zip -@
//-bash: zip: command not found

View File

@ -33,6 +33,7 @@ var popupSizes = {
'device': { 'width': 260, 'height': 150 },
'devices': { 'width': 400, 'height': 240 },
'donate': { 'width': 500, 'height': 280 },
'download': { 'width': 350, 'height': 215 },
'event': { 'addWidth': 108, 'minWidth': 496, 'addHeight': 230, 'minHeight': 540 },
'eventdetail': { 'width': 600, 'height': 420 },
'events': { 'width': 1220, 'height': 780 },

View File

@ -0,0 +1,109 @@
<?php
//
// ZoneMinder web export view file, $Date$, $Revision$
// Copyright (C) 2001-2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
if ( !canView( 'Events' ) ) {
$view = 'error';
return;
}
if (isset($_REQUEST['filter'])) { //Handles montageReview filter
$eventsSql = 'SELECT E.Id FROM Events as E WHERE 1';
parseFilter($_REQUEST['filter']);
$eventsSql .= $_REQUEST['filter']['sql'];
$results = dbQuery($eventsSql);
$eids = [];
while ( $event_row = dbFetchNext( $results ) ) {
array_push($eids, 'eids[]='.$event_row['Id']);
}
$_REQUEST['eids'] = $eids;
}
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('Download') );
?>
<body>
<div id="page">
<div id="header">
<div id="headerButtons">
<a href="#" onclick="closeWindow()"><?php echo translate('Close') ?></a>
</div>
<h2><?php echo translate('Download') ?></h2>
</div>
<div id="content">
<form name="contentForm" id="contentForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<?php
if ( !empty($_REQUEST['eid']) )
{
?>
<input type="hidden" name="id" value="<?php echo validInt($_REQUEST['eid']) ?>"/>
<?php
}
elseif ( !empty($_REQUEST['eids']) )
{
foreach ( $_REQUEST['eids'] as $eid )
{
?>
<input type="hidden" name="eids[]" value="<?php echo validInt($eid) ?>"/>
<?php
}
unset( $eid );
}
?>
<table id="contentTable" class="minor" cellspacing="0">
<tbody>
<tr>
<td><input type="hidden" name="exportVideo" value="1"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('ExportFormat') ?></th>
<td>
<input type="radio" id="exportFormatTar" name="exportFormat" value="tar" onclick="configureExportButton( this )"/><label for="exportFormatTar"><?php echo translate('ExportFormatTar') ?></label>
<input type="radio" id="exportFormatZip" name="exportFormat" value="zip" checked="checked" onclick="configureExportButton( this )"/><label for="exportFormatZip"><?php echo translate('ExportFormatZip') ?></label>
</td>
</tr>
</tbody>
</table>
<input type="button" id="exportButton" name="exportButton" value="<?php echo translate('GenerateDownload') ?>" onclick="exportEvent( this.form );" />
</form>
</div>
<?php
if ( isset($_REQUEST['generated']) )
{
?>
<h2 id="exportProgress" class="<?php echo $_REQUEST['generated']?'infoText':'errorText' ?>"><span id="exportProgressText"><?php echo $_REQUEST['generated']?translate('ExportSucceeded'):translate('ExportFailed') ?></span><span id="exportProgressTicker"></span></h2>
<?php
}
else
{
?>
<h2 id="exportProgress" class="hidden warnText"><span id="exportProgressText"><?php echo translate('Exporting') ?></span><span id="exportProgressTicker"></span></h2>
<?php
}
if ( !empty($_REQUEST['generated']) )
{
?>
<h3 id="downloadLink"><a href="<?php echo validHtmlStr($_REQUEST['exportFile']) ?>"><?php echo translate('Download') ?></a></h3>
<?php
}
?>
</div>
</body>
</html>

View File

@ -269,6 +269,7 @@ if ( true || canEdit( 'Events' ) ) {
<input type="button" name="unarchiveBtn" value="<?php echo translate('Unarchive') ?>" onclick="unarchiveEvents( this, 'markEids' );" disabled="disabled"/>
<input type="button" name="editBtn" value="<?php echo translate('Edit') ?>" onclick="editEvents( this, 'markEids' )" disabled="disabled"/>
<input type="button" name="exportBtn" value="<?php echo translate('Export') ?>" onclick="exportEvents( this, 'markEids' )" disabled="disabled"/>
<input type="button" name="downloadBtn" value="<?php echo translate('DownloadVideo') ?>" onclick="downloadVideo( this, 'markEids' )" disabled="disabled"/>
<input type="button" name="deleteBtn" value="<?php echo translate('Delete') ?>" onclick="deleteEvents( this, 'markEids' );" disabled="disabled"/>
</div>
<?php

View File

@ -0,0 +1,37 @@
function startDownload( exportFile ) {
window.location.replace( exportFile );
}
var exportTimer = null;
function exportProgress() {
var tickerText = $('exportProgressTicker').get('text');
if ( tickerText.length < 1 || tickerText.length > 4 )
$('exportProgressTicker').set( 'text', '.' );
else
$('exportProgressTicker').appendText( '.' );
}
function exportResponse( respObj, respText ) {
window.location.replace( thisUrl+'?view='+currentView+'&'+eidParm+'&exportFile='+respObj.exportFile+'&generated='+((respObj.result=='Ok')?1:0) );
}
function exportEvent( form ) {
var parms = 'view=request&request=event&action=download';
parms += '&'+$(form).toQueryString();
var query = new Request.JSON( { url: thisUrl, method: 'post', data: parms, onSuccess: exportResponse } );
query.send();
$('exportProgress').removeClass( 'hidden' );
$('exportProgress').setProperty( 'class', 'warnText' );
$('exportProgressText').set( 'text', exportProgressString );
exportProgress();
exportTimer = exportProgress.periodical( 500 );
}
function initPage() {
if ( exportReady ) {
startDownload.pass( exportFile ).delay( 1500 );
}
}
window.addEvent( 'domready', initPage );

View File

@ -0,0 +1,19 @@
<?php
if ( isset($_REQUEST['eids']) ) {
$eidParms = array();
foreach ( $_REQUEST['eids'] as $eid )
$eidParms[] = "eids[]=".validInt($eid);
?>
var eidParm = '<?php echo join( '&', $eidParms ) ?>';
<?php
} else if (isset($_REQUEST['eid'])) {
?>
var eidParm = 'eid=<?php echo validInt($_REQUEST['eid']) ?>';
<?php
}
?>
var exportReady = <?php echo !empty($_REQUEST['generated'])?'true':'false' ?>;
var exportFile = '<?php echo !empty($_REQUEST['exportFile'])?validJsStr($_REQUEST['exportFile']):'' ?>';
var exportProgressString = '<?php echo addslashes(translate('Exporting')) ?>';

View File

@ -15,6 +15,7 @@ function toggleCheckbox( element, name ) {
form.editBtn.disabled = !checked;
form.archiveBtn.disabled = unarchivedEvents?!checked:true;
form.unarchiveBtn.disabled = archivedEvents?!checked:true;
form.downloadBtn.disabled = !checked;
form.exportBtn.disabled = !checked;
form.deleteBtn.disabled = !checked;
}
@ -38,6 +39,7 @@ function configureButton( element, name ) {
form.editBtn.disabled = !checked;
form.archiveBtn.disabled = (!checked)||(!unarchivedEvents);
form.unarchiveBtn.disabled = (!checked)||(!archivedEvents);
form.downloadBtn.disabled = !checked;
form.exportBtn.disabled = !checked;
form.deleteBtn.disabled = !checked;
}
@ -74,6 +76,19 @@ function editEvents( element, name ) {
createPopup( '?view=eventdetail&'+eids.join( '&' ), 'zmEventDetail', 'eventdetail' );
}
function downloadVideo( element, name ) {
var form = element.form;
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;
}
}
}
createPopup( '?view=download&'+eids.join( '&' ), 'zmDownload', 'download' );
}
function exportEvents( element, name ) {
var form = element.form;
var eids = new Array();