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 * Moodle file tree viewer based on YUI2 Treeview
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');
29 $contextid = optional_param('contextid', 0, PARAM_INT
);
30 $filepath = optional_param('filepath', '', PARAM_PATH
);
31 $filename = optional_param('filename', '', PARAM_FILE
);
32 // hard-coded to course legacy area
33 $component = 'course';
37 if (empty($contextid)) {
38 $contextid = context_course
::instance(SITEID
)->id
;
41 $PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'filepath'=>$filepath, 'filename'=>$filename));
42 navigation_node
::override_active_url(new moodle_url('/files/index.php', array('contextid'=>$contextid)));
44 if ($filepath === '') {
48 if ($filename === '') {
52 list($context, $course, $cm) = get_context_info_array($contextid);
53 $PAGE->set_context($context);
55 require_login($course, false, $cm);
56 require_capability('moodle/course:managefiles', $context);
58 $browser = get_file_browser();
60 $file_info = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
62 $strfiles = get_string("files");
63 if ($node = $PAGE->settingsnav
->find('coursefiles', navigation_node
::TYPE_SETTING
)) {
66 $PAGE->navbar
->add($strfiles);
69 $PAGE->set_title("$course->shortname: $strfiles");
70 $PAGE->set_heading($course->fullname
);
71 $PAGE->set_pagelayout('incourse');
73 $output = $PAGE->get_renderer('core', 'files');
75 echo $output->header();
76 echo $output->box_start();
80 $options['context'] = $context;
81 //$options['visible_areas'] = array('backup'=>array('section', 'course'), 'course'=>array('legacy'), 'user'=>array('backup'));
82 echo $output->files_tree_viewer($file_info, $options);
84 echo $output->notification(get_string('nofilesavailable', 'repository'));
87 echo $output->box_end();
88 echo $output->footer();