3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Manage files in folder module instance
23 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../../config.php');
28 require_once("$CFG->dirroot/mod/folder/locallib.php");
29 require_once("$CFG->dirroot/mod/folder/edit_form.php");
30 require_once("$CFG->dirroot/repository/lib.php");
32 $id = required_param('id', PARAM_INT
); // Course module ID
34 $cm = get_coursemodule_from_id('folder', $id, 0, false, MUST_EXIST
);
35 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
, MUST_EXIST
);
36 $folder = $DB->get_record('folder', array('id'=>$cm->instance
), '*', MUST_EXIST
);
37 $course = $DB->get_record('course', array('id'=>$cm->course
), '*', MUST_EXIST
);
39 require_login($course, false, $cm);
40 require_capability('mod/folder:managefiles', $context);
42 add_to_log($course->id
, 'folder', 'edit', 'edit.php?id='.$cm->id
, $folder->id
, $cm->id
);
44 $PAGE->set_url('/mod/folder/edit.php', array('id' => $cm->id
));
45 $PAGE->set_title($course->shortname
.': '.$folder->name
);
46 $PAGE->set_heading($course->fullname
);
47 $PAGE->set_activity_record($folder);
49 $data = new stdClass();
51 $options = array('mainfile'=>true, 'subdirs'=>1, 'maxbytes'=>$CFG->maxbytes
, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL
);
52 file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_folder', 'content', 0);
54 $mform = new mod_folder_edit_form(null, array('data'=>$data, 'options'=>$options));
56 if ($mform->is_cancelled()) {
57 redirect(new moodle_url('/mod/folder/view.php', array('id'=>$cm->id
)));
59 } else if ($formdata = $mform->get_data()) {
60 $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_folder', 'content', 0);
61 $DB->set_field('folder', 'revision', $folder->revision+
1, array('id'=>$folder->id
));
62 redirect(new moodle_url('/mod/folder/view.php', array('id'=>$cm->id
)));
65 echo $OUTPUT->header();
66 echo $OUTPUT->box_start('generalbox foldertree');
68 echo $OUTPUT->box_end();
69 echo $OUTPUT->footer();