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 * Moodle file tree viewer based on YUI2 Treeview 20 * 21 * @package core 22 * @subpackage file 23 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com> 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27require('../config.php'); 28 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'; 34$filearea = 'legacy'; 35$itemid = 0; 36 37if (empty($contextid)) { 38 $contextid = context_course::instance(SITEID)->id; 39} 40 41$PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'filepath'=>$filepath, 'filename'=>$filename)); 42navigation_node::override_active_url(new moodle_url('/files/index.php', array('contextid'=>$contextid))); 43 44if ($filepath === '') { 45 $filepath = null; 46} 47 48if ($filename === '') { 49 $filename = null; 50} 51 52list($context, $course, $cm) = get_context_info_array($contextid); 53$PAGE->set_context($context); 54 55require_login($course, false, $cm); 56require_capability('moodle/course:managefiles', $context); 57 58$browser = get_file_browser(); 59 60$file_info = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename); 61 62$strfiles = get_string("files"); 63if ($node = $PAGE->settingsnav->find('coursefiles', navigation_node::TYPE_SETTING)) { 64 $node->make_active(); 65} else { 66 $PAGE->navbar->add($strfiles); 67} 68 69$PAGE->set_title("$course->shortname: $strfiles"); 70$PAGE->set_heading($course->fullname); 71$PAGE->set_pagelayout('incourse'); 72 73$output = $PAGE->get_renderer('core', 'files'); 74 75echo $output->header(); 76echo $output->box_start(); 77 78if ($file_info) { 79 $options = array(); 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); 83} else { 84 echo $output->notification(get_string('nofilesavailable', 'repository')); 85} 86 87echo $output->box_end(); 88echo $output->footer(); 89