Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / course / report / log / index.php
blob2c6030f53c236ab669d1bb8eff7abc150f80dd57
1 <?php // $Id$
2 // Displays different views of the logs.
4 require_once('../../../config.php');
5 require_once('../../lib.php');
6 require_once('lib.php');
7 require_once($CFG->libdir.'/adminlib.php');
9 $id = optional_param('id', 0, PARAM_INT);// Course ID
11 $host_course = optional_param('host_course', '', PARAM_PATH);// Course ID
13 if (empty($host_course)) {
14 $hostid = $CFG->mnet_localhost_id;
15 if (empty($id)) {
16 $site = get_site();
17 $id = $site->id;
19 } else {
20 list($hostid, $id) = explode('/', $host_course);
23 $group = optional_param('group', 0, PARAM_INT); // Group to display
24 $user = optional_param('user', 0, PARAM_INT); // User to display
25 $date = optional_param('date', 0, PARAM_FILE); // Date to display - number or some string
26 $modname = optional_param('modname', '', PARAM_CLEAN); // course_module->id
27 $modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors'
28 $modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs
29 $page = optional_param('page', '0', PARAM_INT); // which page to show
30 $perpage = optional_param('perpage', '100', PARAM_INT); // how many per page
31 $showcourses = optional_param('showcourses', 0, PARAM_INT); // whether to show courses if we're over our limit.
32 $showusers = optional_param('showusers', 0, PARAM_INT); // whether to show users if we're over our limit.
33 $chooselog = optional_param('chooselog', 0, PARAM_INT);
34 $logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA);
36 if ($hostid == $CFG->mnet_localhost_id) {
37 if (!$course = get_record('course', 'id', $id) ) {
38 error('That\'s an invalid course id'.$id);
40 } else {
41 $course_stub = array_pop(get_records_select('mnet_log', " hostid='$hostid' AND course='$id' ", '', '*', '', '1'));
42 $course->id = $id;
43 $course->shortname = $course_stub->coursename;
44 $course->fullname = $course_stub->coursename;
47 require_login($course->id);
49 $context = get_context_instance(CONTEXT_COURSE, $course->id);
51 require_capability('moodle/site:viewreports', $context);
53 add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id);
55 $strlogs = get_string('logs');
56 $stradministration = get_string('administration');
57 $strreports = get_string('reports');
59 session_write_close();
61 $navlinks = array();
63 if (!empty($chooselog)) {
64 $userinfo = get_string('allparticipants');
65 $dateinfo = get_string('alldays');
67 if ($user) {
68 if (!$u = get_record('user', 'id', $user) ) {
69 error('That\'s an invalid user!');
71 $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
73 if ($date) {
74 $dateinfo = userdate($date, get_string('strftimedaydate'));
77 switch ($logformat) {
78 case 'showashtml':
79 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
80 admin_externalpage_setup('reportlog');
81 admin_externalpage_print_header();
83 } else {
84 $navlinks[] = array('name' => $strreports, 'link' => "$CFG->wwwroot/course/report.php?id=$course->id", 'type' => 'misc');
85 $navlinks[] = array('name' => $strlogs, 'link' => "index.php?id=$course->id", 'type' => 'misc');
86 $navlinks[] = array('name' => "$userinfo, $dateinfo", 'link' => null, 'type' => 'misc');
87 $navigation = build_navigation($navlinks);
88 print_header($course->shortname .': '. $strlogs, $course->fullname, $navigation);
91 print_heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")");
92 print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
94 if($hostid == $CFG->mnet_localhost_id) {
95 print_log($course, $user, $date, 'l.time DESC', $page, $perpage,
96 "index.php?id=$course->id&amp;chooselog=1&amp;user=$user&amp;date=$date&amp;modid=$modid&amp;modaction=$modaction&amp;group=$group",
97 $modname, $modid, $modaction, $group);
98 } else {
99 print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group);
101 break;
102 case 'downloadascsv':
103 if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname,
104 $modid, $modaction, $group)) {
105 notify("No logs found!");
106 print_footer($course);
108 exit;
109 case 'downloadasods':
110 if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname,
111 $modid, $modaction, $group)) {
112 notify("No logs found!");
113 print_footer($course);
115 exit;
116 case 'downloadasexcel':
117 if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname,
118 $modid, $modaction, $group)) {
119 notify("No logs found!");
120 print_footer($course);
122 exit;
126 } else {
127 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
128 admin_externalpage_setup('reportlog');
129 admin_externalpage_print_header();
130 } else {
131 $navlinks[] = array('name' => $strreports, 'link' => "$CFG->wwwroot/course/report.php?id=$course->id", 'type' => 'misc');
132 $navlinks[] = array('name' => $strlogs, 'link' => null, 'type' => 'misc');
133 $navigation = build_navigation($navlinks);
134 print_header($course->shortname .': '. $strlogs, $course->fullname, $navigation, '');
137 print_heading(get_string('chooselogs') .':');
139 print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
141 echo '<br />';
142 print_heading(get_string('chooselivelogs') .':');
144 echo '<center><h3>';
145 link_to_popup_window('/course/report/log/live.php?id='. $course->id,'livelog', get_string('livelogs'), 500, 800);
146 echo '</h3></center>';
150 print_footer($course);
152 exit;