New user tabs from Shane and myself ... these bring together the
[moodle.git] / course / user.php
CommitLineData
24f2b65a 1<?php // $Id$
f9903ed0 2
97c270e9 3// Display user activity reports for a course
4
b0e3a925 5 require_once("../config.php");
6 require_once("lib.php");
f9903ed0 7
40343df7 8 $modes = array("outline", "complete", "todaylogs", "alllogs");
9
f9903ed0 10 require_variable($id); // course id
11 require_variable($user); // user id
0ed00b3b 12 optional_variable($mode, "todaylogs");
519d369f 13 optional_variable($page, "0");
14 optional_variable($perpage, "100");
f9903ed0 15
40343df7 16 require_login();
a2ab3b05 17
f9903ed0 18 if (! $course = get_record("course", "id", $id)) {
19 error("Course id is incorrect.");
20 }
21
f9903ed0 22 if (! $user = get_record("user", "id", $user)) {
23 error("User ID is incorrect");
24 }
25
85a6e76c 26 if (! (isteacher($course->id) or ($course->showreports and $USER->id == $user->id))) {
27 error("You are not allowed to look at this page");
28 }
29
839f2456 30 add_to_log($course->id, "course", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
f9903ed0 31
a2ab3b05 32 $stractivityreport = get_string("activityreport");
33 $strparticipants = get_string("participants");
34 $stroutline = get_string("outline");
35 $strcomplete = get_string("complete");
36 $stralllogs = get_string("alllogs");
37 $strtodaylogs = get_string("todaylogs");
38 $strmode = get_string($mode);
6f2e07e8 39 $fullname = fullname($user, true);
a2ab3b05 40
41 if ($course->category) {
42 print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
24f2b65a 43 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
44 <a href=\"../user/index.php?id=$course->id\">$strparticipants</a> ->
839f2456 45 <a href=\"../user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
a2ab3b05 46 $stractivityreport -> $strmode");
47 } else {
48 print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
839f2456 49 "<a href=\"../user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
a2ab3b05 50 $stractivityreport -> $strmode");
51 }
f9a0ea69 52
53
54/// Print tabs at top
55/// This same call is made in:
56/// /user/view.php
57/// /user/edit.php
58/// /course/user.php
59 $currenttab = $mode;
60 include($CFG->dirroot.'/user/tabs.php');
61
bbfe835b 62
9c9f7d77 63 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
600149be 64
7468bf01 65 switch ($mode) {
a2ab3b05 66 case "todaylogs" :
f9a0ea69 67 echo '<div class="graph">';
adecd142 68 print_log_graph($course, $user->id, "userday.png");
f9a0ea69 69 echo '</div>';
519d369f 70 print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
839f2456 71 "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
2b8cef80 72 break;
73
74 case "alllogs" :
f9a0ea69 75 echo '<div class="graph">';
2b8cef80 76 print_log_graph($course, $user->id, "usercourse.png");
f9a0ea69 77 echo '</div>';
519d369f 78 print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
839f2456 79 "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
7468bf01 80 break;
600149be 81
7468bf01 82 case "outline" :
83 case "complete" :
84 default:
85 $sections = get_all_sections($course->id);
600149be 86
7468bf01 87 for ($i=0; $i<=$course->numsections; $i++) {
88
89 if (isset($sections[$i])) { // should always be true
90
91 $section = $sections[$i];
1757627a 92 $showsection = (isteacher($course->id) or $section->visible or !$course->hiddensections);
7468bf01 93
1757627a 94 if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
7468bf01 95
1757627a 96 if ($section->sequence) {
f9a0ea69 97 echo '<div class="section">';
98 echo '<h2>';
1757627a 99 switch ($course->format) {
100 case "weeks": print_string("week"); break;
101 case "topics": print_string("topic"); break;
102 default: print_string("section"); break;
7af6281f 103 }
1757627a 104 echo " $i</h2>";
105
f9a0ea69 106 echo '<div class="content">';
4f91674c 107
1757627a 108 if ($mode == "outline") {
109 echo "<table cellpadding=\"4\" cellspacing=\"0\">";
4f91674c 110 }
111
1757627a 112 $sectionmods = explode(",", $section->sequence);
113 foreach ($sectionmods as $sectionmod) {
114 if (empty($mods[$sectionmod])) {
115 continue;
116 }
117 $mod = $mods[$sectionmod];
118
119 if (empty($mod->visible)) {
120 continue;
121 }
359b138b 122
1757627a 123 $instance = get_record("$mod->modname", "id", "$mod->instance");
124 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
125
126 if (file_exists($libfile)) {
127 require_once($libfile);
128
129 switch ($mode) {
130 case "outline":
131 $user_outline = $mod->modname."_user_outline";
132 if (function_exists($user_outline)) {
133 $output = $user_outline($course, $user, $mod, $instance);
134 print_outline_row($mod, $instance, $output);
135 }
136 break;
137 case "complete":
138 $user_complete = $mod->modname."_user_complete";
139 if (function_exists($user_complete)) {
140 $image = "<img src=\"../mod/$mod->modname/icon.gif\" ".
141 "height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
142 echo "<h4>$image $mod->modfullname: ".
143 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
144 "$instance->name</a></h4>";
145 echo "<ul>";
146 $user_complete($course, $user, $mod, $instance);
147 echo "</ul>";
148 }
149 break;
359b138b 150 }
1757627a 151 }
7468bf01 152 }
1757627a 153
154 if ($mode == "outline") {
155 echo "</table>";
156 print_simple_box_end();
7468bf01 157 }
f9a0ea69 158 echo '</div>'; // content
159 echo '</div>'; // section
7468bf01 160 }
7468bf01 161 }
600149be 162 }
f9903ed0 163 }
7468bf01 164 break;
f9903ed0 165 }
166
7468bf01 167
f9903ed0 168 print_footer($course);
169
7468bf01 170
359b138b 171function print_outline_row($mod, $instance, $result) {
839f2456 172 $image = "<img src=\"../mod/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
24f2b65a 173
174 echo "<tr>";
175 echo "<td valign=\"top\">$image</td>";
176 echo "<td valign=\"top\" width=\"300\">";
177 echo " <a title=\"$mod->modfullname\"";
178 echo " href=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</a></td>";
179 echo "<td>&nbsp;&nbsp;&nbsp;</td>";
180 echo "<td valign=\"top\" bgcolor=\"white\">";
359b138b 181 if (isset($result->info)) {
182 echo "$result->info";
183 } else {
24f2b65a 184 echo "<p align=\"center\">-</p>";
359b138b 185 }
24f2b65a 186 echo "</td>";
187 echo "<td>&nbsp;&nbsp;&nbsp;</td>";
359b138b 188 if (isset($result->time)) {
189 $timeago = format_time(time() - $result->time);
24f2b65a 190 echo "<td valign=\"top\" nowrap=\"nowrap\">".userdate($result->time)." ($timeago)</td>";
359b138b 191 }
24f2b65a 192 echo "</tr>";
7468bf01 193}
194
f9903ed0 195?>
196