Commit 951b5936 authored by Nigel McNie's avatar Nigel McNie
Browse files

Export UI part 2: Progress bar for downloads.

Works without javascript! Using a sneaky iframe.

Untested on browsers other than ff3.

Even on small exports it seems to be needed, which could be worrying ;)

Also added a bunch of i18n for it.
parent b3b1a5ee
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage export
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
// Download the export file if it's been generated
if ($exportfile = $SESSION->get('exportfile')) {
$SESSION->set('exportdata', '');
$SESSION->set('exportfile', '');
require_once('file.php');
serve_file($exportfile, basename($exportfile), 'application/x-zip', array('lifetime' => 0));
exit;
}
if (!$exportdata = $SESSION->get('exportdata')) {
redirect('/export/');
}
$SESSION->set('exportdata', '');
?>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo theme_get_url('style/style.css'); ?>">
<style type="text/css">
html, body {
margin: 0;
padding: 0;
background-color: #808080;
}
</style>
</head>
<body>
<?php
/**
* Outputs enough HTML to make a pretty error message in the iframe
*
* @param string $message The message to display to the user
*/
function export_iframe_die($message) {
echo '<div class="progress-bar" style="width: 100%;"><p>' . hsc($message) . '</p></div></body></html>';
exit;
}
/**
* Registered as the progress report handler for the export. Streams updates
* back to the browser
*
* @param int $percent How far complete the export is
* @param string $status A human-readable string describing the current step
*/
function export_iframe_progress_handler($percent, $status) {
// "Erase" the current output with a new background div
echo '<div style="width: 100%; background-color: #808080;" class="progress-bar"></div>';
// The progress bar itself
echo '<div class="progress-bar" style="width: ' . intval($percent) . '%;"></div>' . "\n";
// The status text
echo '<p class="progress-text">' . hsc($status) . "</p>\n";
flush();
}
// Bail if we don't have enough data to do an export
if (!isset($exportdata['format'])
|| !isset($exportdata['what'])
|| !isset($exportdata['views'])) {
export_iframe_die(get_string('unabletogenerateexport', 'export'));
exit;
}
safe_require('export', $exportdata['format']);
$user = new User();
$user->find_by_id($USER->get('id'));
$class = generate_class_name('export', $exportdata['format']);
switch($exportdata['what']) {
case 'all':
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS, 'export_iframe_progress_handler');
break;
case 'views':
$exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS, 'export_iframe_progress_handler');
break;
default:
export_iframe_die(get_string('unabletoexportportfoliousingoptions', 'export'));
}
$zipfile = $exporter->export();
// Store the filename in the session, and redirect the iframe to it to trigger
// the download. Here it would be nice to trigger the download for everyone,
// but alas this is not possible for people without javascript.
$SESSION->set('exportfile', $exporter->get('exportdir') . $zipfile);
$wwwroot = get_config('wwwroot');
$strexportgeneratedsuccessfullyjs = get_string('exportgeneratedsuccessfullyjs', 'export', '<a href="' . $wwwroot . '" target="_top">', '</a>');
$strexportgeneratedsuccessfully = get_string('exportgeneratedsuccessfully', 'export', '<a href="download.php" target="_top">', '</a>');
?>
<script type="text/javascript">
document.write('<div class="progress-bar" style="width: 100%;"><p><?php echo $strexportgeneratedsuccessfullyjs; ?></p>');
document.location = 'download.php';
</script>
<div class="progress-bar" style="width: 100%;">
<p><?php echo $strexportgeneratedsuccessfully; ?></p>
</div>
</body>
</html>
......@@ -28,7 +28,9 @@ define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/export');
require(dirname(dirname(__FILE__)) . '/init.php');
define('TITLE', get_string('exportyourportfolio', 'export'));
require_once('file.php');
$SESSION->set('exportdata', '');
$SESSION->set('exportfile', '');
$exportoptions = array();
foreach (plugins_installed('export') as $plugin) {
......@@ -50,14 +52,14 @@ $elements = array(
'type' => 'radio',
'options' => array(
'all' => get_string('allmydata', 'export'),
'views' => get_string('justsomeviewsanddata', 'export'),
'views' => get_string('justsomeviews', 'export'),
),
'separator' => '</div><div>',
'defaultvalue' => 'all',
),
);
if ($viewids = get_column('view', 'id', 'owner', $USER->get('id'))) {
if ($viewids = get_column('view', 'id', 'owner', $USER->get('id'), 'type', 'portfolio')) {
foreach ($viewids as $viewid) {
$view = new View($viewid);
$elements['view_' . $viewid] = array(
......@@ -84,33 +86,24 @@ $form = pieform(array(
function export_submit(Pieform $form, $values) {
global $USER;
safe_require('export', $values['format']);
$user = new User();
$user->find_by_id($USER->get('id'));
$class = generate_class_name('export', $values['format']);
switch($values['what']) {
case 'all':
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS);
break;
case 'views':
$views = array();
foreach ($values as $key => $value) {
if (substr($key, 0, 5) == 'view_' && $value) {
$views[] = intval(substr($key, 5));
}
global $SESSION;
$views = array();
foreach ($values as $key => $value) {
if (substr($key, 0, 5) == 'view_' && $value) {
$views[] = intval(substr($key, 5));
}
$exporter = new $class($user, $views, PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS);
break;
default:
throw new SystemException("Unable to export a portfolio using those options");
}
$zipfile = $exporter->export();
serve_file($exporter->get('exportdir') . $zipfile, $zipfile, 'application/x-zip', array('lifetime' => 0));
$exportdata = array(
'format' => $values['format'],
'what' => $values['what'],
'views' => $views,
);
$SESSION->set('exportdata', $exportdata);
$smarty = smarty();
$smarty->assign('heading', '');
$smarty->display('export/export.tpl');
exit;
}
......
......@@ -30,9 +30,14 @@ $string['allmydata'] = 'All my data';
$string['chooseanexportformat'] = 'Choose an export format';
$string['clicktopreview'] = 'Click to preview';
$string['Export'] = 'Export';
$string['exportgeneratedsuccessfully'] = 'Export generated successfully. %sClick here to download it%s';
$string['exportgeneratedsuccessfullyjs'] = 'Export generated successfully. %sContinue%s';
$string['exportyourportfolio'] = 'Export Your Portfolio';
$string['generateexport'] = 'Generate export';
$string['justsomeviewsanddata'] = 'Just some views and their associated data';
$string['justsomeviews'] = 'Just some of my Views';
$string['pleasewaitwhileyourexportisbeinggenerated'] = 'Please wait while your export is being generated...';
$string['unabletoexportportfoliousingoptions'] = 'Unable to export a portfolio using the chosen options';
$string['unabletogenerateexport'] = 'Unable to generate export';
$string['viewstoexport'] = 'Views to export';
$string['whatdoyouwanttoexport'] = 'What do you want to export?';
......
......@@ -2730,6 +2730,42 @@ span.breadcrumbs a {
text-align: center;
}
#exportgeneration {
text-align: center;
}
#progress {
border: 2px solid #d0d0d0;
height: 40px;
width: 600px;
margin-top: 1em;
}
div.progress-bar {
position: absolute;
top: 0;
left: 0;
background-color: #7d9728;
height: 40px;
color: #fff;
text-align: center;
font-weight: bold;
}
div.progress-bar a {
color: #ffd;
text-decoration: underline;
}
p.progress-text {
position: fixed;
top: 0;
left: 0;
text-align: center;
color: #fff;
font-weight: bold;
width: 100%;
}
#progressbar {
height: 40px;
}
/* ADMIN HOME */
/* Administration Home styles */
......
{include file="header.tpl"}
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<div id="exportgeneration">
<h3>{str tag=pleasewaitwhileyourexportisbeinggenerated section=export}</h3>
<iframe src="{$WWWROOT}export/download.php" id="progress" scrolling="no"></iframe>
</div>
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment