Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       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      $DB->set_field('folder', 'revision', $folder->revision+1, array('id'=>$folder->id));
      65  
      66      // Update the variable of the folder revision so we can pass it as an accurate snapshot later.
      67      $folder->revision = $folder->revision + 1;
      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();
    

    Search This Site: