forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recent.php
323 lines (252 loc) · 11.8 KB
/
recent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php // $Id$
// Display all recent activity in a flexible way
require_once("../config.php");
require_once("lib.php");
$id = required_param('id', PARAM_INT);
$user = optional_param('user', '0', PARAM_INT);
$sortby = optional_param('sortby', 'default', PARAM_ALPHA);
$selectedgroup = optional_param('selectedgroup', 0, PARAM_INT);
$date = optional_param('date', '', PARAM_INT);
$advancedfilter = optional_param('advancedfilter', 0, PARAM_INT);
$modname = optional_param('modname', '', PARAM_ALPHA); // not used??
$modid = optional_param('modid', 'activity/All', PARAM_FILE); // not a file, but looks like it anyway
$modaction = optional_param('modaction', '', PARAM_ALPHA); // not used??
$chooserecent = optional_param('chooserecent', 0, PARAM_INT);
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
require_login($course->id);
add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", "$course->id");
$strrecentactivity = get_string("recentactivity");
$meta = '<meta name="robots" content="none" />'; // prevent duplicate content in search engines MDL-7299
$loggedinas = user_login_string($course, $USER);
if (!empty($chooserecent)) {
$userinfo = get_string("allparticipants");
$dateinfo = get_string("alldays");
if ($user) {
if (!$u = get_record("user", "id", $user) ) {
error("That's an invalid user!");
}
$userinfo = fullname($u);
}
if ($date)
$dateinfo = userdate($date, get_string("strftimedaydate"));
if ($course->id != SITEID) {
print_header("$course->shortname: $strrecentactivity", "$course->fullname",
"<a href=\"view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"recent.php?id=$course->id\">$strrecentactivity</a> -> $userinfo, $dateinfo", "", $meta);
} else {
print_header("$course->shortname: $strrecentactivity", "$course->fullname",
"<a href=\"recent.php?id=$course->id\">$strrecentactivity</a> -> $userinfo, $dateinfo", "", $meta);
}
print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")", '', 3);
$advancedfilter = 1;
print_recent_selector_form($course, $advancedfilter, $user, $date, $modname, $modid, $modaction, $selectedgroup, $sortby);
} else {
if (empty($date)) { // no date picked, default to last login time
$date = time() - COURSE_MAX_RECENT_PERIOD;
if (!empty($USER->lastcourseaccess[$course->id])) {
if ($USER->lastcourseaccess[$course->id] > $date) {
$date = $USER->lastcourseaccess[$course->id];
}
}
}
if ($course->id != SITEID) {
print_header("$course->shortname: $strrecentactivity", "$course->fullname",
"<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $strrecentactivity", "", $meta);
} else {
print_header("$course->shortname: $strrecentactivity", "$course->fullname",
"$strrecentactivity", "", $meta);
}
print_heading(get_string("activitysince", "", userdate($date)));
print_recent_selector_form($course, $advancedfilter);
}
$tmpmodid = $modid;
switch ($tmpmodid) {
case "activity/Assignments" : $filter = "assignment"; break;
case "activity/Chats" : $filter = "chat"; break;
case "activity/Forums" : $filter = "forum"; break;
case "activity/Quizzes" : $filter = "quiz"; break;
case "activity/Workshops" : $filter = "workshop"; break;
default : $filter = "";
}
$activities = array();
$sections = array();
switch ($course->format) {
case "weeks": $sectiontitle = get_string("week"); break;
case "topics": $sectiontitle = get_string("topic"); break;
default: $sectiontitle = get_string("section"); break;
}
$index = 0;
if (is_numeric($modid)) { // you chose a single activity
$sections[0]->sequence = "$modid";
} else { // you chose a group of activities
if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
$hiddenfilter = "";
} else {
$hiddenfilter = " AND cs.visible = '1' ";
}
$sections = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
FROM {$CFG->prefix}course_sections cs
WHERE course = '$course->id' $hiddenfilter
ORDER by section");
}
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
if (!empty($sections)) {
echo "<hr />";
$i = 0;
if (!empty($filter)) {
$activityfilter = "AND m.name = '$filter'";
} else {
$activityfilter = "";
}
if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
$hiddenfilter = "";
} else {
$hiddenfilter = " AND cm.visible = '1' ";
}
foreach ($sections as $section) {
if ($i <= $course->numsections) {
$activity = new Object;
$activity->type = "section";
if ($i) {
$activity->name = $sectiontitle . " $i";
} else {
$activity->name = '';
}
$activity->visible = $section->visible;
$activities[$index] = $activity;
}
$index++;
$i++;
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $sectionmod) {
if (empty($mods[$sectionmod])) {
continue;
}
$mod = $mods[$sectionmod];
$instance = get_record("$mod->modname", "id", "$mod->instance");
$coursemod = get_record_sql("SELECT m.id, m.name, cm.groupmode, cm.visible
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}modules m
WHERE course = '$course->id' $hiddenfilter
AND m.id = cm.module $activityfilter
AND cm.id = '$sectionmod'");
$groupmode = groupmode($course, $coursemod);
switch ($groupmode) {
case SEPARATEGROUPS : $groupid = mygroupid($course->id); break;
case VISIBLEGROUPS : $groupid = $selectedgroup; break;
case NOGROUPS :
default : $groupid = 0;
}
$libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php";
if (file_exists($libfile)) {
require_once($libfile);
$get_recent_mod_activity = $coursemod->name."_get_recent_mod_activity";
if (function_exists($get_recent_mod_activity)) {
$activity = new Object;
$activity->type = "activity";
$activity->name = $instance->name;
$activity->visible = $coursemod->visible;
$activity->content->modfullname = $mod->modfullname;
$activity->content->modname = $mod->modname;
$activity->content->modid =$mod->id;
$activities[$index] = $activity;
$index++;
$get_recent_mod_activity($activities, $index, $date, $course->id, $sectionmod, $user, $groupid);
}
}
}
}
}
$detail = true;
switch ($sortby) {
case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break;
case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break;
case "default" :
default : $detail = false; $sortby = "default";
}
if (!empty($activities)) {
$newsection = true;
$lastsection = "";
$newinstance = true;
$lastinstance = "";
$inbox = false;
$section = 0;
if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
$teacher = true;
} else {
$teacher = false;
}
$activity_count = count($activities);
foreach ($activities as $key => $activity) {
// peak at next activity. If it's another section, don't print this one!
// this means there are no activities in the current section
if (($activity->type == "section") &&
(($activity_count == ($key + 1)) ||
($activities[$key+1]->type == "section"))) {
continue;
}
if (($activity->type == "section") && ($sortby == "default")) {
if ($inbox) {
print_simple_box_end();
print_spacer(30);
}
print_simple_box_start("center", "90%");
echo "<h2>$activity->name</h2>";
$inbox = true;
} else if ($activity->type == "activity") {
if ($sortby == "default") {
if ($teacher && $activity->visible == 0) {
$linkformat = 'class="dimmed"';
} else {
$linkformat = '';
}
$image = "<img src=\"$CFG->modpixpath/" . $activity->content->modname . "/icon.gif\"" .
" class=\"icon\" alt=\"" . $activity->content->modfullname . "\" />";
echo "<ul><h4>$image " . $activity->content->modfullname .
" <a href=\"$CFG->wwwroot/mod/" . $activity->content->modname . "/view.php?" .
"id=" . $activity->content->modid . "\" $linkformat>" .
format_string($activity->name,true) . "</a></h4></ul>";
}
} else {
if (!$inbox) {
print_simple_box_start("center", "90%");
$inbox = true;
}
$print_recent_mod_activity = $activity->type."_print_recent_mod_activity";
if (function_exists($print_recent_mod_activity)) {
echo '<ul><ul>';
$print_recent_mod_activity($activity, $course->id, $detail);
echo '</ul></ul>';
}
}
}
if ($inbox) {
print_simple_box_end();
}
} else {
echo "<h4><center>" . get_string("norecentactivity") . "</center></h2>";
}
// fix modid for selection form
$modid =$tmpmodid;
print_footer($course);
function compare_activities_by_time_desc($a, $b) {
// make sure the activities actually have a timestamp property
if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
return 0;
}
if ($a->timestamp == $b->timestamp)
return 0;
return ($a->timestamp > $b->timestamp) ? -1 : 1;
}
function compare_activities_by_time_asc($a, $b) {
// make sure the activities actually have a timestamp property
if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
return 0;
}
if ($a->timestamp == $b->timestamp)
return 0;
return ($a->timestamp < $b->timestamp) ? -1 : 1;
}
?>