Commit | Line | Data |
---|---|---|
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: // | |
bdcb26b7 | 12 | // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) // |
13 | // Jon Papaioannou (pj@moodle.org) // | |
7423f116 | 14 | // // |
15 | // Programming and development: // | |
bdcb26b7 | 16 | // Jon Papaioannou (pj@moodle.org) // |
7423f116 | 17 | // // |
18 | // For bugs, suggestions, etc contact: // | |
bdcb26b7 | 19 | // Jon Papaioannou (pj@moodle.org) // |
7423f116 | 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 | ||
c9c9fb90 | 57 | $url = new moodle_url($CFG->wwwroot.'/calendar/view.php'); |
58 | if ($courseid !== 0) { | |
59 | $url->param('course', $courseid); | |
60 | } | |
61 | if ($view !== 'upcoming') { | |
62 | $url->param('view', $view); | |
63 | } | |
64 | if ($day !== 0) { | |
65 | $url->param('cal_d', $day); | |
66 | } | |
67 | if ($mon !== 0) { | |
68 | $url->param('cal_m', $mon); | |
69 | } | |
70 | if ($yr !== 0) { | |
71 | $url->param('cal_y', $yr); | |
72 | } | |
73 | $PAGE->set_url($url); | |
74 | ||
7dc30088 | 75 | if ($courseid) { |
76 | require_login($courseid); | |
77 | } else if ($CFG->forcelogin) { | |
2d4fb02f | 78 | require_login(); |
79 | } | |
80 | ||
37d87d11 | 81 | // Initialize the session variables |
82 | calendar_session_vars(); | |
83 | ||
7423f116 | 84 | //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); |
7423f116 | 85 | $now = usergetdate(time()); |
86 | $pagetitle = ''; | |
87 | ||
e295df44 | 88 | $strcalendar = get_string('calendar', 'calendar'); |
f22f1333 | 89 | |
90 | $link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$courseid.'&', | |
91 | $now['mday'], $now['mon'], $now['year']); | |
92 | $PAGE->navbar->add($strcalendar, new moodle_url($link)); | |
7423f116 | 93 | |
7423f116 | 94 | if(!checkdate($mon, $day, $yr)) { |
95 | $day = intval($now['mday']); | |
96 | $mon = intval($now['mon']); | |
97 | $yr = intval($now['year']); | |
98 | } | |
5147ad48 | 99 | $time = make_timestamp($yr, $mon, $day); |
7423f116 | 100 | |
482dbe0c | 101 | switch($view) { |
7423f116 | 102 | case 'day': |
f22f1333 | 103 | $PAGE->navbar->add(userdate($time, get_string('strftimedate'))); |
7423f116 | 104 | $pagetitle = get_string('dayview', 'calendar'); |
105 | break; | |
106 | case 'month': | |
f22f1333 | 107 | $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear'))); |
7423f116 | 108 | $pagetitle = get_string('detailedmonthview', 'calendar'); |
7423f116 | 109 | break; |
110 | case 'upcoming': | |
111 | $pagetitle = get_string('upcomingevents', 'calendar'); | |
112 | break; | |
7423f116 | 113 | } |
114 | ||
227bc46b | 115 | // If a course has been supplied in the URL, change the filters to show that one |
7dc30088 | 116 | if (!empty($courseid)) { |
62d11d77 | 117 | if ($course = $DB->get_record('course', array('id'=>$courseid))) { |
69963aa6 | 118 | if ($course->id == SITEID) { |
89adb174 | 119 | // If coming from the home page, show all courses |
120 | $SESSION->cal_courses_shown = calendar_get_default_courses(true); | |
121 | calendar_set_referring_course(0); | |
fd5594a0 | 122 | |
123 | } else { | |
89adb174 | 124 | // Otherwise show just this one |
d57fc786 | 125 | $SESSION->cal_courses_shown = $course->id; |
89adb174 | 126 | calendar_set_referring_course($SESSION->cal_courses_shown); |
127 | } | |
227bc46b | 128 | } |
7dc30088 | 129 | } else { |
130 | $course = null; | |
227bc46b | 131 | } |
132 | ||
1066e0dc | 133 | if (empty($USER->id) or isguest()) { |
43c3ffbe | 134 | $defaultcourses = calendar_get_default_courses(); |
135 | calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses); | |
fd5594a0 | 136 | |
137 | } else { | |
34bf3ad4 | 138 | calendar_set_filters($courses, $groups, $users); |
43c3ffbe | 139 | } |
140 | ||
7423f116 | 141 | // Let's see if we are supposed to provide a referring course link |
142 | // but NOT for the "main page" course | |
69963aa6 | 143 | if ($SESSION->cal_course_referer != SITEID && |
62d11d77 | 144 | ($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer))) !== false) { |
08cebf19 | 145 | require_login(); |
d57fc786 | 146 | if (empty($course)) { |
62d11d77 | 147 | $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer)); // Useful to have around |
d57fc786 | 148 | } |
7423f116 | 149 | } |
150 | ||
1e1ff33b | 151 | $strcalendar = get_string('calendar', 'calendar'); |
1e1ff33b | 152 | $prefsbutton = calendar_preferences_button(); |
153 | ||
7423f116 | 154 | // Print title and header |
f22f1333 | 155 | $PAGE->set_title("$site->shortname: $strcalendar: $pagetitle"); |
156 | $PAGE->set_heading($strcalendar); | |
157 | $PAGE->set_headingmenu(user_login_string($site)); | |
158 | $PAGE->set_button($prefsbutton); | |
159 | ||
c9c9fb90 | 160 | $PAGE->requires->yui_lib('animation'); |
161 | $PAGE->requires->js('calendar/calendar.js'); | |
162 | ||
f22f1333 | 163 | echo $OUTPUT->header(); |
7423f116 | 164 | |
7423f116 | 165 | // Layout the whole page as three big columns. |
3c49918a | 166 | echo '<table id="calendar" style="height:100%;">'; |
7d50b363 | 167 | echo '<tr>'; |
7423f116 | 168 | |
ff2ec3b5 | 169 | // START: Main column |
7423f116 | 170 | |
7d50b363 | 171 | echo '<td class="maincalendar">'; |
3c49918a | 172 | echo '<div class="heightcontainer">'; |
7423f116 | 173 | |
482dbe0c | 174 | switch($view) { |
7423f116 | 175 | case 'day': |
f21ed0f3 | 176 | calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid); |
7423f116 | 177 | break; |
178 | case 'month': | |
f21ed0f3 | 179 | calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid); |
7423f116 | 180 | break; |
181 | case 'upcoming': | |
f21ed0f3 | 182 | calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid); |
7423f116 | 183 | break; |
184 | } | |
3c49918a | 185 | |
ea185313 | 186 | //Link to calendar export page |
d08472fc | 187 | echo $OUTPUT->container_start('bottom'); |
dbf9d4cb | 188 | if (!empty($CFG->enablecalendarexport)) { |
d08472fc | 189 | echo $OUTPUT->button(html_form::make_button('export.php', array('course'=>$courseid), get_string('exportcalendar', 'calendar'))); |
dbf9d4cb | 190 | |
191 | if (!empty($USER->id)) { | |
b20c6318 | 192 | $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt); |
dbf9d4cb | 193 | $usernameencoded = urlencode($USER->username); |
194 | ||
195 | echo "<a href=\"export_execute.php?preset_what=all&preset_time=recentupcoming&username=$usernameencoded&authtoken=$authtoken\">" | |
6b608f8f | 196 | .'<img src="'.$OUTPUT->old_icon_url('i/ical') . '" height="14" width="36" ' |
dbf9d4cb | 197 | .'alt="'.get_string('ical', 'calendar').'" ' |
198 | .'title="'.get_string('quickdownloadcalendar', 'calendar').'" />' | |
199 | .'</a>'; | |
200 | } | |
ea185313 | 201 | } |
7423f116 | 202 | |
d08472fc | 203 | echo $OUTPUT->container_end(); |
3c49918a | 204 | echo '</div>'; |
7423f116 | 205 | echo '</td>'; |
206 | ||
ff2ec3b5 | 207 | // END: Main column |
7423f116 | 208 | |
209 | // START: Last column (3-month display) | |
7d50b363 | 210 | echo '<td class="sidecalendar">'; |
ff2ec3b5 | 211 | list($prevmon, $prevyr) = calendar_sub_month($mon, $yr); |
212 | list($nextmon, $nextyr) = calendar_add_month($mon, $yr); | |
f21ed0f3 | 213 | $getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering |
7d50b363 | 214 | |
03beb65b | 215 | $content='<div class="filters">'; |
216 | $content.=calendar_filter_controls($view, $getvars, NULL, $courses); | |
217 | $content.='</div>'; | |
218 | ||
219 | print_side_block(get_string('eventskey', 'calendar'),$content); | |
220 | ||
221 | $content='<div class="minicalendarblock minicalendartop">'; | |
222 | $content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr)); | |
223 | $content.=calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr); | |
224 | $content.='</div><div class="minicalendarblock">'; | |
225 | $content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr)); | |
226 | $content.=calendar_get_mini($courses, $groups, $users, $mon, $yr); | |
227 | $content.='</div><div class="minicalendarblock">'; | |
228 | $content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr)); | |
229 | $content.=calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr); | |
230 | $content.='</div>'; | |
231 | ||
232 | print_side_block(get_string('monthlyview', 'calendar'),$content); | |
7d50b363 | 233 | |
ff2ec3b5 | 234 | echo '</td>'; |
7423f116 | 235 | |
236 | echo '</tr></table>'; | |
ff2ec3b5 | 237 | |
9314a6be | 238 | echo $OUTPUT->footer(); |
7423f116 | 239 | |
9958a08c | 240 | |
241 | ||
f21ed0f3 | 242 | function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) { |
4a2c4132 | 243 | global $CFG, $USER; |
7423f116 | 244 | |
9958a08c | 245 | if (!checkdate($m, $d, $y)) { |
7423f116 | 246 | $now = usergetdate(time()); |
247 | list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year'])); | |
248 | } | |
249 | ||
34bf3ad4 | 250 | $getvars = 'from=day&cal_d='.$d.'&cal_m='.$m.'&cal_y='.$y; // For filtering |
251 | ||
7423f116 | 252 | $starttime = make_timestamp($y, $m, $d); |
3c7e1b65 | 253 | $endtime = make_timestamp($y, $m, $d + 1) - 1; |
7423f116 | 254 | |
9958a08c | 255 | $events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime); |
7423f116 | 256 | |
2ad2cbc3 | 257 | $text = ''; |
86ac8b24 | 258 | if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) { |
2ad2cbc3 | 259 | $text.= '<div class="buttons">'; |
260 | $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">'; | |
2aab6488 | 261 | $text.= '<div>'; |
7423f116 | 262 | $text.= '<input type="hidden" name="action" value="new" />'; |
f21ed0f3 | 263 | $text.= '<input type="hidden" name="course" value="'.$courseid.'" />'; |
11b0ffe8 | 264 | $text.= '<input type="hidden" name="cal_d" value="'.$d.'" />'; |
7423f116 | 265 | $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />'; |
266 | $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />'; | |
267 | $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />'; | |
2aab6488 | 268 | $text.= '</div></form></div>'; |
7423f116 | 269 | } |
270 | ||
2ad2cbc3 | 271 | $text .= get_string('dayview', 'calendar').': '.calendar_course_filter_selector($getvars); |
272 | ||
df349d1d | 273 | echo '<div class="header">'.$text.'</div>'; |
7d50b363 | 274 | |
f21ed0f3 | 275 | echo '<div class="controls">'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'</div>'; |
7423f116 | 276 | |
9958a08c | 277 | if (empty($events)) { |
7423f116 | 278 | // There is nothing to display today. |
3477a900 | 279 | echo '<h3>'.get_string('daywithnoevents', 'calendar').'</h3>'; |
9958a08c | 280 | |
281 | } else { | |
282 | ||
2ad2cbc3 | 283 | echo '<div class="eventlist">'; |
284 | ||
9958a08c | 285 | $underway = array(); |
7423f116 | 286 | |
287 | // First, print details about events that start today | |
9958a08c | 288 | foreach ($events as $event) { |
7c50db30 | 289 | |
54052a7a | 290 | $event->calendarcourseid = $courseid; |
7c50db30 | 291 | |
9958a08c | 292 | if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now |
9d567178 | 293 | |
9d567178 | 294 | |
8f896582 | 295 | /* |
9d567178 | 296 | $dayend = calendar_day_representation($event->timestart + $event->timeduration); |
297 | $timeend = calendar_time_representation($event->timestart + $event->timeduration); | |
298 | $enddate = usergetdate($event->timestart + $event->timeduration); | |
299 | // Set printable representation | |
300 | echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')'; | |
301 | */ | |
8f896582 | 302 | //unset($event->time); |
b4892fa2 | 303 | |
b4892fa2 | 304 | $event->time = calendar_format_event_time($event, time(), '', false, $starttime); |
227bc46b | 305 | calendar_print_event($event); |
9958a08c | 306 | |
307 | } else { // Save this for later | |
308 | $underway[] = $event; | |
7423f116 | 309 | } |
310 | } | |
311 | ||
312 | // Then, show a list of all events that just span this day | |
9958a08c | 313 | if (!empty($underway)) { |
3c134875 | 314 | echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>'; |
9958a08c | 315 | foreach ($underway as $event) { |
b4892fa2 | 316 | $event->time = calendar_format_event_time($event, time(), '', false, $starttime); |
227bc46b | 317 | calendar_print_event($event); |
7423f116 | 318 | } |
7423f116 | 319 | } |
2ad2cbc3 | 320 | |
321 | echo '</div>'; | |
322 | ||
7423f116 | 323 | } |
7423f116 | 324 | } |
325 | ||
f21ed0f3 | 326 | function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) { |
f2bffd9e | 327 | global $CFG, $SESSION, $USER, $CALENDARDAYS; |
2b10fcf5 | 328 | global $day, $mon, $yr; |
7423f116 | 329 | |
330 | $getvars = 'from=month&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering | |
331 | ||
62d11d77 | 332 | $display = new stdClass; |
7423f116 | 333 | $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); |
334 | $display->maxwday = $display->minwday + 6; | |
335 | ||
336 | if(!empty($m) && !empty($y)) { | |
337 | $thisdate = usergetdate(time()); // Time and day at the user's location | |
338 | if($m == $thisdate['mon'] && $y == $thisdate['year']) { | |
339 | // Navigated to this month | |
340 | $date = $thisdate; | |
341 | $display->thismonth = true; | |
342 | } | |
343 | else { | |
344 | // Navigated to other month, let's do a nice trick and save us a lot of work... | |
345 | if(!checkdate($m, 1, $y)) { | |
346 | $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); | |
347 | $display->thismonth = true; | |
348 | } | |
349 | else { | |
350 | $date = array('mday' => 1, 'mon' => $m, 'year' => $y); | |
351 | $display->thismonth = false; | |
352 | } | |
353 | } | |
354 | } | |
355 | else { | |
356 | $date = usergetdate(time()); | |
357 | $display->thismonth = true; | |
358 | } | |
359 | ||
360 | // Fill in the variables we 're going to use, nice and tidy | |
361 | list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display | |
362 | $display->maxdays = calendar_days_in_month($m, $y); | |
363 | ||
6cc1a805 | 364 | $startwday = 0; |
449c1d6c | 365 | if (get_user_timezone_offset() < 99) { |
366 | // We 'll keep these values as GMT here, and offset them when the time comes to query the db | |
367 | $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT | |
368 | $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT | |
6cc1a805 | 369 | $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ |
449c1d6c | 370 | } else { |
371 | // no timezone info specified | |
372 | $display->tstart = mktime(0, 0, 0, $m, 1, $y); | |
373 | $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); | |
6cc1a805 | 374 | $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() |
449c1d6c | 375 | } |
7423f116 | 376 | |
7423f116 | 377 | // Align the starting weekday to fall in our display range |
378 | if($startwday < $display->minwday) { | |
379 | $startwday += 7; | |
380 | } | |
381 | ||
382 | // Get events from database | |
8263f802 | 383 | $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses); |
13534ef7 ML |
384 | if (!empty($events)) { |
385 | foreach($events as $eventid => $event) { | |
386 | if (!empty($event->modulename)) { | |
387 | $cm = get_coursemodule_from_instance($event->modulename, $event->instance); | |
388 | if (!groups_course_module_visible($cm)) { | |
389 | unset($events[$eventid]); | |
390 | } | |
391 | } | |
392 | } | |
393 | } | |
394 | ||
7423f116 | 395 | // Extract information: events vs. time |
7c50db30 | 396 | calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); |
7423f116 | 397 | |
2ad2cbc3 | 398 | $text = ''; |
86ac8b24 | 399 | if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) { |
2ad2cbc3 | 400 | $text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">'; |
2aab6488 | 401 | $text.= '<div>'; |
7423f116 | 402 | $text.= '<input type="hidden" name="action" value="new" />'; |
f21ed0f3 | 403 | $text.= '<input type="hidden" name="course" value="'.$courseid.'" />'; |
7423f116 | 404 | $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />'; |
405 | $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />'; | |
406 | $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />'; | |
2aab6488 | 407 | $text.= '</div></form></div>'; |
7423f116 | 408 | } |
409 | ||
2ad2cbc3 | 410 | $text .= get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars); |
411 | ||
df349d1d | 412 | echo '<div class="header">'.$text.'</div>'; |
43c3ffbe | 413 | |
7d50b363 | 414 | echo '<div class="controls">'; |
f21ed0f3 | 415 | echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y)); |
7d50b363 | 416 | echo '</div>'; |
7423f116 | 417 | |
418 | // Start calendar display | |
f136e4c5 | 419 | echo '<table class="calendarmonth"><tr class="weekdays">'; // Begin table. First row: day names |
7423f116 | 420 | |
421 | // Print out the names of the weekdays | |
7423f116 | 422 | for($i = $display->minwday; $i <= $display->maxwday; ++$i) { |
423 | // This uses the % operator to get the correct weekday no matter what shift we have | |
424 | // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 | |
54926e78 | 425 | echo '<th scope="col">'.get_string($CALENDARDAYS[$i % 7], 'calendar').'</th>'; |
7423f116 | 426 | } |
427 | ||
f136e4c5 | 428 | echo '</tr><tr>'; // End of day names; prepare for day numbers |
7423f116 | 429 | |
430 | // For the table display. $week is the row; $dayweek is the column. | |
431 | $week = 1; | |
432 | $dayweek = $startwday; | |
433 | ||
434 | // Paddding (the first week may have blank days in the beginning) | |
435 | for($i = $display->minwday; $i < $startwday; ++$i) { | |
b4892fa2 | 436 | echo '<td class="nottoday"> </td>'."\n"; |
7423f116 | 437 | } |
438 | ||
439 | // Now display all the calendar | |
440 | for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { | |
441 | if($dayweek > $display->maxwday) { | |
442 | // We need to change week (table row) | |
443 | echo "</tr>\n<tr>"; | |
444 | $dayweek = $display->minwday; | |
445 | ++$week; | |
446 | } | |
447 | ||
448 | // Reset vars | |
7423f116 | 449 | $cell = ''; |
f21ed0f3 | 450 | $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&course='.$courseid.'&', $day, $m, $y); |
f434283f | 451 | |
bb4a2e85 | 452 | if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) { |
7423f116 | 453 | // Weekend. This is true no matter what the exact range is. |
edbe6c1b | 454 | $class = 'weekend'; |
7423f116 | 455 | } |
456 | else { | |
457 | // Normal working day. | |
92668ad2 | 458 | $class = ''; |
7423f116 | 459 | } |
460 | ||
461 | // Special visual fx if an event is defined | |
462 | if(isset($eventsbyday[$day])) { | |
7423f116 | 463 | if(count($eventsbyday[$day]) == 1) { |
464 | $title = get_string('oneevent', 'calendar'); | |
465 | } | |
466 | else { | |
467 | $title = get_string('manyevents', 'calendar', count($eventsbyday[$day])); | |
468 | } | |
edbe6c1b | 469 | $cell = '<div class="day"><a href="'.$dayhref.'" title="'.$title.'">'.$day.'</a></div>'; |
7423f116 | 470 | } |
471 | else { | |
edbe6c1b | 472 | $cell = '<div class="day">'.$day.'</div>'; |
7423f116 | 473 | } |
474 | ||
475 | // Special visual fx if an event spans many days | |
476 | if(isset($typesbyday[$day]['durationglobal'])) { | |
edbe6c1b | 477 | $class .= ' duration_global'; |
7423f116 | 478 | } |
479 | else if(isset($typesbyday[$day]['durationcourse'])) { | |
edbe6c1b | 480 | $class .= ' duration_course'; |
7423f116 | 481 | } |
482 | else if(isset($typesbyday[$day]['durationgroup'])) { | |
edbe6c1b | 483 | $class .= ' duration_group'; |
7423f116 | 484 | } |
485 | else if(isset($typesbyday[$day]['durationuser'])) { | |
edbe6c1b | 486 | $class .= ' duration_user'; |
7423f116 | 487 | } |
488 | ||
489 | // Special visual fx for today | |
490 | if($display->thismonth && $day == $d) { | |
edbe6c1b | 491 | $class .= ' today'; |
b4892fa2 | 492 | } else { |
493 | $class .= ' nottoday'; | |
7423f116 | 494 | } |
495 | ||
496 | // Just display it | |
92668ad2 | 497 | if(!empty($class)) { |
498 | $class = ' class="'.trim($class).'"'; | |
499 | } | |
500 | echo '<td'.$class.'>'.$cell; | |
501 | ||
7423f116 | 502 | if(isset($eventsbyday[$day])) { |
760e522b | 503 | echo '<ul class="events-new">'; |
7423f116 | 504 | foreach($eventsbyday[$day] as $eventindex) { |
b4892fa2 | 505 | |
506 | // If event has a class set then add it to the event <li> tag | |
507 | $eventclass = ''; | |
508 | if (!empty($events[$eventindex]->class)) { | |
509 | $eventclass = ' class="'.$events[$eventindex]->class.'"'; | |
510 | } | |
511 | ||
512 | echo '<li'.$eventclass.'><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>'; | |
7423f116 | 513 | } |
edbe6c1b | 514 | echo '</ul>'; |
7423f116 | 515 | } |
516 | if(isset($durationbyday[$day])) { | |
760e522b | 517 | echo '<ul class="events-underway">'; |
7423f116 | 518 | foreach($durationbyday[$day] as $eventindex) { |
fb73f3b3 | 519 | echo '<li>['.format_string($events[$eventindex]->name,true).']</li>'; |
7423f116 | 520 | } |
760e522b | 521 | echo '</ul>'; |
7423f116 | 522 | } |
523 | echo "</td>\n"; | |
524 | } | |
525 | ||
526 | // Paddding (the last week may have blank days at the end) | |
527 | for($i = $dayweek; $i <= $display->maxwday; ++$i) { | |
b4892fa2 | 528 | echo '<td class="nottoday"> </td>'; |
7423f116 | 529 | } |
f136e4c5 | 530 | echo "</tr>\n"; // Last row ends |
7423f116 | 531 | |
7d50b363 | 532 | echo "</table>\n"; // Tabular display of days ends |
7423f116 | 533 | |
e3bb6401 | 534 | // OK, now for the filtering display |
535 | echo '<div class="filters"><table><tr>'; | |
536 | ||
537 | // Global events | |
538 | if($SESSION->cal_show_global) { | |
539 | echo '<td class="event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> '; | |
540 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; | |
541 | } | |
542 | else { | |
543 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> '; | |
544 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; | |
545 | } | |
546 | ||
547 | // Course events | |
548 | if(!empty($SESSION->cal_show_course)) { | |
549 | echo '<td class="event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> '; | |
550 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; | |
551 | } | |
552 | else { | |
553 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> '; | |
554 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; | |
555 | } | |
556 | ||
557 | echo "</tr>\n"; | |
558 | ||
559 | if(!empty($USER->id) && !isguest()) { | |
560 | echo '<tr>'; | |
561 | // Group events | |
562 | if($SESSION->cal_show_groups) { | |
563 | echo '<td class="event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> '; | |
564 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; | |
565 | } | |
566 | else { | |
567 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> '; | |
568 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; | |
569 | } | |
570 | // User events | |
571 | if($SESSION->cal_show_user) { | |
572 | echo '<td class="event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> '; | |
573 | echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n"; | |
574 | } | |
575 | else { | |
576 | echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> '; | |
577 | echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n"; | |
578 | } | |
579 | echo "</tr>\n"; | |
580 | } | |
581 | ||
582 | echo '</table></div>'; | |
7423f116 | 583 | } |
584 | ||
f21ed0f3 | 585 | function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents, $courseid) { |
bca9ba8c | 586 | global $USER, $OUTPUT; |
552064d3 | 587 | |
7423f116 | 588 | $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents); |
7423f116 | 589 | |
edbe6c1b | 590 | $text = ''; |
552064d3 | 591 | |
86ac8b24 | 592 | if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) { |
edbe6c1b | 593 | $text.= '<div class="buttons">'; |
594 | $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">'; | |
2aab6488 | 595 | $text.= '<div>'; |
f10f1b7b | 596 | $text.= '<input type="hidden" name="action" value="new" />'; |
f21ed0f3 | 597 | $text.= '<input type="hidden" name="course" value="'.$courseid.'" />'; |
227bc46b | 598 | /* |
f10f1b7b | 599 | $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />'; |
600 | $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />'; | |
227bc46b | 601 | */ |
f10f1b7b | 602 | $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />'; |
2aab6488 | 603 | $text.= '</div></form></div>'; |
7423f116 | 604 | } |
605 | ||
edbe6c1b | 606 | $text .= get_string('upcomingevents', 'calendar').': '.calendar_course_filter_selector('from=upcoming'); |
607 | ||
df349d1d | 608 | echo '<div class="header">'.$text.'</div>'; |
7d50b363 | 609 | |
9958a08c | 610 | if ($events) { |
b4892fa2 | 611 | |
edbe6c1b | 612 | echo '<div class="eventlist">'; |
9958a08c | 613 | foreach ($events as $event) { |
b426fd83 | 614 | $event->calendarcourseid = $courseid; |
9958a08c | 615 | calendar_print_event($event); |
616 | } | |
edbe6c1b | 617 | echo '</div>'; |
9958a08c | 618 | } else { |
bca9ba8c | 619 | echo $OUTPUT->heading(get_string('noupcomingevents', 'calendar')); |
7423f116 | 620 | } |
7423f116 | 621 | } |
622 | ||
34bf3ad4 | 623 | function calendar_course_filter_selector($getvars = '') { |
5da8e2ee | 624 | global $USER, $SESSION, $OUTPUT; |
34bf3ad4 | 625 | |
1066e0dc | 626 | if (empty($USER->id) or isguest()) { |
8792061c | 627 | return ''; |
628 | } | |
629 | ||
ef35441d | 630 | if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) { |
e6d1d120 | 631 | $courses = get_courses('all', 'c.shortname','c.id,c.shortname'); |
ed05bdfa | 632 | } else { |
633 | $courses = get_my_courses($USER->id, 'shortname'); | |
634 | } | |
34bf3ad4 | 635 | |
6c40f0dc | 636 | unset($courses[SITEID]); |
2d88c72a | 637 | |
69963aa6 | 638 | $courseoptions[SITEID] = get_string('fulllistofcourses'); |
ed05bdfa | 639 | foreach ($courses as $course) { |
bf0b04f3 | 640 | $courseoptions[$course->id] = format_string($course->shortname); |
34bf3ad4 | 641 | } |
ed05bdfa | 642 | |
643 | if (is_numeric($SESSION->cal_courses_shown)) { | |
8792061c | 644 | $selected = $SESSION->cal_courses_shown; |
ed05bdfa | 645 | } else { |
8792061c | 646 | $selected = ''; |
647 | } | |
7b1f2c82 | 648 | $select = html_select::make_popup_form(CALENDAR_URL.'set.php?var=setcourse&'.$getvars, 'id', $courseoptions, 'cal_courses_flt', $selected); |
5da8e2ee | 649 | $select->nothinglabel = false; |
650 | return $OUTPUT->select($select); | |
34bf3ad4 | 651 | } |
652 | ||
7423f116 | 653 | ?> |