Added new strings for question grade matching
[moodle-linuxchix.git] / course / user.php
blob85e2d54eacdd3b97c11c6fe30c7d32888c729d41
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 $id = required_param('id',PARAM_INT); // course id
11 $user = required_param('user',PARAM_INT); // user id
12 $mode = optional_param('mode', "todaylogs", PARAM_ALPHA);
13 $page = optional_param('page', 0, PARAM_INT);
14 $perpage = optional_param('perpage', 100, PARAM_INT);
16 require_login();
18 if (! $course = get_record("course", "id", $id)) {
19 error("Course id is incorrect.");
22 if (! $user = get_record("user", "id", $user)) {
23 error("User ID is incorrect");
26 if (! (isteacher($course->id) or ($course->showreports and $USER->id == $user->id))) {
27 error("You are not allowed to look at this page");
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");
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');
63 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
65 switch ($mode) {
66 case "todaylogs" :
67 echo '<div class="graph">';
68 print_log_graph($course, $user->id, "userday.png");
69 echo '</div>';
70 print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
71 "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
72 break;
74 case "alllogs" :
75 echo '<div class="graph">';
76 print_log_graph($course, $user->id, "usercourse.png");
77 echo '</div>';
78 print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
79 "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
80 break;
81 case 'stats':
83 if (empty($CFG->enablestats)) {
84 error("Stats is not enabled.");
87 require_once($CFG->dirroot.'/lib/statslib.php');
89 stats_check_uptodate($course->id);
91 $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend LIMIT 1');
92 $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend LIMIT 1');
93 $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend LIMIT 1');
95 if (empty($earliestday)) $earliestday = time();
96 if (empty($earliestweek)) $earliestweek = time();
97 if (empty($earliestmonth)) $earliestmonth = time();
99 $now = stats_get_base_daily();
100 $lastweekend = stats_get_base_weekly();
101 $lastmonthend = stats_get_base_monthly();
103 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
105 if (empty($timeoptions)) {
106 error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
109 // use the earliest.
110 $time = array_pop(array_keys($timeoptions));
112 $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED);
114 $param->table = 'user_'.$param->table;
116 $sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
117 .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
118 .' userid = '.$user->id
119 .' AND timeend >= '.$param->timeafter
120 .$param->extras
121 .' ORDER BY timeend DESC';
122 $stats = get_records_sql($sql);
124 if (empty($stats)) {
125 error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
128 echo '<center><img src="'.$CFG->wwwroot.'/course/statsgraph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" /></center>';
130 $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
132 $table = new object();
133 $table->align = array('left','center','center','center');
134 $param->table = str_replace('user_','',$param->table);
135 $table->head = array(get_string('periodending','moodle',$param->table),$param->line1,$param->line2,$param->line3);
136 foreach ($stats as $stat) {
137 $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1);
138 $a[] = $stat->line2;
139 $a[] = $stat->line3;
140 $table->data[] = $a;
142 print_table($table);
143 break;
144 case "outline" :
145 case "complete" :
146 default:
147 $sections = get_all_sections($course->id);
149 for ($i=0; $i<=$course->numsections; $i++) {
151 if (isset($sections[$i])) { // should always be true
153 $section = $sections[$i];
154 $showsection = (isteacher($course->id) or $section->visible or !$course->hiddensections);
156 if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
158 if ($section->sequence) {
159 echo '<div class="section">';
160 echo '<h2>';
161 switch ($course->format) {
162 case "weeks": print_string("week"); break;
163 case "topics": print_string("topic"); break;
164 default: print_string("section"); break;
166 echo " $i</h2>";
168 echo '<div class="content">';
170 if ($mode == "outline") {
171 echo "<table cellpadding=\"4\" cellspacing=\"0\">";
174 $sectionmods = explode(",", $section->sequence);
175 foreach ($sectionmods as $sectionmod) {
176 if (empty($mods[$sectionmod])) {
177 continue;
179 $mod = $mods[$sectionmod];
181 if (empty($mod->visible)) {
182 continue;
185 $instance = get_record("$mod->modname", "id", "$mod->instance");
186 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
188 if (file_exists($libfile)) {
189 require_once($libfile);
191 switch ($mode) {
192 case "outline":
193 $user_outline = $mod->modname."_user_outline";
194 if (function_exists($user_outline)) {
195 $output = $user_outline($course, $user, $mod, $instance);
196 print_outline_row($mod, $instance, $output);
198 break;
199 case "complete":
200 $user_complete = $mod->modname."_user_complete";
201 if (function_exists($user_complete)) {
202 $image = "<img src=\"../mod/$mod->modname/icon.gif\" ".
203 "height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
204 echo "<h4>$image $mod->modfullname: ".
205 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
206 format_string($instance->name,true)."</a></h4>";
207 echo "<ul>";
208 $user_complete($course, $user, $mod, $instance);
209 echo "</ul>";
211 break;
216 if ($mode == "outline") {
217 echo "</table>";
218 print_simple_box_end();
220 echo '</div>'; // content
221 echo '</div>'; // section
226 break;
230 print_footer($course);
233 function print_outline_row($mod, $instance, $result) {
234 global $CFG;
236 $image = "<img src=\"$CFG->modpixpath/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\" />";
238 echo "<tr>";
239 echo "<td valign=\"top\">$image</td>";
240 echo "<td valign=\"top\" width=\"300\">";
241 echo " <a title=\"$mod->modfullname\"";
242 echo " href=\"../mod/$mod->modname/view.php?id=$mod->id\">".format_string($instance->name,true)."</a></td>";
243 echo "<td>&nbsp;&nbsp;&nbsp;</td>";
244 echo "<td valign=\"top\">";
245 if (isset($result->info)) {
246 echo "$result->info";
247 } else {
248 echo "<p align=\"center\">-</p>";
250 echo "</td>";
251 echo "<td>&nbsp;&nbsp;&nbsp;</td>";
252 if (!empty($result->time)) {
253 $timeago = format_time(time() - $result->time);
254 echo "<td valign=\"top\" nowrap=\"nowrap\">".userdate($result->time)." ($timeago)</td>";
256 echo "</tr>";