MDL-18011 - removing reference to loancalc block from core
[moodle.git] / files / index.php
CommitLineData
be19e367 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/**
fb2fb46e 19 * Moodle file tree viewer based on YUI2 Treeview
be19e367 20 *
21 * @package moodlecore
22 * @subpackage file
fb2fb46e 23 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
be19e367 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27require('../config.php');
be19e367 28
29$courseid = optional_param('id', 0, PARAM_INT);
30
31$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
32$filearea = optional_param('filearea', '', PARAM_ALPHAEXT);
33$itemid = optional_param('itemid', -1, PARAM_INT);
34$filepath = optional_param('filepath', '', PARAM_PATH);
35$filename = optional_param('filename', '', PARAM_FILE);
36
be19e367 37if ($courseid) {
1904e9b3
SH
38 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
39 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
49c8c8d2 40 redirect(new moodle_url('index.php', array('contextid' => $context->id, 'itemid'=> 0, 'filearea' => 'course_content')));
be19e367 41}
42
1904e9b3 43$context = get_context_instance_by_id($contextid, MUST_EXIST);
61ebef8f 44$PAGE->set_context($context);
1904e9b3
SH
45
46$course = null;
47$cm = null;
48if ($context->contextlevel == CONTEXT_MODULE) {
49 $cm = get_coursemodule_from_id(null, $context->instanceid, 0, false, MUST_EXIST);
50 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
51} else if ($context->contextlevel == CONTEXT_COURSE) {
52 $course = $DB->get_record('course', array('id'=>$context->instanceid), '*', MUST_EXIST);
be19e367 53}
f9903ed0 54
1904e9b3 55require_login($course, false, $cm);
be19e367 56require_capability('moodle/course:managefiles', $context);
f9903ed0 57
be19e367 58if ($filearea === '') {
59 $filearea = null;
60}
ad4e0fcc 61
be19e367 62if ($itemid < 0) {
63 $itemid = null;
64}
f9903ed0 65
be19e367 66if ($filepath === '') {
67 $filepath = null;
68}
fdfc6269 69
be19e367 70if ($filename === '') {
71 $filename = null;
72}
f9903ed0 73
be19e367 74$browser = get_file_browser();
1a11dfd1 75
be19e367 76$file_info = $browser->get_file_info($context, $filearea, $itemid, $filepath, $filename);
1a11dfd1 77
fb2fb46e
DC
78$strfiles = get_string("files");
79if ($context->contextlevel == CONTEXT_MODULE) {
80 $PAGE->set_pagelayout('incourse');
81} else if ($context->contextlevel == CONTEXT_COURSE) {
82 $PAGE->set_pagelayout('course');
83} else {
84 $PAGE->set_pagelayout('admin');
f9903ed0 85}
86
fb2fb46e
DC
87$PAGE->navbar->add($strfiles);
88$PAGE->set_url("/files/index.php", $file_info->get_params());
89$PAGE->set_title("$SITE->shortname: $strfiles");
90$PAGE->set_heading($SITE->fullname);
91echo $OUTPUT->header();
6b091c94 92
6eabadd9
DC
93$options = array();
94$options['enabled_fileareas'] = array('section_backup', 'course_backup', 'course_content', 'user_backup');
fb2fb46e 95echo $OUTPUT->box_start();
6eabadd9 96echo $OUTPUT->moodle_file_tree_viewer($context->id, $filearea, $itemid, $filepath, $options);
fb2fb46e 97echo $OUTPUT->box_end();
70cedbfd 98
fb2fb46e 99echo $OUTPUT->footer();