diff --git a/web/ajax/modals/download.php b/web/ajax/modals/download.php new file mode 100644 index 000000000..4f19abc0f --- /dev/null +++ b/web/ajax/modals/download.php @@ -0,0 +1,119 @@ +'.PHP_EOL; + + $Event = new ZM\Event($eid); + if ( !$Event->Id() ) { + ZM\Error('Invalid event id'); + $result .= '
Invalid event id
'.PHP_EOL; + } else { + $result .= 'Downloading event ' . $Event->Id . '. Resulting file should be approximately ' . human_filesize( $Event->DiskSpace() ).PHP_EOL; + } + } else if ( !empty($eids) ) { + $total_size = 0; + foreach ( $eids as $eid ) { + if ( !validInt($eid) ) { + ZM\Warning("Invalid event id in eids[] $eid"); + continue; + } + $Event = new ZM\Event($eid); + $total_size += $Event->DiskSpace(); + $result .= ''.PHP_EOL; + } + unset($eid); + $result .= 'Downloading ' . count($eids) . ' events. Resulting file should be approximately ' . human_filesize($total_size).PHP_EOL; + } else { + $result .= '
There are no events found. Resulting download will be empty.
'; + } + + return $result; +} + +if ( !canView('Events') ) { + $view = 'error'; + return; +} + +$eid = isset($_REQUEST['eid']) ? $_REQUEST['eid'] : ''; +$eids = isset($_REQUEST['eids']) ? $_REQUEST['eids'] : array(); +$generated = isset($_REQUEST['generated']) ? $_REQUEST['generated'] : ''; + +$total_size = 0; +if ( isset($_SESSION['montageReviewFilter']) and !$eids ) { + # Handles montageReview filter + $eventsSql = 'SELECT E.Id, E.DiskSpace FROM Events AS E WHERE 1'; + $eventsSql .= $_SESSION['montageReviewFilter']['sql']; + $results = dbQuery($eventsSql); + while ( $event_row = dbFetchNext( $results ) ) { + array_push($eids, $event_row['Id']); + $total_size += $event_row['DiskSpace']; + } + if ( ! count($eids) ) { + ZM\Error("No events found for download using $eventsSql"); + } + #session_start(); + #unset($_SESSION['montageReviewFilter']); + #session_write_close(); +#} else { +#Logger::Debug("NO montageReviewFilter"); +} + +$exportFormat = ''; +if ( isset($_REQUEST['exportFormat']) ) { + if ( !in_array($_REQUEST['exportFormat'], array('zip', 'tar')) ) { + ZM\Error('Invalid exportFormat: '.$_REQUEST['exportFormat']); + } else { + $exportFormat = $_REQUEST['exportFormat']; + } +} + +$focusWindow = true; +$connkey = isset($_REQUEST['connkey']) ? validInt($_REQUEST['connkey']) : generateConnKey(); + +?> + diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index dc45f32fe..cb95becf3 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -924,4 +924,34 @@ function human_filesize(size, precision = 2) { return (Math.round(size*(10^precision))/(10^precision))+units[i]; } +function startDownload( exportFile ) { + console.log("Starting download from " + exportFile); + window.location.replace( exportFile ); +} +function exportResponse(data, responseText) { + console.log(data); + + var generated = (data.result=='Ok') ? 1 : 0; + var exportFile = '?view=archive&type='+data.exportFormat+'&connkey='+data.connkey; + + $j('#exportProgress').removeClass( 'text-warning' ); + if ( generated ) { + $j('#downloadLink').text('Download'); + $j('#downloadLink').attr("href", thisUrl + exportFile); + $j('#exportProgress').addClass( 'text-success' ); + $j('#exportProgress').text(exportSucceededString); + startDownload.pass( exportFile ).delay( 1500 ); + } else { + $j('#exportProgress').addClass( 'text-danger' ); + $j('#exportProgress').text(exportFailedString); + } +} + +function exportEvent() { + var form = $j('#downloadForm').serialize(); + $j.getJSON(thisUrl + '?view=request&request=event&action=download', form) + .done(exportResponse) + .fail(logAjaxFail); + $j('#exportProgress').removeClass( 'invisible' ); +} diff --git a/web/skins/classic/js/skin.js.php b/web/skins/classic/js/skin.js.php index 08ed2d57d..9bf0cda6f 100644 --- a/web/skins/classic/js/skin.js.php +++ b/web/skins/classic/js/skin.js.php @@ -25,10 +25,12 @@ ?> var AJAX_TIMEOUT = ; - var navBarRefresh = ; - var currentView = ''; + +var exportProgressString = ''; +var exportFailedString = ''; +var exportSucceededString = ''; '.PHP_EOL; - - $Event = new ZM\Event($eid); - if ( !$Event->Id() ) { - ZM\Error('Invalid event id'); - $result .= '
Invalid event id
'.PHP_EOL; - } else { - $result .= 'Downloading event ' . $Event->Id . '. Resulting file should be approximately ' . human_filesize( $Event->DiskSpace() ).PHP_EOL; - } - } else if ( !empty($eids) ) { - $total_size = 0; - foreach ( $eids as $eid ) { - if ( !validInt($eid) ) { - ZM\Warning("Invalid event id in eids[] $eid"); - continue; - } - $Event = new ZM\Event($eid); - $total_size += $Event->DiskSpace(); - $result .= ''.PHP_EOL; - } - unset($eid); - $result .= 'Downloading ' . count($eids) . ' events. Resulting file should be approximately ' . human_filesize($total_size).PHP_EOL; - } else { - $result .= '
There are no events found. Resulting download will be empty.
'; - } - - return $result; -} - -function getGeneratedHTML($generated, $exportFormat) { - $result = ''; - - if ( $generated == '' ) { - $result .= ''.PHP_EOL; - } else { - $result .= '

'.PHP_EOL; - $result .= '' .($generated ? translate('ExportSucceeded') : translate('ExportFailed')). ''.PHP_EOL; - $result .= ''.PHP_EOL; - $result .= '

'.PHP_EOL; - } - if ( $generated ) { - $result .= ''.PHP_EOL; - } - - return $result; -} - -if ( !canView('Events') ) { - $view = 'error'; - return; -} - -$eid = isset($_REQUEST['eid']) ? $_REQUEST['eid'] : ''; -$eids = isset($_REQUEST['eids']) ? $_REQUEST['eids'] : array(); -$generated = isset($_REQUEST['generated']) ? $_REQUEST['generated'] : ''; - -$total_size = 0; -if ( isset($_SESSION['montageReviewFilter']) and !$eids ) { - # Handles montageReview filter - $eventsSql = 'SELECT E.Id, E.DiskSpace FROM Events AS E WHERE 1'; - $eventsSql .= $_SESSION['montageReviewFilter']['sql']; - $results = dbQuery($eventsSql); - while ( $event_row = dbFetchNext( $results ) ) { - array_push($eids, $event_row['Id']); - $total_size += $event_row['DiskSpace']; - } - if ( ! count($eids) ) { - ZM\Error("No events found for download using $eventsSql"); - } - #session_start(); - #unset($_SESSION['montageReviewFilter']); - #session_write_close(); -#} else { -#Logger::Debug("NO montageReviewFilter"); -} - -$exportFormat = ''; -if ( isset($_REQUEST['exportFormat']) ) { - if ( !in_array($_REQUEST['exportFormat'], array('zip', 'tar')) ) { - ZM\Error('Invalid exportFormat: '.$_REQUEST['exportFormat']); - } else { - $exportFormat = $_REQUEST['exportFormat']; - } -} - -$focusWindow = true; -$connkey = isset($_REQUEST['connkey']) ? validInt($_REQUEST['connkey']) : generateConnKey(); - -xhtmlHeaders(__FILE__, translate('Download')); -?> - -
- -
-
- - - - - - - - - - - - -
- - - - -
- -
-
- -
- diff --git a/web/skins/classic/views/js/download.js b/web/skins/classic/views/js/download.js deleted file mode 100644 index 5ad145083..000000000 --- a/web/skins/classic/views/js/download.js +++ /dev/null @@ -1,63 +0,0 @@ -function configureExportButton( element ) { - var form = element.form; - - var radioCount = 0; - for ( var i = 0, len=form.elements.length; i < len; i++ ) { - if ( form.elements[i].type == "radio" && form.elements[i].checked ) { - radioCount++; - } - } - form.elements['exportButton'].disabled = (radioCount == 0); -} - -function startDownload( exportFile ) { - console.log("Starting download from " + exportFile); - window.location.replace( exportFile ); -} - -var exportTimer = null; - -function exportProgress() { - var tickerText = $j('#exportProgressTicker').text(); - if ( tickerText.length < 1 || tickerText.length > 4 ) { - $j('#exportProgressTicker').text( '.' ); - } else { - $j('#exportProgressTicker').append( '.' ); - } -} - -function exportResponse(respObj, respText) { - console.log(respObj); - - var fullUrl = thisUrl+'?view='+currentView+'&'+eidParm+ - '&exportFormat='+respObj.exportFormat+ - '&exportFile='+respObj.exportFile+ - '&generated='+((respObj.result=='Ok')?1:0)+ - '&connkey='+connkey; - - console.log('The full url is: ' + fullUrl); - window.location.replace(fullUrl); -} - -function exportEvent() { - var form = $j('#contentForm').serialize(); - $j.getJSON(thisUrl + '?view=request&request=event&action=download', form) - .done(exportResponse) - .fail(logAjaxFail); - $j('#exportProgress').removeClass( 'hidden' ); - $j('#exportProgress').addClass( 'warnText' ); - $j('#exportProgressText').text( exportProgressString ); - exportProgress(); - exportTimer = exportProgress.periodical( 500 ); -} - -function initPage() { - if ( exportReady ) { - startDownload.pass( exportFile ).delay( 1500 ); - } - document.getElementById('exportButton').addEventListener("click", exportEvent ); -} - -$j(document).ready(function() { - initPage(); -}); diff --git a/web/skins/classic/views/js/download.js.php b/web/skins/classic/views/js/download.js.php deleted file mode 100644 index 390c9d17f..000000000 --- a/web/skins/classic/views/js/download.js.php +++ /dev/null @@ -1,23 +0,0 @@ - -var eidParm = ''; - -var eidParm = 'eid='; - - -var exportReady = ; -var exportFile = '?view=archive&type=&connkey='; -var connkey = ''; - -var exportProgressString = ''; diff --git a/web/skins/classic/views/js/events.js b/web/skins/classic/views/js/events.js index 68870060b..c826ad5f0 100644 --- a/web/skins/classic/views/js/events.js +++ b/web/skins/classic/views/js/events.js @@ -240,7 +240,18 @@ function initPage() { var selections = getIdSelections(); evt.preventDefault(); - createPopup('?view=download&eids[]='+selections.join('&eids[]='), 'zmDownload', 'download'); + $j.getJSON(thisUrl + '?request=modal&modal=download&eids[]='+selections.join('&eids[]=')) + .done(function(data) { + if ( $j('#downloadModal').length ) { + $j('#downloadModal').replaceWith(data.html); + } else { + $j("body").append(data.html); + } + $j('#downloadModal').modal('show'); + // Manage the GENERATE DOWNLOAD button + $j('#exportButton').click(exportEvent); + }) + .fail(logAjaxFail); }); // Manage the DELETE button