Merge branch '42316-26' of git://github.com/samhemelryk/moodle
[moodle.git] / mod / folder / index.php
blobdc987df9bfb451e8c28aac0c585f65c00c8266af
1 <?php
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.
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/>.
18 /**
19 * List of file folders in course
21 * @package mod
22 * @subpackage folder
23 * @copyright 2009 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../../config.php');
29 $id = required_param('id', PARAM_INT); // course id
31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
33 require_course_login($course, true);
34 $PAGE->set_pagelayout('incourse');
36 add_to_log($course->id, 'folder', 'view all', "index.php?id=$course->id", '');
38 $strfolder = get_string('modulename', 'folder');
39 $strfolders = get_string('modulenameplural', 'folder');
40 $strsectionname = get_string('sectionname', 'format_'.$course->format);
41 $strname = get_string('name');
42 $strintro = get_string('moduleintro');
43 $strlastmodified = get_string('lastmodified');
45 $PAGE->set_url('/mod/folder/index.php', array('id' => $course->id));
46 $PAGE->set_title($course->shortname.': '.$strfolders);
47 $PAGE->set_heading($course->fullname);
48 $PAGE->navbar->add($strfolders);
49 echo $OUTPUT->header();
50 echo $OUTPUT->heading($strfolders);
52 if (!$folders = get_all_instances_in_course('folder', $course)) {
53 notice(get_string('thereareno', 'moodle', $strfolders), "$CFG->wwwroot/course/view.php?id=$course->id");
54 exit;
57 $usesections = course_format_uses_sections($course->format);
59 $table = new html_table();
60 $table->attributes['class'] = 'generaltable mod_index';
62 if ($usesections) {
63 $table->head = array ($strsectionname, $strname, $strintro);
64 $table->align = array ('center', 'left', 'left');
65 } else {
66 $table->head = array ($strlastmodified, $strname, $strintro);
67 $table->align = array ('left', 'left', 'left');
70 $modinfo = get_fast_modinfo($course);
71 $currentsection = '';
72 foreach ($folders as $folder) {
73 $cm = $modinfo->cms[$folder->coursemodule];
74 if ($usesections) {
75 $printsection = '';
76 if ($folder->section !== $currentsection) {
77 if ($folder->section) {
78 $printsection = get_section_name($course, $folder->section);
80 if ($currentsection !== '') {
81 $table->data[] = 'hr';
83 $currentsection = $folder->section;
85 } else {
86 $printsection = '<span class="smallinfo">'.userdate($folder->timemodified)."</span>";
89 $class = $folder->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
90 $table->data[] = array (
91 $printsection,
92 "<a $class href=\"view.php?id=$cm->id\">".format_string($folder->name)."</a>",
93 format_module_intro('folder', $folder, $cm->id));
96 echo html_writer::table($table);
98 echo $OUTPUT->footer();