Merge branch 'MDL-25708' of git://github.com/stronk7/moodle
[moodle.git] / mod / resource / index.php
CommitLineData
aa54ed7b 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 * List of all resources in course
20 *
702ab58c
PS
21 * @package mod
22 * @subpackage resource
23 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
aa54ed7b 25 */
26
27require('../../config.php');
28
29$id = required_param('id', PARAM_INT); // course id
30
31$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
32
33require_course_login($course, true);
191b267b 34$PAGE->set_pagelayout('incourse');
aa54ed7b 35
36add_to_log($course->id, 'resource', 'view all', "index.php?id=$course->id", '');
37
38$strresource = get_string('modulename', 'resource');
39$strresources = get_string('modulenameplural', 'resource');
7487c856 40$strsectionname = get_string('sectionname', 'format_'.$course->format);
aa54ed7b 41$strname = get_string('name');
42$strintro = get_string('moduleintro');
43$strlastmodified = get_string('lastmodified');
44
a6855934 45$PAGE->set_url('/mod/resource/index.php', array('id' => $course->id));
aa54ed7b 46$PAGE->set_title($course->shortname.': '.$strresources);
47$PAGE->set_heading($course->fullname);
ef8869c7 48$PAGE->navbar->add($strresources);
49echo $OUTPUT->header();
aa54ed7b 50
51if (!$resources = get_all_instances_in_course('resource', $course)) {
52 notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
53 exit;
54}
55
7487c856
SH
56$usesections = course_format_uses_sections($course->format);
57if ($usesections) {
58 $sections = get_all_sections($course->id);
59}
60
aa54ed7b 61$table = new html_table();
16be8974 62$table->attributes['class'] = 'generaltable mod_index';
aa54ed7b 63
7487c856
SH
64if ($usesections) {
65 $table->head = array ($strsectionname, $strname, $strintro);
aa54ed7b 66 $table->align = array ('center', 'left', 'left');
67} else {
68 $table->head = array ($strlastmodified, $strname, $strintro);
69 $table->align = array ('left', 'left', 'left');
70}
71
72$modinfo = get_fast_modinfo($course);
73$currentsection = '';
74foreach ($resources as $resource) {
75 $cm = $modinfo->cms[$resource->coursemodule];
7487c856 76 if ($usesections) {
aa54ed7b 77 $printsection = '';
78 if ($resource->section !== $currentsection) {
79 if ($resource->section) {
7487c856 80 $printsection = get_section_name($course, $sections[$resource->section]);
2a439ba7 81 }
aa54ed7b 82 if ($currentsection !== '') {
83 $table->data[] = 'hr';
84 }
85 $currentsection = $resource->section;
81cdaada 86 }
aa54ed7b 87 } else {
88 $printsection = '<span class="smallinfo">'.userdate($resource->timemodified)."</span>";
2a439ba7 89 }
90
aa54ed7b 91 $extra = empty($cm->extra) ? '' : $cm->extra;
92 $icon = '';
93 if (!empty($cm->icon)) {
94 // each resource file has an icon in 2.0
3aa11c75 95 $icon = '<img src="'.$OUTPUT->pix_url($cm->icon).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
aa54ed7b 96 }
2a439ba7 97
aa54ed7b 98 $class = $resource->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
99 $table->data[] = array (
100 $printsection,
101 "<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
102 format_module_intro('resource', $resource, $cm->id));
103}
2a439ba7 104
16be8974 105echo html_writer::table($table);
73c24ef8 106
aa54ed7b 107echo $OUTPUT->footer();