New help translation
[moodle.git] / course / user.php
bloba4fb8047f8bddf4bb9b4b9ca4af5008df84c2c2e
1 <?PHP // $Id$
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 require_variable($id); // course id
11 require_variable($user); // user id
12 optional_variable($mode, "todaylogs");
13 optional_variable($page, "0");
14 optional_variable($perpage, "100");
16 require_login();
18 if (! $course = get_record("course", "id", $id)) {
19 error("Course id is incorrect.");
22 if (!isteacher($course->id)) {
23 error("You are not allowed to look at this page");
26 if (! $user = get_record("user", "id", $user)) {
27 error("User ID is incorrect");
30 add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id");
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);
40 if ($course->category) {
41 print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
42 "<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> ->
43 <A HREF=\"../user/index.php?id=$course->id\">$strparticipants</A> ->
44 <A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
45 $stractivityreport -> $strmode");
46 } else {
47 print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
48 "<A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
49 $stractivityreport -> $strmode");
51 print_heading("$user->firstname $user->lastname");
53 echo "<table cellpadding=10 align=center><tr>";
54 echo "<td>$stractivityreport: </td>";
56 foreach ($modes as $listmode) {
57 $strmode = get_string($listmode);
58 if ($mode == $listmode) {
59 echo "<td><u>$strmode</u></td>";
60 } else {
61 echo "<td><a href=user.php?id=$course->id&user=$user->id&mode=$listmode>$strmode</a></td>";
64 echo "</tr></table>";
66 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
68 switch ($mode) {
69 case "todaylogs" :
70 echo "<HR><CENTER>";
71 print_log_graph($course, $user->id, "userday.png");
72 echo "</CENTER>";
73 print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
74 "user.php?id=$course->id&user=$user->id&mode=$mode");
75 break;
77 case "alllogs" :
78 echo "<HR><CENTER>";
79 print_log_graph($course, $user->id, "usercourse.png");
80 echo "</CENTER>";
81 print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
82 "user.php?id=$course->id&user=$user->id&mode=$mode");
83 break;
85 case "outline" :
86 case "complete" :
87 default:
88 $sections = get_all_sections($course->id);
90 for ($i=0; $i<=$course->numsections; $i++) {
92 if (isset($sections[$i])) { // should always be true
94 $section = $sections[$i];
96 if ($section->sequence) {
97 echo "<HR>";
98 echo "<H2>";
99 switch ($course->format) {
100 case "weeks": print_string("week"); break;
101 case "topics": print_string("topic"); break;
102 default: print_string("section"); break;
104 echo " $i</H2>";
106 echo "<UL>";
108 if ($mode == "outline") {
109 echo "<TABLE CELLPADDING=4 CELLSPACING=0>";
112 $sectionmods = explode(",", $section->sequence);
113 foreach ($sectionmods as $sectionmod) {
114 if (empty($mods[$sectionmod])) {
115 continue;
117 $mod = $mods[$sectionmod];
118 $instance = get_record("$mod->modname", "id", "$mod->instance");
119 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
121 if (file_exists($libfile)) {
122 require_once($libfile);
124 switch ($mode) {
125 case "outline":
126 $user_outline = $mod->modname."_user_outline";
127 if (function_exists($user_outline)) {
128 $output = $user_outline($course, $user, $mod, $instance);
129 print_outline_row($mod, $instance, $output);
131 break;
132 case "complete":
133 $user_complete = $mod->modname."_user_complete";
134 if (function_exists($user_complete)) {
135 $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" ".
136 "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
137 echo "<H4>$image $mod->modfullname: ".
138 "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
139 "$instance->name</A></H4>";
140 echo "<UL>";
141 $user_complete($course, $user, $mod, $instance);
142 echo "</UL>";
144 break;
149 if ($mode == "outline") {
150 echo "</TABLE>";
151 print_simple_box_end();
153 echo "</UL>";
159 break;
163 print_footer($course);
166 function print_outline_row($mod, $instance, $result) {
167 $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
169 echo "<TR>";
170 echo "<TD VALIGN=top>$image</TD>";
171 echo "<TD VALIGN=top width=300>";
172 echo " <A TITLE=\"$mod->modfullname\"";
173 echo " HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</A></TD>";
174 echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
175 echo "<TD VALIGN=top BGCOLOR=white>";
176 if (isset($result->info)) {
177 echo "$result->info";
178 } else {
179 echo "<P ALIGN=CENTER>-</P>";
181 echo "</TD>";
182 echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
183 if (isset($result->time)) {
184 $timeago = format_time(time() - $result->time);
185 echo "<TD VALIGN=top NOWRAP>".userdate($result->time)." ($timeago)</TD>";
187 echo "</TR>";