MDL-33340 completion: Incorrect logic in hidden field check
[moodle.git] / report / outline / index.php
CommitLineData
7f093351 1<?php
275cbac7
PS
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
cc652b4d 16
275cbac7
PS
17/**
18 * Display user activity reports for a course (totals)
19 *
20 * @package report
21 * @subpackage outline
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
cc652b4d 25
3f5389b1 26require('../../config.php');
4d00fded 27require_once($CFG->dirroot.'/report/outline/locallib.php');
3f5389b1
PS
28
29$id = required_param('id',PARAM_INT); // course id
30
31$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
32
33$PAGE->set_url('/report/outline/index.php', array('id'=>$id));
34$PAGE->set_pagelayout('report');
35
36require_login($course);
37$context = get_context_instance(CONTEXT_COURSE, $course->id);
38require_capability('report/outline:view', $context);
39
40add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id);
41
42$showlastaccess = true;
43$hiddenfields = explode(',', $CFG->hiddenuserfields);
44
77a7ed65 45if (array_search('lastaccess', $hiddenfields) !== false and !has_capability('moodle/user:viewhiddendetails', $context)) {
3f5389b1
PS
46 $showlastaccess = false;
47}
48
49$stractivityreport = get_string('pluginname', 'report_outline');
50$stractivity = get_string('activity');
51$strlast = get_string('lastaccess');
52$strreports = get_string('reports');
53$strviews = get_string('views');
54$strrelatedblogentries = get_string('relatedblogentries', 'blog');
55
56$PAGE->set_title($course->shortname .': '. $stractivityreport);
57$PAGE->set_heading($course->fullname);
58echo $OUTPUT->header();
59echo $OUTPUT->heading(format_string($course->fullname));
60
61if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
62 print_error('logfilenotavailable');
63}
64
65echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($logstart)), 'loginfo');
66
67$outlinetable = new html_table();
68$outlinetable->attributes['class'] = 'generaltable boxaligncenter';
69$outlinetable->cellpadding = 5;
70$outlinetable->id = 'outlinetable';
71$outlinetable->head = array($stractivity, $strviews);
72
73if ($CFG->useblogassociations) {
74 $outlinetable->head[] = $strrelatedblogentries;
75}
76
77if ($showlastaccess) {
78 $outlinetable->head[] = $strlast;
79}
80
81$modinfo = get_fast_modinfo($course);
82$sections = get_all_sections($course->id);
83
84$sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
85 FROM {course_modules} cm
86 JOIN {modules} m ON m.id = cm.module
87 JOIN {log} l ON l.cmid = cm.id
88 WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1
89 GROUP BY cm.id";
90$views = $DB->get_records_sql($sql, array($course->id));
91
92$prevsecctionnum = 0;
93foreach ($modinfo->sections as $sectionnum=>$section) {
94 foreach ($section as $cmid) {
95 $cm = $modinfo->cms[$cmid];
96 if (!$cm->has_view()) {
97 continue;
98 }
99 if (!$cm->uservisible) {
100 continue;
101 }
102 if ($prevsecctionnum != $sectionnum) {
103 $sectionrow = new html_table_row();
104 $sectionrow->attributes['class'] = 'section';
105 $sectioncell = new html_table_cell();
106 $sectioncell->colspan = count($outlinetable->head);
ad4e76e7 107
3f5389b1 108 $sectiontitle = get_section_name($course, $sections[$sectionnum]);
ad4e76e7 109
3f5389b1
PS
110 $sectioncell->text = $OUTPUT->heading($sectiontitle, 3);
111 $sectionrow->cells[] = $sectioncell;
112 $outlinetable->data[] = $sectionrow;
5a5cd650 113
3f5389b1
PS
114 $prevsecctionnum = $sectionnum;
115 }
5a5cd650 116
3f5389b1
PS
117 $dimmed = $cm->visible ? '' : 'class="dimmed"';
118 $modulename = get_string('modulename', $cm->modname);
ad4e76e7 119
3f5389b1
PS
120 $reportrow = new html_table_row();
121 $activitycell = new html_table_cell();
122 $activitycell->attributes['class'] = 'activity';
cc652b4d 123
3f5389b1 124 $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon'));
5a5cd650 125
3f5389b1
PS
126 $attributes = array();
127 if (!$cm->visible) {
128 $attributes['class'] = 'dimmed';
129 }
5a5cd650 130
3f5389b1 131 $activitycell->text = $activityicon . html_writer::link("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name), $attributes);;
5a5cd650 132
3f5389b1 133 $reportrow->cells[] = $activitycell;
5a5cd650 134
3f5389b1
PS
135 $numviewscell = new html_table_cell();
136 $numviewscell->attributes['class'] = 'numviews';
5a5cd650 137
3f5389b1
PS
138 if (!empty($views[$cm->id]->numviews)) {
139 $numviewscell->text = $views[$cm->id]->numviews;
140 } else {
141 $numviewscell->text = '-';
142 }
5a5cd650 143
3f5389b1 144 $reportrow->cells[] = $numviewscell;
5a5cd650 145
3f5389b1
PS
146 if ($CFG->useblogassociations) {
147 require_once($CFG->dirroot.'/blog/lib.php');
148 $blogcell = new html_table_cell();
149 $blogcell->attributes['class'] = 'blog';
150 if ($blogcount = blog_get_associated_count($course->id, $cm->id)) {
151 $blogcell->text = html_writer::link('/blog/index.php?modid='.$cm->id, $blogcount);
ad4e76e7 152 } else {
3f5389b1 153 $blogcell->text = '-';
5a5cd650 154 }
3f5389b1
PS
155 $reportrow->cells[] = $blogcell;
156 }
5a5cd650 157
3f5389b1
PS
158 if ($showlastaccess) {
159 $lastaccesscell = new html_table_cell();
160 $lastaccesscell->attributes['class'] = 'lastaccess';
5a5cd650 161
3f5389b1
PS
162 if (isset($views[$cm->id]->lasttime)) {
163 $timeago = format_time(time() - $views[$cm->id]->lasttime);
164 $lastaccesscell->text = userdate($views[$cm->id]->lasttime)." ($timeago)";
ad4e76e7 165 }
3f5389b1 166 $reportrow->cells[] = $lastaccesscell;
cc652b4d 167 }
3f5389b1 168 $outlinetable->data[] = $reportrow;
cc652b4d 169 }
3f5389b1
PS
170}
171echo html_writer::table($outlinetable);
cc652b4d 172
3f5389b1 173echo $OUTPUT->footer();
cc652b4d 174
175
aa6c1ced 176