Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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 19 * 20 * @copyright 1999 Martin Dougiamas http://dougiamas.com 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 * @package course 23 */ 24 25 require_once("../config.php"); 26 require_once ("lib.php"); 27 28 $id = required_param('id',PARAM_INT); // course id 29 $user = required_param('user',PARAM_INT); // user id 30 $mode = optional_param('mode', "todaylogs", PARAM_ALPHA); 31 32 $url = new moodle_url('/course/user.php', array('id'=>$id,'user'=>$user, 'mode'=>$mode)); 33 34 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); 35 $user = $DB->get_record("user", array("id"=>$user, 'deleted'=>0), '*', MUST_EXIST); 36 37 if ($mode === 'outline' or $mode === 'complete') { 38 $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode)); 39 redirect($url); 40 } 41 if ($mode === 'todaylogs' or $mode === 'alllogs') { 42 $logmode = ($mode === 'todaylogs') ? 'today' : 'all'; 43 $url = new moodle_url('/report/log/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$logmode)); 44 redirect($url); 45 } 46 if ($mode === 'stats') { 47 $url = new moodle_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id)); 48 redirect($url); 49 } 50 if ($mode === 'coursecompletions' or $mode === 'coursecompletion') { 51 $url = new moodle_url('/report/completion/user.php', array('id'=>$user->id, 'course'=>$course->id)); 52 redirect($url); 53 } 54 55 $coursecontext = context_course::instance($course->id); 56 $personalcontext = context_user::instance($user->id); 57 58 $PAGE->set_context($personalcontext); 59 60 $PAGE->set_url('/course/user.php', array('id'=>$id, 'user'=>$user->id, 'mode'=>$mode)); 61 62 require_login(); 63 $PAGE->set_pagelayout('report'); 64 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext)) { 65 // do not require parents to be enrolled in courses ;-) 66 $PAGE->set_course($course); 67 } else { 68 require_login($course); 69 } 70 71 if ($user->deleted) { 72 echo $OUTPUT->header(); 73 echo $OUTPUT->heading(get_string('userdeleted')); 74 echo $OUTPUT->footer(); 75 die; 76 } 77 78 // prepare list of allowed modes 79 $myreports = ($course->showreports and $USER->id == $user->id); 80 $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext); 81 82 $modes = array(); 83 84 // Used for grade reports, it represents whether we should be viewing the report as ourselves, or as the targetted user. 85 $viewasuser = false; 86 87 if (has_capability('moodle/grade:viewall', $coursecontext)) { 88 //ok - can view all course grades 89 $modes[] = 'grade'; 90 91 } else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) { 92 //ok - can view own grades 93 $modes[] = 'grade'; 94 95 } else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) { 96 // ok - can view grades of this user - parent most probably 97 $modes[] = 'grade'; 98 $viewasuser = true; 99 100 } else if ($course->showgrades and $anyreport) { 101 // ok - can view grades of this user - parent most probably 102 $modes[] = 'grade'; 103 $viewasuser = true; 104 } 105 106 if (empty($modes)) { 107 require_capability('moodle/user:viewuseractivitiesreport', $personalcontext); 108 } 109 110 if (!in_array($mode, $modes)) { 111 // forbidden or non-existent mode 112 $mode = reset($modes); 113 } 114 115 $eventdata = array( 116 'context' => $coursecontext, 117 'relateduserid' => $user->id, 118 'other' => array('mode' => $mode), 119 ); 120 $event = \core\event\course_user_report_viewed::create($eventdata); 121 $event->trigger(); 122 123 $stractivityreport = get_string("activityreport"); 124 125 $PAGE->navigation->extend_for_user($user); 126 $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. 127 $PAGE->set_title("$course->shortname: $stractivityreport ($mode)"); 128 $PAGE->set_heading(fullname($user)); 129 130 switch ($mode) { 131 case "grade": 132 // Change the navigation to point to the my grade node (If we are a student). 133 if ($USER->id == $user->id) { 134 require_once($CFG->dirroot . '/user/lib.php'); 135 // Make the dashboard active so that it shows up in the navbar correctly. 136 $gradenode = $PAGE->settingsnav->find('dashboard', null)->make_active(); 137 // Get the correct 'Grades' url to point to. 138 $activeurl = user_mygrades_url(); 139 $navbar = $PAGE->navbar->add(get_string('grades', 'grades'), $activeurl, navigation_node::TYPE_SETTING); 140 $activenode = $navbar->add($course->shortname); 141 $activenode->make_active(); 142 // Find the course node and collapse it. 143 $coursenode = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE); 144 $coursenode->collapse = true; 145 $coursenode->make_inactive(); 146 $url = new moodle_url('/course/user.php', array('id' => $id, 'user' => $user->id, 'mode' => $mode)); 147 $reportnode = $activenode->add(get_string('pluginname', 'gradereport_user'), $url); 148 } else { 149 if ($course->id == SITEID) { 150 $activenode = $PAGE->navigation->find('user' . $user->id, null); 151 } else { 152 $currentcoursenode = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE); 153 $activenode = $currentcoursenode->find_active_node(); 154 } 155 156 // Check to see if the active node is a user name. 157 if (!preg_match('/^user\d{0,}$/', $activenode->key)) { // No user name found. 158 $userurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)); 159 // Add the user name. 160 $PAGE->navbar->add(fullname($user), $userurl, navigation_node::TYPE_SETTING); 161 } 162 $PAGE->navbar->add(get_string('report')); 163 $gradeurl = new moodle_url('/course/user.php', array('id' => $id, 'user' => $user->id, 'mode' => $mode)); 164 // Add the 'grades' node to the navbar. 165 $navbar = $PAGE->navbar->add(get_string('grades', 'grades'), $gradeurl, navigation_node::TYPE_SETTING); 166 } 167 echo $OUTPUT->header(); 168 169 if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) { 170 $CFG->grade_profilereport = 'user'; 171 } 172 require_once $CFG->libdir.'/gradelib.php'; 173 require_once $CFG->dirroot.'/grade/lib.php'; 174 require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php'; 175 176 // User must be able to view this grade report. 177 if (!$viewasuser) { 178 require_capability('gradereport/' . $CFG->grade_profilereport . ':view', $coursecontext); 179 } 180 181 $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; 182 if (function_exists($functionname)) { 183 $functionname($course, $user, $viewasuser); 184 } 185 break; 186 187 break; 188 default: 189 // It's unlikely to reach this piece of code, as the mode is never empty and it sets mode as grade in most of the cases. 190 // Display the page header to avoid breaking the navigation. A course/user.php review will be done in MDL-49939. 191 echo $OUTPUT->header(); 192 } 193 194 195 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body