Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  
   3  // this script is a slightly more user friendly way to 'send' the file to them
   4  // (using portfolio/file.php) but still give them the 'return to where you were' link
   5  // to go back to their assignment, or whatever
   6  
   7  require(__DIR__.'/../../config.php');
   8  
   9  if (empty($CFG->enableportfolios)) {
  10      print_error('disabled', 'portfolio');
  11  }
  12  
  13  require_once($CFG->libdir.'/portfoliolib.php');
  14  require_once($CFG->libdir.'/portfolio/exporter.php');
  15  
  16  $id = required_param('id', PARAM_INT);
  17  
  18  $PAGE->set_url('/portfolio/download/file.php', array('id' => $id));
  19  
  20  $exporter = portfolio_exporter::rewaken_object($id);
  21  portfolio_export_pagesetup($PAGE, $exporter->get('caller'));
  22  $exporter->verify_rewaken();
  23  
  24  $exporter->print_header(get_string('downloading', 'portfolio_download'), false);
  25  $returnurl = $exporter->get('caller')->get_return_url();
  26  echo $OUTPUT->notification('<a href="' . $returnurl . '">' . get_string('returntowhereyouwere', 'portfolio') . '</a><br />');
  27  
  28  
  29  // if they don't have javascript, they can submit the form here to get the file.
  30  // if they do, it does it nicely for them.
  31  echo '<div id="redirect">
  32      <form action="' . $exporter->get('instance')->get_base_file_url() . '" method="post" id="redirectform">
  33        <input type="submit" value="' . get_string('downloadfile', 'portfolio_download') . '" />
  34      </form></div>
  35  ';
  36  
  37  $PAGE->requires->js_amd_inline("
  38  require(['jquery'], function($) {
  39      $('#redirectform').submit(function() {
  40          $('#redirect').addClass('hide');
  41      }).submit();
  42  });");
  43  echo $OUTPUT->footer();
  44  
  45