Merge branch 'MDL-76207-39' of https://github.com/andrewnicols/moodle into MOODLE_39_...
[moodle.git] / mod / folder / edit.php
blobe4bb89b7702a098f0c90343ca7b338c0cfe54e7d
1 <?php
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.
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/>.
18 /**
19 * Manage files in folder module instance
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
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");
31 $id = required_param('id', PARAM_INT); // Course module ID
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);
38 require_login($course, false, $cm);
39 require_capability('mod/folder:managefiles', $context);
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);
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);
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));
59 if ($mform->is_cancelled()) {
60 redirect($redirecturl);
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;
67 $DB->update_record('folder', $folder);
69 $params = array(
70 'context' => $context,
71 'objectid' => $folder->id
73 $event = \mod_folder\event\folder_updated::create($params);
74 $event->add_record_snapshot('folder', $folder);
75 $event->trigger();
77 redirect($redirecturl);
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();