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