Checking in latest calendar code! Looking great, Jon!
[moodle.git] / calendar / view.php
CommitLineData
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');
44 require_once('lib.php');
45 require_once('../course/lib.php');
46 require_once('../mod/forum/lib.php');
47
48 require_variable($_GET['view']);
49 optional_variable($_GET['cal_d']);
50 optional_variable($_GET['cal_m']);
51 optional_variable($_GET['cal_y']);
52
53 if(!$site = get_site()) {
54 redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
55 }
56
57 //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
58
59 $firstcolumn = false; // for now
60 $lastcolumn = true; // for now
61 $side = 175;
62
63 $prefmenu = true; // By default, display it
64 calendar_session_vars();
65 $now = usergetdate(time());
66 $pagetitle = '';
67
68 $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&amp;', $now['mday'], $now['mon'], $now['year']);
69
70 // Make sure that the GET variables are correct
71 $day = intval($_GET['cal_d']);
72 $mon = intval($_GET['cal_m']);
73 $yr = intval($_GET['cal_y']);
74 if(!checkdate($mon, $day, $yr)) {
75 $day = intval($now['mday']);
76 $mon = intval($now['mon']);
77 $yr = intval($now['year']);
78 }
79
80 switch($_GET['view']) {
81 case 'day':
82 $nav .= ' -> '.$day.' '.calendar_month_name($mon).' '.$yr;
83 $pagetitle = get_string('dayview', 'calendar');
84 break;
85 case 'month':
86 $nav .= ' -> '.calendar_month_name($mon).' '.$yr;
87 $pagetitle = get_string('detailedmonthview', 'calendar');
88 $lastcolumn = false;
89 break;
90 case 'upcoming':
91 $pagetitle = get_string('upcomingevents', 'calendar');
92 break;
93 case 'event':
94 $pagetitle = get_string('eventview', 'calendar');
95 $nav .= ' -> '.$pagetitle; // Smart guy... :)
96 break;
97 }
98
99 // Let's see if we are supposed to provide a referring course link
100 // but NOT for the "main page" course
101 if($SESSION->cal_course_referer > 1 &&
102 ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) {
103 // If we know about the referring course, show a return link
104 $nav = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$SESSION->cal_course_referer.'">'.$shortname.'</a> -> '.$nav;
105 }
106
107 // Print title and header
108 if(!empty($pagetitle)) {
109 $pagetitle = ': '.$pagetitle;
110 }
111 print_header(get_string('calendar', 'calendar').$pagetitle, $site->fullname, $nav,
112 '', '', true, '', '<p class="logininfo">'.user_login_string($site).'</p>');
113
114 echo calendar_overlib_html();
115
116 // Layout the whole page as three big columns.
117 echo '<table border="0" cellpadding="3" cellspacing="0" width="100%">';
118
119 // START: The left column ...
120 echo '<tr valign="top"><td valign="top" width="180">';
121
122 $sections = get_all_sections($site->id);
123
124 // Latest site news
125 if ($site->newsitems > 0 || $sections[0]->sequence || isediting($site->id) || isadmin()) {
126 echo "<td width=\"$side\" valign=top nowrap>";
127 $firstcolumn=true;
128
129 if ($sections[0]->sequence or isediting($site->id)) {
130 get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
131 print_section_block(get_string("mainmenu"), $site, $sections[0],
132 $mods, $modnames, $modnamesused, true, $side);
133 }
134 print_courses_sideblock(0, $side);
135 if ($site->newsitems) {
136 if ($news = forum_get_course_forum($site->id, "news")) {
137 print_side_block_start(get_string("latestnews"), $side, "sideblocklatestnews");
138 echo "<font size=\"-2\">";
139 forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false);
140 echo "</font>";
141 print_side_block_end();
142 }
143 }
144 print_spacer(1,$side);
145 }
146
147 if (iscreator()) {
148 if (!$firstcolumn) {
149 echo "<td width=\"$side\" valign=top nowrap>";
150 $firstcolumn=true;
151 }
152 print_admin_links($site->id, $side);
153 }
154
155 if ($firstcolumn) {
156 echo '</td>';
157 }
158
159 // END: The left column
160
161 // START: Middle column
162 if ($lastcolumn) {
163 echo '<td width="70%" valign="top\">';
164 }
165 else {
166 echo '<td width="100%" valign="top">';
167 }
168
169 if($prefmenu) {
170 $text = '<div style="float: left;">'.get_string('calendarheading', 'calendar', strip_tags($site->shortname)).'</div><div style="float: right;">';
171 $text.= calendar_get_preferences_menu();
172 $text.= '</div>';
173 }
174 else {
175 $text = get_string('calendarheading', 'calendar', strip_tags($site->shortname));
176 }
177
178 print_heading_block($text);
179 print_spacer(8, 1);
180
181 $defaultcourses = calendar_get_default_courses();
182 $courses = array();
183
184 calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
185
186 // Are we left with a bad filter in effect?
187 if($_GET['view'] != 'month') {
188 if(is_int($SESSION->cal_show_course)) {
189 // There is a filter in action that shows events from courses other than the current.
190 // Reset the filter... this effectively allows course filtering only in the month display.
191 // This filter resetting is also done in the course sideblock display, in case someone
192 // sets a filter for course X and then goes to view course Y.
193 $SESSION->cal_show_course = true;
194 }
195 }
196
197 switch($_GET['view']) {
198 case 'event':
199 optional_variable($_GET['id'], 0);
200 $event = get_record('event', 'id', intval($_GET['id']));
201 if($event === false) {
202 error('Invalid event id');
203 }
204 $date = calendar_show_event($event);
205 $day = $date['mday'];
206 $mon = $date['mon'];
207 $yr = $date['year'];
208 break;
209 case 'day':
210 calendar_show_day($day, $mon, $yr, $courses, $groups, $users);
211 break;
212 case 'month':
213 calendar_show_month_detailed($mon, $yr, $courses, $groups, $users);
214 break;
215 case 'upcoming':
216 calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
217 break;
218 }
219
220 echo '</td>';
221
222 // END: Middle column
223
224 // START: Last column (3-month display)
225 if ($lastcolumn) {
226 echo '<td valign="top">';
227 print_side_block_start(get_string('monthlyview', 'calendar'), '', 'sideblockmain');
228 list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
229 list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
230 echo calendar_filter_controls($_GET['view']);
231 echo '<p>';
232 echo calendar_top_controls('display', array('m' => $prevmon, 'y' => $prevyr));
233 echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
234 echo '</p><p>';
235 echo calendar_top_controls('display', array('m' => $mon, 'y' => $yr));
236 echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
237 echo '</p><p>';
238 echo calendar_top_controls('display', array('m' => $nextmon, 'y' => $nextyr));
239 echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
240 echo '</p>';
241 print_side_block_end();
242 print_spacer(1, $side);
243 echo '</td>';
244 }
245
246 echo '</tr></table>';
247 print_footer();
248
249function calendar_show_event($event) {
250 // In this case, we haven't been given month, day, year. So we 'll have to
251 // get them from the event date, and return them to the main function.
252
253 $startdate = usergetdate($event->timestart); // This is only to be returned
254 $coursecache = array();
255
256 print_side_block_start(get_string('eventview', 'calendar'), '', 'mycalendar');
257 calendar_print_event_table($event, $event->timestart, $event->timestart + $event->timeduration, $coursecache, true);
258 print_side_block_end();
259
260 return $startdate; // We need this to set "current" day, month, year
261}
262
263function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
264 global $CFG, $THEME;
265
266 if(!checkdate($m, $d, $y)) {
267 $now = usergetdate(time());
268 list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year']));
269 }
270
271 $starttime = make_timestamp($y, $m, $d);
272 $endtime = $starttime + SECS_IN_DAY - 1;
273 $whereclause = calendar_sql_where($starttime, $endtime, $users, $groups, $courses);
274
275 if($whereclause === false) {
276 $events = array();
277 }
278 else {
279 $events = get_records_select('event', $whereclause);
280 }
281
282 // New event button
283 if(isguest()) {
284 $text = get_string('dayview', 'calendar');
285 }
286 else {
287 $text = '<div style="float: left;">'.get_string('dayview', 'calendar').'</div><div style="float: right;">';
288 $text.= '<form style="display: inline;" action="'.CALENDAR_URL.'event.php" method="get">';
289 $text.= '<input type="hidden" name="action" value="new" />';
290 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
291 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
292 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
293 $text.= '</form></div>';
294 }
295
296 print_side_block_start($text, '', 'mycalendar');
297 echo '<p>'.calendar_top_controls('day', array('d' => $d, 'm' => $m, 'y' => $y)).'</p>';
298
299 if($events === false) {
300 // There is nothing to display today.
301 echo '<p style="text-align: center;">'.get_string('daywithnoevents', 'calendar').'</p>';
302 }
303 else {
304 $coursecache = array();
305 $summarize = array();
306
307 // First, print details about events that start today
308 foreach($events as $event) {
309 if($event->timestart >= $starttime && $event->timestart <= $endtime) {
310 // Print this
311 calendar_print_event_table($event, $starttime, $endtime, $coursecache);
312 }
313 else {
314 // Save this for later
315 $summarize[] = $event->id;
316 }
317 }
318
319 // Then, show a list of all events that just span this day
320 if(!empty($summarize)) {
321 $until = get_string('durationuntil', 'calendar');
322 echo '<p style="text-align: center;"><strong>'.get_string('spanningevents', 'calendar').':</strong></p>';
323 echo '<p style="text-align: center;"><ul>';
324 foreach($summarize as $index) {
325 $endstamp = $events[$index]->timestart + $events[$index]->timeduration;
326 $enddate = usergetdate($endstamp);
327 echo '<li><a href="view.php?view=event&amp;id='.$events[$index]->id.'">'.$events[$index]->name.'</a> ';
328 echo '('.$until.' <a href="'.calendar_get_link_href('view.php?view=day&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).'">';
329 echo calendar_day_representation($endstamp, false, false).'</a>)</li>';
330 }
331 echo '</ul></p>';
332 }
333 }
334
335 print_side_block_end();
336}
337
338function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
339 global $CFG, $SESSION, $USER;
340 global $day, $mon, $yr, $defaultcourses;
341
342 $getvars = 'from=month&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
343
344 $display = &New stdClass;
345 $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
346 $display->maxwday = $display->minwday + 6;
347
348 if(!empty($m) && !empty($y)) {
349 $thisdate = usergetdate(time()); // Time and day at the user's location
350 if($m == $thisdate['mon'] && $y == $thisdate['year']) {
351 // Navigated to this month
352 $date = $thisdate;
353 $display->thismonth = true;
354 }
355 else {
356 // Navigated to other month, let's do a nice trick and save us a lot of work...
357 if(!checkdate($m, 1, $y)) {
358 $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
359 $display->thismonth = true;
360 }
361 else {
362 $date = array('mday' => 1, 'mon' => $m, 'year' => $y);
363 $display->thismonth = false;
364 }
365 }
366 }
367 else {
368 $date = usergetdate(time());
369 $display->thismonth = true;
370 }
371
372 // Fill in the variables we 're going to use, nice and tidy
373 list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
374 $display->maxdays = calendar_days_in_month($m, $y);
375
376 // We 'll keep these values as GMT here, and offset them when the time comes to query the db
377 $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
378 $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
379
380 $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
381
382 // Align the starting weekday to fall in our display range
383 if($startwday < $display->minwday) {
384 $startwday += 7;
385 }
386
387 // Get events from database
388 $whereclause = calendar_sql_where(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
389 if($whereclause === false) {
390 $events = array();
391 }
392 else {
393 $events = get_records_select('event', $whereclause);
394 }
395
396 // Extract information: events vs. time
397 calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday);
398
399 // New event button
400 if(isguest()) {
401 $text = get_string('detailedmonthview', 'calendar');
402 }
403 else {
404 $text = '<div style="float: left;">'.get_string('detailedmonthview', 'calendar').'</div><div style="float: right;">';
405 $text.= '<form style="display: inline;" action="'.CALENDAR_URL.'event.php" method="get">';
406 $text.= '<input type="hidden" name="action" value="new" />';
407 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
408 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
409 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
410 $text.= '</form></div>';
411 }
412
413 print_side_block_start($text, '', 'mycalendar');
414 echo calendar_top_controls('month', array('m' => $m, 'y' => $y));
415
416 // Start calendar display
417 echo '<table class="calendarmonth"><tr>'; // Begin table. First row: day names
418
419 // Print out the names of the weekdays
420 $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
421 for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
422 // This uses the % operator to get the correct weekday no matter what shift we have
423 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
424 echo '<td class="calendarheader">'.get_string($days[$i % 7], 'calendar')."</td>\n";
425 }
426
427 echo '</tr><tr>'; // End of day names; prepare for day numbers
428
429 // For the table display. $week is the row; $dayweek is the column.
430 $week = 1;
431 $dayweek = $startwday;
432
433 // Paddding (the first week may have blank days in the beginning)
434 for($i = $display->minwday; $i < $startwday; ++$i) {
435 echo '<td class="calendardaymonth">&nbsp;</td>'."\n";
436 }
437
438 // Now display all the calendar
439 for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
440 if($dayweek > $display->maxwday) {
441 // We need to change week (table row)
442 echo "</tr>\n<tr>";
443 $dayweek = $display->minwday;
444 ++$week;
445 }
446
447 // Reset vars
448 $class = '';
449 $cell = '';
450 if($dayweek % 7 == 0 || $dayweek % 7 == 6) {
451 // Weekend. This is true no matter what the exact range is.
452 $class = 'calendardaymonth calendarweekend';
453 }
454 else {
455 // Normal working day.
456 $class = 'calendardaymonth';
457 }
458
459 // Special visual fx if an event is defined
460 if(isset($eventsbyday[$day])) {
461 if(isset($typesbyday[$day]['startglobal'])) {
462 $class .= ' cal_event_global';
463 }
464 else if(isset($typesbyday[$day]['startcourse'])) {
465 $class .= ' cal_event_course';
466 }
467 else if(isset($typesbyday[$day]['startgroup'])) {
468 $class .= ' cal_event_group';
469 }
470 else if(isset($typesbyday[$day]['startuser'])) {
471 $class .= ' cal_event_user';
472 }
473 if(count($eventsbyday[$day]) == 1) {
474 $title = get_string('oneevent', 'calendar');
475 }
476 else {
477 $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
478 }
479 $cell = '<strong><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=day&amp;', $day, $m, $y).'" title="'.$title.'">'.$day.'</a></strong>';
480 }
481 else {
482 $cell = $day;
483 }
484
485 // Special visual fx if an event spans many days
486 if(isset($typesbyday[$day]['durationglobal'])) {
487 $class .= ' cal_duration_global';
488 }
489 else if(isset($typesbyday[$day]['durationcourse'])) {
490 $class .= ' cal_duration_course';
491 }
492 else if(isset($typesbyday[$day]['durationgroup'])) {
493 $class .= ' cal_duration_group';
494 }
495 else if(isset($typesbyday[$day]['durationuser'])) {
496 $class .= ' cal_duration_user';
497 }
498
499 // Special visual fx for today
500 if($display->thismonth && $day == $d) {
501 $class .= ' cal_today';
502 }
503
504 // Just display it
505 echo '<td class="'.$class.'">'.$cell;
506 if(isset($eventsbyday[$day])) {
507 echo '<table>';
508 foreach($eventsbyday[$day] as $eventindex) {
509 echo '<tr><td valign="top"><strong>&middot;</strong></td>';
510 echo '<td><a href="'.CALENDAR_URL.'view.php?view=event&amp;id='.$events[$eventindex]->id.'">'.$events[$eventindex]->name.'</a></td></tr>';
511 }
512 echo '</table>';
513 }
514 if(isset($durationbyday[$day])) {
515 foreach($durationbyday[$day] as $eventindex) {
516 echo '<div class="dimmed_text">('.$events[$eventindex]->name.')</div>';
517 }
518 }
519 echo "</td>\n";
520 }
521
522 // Paddding (the last week may have blank days at the end)
523 for($i = $dayweek; $i <= $display->maxwday; ++$i) {
524 echo '<td class="calendardaymonth">&nbsp;</td>';
525 }
526 echo "</tr>\n"; // Last row ends
527
528 echo "</table>\n<br />\n"; // Tabular display of days ends
529
530 // OK, now for the filtering display
531 echo '<table class="cal_filters">';
532 echo '<tbody>';
533 echo '<tr>';
534
535 // Global events
536 if($SESSION->cal_show_global) {
537 echo '<td class="cal_event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
538 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
539 }
540 else {
541 echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
542 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
543 }
544
545 // Course events (this is kinda... tricky... :)
546 echo '<td ';
547 if($SESSION->cal_show_course !== false) {
548 echo 'class="cal_event_course" ';
549 }
550 echo 'style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
551
552 $defaultcourses = array_diff_assoc($defaultcourses, array(1 => 1)); // Filter the site out
553 $getcourses = array_keys($defaultcourses);
554
555 $select = 'id IN ('.implode(',', $getcourses).')';
556
557 $coursesdata = get_records_select('course', $select, 'fullname');
558 echo '<select name="course" onchange="document.location.href=\''.CALENDAR_URL.'set.php?var=setcourse&amp;'.$getvars.'&amp;id=\' + this.value;">';
559 echo '<option value="0"'.($SESSION->cal_show_course === false?' selected':'').'>'.get_string('hidden', 'calendar')."</option>\n";
560 echo '<option value="1"'.($SESSION->cal_show_course === true?' selected':'').'>'.get_string('shown', 'calendar')."</option>\n";
561 if($coursesdata !== false) {
562 foreach($coursesdata as $coursedata) {
563 echo "\n<option value='$coursedata->id'";
564 if(is_int($SESSION->cal_show_course) && $coursedata->id == $SESSION->cal_show_course) echo ' selected';
565 echo '>'.$coursedata->shortname."</option>\n";
566 }
567 }
568 echo '</select>';
569 echo '</td>';
570 echo "</tr>\n";
571 echo '<tr>';
572
573 // Group events
574 if($SESSION->cal_show_groups) {
575 echo '<td class="cal_event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
576 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
577 }
578 else {
579 echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
580 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
581 }
582 // User events
583 if($SESSION->cal_show_user) {
584 echo '<td class="cal_event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
585 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
586 }
587 else {
588 echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
589 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
590 }
591
592 echo "</tr>\n";
593 echo '<tbody></table><br />';
594 print_side_block_end();
595}
596
597function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents) {
598 $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);
599 $numevents = count($events);
600
601 if(!$numevents) {
602 // There are no events in the specified time period
603 return;
604 }
605
606 print_side_block_start(get_string('upcomingevents', 'calendar'), '', 'mycalendar');
607 for($i = 0; $i < $numevents; ++$i) {
608 echo '<p>';
609 if(!empty($events[$i]->icon)) {
610 echo '<span class="cal_event">'.$events[$i]->icon.' </span>';
611 }
612 if(!empty($events[$i]->referer) && empty($events[$i]->icon)) {
613 echo '<span class="calendarreferer">'.$events[$i]->referer.': </span>';
614 }
615 echo '<span class="cal_event">'.$events[$i]->name.":</span>\n";
616 if(!empty($events[$i]->referer) && !empty($events[$i]->icon)) {
617 echo '<span class="calendarreferer">'.$events[$i]->referer.': </span>';
618 }
619 echo '<span class="cal_event_date">'.$events[$i]->time.'</span>';
620 echo '<br />'.$events[$i]->description.'<br />';
621 if($i < $lines - 1) {
622 echo '<hr />';
623 }
624 echo '</p>';
625 }
626 print_side_block_end();
627}
628
629
630function calendar_print_event_table($event, $starttime, $endtime, &$coursecache, $alldetails = false) {
631 global $CFG;
632
633 echo '<table class="cal_event_table"><thead>';
634
635 if(calendar_edit_event_allowed($event)) {
636 echo '<tr><td colspan="2">'.$event->name;
637 echo ' <a href="'.CALENDAR_URL.'event.php?action=edit&amp;id='.$event->id.'"><img style="vertical-align: middle;" src="'.$CFG->pixpath.'/t/edit.gif" alt="'.get_string('tt_editevent', 'calendar').'" title="'.get_string('tt_editevent', 'calendar').'" /></a>';
638 echo ' <a href="'.CALENDAR_URL.'event.php?action=delete&amp;id='.$event->id.'"><img style="vertical-align: middle;" src="'.$CFG->pixpath.'/t/delete.gif" alt="'.get_string('tt_deleteevent', 'calendar').'" title="'.get_string('tt_deleteevent', 'calendar').'" /></a>';
639 echo '</td></tr>';
640 }
641 else {
642 echo '<tr><td colspan="2">'.$event->name.'</td></tr>';
643 }
644
645 echo "</thead>\n<tbody>\n<tr><td style='vertical-align: top;'>";
646
647 if(!empty($event->modulename)) {
648 // The module name is set. This handling code should be synchronized with that in calendar_get_upcoming()
649 $module = calendar_get_module_cached($coursecache, $event->modulename, $event->instance, $event->courseid);
650 if($module === false) {
651 // This shouldn't have happened. What to do now? Just ignore it...
652 echo '</td></tr></table>';
653 return;
654 }
655 $modulename = get_string('modulename', $event->modulename);
656 $eventtype = get_string($event->eventtype, $event->modulename);
657 $icon = $CFG->modpixpath.'/'.$event->modulename.'/icon.gif';
658 $coursereferer = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$module->course.'">'.$coursecache[$module->course]->fullname.'</a>';
659 $instancereferer = '<a href="'.$CFG->wwwroot.'/mod/'.$event->modulename.'/view.php?id='.$module->id.'">'.$module->name.'</a>';
660
661 echo '<div><strong>'.get_string('course').':</strong></div><div>'.$coursereferer.'</div>';
662 echo '<div><strong><img src="'.$icon.'" title="'.$modulename.'" style="vertical-align: middle;" /> '.$modulename.':</strong></div><div>'.$instancereferer.'</div>';
663 }
664 else if($event->courseid > 1) {
665 $course = calendar_get_course_cached($coursecache, $event->courseid);
666 $coursereferer = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>';
667 echo '<div><strong>'.get_string('course').':</strong></div><div>'.$coursereferer.'</div>';
668 }
669 else if($event->courseid == 1) {
670 echo '<div><strong>'.get_string('typesite', 'calendar').'</strong></div>';
671 }
672
673 if($event->timeduration) {
674 if($event->timestart + $event->timeduration > $endtime || $alldetails) {
675 // It doesn't end today, or full details requested, so we 'll go into a little more trouble
676 $enddate = usergetdate($event->timestart + $event->timeduration);
677 $enddisplay = calendar_get_link_tag(
678 calendar_day_representation($event->timestart + $event->timeduration, $starttime, false),
679 CALENDAR_URL.'view.php?view=day&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']);
680 $enddisplay .= ', '.calendar_time_representation($event->timestart + $event->timeduration);
681 }
682 else {
683 $enddisplay = calendar_time_representation($event->timestart + $event->timeduration);
684 }
685 if($alldetails) {
686 // We want to give a full representation of the event's date
687 $startdate = usergetdate($event->timestart);
688 $startdisplay = calendar_get_link_tag(
689 calendar_day_representation($event->timestart, $starttime, false),
690 CALENDAR_URL.'view.php?view=day&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']);
691 $startdisplay .= ', '.calendar_time_representation($event->timestart);
692 }
693 else {
694 $startdisplay = calendar_time_representation($event->timestart);
695 }
696 echo '<div><strong>'.get_string('eventstarttime', 'calendar').':</strong></div><div>'.$startdisplay.'</div>';
697 echo '<div><strong>'.get_string('eventendtime', 'calendar').':</strong></div><div>'.$enddisplay.'</div>';
698 }
699 else {
700 // Event without duration
701 if($alldetails) {
702 // We want to give a full representation of the event's date
703 $startdate = usergetdate($event->timestart);
704 $startdisplay = calendar_get_link_tag(
705 calendar_day_representation($event->timestart, $starttime, false),
706 CALENDAR_URL.'view.php?view=day&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']);
707 $startdisplay .= ', '.calendar_time_representation($event->timestart);
708 }
709 else {
710 $startdisplay = calendar_time_representation($event->timestart);
711 }
712 echo '<div><strong>'.get_string('eventinstanttime', 'calendar').':</strong></div><div>'.$startdisplay.'</div>';
713 }
714
715 echo '</td><td class="cal_event_description">'.$event->description.'</td></tr>'."\n";
716 echo "</tbody>\n</table>\n";
717}
718
719?>