2004-03-29 15:28:15 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// NOTICE OF COPYRIGHT //
|
|
|
|
// //
|
|
|
|
// Moodle - Calendar extension //
|
|
|
|
// //
|
|
|
|
// Copyright (C) 2003-2004 Greek School Network www.sch.gr //
|
|
|
|
// //
|
|
|
|
// Designed by: //
|
2007-02-27 13:49:43 +00:00
|
|
|
// Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
|
|
|
|
// Jon Papaioannou (pj@moodle.org) //
|
2004-03-29 15:28:15 +00:00
|
|
|
// //
|
|
|
|
// Programming and development: //
|
2007-02-27 13:49:43 +00:00
|
|
|
// Jon Papaioannou (pj@moodle.org) //
|
2004-03-29 15:28:15 +00:00
|
|
|
// //
|
|
|
|
// For bugs, suggestions, etc contact: //
|
2007-02-27 13:49:43 +00:00
|
|
|
// Jon Papaioannou (pj@moodle.org) //
|
2004-03-29 15:28:15 +00:00
|
|
|
// //
|
|
|
|
// The current module was developed at the University of Macedonia //
|
|
|
|
// (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
|
|
|
|
// The aim of this project is to provide additional and improved //
|
|
|
|
// functionality to the Asynchronous Distance Education service that the //
|
|
|
|
// Greek School Network deploys. //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License for more details: //
|
|
|
|
// //
|
|
|
|
// http://www.gnu.org/copyleft/gpl.html //
|
|
|
|
// //
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Display the calendar page.
|
|
|
|
|
|
|
|
require_once('../config.php');
|
2004-06-02 08:13:26 +00:00
|
|
|
require_once($CFG->dirroot.'/course/lib.php');
|
|
|
|
require_once($CFG->dirroot.'/calendar/lib.php');
|
2004-05-25 06:36:09 +00:00
|
|
|
|
2007-01-17 19:53:03 +00:00
|
|
|
$courseid = optional_param('course', 0, PARAM_INT);
|
|
|
|
$view = optional_param('view', 'upcoming', PARAM_ALPHA);
|
2005-06-15 14:58:17 +00:00
|
|
|
$day = optional_param('cal_d', 0, PARAM_INT);
|
|
|
|
$mon = optional_param('cal_m', 0, PARAM_INT);
|
|
|
|
$yr = optional_param('cal_y', 0, PARAM_INT);
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
if(!$site = get_site()) {
|
|
|
|
redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
|
|
|
|
}
|
|
|
|
|
2007-01-17 19:53:03 +00:00
|
|
|
if ($courseid) {
|
|
|
|
require_login($courseid);
|
|
|
|
} else if ($CFG->forcelogin) {
|
2006-07-17 21:08:01 +00:00
|
|
|
require_login();
|
|
|
|
}
|
|
|
|
|
2007-05-06 04:28:11 +00:00
|
|
|
// Initialize the session variables
|
|
|
|
calendar_session_vars();
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
//add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
|
|
|
|
$now = usergetdate(time());
|
|
|
|
$pagetitle = '';
|
|
|
|
|
2007-08-17 11:18:58 +00:00
|
|
|
$strcalendar = get_string('calendar', 'calendar');
|
2009-09-04 04:26:50 +00:00
|
|
|
|
|
|
|
$link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$courseid.'&',
|
|
|
|
$now['mday'], $now['mon'], $now['year']);
|
|
|
|
$PAGE->navbar->add($strcalendar, new moodle_url($link));
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
if(!checkdate($mon, $day, $yr)) {
|
|
|
|
$day = intval($now['mday']);
|
|
|
|
$mon = intval($now['mon']);
|
|
|
|
$yr = intval($now['year']);
|
|
|
|
}
|
2005-02-18 01:11:10 +00:00
|
|
|
$time = make_timestamp($yr, $mon, $day);
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-11-19 02:47:00 +00:00
|
|
|
switch($view) {
|
2004-03-29 15:28:15 +00:00
|
|
|
case 'day':
|
2009-09-04 04:26:50 +00:00
|
|
|
$PAGE->navbar->add(userdate($time, get_string('strftimedate')));
|
2004-03-29 15:28:15 +00:00
|
|
|
$pagetitle = get_string('dayview', 'calendar');
|
|
|
|
break;
|
|
|
|
case 'month':
|
2009-09-04 04:26:50 +00:00
|
|
|
$PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
|
2004-03-29 15:28:15 +00:00
|
|
|
$pagetitle = get_string('detailedmonthview', 'calendar');
|
|
|
|
break;
|
|
|
|
case 'upcoming':
|
|
|
|
$pagetitle = get_string('upcomingevents', 'calendar');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-05-24 09:20:01 +00:00
|
|
|
// If a course has been supplied in the URL, change the filters to show that one
|
2007-01-17 19:53:03 +00:00
|
|
|
if (!empty($courseid)) {
|
2008-06-01 14:25:05 +00:00
|
|
|
if ($course = $DB->get_record('course', array('id'=>$courseid))) {
|
2005-08-23 20:43:32 +00:00
|
|
|
if ($course->id == SITEID) {
|
2004-05-28 10:53:54 +00:00
|
|
|
// If coming from the home page, show all courses
|
|
|
|
$SESSION->cal_courses_shown = calendar_get_default_courses(true);
|
|
|
|
calendar_set_referring_course(0);
|
2004-08-12 07:42:52 +00:00
|
|
|
|
|
|
|
} else {
|
2004-05-28 10:53:54 +00:00
|
|
|
// Otherwise show just this one
|
2005-02-13 08:50:37 +00:00
|
|
|
$SESSION->cal_courses_shown = $course->id;
|
2004-05-28 10:53:54 +00:00
|
|
|
calendar_set_referring_course($SESSION->cal_courses_shown);
|
|
|
|
}
|
2004-05-24 09:20:01 +00:00
|
|
|
}
|
2007-01-17 19:53:03 +00:00
|
|
|
} else {
|
|
|
|
$course = null;
|
2004-05-24 09:20:01 +00:00
|
|
|
}
|
|
|
|
|
2004-10-06 16:52:24 +00:00
|
|
|
if (empty($USER->id) or isguest()) {
|
2004-05-20 15:16:42 +00:00
|
|
|
$defaultcourses = calendar_get_default_courses();
|
|
|
|
calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
|
2004-08-12 07:42:52 +00:00
|
|
|
|
|
|
|
} else {
|
2004-05-21 10:54:46 +00:00
|
|
|
calendar_set_filters($courses, $groups, $users);
|
2004-05-20 15:16:42 +00:00
|
|
|
}
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
// Let's see if we are supposed to provide a referring course link
|
|
|
|
// but NOT for the "main page" course
|
2005-08-23 20:43:32 +00:00
|
|
|
if ($SESSION->cal_course_referer != SITEID &&
|
2008-06-01 14:25:05 +00:00
|
|
|
($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer))) !== false) {
|
2004-06-02 08:13:26 +00:00
|
|
|
require_login();
|
2005-02-13 08:50:37 +00:00
|
|
|
if (empty($course)) {
|
2008-06-01 14:25:05 +00:00
|
|
|
$course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer)); // Useful to have around
|
2005-02-13 08:50:37 +00:00
|
|
|
}
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 17:32:37 +00:00
|
|
|
$strcalendar = get_string('calendar', 'calendar');
|
|
|
|
$prefsbutton = calendar_preferences_button();
|
|
|
|
|
2009-09-17 07:46:20 +00:00
|
|
|
$PAGE->requires->js('calendar/calendar.js');
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
// Print title and header
|
2009-09-04 04:26:50 +00:00
|
|
|
$PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
|
|
|
|
$PAGE->set_heading($strcalendar);
|
|
|
|
$PAGE->set_headingmenu(user_login_string($site));
|
|
|
|
$PAGE->set_button($prefsbutton);
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// Layout the whole page as three big columns.
|
2007-01-03 08:12:21 +00:00
|
|
|
echo '<table id="calendar" style="height:100%;">';
|
2005-02-10 00:42:41 +00:00
|
|
|
echo '<tr>';
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-04-27 08:49:22 +00:00
|
|
|
// START: Main column
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2005-02-10 00:42:41 +00:00
|
|
|
echo '<td class="maincalendar">';
|
2007-01-03 08:12:21 +00:00
|
|
|
echo '<div class="heightcontainer">';
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-11-19 02:47:00 +00:00
|
|
|
switch($view) {
|
2004-03-29 15:28:15 +00:00
|
|
|
case 'day':
|
2007-06-21 15:46:04 +00:00
|
|
|
calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
|
2004-03-29 15:28:15 +00:00
|
|
|
break;
|
|
|
|
case 'month':
|
2007-06-21 15:46:04 +00:00
|
|
|
calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
|
2004-03-29 15:28:15 +00:00
|
|
|
break;
|
|
|
|
case 'upcoming':
|
2007-06-21 15:46:04 +00:00
|
|
|
calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
|
2004-03-29 15:28:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-03 08:12:21 +00:00
|
|
|
|
2006-11-23 20:21:29 +00:00
|
|
|
//Link to calendar export page
|
2009-08-20 08:51:44 +00:00
|
|
|
echo $OUTPUT->container_start('bottom');
|
2008-12-31 14:10:44 +00:00
|
|
|
if (!empty($CFG->enablecalendarexport)) {
|
2009-08-20 08:51:44 +00:00
|
|
|
echo $OUTPUT->button(html_form::make_button('export.php', array('course'=>$courseid), get_string('exportcalendar', 'calendar')));
|
2008-12-31 14:10:44 +00:00
|
|
|
|
|
|
|
if (!empty($USER->id)) {
|
2008-12-31 15:50:46 +00:00
|
|
|
$authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
|
2008-12-31 14:10:44 +00:00
|
|
|
$usernameencoded = urlencode($USER->username);
|
|
|
|
|
|
|
|
echo "<a href=\"export_execute.php?preset_what=all&preset_time=recentupcoming&username=$usernameencoded&authtoken=$authtoken\">"
|
2009-07-02 10:53:31 +00:00
|
|
|
.'<img src="'.$OUTPUT->old_icon_url('i/ical') . '" height="14" width="36" '
|
2008-12-31 14:10:44 +00:00
|
|
|
.'alt="'.get_string('ical', 'calendar').'" '
|
|
|
|
.'title="'.get_string('quickdownloadcalendar', 'calendar').'" />'
|
|
|
|
.'</a>';
|
|
|
|
}
|
2006-11-23 20:21:29 +00:00
|
|
|
}
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2009-08-20 08:51:44 +00:00
|
|
|
echo $OUTPUT->container_end();
|
2007-01-03 08:12:21 +00:00
|
|
|
echo '</div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
echo '</td>';
|
|
|
|
|
2004-04-27 08:49:22 +00:00
|
|
|
// END: Main column
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// START: Last column (3-month display)
|
2005-02-10 00:42:41 +00:00
|
|
|
echo '<td class="sidecalendar">';
|
2004-04-27 08:49:22 +00:00
|
|
|
list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
|
|
|
|
list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
|
2007-06-21 15:46:04 +00:00
|
|
|
$getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
|
2005-02-10 00:42:41 +00:00
|
|
|
|
2008-04-22 14:14:47 +00:00
|
|
|
$content='<div class="filters">';
|
|
|
|
$content.=calendar_filter_controls($view, $getvars, NULL, $courses);
|
|
|
|
$content.='</div>';
|
|
|
|
|
|
|
|
print_side_block(get_string('eventskey', 'calendar'),$content);
|
|
|
|
|
|
|
|
$content='<div class="minicalendarblock minicalendartop">';
|
|
|
|
$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
|
|
|
|
$content.=calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
|
|
|
|
$content.='</div><div class="minicalendarblock">';
|
|
|
|
$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
|
|
|
|
$content.=calendar_get_mini($courses, $groups, $users, $mon, $yr);
|
|
|
|
$content.='</div><div class="minicalendarblock">';
|
|
|
|
$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
|
|
|
|
$content.=calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
|
|
|
|
$content.='</div>';
|
|
|
|
|
|
|
|
print_side_block(get_string('monthlyview', 'calendar'),$content);
|
2005-02-10 00:42:41 +00:00
|
|
|
|
2004-04-27 08:49:22 +00:00
|
|
|
echo '</td>';
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
echo '</tr></table>';
|
2004-04-27 08:49:22 +00:00
|
|
|
|
2009-08-06 14:22:10 +00:00
|
|
|
echo $OUTPUT->footer();
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
|
|
|
|
|
2007-06-21 15:46:04 +00:00
|
|
|
function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) {
|
2005-01-25 17:16:34 +00:00
|
|
|
global $CFG, $USER;
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
if (!checkdate($m, $d, $y)) {
|
2004-03-29 15:28:15 +00:00
|
|
|
$now = usergetdate(time());
|
|
|
|
list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year']));
|
|
|
|
}
|
|
|
|
|
2004-05-21 10:54:46 +00:00
|
|
|
$getvars = 'from=day&cal_d='.$d.'&cal_m='.$m.'&cal_y='.$y; // For filtering
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
$starttime = make_timestamp($y, $m, $d);
|
2004-11-20 20:10:03 +00:00
|
|
|
$endtime = make_timestamp($y, $m, $d + 1) - 1;
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
$events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime);
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2005-02-11 03:08:30 +00:00
|
|
|
$text = '';
|
2007-06-28 04:03:30 +00:00
|
|
|
if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
|
2005-02-11 03:08:30 +00:00
|
|
|
$text.= '<div class="buttons">';
|
|
|
|
$text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
|
2007-03-01 05:10:58 +00:00
|
|
|
$text.= '<div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
$text.= '<input type="hidden" name="action" value="new" />';
|
2007-06-21 15:46:04 +00:00
|
|
|
$text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
|
2004-05-24 12:28:38 +00:00
|
|
|
$text.= '<input type="hidden" name="cal_d" value="'.$d.'" />';
|
2004-03-29 15:28:15 +00:00
|
|
|
$text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
|
|
|
|
$text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
|
|
|
|
$text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
|
2007-03-01 05:10:58 +00:00
|
|
|
$text.= '</div></form></div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
2005-02-11 03:08:30 +00:00
|
|
|
$text .= get_string('dayview', 'calendar').': '.calendar_course_filter_selector($getvars);
|
|
|
|
|
2005-03-18 14:45:13 +00:00
|
|
|
echo '<div class="header">'.$text.'</div>';
|
2005-02-10 00:42:41 +00:00
|
|
|
|
2007-06-21 15:46:04 +00:00
|
|
|
echo '<div class="controls">'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'</div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
if (empty($events)) {
|
2004-03-29 15:28:15 +00:00
|
|
|
// There is nothing to display today.
|
2005-02-18 01:26:04 +00:00
|
|
|
echo '<h3>'.get_string('daywithnoevents', 'calendar').'</h3>';
|
2004-05-23 11:05:45 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2005-02-11 03:08:30 +00:00
|
|
|
echo '<div class="eventlist">';
|
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
$underway = array();
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// First, print details about events that start today
|
2004-05-23 11:05:45 +00:00
|
|
|
foreach ($events as $event) {
|
2007-06-13 10:00:30 +00:00
|
|
|
|
2007-06-22 13:30:22 +00:00
|
|
|
$event->calendarcourseid = $courseid;
|
2007-06-13 10:00:30 +00:00
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now
|
2004-06-02 09:15:07 +00:00
|
|
|
|
|
|
|
|
2004-08-22 17:19:24 +00:00
|
|
|
/*
|
2004-06-02 09:15:07 +00:00
|
|
|
$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.')';
|
|
|
|
*/
|
2004-08-22 17:19:24 +00:00
|
|
|
//unset($event->time);
|
2007-06-12 16:26:38 +00:00
|
|
|
|
|
|
|
$event->time = calendar_format_event_time($event, time(), '', false, $starttime);
|
2004-05-24 09:20:01 +00:00
|
|
|
calendar_print_event($event);
|
2004-05-23 11:05:45 +00:00
|
|
|
|
|
|
|
} else { // Save this for later
|
|
|
|
$underway[] = $event;
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then, show a list of all events that just span this day
|
2004-05-23 11:05:45 +00:00
|
|
|
if (!empty($underway)) {
|
2005-02-11 15:52:59 +00:00
|
|
|
echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>';
|
2004-05-23 11:05:45 +00:00
|
|
|
foreach ($underway as $event) {
|
2007-06-12 16:26:38 +00:00
|
|
|
$event->time = calendar_format_event_time($event, time(), '', false, $starttime);
|
2004-05-24 09:20:01 +00:00
|
|
|
calendar_print_event($event);
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-11 03:08:30 +00:00
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-21 15:46:04 +00:00
|
|
|
function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) {
|
2005-05-26 12:54:56 +00:00
|
|
|
global $CFG, $SESSION, $USER, $CALENDARDAYS;
|
2004-04-01 12:51:24 +00:00
|
|
|
global $day, $mon, $yr;
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
$getvars = 'from=month&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
|
|
|
|
|
2008-06-01 14:25:05 +00:00
|
|
|
$display = new stdClass;
|
2004-03-29 15:28:15 +00:00
|
|
|
$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);
|
|
|
|
|
2007-05-29 09:56:44 +00:00
|
|
|
$startwday = 0;
|
2007-02-27 13:59:43 +00:00
|
|
|
if (get_user_timezone_offset() < 99) {
|
|
|
|
// 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
|
2007-05-29 09:56:44 +00:00
|
|
|
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
|
2007-02-27 13:59:43 +00:00
|
|
|
} else {
|
|
|
|
// no timezone info specified
|
|
|
|
$display->tstart = mktime(0, 0, 0, $m, 1, $y);
|
|
|
|
$display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
|
2007-05-29 09:56:44 +00:00
|
|
|
$startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
|
2007-02-27 13:59:43 +00:00
|
|
|
}
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// Align the starting weekday to fall in our display range
|
|
|
|
if($startwday < $display->minwday) {
|
|
|
|
$startwday += 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get events from database
|
2007-11-26 14:43:28 +00:00
|
|
|
$events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
|
2007-08-20 10:52:59 +00:00
|
|
|
if (!empty($events)) {
|
|
|
|
foreach($events as $eventid => $event) {
|
|
|
|
if (!empty($event->modulename)) {
|
|
|
|
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
|
|
|
|
if (!groups_course_module_visible($cm)) {
|
|
|
|
unset($events[$eventid]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
// Extract information: events vs. time
|
2007-06-13 10:00:30 +00:00
|
|
|
calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2005-02-11 03:08:30 +00:00
|
|
|
$text = '';
|
2007-06-28 04:03:30 +00:00
|
|
|
if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
|
2005-02-11 03:08:30 +00:00
|
|
|
$text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">';
|
2007-03-01 05:10:58 +00:00
|
|
|
$text.= '<div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
$text.= '<input type="hidden" name="action" value="new" />';
|
2007-06-21 15:46:04 +00:00
|
|
|
$text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
|
2004-03-29 15:28:15 +00:00
|
|
|
$text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
|
|
|
|
$text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
|
|
|
|
$text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
|
2007-03-01 05:10:58 +00:00
|
|
|
$text.= '</div></form></div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
2005-02-11 03:08:30 +00:00
|
|
|
$text .= get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars);
|
|
|
|
|
2005-03-18 14:45:13 +00:00
|
|
|
echo '<div class="header">'.$text.'</div>';
|
2004-05-20 15:16:42 +00:00
|
|
|
|
2005-02-10 00:42:41 +00:00
|
|
|
echo '<div class="controls">';
|
2007-06-21 15:46:04 +00:00
|
|
|
echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y));
|
2005-02-10 00:42:41 +00:00
|
|
|
echo '</div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// Start calendar display
|
2005-02-14 16:50:02 +00:00
|
|
|
echo '<table class="calendarmonth"><tr class="weekdays">'; // Begin table. First row: day names
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// Print out the names of the weekdays
|
|
|
|
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
|
2006-12-13 03:03:43 +00:00
|
|
|
echo '<th scope="col">'.get_string($CALENDARDAYS[$i % 7], 'calendar').'</th>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
2005-02-14 16:50:02 +00:00
|
|
|
echo '</tr><tr>'; // End of day names; prepare for day numbers
|
2004-03-29 15:28:15 +00:00
|
|
|
|
|
|
|
// 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) {
|
2007-06-12 16:26:38 +00:00
|
|
|
echo '<td class="nottoday"> </td>'."\n";
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 "</tr>\n<tr>";
|
|
|
|
$dayweek = $display->minwday;
|
|
|
|
++$week;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset vars
|
|
|
|
$cell = '';
|
2007-06-21 15:46:04 +00:00
|
|
|
$dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&course='.$courseid.'&', $day, $m, $y);
|
2004-05-21 11:24:22 +00:00
|
|
|
|
2004-12-16 18:49:57 +00:00
|
|
|
if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
|
2004-03-29 15:28:15 +00:00
|
|
|
// Weekend. This is true no matter what the exact range is.
|
2005-02-11 03:54:33 +00:00
|
|
|
$class = 'weekend';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Normal working day.
|
2004-04-20 11:14:55 +00:00
|
|
|
$class = '';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Special visual fx if an event is defined
|
|
|
|
if(isset($eventsbyday[$day])) {
|
|
|
|
if(count($eventsbyday[$day]) == 1) {
|
|
|
|
$title = get_string('oneevent', 'calendar');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
|
|
|
|
}
|
2005-02-11 03:54:33 +00:00
|
|
|
$cell = '<div class="day"><a href="'.$dayhref.'" title="'.$title.'">'.$day.'</a></div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-02-11 03:54:33 +00:00
|
|
|
$cell = '<div class="day">'.$day.'</div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Special visual fx if an event spans many days
|
|
|
|
if(isset($typesbyday[$day]['durationglobal'])) {
|
2005-02-11 03:54:33 +00:00
|
|
|
$class .= ' duration_global';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
else if(isset($typesbyday[$day]['durationcourse'])) {
|
2005-02-11 03:54:33 +00:00
|
|
|
$class .= ' duration_course';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
else if(isset($typesbyday[$day]['durationgroup'])) {
|
2005-02-11 03:54:33 +00:00
|
|
|
$class .= ' duration_group';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
else if(isset($typesbyday[$day]['durationuser'])) {
|
2005-02-11 03:54:33 +00:00
|
|
|
$class .= ' duration_user';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Special visual fx for today
|
|
|
|
if($display->thismonth && $day == $d) {
|
2005-02-11 03:54:33 +00:00
|
|
|
$class .= ' today';
|
2007-06-12 16:26:38 +00:00
|
|
|
} else {
|
|
|
|
$class .= ' nottoday';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Just display it
|
2004-04-20 11:14:55 +00:00
|
|
|
if(!empty($class)) {
|
|
|
|
$class = ' class="'.trim($class).'"';
|
|
|
|
}
|
|
|
|
echo '<td'.$class.'>'.$cell;
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
if(isset($eventsbyday[$day])) {
|
2005-02-12 16:00:47 +00:00
|
|
|
echo '<ul class="events-new">';
|
2004-03-29 15:28:15 +00:00
|
|
|
foreach($eventsbyday[$day] as $eventindex) {
|
2007-06-12 16:26:38 +00:00
|
|
|
|
|
|
|
// If event has a class set then add it to the event <li> tag
|
|
|
|
$eventclass = '';
|
|
|
|
if (!empty($events[$eventindex]->class)) {
|
|
|
|
$eventclass = ' class="'.$events[$eventindex]->class.'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<li'.$eventclass.'><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
2005-02-11 03:54:33 +00:00
|
|
|
echo '</ul>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
if(isset($durationbyday[$day])) {
|
2005-02-12 16:00:47 +00:00
|
|
|
echo '<ul class="events-underway">';
|
2004-03-29 15:28:15 +00:00
|
|
|
foreach($durationbyday[$day] as $eventindex) {
|
2005-03-27 16:41:04 +00:00
|
|
|
echo '<li>['.format_string($events[$eventindex]->name,true).']</li>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
2005-02-12 16:00:47 +00:00
|
|
|
echo '</ul>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
echo "</td>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paddding (the last week may have blank days at the end)
|
|
|
|
for($i = $dayweek; $i <= $display->maxwday; ++$i) {
|
2007-06-12 16:26:38 +00:00
|
|
|
echo '<td class="nottoday"> </td>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
2005-02-14 16:50:02 +00:00
|
|
|
echo "</tr>\n"; // Last row ends
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2005-02-10 00:42:41 +00:00
|
|
|
echo "</table>\n"; // Tabular display of days ends
|
2004-03-29 15:28:15 +00:00
|
|
|
|
2007-10-09 04:02:43 +00:00
|
|
|
// OK, now for the filtering display
|
|
|
|
echo '<div class="filters"><table><tr>';
|
|
|
|
|
|
|
|
// Global events
|
|
|
|
if($SESSION->cal_show_global) {
|
|
|
|
echo '<td class="event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Course events
|
|
|
|
if(!empty($SESSION->cal_show_course)) {
|
|
|
|
echo '<td class="event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
if(!empty($USER->id) && !isguest()) {
|
|
|
|
echo '<tr>';
|
|
|
|
// Group events
|
|
|
|
if($SESSION->cal_show_groups) {
|
|
|
|
echo '<td class="event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
// User events
|
|
|
|
if($SESSION->cal_show_user) {
|
|
|
|
echo '<td class="event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
|
|
|
|
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</table></div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 15:46:04 +00:00
|
|
|
function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents, $courseid) {
|
2009-08-06 08:26:34 +00:00
|
|
|
global $USER, $OUTPUT;
|
2004-05-22 07:14:49 +00:00
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
$events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);
|
|
|
|
|
2005-02-11 03:54:33 +00:00
|
|
|
$text = '';
|
2004-05-22 07:14:49 +00:00
|
|
|
|
2007-06-28 04:03:30 +00:00
|
|
|
if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
|
2005-02-11 03:54:33 +00:00
|
|
|
$text.= '<div class="buttons">';
|
|
|
|
$text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
|
2007-03-01 05:10:58 +00:00
|
|
|
$text.= '<div>';
|
2004-05-21 13:51:02 +00:00
|
|
|
$text.= '<input type="hidden" name="action" value="new" />';
|
2007-06-21 15:46:04 +00:00
|
|
|
$text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
|
2004-05-24 09:20:01 +00:00
|
|
|
/*
|
2004-05-21 13:51:02 +00:00
|
|
|
$text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
|
|
|
|
$text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
|
2004-05-24 09:20:01 +00:00
|
|
|
*/
|
2004-05-21 13:51:02 +00:00
|
|
|
$text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
|
2007-03-01 05:10:58 +00:00
|
|
|
$text.= '</div></form></div>';
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
|
2005-02-11 03:54:33 +00:00
|
|
|
$text .= get_string('upcomingevents', 'calendar').': '.calendar_course_filter_selector('from=upcoming');
|
|
|
|
|
2005-03-18 14:45:13 +00:00
|
|
|
echo '<div class="header">'.$text.'</div>';
|
2005-02-10 00:42:41 +00:00
|
|
|
|
2004-05-23 11:05:45 +00:00
|
|
|
if ($events) {
|
2007-06-12 16:26:38 +00:00
|
|
|
|
2005-02-11 03:54:33 +00:00
|
|
|
echo '<div class="eventlist">';
|
2004-05-23 11:05:45 +00:00
|
|
|
foreach ($events as $event) {
|
2007-10-11 05:24:12 +00:00
|
|
|
$event->calendarcourseid = $courseid;
|
2004-05-23 11:05:45 +00:00
|
|
|
calendar_print_event($event);
|
|
|
|
}
|
2005-02-11 03:54:33 +00:00
|
|
|
echo '</div>';
|
2004-05-23 11:05:45 +00:00
|
|
|
} else {
|
2009-08-06 08:26:34 +00:00
|
|
|
echo $OUTPUT->heading(get_string('noupcomingevents', 'calendar'));
|
2004-03-29 15:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-21 10:54:46 +00:00
|
|
|
function calendar_course_filter_selector($getvars = '') {
|
2009-08-10 03:41:44 +00:00
|
|
|
global $USER, $SESSION, $OUTPUT;
|
2004-05-21 10:54:46 +00:00
|
|
|
|
2004-10-06 16:52:24 +00:00
|
|
|
if (empty($USER->id) or isguest()) {
|
2004-05-21 13:03:59 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2008-04-22 06:24:14 +00:00
|
|
|
if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
|
2004-11-22 05:41:14 +00:00
|
|
|
$courses = get_courses('all', 'c.shortname','c.id,c.shortname');
|
2004-05-22 04:28:36 +00:00
|
|
|
} else {
|
|
|
|
$courses = get_my_courses($USER->id, 'shortname');
|
|
|
|
}
|
2004-05-21 10:54:46 +00:00
|
|
|
|
2005-02-18 01:32:49 +00:00
|
|
|
unset($courses[SITEID]);
|
2004-05-22 04:32:35 +00:00
|
|
|
|
2005-08-23 20:43:32 +00:00
|
|
|
$courseoptions[SITEID] = get_string('fulllistofcourses');
|
2004-05-22 04:28:36 +00:00
|
|
|
foreach ($courses as $course) {
|
2007-03-01 05:16:02 +00:00
|
|
|
$courseoptions[$course->id] = format_string($course->shortname);
|
2004-05-21 10:54:46 +00:00
|
|
|
}
|
2004-05-22 04:28:36 +00:00
|
|
|
|
|
|
|
if (is_numeric($SESSION->cal_courses_shown)) {
|
2004-05-21 13:03:59 +00:00
|
|
|
$selected = $SESSION->cal_courses_shown;
|
2004-05-22 04:28:36 +00:00
|
|
|
} else {
|
2004-05-21 13:03:59 +00:00
|
|
|
$selected = '';
|
|
|
|
}
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = html_select::make_popup_form(CALENDAR_URL.'set.php?var=setcourse&'.$getvars, 'id', $courseoptions, 'cal_courses_flt', $selected);
|
2009-08-10 03:41:44 +00:00
|
|
|
$select->nothinglabel = false;
|
|
|
|
return $OUTPUT->select($select);
|
2004-05-21 10:54:46 +00:00
|
|
|
}
|
|
|
|
|
2004-03-29 15:28:15 +00:00
|
|
|
?>
|