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