1
<?php // $Id: user.php,v 1.66.2.1 2007/02/28 05:36:14 nicolasconnault Exp $
1
<?php // $Id: user.php,v 1.75.2.12 2008/12/01 19:20:16 skodak Exp $
3
3
// Display user activity reports for a course
5
5
require_once("../config.php");
6
6
require_once("lib.php");
8
$modes = array("outline", "complete", "todaylogs", "alllogs");
10
8
$id = required_param('id',PARAM_INT); // course id
11
9
$user = required_param('user',PARAM_INT); // user id
12
10
$mode = optional_param('mode', "todaylogs", PARAM_ALPHA);
13
11
$page = optional_param('page', 0, PARAM_INT);
14
12
$perpage = optional_param('perpage', 100, PARAM_INT);
18
14
if (! $course = get_record("course", "id", $id)) {
19
15
error("Course id is incorrect.");
23
19
error("User ID is incorrect");
26
$coursecontext = get_context_instance(CONTEXT_COURSE, $id);
22
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
27
23
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
29
// if in either context, we can read report, then we can proceed
30
if (!(has_capability('moodle/site:viewreports', $coursecontext) or ($course->showreports and $USER->id == $user->id) or has_capability('moodle/user:viewuseractivitiesreport', $personalcontext))) {
31
error("You are not allowed to look at this page");
34
add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id");
26
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !has_capability('moodle/course:view', $coursecontext)) {
27
// do not require parents to be enrolled in courses ;-)
28
course_setup($course);
30
require_login($course);
35
print_heading(get_string('userdeleted'));
40
// prepare list of allowed modes
41
$myreports = ($course->showreports and $USER->id == $user->id);
42
$anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
46
if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
50
if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
51
$modes[] = 'complete';
54
if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) {
55
$modes[] = 'todaylogs';
58
if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) {
62
if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) {
66
if (has_capability('moodle/grade:viewall', $coursecontext)) {
67
//ok - can view all course grades
70
} else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) {
71
//ok - can view own grades
74
} else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) {
75
// ok - can view grades of this user - parent most probably
78
} else if ($course->showgrades and $anyreport) {
79
// ok - can view grades of this user - parent most probably
84
require_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
87
if (!in_array($mode, $modes)) {
88
// forbidden or non-exitent mode
89
$mode = reset($modes);
92
add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id");
36
94
$stractivityreport = get_string("activityreport");
37
95
$strparticipants = get_string("participants");
42
100
$strmode = get_string($mode);
43
101
$fullname = fullname($user, true);
45
if ($course->id != SITEID) {
46
print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname,
47
"<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
48
<a href=\"../user/index.php?id=$course->id\">$strparticipants</a> ->
49
<a href=\"../user/view.php?id=$user->id&course=$course->id\">$fullname</a> ->
50
$stractivityreport -> $strmode");
52
print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname,
53
"<a href=\"../user/view.php?id=$user->id&course=$course->id\">$fullname</a> ->
54
$stractivityreport -> $strmode");
105
if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $coursecontext)) {
106
$navlinks[] = array('name' => $strparticipants, 'link' => "../user/index.php?id=$course->id", 'type' => 'misc');
109
$navlinks[] = array('name' => $fullname, 'link' => "../user/view.php?id=$user->id&course=$course->id", 'type' => 'misc');
110
$navlinks[] = array('name' => $stractivityreport, 'link' => null, 'type' => 'misc');
111
$navlinks[] = array('name' => $strmode, 'link' => null, 'type' => 'misc');
112
$navigation = build_navigation($navlinks);
114
print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname, $navigation);
58
117
/// Print tabs at top
59
118
/// This same call is made in:
65
124
include($CFG->dirroot.'/user/tabs.php');
67
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
71
$course = get_record('course', 'id', required_param('id', PARAM_INT));
72
if (!empty($course->showgrades)) {
73
require_once($CFG->dirroot.'/grade/lib.php');
74
print_student_grade($user, $course);
128
if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) {
129
$CFG->grade_profilereport = 'user';
131
require_once $CFG->libdir.'/gradelib.php';
132
require_once $CFG->dirroot.'/grade/lib.php';
133
require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php';
135
$functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport';
136
if (function_exists($functionname)) {
137
$functionname($course, $user);
78
141
case "todaylogs" :
79
142
echo '<div class="graph">';
80
143
print_log_graph($course, $user->id, "userday.png");
82
print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
145
print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
83
146
"user.php?id=$course->id&user=$user->id&mode=$mode");
87
150
echo '<div class="graph">';
88
151
print_log_graph($course, $user->id, "usercourse.png");
90
print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
153
print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
91
154
"user.php?id=$course->id&user=$user->id&mode=$mode");
106
169
$earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend');
107
170
$earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend');
108
171
$earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend');
110
173
if (empty($earliestday)) $earliestday = time();
111
174
if (empty($earliestweek)) $earliestweek = time();
112
175
if (empty($earliestmonth)) $earliestmonth = time();
114
177
$now = stats_get_base_daily();
115
178
$lastweekend = stats_get_base_weekly();
116
179
$lastmonthend = stats_get_base_monthly();
118
181
$timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
120
if (empty($timeoptions)) {
121
error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
183
if (empty($timeoptions)) {
184
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
124
187
// use the earliest.
125
188
$time = array_pop(array_keys($timeoptions));
127
190
$param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED);
129
192
$param->table = 'user_'.$param->table;
137
200
$stats = get_records_sql($sql);
139
202
if (empty($stats)) {
140
error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
203
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
143
echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>';
206
// MDL-10818, do not display broken graph when user has no permission to view graph
207
if ($myreports or has_capability('coursereport/stats:view', $coursecontext)) {
208
echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>';
145
211
// What the heck is this about? -- MD
146
212
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
148
214
$table = new object();
149
215
$table->align = array('left','center','center','center');
150
216
$param->table = str_replace('user_','',$param->table);
151
$table->head = array(get_string('periodending','moodle',$param->table),$param->line1,$param->line2,$param->line3);
217
switch ($param->table) {
218
case 'daily' : $period = get_string('day'); break;
219
case 'weekly' : $period = get_string('week'); break;
220
case 'monthly': $period = get_string('month', 'form'); break;
221
default : $period = '';
223
$table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3);
152
224
foreach ($stats as $stat) {
153
225
if (!empty($stat->zerofixed)) { // Don't know why this is necessary, see stats_fix_zeros above - MD