$CFG->preferlinegraphs will make graphs use lines instead of bars
[moodle.git] / course / user.php
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.");
20     }
22     if (! $user = get_record("user", "id", $user)) {
23         error("User ID is incorrect");
24     }
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     }
30     add_to_log($course->id, "course", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;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);
39     $fullname          = fullname($user, true);
41     if ($course->category) {
42         print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
43                  "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
44                   <a href=\"../user/index.php?id=$course->id\">$strparticipants</a> ->
45                   <a href=\"../user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> -> 
46                   $stractivityreport -> $strmode");
47     } else {
48         print_header("$course->shortname: $stractivityreport ($mode)", "$course->fullname",
49                  "<a href=\"../user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> -> 
50                   $stractivityreport -> $strmode");
51     }
52     print_heading($fullname);
54     echo "<table cellpadding=\"10\" align=\"center\"><tr>";
55     echo "<td>$stractivityreport: </td>";
57     foreach ($modes as $listmode) {
58         $strmode = get_string($listmode);
59         if ($mode == $listmode) {
60             echo "<td><u>$strmode</u></td>";
61         } else {
62             echo "<td><a href=\"user.php?id=$course->id&amp;user=$user->id&amp;mode=$listmode\">$strmode</a></td>";
63         }
64     }
65     echo "</tr></table>";
67     get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
69     switch ($mode) {
70         case "todaylogs" :
71             echo "<hr /><center>";
72             print_log_graph($course, $user->id, "userday.png");
73             echo "</center>";
74             print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage, 
75                       "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
76             break;
78         case "alllogs" :
79             echo "<hr /><center>";
80             print_log_graph($course, $user->id, "usercourse.png");
81             echo "</center>";
82             print_log($course, $user->id, 0, "l.time DESC", $page, $perpage, 
83                       "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
84             break;
86         case "outline" :
87         case "complete" :
88         default:
89             $sections = get_all_sections($course->id);
91             for ($i=0; $i<=$course->numsections; $i++) {
93                 if (isset($sections[$i])) {   // should always be true
95                     $section = $sections[$i];
96                     $showsection = (isteacher($course->id) or $section->visible or !$course->hiddensections);
98                     if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
100                         if ($section->sequence) {
101                             echo "<hr />";
102                             echo "<h2>";
103                             switch ($course->format) {
104                                 case "weeks": print_string("week"); break;
105                                 case "topics": print_string("topic"); break;
106                                 default: print_string("section"); break;
107                             }
108                             echo " $i</h2>";
109     
110                             echo "<ul>";
112                             if ($mode == "outline") {
113                                 echo "<table cellpadding=\"4\" cellspacing=\"0\">";
114                             }
116                             $sectionmods = explode(",", $section->sequence);
117                             foreach ($sectionmods as $sectionmod) {
118                                 if (empty($mods[$sectionmod])) {
119                                     continue;
120                                 }
121                                 $mod = $mods[$sectionmod];
122     
123                                 if (empty($mod->visible)) {
124                                     continue;
125                                 }
127                                 $instance = get_record("$mod->modname", "id", "$mod->instance");
128                                 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
130                                 if (file_exists($libfile)) {
131                                     require_once($libfile);
133                                     switch ($mode) {
134                                         case "outline":
135                                             $user_outline = $mod->modname."_user_outline";
136                                             if (function_exists($user_outline)) {
137                                                 $output = $user_outline($course, $user, $mod, $instance);
138                                                 print_outline_row($mod, $instance, $output);
139                                             }
140                                             break;
141                                         case "complete":
142                                             $user_complete = $mod->modname."_user_complete";
143                                             if (function_exists($user_complete)) {
144                                                 $image = "<img src=\"../mod/$mod->modname/icon.gif\" ".
145                                                          "height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
146                                                 echo "<h4>$image $mod->modfullname: ".
147                                                      "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
148                                                      "$instance->name</a></h4>";
149                                                 echo "<ul>";
150                                                 $user_complete($course, $user, $mod, $instance);
151                                                 echo "</ul>";
152                                             }
153                                             break;
154                                         }
155                                     }
156                                 }
157     
158                             if ($mode == "outline") {
159                                 echo "</table>";
160                                 print_simple_box_end();
161                             }
162                             echo "</ul>";
163                         }
164                     }
165                 }
166             }
167             break;
168     }
171     print_footer($course);
174 function print_outline_row($mod, $instance, $result) {
175     $image = "<img src=\"../mod/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
177     echo "<tr>";
178     echo "<td valign=\"top\">$image</td>";
179     echo "<td valign=\"top\" width=\"300\">";
180     echo "   <a title=\"$mod->modfullname\"";
181     echo "   href=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</a></td>";
182     echo "<td>&nbsp;&nbsp;&nbsp;</td>";
183     echo "<td valign=\"top\" bgcolor=\"white\">";
184     if (isset($result->info)) {
185         echo "$result->info";
186     } else {
187         echo "<p align=\"center\">-</p>";
188     }
189     echo "</td>";
190     echo "<td>&nbsp;&nbsp;&nbsp;</td>";
191     if (isset($result->time)) {
192         $timeago = format_time(time() - $result->time);
193         echo "<td valign=\"top\" nowrap=\"nowrap\">".userdate($result->time)." ($timeago)</td>";
194     }
195     echo "</tr>";
198 ?>