Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Manage backup files
  20   * @package   moodlecore
  21   * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once('../config.php');
  26  require_once (__DIR__ . '/backupfilesedit_form.php');
  27  require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
  28  require_once($CFG->dirroot . '/repository/lib.php');
  29  
  30  // current context
  31  $contextid = required_param('contextid', PARAM_INT);
  32  $currentcontext = required_param('currentcontext', PARAM_INT);
  33  // file parameters
  34  $component  = optional_param('component', null, PARAM_COMPONENT);
  35  $filearea   = optional_param('filearea', null, PARAM_AREA);
  36  $returnurl  = optional_param('returnurl', null, PARAM_LOCALURL);
  37  
  38  list($context, $course, $cm) = get_context_info_array($currentcontext);
  39  $filecontext = context::instance_by_id($contextid, IGNORE_MISSING);
  40  
  41  $url = new moodle_url('/backup/backupfilesedit.php', array('currentcontext'=>$currentcontext, 'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea));
  42  
  43  require_login($course, false, $cm);
  44  require_capability('moodle/restore:uploadfile', $context);
  45  if ($filearea == 'automated' && !can_download_from_backup_filearea($filearea, $context)) {
  46      throw new required_capability_exception($context, 'moodle/backup:downloadfile', 'nopermissions', '');
  47  }
  48  
  49  $PAGE->set_url($url);
  50  $PAGE->set_context($context);
  51  
  52  if ($context->contextlevel == CONTEXT_COURSECAT) {
  53      core_course_category::page_setup();
  54      $PAGE->set_secondary_active_tab('restorecourse');
  55  } else if ($context->contextlevel == CONTEXT_COURSE) {
  56      $course = get_course($context->instanceid);
  57      $PAGE->set_heading($course->fullname);
  58      $PAGE->set_secondary_active_tab('coursereuse');
  59  } else if ($context->contextlevel == CONTEXT_SYSTEM) {
  60      $PAGE->set_heading($SITE->fullname);
  61      $PAGE->set_primary_active_tab('siteadminnode');
  62      $PAGE->set_secondary_active_tab('courses');
  63  } else {
  64      $PAGE->set_heading($SITE->fullname);
  65  }
  66  // Set the restore course node active in the settings navigation block.
  67  navigation_node::override_active_url(new moodle_url('/backup/restorefile.php', ['contextid' => $contextid]));
  68  
  69  $title = get_string('managefiles', 'backup');
  70  $PAGE->navbar->add($title);
  71  $PAGE->set_title($title);
  72  $PAGE->set_pagelayout('admin');
  73  $browser = get_file_browser();
  74  
  75  $data = new stdClass();
  76  $options = array('subdirs'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
  77  file_prepare_standard_filemanager($data, 'files', $options, $filecontext, $component, $filearea, 0);
  78  $form = new backup_files_edit_form(null, array('data'=>$data, 'contextid'=>$contextid, 'currentcontext'=>$currentcontext, 'filearea'=>$filearea, 'component'=>$component, 'returnurl'=>$returnurl));
  79  
  80  if ($form->is_cancelled()) {
  81      redirect($returnurl);
  82  }
  83  
  84  $data = $form->get_data();
  85  if ($data) {
  86      $formdata = file_postupdate_standard_filemanager($data, 'files', $options, $filecontext, $component, $filearea, 0);
  87      redirect($returnurl);
  88  }
  89  
  90  echo $OUTPUT->header();
  91  
  92  echo $OUTPUT->container_start();
  93  echo $OUTPUT->heading($title);
  94  $form->display();
  95  echo $OUTPUT->container_end();
  96  
  97  echo $OUTPUT->footer();