0a935fb3 |
1 | <?php |
2 | |
3 | function print_log_selector_form($course, $selecteduser=0, $selecteddate="today", |
4 | $modname="", $modid=0, $modaction="", $selectedgroup=-1,$showcourses=0,$showusers=0) { |
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 | } |
13 | |
14 | /// Setup for group handling. |
15 | $isteacher = isteacher($course->id); |
16 | $isteacheredit = isteacheredit($course->id); |
17 | if ($course->groupmode == SEPARATEGROUPS and !$isteacheredit) { |
18 | $selectedgroup = get_current_group($course->id); |
19 | $showgroups = false; |
20 | } |
21 | else if ($course->groupmode) { |
22 | $selectedgroup = ($selectedgroup == -1) ? get_current_group($course->id) : $selectedgroup; |
23 | $showgroups = true; |
24 | } |
25 | else { |
26 | $selectedgroup = 0; |
27 | $showgroups = false; |
28 | } |
29 | |
30 | // Get all the possible users |
31 | $users = array(); |
32 | |
33 | if ($course->category) { |
34 | if ($selectedgroup) { // If using a group, only get users in that group. |
35 | $courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname, u.idnumber'); |
36 | } else { |
37 | $courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname, u.idnumber'); |
38 | } |
39 | } else { |
40 | $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname, u.idnumber"); |
41 | } |
42 | |
43 | if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { |
44 | $showusers = 1; |
45 | } |
46 | |
47 | if ($showusers) { |
48 | if ($courseusers) { |
49 | foreach ($courseusers as $courseuser) { |
50 | $users[$courseuser->id] = fullname($courseuser, $isteacher); |
51 | } |
52 | } |
53 | if ($guest = get_guest()) { |
54 | $users[$guest->id] = fullname($guest); |
55 | } |
56 | } |
57 | |
58 | if (isadmin() && $showcourses) { |
59 | if ($ccc = get_records("course", "", "", "fullname","id,fullname,category")) { |
60 | foreach ($ccc as $cc) { |
61 | if ($cc->category) { |
62 | $courses["$cc->id"] = "$cc->fullname"; |
63 | } else { |
64 | $courses["$cc->id"] = " $cc->fullname (Site)"; |
65 | } |
66 | } |
67 | } |
68 | asort($courses); |
69 | } |
70 | |
71 | $activities = array(); |
72 | $selectedactivity = ""; |
73 | |
74 | if ($modinfo = unserialize($course->modinfo)) { |
75 | $section = 0; |
76 | if ($course->format == 'weeks') { // Bodgy |
77 | $strsection = get_string("week"); |
78 | } else { |
79 | $strsection = get_string("topic"); |
80 | } |
81 | foreach ($modinfo as $mod) { |
82 | if ($mod->mod == "label") { |
83 | continue; |
84 | } |
85 | if ($mod->section > 0 and $section <> $mod->section) { |
86 | $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------"; |
87 | } |
88 | $section = $mod->section; |
89 | $mod->name = strip_tags(format_string(urldecode($mod->name),true)); |
90 | if (strlen($mod->name) > 55) { |
91 | $mod->name = substr($mod->name, 0, 50)."..."; |
92 | } |
93 | if (!$mod->visible) { |
94 | $mod->name = "(".$mod->name.")"; |
95 | } |
96 | $activities["$mod->cm"] = $mod->name; |
97 | |
98 | if ($mod->cm == $modid) { |
99 | $selectedactivity = "$mod->cm"; |
100 | } |
101 | } |
102 | } |
103 | |
104 | if (isadmin() && !$course->category) { |
105 | $activities["site_errors"] = get_string("siteerrors"); |
106 | if ($modid === "site_errors") { |
107 | $selectedactivity = "site_errors"; |
108 | } |
109 | } |
110 | |
111 | $strftimedate = get_string("strftimedate"); |
112 | $strftimedaydate = get_string("strftimedaydate"); |
113 | |
114 | asort($users); |
115 | |
116 | // Get all the possible dates |
117 | // Note that we are keeping track of real (GMT) time and user time |
118 | // User time is only used in displays - all calcs and passing is GMT |
119 | |
120 | $timenow = time(); // GMT |
121 | |
122 | // What day is it now for the user, and when is midnight that day (in GMT). |
123 | $timemidnight = $today = usergetmidnight($timenow); |
124 | |
125 | // Put today up the top of the list |
126 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); |
127 | |
128 | if (!$course->startdate or ($course->startdate > $timenow)) { |
129 | $course->startdate = $course->timecreated; |
130 | } |
131 | |
132 | $numdates = 1; |
133 | while ($timemidnight > $course->startdate and $numdates < 365) { |
134 | $timemidnight = $timemidnight - 86400; |
135 | $timenow = $timenow - 86400; |
136 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); |
137 | $numdates++; |
138 | } |
139 | |
140 | if ($selecteddate == "today") { |
141 | $selecteddate = $today; |
142 | } |
143 | |
144 | echo "<center>\n"; |
145 | echo "<form action=\"log.php\" method=\"get\">\n"; |
146 | echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; |
147 | echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n"; |
148 | echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n"; |
149 | if (isadmin() && $showcourses) { |
150 | choose_from_menu ($courses, "id", $course->id, ""); |
151 | } else { |
152 | // echo '<input type="hidden" name="id" value="'.$course->id.'" />'; |
153 | $courses = array(); |
154 | $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' (Site) ' : ''); |
155 | choose_from_menu($courses,"id",$course->id,false); |
156 | if (isadmin()) { |
157 | $a->url = "log.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
158 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; |
159 | print_string('logtoomanycourses','moodle',$a); |
160 | } |
161 | } |
162 | |
163 | if ($showgroups) { |
164 | if ($cgroups = get_groups($course->id)) { |
165 | foreach ($cgroups as $cgroup) { |
166 | $groups[$cgroup->id] = $cgroup->name; |
167 | } |
168 | } |
169 | else { |
170 | $groups = array(); |
171 | } |
172 | choose_from_menu ($groups, "group", $selectedgroup, get_string("allgroups") ); |
173 | } |
174 | |
175 | if ($showusers) { |
176 | choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); |
177 | } |
178 | else { |
179 | $users = array(); |
180 | if (!empty($selecteduser)) { |
181 | $user = get_record('user','id',$selecteduser); |
182 | $users[$selecteduser] = fullname($user); |
183 | } |
184 | else { |
185 | $users[0] = get_string('allparticipants'); |
186 | } |
187 | choose_from_menu($users,'user',$selecteduser,false); |
188 | $a->url = "log.php?chooselog=0&group=$selectedgroup&user=$selecteduser" |
189 | ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; |
190 | print_string('logtoomanyusers','moodle',$a); |
191 | } |
192 | choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); |
193 | choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", ""); |
194 | echo '<input type="submit" value="'.get_string('showtheselogs').'" />'; |
195 | echo "</form>"; |
196 | echo "</center>"; |
197 | } |
198 | |
199 | ?> |