XML support
[moodle.git] / course / user.php
CommitLineData
f9903ed0 1<?PHP // $Id$
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");
f9903ed0 13
40343df7 14 require_login();
a2ab3b05 15
f9903ed0 16 if (! $course = get_record("course", "id", $id)) {
17 error("Course id is incorrect.");
18 }
19
40343df7 20 if (!isteacher($course->id)) {
21 error("You are not allowed to look at this page");
22 }
f9903ed0 23
f9903ed0 24 if (! $user = get_record("user", "id", $user)) {
25 error("User ID is incorrect");
26 }
27
359b138b 28 add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id");
f9903ed0 29
a2ab3b05 30 $stractivityreport = get_string("activityreport");
31 $strparticipants = get_string("participants");
32 $stroutline = get_string("outline");
33 $strcomplete = get_string("complete");
34 $stralllogs = get_string("alllogs");
35 $strtodaylogs = get_string("todaylogs");
36 $strmode = get_string($mode);
37
38 if ($course->category) {
39 print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
f9903ed0 40 "<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> ->
a2ab3b05 41 <A HREF=\"../user/index.php?id=$course->id\">$strparticipants</A> ->
f9903ed0 42 <A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
a2ab3b05 43 $stractivityreport -> $strmode");
44 } else {
45 print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
46 "<A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
47 $stractivityreport -> $strmode");
48 }
bbfe835b 49 print_heading("$user->firstname $user->lastname");
50
40343df7 51 echo "<table cellpadding=10 align=center><tr>";
350a05c4 52 echo "<td>$stractivityreport: </td>";
40343df7 53
a2ab3b05 54 foreach ($modes as $listmode) {
55 $strmode = get_string($listmode);
56 if ($mode == $listmode) {
40343df7 57 echo "<td><u>$strmode</u></td>";
a2ab3b05 58 } else {
40343df7 59 echo "<td><a href=user.php?id=$course->id&user=$user->id&mode=$listmode>$strmode</a></td>";
a2ab3b05 60 }
2b8cef80 61 }
40343df7 62 echo "</tr></table>";
bbfe835b 63
9c9f7d77 64 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
600149be 65
7468bf01 66 switch ($mode) {
a2ab3b05 67 case "todaylogs" :
2b8cef80 68 echo "<HR><CENTER>";
adecd142 69 print_log_graph($course, $user->id, "userday.png");
2b8cef80 70 echo "</CENTER>";
71 print_log($course, $user->id, usergetmidnight(time()), "ORDER BY l.time DESC");
72 break;
73
74 case "alllogs" :
75 echo "<HR><CENTER>";
76 print_log_graph($course, $user->id, "usercourse.png");
77 echo "</CENTER>";
78 print_log($course, $user->id, 0, "ORDER BY l.time DESC");
7468bf01 79 break;
600149be 80
7468bf01 81 case "outline" :
82 case "complete" :
83 default:
84 $sections = get_all_sections($course->id);
600149be 85
7468bf01 86 for ($i=0; $i<=$course->numsections; $i++) {
87
88 if (isset($sections[$i])) { // should always be true
89
90 $section = $sections[$i];
91
92 if ($section->sequence) {
93 echo "<HR>";
94 echo "<H2>";
95 switch ($course->format) {
96 case "weeks": print_string("week"); break;
97 case "topics": print_string("topic"); break;
98 default: print_string("section"); break;
99 }
100 echo " $i</H2>";
101
102 echo "<UL>";
103
104 if ($mode == "outline") {
105 echo "<TABLE CELLPADDING=4 CELLSPACING=0>";
106 }
107
108 $sectionmods = explode(",", $section->sequence);
109 foreach ($sectionmods as $sectionmod) {
7af6281f 110 if (empty($mods[$sectionmod])) {
111 continue;
112 }
7468bf01 113 $mod = $mods[$sectionmod];
114 $instance = get_record("$mod->modname", "id", "$mod->instance");
359b138b 115 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
116
117 if (file_exists($libfile)) {
118 require_once($libfile);
119
120 switch ($mode) {
121 case "outline":
122 $user_outline = $mod->modname."_user_outline";
123 if (function_exists($user_outline)) {
124 $output = $user_outline($course, $user, $mod, $instance);
125 print_outline_row($mod, $instance, $output);
126 }
127 break;
128 case "complete":
129 $user_complete = $mod->modname."_user_complete";
130 if (function_exists($user_complete)) {
131 $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" ".
132 "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
133 echo "<H4>$image $mod->modfullname: ".
134 "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
135 "$instance->name</A></H4>";
136 echo "<UL>";
137 $user_complete($course, $user, $mod, $instance);
138 echo "</UL>";
139 }
140 break;
7468bf01 141 }
142 }
143 }
144
145 if ($mode == "outline") {
146 echo "</TABLE>";
147 print_simple_box_end();
148 }
149 echo "</UL>";
359b138b 150
600149be 151
7468bf01 152 }
600149be 153 }
f9903ed0 154 }
7468bf01 155 break;
f9903ed0 156 }
157
7468bf01 158
f9903ed0 159 print_footer($course);
160
7468bf01 161
359b138b 162function print_outline_row($mod, $instance, $result) {
7468bf01 163 $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
49a6849e 164
359b138b 165 echo "<TR>";
166 echo "<TD VALIGN=top>$image</TD>";
49a6849e 167 echo "<TD VALIGN=top width=300>";
359b138b 168 echo " <A TITLE=\"$mod->modfullname\"";
7468bf01 169 echo " HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</A></TD>";
170 echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
359b138b 171 echo "<TD VALIGN=top BGCOLOR=white>";
172 if (isset($result->info)) {
173 echo "$result->info";
174 } else {
175 echo "<P ALIGN=CENTER>-</P>";
176 }
177 echo "</TD>";
178 echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
179 if (isset($result->time)) {
180 $timeago = format_time(time() - $result->time);
2a231ed6 181 echo "<TD VALIGN=top NOWRAP>".userdate($result->time)." ($timeago)</TD>";
359b138b 182 }
183 echo "</TR>";
7468bf01 184}
185
f9903ed0 186?>
187