Commit | Line | Data |
---|---|---|
dfab77a2 | 1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This file contains functions used by the log reports | |
20 | * | |
d9cb06dc | 21 | * @package course |
dfab77a2 | 22 | * @copyright 1999 onwards Martin Dougiamas http://moodle.com |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
0a935fb3 | 25 | |
c215b32b | 26 | function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $selecteddate='today', |
27 | $modname="", $modid=0, $modaction='', $selectedgroup=-1, $showcourses=0, $showusers=0, $logformat='showashtml') { | |
28 | ||
928d4738 | 29 | global $USER, $CFG, $SITE, $DB, $OUTPUT, $SESSION; |
c215b32b | 30 | require_once $CFG->dirroot.'/mnet/peer.php'; |
aa6c1ced | 31 | |
c215b32b | 32 | $mnet_peer = new mnet_peer(); |
33 | $mnet_peer->set_id($hostid); | |
34 | ||
29f83769 | 35 | $sql = "SELECT DISTINCT course, hostid, coursename FROM {mnet_log}"; |
36 | $courses = $DB->get_records_sql($sql); | |
c215b32b | 37 | $remotecoursecount = count($courses); |
38 | ||
39 | // first check to see if we can override showcourses and showusers | |
29f83769 | 40 | $numcourses = $remotecoursecount + $DB->count_records('course'); |
c215b32b | 41 | if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { |
42 | $showcourses = 1; | |
43 | } | |
aa6c1ced | 44 | |
09ee7b0d | 45 | $sitecontext = get_context_instance(CONTEXT_SYSTEM); |
aa6c1ced | 46 | |
c215b32b | 47 | // Context for remote data is always SITE |
48 | // Groups for remote data are always OFF | |
49 | if ($hostid == $CFG->mnet_localhost_id) { | |
50 | $context = get_context_instance(CONTEXT_COURSE, $course->id); | |
51 | ||
52 | /// Setup for group handling. | |
53 | if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { | |
928d4738 | 54 | $selectedgroup = -1; |
c215b32b | 55 | $showgroups = false; |
928d4738 | 56 | } else if ($course->groupmode) { |
c215b32b | 57 | $showgroups = true; |
928d4738 | 58 | } else { |
c215b32b | 59 | $selectedgroup = 0; |
60 | $showgroups = false; | |
61 | } | |
62 | ||
928d4738 | 63 | if ($selectedgroup === -1) { |
64 | if (isset($SESSION->currentgroup[$course->id])) { | |
65 | $selectedgroup = $SESSION->currentgroup[$course->id]; | |
66 | } else { | |
67 | $selectedgroup = groups_get_all_groups($course->id, $USER->id); | |
68 | if (is_array($selectedgroup)) { | |
69 | $selectedgroup = array_shift(array_keys($selectedgroup)); | |
70 | $SESSION->currentgroup[$course->id] = $selectedgroup; | |
71 | } else { | |
72 | $selectedgroup = 0; | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
c215b32b | 77 | } else { |
78 | $context = $sitecontext; | |
79 | } | |
80 | ||
81 | // Get all the possible users | |
82 | $users = array(); | |
83 | ||
ae1467bb | 84 | // Define limitfrom and limitnum for queries below |
85 | // If $showusers is enabled... don't apply limitfrom and limitnum | |
86 | $limitfrom = empty($showusers) ? 0 : ''; | |
87 | $limitnum = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : ''; | |
88 | ||
c215b32b | 89 | // If looking at a different host, we're interested in all our site users |
5841aa91 | 90 | if ($hostid == $CFG->mnet_localhost_id && $course->id != SITEID) { |
df997f84 | 91 | $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname, u.idnumber', 'lastname ASC, firstname ASC', $limitfrom, $limitnum); |
c215b32b | 92 | } else { |
79eaec48 | 93 | // this may be a lot of users :-( |
ae1467bb | 94 | $courseusers = $DB->get_records('user', array('deleted'=>0), 'lastaccess DESC', 'id, firstname, lastname, idnumber', $limitfrom, $limitnum); |
c215b32b | 95 | } |
96 | ||
97 | if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { | |
98 | $showusers = 1; | |
99 | } | |
100 | ||
101 | if ($showusers) { | |
102 | if ($courseusers) { | |
103 | foreach ($courseusers as $courseuser) { | |
104 | $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); | |
105 | } | |
106 | } | |
629e12fd | 107 | $users[$CFG->siteguest] = get_string('guestuser'); |
c215b32b | 108 | } |
109 | ||
2c1833bd | 110 | // Get all the hosts that have log records |
111 | $sql = "select distinct | |
112 | h.id, | |
113 | h.name | |
114 | from | |
29f83769 | 115 | {mnet_host} h, |
116 | {mnet_log} l | |
2c1833bd | 117 | where |
118 | h.id = l.hostid | |
119 | order by | |
120 | h.name"; | |
c215b32b | 121 | |
29f83769 | 122 | if ($hosts = $DB->get_records_sql($sql)) { |
dd2a21da | 123 | foreach($hosts as $host) { |
124 | $hostarray[$host->id] = $host->name; | |
125 | } | |
c215b32b | 126 | } |
127 | ||
128 | $hostarray[$CFG->mnet_localhost_id] = $SITE->fullname; | |
129 | asort($hostarray); | |
130 | ||
6770330d PS |
131 | $dropdown = array(); |
132 | ||
c215b32b | 133 | foreach($hostarray as $hostid => $name) { |
134 | $courses = array(); | |
135 | $sites = array(); | |
136 | if ($CFG->mnet_localhost_id == $hostid) { | |
a2e4bf7f | 137 | if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { |
29f83769 | 138 | if ($ccc = $DB->get_records("course", null, "fullname","id,fullname,category")) { |
c215b32b | 139 | foreach ($ccc as $cc) { |
5577ceb3 | 140 | if ($cc->id == SITEID) { |
f054df17 | 141 | $sites["$hostid/$cc->id"] = format_string($cc->fullname).' ('.get_string('site').')'; |
c215b32b | 142 | } else { |
f054df17 | 143 | $courses["$hostid/$cc->id"] = format_string($cc->fullname); |
c215b32b | 144 | } |
145 | } | |
146 | } | |
147 | } | |
148 | } else { | |
a2e4bf7f | 149 | if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { |
29f83769 | 150 | $sql = "SELECT DISTINCT course, coursename FROM {mnet_log} where hostid = ?"; |
151 | if ($ccc = $DB->get_records_sql($sql, array($hostid))) { | |
c215b32b | 152 | foreach ($ccc as $cc) { |
5577ceb3 | 153 | if (1 == $cc->course) { // TODO: this might be wrong - site course may have another id |
154 | $sites["$hostid/$cc->course"] = $cc->coursename.' ('.get_string('site').')'; | |
c215b32b | 155 | } else { |
5577ceb3 | 156 | $courses["$hostid/$cc->course"] = $cc->coursename; |
c215b32b | 157 | } |
158 | } | |
159 | } | |
160 | } | |
161 | } | |
162 | ||
163 | asort($courses); | |
6770330d | 164 | $dropdown[] = array($name=>($sites + $courses)); |
c215b32b | 165 | } |
166 | ||
167 | ||
168 | $activities = array(); | |
169 | $selectedactivity = ""; | |
170 | ||
171 | /// Casting $course->modinfo to string prevents one notice when the field is null | |
172 | if ($modinfo = unserialize((string)$course->modinfo)) { | |
173 | $section = 0; | |
d13864e6 | 174 | $sections = get_all_sections($course->id); |
c215b32b | 175 | foreach ($modinfo as $mod) { |
176 | if ($mod->mod == "label") { | |
177 | continue; | |
178 | } | |
179 | if ($mod->section > 0 and $section <> $mod->section) { | |
d13864e6 | 180 | $activities["section/$mod->section"] = '--- '.get_section_name($course, $sections[$mod->section]).' ---'; |
c215b32b | 181 | } |
182 | $section = $mod->section; | |
9a9012dc | 183 | $mod->name = strip_tags(format_string($mod->name, true)); |
138c7678 PS |
184 | if (textlib::strlen($mod->name) > 55) { |
185 | $mod->name = textlib::substr($mod->name, 0, 50)."..."; | |
c215b32b | 186 | } |
187 | if (!$mod->visible) { | |
188 | $mod->name = "(".$mod->name.")"; | |
189 | } | |
190 | $activities["$mod->cm"] = $mod->name; | |
191 | ||
192 | if ($mod->cm == $modid) { | |
193 | $selectedactivity = "$mod->cm"; | |
194 | } | |
195 | } | |
196 | } | |
197 | ||
a2e4bf7f | 198 | if (has_capability('coursereport/log:view', $sitecontext) && !$course->category) { |
c215b32b | 199 | $activities["site_errors"] = get_string("siteerrors"); |
200 | if ($modid === "site_errors") { | |
201 | $selectedactivity = "site_errors"; | |
202 | } | |
203 | } | |
204 | ||
205 | $strftimedate = get_string("strftimedate"); | |
206 | $strftimedaydate = get_string("strftimedaydate"); | |
207 | ||
208 | asort($users); | |
209 | ||
210 | // Prepare the list of action options. | |
211 | $actions = array( | |
212 | 'view' => get_string('view'), | |
213 | 'add' => get_string('add'), | |
214 | 'update' => get_string('update'), | |
215 | 'delete' => get_string('delete'), | |
216 | '-view' => get_string('allchanges') | |
217 | ); | |
218 | ||
219 | // Get all the possible dates | |
220 | // Note that we are keeping track of real (GMT) time and user time | |
221 | // User time is only used in displays - all calcs and passing is GMT | |
222 | ||
223 | $timenow = time(); // GMT | |
224 | ||
225 | // What day is it now for the user, and when is midnight that day (in GMT). | |
226 | $timemidnight = $today = usergetmidnight($timenow); | |
227 | ||
228 | // Put today up the top of the list | |
229 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); | |
230 | ||
231 | if (!$course->startdate or ($course->startdate > $timenow)) { | |
232 | $course->startdate = $course->timecreated; | |
233 | } | |
234 | ||
235 | $numdates = 1; | |
236 | while ($timemidnight > $course->startdate and $numdates < 365) { | |
237 | $timemidnight = $timemidnight - 86400; | |
238 | $timenow = $timenow - 86400; | |
239 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); | |
240 | $numdates++; | |
241 | } | |
242 | ||
243 | if ($selecteddate == "today") { | |
244 | $selecteddate = $today; | |
245 | } | |
246 | ||
5577ceb3 | 247 | echo "<form class=\"logselectform\" action=\"$CFG->wwwroot/course/report/log/index.php\" method=\"get\">\n"; |
248 | echo "<div>\n";//invisible fieldset here breaks wrapping | |
c215b32b | 249 | echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; |
250 | echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n"; | |
251 | echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n"; | |
a2e4bf7f | 252 | if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { |
aa6c1ced | 253 | $cid = empty($course->id)? '1' : $course->id; |
6770330d | 254 | echo html_writer::select($dropdown, "host_course", $hostid.'/'.$cid); |
c215b32b | 255 | } else { |
256 | $courses = array(); | |
5577ceb3 | 257 | $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' ('.get_string('site').') ' : ''); |
d776d59e | 258 | echo html_writer::select($courses,"id",$course->id, false); |
a2e4bf7f | 259 | if (has_capability('coursereport/log:view', $sitecontext)) { |
fbaea88f | 260 | $a = new stdClass(); |
c215b32b | 261 | $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
262 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; | |
263 | print_string('logtoomanycourses','moodle',$a); | |
264 | } | |
265 | } | |
266 | ||
267 | if ($showgroups) { | |
2c386f82 | 268 | if ($cgroups = groups_get_all_groups($course->id)) { |
c215b32b | 269 | foreach ($cgroups as $cgroup) { |
270 | $groups[$cgroup->id] = $cgroup->name; | |
271 | } | |
272 | } | |
273 | else { | |
274 | $groups = array(); | |
275 | } | |
d776d59e | 276 | echo html_writer::select($groups, "group", $selectedgroup, get_string("allgroups")); |
c215b32b | 277 | } |
278 | ||
279 | if ($showusers) { | |
d776d59e | 280 | echo html_writer::select($users, "user", $selecteduser, get_string("allparticipants")); |
c215b32b | 281 | } |
282 | else { | |
283 | $users = array(); | |
284 | if (!empty($selecteduser)) { | |
29f83769 | 285 | $user = $DB->get_record('user', array('id'=>$selecteduser)); |
c215b32b | 286 | $users[$selecteduser] = fullname($user); |
287 | } | |
288 | else { | |
289 | $users[0] = get_string('allparticipants'); | |
290 | } | |
d776d59e | 291 | echo html_writer::select($users, "user", $selecteduser, false); |
c215b32b | 292 | $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
293 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; | |
294 | print_string('logtoomanyusers','moodle',$a); | |
295 | } | |
aa6c1ced | 296 | |
d776d59e PS |
297 | echo html_writer::select($dates, "date", $selecteddate, get_string("alldays")); |
298 | echo html_writer::select($activities, "modid", $selectedactivity, get_string("allactivities")); | |
299 | echo html_writer::select($actions, 'modaction', $modaction, get_string("allactions")); | |
aa6c1ced | 300 | |
c215b32b | 301 | $logformats = array('showashtml' => get_string('displayonpage'), |
302 | 'downloadascsv' => get_string('downloadtext'), | |
5577ceb3 | 303 | 'downloadasods' => get_string('downloadods'), |
c215b32b | 304 | 'downloadasexcel' => get_string('downloadexcel')); |
d776d59e | 305 | echo html_writer::select($logformats, 'logformat', $logformat, false); |
c215b32b | 306 | echo '<input type="submit" value="'.get_string('gettheselogs').'" />'; |
5577ceb3 | 307 | echo '</div>'; |
308 | echo '</form>'; | |
c215b32b | 309 | } |
310 | ||
92890025 | 311 | function print_log_selector_form($course, $selecteduser=0, $selecteddate='today', |
312 | $modname="", $modid=0, $modaction='', $selectedgroup=-1, $showcourses=0, $showusers=0, $logformat='showashtml') { | |
0a935fb3 | 313 | |
928d4738 | 314 | global $USER, $CFG, $DB, $OUTPUT, $SESSION; |
0a935fb3 | 315 | |
316 | // first check to see if we can override showcourses and showusers | |
29f83769 | 317 | $numcourses = $DB->count_records("course"); |
0a935fb3 | 318 | if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { |
319 | $showcourses = 1; | |
320 | } | |
aa6c1ced | 321 | |
09ee7b0d | 322 | $sitecontext = get_context_instance(CONTEXT_SYSTEM); |
d02eeded | 323 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
aa6c1ced | 324 | |
0a935fb3 | 325 | /// Setup for group handling. |
d02eeded | 326 | if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { |
928d4738 | 327 | $selectedgroup = -1; |
0a935fb3 | 328 | $showgroups = false; |
928d4738 | 329 | } else if ($course->groupmode) { |
0a935fb3 | 330 | $showgroups = true; |
928d4738 | 331 | } else { |
0a935fb3 | 332 | $selectedgroup = 0; |
333 | $showgroups = false; | |
334 | } | |
335 | ||
928d4738 | 336 | if ($selectedgroup === -1) { |
337 | if (isset($SESSION->currentgroup[$course->id])) { | |
338 | $selectedgroup = $SESSION->currentgroup[$course->id]; | |
339 | } else { | |
340 | $selectedgroup = groups_get_all_groups($course->id, $USER->id); | |
341 | if (is_array($selectedgroup)) { | |
342 | $selectedgroup = array_shift(array_keys($selectedgroup)); | |
343 | $SESSION->currentgroup[$course->id] = $selectedgroup; | |
344 | } else { | |
345 | $selectedgroup = 0; | |
346 | } | |
347 | } | |
348 | } | |
349 | ||
0a935fb3 | 350 | // Get all the possible users |
351 | $users = array(); | |
352 | ||
df997f84 | 353 | $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname, u.idnumber', 'lastname ASC, firstname ASC'); |
aa6c1ced | 354 | |
0a935fb3 | 355 | if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { |
356 | $showusers = 1; | |
357 | } | |
358 | ||
359 | if ($showusers) { | |
360 | if ($courseusers) { | |
361 | foreach ($courseusers as $courseuser) { | |
d02eeded | 362 | $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); |
0a935fb3 | 363 | } |
364 | } | |
629e12fd | 365 | $users[$CFG->siteguest] = get_string('guestuser'); |
0a935fb3 | 366 | } |
367 | ||
a2e4bf7f | 368 | if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { |
29f83769 | 369 | if ($ccc = $DB->get_records("course", null, "fullname", "id,fullname,category")) { |
0a935fb3 | 370 | foreach ($ccc as $cc) { |
371 | if ($cc->category) { | |
f054df17 | 372 | $courses["$cc->id"] = format_string($cc->fullname); |
0a935fb3 | 373 | } else { |
f054df17 | 374 | $courses["$cc->id"] = format_string($cc->fullname) . ' (Site)'; |
0a935fb3 | 375 | } |
376 | } | |
377 | } | |
378 | asort($courses); | |
379 | } | |
380 | ||
381 | $activities = array(); | |
382 | $selectedactivity = ""; | |
383 | ||
fea43a7f | 384 | /// Casting $course->modinfo to string prevents one notice when the field is null |
385 | if ($modinfo = unserialize((string)$course->modinfo)) { | |
0a935fb3 | 386 | $section = 0; |
d13864e6 | 387 | $sections = get_all_sections($course->id); |
0a935fb3 | 388 | foreach ($modinfo as $mod) { |
389 | if ($mod->mod == "label") { | |
390 | continue; | |
391 | } | |
392 | if ($mod->section > 0 and $section <> $mod->section) { | |
d13864e6 | 393 | $activities["section/$mod->section"] = '--- '.get_section_name($course, $sections[$mod->section]).' ---'; |
0a935fb3 | 394 | } |
395 | $section = $mod->section; | |
9a9012dc | 396 | $mod->name = strip_tags(format_string($mod->name, true)); |
138c7678 PS |
397 | if (textlib::strlen($mod->name) > 55) { |
398 | $mod->name = textlib::substr($mod->name, 0, 50)."..."; | |
0a935fb3 | 399 | } |
400 | if (!$mod->visible) { | |
401 | $mod->name = "(".$mod->name.")"; | |
402 | } | |
403 | $activities["$mod->cm"] = $mod->name; | |
404 | ||
405 | if ($mod->cm == $modid) { | |
406 | $selectedactivity = "$mod->cm"; | |
407 | } | |
408 | } | |
409 | } | |
410 | ||
a2e4bf7f | 411 | if (has_capability('coursereport/log:view', $sitecontext) && ($course->id == SITEID)) { |
0a935fb3 | 412 | $activities["site_errors"] = get_string("siteerrors"); |
413 | if ($modid === "site_errors") { | |
414 | $selectedactivity = "site_errors"; | |
415 | } | |
416 | } | |
417 | ||
418 | $strftimedate = get_string("strftimedate"); | |
419 | $strftimedaydate = get_string("strftimedaydate"); | |
420 | ||
421 | asort($users); | |
422 | ||
ee35e0b8 | 423 | // Prepare the list of action options. |
424 | $actions = array( | |
425 | 'view' => get_string('view'), | |
426 | 'add' => get_string('add'), | |
427 | 'update' => get_string('update'), | |
428 | 'delete' => get_string('delete'), | |
429 | '-view' => get_string('allchanges') | |
430 | ); | |
431 | ||
0a935fb3 | 432 | // Get all the possible dates |
433 | // Note that we are keeping track of real (GMT) time and user time | |
434 | // User time is only used in displays - all calcs and passing is GMT | |
435 | ||
436 | $timenow = time(); // GMT | |
437 | ||
438 | // What day is it now for the user, and when is midnight that day (in GMT). | |
439 | $timemidnight = $today = usergetmidnight($timenow); | |
440 | ||
441 | // Put today up the top of the list | |
442 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); | |
443 | ||
444 | if (!$course->startdate or ($course->startdate > $timenow)) { | |
445 | $course->startdate = $course->timecreated; | |
446 | } | |
447 | ||
448 | $numdates = 1; | |
449 | while ($timemidnight > $course->startdate and $numdates < 365) { | |
450 | $timemidnight = $timemidnight - 86400; | |
451 | $timenow = $timenow - 86400; | |
452 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); | |
453 | $numdates++; | |
454 | } | |
455 | ||
456 | if ($selecteddate == "today") { | |
457 | $selecteddate = $today; | |
458 | } | |
459 | ||
5577ceb3 | 460 | echo "<form class=\"logselectform\" action=\"$CFG->wwwroot/course/report/log/index.php\" method=\"get\">\n"; |
461 | echo "<div>\n"; | |
0a935fb3 | 462 | echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; |
463 | echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n"; | |
464 | echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n"; | |
a2e4bf7f | 465 | if (has_capability('coursereport/log:view', $sitecontext) && $showcourses) { |
d776d59e | 466 | echo html_writer::select($courses, "id", $course->id, false); |
0a935fb3 | 467 | } else { |
468 | // echo '<input type="hidden" name="id" value="'.$course->id.'" />'; | |
469 | $courses = array(); | |
5577ceb3 | 470 | $courses[$course->id] = $course->fullname . (($course->id == SITEID) ? ' ('.get_string('site').') ' : ''); |
d776d59e | 471 | echo html_writer::select($courses,"id",$course->id, false); |
a2e4bf7f | 472 | if (has_capability('coursereport/log:view', $sitecontext)) { |
fbaea88f | 473 | $a = new stdClass(); |
4d70ff5c | 474 | $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
0a935fb3 | 475 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; |
476 | print_string('logtoomanycourses','moodle',$a); | |
477 | } | |
478 | } | |
479 | ||
480 | if ($showgroups) { | |
2c386f82 | 481 | if ($cgroups = groups_get_all_groups($course->id)) { |
0a935fb3 | 482 | foreach ($cgroups as $cgroup) { |
483 | $groups[$cgroup->id] = $cgroup->name; | |
484 | } | |
485 | } | |
486 | else { | |
487 | $groups = array(); | |
488 | } | |
d776d59e | 489 | echo html_writer::select($groups, "group", $selectedgroup, get_string("allgroups")); |
0a935fb3 | 490 | } |
491 | ||
492 | if ($showusers) { | |
d776d59e | 493 | echo html_writer::select($users, "user", $selecteduser, get_string("allparticipants")); |
0a935fb3 | 494 | } |
495 | else { | |
496 | $users = array(); | |
497 | if (!empty($selecteduser)) { | |
29f83769 | 498 | $user = $DB->get_record('user', array('id'=>$selecteduser)); |
0a935fb3 | 499 | $users[$selecteduser] = fullname($user); |
500 | } | |
501 | else { | |
502 | $users[0] = get_string('allparticipants'); | |
503 | } | |
d776d59e | 504 | echo html_writer::select($users, "user", $selecteduser, false); |
fbaea88f | 505 | $a = new stdClass(); |
4d70ff5c | 506 | $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
0a935fb3 | 507 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; |
508 | print_string('logtoomanyusers','moodle',$a); | |
509 | } | |
d776d59e | 510 | echo html_writer::select($dates, "date", $selecteddate, get_string("alldays")); |
aa6c1ced | 511 | |
d776d59e PS |
512 | echo html_writer::select($activities, "modid", $selectedactivity, get_string("allactivities")); |
513 | echo html_writer::select($actions, 'modaction', $modaction, get_string("allactions")); | |
aa6c1ced | 514 | |
92890025 | 515 | $logformats = array('showashtml' => get_string('displayonpage'), |
516 | 'downloadascsv' => get_string('downloadtext'), | |
ea49a66c | 517 | 'downloadasods' => get_string('downloadods'), |
92890025 | 518 | 'downloadasexcel' => get_string('downloadexcel')); |
aa6c1ced | 519 | |
d776d59e | 520 | echo html_writer::select($logformats, 'logformat', $logformat, false); |
92890025 | 521 | echo '<input type="submit" value="'.get_string('gettheselogs').'" />'; |
5577ceb3 | 522 | echo '</div>'; |
523 | echo '</form>'; | |
0a935fb3 | 524 | } |
525 | ||
dfab77a2 | 526 | /** |
527 | * This function extends the navigation with the report items | |
528 | * | |
529 | * @param navigation_node $navigation The navigation node to extend | |
530 | * @param stdClass $course The course to object for the report | |
531 | * @param stdClass $context The context of the course | |
532 | */ | |
533 | function log_report_extend_navigation($navigation, $course, $context) { | |
534 | global $CFG, $OUTPUT; | |
535 | if (has_capability('coursereport/log:view', $context)) { | |
a6855934 | 536 | $url = new moodle_url('/course/report/log/index.php', array('id'=>$course->id)); |
ea118bed | 537 | $navigation->add(get_string('pluginname', 'coursereport_log'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); |
dfab77a2 | 538 | } |
07a737de | 539 | } |
b38e2e28 AD |
540 | |
541 | /** | |
542 | * Return a list of page types | |
543 | * @param string $pagetype current page type | |
544 | * @param stdClass $parentcontext Block's parent context | |
545 | * @param stdClass $currentcontext Current context of block | |
546 | */ | |
547 | function log_page_type_list($pagetype, $parentcontext, $currentcontext) { | |
548 | $array = array( | |
549 | '*' => get_string('page-x', 'pagetype'), | |
550 | 'course-report-*' => get_string('page-course-report-x', 'pagetype'), | |
346a32a7 AD |
551 | 'course-report-log-index' => get_string('pluginpagetype', 'coursereport_log') |
552 | //course-report-log-live not included as theres no blocks on the live log page | |
b38e2e28 AD |
553 | ); |
554 | return $array; | |
555 | } |