1f411afd |
1 | <?php // $Id$ |
0a935fb3 |
2 | |
92890025 |
3 | function print_log_selector_form($course, $selecteduser=0, $selecteddate='today', |
4 | $modname="", $modid=0, $modaction='', $selectedgroup=-1, $showcourses=0, $showusers=0, $logformat='showashtml') { |
0a935fb3 |
5 | |
6 | global $USER, $CFG; |
7 | |
8 | // first check to see if we can override showcourses and showusers |
9 | $numcourses = count_records_select("course", "", "COUNT(id)"); |
10 | if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { |
11 | $showcourses = 1; |
12 | } |
51792df0 |
13 | |
14 | $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); |
d02eeded |
15 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
16 | |
0a935fb3 |
17 | /// Setup for group handling. |
d02eeded |
18 | if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { |
0a935fb3 |
19 | $selectedgroup = get_current_group($course->id); |
20 | $showgroups = false; |
21 | } |
22 | else if ($course->groupmode) { |
23 | $selectedgroup = ($selectedgroup == -1) ? get_current_group($course->id) : $selectedgroup; |
24 | $showgroups = true; |
25 | } |
26 | else { |
27 | $selectedgroup = 0; |
28 | $showgroups = false; |
29 | } |
30 | |
31 | // Get all the possible users |
32 | $users = array(); |
33 | |
1936c10e |
34 | if ($course->id != SITEID) { |
0a935fb3 |
35 | if ($selectedgroup) { // If using a group, only get users in that group. |
36 | $courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname, u.idnumber'); |
37 | } else { |
38 | $courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname, u.idnumber'); |
39 | } |
40 | } else { |
41 | $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname, u.idnumber"); |
42 | } |
43 | |
44 | if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { |
45 | $showusers = 1; |
46 | } |
47 | |
48 | if ($showusers) { |
49 | if ($courseusers) { |
50 | foreach ($courseusers as $courseuser) { |
d02eeded |
51 | $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); |
0a935fb3 |
52 | } |
53 | } |
54 | if ($guest = get_guest()) { |
55 | $users[$guest->id] = fullname($guest); |
56 | } |
57 | } |
58 | |
51792df0 |
59 | if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { |
0a935fb3 |
60 | if ($ccc = get_records("course", "", "", "fullname","id,fullname,category")) { |
61 | foreach ($ccc as $cc) { |
62 | if ($cc->category) { |
63 | $courses["$cc->id"] = "$cc->fullname"; |
64 | } else { |
65 | $courses["$cc->id"] = " $cc->fullname (Site)"; |
66 | } |
67 | } |
68 | } |
69 | asort($courses); |
70 | } |
71 | |
72 | $activities = array(); |
73 | $selectedactivity = ""; |
74 | |
fea43a7f |
75 | /// Casting $course->modinfo to string prevents one notice when the field is null |
76 | if ($modinfo = unserialize((string)$course->modinfo)) { |
0a935fb3 |
77 | $section = 0; |
78 | if ($course->format == 'weeks') { // Bodgy |
79 | $strsection = get_string("week"); |
80 | } else { |
81 | $strsection = get_string("topic"); |
82 | } |
83 | foreach ($modinfo as $mod) { |
84 | if ($mod->mod == "label") { |
85 | continue; |
86 | } |
87 | if ($mod->section > 0 and $section <> $mod->section) { |
88 | $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------"; |
89 | } |
90 | $section = $mod->section; |
91 | $mod->name = strip_tags(format_string(urldecode($mod->name),true)); |
92 | if (strlen($mod->name) > 55) { |
93 | $mod->name = substr($mod->name, 0, 50)."..."; |
94 | } |
95 | if (!$mod->visible) { |
96 | $mod->name = "(".$mod->name.")"; |
97 | } |
98 | $activities["$mod->cm"] = $mod->name; |
99 | |
100 | if ($mod->cm == $modid) { |
101 | $selectedactivity = "$mod->cm"; |
102 | } |
103 | } |
104 | } |
105 | |
1936c10e |
106 | if (has_capability('moodle/site:viewreports', $sitecontext) && ($course->id == SITEID)) { |
0a935fb3 |
107 | $activities["site_errors"] = get_string("siteerrors"); |
108 | if ($modid === "site_errors") { |
109 | $selectedactivity = "site_errors"; |
110 | } |
111 | } |
112 | |
113 | $strftimedate = get_string("strftimedate"); |
114 | $strftimedaydate = get_string("strftimedaydate"); |
115 | |
116 | asort($users); |
117 | |
ee35e0b8 |
118 | // Prepare the list of action options. |
119 | $actions = array( |
120 | 'view' => get_string('view'), |
121 | 'add' => get_string('add'), |
122 | 'update' => get_string('update'), |
123 | 'delete' => get_string('delete'), |
124 | '-view' => get_string('allchanges') |
125 | ); |
126 | |
0a935fb3 |
127 | // Get all the possible dates |
128 | // Note that we are keeping track of real (GMT) time and user time |
129 | // User time is only used in displays - all calcs and passing is GMT |
130 | |
131 | $timenow = time(); // GMT |
132 | |
133 | // What day is it now for the user, and when is midnight that day (in GMT). |
134 | $timemidnight = $today = usergetmidnight($timenow); |
135 | |
136 | // Put today up the top of the list |
137 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); |
138 | |
139 | if (!$course->startdate or ($course->startdate > $timenow)) { |
140 | $course->startdate = $course->timecreated; |
141 | } |
142 | |
143 | $numdates = 1; |
144 | while ($timemidnight > $course->startdate and $numdates < 365) { |
145 | $timemidnight = $timemidnight - 86400; |
146 | $timenow = $timenow - 86400; |
147 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); |
148 | $numdates++; |
149 | } |
150 | |
151 | if ($selecteddate == "today") { |
152 | $selecteddate = $today; |
153 | } |
154 | |
155 | echo "<center>\n"; |
4d70ff5c |
156 | echo "<form action=\"$CFG->wwwroot/course/report/log/index.php\" method=\"get\">\n"; |
0a935fb3 |
157 | echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; |
158 | echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n"; |
159 | echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n"; |
51792df0 |
160 | if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { |
0a935fb3 |
161 | choose_from_menu ($courses, "id", $course->id, ""); |
162 | } else { |
163 | // echo '<input type="hidden" name="id" value="'.$course->id.'" />'; |
164 | $courses = array(); |
1936c10e |
165 | $courses[$course->id] = $course->fullname . (($course->id == SITEID) ? ' (Site) ' : ''); |
0a935fb3 |
166 | choose_from_menu($courses,"id",$course->id,false); |
51792df0 |
167 | if (has_capability('moodle/site:viewreports', $sitecontext)) { |
4d70ff5c |
168 | $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
0a935fb3 |
169 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; |
170 | print_string('logtoomanycourses','moodle',$a); |
171 | } |
172 | } |
173 | |
174 | if ($showgroups) { |
175 | if ($cgroups = get_groups($course->id)) { |
176 | foreach ($cgroups as $cgroup) { |
177 | $groups[$cgroup->id] = $cgroup->name; |
178 | } |
179 | } |
180 | else { |
181 | $groups = array(); |
182 | } |
183 | choose_from_menu ($groups, "group", $selectedgroup, get_string("allgroups") ); |
184 | } |
185 | |
186 | if ($showusers) { |
187 | choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); |
188 | } |
189 | else { |
190 | $users = array(); |
191 | if (!empty($selecteduser)) { |
192 | $user = get_record('user','id',$selecteduser); |
193 | $users[$selecteduser] = fullname($user); |
194 | } |
195 | else { |
196 | $users[0] = get_string('allparticipants'); |
197 | } |
92890025 |
198 | choose_from_menu($users, 'user', $selecteduser, false); |
4d70ff5c |
199 | $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
0a935fb3 |
200 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; |
201 | print_string('logtoomanyusers','moodle',$a); |
202 | } |
203 | choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); |
204 | choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", ""); |
ee35e0b8 |
205 | choose_from_menu ($actions, 'modaction', $modaction, get_string("allactions")); |
92890025 |
206 | |
207 | $logformats = array('showashtml' => get_string('displayonpage'), |
208 | 'downloadascsv' => get_string('downloadtext'), |
ea49a66c |
209 | 'downloadasods' => get_string('downloadods'), |
92890025 |
210 | 'downloadasexcel' => get_string('downloadexcel')); |
92890025 |
211 | choose_from_menu ($logformats, 'logformat', $logformat, false); |
212 | echo '<input type="submit" value="'.get_string('gettheselogs').'" />'; |
0a935fb3 |
213 | echo "</form>"; |
214 | echo "</center>"; |
215 | } |
216 | |
fea43a7f |
217 | ?> |