wwwroot.'/'.$CFG->admin.'/index.php');
}
//add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
$side = 175;
$prefmenu = true; // By default, display it
calendar_session_vars();
$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;
case 'event':
$pagetitle = get_string('eventview', 'calendar');
$nav .= ' -> '.$pagetitle; // Smart guy... :)
break;
}
// 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
$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 '
';
echo '
';
// START: Main column
echo '
';
$defaultcourses = calendar_get_default_courses();
$courses = array();
calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
// Are we left with a bad filter in effect?
if($_GET['view'] != 'month') {
if(is_int($SESSION->cal_show_course)) {
// There is a filter in action that shows events from courses other than the current.
// Reset the filter... this effectively allows course filtering only in the month display.
// This filter resetting is also done in the course sideblock display, in case someone
// sets a filter for course X and then goes to view course Y.
$SESSION->cal_show_course = true;
}
}
switch($_GET['view']) {
case 'event':
optional_variable($_GET['id'], 0);
$event = get_record('event', 'id', intval($_GET['id']));
if($event === false) {
error('Invalid event id');
}
$date = calendar_show_event($event);
$day = $date['mday'];
$mon = $date['mon'];
$yr = $date['year'];
break;
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_footer();
function calendar_show_event($event) {
// In this case, we haven't been given month, day, year. So we 'll have to
// get them from the event date, and return them to the main function.
$startdate = usergetdate($event->timestart); // This is only to be returned
$coursecache = array();
print_side_block_start(get_string('eventview', 'calendar'), '', 'mycalendar');
calendar_print_event_table($event, $event->timestart, $event->timestart + $event->timeduration, $coursecache, true);
print_side_block_end();
return $startdate; // We need this to set "current" day, month, year
}
function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
global $CFG, $THEME;
if(!checkdate($m, $d, $y)) {
$now = usergetdate(time());
list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year']));
}
$starttime = make_timestamp($y, $m, $d);
$endtime = $starttime + SECS_IN_DAY - 1;
$whereclause = calendar_sql_where($starttime, $endtime, $users, $groups, $courses);
if($whereclause === false) {
$events = array();
}
else {
$events = get_records_select('event', $whereclause);
}
// New event button
if(isguest()) {
$text = get_string('dayview', 'calendar');
}
else {
$text = '
';
if($events === false) {
// There is nothing to display today.
echo '
'.get_string('daywithnoevents', 'calendar').'
';
}
else {
$coursecache = array();
$summarize = array();
// First, print details about events that start today
foreach($events as $event) {
if($event->timestart >= $starttime && $event->timestart <= $endtime) {
// Print this
calendar_print_event_table($event, $starttime, $endtime, $coursecache);
}
else {
// Save this for later
$summarize[] = $event->id;
}
}
// Then, show a list of all events that just span this day
if(!empty($summarize)) {
$until = get_string('durationuntil', 'calendar');
echo '
'; // Begin table. First row: day names
// Print out the names of the weekdays
$days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
// This uses the % operator to get the correct weekday no matter what shift we have
// applied to the $display->minwday : $display->maxwday range from the default 0 : 6
echo '
'.get_string($days[$i % 7], 'calendar').'
';
}
echo '
'; // End of day names; prepare for day numbers
// For the table display. $week is the row; $dayweek is the column.
$week = 1;
$dayweek = $startwday;
// Paddding (the first week may have blank days in the beginning)
for($i = $display->minwday; $i < $startwday; ++$i) {
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 "
\n
";
$dayweek = $display->minwday;
++$week;
}
// Reset vars
$cell = '';
if($dayweek % 7 == 0 || $dayweek % 7 == 6) {
// Weekend. This is true no matter what the exact range is.
$class = 'cal_weekend';
}
else {
// Normal working day.
$class = '';
}
// Special visual fx if an event is defined
if(isset($eventsbyday[$day])) {
if(isset($typesbyday[$day]['startglobal'])) {
$class .= ' cal_event_global';
}
else if(isset($typesbyday[$day]['startcourse'])) {
$class .= ' cal_event_course';
}
else if(isset($typesbyday[$day]['startgroup'])) {
$class .= ' cal_event_group';
}
else if(isset($typesbyday[$day]['startuser'])) {
$class .= ' cal_event_user';
}
if(count($eventsbyday[$day]) == 1) {
$title = get_string('oneevent', 'calendar');
}
else {
$title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
}
$cell = ''.$day.'';
}
else {
$cell = $day;
}
// Special visual fx if an event spans many days
if(isset($typesbyday[$day]['durationglobal'])) {
$class .= ' cal_duration_global';
}
else if(isset($typesbyday[$day]['durationcourse'])) {
$class .= ' cal_duration_course';
}
else if(isset($typesbyday[$day]['durationgroup'])) {
$class .= ' cal_duration_group';
}
else if(isset($typesbyday[$day]['durationuser'])) {
$class .= ' cal_duration_user';
}
// Special visual fx for today
if($display->thismonth && $day == $d) {
$class .= ' cal_today';
}
// Just display it
if(!empty($class)) {
$class = ' class="'.trim($class).'"';
}
echo '
'.$cell;
if(isset($eventsbyday[$day])) {
echo '
';
foreach($eventsbyday[$day] as $eventindex) {
echo '
";
if(!empty($event->modulename)) {
// The module name is set. This handling code should be synchronized with that in calendar_get_upcoming()
$module = calendar_get_module_cached($coursecache, $event->modulename, $event->instance, $event->courseid);
if($module === false) {
// This shouldn't have happened. What to do now? Just ignore it...
echo '