MDL-22764, added capability check on view.php, edit.php requires managefiles capabili...
[moodle.git] / mod / folder / edit.php
CommitLineData
c84cea17
DC
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
26require('../../config.php');
27require_once("$CFG->dirroot/mod/folder/locallib.php");
28require_once("$CFG->dirroot/mod/folder/edit_form.php");
29require_once("$CFG->dirroot/repository/lib.php");
30
df911361 31$id = required_param('id', PARAM_INT); // Course module ID
c84cea17
DC
32
33$cm = get_coursemodule_from_id('folder', $id, 0, false, MUST_EXIST);
3ebb42ae 34$context = get_context_instance(CONTEXT_MODULE, $cm->id);
c84cea17 35$folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST);
c84cea17
DC
36$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
37
3ebb42ae
DC
38require_login($course, true, $cm);
39require_capability('moodle/course:managefiles', $context);
c84cea17
DC
40
41add_to_log($course->id, 'folder', 'edit', 'edit.php?id='.$cm->id, $folder->id, $cm->id);
42
43$data = new stdclass;
44$data->id = $cm->id;
45
46$options = array('subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
47
48$PAGE->set_url('/mod/folder/edit.php', array('id' => $cm->id));
49
50$PAGE->set_title($course->shortname.': '.$folder->name);
51$PAGE->set_heading($course->fullname);
52$PAGE->set_activity_record($folder);
53
54
55$form = new mod_folder_edit_form(null, array('id'=>$cm->id));
56
57if ($formdata = $form->get_data()) {
58 $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'folder_content', 0);
59 redirect(new moodle_url('/mod/folder/view.php', array('id'=>$cm->id)));
60} else {
61 file_prepare_standard_filemanager($data, 'files', $options, $context, 'folder_content', 0);
62 $form->set_data($data);
63 echo $OUTPUT->header();
64 echo $OUTPUT->box_start('generalbox foldertree');
65 $form->display();
66 echo $OUTPUT->box_end();
67 echo $OUTPUT->footer();
68}