Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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 files in folder module instance
  20   *
  21   * @package   mod_folder
  22   * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require('../../config.php');
  27  require_once("$CFG->dirroot/mod/folder/locallib.php");
  28  require_once("$CFG->dirroot/mod/folder/edit_form.php");
  29  require_once("$CFG->dirroot/repository/lib.php");
  30  
  31  $id = required_param('id', PARAM_INT);  // Course module ID
  32  
  33  $cm = get_coursemodule_from_id('folder', $id, 0, true, MUST_EXIST);
  34  $context = context_module::instance($cm->id, MUST_EXIST);
  35  $folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST);
  36  $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
  37  
  38  require_login($course, false, $cm);
  39  require_capability('mod/folder:managefiles', $context);
  40  
  41  $PAGE->set_url('/mod/folder/edit.php', array('id' => $cm->id));
  42  $PAGE->set_title($course->shortname.': '.$folder->name);
  43  $PAGE->set_heading($course->fullname);
  44  $PAGE->set_activity_record($folder);
  45  
  46  $data = new stdClass();
  47  $data->id = $cm->id;
  48  $maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes);
  49  $options = array('subdirs' => 1, 'maxbytes' => $maxbytes, 'maxfiles' => -1, 'accepted_types' => '*');
  50  file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_folder', 'content', 0);
  51  
  52  $mform = new mod_folder_edit_form(null, array('data'=>$data, 'options'=>$options));
  53  if ($folder->display == FOLDER_DISPLAY_INLINE) {
  54      $redirecturl = course_get_url($cm->course, $cm->sectionnum);
  55  } else {
  56      $redirecturl = new moodle_url('/mod/folder/view.php', array('id' => $cm->id));
  57  }
  58  
  59  if ($mform->is_cancelled()) {
  60      redirect($redirecturl);
  61  
  62  } else if ($formdata = $mform->get_data()) {
  63      $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_folder', 'content', 0);
  64      $folder->timemodified = time();
  65      $folder->revision = $folder->revision + 1;
  66  
  67      $DB->update_record('folder', $folder);
  68  
  69      $params = array(
  70          'context' => $context,
  71          'objectid' => $folder->id
  72      );
  73      $event = \mod_folder\event\folder_updated::create($params);
  74      $event->add_record_snapshot('folder', $folder);
  75      $event->trigger();
  76  
  77      redirect($redirecturl);
  78  }
  79  
  80  echo $OUTPUT->header();
  81  echo $OUTPUT->heading(format_string($folder->name));
  82  echo $OUTPUT->box_start('generalbox foldertree');
  83  $mform->display();
  84  echo $OUTPUT->box_end();
  85  echo $OUTPUT->footer();