translated some.
[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 }
6f2e07e8 52 print_heading($fullname);
bbfe835b 53
24f2b65a 54 echo "<table cellpadding=\"10\" align=\"center\"><tr>";
350a05c4 55 echo "<td>$stractivityreport: </td>";
40343df7 56
a2ab3b05 57 foreach ($modes as $listmode) {
58 $strmode = get_string($listmode);
59 if ($mode == $listmode) {
40343df7 60 echo "<td><u>$strmode</u></td>";
a2ab3b05 61 } else {
b56681b0 62 echo "<td><a href=\"user.php?id=$course->id&amp;user=$user->id&amp;mode=$listmode\">$strmode</a></td>";
a2ab3b05 63 }
2b8cef80 64 }
40343df7 65 echo "</tr></table>";
bbfe835b 66
9c9f7d77 67 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
600149be 68
7468bf01 69 switch ($mode) {
a2ab3b05 70 case "todaylogs" :
24f2b65a 71 echo "<hr /><center>";
adecd142 72 print_log_graph($course, $user->id, "userday.png");
24f2b65a 73 echo "</center>";
519d369f 74 print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
839f2456 75 "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
2b8cef80 76 break;
77
78 case "alllogs" :
24f2b65a 79 echo "<hr /><center>";
2b8cef80 80 print_log_graph($course, $user->id, "usercourse.png");
24f2b65a 81 echo "</center>";
519d369f 82 print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
839f2456 83 "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
7468bf01 84 break;
600149be 85
7468bf01 86 case "outline" :
87 case "complete" :
88 default:
89 $sections = get_all_sections($course->id);
600149be 90
7468bf01 91 for ($i=0; $i<=$course->numsections; $i++) {
92
93 if (isset($sections[$i])) { // should always be true
94
95 $section = $sections[$i];
96
97 if ($section->sequence) {
24f2b65a 98 echo "<hr />";
99 echo "<h2>";
7468bf01 100 switch ($course->format) {
101 case "weeks": print_string("week"); break;
102 case "topics": print_string("topic"); break;
103 default: print_string("section"); break;
104 }
24f2b65a 105 echo " $i</h2>";
7468bf01 106
24f2b65a 107 echo "<ul>";
7468bf01 108
109 if ($mode == "outline") {
24f2b65a 110 echo "<table cellpadding=\"4\" cellspacing=\"0\">";
7468bf01 111 }
112
113 $sectionmods = explode(",", $section->sequence);
114 foreach ($sectionmods as $sectionmod) {
7af6281f 115 if (empty($mods[$sectionmod])) {
116 continue;
117 }
7468bf01 118 $mod = $mods[$sectionmod];
4f91674c 119
120 if (empty($mod->visible)) {
121 continue;
122 }
123
7468bf01 124 $instance = get_record("$mod->modname", "id", "$mod->instance");
359b138b 125 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
126
127 if (file_exists($libfile)) {
128 require_once($libfile);
129
130 switch ($mode) {
131 case "outline":
132 $user_outline = $mod->modname."_user_outline";
133 if (function_exists($user_outline)) {
134 $output = $user_outline($course, $user, $mod, $instance);
135 print_outline_row($mod, $instance, $output);
136 }
137 break;
138 case "complete":
139 $user_complete = $mod->modname."_user_complete";
140 if (function_exists($user_complete)) {
24f2b65a 141 $image = "<img src=\"../mod/$mod->modname/icon.gif\" ".
839f2456 142 "height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
24f2b65a 143 echo "<h4>$image $mod->modfullname: ".
144 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
145 "$instance->name</a></h4>";
146 echo "<ul>";
359b138b 147 $user_complete($course, $user, $mod, $instance);
24f2b65a 148 echo "</ul>";
359b138b 149 }
150 break;
7468bf01 151 }
152 }
153 }
154
155 if ($mode == "outline") {
24f2b65a 156 echo "</table>";
7468bf01 157 print_simple_box_end();
158 }
24f2b65a 159 echo "</ul>";
359b138b 160
600149be 161
7468bf01 162 }
600149be 163 }
f9903ed0 164 }
7468bf01 165 break;
f9903ed0 166 }
167
7468bf01 168
f9903ed0 169 print_footer($course);
170
7468bf01 171
359b138b 172function print_outline_row($mod, $instance, $result) {
839f2456 173 $image = "<img src=\"../mod/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
24f2b65a 174
175 echo "<tr>";
176 echo "<td valign=\"top\">$image</td>";
177 echo "<td valign=\"top\" width=\"300\">";
178 echo " <a title=\"$mod->modfullname\"";
179 echo " href=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</a></td>";
180 echo "<td>&nbsp;&nbsp;&nbsp;</td>";
181 echo "<td valign=\"top\" bgcolor=\"white\">";
359b138b 182 if (isset($result->info)) {
183 echo "$result->info";
184 } else {
24f2b65a 185 echo "<p align=\"center\">-</p>";
359b138b 186 }
24f2b65a 187 echo "</td>";
188 echo "<td>&nbsp;&nbsp;&nbsp;</td>";
359b138b 189 if (isset($result->time)) {
190 $timeago = format_time(time() - $result->time);
24f2b65a 191 echo "<td valign=\"top\" nowrap=\"nowrap\">".userdate($result->time)." ($timeago)</td>";
359b138b 192 }
24f2b65a 193 echo "</tr>";
7468bf01 194}
195
f9903ed0 196?>
197