Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / course / recent.php
blobaf2f60f1aeda72f8eac947a2f0f29208ed447b8e
1 <?php // $Id$
3 // Display all recent activity in a flexible way
5 require_once("../config.php");
6 require_once("lib.php");
8 $id = required_param('id', PARAM_INT);
9 $user = optional_param('user', '0', PARAM_INT);
10 $sortby = optional_param('sortby', 'default', PARAM_ALPHA);
11 $selectedgroup = optional_param('selectedgroup', 0, PARAM_INT);
12 $date = optional_param('date', '', PARAM_INT);
13 $advancedfilter = optional_param('advancedfilter', 0, PARAM_INT);
14 $modname = optional_param('modname', '', PARAM_ALPHA); // not used??
15 $modid = optional_param('modid', 'activity/All', PARAM_FILE); // not a file, but looks like it anyway
16 $modaction = optional_param('modaction', '', PARAM_ALPHA); // not used??
17 $chooserecent = optional_param('chooserecent', 0, PARAM_INT);
19 if (! $course = get_record("course", "id", $id) ) {
20 error("That's an invalid course id");
23 require_login($course->id);
25 add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", "$course->id");
27 $strrecentactivity = get_string("recentactivity");
28 $meta = '<meta name="robots" content="none" />'; // prevent duplicate content in search engines MDL-7299
30 $loggedinas = user_login_string($course, $USER);
33 if (!empty($chooserecent)) {
34 $userinfo = get_string("allparticipants");
35 $dateinfo = get_string("alldays");
37 if ($user) {
38 if (!$u = get_record("user", "id", $user) ) {
39 error("That's an invalid user!");
41 $userinfo = fullname($u);
43 if ($date)
44 $dateinfo = userdate($date, get_string("strftimedaydate"));
46 if ($course->id != SITEID) {
47 print_header("$course->shortname: $strrecentactivity", $course->fullname,
48 "<a href=\"view.php?id=$course->id\">$course->shortname</a> ->
49 <a href=\"recent.php?id=$course->id\">$strrecentactivity</a> -> $userinfo, $dateinfo", "", $meta);
50 } else {
51 print_header("$course->shortname: $strrecentactivity", $course->fullname,
52 "<a href=\"recent.php?id=$course->id\">$strrecentactivity</a> -> $userinfo, $dateinfo", "", $meta);
55 print_heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")", '', 3);
56 $advancedfilter = 1;
57 print_recent_selector_form($course, $advancedfilter, $user, $date, $modname, $modid, $modaction, $selectedgroup, $sortby);
59 } else {
61 if (empty($date)) { // no date picked, default to last login time
62 $date = time() - COURSE_MAX_RECENT_PERIOD;
64 if (!empty($USER->lastcourseaccess[$course->id])) {
65 if ($USER->lastcourseaccess[$course->id] > $date) {
66 $date = $USER->lastcourseaccess[$course->id];
71 if ($course->id != SITEID) {
72 print_header("$course->shortname: $strrecentactivity", $course->fullname,
73 "<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $strrecentactivity", "", $meta);
74 } else {
75 print_header("$course->shortname: $strrecentactivity", $course->fullname,
76 "$strrecentactivity", "", $meta);
79 print_heading(get_string("activitysince", "", userdate($date)));
81 print_recent_selector_form($course, $advancedfilter);
85 $tmpmodid = $modid;
87 switch ($tmpmodid) {
88 case "activity/Assignments" : $filter = "assignment"; break;
89 case "activity/Chats" : $filter = "chat"; break;
90 case "activity/Forums" : $filter = "forum"; break;
91 case "activity/Quizzes" : $filter = "quiz"; break;
92 case "activity/Workshops" : $filter = "workshop"; break;
93 default : $filter = "";
96 $activities = array();
97 $sections = array();
99 switch ($course->format) {
100 case "weeks": $sectiontitle = get_string("week"); break;
101 case "topics": $sectiontitle = get_string("topic"); break;
102 default: $sectiontitle = get_string("section"); break;
105 $index = 0;
107 if (is_numeric($modid)) { // you chose a single activity
109 $sections[0]->sequence = "$modid";
111 } else { // you chose a group of activities
113 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
114 $hiddenfilter = "";
115 } else {
116 $hiddenfilter = " AND cs.visible = '1' ";
119 $sections = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
120 FROM {$CFG->prefix}course_sections cs
121 WHERE course = '$course->id' $hiddenfilter
122 ORDER by section");
125 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
127 if (!empty($sections)) {
129 echo "<hr />";
130 $i = 0;
132 if (!empty($filter)) {
133 $activityfilter = "AND m.name = '$filter'";
134 } else {
135 $activityfilter = "";
138 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
139 $hiddenfilter = "";
140 } else {
141 $hiddenfilter = " AND cm.visible = '1' ";
144 foreach ($sections as $section) {
146 if ($i <= $course->numsections) {
147 $activity = new Object;
148 $activity->type = "section";
149 if ($i) {
150 $activity->name = $sectiontitle . " $i";
151 } else {
152 $activity->name = '';
154 $activity->visible = $section->visible;
155 $activities[$index] = $activity;
157 $index++;
158 $i++;
160 $sectionmods = explode(",", $section->sequence);
162 foreach ($sectionmods as $sectionmod) {
164 if (empty($mods[$sectionmod])) {
165 continue;
167 $mod = $mods[$sectionmod];
168 $instance = get_record("$mod->modname", "id", "$mod->instance");
170 $coursemod = get_record_sql("SELECT m.id, m.name, cm.groupmode, cm.visible
171 FROM {$CFG->prefix}course_modules cm,
172 {$CFG->prefix}modules m
173 WHERE course = '$course->id' $hiddenfilter
174 AND m.id = cm.module $activityfilter
175 AND cm.id = '$sectionmod'");
177 $groupmode = groupmode($course, $coursemod);
178 switch ($groupmode) {
179 case SEPARATEGROUPS : $groupid = mygroupid($course->id); break;
180 case VISIBLEGROUPS : $groupid = $selectedgroup; break;
181 case NOGROUPS :
182 default : $groupid = 0;
185 $libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php";
187 if (file_exists($libfile)) {
188 require_once($libfile);
189 $get_recent_mod_activity = $coursemod->name."_get_recent_mod_activity";
191 if (function_exists($get_recent_mod_activity)) {
192 $activity = new Object;
193 $activity->type = "activity";
194 $activity->name = $instance->name;
195 $activity->visible = $coursemod->visible;
196 $activity->content->modfullname = $mod->modfullname;
197 $activity->content->modname = $mod->modname;
198 $activity->content->modid =$mod->id;
199 $activities[$index] = $activity;
200 $index++;
201 $get_recent_mod_activity($activities, $index, $date, $course->id, $sectionmod, $user, $groupid);
208 $detail = true;
210 switch ($sortby) {
211 case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break;
212 case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break;
213 case "default" :
214 default : $detail = false; $sortby = "default";
218 if (!empty($activities)) {
220 $newsection = true;
221 $lastsection = "";
222 $newinstance = true;
223 $lastinstance = "";
224 $inbox = false;
226 $section = 0;
228 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
229 $teacher = true;
230 } else {
231 $teacher = false;
233 $activity_count = count($activities);
235 foreach ($activities as $key => $activity) {
237 // peak at next activity. If it's another section, don't print this one!
238 // this means there are no activities in the current section
239 if (($activity->type == "section") &&
240 (($activity_count == ($key + 1)) ||
241 ($activities[$key+1]->type == "section"))) {
243 continue;
247 if (($activity->type == "section") && ($sortby == "default")) {
248 if ($inbox) {
249 print_simple_box_end();
250 print_spacer(30);
252 print_simple_box_start("center", "90%");
253 echo "<h2>$activity->name</h2>";
254 $inbox = true;
256 } else if ($activity->type == "activity") {
258 if ($sortby == "default") {
259 if ($teacher && $activity->visible == 0) {
260 $linkformat = 'class="dimmed"';
261 } else {
262 $linkformat = '';
264 $image = "<img src=\"$CFG->modpixpath/" . $activity->content->modname . "/icon.gif\"" .
265 " class=\"icon\" alt=\"" . $activity->content->modfullname . "\" />";
266 echo "<ul><h4>$image " . $activity->content->modfullname .
267 " <a href=\"$CFG->wwwroot/mod/" . $activity->content->modname . "/view.php?" .
268 "id=" . $activity->content->modid . "\" $linkformat>" .
269 format_string($activity->name,true) . "</a></h4></ul>";
272 } else {
274 if (!$inbox) {
275 print_simple_box_start("center", "90%");
276 $inbox = true;
279 $print_recent_mod_activity = $activity->type."_print_recent_mod_activity";
281 if (function_exists($print_recent_mod_activity)) {
282 echo '<ul><ul>';
283 $print_recent_mod_activity($activity, $course->id, $detail);
284 echo '</ul></ul>';
289 if ($inbox) {
290 print_simple_box_end();
294 } else {
296 echo "<h4><center>" . get_string("norecentactivity") . "</center></h2>";
299 // fix modid for selection form
300 $modid =$tmpmodid;
302 print_footer($course);
304 function compare_activities_by_time_desc($a, $b) {
305 // make sure the activities actually have a timestamp property
306 if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
307 return 0;
309 if ($a->timestamp == $b->timestamp)
310 return 0;
311 return ($a->timestamp > $b->timestamp) ? -1 : 1;
314 function compare_activities_by_time_asc($a, $b) {
315 // make sure the activities actually have a timestamp property
316 if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
317 return 0;
319 if ($a->timestamp == $b->timestamp)
320 return 0;
321 return ($a->timestamp < $b->timestamp) ? -1 : 1;