3 // Display user activity reports for a course
5 require_once("../config.php");
6 require_once("lib.php");
8 $modes = array("outline", "complete", "todaylogs", "alllogs");
10 $id = required_param('id',PARAM_INT
); // course id
11 $user = required_param('user',PARAM_INT
); // user id
12 $mode = optional_param('mode', "todaylogs", PARAM_ALPHA
);
13 $page = optional_param('page', 0, PARAM_INT
);
14 $perpage = optional_param('perpage', 100, PARAM_INT
);
18 if (! $course = get_record("course", "id", $id)) {
19 error("Course id is incorrect.");
22 if (! $user = get_record("user", "id", $user)) {
23 error("User ID is incorrect");
26 $coursecontext = get_context_instance(CONTEXT_COURSE
, $id);
27 $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");
36 $stractivityreport = get_string("activityreport");
37 $strparticipants = get_string("participants");
38 $stroutline = get_string("outline");
39 $strcomplete = get_string("complete");
40 $stralllogs = get_string("alllogs");
41 $strtodaylogs = get_string("todaylogs");
42 $strmode = get_string($mode);
43 $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");
59 /// This same call is made in:
65 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 require_once $CFG->dirroot
.'/grade/report/user/lib.php';
75 $context = get_context_instance(CONTEXT_COURSE
, $id);
76 /// return tracking object
77 $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$id, 'userid'=>$user->id
));
78 // Create a report instance
79 $report = new grade_report_user($id, $gpr, $context, $user->id
);
85 print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user
));
87 if ($report->fill_table()) {
88 echo $report->print_table(true);
90 // print_student_grade($user, $course);
95 echo '<div class="graph">';
96 print_log_graph($course, $user->id
, "userday.png");
98 print_log($course, $user->id
, usergetmidnight(time()), "l.time DESC", $page, $perpage,
99 "user.php?id=$course->id&user=$user->id&mode=$mode");
103 echo '<div class="graph">';
104 print_log_graph($course, $user->id
, "usercourse.png");
106 print_log($course, $user->id
, 0, "l.time DESC", $page, $perpage,
107 "user.php?id=$course->id&user=$user->id&mode=$mode");
111 if (empty($CFG->enablestats
)) {
112 error("Stats is not enabled.");
115 require_once($CFG->dirroot
.'/lib/statslib.php');
117 $statsstatus = stats_check_uptodate($course->id
);
118 if ($statsstatus !== NULL) {
119 notify ($statsstatus);
122 $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix
.'stats_user_daily ORDER BY timeend');
123 $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix
.'stats_user_weekly ORDER BY timeend');
124 $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix
.'stats_user_monthly ORDER BY timeend');
126 if (empty($earliestday)) $earliestday = time();
127 if (empty($earliestweek)) $earliestweek = time();
128 if (empty($earliestmonth)) $earliestmonth = time();
130 $now = stats_get_base_daily();
131 $lastweekend = stats_get_base_weekly();
132 $lastmonthend = stats_get_base_monthly();
134 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
136 if (empty($timeoptions)) {
137 error(get_string('nostatstodisplay'), $CFG->wwwroot
.'/course/user.php?id='.$course->id
.'&user='.$user->id
.'&mode=outline');
141 $time = array_pop(array_keys($timeoptions));
143 $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW
,$course->id
,STATS_MODE_DETAILED
);
145 $param->table
= 'user_'.$param->table
;
147 $sql = 'SELECT timeend,'.$param->fields
.' FROM '.$CFG->prefix
.'stats_'.$param->table
.' WHERE '
148 .(($course->id
== SITEID
) ?
'' : ' courseid = '.$course->id
.' AND ')
149 .' userid = '.$user->id
150 .' AND timeend >= '.$param->timeafter
152 .' ORDER BY timeend DESC';
153 $stats = get_records_sql($sql);
156 error(get_string('nostatstodisplay'), $CFG->wwwroot
.'/course/user.php?id='.$course->id
.'&user='.$user->id
.'&mode=outline');
159 // MDL-10818, do not display broken graph when user has no permission to view graph
160 if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE
, $id))) {
161 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>';
164 // What the heck is this about? -- MD
165 $stats = stats_fix_zeros($stats,$param->timeafter
,$param->table
,(!empty($param->line2
)),(!empty($param->line3
)));
167 $table = new object();
168 $table->align
= array('left','center','center','center');
169 $param->table
= str_replace('user_','',$param->table
);
170 $table->head
= array(get_string('periodending','moodle',$param->table
),$param->line1
,$param->line2
,$param->line3
);
171 foreach ($stats as $stat) {
172 if (!empty($stat->zerofixed
)) { // Don't know why this is necessary, see stats_fix_zeros above - MD
175 $a = array(userdate($stat->timeend
,get_string('strftimedate'),$CFG->timezone
),$stat->line1
);
185 $sections = get_all_sections($course->id
);
187 for ($i=0; $i<=$course->numsections
; $i++
) {
189 if (isset($sections[$i])) { // should always be true
191 $section = $sections[$i];
192 $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible
or !$course->hiddensections
);
194 if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
196 if ($section->sequence
) {
197 echo '<div class="section">';
199 switch ($course->format
) {
200 case "weeks": print_string("week"); break;
201 case "topics": print_string("topic"); break;
202 default: print_string("section"); break;
206 echo '<div class="content">';
208 if ($mode == "outline") {
209 echo "<table cellpadding=\"4\" cellspacing=\"0\">";
212 $sectionmods = explode(",", $section->sequence
);
213 foreach ($sectionmods as $sectionmod) {
214 if (empty($mods[$sectionmod])) {
217 $mod = $mods[$sectionmod];
219 if (empty($mod->visible
)) {
223 $instance = get_record("$mod->modname", "id", "$mod->instance");
224 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
226 if (file_exists($libfile)) {
227 require_once($libfile);
231 $user_outline = $mod->modname
."_user_outline";
232 if (function_exists($user_outline)) {
233 $output = $user_outline($course, $user, $mod, $instance);
234 print_outline_row($mod, $instance, $output);
238 $user_complete = $mod->modname
."_user_complete";
239 if (function_exists($user_complete)) {
240 $image = "<img src=\"../mod/$mod->modname/icon.gif\" ".
241 "class=\"icon\" alt=\"$mod->modfullname\" />";
242 echo "<h4>$image $mod->modfullname: ".
243 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
244 format_string($instance->name
,true)."</a></h4>";
249 $user_complete($course, $user, $mod, $instance);
252 $output = ob_get_contents();
255 if (str_replace(' ', '', $output) != '<ul></ul>') {
264 if ($mode == "outline") {
267 echo '</div>'; // content
268 echo '</div>'; // section
277 print_footer($course);
280 function print_outline_row($mod, $instance, $result) {
283 $image = "<img src=\"$CFG->modpixpath/$mod->modname/icon.gif\" class=\"icon\" alt=\"$mod->modfullname\" />";
286 echo "<td valign=\"top\">$image</td>";
287 echo "<td valign=\"top\" style=\"width:300\">";
288 echo " <a title=\"$mod->modfullname\"";
289 echo " href=\"../mod/$mod->modname/view.php?id=$mod->id\">".format_string($instance->name
,true)."</a></td>";
290 echo "<td> </td>";
291 echo "<td valign=\"top\">";
292 if (isset($result->info
)) {
293 echo "$result->info";
295 echo "<p style=\"text-align:center\">-</p>";
298 echo "<td> </td>";
299 if (!empty($result->time
)) {
300 $timeago = format_time(time() - $result->time
);
301 echo "<td valign=\"top\" style=\"white-space: nowrap\">".userdate($result->time
)." ($timeago)</td>";