dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/calendar/lib.php'); optional_variable($_GET['view'], 'upcoming'); optional_variable($_GET['course'], 0); optional_variable($_GET['cal_d']); optional_variable($_GET['cal_m']); optional_variable($_GET['cal_y']); if(!$site = get_site()) { redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php'); } //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); $now = usergetdate(time()); $pagetitle = ''; $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']); // Make sure that the GET variables are correct $day = intval($_GET['cal_d']); $mon = intval($_GET['cal_m']); $yr = intval($_GET['cal_y']); if(!checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); } $time = mktime(0, 0, 0, $mon, $day, $yr); switch($_GET['view']) { case 'day': $text = strftime(get_string('strftimedate'), $time); if($text[0] == '0') { $text = substr($text, 1); } $nav .= ' -> '.$text; $pagetitle = get_string('dayview', 'calendar'); break; case 'month': $nav .= ' -> '.strftime(get_string('strftimemonthyear'), $time); $pagetitle = get_string('detailedmonthview', 'calendar'); break; case 'upcoming': $pagetitle = get_string('upcomingevents', 'calendar'); break; } // If a course has been supplied in the URL, change the filters to show that one if (!empty($_GET['course'])) { if (is_numeric($_GET['course']) && $_GET['course'] > 0 && record_exists('course', 'id', $_GET['course'])) { if ($_GET['course'] == 1) { // If coming from the home page, show all courses $SESSION->cal_courses_shown = calendar_get_default_courses(true); calendar_set_referring_course(0); } else { // Otherwise show just this one $SESSION->cal_courses_shown = intval($_GET['course']); calendar_set_referring_course($SESSION->cal_courses_shown); } } } if (empty($USER->id) or isguest()) { $defaultcourses = calendar_get_default_courses(); calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses); } else { calendar_set_filters($courses, $groups, $users); } // Let's see if we are supposed to provide a referring course link // but NOT for the "main page" course if ($SESSION->cal_course_referer > 1 && ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) { // If we know about the referring course, show a return link and ALSO require login! require_login(); $nav = ''.$shortname.' -> '.$nav; } $strcalendar = get_string('calendar', 'calendar'); $prefsbutton = calendar_preferences_button(); // Print title and header print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $nav, '', '', true, $prefsbutton, '
'.user_login_string($site).'
'); echo calendar_overlib_html(); // Layout the whole page as three big columns. echo ''; switch($_GET['view']) { case 'day': calendar_show_day($day, $mon, $yr, $courses, $groups, $users); break; case 'month': calendar_show_month_detailed($mon, $yr, $courses, $groups, $users); break; case 'upcoming': calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS)); break; } echo ' | '; // END: Main column // START: Last column (3-month display) echo '';
print_side_block_start(get_string('monthlyview', 'calendar'));
list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
$getvars = 'cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
echo calendar_filter_controls($_GET['view'], $getvars);
echo ' ';
echo calendar_top_controls('display', array('m' => $prevmon, 'y' => $prevyr));
echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
echo ' ';
echo calendar_top_controls('display', array('m' => $mon, 'y' => $yr));
echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
echo ' ';
echo calendar_top_controls('display', array('m' => $nextmon, 'y' => $nextyr));
echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
echo ' ';
print_side_block_end();
print_spacer(1, 180);
echo ' | ';
echo '
'.get_string('daywithnoevents', 'calendar').'
'; } else { $underway = array(); // First, print details about events that start today foreach ($events as $event) { if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now /* $dayend = calendar_day_representation($event->timestart + $event->timeduration); $timeend = calendar_time_representation($event->timestart + $event->timeduration); $enddate = usergetdate($event->timestart + $event->timeduration); // Set printable representation echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')'; */ //unset($event->time); $event->time = calendar_format_event_time($event, time(), '', false); calendar_print_event($event); } else { // Save this for later $underway[] = $event; } } // Then, show a list of all events that just span this day if (!empty($underway)) { echo ''.get_string('spanningevents', 'calendar').':
'; foreach ($underway as $event) { $event->time = calendar_format_event_time($event, time(), '', false); calendar_print_event($event); } } } print_side_block_end(); } function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { global $CFG, $SESSION, $USER; global $day, $mon, $yr; $getvars = 'from=month&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering $display = &New stdClass; $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); $display->maxwday = $display->minwday + 6; if(!empty($m) && !empty($y)) { $thisdate = usergetdate(time()); // Time and day at the user's location if($m == $thisdate['mon'] && $y == $thisdate['year']) { // Navigated to this month $date = $thisdate; $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... if(!checkdate($m, 1, $y)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { $date = array('mday' => 1, 'mon' => $m, 'year' => $y); $display->thismonth = false; } } } else { $date = usergetdate(time()); $display->thismonth = true; } // Fill in the variables we 're going to use, nice and tidy list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display $display->maxdays = calendar_days_in_month($m, $y); // We 'll keep these values as GMT here, and offset them when the time comes to query the db $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ // Align the starting weekday to fall in our display range if($startwday < $display->minwday) { $startwday += 7; } // Get events from database $whereclause = calendar_sql_where(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses); if($whereclause === false) { $events = array(); } else { $events = get_records_select('event', $whereclause); } // Extract information: events vs. time calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday); // New event button if(empty($USER->id) || isguest()) { $text = get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars); } else { $text = ''.get_string($days[$i % 7], 'calendar').' | '; } echo '|||
'."\n"; } // Now display all the calendar for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { if($dayweek > $display->maxwday) { // We need to change week (table row) echo " | |||
'.$cell;
if(isset($eventsbyday[$day])) {
echo '
('.$events[$eventindex]->name.') ';
}
}
echo " | \n";
}
// Paddding (the last week may have blank days at the end)
for($i = $dayweek; $i <= $display->maxwday; ++$i) {
echo ''; } echo " |
'.get_string('globalevents', 'calendar').': '; echo get_string('shown', 'calendar').' ('.get_string('clickhide', 'calendar').') | '."\n"; } else { echo ''.get_string('globalevents', 'calendar').': '; echo get_string('hidden', 'calendar').' ('.get_string('clickshow', 'calendar').') | '."\n"; } // Course events if(!empty($SESSION->cal_show_course)) { echo ''.get_string('courseevents', 'calendar').': '; echo get_string('shown', 'calendar').' ('.get_string('clickhide', 'calendar').') | '."\n"; } else { echo ''.get_string('courseevents', 'calendar').': '; echo get_string('hidden', 'calendar').' ('.get_string('clickshow', 'calendar').') | '."\n"; } echo "||||
'.get_string('groupevents', 'calendar').': '; echo get_string('shown', 'calendar').' ('.get_string('clickhide', 'calendar').') | '."\n"; } else { echo ''.get_string('groupevents', 'calendar').': '; echo get_string('hidden', 'calendar').' ('.get_string('clickshow', 'calendar').') | '."\n"; } // User events if($SESSION->cal_show_user) { echo ''.get_string('userevents', 'calendar').': '; echo get_string('shown', 'calendar').' ('.get_string('clickhide', 'calendar').') | '."\n"; } else { echo ''.get_string('userevents', 'calendar').': '; echo get_string('hidden', 'calendar').' ('.get_string('clickshow', 'calendar').') | '."\n"; } echo "