diff --git a/lang/en_utf8/portfolio.php b/lang/en_utf8/portfolio.php index ef830e3c8f3..8054b5ce493 100644 --- a/lang/en_utf8/portfolio.php +++ b/lang/en_utf8/portfolio.php @@ -33,6 +33,8 @@ $string['exportqueued'] = 'Portfolio export has been successfully queued for tra $string['exportqueuedforced'] = 'Portfolio export has been successfully queued for transfer (the remote system has enforced queued transfers)'; $string['exportedpreviously'] = 'Previous exports'; $string['exportexceptionnoexporter'] = 'A portfolio_export_exception was thrown with an active session but no exporter object'; +$string['exportexpired'] = 'Portfolio export expired'; +$string['exportexpireddesc'] = 'You tried to repeat the export of some information, or start an empty export. To do that properly you should go back to the original location and start again. This sometimes happens if you use the back button after an export has completed, or by bookmarking an invalid url.'; $string['failedtosendpackage'] = 'Failed to send your data to the selected portfolio system: original error was $a'; $string['failedtopackage'] = 'Could not find files to package'; $string['filedenied'] = 'Access denied to this file'; diff --git a/lib/portfolio/exporter.php b/lib/portfolio/exporter.php index 56ef62290f2..d7663874c9f 100644 --- a/lib/portfolio/exporter.php +++ b/lib/portfolio/exporter.php @@ -760,6 +760,19 @@ class portfolio_exporter { ); } + /** wrapper function to print a friendly error to users + * + * this is generally caused by them hitting an expired transfer + * through the usage of the backbutton + */ + public static function print_expired_export() { + $title = get_string('exportexpired', 'portfolio'); + print_header($title, $title); + notify(get_string('exportexpireddesc', 'portfolio')); + print_footer(); + exit; + } + } ?> diff --git a/portfolio/add.php b/portfolio/add.php index 32116e84cc4..65769de693c 100644 --- a/portfolio/add.php +++ b/portfolio/add.php @@ -29,7 +29,7 @@ if ($dataid) { unset($SESSION->portfolioexport); redirect($CFG->wwwroot); } else { - throw $e; + portfolio_exporter::print_expired_export(); } } if ($cancel) { @@ -53,6 +53,10 @@ if ($dataid) { } } } else { + + if (empty($_GET) && empty($_POST)) { + portfolio_exporter::print_expired_export(); + } // we'e just posted here for the first time and have might the instance already if ($instance = optional_param('instance', 0, PARAM_INT)) { // this can throw exceptions but there's no point catching and rethrowing here @@ -66,8 +70,12 @@ if ($dataid) { $instance = null; } - $callbackfile = required_param('callbackfile', PARAM_PATH); - $callbackclass = required_param('callbackclass', PARAM_ALPHAEXT); + $callbackfile = optional_param('callbackfile', null, PARAM_PATH); + $callbackclass = optional_param('callbackclass', null, PARAM_ALPHAEXT); + + if (empty($callbackfile) || empty($callbackclass)) { + portfolio_exporter::print_expired_export(); + } $callbackargs = array(); foreach (array_keys(array_merge($_GET, $_POST)) as $key) {