| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: user.php,v 1.75.2.9 2008/07/05 14:53:31 skodak Exp $ 2 3 // Display user activity reports for a course 4 5 require_once("../config.php"); 6 require_once ("lib.php"); 7 8 $modes = array("outline", "complete", "todaylogs", "alllogs"); 9 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); 15 16 if (! $course = get_record("course", "id", $id)) { 17 error("Course id is incorrect."); 18 } 19 20 if (! $user = get_record("user", "id", $user)) { 21 error("User ID is incorrect"); 22 } 23 24 require_login(); 25 $COURSE = clone($course); 26 27 if ($user->deleted) { 28 print_header(); 29 print_heading(get_string('userdeleted')); 30 print_footer(); 31 die; 32 } 33 34 $coursecontext = get_context_instance(CONTEXT_COURSE, $id); 35 $personalcontext = get_context_instance(CONTEXT_USER, $user->id); 36 37 // if in either context, we can read report, then we can proceed 38 if (!(has_capability('moodle/site:viewreports', $coursecontext) or ($course->showreports and $USER->id == $user->id) or has_capability('moodle/user:viewuseractivitiesreport', $personalcontext))) { 39 error("You are not allowed to look at this page"); 40 } 41 42 add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id"); 43 44 $stractivityreport = get_string("activityreport"); 45 $strparticipants = get_string("participants"); 46 $stroutline = get_string("outline"); 47 $strcomplete = get_string("complete"); 48 $stralllogs = get_string("alllogs"); 49 $strtodaylogs = get_string("todaylogs"); 50 $strmode = get_string($mode); 51 $fullname = fullname($user, true); 52 53 $navlinks = array(); 54 55 if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $coursecontext)) { 56 $navlinks[] = array('name' => $strparticipants, 'link' => "../user/index.php?id=$course->id", 'type' => 'misc'); 57 } 58 59 $navlinks[] = array('name' => $fullname, 'link' => "../user/view.php?id=$user->id&course=$course->id", 'type' => 'misc'); 60 $navlinks[] = array('name' => $stractivityreport, 'link' => null, 'type' => 'misc'); 61 $navlinks[] = array('name' => $strmode, 'link' => null, 'type' => 'misc'); 62 $navigation = build_navigation($navlinks); 63 64 print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname, $navigation); 65 66 67 /// Print tabs at top 68 /// This same call is made in: 69 /// /user/view.php 70 /// /user/edit.php 71 /// /course/user.php 72 $currenttab = $mode; 73 $showroles = 1; 74 include($CFG->dirroot.'/user/tabs.php'); 75 76 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); 77 78 switch ($mode) { 79 case "grade": 80 if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) { 81 $CFG->grade_profilereport = 'user'; 82 } 83 require_once $CFG->libdir.'/gradelib.php'; 84 require_once $CFG->dirroot.'/grade/lib.php'; 85 require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php'; 86 87 $course = get_record('course', 'id', required_param('id', PARAM_INT)); 88 $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; 89 if (function_exists($functionname)) { 90 $functionname($course, $user); 91 } 92 break; 93 94 case "todaylogs" : 95 echo '<div class="graph">'; 96 print_log_graph($course, $user->id, "userday.png"); 97 echo '</div>'; 98 print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage, 99 "user.php?id=$course->id&user=$user->id&mode=$mode"); 100 break; 101 102 case "alllogs" : 103 echo '<div class="graph">'; 104 print_log_graph($course, $user->id, "usercourse.png"); 105 echo '</div>'; 106 print_log($course, $user->id, 0, "l.time DESC", $page, $perpage, 107 "user.php?id=$course->id&user=$user->id&mode=$mode"); 108 break; 109 case 'stats': 110 111 if (empty($CFG->enablestats)) { 112 error("Stats is not enabled."); 113 } 114 115 require_once($CFG->dirroot.'/lib/statslib.php'); 116 117 $statsstatus = stats_check_uptodate($course->id); 118 if ($statsstatus !== NULL) { 119 notify ($statsstatus); 120 } 121 122 $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend'); 123 $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend'); 124 $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend'); 125 126 if (empty($earliestday)) $earliestday = time(); 127 if (empty($earliestweek)) $earliestweek = time(); 128 if (empty($earliestmonth)) $earliestmonth = time(); 129 130 $now = stats_get_base_daily(); 131 $lastweekend = stats_get_base_weekly(); 132 $lastmonthend = stats_get_base_monthly(); 133 134 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); 135 136 if (empty($timeoptions)) { 137 print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); 138 } 139 140 // use the earliest. 141 $time = array_pop(array_keys($timeoptions)); 142 143 $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED); 144 145 $param->table = 'user_'.$param->table; 146 147 $sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE ' 148 .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') 149 .' userid = '.$user->id 150 .' AND timeend >= '.$param->timeafter 151 .$param->extras 152 .' ORDER BY timeend DESC'; 153 $stats = get_records_sql($sql); 154 155 if (empty($stats)) { 156 print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); 157 } 158 159 // MDL-10818, do not display broken graph when user has no permission to view graph 160 if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $id)) || 161 ($course->showreports and $USER->id == $user->id)) { 162 echo '<center><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>'; 163 } 164 165 // What the heck is this about? -- MD 166 $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); 167 168 $table = new object(); 169 $table->align = array('left','center','center','center'); 170 $param->table = str_replace('user_','',$param->table); 171 switch ($param->table) { 172 case 'daily' : $period = get_string('day'); break; 173 case 'weekly' : $period = get_string('week'); break; 174 case 'monthly': $period = get_string('month', 'form'); break; 175 default : $period = ''; 176 } 177 $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3); 178 foreach ($stats as $stat) { 179 if (!empty($stat->zerofixed)) { // Don't know why this is necessary, see stats_fix_zeros above - MD 180 continue; 181 } 182 $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1); 183 $a[] = $stat->line2; 184 $a[] = $stat->line3; 185 $table->data[] = $a; 186 } 187 print_table($table); 188 break; 189 case "outline" : 190 case "complete" : 191 default: 192 $sections = get_all_sections($course->id); 193 194 for ($i=0; $i<=$course->numsections; $i++) { 195 196 if (isset($sections[$i])) { // should always be true 197 198 $section = $sections[$i]; 199 $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible or !$course->hiddensections); 200 201 if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert! 202 203 if ($section->sequence) { 204 echo '<div class="section">'; 205 echo '<h2>'; 206 switch ($course->format) { 207 case "weeks": print_string("week"); break; 208 case "topics": print_string("topic"); break; 209 default: print_string("section"); break; 210 } 211 echo " $i</h2>"; 212 213 echo '<div class="content">'; 214 215 if ($mode == "outline") { 216 echo "<table cellpadding=\"4\" cellspacing=\"0\">"; 217 } 218 219 $sectionmods = explode(",", $section->sequence); 220 foreach ($sectionmods as $sectionmod) { 221 if (empty($mods[$sectionmod])) { 222 continue; 223 } 224 $mod = $mods[$sectionmod]; 225 226 if (empty($mod->visible)) { 227 continue; 228 } 229 230 $instance = get_record("$mod->modname", "id", "$mod->instance"); 231 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php"; 232 233 if (file_exists($libfile)) { 234 require_once($libfile); 235 236 switch ($mode) { 237 case "outline": 238 $user_outline = $mod->modname."_user_outline"; 239 if (function_exists($user_outline)) { 240 $output = $user_outline($course, $user, $mod, $instance); 241 print_outline_row($mod, $instance, $output); 242 } 243 break; 244 case "complete": 245 $user_complete = $mod->modname."_user_complete"; 246 if (function_exists($user_complete)) { 247 $image = "<img src=\"../mod/$mod->modname/icon.gif\" ". 248 "class=\"icon\" alt=\"$mod->modfullname\" />"; 249 echo "<h4>$image $mod->modfullname: ". 250 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">". 251 format_string($instance->name,true)."</a></h4>"; 252 253 ob_start(); 254 255 echo "<ul>"; 256 $user_complete($course, $user, $mod, $instance); 257 echo "</ul>"; 258 259 $output = ob_get_contents(); 260 ob_end_clean(); 261 262 if (str_replace(' ', '', $output) != '<ul></ul>') { 263 echo $output; 264 } 265 } 266 break; 267 } 268 } 269 } 270 271 if ($mode == "outline") { 272 echo "</table>"; 273 } 274 echo '</div>'; // content 275 echo '</div>'; // section 276 } 277 } 278 } 279 } 280 break; 281 } 282 283 284 print_footer($course); 285 286 287 function print_outline_row($mod, $instance, $result) { 288 global $CFG; 289 290 $image = "<img src=\"$CFG->modpixpath/$mod->modname/icon.gif\" class=\"icon\" alt=\"$mod->modfullname\" />"; 291 292 echo "<tr>"; 293 echo "<td valign=\"top\">$image</td>"; 294 echo "<td valign=\"top\" style=\"width:300\">"; 295 echo " <a title=\"$mod->modfullname\""; 296 echo " href=\"../mod/$mod->modname/view.php?id=$mod->id\">".format_string($instance->name,true)."</a></td>"; 297 echo "<td> </td>"; 298 echo "<td valign=\"top\">"; 299 if (isset($result->info)) { 300 echo "$result->info"; 301 } else { 302 echo "<p style=\"text-align:center\">-</p>"; 303 } 304 echo "</td>"; 305 echo "<td> </td>"; 306 if (!empty($result->time)) { 307 $timeago = format_time(time() - $result->time); 308 echo "<td valign=\"top\" style=\"white-space: nowrap\">".userdate($result->time)." ($timeago)</td>"; 309 } 310 echo "</tr>"; 311 } 312 313 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |