Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / course / report / outline / index.php
blob989543970fd2b4c36d8877334225095ec98a21ae
1 <?php // $Id$
3 // Display user activity reports for a course (totals)
5 require_once('../../../config.php');
6 require_once($CFG->dirroot.'/course/lib.php');
8 $id = required_param('id',PARAM_INT); // course id
10 if (!$course = get_record('course', 'id', $id)) {
11 error('Course id is incorrect.');
14 require_login($course);
15 require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id));
17 add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id);
19 $stractivityreport = get_string('activityreport');
20 $stractivity = get_string('activity');
21 $strlast = get_string('lastaccess');
22 $strreports = get_string('reports');
23 $strviews = get_string('views');
25 $navlinks = array();
26 $navlinks[] = array('name' => $strreports, 'link' => "../../report.php?id=$course->id", 'type' => 'misc');
27 $navlinks[] = array('name' => $stractivityreport, 'link' => null, 'type' => 'misc');
28 $navigation = build_navigation($navlinks);
30 print_header("$course->shortname: $stractivityreport", $course->fullname, $navigation);
32 print_heading(format_string($course->fullname));
34 if (!$logstart = get_field_sql("SELECT MIN(time) FROM {$CFG->prefix}log")) {
35 error('Logs not available');
38 echo '<div class="loginfo">'.get_string('computedfromlogs', 'admin', userdate($logstart)).'</div>';
40 echo '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5"><tr>';
41 echo '<th class="header c0" scope="col">'.$stractivity.'</th>';
42 echo '<th class="header c1" scope="col">'.$strviews.'</th>';
43 echo '<th class="header c2" scope="col">'.$strlast.'</th>';
44 echo '</tr>';
46 $modinfo = get_fast_modinfo($course);
48 $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
49 FROM {$CFG->prefix}course_modules cm
50 JOIN {$CFG->prefix}modules m ON m.id = cm.module
51 JOIN {$CFG->prefix}log l ON l.cmid = cm.id
52 WHERE cm.course = $course->id AND l.action LIKE 'view%' AND m.visible = 1
53 GROUP BY cm.id";
54 $views = get_records_sql($sql);
56 $ri = 0;
57 $prevsecctionnum = 0;
58 foreach ($modinfo->sections as $sectionnum=>$section) {
59 foreach ($section as $cmid) {
60 $cm = $modinfo->cms[$cmid];
61 if ($cm->modname == 'label') {
62 continue;
64 if (!$cm->uservisible) {
65 continue;
67 if ($prevsecctionnum != $sectionnum) {
68 echo '<tr class="r'.$ri++.' section"><td colspan="3"><h3>';
69 switch ($course->format) {
70 case 'weeks': print_string('week'); break;
71 case 'topics': print_string('topic'); break;
72 default: print_string('section'); break;
74 echo ' '.$sectionnum.'</h3></td></tr>';
76 $prevsecctionnum = $sectionnum;
79 $dimmed = $cm->visible ? '' : 'class="dimmed"';
80 $modulename = get_string('modulename', $cm->modname);
81 echo '<tr class="r'.$ri++.'">';
82 echo "<td class=\"cell c0 actvity\"><img src=\"$CFG->modpixpath/$cm->modname/icon.gif\" class=\"icon\" alt=\"$modulename\" />";
83 echo "<a $dimmed title=\"$modulename\" href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\">".format_string($cm->name)."</a></td>";
84 echo "<td class=\"cell c1 numviews\">";
85 if (!empty($views[$cm->id]->numviews)) {
86 echo $views[$cm->id]->numviews;
87 } else {
88 echo '-';
90 echo "</td>";
91 echo "<td class=\"cell c2 lastaccess\">";
92 if (isset($views[$cm->id]->lasttime)) {
93 $timeago = format_time(time() - $views[$cm->id]->lasttime);
94 echo userdate($views[$cm->id]->lasttime)." ($timeago)";
96 echo "</td>";
97 echo '</tr>';
100 echo '</table>';
102 print_footer($course);