7423f116 |
1 | <?php // $Id$ |
2 | |
3 | ///////////////////////////////////////////////////////////////////////////// |
4 | // // |
5 | // NOTICE OF COPYRIGHT // |
6 | // // |
7 | // Moodle - Calendar extension // |
8 | // // |
9 | // Copyright (C) 2003-2004 Greek School Network www.sch.gr // |
10 | // // |
11 | // Designed by: // |
12 | // Avgoustos Tsinakos (tsinakos@uom.gr) // |
13 | // Jon Papaioannou (pj@uom.gr) // |
14 | // // |
15 | // Programming and development: // |
16 | // Jon Papaioannou (pj@uom.gr) // |
17 | // // |
18 | // For bugs, suggestions, etc contact: // |
19 | // Jon Papaioannou (pj@uom.gr) // |
20 | // // |
21 | // The current module was developed at the University of Macedonia // |
22 | // (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) // |
23 | // The aim of this project is to provide additional and improved // |
24 | // functionality to the Asynchronous Distance Education service that the // |
25 | // Greek School Network deploys. // |
26 | // // |
27 | // This program is free software; you can redistribute it and/or modify // |
28 | // it under the terms of the GNU General Public License as published by // |
29 | // the Free Software Foundation; either version 2 of the License, or // |
30 | // (at your option) any later version. // |
31 | // // |
32 | // This program is distributed in the hope that it will be useful, // |
33 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
34 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
35 | // GNU General Public License for more details: // |
36 | // // |
37 | // http://www.gnu.org/copyleft/gpl.html // |
38 | // // |
39 | ///////////////////////////////////////////////////////////////////////////// |
40 | |
41 | // Display the calendar page. |
42 | |
43 | require_once('../config.php'); |
08cebf19 |
44 | require_once($CFG->dirroot.'/course/lib.php'); |
45 | require_once($CFG->dirroot.'/calendar/lib.php'); |
707fbef4 |
46 | |
7dc30088 |
47 | $courseid = optional_param('course', 0, PARAM_INT); |
48 | $view = optional_param('view', 'upcoming', PARAM_ALPHA); |
7f4d18fc |
49 | $day = optional_param('cal_d', 0, PARAM_INT); |
50 | $mon = optional_param('cal_m', 0, PARAM_INT); |
51 | $yr = optional_param('cal_y', 0, PARAM_INT); |
7423f116 |
52 | |
53 | if(!$site = get_site()) { |
54 | redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php'); |
55 | } |
56 | |
7dc30088 |
57 | if ($courseid) { |
58 | require_login($courseid); |
59 | } else if ($CFG->forcelogin) { |
2d4fb02f |
60 | require_login(); |
61 | } |
62 | |
7423f116 |
63 | //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); |
7423f116 |
64 | $now = usergetdate(time()); |
65 | $pagetitle = ''; |
66 | |
67 | $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']); |
68 | |
482dbe0c |
69 | |
7423f116 |
70 | if(!checkdate($mon, $day, $yr)) { |
71 | $day = intval($now['mday']); |
72 | $mon = intval($now['mon']); |
73 | $yr = intval($now['year']); |
74 | } |
5147ad48 |
75 | $time = make_timestamp($yr, $mon, $day); |
7423f116 |
76 | |
482dbe0c |
77 | switch($view) { |
7423f116 |
78 | case 'day': |
5147ad48 |
79 | $nav .= ' -> '.userdate($time, get_string('strftimedate')); |
7423f116 |
80 | $pagetitle = get_string('dayview', 'calendar'); |
81 | break; |
82 | case 'month': |
5147ad48 |
83 | $nav .= ' -> '.userdate($time, get_string('strftimemonthyear')); |
7423f116 |
84 | $pagetitle = get_string('detailedmonthview', 'calendar'); |
7423f116 |
85 | break; |
86 | case 'upcoming': |
87 | $pagetitle = get_string('upcomingevents', 'calendar'); |
88 | break; |
7423f116 |
89 | } |
90 | |
227bc46b |
91 | // If a course has been supplied in the URL, change the filters to show that one |
7dc30088 |
92 | if (!empty($courseid)) { |
93 | if ($course = get_record('course', 'id', $courseid)) { |
69963aa6 |
94 | if ($course->id == SITEID) { |
89adb174 |
95 | // If coming from the home page, show all courses |
96 | $SESSION->cal_courses_shown = calendar_get_default_courses(true); |
97 | calendar_set_referring_course(0); |
fd5594a0 |
98 | |
99 | } else { |
89adb174 |
100 | // Otherwise show just this one |
d57fc786 |
101 | $SESSION->cal_courses_shown = $course->id; |
89adb174 |
102 | calendar_set_referring_course($SESSION->cal_courses_shown); |
103 | } |
227bc46b |
104 | } |
7dc30088 |
105 | } else { |
106 | $course = null; |
227bc46b |
107 | } |
108 | |
1066e0dc |
109 | if (empty($USER->id) or isguest()) { |
43c3ffbe |
110 | $defaultcourses = calendar_get_default_courses(); |
111 | calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses); |
fd5594a0 |
112 | |
113 | } else { |
34bf3ad4 |
114 | calendar_set_filters($courses, $groups, $users); |
43c3ffbe |
115 | } |
116 | |
7423f116 |
117 | // Let's see if we are supposed to provide a referring course link |
118 | // but NOT for the "main page" course |
69963aa6 |
119 | if ($SESSION->cal_course_referer != SITEID && |
fd5594a0 |
120 | ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) { |
08cebf19 |
121 | // If we know about the referring course, show a return link and ALSO require login! |
122 | require_login(); |
7423f116 |
123 | $nav = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$SESSION->cal_course_referer.'">'.$shortname.'</a> -> '.$nav; |
d57fc786 |
124 | if (empty($course)) { |
125 | $course = get_record('course', 'id', $SESSION->cal_course_referer); // Useful to have around |
126 | } |
7423f116 |
127 | } |
128 | |
1e1ff33b |
129 | $strcalendar = get_string('calendar', 'calendar'); |
1e1ff33b |
130 | $prefsbutton = calendar_preferences_button(); |
131 | |
7423f116 |
132 | // Print title and header |
1e1ff33b |
133 | print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $nav, |
84854c09 |
134 | '', '', true, $prefsbutton, user_login_string($site)); |
7423f116 |
135 | |
136 | echo calendar_overlib_html(); |
137 | |
138 | // Layout the whole page as three big columns. |
3c49918a |
139 | echo '<table id="calendar" style="height:100%;">'; |
7d50b363 |
140 | echo '<tr>'; |
7423f116 |
141 | |
ff2ec3b5 |
142 | // START: Main column |
7423f116 |
143 | |
7d50b363 |
144 | echo '<td class="maincalendar">'; |
3c49918a |
145 | echo '<div class="heightcontainer">'; |
7423f116 |
146 | |
482dbe0c |
147 | switch($view) { |
7423f116 |
148 | case 'day': |
149 | calendar_show_day($day, $mon, $yr, $courses, $groups, $users); |
150 | break; |
151 | case 'month': |
152 | calendar_show_month_detailed($mon, $yr, $courses, $groups, $users); |
153 | break; |
154 | case 'upcoming': |
155 | calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS)); |
156 | break; |
157 | } |
3c49918a |
158 | |
ea185313 |
159 | //Link to calendar export page |
3c49918a |
160 | echo '<div class="bottom">'; |
161 | print_single_button('export.php', false, get_string('exportcalendar', 'calendar')); |
162 | |
ea185313 |
163 | if (!empty($USER->id)) { |
164 | $authtoken = sha1($USER->username . $USER->password); |
165 | $usernameencoded = urlencode($USER->username); |
3c49918a |
166 | |
167 | echo "<a href=\"export_execute.php?preset_what=all&preset_time=recentupcoming&username=$usernameencoded&authtoken=$authtoken\">" |
168 | .'<img src="'.$CFG->pixpath.'/i/ical.gif" height="14" width="36" ' |
169 | .'alt="'.get_string('ical', 'calendar').'" ' |
170 | .'title="'.get_string('quickdownloadcalendar', 'calendar').'" />' |
171 | .'</a>'; |
ea185313 |
172 | } |
7423f116 |
173 | |
3c49918a |
174 | echo '</div>'; |
175 | echo '</div>'; |
7423f116 |
176 | echo '</td>'; |
177 | |
ff2ec3b5 |
178 | // END: Main column |
7423f116 |
179 | |
180 | // START: Last column (3-month display) |
7d50b363 |
181 | echo '<td class="sidecalendar">'; |
df349d1d |
182 | echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>'; |
7d50b363 |
183 | |
ff2ec3b5 |
184 | list($prevmon, $prevyr) = calendar_sub_month($mon, $yr); |
185 | list($nextmon, $nextyr) = calendar_add_month($mon, $yr); |
34bf3ad4 |
186 | $getvars = 'cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering |
7d50b363 |
187 | |
188 | echo '<div class="filters">'; |
482dbe0c |
189 | echo calendar_filter_controls($view, $getvars); |
7d50b363 |
190 | echo '</div>'; |
191 | |
3c47bfc7 |
192 | echo '<div class="minicalendarblock">'; |
ff2ec3b5 |
193 | echo calendar_top_controls('display', array('m' => $prevmon, 'y' => $prevyr)); |
194 | echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr); |
3c47bfc7 |
195 | echo '</div><div class="minicalendarblock">'; |
ff2ec3b5 |
196 | echo calendar_top_controls('display', array('m' => $mon, 'y' => $yr)); |
197 | echo calendar_get_mini($courses, $groups, $users, $mon, $yr); |
3c47bfc7 |
198 | echo '</div><div class="minicalendarblock">'; |
ff2ec3b5 |
199 | echo calendar_top_controls('display', array('m' => $nextmon, 'y' => $nextyr)); |
200 | echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr); |
deaa8842 |
201 | echo '</div>'; |
7d50b363 |
202 | |
ff2ec3b5 |
203 | echo '</td>'; |
7423f116 |
204 | |
205 | echo '</tr></table>'; |
ff2ec3b5 |
206 | |
7423f116 |
207 | print_footer(); |
208 | |
9958a08c |
209 | |
210 | |
7423f116 |
211 | function calendar_show_day($d, $m, $y, $courses, $groups, $users) { |
4a2c4132 |
212 | global $CFG, $USER; |
7423f116 |
213 | |
9958a08c |
214 | if (!checkdate($m, $d, $y)) { |
7423f116 |
215 | $now = usergetdate(time()); |
216 | list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year'])); |
217 | } |
218 | |
34bf3ad4 |
219 | $getvars = 'from=day&cal_d='.$d.'&cal_m='.$m.'&cal_y='.$y; // For filtering |
220 | |
7423f116 |
221 | $starttime = make_timestamp($y, $m, $d); |
3c7e1b65 |
222 | $endtime = make_timestamp($y, $m, $d + 1) - 1; |
7423f116 |
223 | |
9958a08c |
224 | $events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime); |
7423f116 |
225 | |
2ad2cbc3 |
226 | $text = ''; |
227 | if (!isguest() && !empty($USER->id)) { |
228 | $text.= '<div class="buttons">'; |
229 | $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">'; |
d0a32914 |
230 | $text.= '<fieldset class="invisiblefieldset">'; |
7423f116 |
231 | $text.= '<input type="hidden" name="action" value="new" />'; |
11b0ffe8 |
232 | $text.= '<input type="hidden" name="cal_d" value="'.$d.'" />'; |
7423f116 |
233 | $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />'; |
234 | $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />'; |
235 | $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />'; |
d0a32914 |
236 | $text.= '</fieldset></form></div>'; |
7423f116 |
237 | } |
238 | |
2ad2cbc3 |
239 | $text .= get_string('dayview', 'calendar').': '.calendar_course_filter_selector($getvars); |
240 | |
df349d1d |
241 | echo '<div class="header">'.$text.'</div>'; |
7d50b363 |
242 | |
243 | echo '<div class="controls">'.calendar_top_controls('day', array('d' => $d, 'm' => $m, 'y' => $y)).'</div>'; |
7423f116 |
244 | |
9958a08c |
245 | if (empty($events)) { |
7423f116 |
246 | // There is nothing to display today. |
3477a900 |
247 | echo '<h3>'.get_string('daywithnoevents', 'calendar').'</h3>'; |
9958a08c |
248 | |
249 | } else { |
250 | |
2ad2cbc3 |
251 | echo '<div class="eventlist">'; |
252 | |
9958a08c |
253 | $underway = array(); |
7423f116 |
254 | |
255 | // First, print details about events that start today |
9958a08c |
256 | foreach ($events as $event) { |
257 | if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now |
9d567178 |
258 | |
9d567178 |
259 | |
8f896582 |
260 | /* |
9d567178 |
261 | $dayend = calendar_day_representation($event->timestart + $event->timeduration); |
262 | $timeend = calendar_time_representation($event->timestart + $event->timeduration); |
263 | $enddate = usergetdate($event->timestart + $event->timeduration); |
264 | // Set printable representation |
265 | echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')'; |
266 | */ |
8f896582 |
267 | //unset($event->time); |
268 | $event->time = calendar_format_event_time($event, time(), '', false); |
227bc46b |
269 | calendar_print_event($event); |
9958a08c |
270 | |
271 | } else { // Save this for later |
272 | $underway[] = $event; |
7423f116 |
273 | } |
274 | } |
275 | |
276 | // Then, show a list of all events that just span this day |
9958a08c |
277 | if (!empty($underway)) { |
3c134875 |
278 | echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>'; |
9958a08c |
279 | foreach ($underway as $event) { |
8f896582 |
280 | $event->time = calendar_format_event_time($event, time(), '', false); |
227bc46b |
281 | calendar_print_event($event); |
7423f116 |
282 | } |
7423f116 |
283 | } |
2ad2cbc3 |
284 | |
285 | echo '</div>'; |
286 | |
7423f116 |
287 | } |
7423f116 |
288 | } |
289 | |
290 | function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { |
f2bffd9e |
291 | global $CFG, $SESSION, $USER, $CALENDARDAYS; |
2b10fcf5 |
292 | global $day, $mon, $yr; |
7423f116 |
293 | |
294 | $getvars = 'from=month&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering |
295 | |
296 | $display = &New stdClass; |
297 | $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); |
298 | $display->maxwday = $display->minwday + 6; |
299 | |
300 | if(!empty($m) && !empty($y)) { |
301 | $thisdate = usergetdate(time()); // Time and day at the user's location |
302 | if($m == $thisdate['mon'] && $y == $thisdate['year']) { |
303 | // Navigated to this month |
304 | $date = $thisdate; |
305 | $display->thismonth = true; |
306 | } |
307 | else { |
308 | // Navigated to other month, let's do a nice trick and save us a lot of work... |
309 | if(!checkdate($m, 1, $y)) { |
310 | $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); |
311 | $display->thismonth = true; |
312 | } |
313 | else { |
314 | $date = array('mday' => 1, 'mon' => $m, 'year' => $y); |
315 | $display->thismonth = false; |
316 | } |
317 | } |
318 | } |
319 | else { |
320 | $date = usergetdate(time()); |
321 | $display->thismonth = true; |
322 | } |
323 | |
324 | // Fill in the variables we 're going to use, nice and tidy |
325 | list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display |
326 | $display->maxdays = calendar_days_in_month($m, $y); |
327 | |
328 | // We 'll keep these values as GMT here, and offset them when the time comes to query the db |
329 | $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT |
330 | $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT |
331 | |
332 | $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ |
333 | |
334 | // Align the starting weekday to fall in our display range |
335 | if($startwday < $display->minwday) { |
336 | $startwday += 7; |
337 | } |
338 | |
339 | // Get events from database |
340 | $whereclause = calendar_sql_where(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses); |
341 | if($whereclause === false) { |
342 | $events = array(); |
343 | } |
344 | else { |
a94329a8 |
345 | $events = get_records_select('event', $whereclause, 'timestart'); |
7423f116 |
346 | } |
347 | |
348 | // Extract information: events vs. time |
7b38bfa6 |
349 | calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday); |
7423f116 |
350 | |
2ad2cbc3 |
351 | $text = ''; |
352 | if(!isguest() && !empty($USER->id)) { |
353 | $text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">'; |
d0a32914 |
354 | $text.= '<fieldset class="invisiblefieldset">'; |
7423f116 |
355 | $text.= '<input type="hidden" name="action" value="new" />'; |
356 | $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />'; |
357 | $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />'; |
358 | $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />'; |
d0a32914 |
359 | $text.= '</fieldset></form></div>'; |
7423f116 |
360 | } |
361 | |
2ad2cbc3 |
362 | $text .= get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars); |
363 | |
df349d1d |
364 | echo '<div class="header">'.$text.'</div>'; |
43c3ffbe |
365 | |
7d50b363 |
366 | echo '<div class="controls">'; |
7423f116 |
367 | echo calendar_top_controls('month', array('m' => $m, 'y' => $y)); |
7d50b363 |
368 | echo '</div>'; |
7423f116 |
369 | |
370 | // Start calendar display |
f136e4c5 |
371 | echo '<table class="calendarmonth"><tr class="weekdays">'; // Begin table. First row: day names |
7423f116 |
372 | |
373 | // Print out the names of the weekdays |
7423f116 |
374 | for($i = $display->minwday; $i <= $display->maxwday; ++$i) { |
375 | // This uses the % operator to get the correct weekday no matter what shift we have |
376 | // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 |
54926e78 |
377 | echo '<th scope="col">'.get_string($CALENDARDAYS[$i % 7], 'calendar').'</th>'; |
7423f116 |
378 | } |
379 | |
f136e4c5 |
380 | echo '</tr><tr>'; // End of day names; prepare for day numbers |
7423f116 |
381 | |
382 | // For the table display. $week is the row; $dayweek is the column. |
383 | $week = 1; |
384 | $dayweek = $startwday; |
385 | |
386 | // Paddding (the first week may have blank days in the beginning) |
387 | for($i = $display->minwday; $i < $startwday; ++$i) { |
92668ad2 |
388 | echo '<td> </td>'."\n"; |
7423f116 |
389 | } |
390 | |
391 | // Now display all the calendar |
392 | for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { |
393 | if($dayweek > $display->maxwday) { |
394 | // We need to change week (table row) |
395 | echo "</tr>\n<tr>"; |
396 | $dayweek = $display->minwday; |
397 | ++$week; |
398 | } |
399 | |
400 | // Reset vars |
7423f116 |
401 | $cell = ''; |
f434283f |
402 | $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&', $day, $m, $y); |
403 | |
bb4a2e85 |
404 | if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) { |
7423f116 |
405 | // Weekend. This is true no matter what the exact range is. |
edbe6c1b |
406 | $class = 'weekend'; |
7423f116 |
407 | } |
408 | else { |
409 | // Normal working day. |
92668ad2 |
410 | $class = ''; |
7423f116 |
411 | } |
412 | |
413 | // Special visual fx if an event is defined |
414 | if(isset($eventsbyday[$day])) { |
415 | if(isset($typesbyday[$day]['startglobal'])) { |
edbe6c1b |
416 | $class .= ' event_global'; |
7423f116 |
417 | } |
418 | else if(isset($typesbyday[$day]['startcourse'])) { |
edbe6c1b |
419 | $class .= ' event_course'; |
7423f116 |
420 | } |
421 | else if(isset($typesbyday[$day]['startgroup'])) { |
edbe6c1b |
422 | $class .= ' event_group'; |
7423f116 |
423 | } |
424 | else if(isset($typesbyday[$day]['startuser'])) { |
edbe6c1b |
425 | $class .= ' event_user'; |
7423f116 |
426 | } |
427 | if(count($eventsbyday[$day]) == 1) { |
428 | $title = get_string('oneevent', 'calendar'); |
429 | } |
430 | else { |
431 | $title = get_string('manyevents', 'calendar', count($eventsbyday[$day])); |
432 | } |
edbe6c1b |
433 | $cell = '<div class="day"><a href="'.$dayhref.'" title="'.$title.'">'.$day.'</a></div>'; |
7423f116 |
434 | } |
435 | else { |
edbe6c1b |
436 | $cell = '<div class="day">'.$day.'</div>'; |
7423f116 |
437 | } |
438 | |
439 | // Special visual fx if an event spans many days |
440 | if(isset($typesbyday[$day]['durationglobal'])) { |
edbe6c1b |
441 | $class .= ' duration_global'; |
7423f116 |
442 | } |
443 | else if(isset($typesbyday[$day]['durationcourse'])) { |
edbe6c1b |
444 | $class .= ' duration_course'; |
7423f116 |
445 | } |
446 | else if(isset($typesbyday[$day]['durationgroup'])) { |
edbe6c1b |
447 | $class .= ' duration_group'; |
7423f116 |
448 | } |
449 | else if(isset($typesbyday[$day]['durationuser'])) { |
edbe6c1b |
450 | $class .= ' duration_user'; |
7423f116 |
451 | } |
452 | |
453 | // Special visual fx for today |
454 | if($display->thismonth && $day == $d) { |
edbe6c1b |
455 | $class .= ' today'; |
7423f116 |
456 | } |
457 | |
458 | // Just display it |
92668ad2 |
459 | if(!empty($class)) { |
460 | $class = ' class="'.trim($class).'"'; |
461 | } |
462 | echo '<td'.$class.'>'.$cell; |
463 | |
7423f116 |
464 | if(isset($eventsbyday[$day])) { |
760e522b |
465 | echo '<ul class="events-new">'; |
7423f116 |
466 | foreach($eventsbyday[$day] as $eventindex) { |
fb73f3b3 |
467 | echo '<li><a href="'.$dayhref.'">'.format_string($events[$eventindex]->name,true).'</a></li>'; |
7423f116 |
468 | } |
edbe6c1b |
469 | echo '</ul>'; |
7423f116 |
470 | } |
471 | if(isset($durationbyday[$day])) { |
760e522b |
472 | echo '<ul class="events-underway">'; |
7423f116 |
473 | foreach($durationbyday[$day] as $eventindex) { |
fb73f3b3 |
474 | echo '<li>['.format_string($events[$eventindex]->name,true).']</li>'; |
7423f116 |
475 | } |
760e522b |
476 | echo '</ul>'; |
7423f116 |
477 | } |
478 | echo "</td>\n"; |
479 | } |
480 | |
481 | // Paddding (the last week may have blank days at the end) |
482 | for($i = $dayweek; $i <= $display->maxwday; ++$i) { |
92668ad2 |
483 | echo '<td> </td>'; |
7423f116 |
484 | } |
f136e4c5 |
485 | echo "</tr>\n"; // Last row ends |
7423f116 |
486 | |
7d50b363 |
487 | echo "</table>\n"; // Tabular display of days ends |
7423f116 |
488 | |
489 | // OK, now for the filtering display |
f136e4c5 |
490 | echo '<div class="filters"><table><tr>'; |
7423f116 |
491 | |
492 | // Global events |
493 | if($SESSION->cal_show_global) { |
edbe6c1b |
494 | echo '<td class="event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> '; |
7423f116 |
495 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; |
496 | } |
497 | else { |
498 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> '; |
499 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; |
500 | } |
501 | |
43c3ffbe |
502 | // Course events |
503 | if(!empty($SESSION->cal_show_course)) { |
edbe6c1b |
504 | echo '<td class="event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> '; |
43c3ffbe |
505 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; |
1f695119 |
506 | } |
507 | else { |
43c3ffbe |
508 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> '; |
509 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; |
1f695119 |
510 | } |
7423f116 |
511 | |
7423f116 |
512 | echo "</tr>\n"; |
7423f116 |
513 | |
1066e0dc |
514 | if(!empty($USER->id) && !isguest()) { |
43c3ffbe |
515 | echo '<tr>'; |
516 | // Group events |
517 | if($SESSION->cal_show_groups) { |
edbe6c1b |
518 | echo '<td class="event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> '; |
43c3ffbe |
519 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; |
520 | } |
521 | else { |
522 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> '; |
523 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; |
524 | } |
525 | // User events |
526 | if($SESSION->cal_show_user) { |
edbe6c1b |
527 | echo '<td class="event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> '; |
43c3ffbe |
528 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; |
529 | } |
530 | else { |
531 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> '; |
532 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; |
533 | } |
534 | echo "</tr>\n"; |
7423f116 |
535 | } |
536 | |
f136e4c5 |
537 | echo '</table></div>'; |
7423f116 |
538 | } |
539 | |
540 | function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents) { |
3395a558 |
541 | global $USER; |
552064d3 |
542 | |
7423f116 |
543 | $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents); |
7423f116 |
544 | |
edbe6c1b |
545 | $text = ''; |
552064d3 |
546 | |
edbe6c1b |
547 | if(!isguest() && !empty($USER->id)) { |
548 | $text.= '<div class="buttons">'; |
549 | $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">'; |
d0a32914 |
550 | $text.= '<fieldset class="invisiblefieldset">'; |
f10f1b7b |
551 | $text.= '<input type="hidden" name="action" value="new" />'; |
227bc46b |
552 | /* |
f10f1b7b |
553 | $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />'; |
554 | $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />'; |
227bc46b |
555 | */ |
f10f1b7b |
556 | $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />'; |
d0a32914 |
557 | $text.= '</fieldset></form></div>'; |
7423f116 |
558 | } |
559 | |
edbe6c1b |
560 | $text .= get_string('upcomingevents', 'calendar').': '.calendar_course_filter_selector('from=upcoming'); |
561 | |
df349d1d |
562 | echo '<div class="header">'.$text.'</div>'; |
7d50b363 |
563 | |
9958a08c |
564 | if ($events) { |
edbe6c1b |
565 | echo '<div class="eventlist">'; |
9958a08c |
566 | foreach ($events as $event) { |
567 | calendar_print_event($event); |
568 | } |
edbe6c1b |
569 | echo '</div>'; |
9958a08c |
570 | } else { |
9958a08c |
571 | print_heading(get_string('noupcomingevents', 'calendar')); |
7423f116 |
572 | } |
7423f116 |
573 | } |
574 | |
34bf3ad4 |
575 | function calendar_course_filter_selector($getvars = '') { |
576 | global $USER, $SESSION; |
577 | |
1066e0dc |
578 | if (empty($USER->id) or isguest()) { |
8792061c |
579 | return ''; |
580 | } |
581 | |
9c37662f |
582 | if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID)) && !empty($CFG->calendar_adminseesall)) { |
e6d1d120 |
583 | $courses = get_courses('all', 'c.shortname','c.id,c.shortname'); |
ed05bdfa |
584 | } else { |
585 | $courses = get_my_courses($USER->id, 'shortname'); |
586 | } |
34bf3ad4 |
587 | |
6c40f0dc |
588 | unset($courses[SITEID]); |
2d88c72a |
589 | |
69963aa6 |
590 | $courseoptions[SITEID] = get_string('fulllistofcourses'); |
ed05bdfa |
591 | foreach ($courses as $course) { |
592 | $courseoptions[$course->id] = $course->shortname; |
34bf3ad4 |
593 | } |
ed05bdfa |
594 | |
595 | if (is_numeric($SESSION->cal_courses_shown)) { |
8792061c |
596 | $selected = $SESSION->cal_courses_shown; |
ed05bdfa |
597 | } else { |
8792061c |
598 | $selected = ''; |
599 | } |
ed05bdfa |
600 | |
647213f7 |
601 | return popup_form(CALENDAR_URL.'set.php?var=setcourse&'.$getvars.'&id=', |
ed05bdfa |
602 | $courseoptions, 'cal_course_flt', $selected, '', '', '', true); |
34bf3ad4 |
603 | } |
604 | |
7423f116 |
605 | ?> |