e4027ac9 |
1 | <?php // $Id$ |
97c270e9 |
2 | // Library of useful functions |
f9903ed0 |
3 | |
f9903ed0 |
4 | |
3d891989 |
5 | if (defined('COURSE_MAX_LOG_DISPLAY')) { // Being included again - should never happen!! |
9ae687af |
6 | return; |
7 | } |
8 | |
3d891989 |
9 | define('COURSE_MAX_LOG_DISPLAY', 150); // days |
d9d1c35d |
10 | |
3d891989 |
11 | define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records |
1c0200e0 |
12 | |
3d891989 |
13 | define('COURSE_LIVELOG_REFRESH', 60); // Seconds |
87ffed0d |
14 | |
9e51847a |
15 | define('COURSE_MAX_RECENT_PERIOD', 172800); // Two days, in seconds |
cb29b020 |
16 | |
17 | define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses |
ef58b822 |
18 | |
60fdc714 |
19 | define('COURSE_MAX_COURSES_PER_DROPDOWN',5000); // max courses in log dropdown before switching to optional |
20 | |
21 | define('COURSE_MAX_USERS_PER_DROPDOWN',5000); // max users in log dropdown before switching to optional |
22 | |
c2cb4545 |
23 | define("FRONTPAGENEWS", 0); |
24 | define("FRONTPAGECOURSELIST", 1); |
25 | define("FRONTPAGECATEGORYNAMES", 2); |
5eafd948 |
26 | define("FRONTPAGETOPICONLY", 3); |
f9903ed0 |
27 | |
587510be |
28 | function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin", |
4581271a |
29 | $mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") { |
cb83c3cb |
30 | |
31 | global $USER, $CFG; |
32 | |
cb83c3cb |
33 | $isteacher = isteacher($course->id); |
587510be |
34 | if ($advancedfilter) { |
35 | |
36 | // Get all the possible users |
37 | $users = array(); |
89adb174 |
38 | |
65ee9c16 |
39 | if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) { |
587510be |
40 | foreach ($courseusers as $courseuser) { |
41 | $users[$courseuser->id] = fullname($courseuser, $isteacher); |
42 | } |
cb83c3cb |
43 | } |
587510be |
44 | if ($guest = get_guest()) { |
45 | $users[$guest->id] = fullname($guest); |
46 | } |
89adb174 |
47 | |
587510be |
48 | if (isadmin()) { |
49 | if ($ccc = get_records("course", "", "", "fullname")) { |
50 | foreach ($ccc as $cc) { |
51 | if ($cc->category) { |
52 | $courses["$cc->id"] = "$cc->fullname"; |
53 | } else { |
54 | $courses["$cc->id"] = " $cc->fullname (Site)"; |
89adb174 |
55 | } |
587510be |
56 | } |
cb83c3cb |
57 | } |
587510be |
58 | asort($courses); |
59 | } |
4581271a |
60 | |
587510be |
61 | $activities = array(); |
cb83c3cb |
62 | |
587510be |
63 | $selectedactivity = $modid; |
4581271a |
64 | |
587510be |
65 | if ($modinfo = unserialize($course->modinfo)) { |
66 | $section = 0; |
67 | if ($course->format == 'weeks') { // Body |
68 | $strsection = get_string("week"); |
69 | } else { |
70 | $strsection = get_string("topic"); |
cb83c3cb |
71 | } |
cb83c3cb |
72 | |
587510be |
73 | $activities["activity/All"] = "All activities"; |
74 | $activities["activity/Assignments"] = "All assignments"; |
75 | $activities["activity/Chats"] = "All chats"; |
76 | $activities["activity/Forums"] = "All forums"; |
77 | $activities["activity/Quizzes"] = "All quizzes"; |
78 | $activities["activity/Workshops"] = "All workshops"; |
79 | |
80 | $activities["section/individual"] = "------------- Individual Activities --------------"; |
81 | |
82 | foreach ($modinfo as $mod) { |
83 | if ($mod->mod == "label") { |
84 | continue; |
89adb174 |
85 | } |
9c08ad13 |
86 | if (!$mod->visible and !$isteacher) { |
87 | continue; |
88 | } |
89 | |
587510be |
90 | if ($mod->section > 0 and $section <> $mod->section) { |
91 | $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------"; |
92 | } |
93 | $section = $mod->section; |
235a4ee8 |
94 | $mod->name = strip_tags(format_string(urldecode($mod->name),true)); |
587510be |
95 | if (strlen($mod->name) > 55) { |
96 | $mod->name = substr($mod->name, 0, 50)."..."; |
97 | } |
98 | if (!$mod->visible) { |
99 | $mod->name = "(".$mod->name.")"; |
100 | } |
101 | $activities["$mod->cm"] = $mod->name; |
102 | |
103 | if ($mod->cm == $modid) { |
104 | $selectedactivity = "$mod->cm"; |
105 | } |
cb83c3cb |
106 | } |
107 | } |
cb83c3cb |
108 | |
587510be |
109 | $strftimedate = get_string("strftimedate"); |
110 | $strftimedaydate = get_string("strftimedaydate"); |
cb83c3cb |
111 | |
587510be |
112 | asort($users); |
cb83c3cb |
113 | |
587510be |
114 | // Get all the possible dates |
115 | // Note that we are keeping track of real (GMT) time and user time |
116 | // User time is only used in displays - all calcs and passing is GMT |
cb83c3cb |
117 | |
587510be |
118 | $timenow = time(); // GMT |
cb83c3cb |
119 | |
587510be |
120 | // What day is it now for the user, and when is midnight that day (in GMT). |
121 | $timemidnight = $today = usergetmidnight($timenow); |
cb83c3cb |
122 | |
587510be |
123 | $dates = array(); |
124 | $dates["$USER->lastlogin"] = get_string("lastlogin").", ".userdate($USER->lastlogin, $strftimedate); |
125 | $dates["$timemidnight"] = get_string("today").", ".userdate($timenow, $strftimedate); |
cb83c3cb |
126 | |
587510be |
127 | if (!$course->startdate or ($course->startdate > $timenow)) { |
128 | $course->startdate = $course->timecreated; |
129 | } |
cb83c3cb |
130 | |
587510be |
131 | $numdates = 1; |
132 | while ($timemidnight > $course->startdate and $numdates < 365) { |
133 | $timemidnight = $timemidnight - 86400; |
134 | $timenow = $timenow - 86400; |
135 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); |
136 | $numdates++; |
137 | } |
cb83c3cb |
138 | |
96dcfb56 |
139 | if ($selecteddate === "lastlogin") { |
587510be |
140 | $selecteddate = $USER->lastlogin; |
141 | } |
142 | |
143 | echo '<form action="recent.php" method="get">'; |
1c919752 |
144 | echo '<input type="hidden" name="chooserecent" value="1" />'; |
587510be |
145 | echo "<center>"; |
146 | echo "<table>"; |
147 | |
148 | if (isadmin()) { |
149 | echo "<tr><td><b>" . get_string("courses") . "</b></td><td>"; |
150 | choose_from_menu ($courses, "id", $course->id, ""); |
151 | echo "</td></tr>"; |
152 | } else { |
1c919752 |
153 | echo '<input type="hidden" name="id" value="'.$course->id.'" />'; |
587510be |
154 | } |
cb83c3cb |
155 | |
f5ffb87d |
156 | $sortfields = array("default" => get_string("bycourseorder"),"dateasc" => get_string("datemostrecentlast"), "datedesc" => get_string("datemostrecentfirst")); |
4581271a |
157 | |
587510be |
158 | echo "<tr><td><b>" . get_string("participants") . "</b></td><td>"; |
159 | choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); |
160 | echo "</td>"; |
161 | |
1c919752 |
162 | echo '<td align="right"><b>' . get_string("since") . '</b></td><td>'; |
587510be |
163 | choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); |
4581271a |
164 | echo "</td></tr>"; |
4581271a |
165 | |
587510be |
166 | echo "<tr><td><b>" . get_string("activities") . "</b></td><td>"; |
167 | choose_from_menu ($activities, "modid", $selectedactivity, ""); |
168 | echo "</td>"; |
4581271a |
169 | |
1c919752 |
170 | echo '<td align="right"><b>' . get_string("sortby") . "</b></td><td>"; |
587510be |
171 | choose_from_menu ($sortfields, "sortby", $selectedsort, ""); |
172 | echo "</td></tr>"; |
4581271a |
173 | |
587510be |
174 | echo '<tr>'; |
4581271a |
175 | |
587510be |
176 | $groupmode = groupmode($course); |
4581271a |
177 | |
587510be |
178 | if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { |
179 | if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { |
4581271a |
180 | echo '<td><b>'; |
587510be |
181 | if ($groupmode == VISIBLEGROUPS) { |
182 | print_string('groupsvisible'); |
183 | } else { |
184 | print_string('groupsseparate'); |
185 | } |
186 | echo ':</b></td><td>'; |
187 | choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", ""); |
188 | echo '</td>'; |
189 | } |
190 | } |
191 | |
192 | |
1c919752 |
193 | echo '<td colspan="2" align="right">'; |
194 | echo '<input type="submit" value="'.get_string('showrecent').'" />'; |
587510be |
195 | echo "</td></tr>"; |
196 | |
197 | echo "</table>"; |
198 | |
839f2456 |
199 | $advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=0\">" . get_string("normalfilter") . "</a>"; |
587510be |
200 | print_heading($advancedlink); |
201 | echo "</center>"; |
202 | echo "</form>"; |
203 | |
204 | } else { |
205 | |
206 | $day_list = array("1","7","14","21","30"); |
207 | $strsince = get_string("since"); |
208 | $strlastlogin = get_string("lastlogin"); |
209 | $strday = get_string("day"); |
210 | $strdays = get_string("days"); |
211 | |
212 | $heading = ""; |
213 | foreach ($day_list as $count) { |
214 | if ($count == "1") { |
215 | $day = $strday; |
4581271a |
216 | } else { |
587510be |
217 | $day = $strdays; |
4581271a |
218 | } |
3819ed31 |
219 | $tmpdate = time() - ($count * 3600 * 24); |
587510be |
220 | $heading = $heading . |
839f2456 |
221 | "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&date=$tmpdate\"> $count $day</a> | "; |
4581271a |
222 | } |
4581271a |
223 | |
587510be |
224 | $heading = $strsince . ": <a href=\"$CFG->wwwroot/course/recent.php?id=$course->id\">$strlastlogin</a>" . " | " . $heading; |
225 | print_heading($heading); |
4581271a |
226 | |
839f2456 |
227 | $advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&advancedfilter=1\">" . get_string("advancedfilter") . "</a>"; |
587510be |
228 | print_heading($advancedlink); |
229 | |
230 | } |
4581271a |
231 | |
cb83c3cb |
232 | } |
9ae687af |
233 | |
f24cffb9 |
234 | function print_log_selector_form($course, $selecteduser=0, $selecteddate="today", |
60fdc714 |
235 | $modname="", $modid=0, $modaction="", $selectedgroup=-1,$showcourses=0,$showusers=0) { |
f9903ed0 |
236 | |
9481285b |
237 | global $USER, $CFG; |
238 | |
60fdc714 |
239 | // first check to see if we can override showcourses and showusers |
240 | $numcourses = count_records_select("course", "", "COUNT(id)"); |
241 | if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { |
242 | $showcourses = 1; |
243 | } |
244 | |
4920d238 |
245 | |
246 | if ($course->category) { |
247 | if ($selectedgroup) { // If using a group, only get users in that group. |
248 | $courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id'); |
249 | } else { |
250 | $courseusers = get_course_users($course->id, '', '', 'u.id'); |
251 | } |
252 | } else { |
253 | $courseusers = get_site_users('u.lastaccess DESC', 'u.id'); |
60fdc714 |
254 | } |
255 | |
4920d238 |
256 | $numusers = count((array)$courseusers); |
257 | |
258 | |
60fdc714 |
259 | if ($numusers < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { |
260 | $showusers = 1; |
261 | } |
262 | |
263 | |
69c76405 |
264 | /// Setup for group handling. |
2ac64806 |
265 | $isteacher = isteacher($course->id); |
69c76405 |
266 | $isteacheredit = isteacheredit($course->id); |
267 | if ($course->groupmode == SEPARATEGROUPS and !$isteacheredit) { |
268 | $selectedgroup = get_current_group($course->id); |
269 | $showgroups = false; |
270 | } |
271 | else if ($course->groupmode) { |
272 | $selectedgroup = ($selectedgroup == -1) ? get_current_group($course->id) : $selectedgroup; |
273 | $showgroups = true; |
274 | } |
275 | else { |
276 | $selectedgroup = 0; |
277 | $showgroups = false; |
278 | } |
279 | |
f9903ed0 |
280 | // Get all the possible users |
281 | $users = array(); |
720a43ce |
282 | |
60fdc714 |
283 | if ($showusers) { |
284 | if ($course->category) { |
90b127ff |
285 | if ($selectedgroup) { // If using a group, only get users in that group. |
286 | $courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname'); |
60fdc714 |
287 | } else { |
288 | $courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname'); |
289 | } |
65ee9c16 |
290 | } else { |
60fdc714 |
291 | $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname"); |
69c76405 |
292 | } |
1a5ab449 |
293 | |
60fdc714 |
294 | if ($courseusers) { |
295 | foreach ($courseusers as $courseuser) { |
296 | $users[$courseuser->id] = fullname($courseuser, $isteacher); |
297 | } |
298 | } |
299 | if ($guest = get_guest()) { |
300 | $users[$guest->id] = fullname($guest); |
122cffc9 |
301 | } |
1a5ab449 |
302 | } |
720a43ce |
303 | |
60fdc714 |
304 | if (isadmin() && $showcourses) { |
01669f16 |
305 | if ($ccc = get_records("course", "", "", "fullname","id,fullname,category")) { |
720a43ce |
306 | foreach ($ccc as $cc) { |
cfa5d3f2 |
307 | if ($cc->category) { |
308 | $courses["$cc->id"] = "$cc->fullname"; |
309 | } else { |
310 | $courses["$cc->id"] = " $cc->fullname (Site)"; |
311 | } |
720a43ce |
312 | } |
f9903ed0 |
313 | } |
cfa5d3f2 |
314 | asort($courses); |
f9903ed0 |
315 | } |
316 | |
f24cffb9 |
317 | $activities = array(); |
318 | $selectedactivity = ""; |
319 | |
320 | if ($modinfo = unserialize($course->modinfo)) { |
321 | $section = 0; |
322 | if ($course->format == 'weeks') { // Bodgy |
323 | $strsection = get_string("week"); |
324 | } else { |
325 | $strsection = get_string("topic"); |
326 | } |
327 | foreach ($modinfo as $mod) { |
328 | if ($mod->mod == "label") { |
329 | continue; |
330 | } |
331 | if ($mod->section > 0 and $section <> $mod->section) { |
332 | $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------"; |
333 | } |
334 | $section = $mod->section; |
d11c7c9b |
335 | $mod->name = strip_tags(format_string(urldecode($mod->name),true)); |
f24cffb9 |
336 | if (strlen($mod->name) > 55) { |
337 | $mod->name = substr($mod->name, 0, 50)."..."; |
338 | } |
339 | if (!$mod->visible) { |
340 | $mod->name = "(".$mod->name.")"; |
341 | } |
69d79bc3 |
342 | $activities["$mod->cm"] = $mod->name; |
f24cffb9 |
343 | |
344 | if ($mod->cm == $modid) { |
69d79bc3 |
345 | $selectedactivity = "$mod->cm"; |
f24cffb9 |
346 | } |
347 | } |
c80b7585 |
348 | } |
69c76405 |
349 | |
c80b7585 |
350 | if (isadmin() && !$course->category) { |
351 | $activities["site_errors"] = get_string("siteerrors"); |
352 | if ($modid === "site_errors") { |
69c76405 |
353 | $selectedactivity = "site_errors"; |
69c76405 |
354 | } |
f24cffb9 |
355 | } |
69c76405 |
356 | |
dcde9f02 |
357 | $strftimedate = get_string("strftimedate"); |
358 | $strftimedaydate = get_string("strftimedaydate"); |
359 | |
f9903ed0 |
360 | asort($users); |
361 | |
362 | // Get all the possible dates |
9481285b |
363 | // Note that we are keeping track of real (GMT) time and user time |
364 | // User time is only used in displays - all calcs and passing is GMT |
365 | |
366 | $timenow = time(); // GMT |
367 | |
368 | // What day is it now for the user, and when is midnight that day (in GMT). |
9604ccb1 |
369 | $timemidnight = $today = usergetmidnight($timenow); |
9481285b |
370 | |
371 | // Put today up the top of the list |
dcde9f02 |
372 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); |
9481285b |
373 | |
3695f5b4 |
374 | if (!$course->startdate or ($course->startdate > $timenow)) { |
9481285b |
375 | $course->startdate = $course->timecreated; |
376 | } |
f9903ed0 |
377 | |
9481285b |
378 | $numdates = 1; |
379 | while ($timemidnight > $course->startdate and $numdates < 365) { |
f9903ed0 |
380 | $timemidnight = $timemidnight - 86400; |
9481285b |
381 | $timenow = $timenow - 86400; |
dcde9f02 |
382 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); |
9481285b |
383 | $numdates++; |
f9903ed0 |
384 | } |
385 | |
386 | if ($selecteddate == "today") { |
387 | $selecteddate = $today; |
388 | } |
389 | |
21283ddc |
390 | echo "<center>\n"; |
391 | echo "<form action=\"log.php\" method=\"get\">\n"; |
392 | echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; |
393 | echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n"; |
394 | echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n"; |
60fdc714 |
395 | if (isadmin() && $showcourses) { |
849bc02a |
396 | choose_from_menu ($courses, "id", $course->id, ""); |
720a43ce |
397 | } else { |
60fdc714 |
398 | // echo '<input type="hidden" name="id" value="'.$course->id.'" />'; |
399 | $courses = array(); |
400 | $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' (Site) ' : ''); |
401 | choose_from_menu($courses,"id",$course->id,false); |
402 | if (isadmin()) { |
403 | $a->url = "log.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
404 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; |
405 | print_string('logtoomanycourses','moodle',$a); |
406 | } |
720a43ce |
407 | } |
69c76405 |
408 | |
409 | if ($showgroups) { |
6c4e8471 |
410 | if ($cgroups = get_groups($course->id)) { |
411 | foreach ($cgroups as $cgroup) { |
412 | $groups[$cgroup->id] = $cgroup->name; |
413 | } |
414 | } |
415 | else { |
416 | $groups = array(); |
69c76405 |
417 | } |
418 | choose_from_menu ($groups, "group", $selectedgroup, get_string("allgroups") ); |
419 | } |
420 | |
60fdc714 |
421 | if ($showusers) { |
422 | choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); |
423 | } |
424 | else { |
425 | $users = array(); |
426 | if (!empty($selecteduser)) { |
427 | $user = get_record('user','id',$selecteduser); |
428 | $users[$selecteduser] = fullname($user); |
429 | } |
430 | else { |
431 | $users[0] = get_string('allparticipants'); |
432 | } |
433 | choose_from_menu($users,'user',$selecteduser,false); |
434 | $a->url = "log.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
435 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; |
436 | print_string('logtoomanyusers','moodle',$a); |
437 | } |
97c270e9 |
438 | choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); |
69d79bc3 |
439 | choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", ""); |
1c919752 |
440 | echo '<input type="submit" value="'.get_string('showtheselogs').'" />'; |
f24cffb9 |
441 | echo "</form>"; |
442 | echo "</center>"; |
f9903ed0 |
443 | } |
444 | |
600149be |
445 | function make_log_url($module, $url) { |
446 | switch ($module) { |
de2dfe68 |
447 | case "user": |
600149be |
448 | case "course": |
600149be |
449 | case "file": |
450 | case "login": |
451 | case "lib": |
452 | case "admin": |
c3dd5410 |
453 | case "message": |
454 | case "calendar": |
600149be |
455 | return "/$module/$url"; |
456 | break; |
c80b7585 |
457 | case "upload": |
458 | return "$url"; |
459 | break; |
de2dfe68 |
460 | case "library": |
461 | case "": |
462 | return "/"; |
463 | break; |
600149be |
464 | default: |
465 | return "/mod/$module/$url"; |
466 | break; |
467 | } |
468 | } |
469 | |
8f0cd6ef |
470 | function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100, |
69c76405 |
471 | $url="", $modname="", $modid=0, $modaction="", $groupid=0) { |
f24cffb9 |
472 | |
e0161bff |
473 | // It is assumed that $date is the GMT time of midnight for that day, |
474 | // and so the next 86400 seconds worth of logs are printed. |
f9903ed0 |
475 | |
f24cffb9 |
476 | global $CFG, $db; |
47f1da80 |
477 | |
69c76405 |
478 | /// Setup for group handling. |
479 | $isteacher = isteacher($course->id); |
480 | $isteacheredit = isteacheredit($course->id); |
481 | |
482 | /// If the group mode is separate, and this user does not have editing privileges, |
483 | /// then only the user's group can be viewed. |
484 | if ($course->groupmode == SEPARATEGROUPS and !$isteacheredit) { |
485 | $groupid = get_current_group($course->id); |
486 | } |
487 | /// If this course doesn't have groups, no groupid can be specified. |
488 | else if (!$course->groupmode) { |
489 | $groupid = 0; |
490 | } |
491 | |
e0161bff |
492 | $joins = array(); |
a2ab3b05 |
493 | |
e0161bff |
494 | if ($course->category) { |
8f0cd6ef |
495 | $joins[] = "l.course='$course->id'"; |
720a43ce |
496 | } else { |
2eb68e6f |
497 | $courses[0] = ''; |
1a5ab449 |
498 | if ($ccc = get_courses("all", "c.id ASC", "c.id,c.shortname")) { |
720a43ce |
499 | foreach ($ccc as $cc) { |
500 | $courses[$cc->id] = "$cc->shortname"; |
501 | } |
502 | } |
503 | } |
f9903ed0 |
504 | |
c469a7ef |
505 | if ($modname) { |
e0161bff |
506 | $joins[] = "l.module = '$modname'"; |
f24cffb9 |
507 | } |
508 | |
e21922f0 |
509 | if ('site_errors' === $modid) { |
bf35eb15 |
510 | $joins[] = "( l.action='error' OR l.action='infected' )"; |
e21922f0 |
511 | } else if ($modid) { |
512 | $joins[] = "l.cmid = '$modid'"; |
69d79bc3 |
513 | } |
514 | |
515 | if ($modaction) { |
e0161bff |
516 | $joins[] = "l.action = '$modaction'"; |
f24cffb9 |
517 | } |
518 | |
69c76405 |
519 | /// Getting all members of a group. |
520 | if ($groupid and !$user) { |
521 | if ($gusers = get_records('groups_members', 'groupid', $groupid)) { |
522 | $first = true; |
523 | foreach($gusers as $guser) { |
524 | if ($first) { |
525 | $gselect = '(l.userid='.$guser->userid; |
526 | $first = false; |
527 | } |
528 | else { |
529 | $gselect .= ' OR l.userid='.$guser->userid; |
530 | } |
531 | } |
532 | if (!$first) $gselect .= ')'; |
533 | $joins[] = $gselect; |
534 | } |
535 | } |
536 | else if ($user) { |
e0161bff |
537 | $joins[] = "l.userid = '$user'"; |
f9903ed0 |
538 | } |
539 | |
540 | if ($date) { |
541 | $enddate = $date + 86400; |
e0161bff |
542 | $joins[] = "l.time > '$date' AND l.time < '$enddate'"; |
f9903ed0 |
543 | } |
544 | |
2828ff51 |
545 | $selector = ''; |
e0161bff |
546 | for ($i = 0; $i < count($joins); $i++) { |
547 | $selector .= $joins[$i] . (($i == count($joins)-1) ? " " : " AND "); |
548 | } |
549 | |
550 | |
d09f3c80 |
551 | $totalcount = 0; // Initialise |
552 | |
519d369f |
553 | if (!$logs = get_logs($selector, $order, $page*$perpage, $perpage, $totalcount)) { |
f9903ed0 |
554 | notify("No logs found!"); |
555 | print_footer($course); |
556 | exit; |
557 | } |
558 | |
559 | $count=0; |
2eb68e6f |
560 | $ldcache = array(); |
f9903ed0 |
561 | $tt = getdate(time()); |
562 | $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); |
1c0200e0 |
563 | |
dcde9f02 |
564 | $strftimedatetime = get_string("strftimedatetime"); |
2ac64806 |
565 | $isteacher = isteacher($course->id); |
dcde9f02 |
566 | |
21283ddc |
567 | echo "<p align=\"center\">\n"; |
519d369f |
568 | print_string("displayingrecords", "", $totalcount); |
21283ddc |
569 | echo "</p>\n"; |
1c0200e0 |
570 | |
1548978d |
571 | |
8f0cd6ef |
572 | print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&"); |
519d369f |
573 | |
21283ddc |
574 | echo "<table class=\"logtable\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\">\n"; |
575 | echo "<tr>"; |
1548978d |
576 | if ($course->id == SITEID) { |
21283ddc |
577 | echo "<th class=\"c0 header\">".get_string('course')."</th>\n"; |
1548978d |
578 | } |
21283ddc |
579 | echo "<th class=\"c1 header\">".get_string('time')."</th>\n"; |
580 | echo "<th class=\"c2 header\">".get_string('ip_address')."</th>\n"; |
581 | echo "<th class=\"c3 header\">".get_string('fullname')."</th>\n"; |
582 | echo "<th class=\"c4 header\">".get_string('action')."</th>\n"; |
583 | echo "<th class=\"c5 header\">".get_string('info')."</th>\n"; |
584 | echo "</tr>\n"; |
1548978d |
585 | |
586 | $row = 1; |
f9903ed0 |
587 | foreach ($logs as $log) { |
600149be |
588 | |
1548978d |
589 | $row = ($row + 1) % 2; |
590 | |
2eb68e6f |
591 | if (isset($ldcache[$log->module][$log->action])) { |
592 | $ld = $ldcache[$log->module][$log->action]; |
593 | } else { |
1548978d |
594 | $ld = get_record('log_display', 'module', $log->module, 'action', $log->action); |
2eb68e6f |
595 | $ldcache[$log->module][$log->action] = $ld; |
596 | } |
76feee3f |
597 | if ($ld && !empty($log->info)) { |
181b888e |
598 | // ugly hack to make sure fullname is shown correctly |
599 | if (($ld->mtable == 'user') and ($ld->field == 'CONCAT(firstname," ",lastname)')) { |
600 | $log->info = fullname(get_record($ld->mtable, 'id', $log->info), true); |
601 | } else { |
602 | $log->info = get_field($ld->mtable, $ld->field, 'id', $log->info); |
603 | } |
600149be |
604 | } |
605 | |
c8b0a50b |
606 | //Filter log->info |
607 | $log->info = format_string($log->info); |
608 | |
d7d145b1 |
609 | $log->url = strip_tags(urldecode($log->url)); // Some XSS protection |
610 | $log->info = strip_tags(urldecode($log->info)); // Some XSS protection |
6ac98433 |
611 | $log->url = str_replace('&', '&', $log->url); /// XHTML compatibility |
d7d145b1 |
612 | |
1548978d |
613 | echo '<tr class="r'.$row.'">'; |
614 | if ($course->id == SITEID) { |
21283ddc |
615 | echo "<td class=\"r$row c0\" nowrap=\"nowrap\">\n"; |
616 | echo " <a href=\"view.php?id={$log->course}\">".$courses[$log->course]."</a>\n"; |
617 | echo "</td>\n"; |
720a43ce |
618 | } |
21283ddc |
619 | echo "<td class=\"r$row c1\" nowrap=\"nowrap\" align=\"right\">".userdate($log->time, '%a'). |
620 | ' '.userdate($log->time, $strftimedatetime)."</td>\n"; |
621 | echo "<td class=\"r$row c2\" nowrap=\"nowrap\">\n"; |
7eca967c |
622 | link_to_popup_window("/iplookup/index.php?ip=$log->ip&user=$log->userid", 'iplookup',$log->ip, 400, 700); |
21283ddc |
623 | echo "</td>\n"; |
2ac64806 |
624 | $fullname = fullname($log, $isteacher); |
21283ddc |
625 | echo "<td class=\"r$row c3\" nowrap=\"nowrap\">\n"; |
626 | echo " <a href=\"../user/view.php?id={$log->userid}&course={$log->course}\">$fullname</a>\n"; |
627 | echo "</td>\n"; |
628 | echo "<td class=\"r$row c4\" nowrap=\"nowrap\">\n"; |
2eb68e6f |
629 | link_to_popup_window( make_log_url($log->module,$log->url), 'fromloglive',"$log->module $log->action", 400, 600); |
21283ddc |
630 | echo "</td>\n";; |
631 | echo "<td class=\"r$row c5\" nowrap=\"nowrap\">{$log->info}</td>\n"; |
632 | echo "</tr>\n"; |
f9903ed0 |
633 | } |
21283ddc |
634 | echo "</table>\n"; |
519d369f |
635 | |
8f0cd6ef |
636 | print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&"); |
f9903ed0 |
637 | } |
638 | |
639 | |
c2cb4545 |
640 | function print_log_graph($course, $userid=0, $type="course.png", $date=0) { |
641 | global $CFG; |
642 | if (empty($CFG->gdversion)) { |
643 | echo "(".get_string("gdneed").")"; |
d887b5a7 |
644 | } else { |
29b59206 |
645 | echo '<img src="'.$CFG->wwwroot.'/course/loggraph.php?id='.$course->id. |
646 | '&user='.$userid.'&type='.$type.'&date='.$date.'" alt="" />'; |
d887b5a7 |
647 | } |
648 | } |
649 | |
650 | |
0d6b9d4f |
651 | function print_overview($course) { |
652 | |
653 | global $CFG, $USER; |
654 | |
655 | if (!$lastaccess = get_record("user_teachers","userid",$USER->id,"course",$course->id)) { |
656 | if (!$lastaccess = get_record("user_students","userid",$USER->id,"course",$course->id)) { |
657 | return false; |
658 | } |
659 | } |
660 | $lastaccess = $lastaccess->timeaccess; |
661 | |
662 | print_simple_box_start("center", '400', '', 5, "coursebox"); |
663 | print_heading('<a title="'.$course->fullname.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>'); |
664 | if ($mods = get_course_mods($course->id)) { |
665 | foreach ($mods as $mod) { |
666 | if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->modname.'/lib.php')) { |
667 | require_once(dirname(dirname(__FILE__)).'/mod/'.$mod->modname.'/lib.php'); |
668 | $fname = $mod->modname.'_print_overview'; |
669 | if (function_exists($fname)) { |
670 | $fname($course,$mod,$lastaccess); |
671 | } |
672 | } |
673 | } |
674 | } |
675 | print_simple_box_end(); |
676 | } |
677 | |
678 | |
f9903ed0 |
679 | |
600149be |
680 | function print_recent_activity($course) { |
681 | // $course is an object |
89adb174 |
682 | // This function trawls through the logs looking for |
600149be |
683 | // anything new since the user's last login |
684 | |
810393c8 |
685 | global $CFG, $USER, $SESSION; |
600149be |
686 | |
2ac64806 |
687 | $isteacher = isteacher($course->id); |
688 | |
6f80940b |
689 | $timestart = time() - COURSE_MAX_RECENT_PERIOD; |
0f87cb1d |
690 | |
9e51847a |
691 | if (!empty($USER->timeaccess[$course->id])) { |
6f80940b |
692 | if ($USER->timeaccess[$course->id] > $timestart) { |
9e51847a |
693 | $timestart = $USER->timeaccess[$course->id]; |
694 | } |
3d891989 |
695 | } |
0f87cb1d |
696 | |
de785682 |
697 | echo '<div class="activitydate">'; |
27bf9e20 |
698 | echo get_string('activitysince', '', userdate($timestart)); |
de785682 |
699 | echo '</div>'; |
700 | echo '<div class="activityhead">'; |
0f87cb1d |
701 | |
de785682 |
702 | echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>'; |
0f87cb1d |
703 | |
de785682 |
704 | echo '</div>'; |
0f87cb1d |
705 | |
600149be |
706 | |
707 | // Firstly, have there been any new enrolments? |
708 | |
709 | $heading = false; |
710 | $content = false; |
1b5910c4 |
711 | |
6c38b7e0 |
712 | $users = get_recent_enrolments($course->id, $timestart); |
1b5910c4 |
713 | |
6c38b7e0 |
714 | if ($users) { |
27bf9e20 |
715 | echo '<div class="newusers">'; |
6c38b7e0 |
716 | foreach ($users as $user) { |
600149be |
717 | if (! $heading) { |
27bf9e20 |
718 | print_headline(get_string("newusers").':', 3); |
600149be |
719 | $heading = true; |
720 | $content = true; |
721 | } |
2ac64806 |
722 | $fullname = fullname($user, $isteacher); |
27bf9e20 |
723 | echo '<span class="name"><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&course=$course->id\">$fullname</a></span><br />"; |
600149be |
724 | } |
27bf9e20 |
725 | echo '</div>'; |
600149be |
726 | } |
727 | |
1b5910c4 |
728 | // Next, have there been any modifications to the course structure? |
729 | |
27bf9e20 |
730 | $logs = get_records_select('log', "time > '$timestart' AND course = '$course->id' AND |
1b5910c4 |
731 | module = 'course' AND action LIKE '% mod'", "time ASC"); |
732 | |
733 | if ($logs) { |
734 | foreach ($logs as $key => $log) { |
27bf9e20 |
735 | $info = split(' ', $log->info); |
c9f6251e |
736 | |
27bf9e20 |
737 | if ($info[0] == 'label') { // Labels are special activities |
c9f6251e |
738 | continue; |
739 | } |
740 | |
27bf9e20 |
741 | $modname = get_field($info[0], 'name', 'id', $info[1]); |
1b5910c4 |
742 | //Create a temp valid module structure (course,id) |
743 | $tempmod->course = $log->course; |
744 | $tempmod->id = $info[1]; |
745 | //Obtain the visible property from the instance |
746 | $modvisible = instance_is_visible($info[0],$tempmod); |
89adb174 |
747 | |
1b5910c4 |
748 | //Only if the mod is visible |
749 | if ($modvisible) { |
750 | switch ($log->action) { |
27bf9e20 |
751 | case 'add mod': |
752 | $stradded = get_string('added', 'moodle', get_string('modulename', $info[0])); |
5847b267 |
753 | $changelist[$log->info] = array ('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>"); |
1b5910c4 |
754 | break; |
27bf9e20 |
755 | case 'update mod': |
756 | $strupdated = get_string('updated', 'moodle', get_string('modulename', $info[0])); |
757 | if (empty($changelist[$log->info])) { |
5847b267 |
758 | $changelist[$log->info] = array ('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>"); |
1b5910c4 |
759 | } |
760 | break; |
27bf9e20 |
761 | case 'delete mod': |
762 | if (!empty($changelist[$log->info]['operation']) and |
763 | $changelist[$log->info]['operation'] == 'add') { |
764 | $changelist[$log->info] = NULL; |
1b5910c4 |
765 | } else { |
27bf9e20 |
766 | $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $info[0])); |
767 | $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted); |
1b5910c4 |
768 | } |
769 | break; |
600149be |
770 | } |
ef25340c |
771 | } |
772 | } |
773 | } |
774 | |
9c9f7d77 |
775 | if (!empty($changelist)) { |
ef25340c |
776 | foreach ($changelist as $changeinfo => $change) { |
777 | if ($change) { |
778 | $changes[$changeinfo] = $change; |
779 | } |
780 | } |
8a59942e |
781 | if (isset($changes)){ |
782 | if (count($changes) > 0) { |
27bf9e20 |
783 | print_headline(get_string('courseupdates').':', 3); |
8a59942e |
784 | $content = true; |
785 | foreach ($changes as $changeinfo => $change) { |
27bf9e20 |
786 | echo '<p class="activity">'.$change['text'].'</p>'; |
8a59942e |
787 | } |
600149be |
788 | } |
789 | } |
89adb174 |
790 | } |
bf40f9c1 |
791 | |
3869a2ac |
792 | // Now display new things from each module |
600149be |
793 | |
27bf9e20 |
794 | $mods = get_records('modules', 'visible', '1', 'name', 'id, name'); |
0fd7da81 |
795 | |
1b5910c4 |
796 | foreach ($mods as $mod) { // Each module gets it's own logs and prints them |
27bf9e20 |
797 | include_once($CFG->dirroot.'/mod/'.$mod->name.'/lib.php'); |
798 | $print_recent_activity = $mod->name.'_print_recent_activity'; |
1b5910c4 |
799 | if (function_exists($print_recent_activity)) { |
800 | $modcontent = $print_recent_activity($course, $isteacher, $timestart); |
3869a2ac |
801 | if ($modcontent) { |
802 | $content = true; |
600149be |
803 | } |
600149be |
804 | } |
805 | } |
806 | |
807 | if (! $content) { |
27bf9e20 |
808 | echo '<p class="message">'.get_string('nothingnew').'</p>'; |
600149be |
809 | } |
600149be |
810 | } |
811 | |
e1360728 |
812 | |
d897cae4 |
813 | function get_array_of_activities($courseid) { |
89adb174 |
814 | // For a given course, returns an array of course activity objects |
d897cae4 |
815 | // Each item in the array contains he following properties: |
816 | // cm - course module id |
817 | // mod - name of the module (eg forum) |
818 | // section - the number of the section (eg week or topic) |
819 | // name - the name of the instance |
5867bfb5 |
820 | // visible - is the instance visible or not |
86aa7ccf |
821 | // extra - contains extra string to include in any link |
d897cae4 |
822 | |
8dddba42 |
823 | global $CFG; |
824 | |
d897cae4 |
825 | $mod = array(); |
826 | |
9fa49e22 |
827 | if (!$rawmods = get_course_mods($courseid)) { |
d897cae4 |
828 | return NULL; |
829 | } |
830 | |
831 | if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { |
832 | foreach ($sections as $section) { |
74666583 |
833 | if (!empty($section->sequence)) { |
d897cae4 |
834 | $sequence = explode(",", $section->sequence); |
835 | foreach ($sequence as $seq) { |
7af6281f |
836 | if (empty($rawmods[$seq])) { |
837 | continue; |
838 | } |
d897cae4 |
839 | $mod[$seq]->cm = $rawmods[$seq]->id; |
840 | $mod[$seq]->mod = $rawmods[$seq]->modname; |
841 | $mod[$seq]->section = $section->section; |
842 | $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); |
fec5a6a6 |
843 | $mod[$seq]->visible = $rawmods[$seq]->visible; |
86aa7ccf |
844 | $mod[$seq]->extra = ""; |
8dddba42 |
845 | |
846 | $modname = $mod[$seq]->mod; |
847 | $functionname = $modname."_get_coursemodule_info"; |
848 | |
849 | include_once("$CFG->dirroot/mod/$modname/lib.php"); |
850 | |
851 | if (function_exists($functionname)) { |
9d361034 |
852 | if ($info = $functionname($rawmods[$seq])) { |
853 | if (!empty($info->extra)) { |
854 | $mod[$seq]->extra = $info->extra; |
855 | } |
856 | if (!empty($info->icon)) { |
857 | $mod[$seq]->icon = $info->icon; |
858 | } |
c9f6251e |
859 | } |
860 | } |
d897cae4 |
861 | } |
862 | } |
863 | } |
864 | } |
865 | return $mod; |
866 | } |
867 | |
868 | |
869 | |
e1360728 |
870 | |
90845098 |
871 | function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { |
872 | // Returns a number of useful structures for course displays |
7468bf01 |
873 | |
90845098 |
874 | $mods = NULL; // course modules indexed by id |
e0161bff |
875 | $modnames = NULL; // all course module names (except resource!) |
94361e02 |
876 | $modnamesplural= NULL; // all course module names (plural form) |
90845098 |
877 | $modnamesused = NULL; // course module names used |
7468bf01 |
878 | |
9fa49e22 |
879 | if ($allmods = get_records("modules")) { |
90845098 |
880 | foreach ($allmods as $mod) { |
5867bfb5 |
881 | if ($mod->visible) { |
882 | $modnames[$mod->name] = get_string("modulename", "$mod->name"); |
883 | $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); |
884 | } |
90845098 |
885 | } |
886 | asort($modnames); |
887 | } else { |
888 | error("No modules are installed!"); |
889 | } |
890 | |
9fa49e22 |
891 | if ($rawmods = get_course_mods($courseid)) { |
7468bf01 |
892 | foreach($rawmods as $mod) { // Index the mods |
959ae824 |
893 | if (empty($modnames[$mod->modname])) { |
894 | continue; |
895 | } |
7468bf01 |
896 | $mods[$mod->id] = $mod; |
959ae824 |
897 | $mods[$mod->id]->modfullname = $modnames[$mod->modname]; |
898 | if ($mod->visible or isteacher($courseid)) { |
899 | $modnamesused[$mod->modname] = $modnames[$mod->modname]; |
1acfbce5 |
900 | } |
7468bf01 |
901 | } |
c7da6f7a |
902 | if ($modnamesused) { |
903 | asort($modnamesused); |
904 | } |
7468bf01 |
905 | } |
e0161bff |
906 | |
907 | unset($modnames['resource']); |
908 | unset($modnames['label']); |
7468bf01 |
909 | } |
910 | |
9fa49e22 |
911 | |
7468bf01 |
912 | function get_all_sections($courseid) { |
89adb174 |
913 | |
914 | return get_records("course_sections", "course", "$courseid", "section", |
7d99d695 |
915 | "section, id, course, summary, sequence, visible"); |
7468bf01 |
916 | } |
917 | |
b86fc0e2 |
918 | function course_set_display($courseid, $display=0) { |
919 | global $USER; |
920 | |
1066e0dc |
921 | if (empty($USER->id)) { |
b86fc0e2 |
922 | return false; |
923 | } |
924 | |
925 | if ($display == "all" or empty($display)) { |
926 | $display = 0; |
927 | } |
928 | |
929 | if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) { |
930 | set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid); |
931 | } else { |
932 | $record->userid = $USER->id; |
933 | $record->course = $courseid; |
934 | $record->display = $display; |
935 | if (!insert_record("course_display", $record)) { |
936 | notify("Could not save your course display!"); |
937 | } |
938 | } |
939 | |
940 | return $USER->display[$courseid] = $display; // Note: = not == |
941 | } |
942 | |
7d99d695 |
943 | function set_section_visible($courseid, $sectionnumber, $visibility) { |
944 | /// For a given course section, markes it visible or hidden, |
945 | /// and does the same for every activity in that section |
946 | |
947 | if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) { |
948 | set_field("course_sections", "visible", "$visibility", "id", $section->id); |
949 | if (!empty($section->sequence)) { |
950 | $modules = explode(",", $section->sequence); |
951 | foreach ($modules as $moduleid) { |
48e535bc |
952 | set_coursemodule_visible($moduleid, $visibility); |
7d99d695 |
953 | } |
954 | } |
5867bfb5 |
955 | rebuild_course_cache($courseid); |
7d99d695 |
956 | } |
957 | } |
ba2e5d73 |
958 | |
5e367a2d |
959 | |
d897cae4 |
960 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") { |
52dcc2f9 |
961 | /// Prints a section full of activity modules |
7977cffd |
962 | global $CFG, $USER; |
963 | |
3d575e6f |
964 | static $groupbuttons; |
32d03b7b |
965 | static $groupbuttonslink; |
52dcc2f9 |
966 | static $isteacher; |
967 | static $isediting; |
7977cffd |
968 | static $ismoving; |
969 | static $strmovehere; |
970 | static $strmovefull; |
54669989 |
971 | static $strunreadpostsone; |
52dcc2f9 |
972 | |
4877707e |
973 | static $untracked; |
a2d71d8e |
974 | static $usetracking; |
4877707e |
975 | |
a22f8313 |
976 | $labelformatoptions = New stdClass; |
110a32e2 |
977 | |
52dcc2f9 |
978 | if (!isset($isteacher)) { |
9fd9c29b |
979 | $groupbuttons = ($course->groupmode or (!$course->groupmodeforce)); |
32d03b7b |
980 | $groupbuttonslink = (!$course->groupmodeforce); |
52dcc2f9 |
981 | $isteacher = isteacher($course->id); |
52dcc2f9 |
982 | $isediting = isediting($course->id); |
ff0c7de0 |
983 | $ismoving = $isediting && ismoving($course->id); |
3d575e6f |
984 | if ($ismoving) { |
985 | $strmovehere = get_string("movehere"); |
986 | $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); |
987 | } |
94a6a70f |
988 | include_once($CFG->dirroot.'/mod/forum/lib.php'); |
989 | if ($usetracking = forum_tp_can_track_forums()) { |
a2d71d8e |
990 | $strunreadpostsone = get_string('unreadpostsone', 'forum'); |
94a6a70f |
991 | $untracked = forum_tp_get_untracked_forums($USER->id, $course->id); |
a2d71d8e |
992 | } |
7977cffd |
993 | } |
60bd11cf |
994 | $labelformatoptions->noclean = true; |
94361e02 |
995 | |
c408b0c4 |
996 | $modinfo = unserialize($course->modinfo); |
94361e02 |
997 | |
446390fb |
998 | echo '<table width="'.$width.'" class="section">'; |
74666583 |
999 | if (!empty($section->sequence)) { |
94361e02 |
1000 | |
1001 | $sectionmods = explode(",", $section->sequence); |
1002 | |
1003 | foreach ($sectionmods as $modnumber) { |
9ae687af |
1004 | if (empty($mods[$modnumber])) { |
1005 | continue; |
1006 | } |
94361e02 |
1007 | $mod = $mods[$modnumber]; |
c9f6251e |
1008 | |
52dcc2f9 |
1009 | if ($mod->visible or $isteacher) { |
446390fb |
1010 | echo '<tr><td class="activity '.$mod->modname.'">'; |
7977cffd |
1011 | if ($ismoving) { |
1012 | if ($mod->id == $USER->activitycopy) { |
1013 | continue; |
1014 | } |
1c919752 |
1015 | echo '<a title="'.$strmovefull.'"'. |
8b92f5bb |
1016 | ' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.$USER->sesskey.'">'. |
446390fb |
1017 | '<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '. |
1018 | ' alt="'.$strmovehere.'" /></a><br /> |
1c919752 |
1019 | '; |
1acfbce5 |
1020 | } |
7977cffd |
1021 | $instancename = urldecode($modinfo[$modnumber]->name); |
a92d95b1 |
1022 | $instancename = format_string($instancename, true, $course->id); |
c9f6251e |
1023 | |
86aa7ccf |
1024 | if (!empty($modinfo[$modnumber]->extra)) { |
1025 | $extra = urldecode($modinfo[$modnumber]->extra); |
1026 | } else { |
1027 | $extra = ""; |
1028 | } |
c9f6251e |
1029 | |
9d361034 |
1030 | if (!empty($modinfo[$modnumber]->icon)) { |
1031 | $icon = "$CFG->pixpath/".urldecode($modinfo[$modnumber]->icon); |
1032 | } else { |
1033 | $icon = "$CFG->modpixpath/$mod->modname/icon.gif"; |
1034 | } |
1035 | |
aac94fd0 |
1036 | if ($mod->indent) { |
1037 | print_spacer(12, 20 * $mod->indent, false); |
1038 | } |
1039 | |
c9f6251e |
1040 | if ($mod->modname == "label") { |
aac94fd0 |
1041 | if (!$mod->visible) { |
1042 | echo "<span class=\"dimmed_text\">"; |
1043 | } |
179c9a50 |
1044 | echo format_text($extra, FORMAT_HTML, $labelformatoptions); |
aac94fd0 |
1045 | if (!$mod->visible) { |
1046 | echo "</span>"; |
1047 | } |
c9f6251e |
1048 | |
1049 | } else { // Normal activity |
1050 | $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; |
1c919752 |
1051 | echo '<img src="'.$icon.'"'. |
446390fb |
1052 | ' class="activityicon" alt="'.$mod->modfullname.'" />'. |
1053 | ' <a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra. |
1c919752 |
1054 | ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'. |
446390fb |
1055 | $instancename.'</a>'; |
c9f6251e |
1056 | } |
a2d71d8e |
1057 | if ($usetracking && $mod->modname == 'forum') { |
f37da850 |
1058 | $groupmode = groupmode($course, $mod); |
1059 | $groupid = ($groupmode == SEPARATEGROUPS && !isteacheredit($course->id)) ? |
a2d71d8e |
1060 | get_current_group($course->id) : false; |
4877707e |
1061 | |
94a6a70f |
1062 | if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) { |
4877707e |
1063 | $unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid); |
1064 | if ($unread) { |
1065 | echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">'; |
1066 | if ($unread == 1) { |
1067 | echo $strunreadpostsone; |
1068 | } else { |
1069 | print_string('unreadpostsnumber', 'forum', $unread); |
1070 | } |
1071 | echo '</a> </span>'; |
d0388ebe |
1072 | } |
54669989 |
1073 | } |
f37da850 |
1074 | } |
1075 | |
c9f6251e |
1076 | if ($isediting) { |
5f390342 |
1077 | if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource') { |
32d03b7b |
1078 | if (! $mod->groupmodelink = $groupbuttonslink) { |
1079 | $mod->groupmode = $course->groupmode; |
1080 | } |
1081 | |
1082 | } else { |
3d575e6f |
1083 | $mod->groupmode = false; |
1084 | } |
37a88449 |
1085 | echo ' '; |
24e1eae4 |
1086 | echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); |
c9f6251e |
1087 | } |
ffc69cd3 |
1088 | echo "</td>"; |
c9f6251e |
1089 | echo "</tr>"; |
94361e02 |
1090 | } |
94361e02 |
1091 | } |
87d32352 |
1092 | } else { |
1093 | echo "<tr><td></td></tr>"; // needed for XHTML compatibility |
94361e02 |
1094 | } |
7977cffd |
1095 | if ($ismoving) { |
1c919752 |
1096 | echo '<tr><td><a title="'.$strmovefull.'"'. |
8b92f5bb |
1097 | ' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.$USER->sesskey.'">'. |
446390fb |
1098 | '<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '. |
1099 | ' alt="'.$strmovehere.'" /></a></td></tr> |
1c919752 |
1100 | '; |
7977cffd |
1101 | } |
c9f6251e |
1102 | echo "</table>\n\n"; |
a7ad3ea6 |
1103 | } |
1104 | |
5867bfb5 |
1105 | |
cb57e6f4 |
1106 | function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) { |
e0161bff |
1107 | // Prints the menus to add activities and resources |
1108 | |
8b92f5bb |
1109 | global $CFG, $USER; |
6da4b261 |
1110 | static $straddactivity, $stractivities, $straddresource, $resources; |
e0161bff |
1111 | |
1112 | if (!isset($straddactivity)) { |
1113 | $straddactivity = get_string('addactivity'); |
1114 | $straddresource = get_string('addresource'); |
6da4b261 |
1115 | |
1116 | /// Standard resource types |
1117 | require_once("$CFG->dirroot/mod/resource/lib.php"); |
1118 | $resourceraw = resource_get_resource_types(); |
1119 | |
1120 | foreach ($resourceraw as $type => $name) { |
839f2456 |
1121 | $resources["resource&type=$type"] = $name; |
e0161bff |
1122 | } |
e0161bff |
1123 | $resources['label'] = get_string('resourcetypelabel', 'resource'); |
1124 | } |
1125 | |
d33d0cda |
1126 | $output = '<div style="text-align: right">'; |
8b92f5bb |
1127 | $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=$USER->sesskey&add=", |
6da4b261 |
1128 | $resources, "ressection$section", "", $straddresource, 'resource/types', $straddresource, true); |
cb57e6f4 |
1129 | |
1130 | if ($vertical) { |
d33d0cda |
1131 | $output .= '<div>'; |
cb57e6f4 |
1132 | } |
1133 | |
1c46eb03 |
1134 | $output .= ' '; |
8b92f5bb |
1135 | $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=$USER->sesskey&add=", |
6da4b261 |
1136 | $modnames, "section$section", "", $straddactivity, 'mods', $straddactivity, true); |
d33d0cda |
1137 | |
1138 | if ($vertical) { |
1139 | $output .= '</div>'; |
1140 | } |
1141 | |
cb57e6f4 |
1142 | $output .= '</div>'; |
1143 | |
1144 | if ($return) { |
1145 | return $output; |
1146 | } else { |
1147 | echo $output; |
1148 | } |
e0161bff |
1149 | } |
1150 | |
5867bfb5 |
1151 | function rebuild_course_cache($courseid=0) { |
1152 | // Rebuilds the cached list of course activities stored in the database |
1153 | // If a courseid is not specified, then all are rebuilt |
1154 | |
1155 | if ($courseid) { |
1156 | $select = "id = '$courseid'"; |
1157 | } else { |
1158 | $select = ""; |
1159 | } |
1160 | |
1a31c2b3 |
1161 | if ($courses = get_records_select("course", $select,'','id,fullname')) { |
5867bfb5 |
1162 | foreach ($courses as $course) { |
1163 | $modinfo = serialize(get_array_of_activities($course->id)); |
1164 | if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) { |
1165 | notify("Could not cache module information for course '$course->fullname'!"); |
1166 | } |
1167 | } |
1168 | } |
1169 | } |
1170 | |
1171 | |
c2cb4545 |
1172 | |
1173 | function make_categories_list(&$list, &$parents, $category=NULL, $path="") { |
89adb174 |
1174 | /// Given an empty array, this function recursively travels the |
c2cb4545 |
1175 | /// categories, building up a nice list for display. It also makes |
1176 | /// an array that list all the parents for each category. |
1177 | |
1178 | if ($category) { |
1179 | if ($path) { |
e05bcf2f |
1180 | $path = $path.' / '.$category->name; |
c2cb4545 |
1181 | } else { |
e05bcf2f |
1182 | $path = $category->name; |
c2cb4545 |
1183 | } |
1184 | $list[$category->id] = $path; |
1185 | } else { |
1186 | $category->id = 0; |
1187 | } |
1188 | |
e05bcf2f |
1189 | if ($categories = get_categories($category->id)) { // Print all the children recursively |
c2cb4545 |
1190 | foreach ($categories as $cat) { |
1191 | if (!empty($category->id)) { |
3bd4de22 |
1192 | if (isset($parents[$category->id])) { |
2832badf |
1193 | $parents[$cat->id] = $parents[$category->id]; |
1194 | } |
c2cb4545 |
1195 | $parents[$cat->id][] = $category->id; |
1196 | } |
89adb174 |
1197 | make_categories_list($list, $parents, $cat, $path); |
c2cb4545 |
1198 | } |
1199 | } |
1200 | } |
1201 | |
1202 | |
c2cb4545 |
1203 | function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) { |
89adb174 |
1204 | /// Recursive function to print out all the categories in a nice format |
c2cb4545 |
1205 | /// with or without courses included |
9ff5310a |
1206 | global $CFG; |
e05bcf2f |
1207 | |
1208 | if (isset($CFG->max_category_depth) && ($depth >= $CFG->max_category_depth)) { |
1209 | return; |
9ff5310a |
1210 | } |
c2cb4545 |
1211 | |
1212 | if (!$displaylist) { |
e92fe848 |
1213 | make_categories_list($displaylist, $parentslist); |
c2cb4545 |
1214 | } |
1215 | |
1216 | if ($category) { |
3af6e1db |
1217 | if ($category->visible or iscreator()) { |
d2b6ba70 |
1218 | print_category_info($category, $depth); |
c2cb4545 |
1219 | } else { |
1220 | return; // Don't bother printing children of invisible categories |
1221 | } |
89adb174 |
1222 | |
c2cb4545 |
1223 | } else { |
c2cb4545 |
1224 | $category->id = "0"; |
1225 | } |
1226 | |
1227 | if ($categories = get_categories($category->id)) { // Print all the children recursively |
1228 | $countcats = count($categories); |
1229 | $count = 0; |
1230 | $first = true; |
1231 | $last = false; |
1232 | foreach ($categories as $cat) { |
1233 | $count++; |
1234 | if ($count == $countcats) { |
1235 | $last = true; |
1236 | } |
1237 | $up = $first ? false : true; |
1238 | $down = $last ? false : true; |
1239 | $first = false; |
1240 | |
89adb174 |
1241 | print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1); |
c2cb4545 |
1242 | } |
1243 | } |
c2cb4545 |
1244 | } |
1245 | |
1246 | |
d2b6ba70 |
1247 | function print_category_info($category, $depth) { |
1248 | /// Prints the category info in indented fashion |
1249 | /// This function is only used by print_whole_category_list() above |
c2cb4545 |
1250 | |
1251 | global $CFG; |
b48f834c |
1252 | static $strallowguests, $strrequireskey, $strsummary; |
c2cb4545 |
1253 | |
b48f834c |
1254 | if (empty($strsummary)) { |
e05bcf2f |
1255 | $strallowguests = get_string('allowguests'); |
1256 | $strrequireskey = get_string('requireskey'); |
1257 | $strsummary = get_string('summary'); |
b48f834c |
1258 | } |
ba2e5d73 |
1259 | |
e05bcf2f |
1260 | $catlinkcss = $category->visible ? '' : ' class="dimmed" '; |
d5f26b07 |
1261 | |
8ef9cb56 |
1262 | if ($CFG->frontpage == FRONTPAGECOURSELIST) { |
839f2456 |
1263 | $catimage = '<img src="'.$CFG->pixpath.'/i/course.gif" width="16" height="16" border="0" alt="" />'; |
b48f834c |
1264 | } else { |
1265 | $catimage = " "; |
8ef9cb56 |
1266 | } |
b48f834c |
1267 | |
87d32352 |
1268 | echo "\n\n".'<table border="0" cellpadding="3" cellspacing="0" width="100%">'; |
d2b6ba70 |
1269 | |
c2cb4545 |
1270 | if ($CFG->frontpage == FRONTPAGECOURSELIST) { |
19374e76 |
1271 | $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency'); |
b48f834c |
1272 | |
1273 | echo "<tr>"; |
1274 | |
1275 | if ($depth) { |
1276 | $indent = $depth*30; |
1277 | $rows = count($courses) + 1; |
1c919752 |
1278 | echo '<td rowspan="'.$rows.'" valign="top" width="'.$indent.'">'; |
b48f834c |
1279 | print_spacer(10, $indent); |
e05bcf2f |
1280 | echo '</td>'; |
b48f834c |
1281 | } |
89adb174 |
1282 | |
e05bcf2f |
1283 | echo '<td valign="top">'.$catimage.'</td>'; |
290130b3 |
1284 | echo '<td valign="top" width="100%" class="category name">'; |
e05bcf2f |
1285 | echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.$category->name.'</a>'; |
1286 | echo '</td>'; |
290130b3 |
1287 | echo '<td class="category info"> </td>'; |
e05bcf2f |
1288 | echo '</tr>'; |
b48f834c |
1289 | |
9ff5310a |
1290 | if ($courses && !(isset($CFG->max_category_depth)&&($depth>=$CFG->max_category_depth-1))) { |
c2cb4545 |
1291 | foreach ($courses as $course) { |
e05bcf2f |
1292 | $linkcss = $course->visible ? '' : ' class="dimmed" '; |
1293 | echo '<tr><td valign="top" width="30"> '; |
290130b3 |
1294 | echo '</td><td valign="top" width="100%" class="course name">'; |
e05bcf2f |
1295 | echo '<a '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>'; |
290130b3 |
1296 | echo '</td><td align="right" valign="top" nowrap="nowrap" class="course info">'; |
c2cb4545 |
1297 | if ($course->guest ) { |
e05bcf2f |
1298 | echo '<a title="'.$strallowguests.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'; |
1299 | echo '<img hspace="1" alt="'.$strallowguests.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/guest.gif" /></a>'; |
ebe8ddc1 |
1300 | } else { |
e05bcf2f |
1301 | echo '<img alt="" height="16" width="18" border="0" src="'.$CFG->pixpath.'/spacer.gif" />'; |
0c656181 |
1302 | } |
c2cb4545 |
1303 | if ($course->password) { |
e05bcf2f |
1304 | echo '<a title="'.$strrequireskey.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'; |
1305 | echo '<img hspace="1" alt="'.$strrequireskey.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/key.gif" /></a>'; |
ebe8ddc1 |
1306 | } else { |
e05bcf2f |
1307 | echo '<img alt="" height="16" width="18" border="0" src="'.$CFG->pixpath.'/spacer.gif" />'; |
b48f834c |
1308 | } |
1309 | if ($course->summary) { |
e05bcf2f |
1310 | link_to_popup_window ('/course/info.php?id='.$course->id, 'courseinfo', |
1311 | '<img hspace="1" alt="'.$strsummary.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/info.gif" />', |
b48f834c |
1312 | 400, 500, $strsummary); |
ebe8ddc1 |
1313 | } else { |
e05bcf2f |
1314 | echo '<img alt="" height="16" width="18" border="0" src="'.$CFG->pixpath.'/spacer.gif" />'; |
0c656181 |
1315 | } |
e05bcf2f |
1316 | echo '</td></tr>'; |
0c656181 |
1317 | } |
ba2e5d73 |
1318 | } |
d2b6ba70 |
1319 | } else { |
b48f834c |
1320 | |
1321 | if ($depth) { |
1322 | $indent = $depth*20; |
e05bcf2f |
1323 | echo '<td valign="top" width="'.$indent.'">'; |
b48f834c |
1324 | print_spacer(10, $indent); |
e05bcf2f |
1325 | echo '</td>'; |
d2b6ba70 |
1326 | } |
89adb174 |
1327 | |
290130b3 |
1328 | echo '<td valign="top" width="100%" class="category name">'; |
e05bcf2f |
1329 | echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.$category->name.'</a>'; |
1330 | echo '</td>'; |
290130b3 |
1331 | echo '<td valign="top" class="category number">'; |
e05bcf2f |
1332 | if ($category->coursecount) { |
1333 | echo $category->coursecount; |
1334 | } |
1335 | echo '</td></tr>'; |
c2cb4545 |
1336 | } |
e05bcf2f |
1337 | echo '</table>'; |
c2cb4545 |
1338 | } |
1339 | |
c2cb4545 |
1340 | |
c2cb4545 |
1341 | function print_courses($category, $width="100%") { |
1342 | /// Category is 0 (for all courses) or an object |
1343 | |
810393c8 |
1344 | global $CFG; |
c2cb4545 |
1345 | |
1346 | if (empty($category)) { |
90c2ca2e |
1347 | $categories = get_categories(0); // Parent = 0 ie top-level categories only |
1348 | if (count($categories) == 1) { |
1349 | $category = array_shift($categories); |
19374e76 |
1350 | $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency'); |
90c2ca2e |
1351 | } else { |
19374e76 |
1352 | $courses = get_courses('all', 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency'); |
90c2ca2e |
1353 | } |
1354 | unset($categories); |
607809b3 |
1355 | } else { |
c2cb4545 |
1356 | $categories = get_categories($category->id); // sub categories |
19374e76 |
1357 | $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency'); |
c2cb4545 |
1358 | } |
1359 | |
c2cb4545 |
1360 | if ($courses) { |
1361 | foreach ($courses as $course) { |
1362 | print_course($course, $width); |
c2cb4545 |
1363 | } |
1364 | } else { |
1365 | print_heading(get_string("nocoursesyet")); |
1366 | } |
1367 | |
1368 | } |
1369 | |
1370 | |
1371 | function print_course($course, $width="100%") { |
1372 | |
810393c8 |
1373 | global $CFG; |
c2cb4545 |
1374 | |
146bbb8f |
1375 | static $enrol; |
1376 | |
1377 | if (empty($enrol)) { |
1378 | require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php"); |
1379 | $enrol = new enrolment_plugin; |
1380 | } |
1381 | |
810393c8 |
1382 | print_simple_box_start("center", "$width", '', 5, "coursebox"); |
c2cb4545 |
1383 | |
22288704 |
1384 | $linkcss = $course->visible ? "" : " class=\"dimmed\" "; |
1385 | |
c2cb4545 |
1386 | echo "<table width=\"100%\">"; |
e5e81e78 |
1387 | echo '<tr valign="top">'; |
290130b3 |
1388 | echo '<td valign="top" width="50%" class="info">'; |
34b5847a |
1389 | echo '<b><a title="'.get_string('entercourse').'"'. |
e5e81e78 |
1390 | $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. |
34b5847a |
1391 | $course->fullname.'</a></b><br />'; |
c2cb4545 |
1392 | if ($teachers = get_course_teachers($course->id)) { |
290130b3 |
1393 | echo "<span class=\"teachers\">\n"; |
c2cb4545 |
1394 | foreach ($teachers as $teacher) { |
1395 | if ($teacher->authority > 0) { |
1396 | if (!$teacher->role) { |
1397 | $teacher->role = $course->teacher; |
1398 | } |
2ac64806 |
1399 | $fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course |
8bd84b4d |
1400 | echo $teacher->role.': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id. |
1401 | '&course='.SITEID.'">'.$fullname.'</a><br />'; |
c2cb4545 |
1402 | } |
1403 | } |
34b5847a |
1404 | echo "</span>\n"; |
c2cb4545 |
1405 | } |
c2cb4545 |
1406 | |
146bbb8f |
1407 | echo $enrol->get_access_icons($course); |
c2cb4545 |
1408 | |
290130b3 |
1409 | echo '</td><td valign="top" width="50%" class="summary">'; |
9f39c190 |
1410 | $options = NULL; |
1411 | $options->noclean = true; |
34b5847a |
1412 | $options->para = false; |
9f39c190 |
1413 | echo format_text($course->summary, FORMAT_MOODLE, $options, $course->id); |
c2cb4545 |
1414 | echo "</td></tr>"; |
1415 | echo "</table>"; |
1416 | |
1417 | print_simple_box_end(); |
1418 | } |
1419 | |
1420 | |
1421 | function print_my_moodle() { |
1422 | /// Prints custom user information on the home page. |
1423 | /// Over time this can include all sorts of information |
1424 | |
1425 | global $USER, $CFG; |
1426 | |
1427 | if (!isset($USER->id)) { |
1428 | error("It shouldn't be possible to see My Moodle without being logged in."); |
1429 | } |
1430 | |
1431 | if ($courses = get_my_courses($USER->id)) { |
1432 | foreach ($courses as $course) { |
c81696e5 |
1433 | if (!$course->category) { |
1434 | continue; |
1435 | } |
c2cb4545 |
1436 | print_course($course, "100%"); |
c2cb4545 |
1437 | } |
38a10939 |
1438 | |
7f989948 |
1439 | if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed |
1440 | echo "<table width=\"100%\"><tr><td align=\"center\">"; |
1441 | print_course_search("", false, "short"); |
1442 | echo "</td><td align=\"center\">"; |
1443 | print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get"); |
1444 | echo "</td></tr></table>\n"; |
1445 | } |
26330001 |
1446 | } else { |
1447 | if (count_records("course_categories") > 1) { |
cb29b020 |
1448 | print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox"); |
26330001 |
1449 | print_whole_category_list(); |
1450 | print_simple_box_end(); |
1451 | } else { |
1452 | print_courses(0, "100%"); |
1453 | } |
607809b3 |
1454 | } |
2b8cef80 |
1455 | } |
1456 | |
11b0c469 |
1457 | |
a8b56716 |
1458 | function print_course_search($value="", $return=false, $format="plain") { |
38a10939 |
1459 | |
1460 | global $CFG; |
1461 | |
1462 | $strsearchcourses= get_string("searchcourses"); |
1463 | |
1c919752 |
1464 | if ($format == 'plain') { |
87d32352 |
1465 | $output = '<form name="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">'; |
1466 | $output .= '<center><p align="center" class="coursesearchbox">'; |
1467 | $output .= '<input type="text" size="30" name="search" alt="'.$strsearchcourses.'" value="'.$value.'" />'; |
1c919752 |
1468 | $output .= '<input type="submit" value="'.$strsearchcourses.'" />'; |
87d32352 |
1469 | $output .= '</p></center></form>'; |
1c919752 |
1470 | } else if ($format == 'short') { |
87d32352 |
1471 | $output = '<form name="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">'; |
1472 | $output .= '<center><p align="center" class="coursesearchbox">'; |
1473 | $output .= '<input type="text" size="12" name="search" alt="'.$strsearchcourses.'" value="'.$value.'" />'; |
1c919752 |
1474 | $output .= '<input type="submit" value="'.$strsearchcourses.'" />'; |
87d32352 |
1475 | $output .= '</p></center></form>'; |
1c919752 |
1476 | } else if ($format == 'navbar') { |
87d32352 |
1477 | $output = '<form name="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">'; |
1478 | $output .= '<table border="0" cellpadding="0" cellspacing="0"><tr><td nowrap="nowrap">'; |
1479 | $output .= '<input type="text" size="20" name="search" alt="'.$strsearchcourses.'" value="'.$value.'" />'; |
1c919752 |
1480 | $output .= '<input type="submit" value="'.$strsearchcourses.'" />'; |
1c919752 |
1481 | $output .= '</td></tr></table>'; |
87d32352 |
1482 | $output .= '</form>'; |
a8b56716 |
1483 | } |
1484 | |
1485 | if ($return) { |
1486 | return $output; |
1487 | } |
1488 | echo $output; |
38a10939 |
1489 | } |
11b0c469 |
1490 | |
1491 | /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// |
1492 | |
1493 | function add_course_module($mod) { |
11b0c469 |
1494 | |
e5dfd0f3 |
1495 | $mod->added = time(); |
53f4ad2c |
1496 | unset($mod->id); |
11b0c469 |
1497 | |
e5dfd0f3 |
1498 | return insert_record("course_modules", $mod); |
11b0c469 |
1499 | } |
1500 | |
7977cffd |
1501 | function add_mod_to_section($mod, $beforemod=NULL) { |
1502 | /// Given a full mod object with section and course already defined |
1503 | /// If $before is specified, then this is an existing ID which we |
1504 | /// will insert the new module before |
1505 | /// |
1506 | /// Returns the course_sections ID where the mod is inserted |
11b0c469 |
1507 | |
9fa49e22 |
1508 | if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) { |
7977cffd |
1509 | |
1510 | $section->sequence = trim($section->sequence); |
1511 | |
1512 | if (empty($section->sequence)) { |
11b0c469 |
1513 | $newsequence = "$mod->coursemodule"; |
7977cffd |
1514 | |
1515 | } else if ($beforemod) { |
1516 | $modarray = explode(",", $section->sequence); |
1517 | |
1518 | if ($key = array_keys ($modarray, $beforemod->id)) { |
1519 | $insertarray = array($mod->id, $beforemod->id); |
1520 | array_splice($modarray, $key[0], 1, $insertarray); |
1521 | $newsequence = implode(",", $modarray); |
1522 | |
1523 | } else { // Just tack it on the end anyway |
1524 | $newsequence = "$section->sequence,$mod->coursemodule"; |
1525 | } |
1526 | |
1527 | } else { |
1528 | $newsequence = "$section->sequence,$mod->coursemodule"; |
11b0c469 |
1529 | } |
89adb174 |
1530 | |
e5dfd0f3 |
1531 | if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) { |
1532 | return $section->id; // Return course_sections ID that was used. |
11b0c469 |
1533 | } else { |
e5dfd0f3 |
1534 | return 0; |
11b0c469 |
1535 | } |
89adb174 |
1536 | |
11b0c469 |
1537 | } else { // Insert a new record |
e5dfd0f3 |
1538 | $section->course = $mod->course; |
1539 | $section->section = $mod->section; |
1540 | $section->summary = ""; |
1541 | $section->sequence = $mod->coursemodule; |
1542 | return insert_record("course_sections", $section); |
11b0c469 |
1543 | } |
1544 | } |
1545 | |
48e535bc |
1546 | function set_coursemodule_groupmode($id, $groupmode) { |
3d575e6f |
1547 | return set_field("course_modules", "groupmode", $groupmode, "id", $id); |
1548 | } |
1549 | |
48e535bc |
1550 | function set_coursemodule_visible($id, $visible) { |
1551 | $cm = get_record('course_modules', 'id', $id); |
dcd338ff |
1552 | $modulename = get_field('modules', 'name', 'id', $cm->module); |
1553 | if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) { |
1554 | foreach($events as $event) { |
48e535bc |
1555 | if ($visible) { |
1556 | show_event($event); |
1557 | } else { |
1558 | hide_event($event); |
1559 | } |
dcd338ff |
1560 | } |
1561 | } |
48e535bc |
1562 | return set_field("course_modules", "visible", $visible, "id", $id); |
1acfbce5 |
1563 | } |
1564 | |
290130b3 |
1565 | /* |
1566 | * Delete a course module and any associated data at the course level (events) |
1567 | * Until 1.5 this function simply marked a deleted flag ... now it |
1568 | * deletes it completely. |
1569 | * |
1570 | */ |
48e535bc |
1571 | function delete_course_module($id) { |
290130b3 |
1572 | if (!$cm = get_record('course_modules', 'id', $id)) { |
1573 | return true; |
1574 | } |
dcd338ff |
1575 | $modulename = get_field('modules', 'name', 'id', $cm->module); |
1576 | if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) { |
1577 | foreach($events as $event) { |
48e535bc |
1578 | delete_event($event); |
dcd338ff |
1579 | } |
1580 | } |
290130b3 |
1581 | return delete_records('course_modules', 'id', $cm->id); |
11b0c469 |
1582 | } |
1583 | |
1584 | function delete_mod_from_section($mod, $section) { |
11b0c469 |
1585 | |
e5dfd0f3 |
1586 | if ($section = get_record("course_sections", "id", "$section") ) { |
11b0c469 |
1587 | |
e5dfd0f3 |
1588 | $modarray = explode(",", $section->sequence); |
11b0c469 |
1589 | |
1590 | if ($key = array_keys ($modarray, $mod)) { |
1591 | array_splice($modarray, $key[0], 1); |
1592 | $newsequence = implode(",", $modarray); |
e5dfd0f3 |
1593 | return set_field("course_sections", "sequence", $newsequence, "id", $section->id); |
11b0c469 |
1594 | } else { |
1595 | return false; |
1596 | } |
89adb174 |
1597 | |
11b0c469 |
1598 | } |
7977cffd |
1599 | return false; |
11b0c469 |
1600 | } |
1601 | |
12905134 |
1602 | function move_section($course, $section, $move) { |
1603 | /// Moves a whole course section up and down within the course |
798b70a1 |
1604 | global $USER; |
12905134 |
1605 | |
1606 | if (!$move) { |
1607 | return true; |
1608 | } |
1609 | |
1610 | $sectiondest = $section + $move; |
1611 | |
1612 | if ($sectiondest > $course->numsections or $sectiondest < 1) { |
1613 | return false; |
1614 | } |
1615 | |
1616 | if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) { |
1617 | return false; |
1618 | } |
1619 | |
1620 | if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) { |
1621 | return false; |
1622 | } |
1623 | |
56e34ee4 |
1624 | if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) { |
12905134 |
1625 | return false; |
1626 | } |
56e34ee4 |
1627 | if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) { |
12905134 |
1628 | return false; |
1629 | } |
798b70a1 |
1630 | // if the focus is on the section that is being moved, then move the focus along |
1631 | if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) { |
1632 | course_set_display($course->id, $sectiondest); |
1633 | } |
12905134 |
1634 | return true; |
1635 | } |
1636 | |
1637 | |
7977cffd |
1638 | function moveto_module($mod, $section, $beforemod=NULL) { |
1639 | /// All parameters are objects |
1640 | /// Move the module object $mod to the specified $section |
1641 | /// If $beforemod exists then that is the module |
1642 | /// before which $modid should be inserted |
1643 | |
1644 | /// Remove original module from original section |
1645 | |
1646 | if (! delete_mod_from_section($mod->id, $mod->section)) { |
1647 | notify("Could not delete module from existing section"); |
1648 | } |
1649 | |
1650 | /// Update module itself if necessary |
1651 | |
1652 | if ($mod->section != $section->id) { |
89adb174 |
1653 | $mod->section = $section->id; |
7977cffd |
1654 | if (!update_record("course_modules", $mod)) { |
1655 | return false; |
1656 | } |
48e535bc |
1657 | // if moving to a hidden section then hide module |
1658 | if (!$section->visible) { |
1659 | set_coursemodule_visible($mod->id, 0); |
1660 | } |
7977cffd |
1661 | } |
1662 | |
1663 | /// Add the module into the new section |
1664 | |
1665 | $mod->course = $section->course; |
1666 | $mod->section = $section->section; // need relative reference |
1667 | $mod->coursemodule = $mod->id; |
1668 | |
1669 | if (! add_mod_to_section($mod, $beforemod)) { |
1670 | return false; |
1671 | } |
1672 | |
1673 | return true; |
1674 | |
1675 | } |
1676 | |
24e1eae4 |
1677 | function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-1, $section=-1) { |
810393c8 |
1678 | global $CFG, $USER; |
94361e02 |
1679 | |
3d575e6f |
1680 | static $str; |
37a88449 |
1681 | static $sesskey; |
3d575e6f |
1682 | |
1683 | if (!isset($str)) { |
1684 | $str->delete = get_string("delete"); |
1685 | $str->move = get_string("move"); |
1686 | $str->moveup = get_string("moveup"); |
1687 | $str->movedown = get_string("movedown"); |
1688 | $str->moveright = get_string("moveright"); |
1689 | $str->moveleft = get_string("moveleft"); |
1690 | $str->update = get_string("update"); |
d33a2a6f |
1691 | $str->duplicate = get_string("duplicate"); |
3d575e6f |
1692 | $str->hide = get_string("hide"); |
1693 | $str->show = get_string("show"); |
1694 | $str->clicktochange = get_string("clicktochange"); |
32d03b7b |
1695 | $str->forcedmode = get_string("forcedmode"); |
3d575e6f |
1696 | $str->groupsnone = get_string("groupsnone"); |
1697 | $str->groupsseparate = get_string("groupsseparate"); |
1698 | $str->groupsvisible = get_string("groupsvisible"); |
37a88449 |
1699 | $sesskey = sesskey(); |
1acfbce5 |
1700 | } |
94361e02 |
1701 | |
24e1eae4 |
1702 | if ($section >= 0) { |
75f087b6 |
1703 | $section = '&sr='.$section; // Section return |
24e1eae4 |
1704 | } else { |
1705 | $section = ''; |
1706 | } |
1707 | |
94361e02 |
1708 | if ($absolute) { |
37a88449 |
1709 | $path = $CFG->wwwroot.'/course'; |
dc0dc7d5 |
1710 | } else { |
37a88449 |
1711 | $path = '.'; |
dc0dc7d5 |
1712 | } |
1713 | |
3d575e6f |
1714 | if ($mod->visible) { |
37a88449 |
1715 | $hideshow = '<a title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id. |
1716 | '&sesskey='.$sesskey.$section.'"><img'. |
1717 | ' src="'.$CFG->pixpath.'/t/hide.gif" hspace="2" height="11" width="11" '. |
1718 | ' border="0" alt="'.$str->hide.'" /></a> '; |
1acfbce5 |
1719 | } else { |
37a88449 |
1720 | $hideshow = '<a title="'.$str->show.'" href="'.$path.'/mod.php?show='.$mod->id. |
1721 | '&sesskey='.$sesskey.$section.'"><img'. |
1722 | ' src="'.$CFG->pixpath.'/t/show.gif" hspace="2" height="11" width="11" '. |
1723 | ' border="0" alt="'.$str->show.'" /></a> '; |
7977cffd |
1724 | } |
3d575e6f |
1725 | if ($mod->groupmode !== false) { |
1726 | if ($mod->groupmode == SEPARATEGROUPS) { |
32d03b7b |
1727 | $grouptitle = $str->groupsseparate; |
37a88449 |
1728 | $groupimage = $CFG->pixpath.'/t/groups.gif'; |
1729 | $grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=0&sesskey='.$sesskey; |
3d575e6f |
1730 | } else if ($mod->groupmode == VISIBLEGROUPS) { |
32d03b7b |
1731 | $grouptitle = $str->groupsvisible; |
37a88449 |
1732 | $groupimage = $CFG->pixpath.'/t/groupv.gif'; |
1733 | $grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=1&sesskey='.$sesskey; |
32d03b7b |
1734 | } else { |
1735 | $grouptitle = $str->groupsnone; |
37a88449 |
1736 | $groupimage = $CFG->pixpath.'/t/groupn.gif'; |
1737 | $grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=2&sesskey='.$sesskey; |
32d03b7b |
1738 | } |
1739 | if ($mod->groupmodelink) { |
37a88449 |
1740 | $groupmode = '<a title="'.$grouptitle.' ('.$str->clicktochange.')" href="'.$grouplink.'">'. |
1741 | '<img src="'.$groupimage.'" hspace="2" height="11" width="11" '. |
1742 | 'border="0" alt="'.$grouptitle.'" /></a>'; |
3d575e6f |
1743 | } else { |
37a88449 |
1744 | $groupmode = '<img title="'.$grouptitle.' ('.$str->forcedmode.')" '. |
1745 | ' src="'.$groupimage.'" hspace="2" height="11" width="11" '. |
1746 | 'border="0" alt="'.$grouptitle.'" />'; |
3d575e6f |
1747 | } |
1748 | } else { |
1749 | $groupmode = ""; |
1750 | } |
7977cffd |
1751 | |
1752 | if ($moveselect) { |
37a88449 |
1753 | $move = '<a title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id. |
1754 | '&sesskey='.$sesskey.$section.'"><img'. |
1755 | ' src="'.$CFG->pixpath.'/t/move.gif" hspace="2" height="11" width="11" '. |
1756 | ' border="0" alt="'.$str->move.'" /></a>'; |
493486c4 |
1757 | } else { |
37a88449 |
1758 | $move = '<a title="'.$str->moveup.'" href="'.$path.'/mod.php?id='.$mod->id. |
1759 | '&move=-1&sesskey='.$sesskey.$section.'"><img'. |
1760 | ' src="'.$CFG->pixpath.'/t/up.gif" hspace="2" height="11" width="11" '. |
1761 | ' border="0" alt="'.$str->moveup.'" /></a>'. |
1762 | '<a title="'.$str->movedown.'" href="'.$path.'/mod.php?id='.$mod->id. |
1763 | '&move=1&sesskey='.$sesskey.$section.'"><img'. |
1764 | ' src="'.$CFG->pixpath.'/t/down.gif" hspace="2" height="11" width="11" '. |
1765 | ' border="0" alt="'.$str->movedown.'" /></a>'; |
7977cffd |
1766 | } |
1767 | |
aac94fd0 |
1768 | $leftright = ""; |
1769 | if ($indent > 0) { |
37a88449 |
1770 | $leftright .= '<a title="'.$str->moveleft.'" href="'.$path.'/mod.php?id='.$mod->id. |
1771 | '&indent=-1&sesskey='.$sesskey.$section.'"><img'. |
1772 | ' src="'.$CFG->pixpath.'/t/left.gif" hspace="2" height="11" width="11" '. |
1773 | ' border="0" alt="'.$str->moveleft.'" /></a>'; |
aac94fd0 |
1774 | } |
1775 | if ($indent >= 0) { |
37a88449 |
1776 | $leftright .= '<a title="'.$str->moveright.'" href="'.$path.'/mod.php?id='.$mod->id. |
1777 | '&indent=1&sesskey='.$sesskey.$section.'"><img'. |
1778 | ' src="'.$CFG->pixpath.'/t/right.gif" hspace="2" height="11" width="11" '. |
1779 | ' border="0" alt="'.$str->moveright.'" /></a>'; |
1780 | } |
1781 | |
1782 | return '<span class="commands">'.$leftright.$move. |
1783 | '<a title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id. |
1784 | '&sesskey='.$sesskey.$section.'"><img'. |
1785 | ' src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" '. |
1786 | ' alt="'.$str->update.'" /></a>'. |
1787 | '<a title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id. |
1788 | '&sesskey='.$sesskey.$section.'"><img'. |
1789 | ' src="'.$CFG->pixpath.'/t/delete.gif" hspace="2" height="11" width="11" border="0" '. |
1790 | ' alt="'.$str->delete.'" /></a>'.$hideshow.$groupmode.'</span>'; |
90845098 |
1791 | } |
1792 | |
b61efafb |
1793 | /** |
1794 | * given a course object with shortname & fullname, this function will |
1795 | * truncate the the number of chars allowed and add ... if it was too long |
1796 | */ |
1797 | function course_format_name ($course,$max=100) { |
1798 | |
1799 | $str = $course->shortname.': '.$course->fullname; |
1800 | if (strlen($str) <= $max) { |
1801 | return $str; |
1802 | } |
1803 | else { |
1804 | return substr($str,0,$max-3).'...'; |
1805 | } |
1806 | } |
1807 | |
1808 | /** |
1809 | * This function will return true if the given course is a child course at all |
1810 | */ |
1811 | function course_in_meta ($course) { |
5f37b628 |
1812 | return record_exists("course_meta","child_course",$course->id); |
b61efafb |
1813 | } |
1814 | |
48e535bc |
1815 | |
1816 | /** |
1817 | * Print standard form elements on module setup forms in mod/.../mod.html |
1818 | */ |
1819 | function print_standard_coursemodule_settings($form) { |
da2224f8 |
1820 | if (! $course = get_record('course', 'id', $form->course)) { |
1821 | error("This course doesn't exist"); |
1822 | } |
1823 | print_groupmode_setting($form, $course); |
1824 | print_visible_setting($form, $course); |
48e535bc |
1825 | } |
1826 | |
1827 | /** |
1828 | * Print groupmode form element on module setup forms in mod/.../mod.html |
1829 | */ |
5ebb746b |
1830 | function print_groupmode_setting($form, $course=NULL) { |
48e535bc |
1831 | |
5ebb746b |
1832 | if (empty($course)) { |
1833 | if (! $course = get_record('course', 'id', $form->course)) { |
1834 | error("This course doesn't exist"); |
1835 | } |
1836 | } |
48e535bc |
1837 | if ($form->coursemodule) { |
1838 | if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) { |
1839 | error("This course module doesn't exist"); |
1840 | } |
1841 | } else { |
1842 | $cm = null; |
1843 | } |
1844 | $groupmode = groupmode($course, $cm); |
1845 | if ($course->groupmode or (!$course->groupmodeforce)) { |
1846 | echo '<tr valign="top">'; |
1847 | echo '<td align="right"><b>'.get_string('groupmode').':</b></td>'; |
7bbe08a2 |
1848 | echo '<td align="left">'; |
48e535bc |
1849 | unset($choices); |
1850 | $choices[NOGROUPS] = get_string('groupsnone'); |
1851 | $choices[SEPARATEGROUPS] = get_string('groupsseparate'); |
1852 | $choices[VISIBLEGROUPS] = get_string('groupsvisible'); |
1853 | choose_from_menu($choices, 'groupmode', $groupmode, '', '', 0, false, $course->groupmodeforce); |
1854 | helpbutton('groupmode', get_string('groupmode')); |
1855 | echo '</td></tr>'; |
1856 | } |
1857 | } |
1858 | |
1859 | /** |
1860 | * Print visibility setting form element on module setup forms in mod/.../mod.html |
1861 | */ |
5ebb746b |
1862 | function print_visible_setting($form, $course=NULL) { |
1ee55c41 |
1863 | if (empty($course)) { |
1864 | if (! $course = get_record('course', 'id', $form->course)) { |
1865 | error("This course doesn't exist"); |
1866 | } |
1867 | } |
48e535bc |
1868 | if ($form->coursemodule) { |
1869 | $visible = get_field('course_modules', 'visible', 'id', $form->coursemodule); |
1870 | } else { |
1871 | $visible = true; |
1872 | } |
1873 | |
1874 | if ($form->mode == 'add') { // in this case $form->section is the section number, not the id |
1875 | $hiddensection = !get_field('course_sections', 'visible', 'section', $form->section, 'course', $form->course); |
1876 | } else { |
1877 | $hiddensection = !get_field('course_sections', 'visible', 'id', $form->section); |
1878 | } |
1879 | if ($hiddensection) { |
1880 | $visible = false; |
1881 | } |
1882 | |
1883 | echo '<tr valign="top">'; |
1f15db9d |
1884 | echo '<td align="right"><b>'.get_string('visibletostudents','',moodle_strtolower($course->students)).':</b></td>'; |
7bbe08a2 |
1885 | echo '<td align="left">'; |
48e535bc |
1886 | unset($choices); |
1f15db9d |
1887 | $choices[1] = get_string('show'); |
1888 | $choices[0] = get_string('hide'); |
48e535bc |
1889 | choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection); |
1890 | echo '</td></tr>'; |
1891 | } |
1892 | |
87d32352 |
1893 | ?> |