1<?php 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/>. 16 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 */ 25 26require('../../config.php'); 27require_once($CFG->dirroot.'/report/outline/locallib.php'); 28require_once($CFG->dirroot.'/report/outline/lib.php'); 29 30$userid = required_param('id', PARAM_INT); 31$courseid = required_param('course', PARAM_INT); 32$mode = optional_param('mode', 'outline', PARAM_ALPHA); 33 34if ($mode !== 'complete' and $mode !== 'outline') { 35 $mode = 'outline'; 36} 37 38$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST); 39$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 40 41$coursecontext = context_course::instance($course->id); 42$personalcontext = context_user::instance($user->id); 43 44if ($courseid == SITEID) { 45 $PAGE->set_context($personalcontext); 46} 47 48if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) 49 and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) { 50 //TODO: do not require parents to be enrolled in courses - this is a hack! 51 require_login(); 52 $PAGE->set_course($course); 53} else { 54 require_login($course); 55} 56$PAGE->set_url('/report/outline/user.php', array('id'=>$userid, 'course'=>$courseid, 'mode'=>$mode)); 57 58if (!report_outline_can_access_user_report($user, $course)) { 59 print_error('nocapability', 'report_outline'); 60} 61 62$stractivityreport = get_string('activityreport'); 63 64$PAGE->set_pagelayout('report'); 65$PAGE->set_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode)); 66$PAGE->navigation->extend_for_user($user); 67$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. 68$PAGE->set_title("$course->shortname: $stractivityreport"); 69 70// Create the appropriate breadcrumb. 71$navigationnode = array( 72 'url' => new moodle_url('/report/outline/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode)) 73 ); 74if ($mode === 'complete') { 75 $navigationnode['name'] = get_string('completereport'); 76} else { 77 $navigationnode['name'] = get_string('outlinereport'); 78} 79$PAGE->add_report_nodes($user->id, $navigationnode); 80 81if ($courseid == SITEID) { 82 $PAGE->set_heading(fullname($user)); 83} else { 84 $PAGE->set_heading($course->fullname); 85} 86 87// Trigger a report viewed event. 88$event = \report_outline\event\report_viewed::create(array('context' => context_course::instance($course->id), 89 'relateduserid' => $userid, 'other' => array('mode' => $mode))); 90$event->trigger(); 91 92echo $OUTPUT->header(); 93if ($courseid != SITEID) { 94 echo $OUTPUT->context_header( 95 array( 96 'heading' => fullname($user), 97 'user' => $user, 98 'usercontext' => $personalcontext 99 ), 2); 100} 101 102$modinfo = get_fast_modinfo($course, $user->id); 103$sections = $modinfo->get_section_info_all(); 104$itemsprinted = false; 105 106foreach ($sections as $i => $section) { 107 108 if ($section->uservisible) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert! 109 // Check the section has modules/resources, if not there is nothing to display. 110 if (!empty($modinfo->sections[$i])) { 111 $itemsprinted = true; 112 echo '<div class="section">'; 113 echo '<h2>'; 114 echo get_section_name($course, $section); 115 echo "</h2>"; 116 117 echo '<div class="content">'; 118 119 if ($mode == "outline") { 120 echo "<table cellpadding=\"4\" cellspacing=\"0\">"; 121 } 122 123 foreach ($modinfo->sections[$i] as $cmid) { 124 $mod = $modinfo->cms[$cmid]; 125 126 if (empty($mod->uservisible)) { 127 continue; 128 } 129 130 $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance)); 131 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php"; 132 133 if (file_exists($libfile)) { 134 require_once($libfile); 135 136 switch ($mode) { 137 case "outline": 138 $user_outline = $mod->modname."_user_outline"; 139 if (function_exists($user_outline)) { 140 $output = $user_outline($course, $user, $mod, $instance); 141 } else { 142 $output = report_outline_user_outline($user->id, $cmid, $mod->modname, $instance->id); 143 } 144 report_outline_print_row($mod, $instance, $output); 145 break; 146 case "complete": 147 $user_complete = $mod->modname."_user_complete"; 148 $image = $OUTPUT->pix_icon('icon', $mod->modfullname, 'mod_'.$mod->modname, array('class'=>'icon')); 149 echo "<h4>$image $mod->modfullname: ". 150 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">". 151 format_string($instance->name,true)."</a></h4>"; 152 153 ob_start(); 154 155 echo "<ul>"; 156 if (function_exists($user_complete)) { 157 $user_complete($course, $user, $mod, $instance); 158 } else { 159 echo report_outline_user_complete($user->id, $cmid, $mod->modname, $instance->id); 160 } 161 echo "</ul>"; 162 163 $output = ob_get_contents(); 164 ob_end_clean(); 165 166 if (str_replace(' ', '', $output) != '<ul></ul>') { 167 echo $output; 168 } 169 break; 170 } 171 } 172 } 173 174 if ($mode == "outline") { 175 echo "</table>"; 176 } 177 echo '</div>'; // content 178 echo '</div>'; // section 179 } 180 } 181} 182 183if (!$itemsprinted) { 184 echo $OUTPUT->notification(get_string('nothingtodisplay')); 185} 186 187echo $OUTPUT->footer(); 188