MDL-14627 new mod/folder:view capability
[moodle.git] / mod / folder / view.php
CommitLineData
0e16b939 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 * Folder module main user interface
20 *
9fe1fbcc
PS
21 * @package mod
22 * @subpackage folder
23 * @copyright 2009 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0e16b939 25 */
26
27require('../../config.php');
28require_once("$CFG->dirroot/mod/folder/locallib.php");
64f93798 29require_once("$CFG->dirroot/repository/lib.php");
33c36cf1 30require_once($CFG->libdir . '/completionlib.php');
0e16b939 31
32$id = optional_param('id', 0, PARAM_INT); // Course module ID
33$f = optional_param('f', 0, PARAM_INT); // Folder instance id
34
35if ($f) { // Two ways to specify the module
36 $folder = $DB->get_record('folder', array('id'=>$f), '*', MUST_EXIST);
37 $cm = get_coursemodule_from_instance('folder', $folder->id, $folder->course, false, MUST_EXIST);
38
39} else {
40 $cm = get_coursemodule_from_id('folder', $id, 0, false, MUST_EXIST);
41 $folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST);
42}
43
44$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
45
46require_course_login($course, true, $cm);
47$context = get_context_instance(CONTEXT_MODULE, $cm->id);
9093de63 48require_capability('mod/folder:view', $context);
0e16b939 49
50add_to_log($course->id, 'folder', 'view', 'view.php?id='.$cm->id, $folder->id, $cm->id);
51
c15a60e6
SM
52// Update 'viewed' state if required by completion system
53$completion = new completion_info($course);
54$completion->set_module_viewed($cm);
55
a6855934 56$PAGE->set_url('/mod/folder/view.php', array('id' => $cm->id));
0e16b939 57
58$PAGE->set_title($course->shortname.': '.$folder->name);
59$PAGE->set_heading($course->fullname);
60$PAGE->set_activity_record($folder);
0e16b939 61
64f93798
PS
62
63$output = $PAGE->get_renderer('mod_folder');
64
65echo $output->header();
66
67echo $output->heading(format_string($folder->name), 2);
0e16b939 68
69if (trim(strip_tags($folder->intro))) {
64f93798 70 echo $output->box_start('mod_introbox', 'pageintro');
0e16b939 71 echo format_module_intro('folder', $folder, $cm->id);
64f93798 72 echo $output->box_end();
0e16b939 73}
74
64f93798
PS
75echo $output->box_start('generalbox foldertree');
76echo $output->folder_tree($folder, $cm, $course);
77echo $output->box_end();
c84cea17 78
a2580005 79if (has_capability('mod/folder:managefiles', $context)) {
64f93798
PS
80 echo $output->container_start('mdl-align');
81 echo $output->single_button(new moodle_url('/mod/folder/edit.php', array('id'=>$id)), get_string('edit'));
82 echo $output->container_end();
3ebb42ae 83}
c84cea17 84
64f93798 85echo $output->footer();