weblib MDL-6820 Reverted modification due to unforseen regressions
[moodle.git] / calendar / export.php
blobeb106054a0728efebba4cc84d9afc026d8b1164b
1 <?php // $Id$
3 require_once('../config.php');
4 require_once($CFG->dirroot.'/course/lib.php');
5 require_once($CFG->dirroot.'/calendar/lib.php');
6 //require_once($CFG->libdir.'/bennu/bennu.inc.php');
8 $action = optional_param('action', '', PARAM_ALPHA);
9 $day = optional_param('cal_d', 0, PARAM_INT);
10 $mon = optional_param('cal_m', 0, PARAM_INT);
11 $yr = optional_param('cal_y', 0, PARAM_INT);
12 if ($courseid = optional_param('course', 0, PARAM_INT)) {
13 $course = get_record('course', 'id', $courseid);
14 } else {
15 $course = NULL;
18 require_login();
20 if (empty($CFG->enablecalendarexport)) {
21 die('no export');
24 if(!$site = get_site()) {
25 redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
28 // Initialize the session variables
29 calendar_session_vars();
31 $pagetitle = get_string('export', 'calendar');
32 $navlinks = array();
33 $now = usergetdate(time());
35 if (!empty($courseid) && $course->id != SITEID) {
36 $navlinks[] = array('name' => $course->shortname,
37 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
38 'type' => 'misc');
40 $navlinks[] = array('name' => get_string('calendar', 'calendar'),
41 'link' =>calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&amp;course='.$courseid.'&amp;',
42 $now['mday'], $now['mon'], $now['year']),
43 'type' => 'misc');
44 $navlinks[] = array('name' => $pagetitle, 'link' => null, 'type' => 'misc');
46 $navigation = build_navigation($navlinks);
48 if(!checkdate($mon, $day, $yr)) {
49 $day = intval($now['mday']);
50 $mon = intval($now['mon']);
51 $yr = intval($now['year']);
53 $time = make_timestamp($yr, $mon, $day);
55 if (empty($USER->id) or isguest()) {
56 $defaultcourses = calendar_get_default_courses();
57 calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
58 } else {
59 calendar_set_filters($courses, $groups, $users);
62 if (empty($USER->id) or isguest()) {
63 $defaultcourses = calendar_get_default_courses();
64 calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
66 } else {
67 calendar_set_filters($courses, $groups, $users);
70 $strcalendar = get_string('calendar', 'calendar');
71 $prefsbutton = calendar_preferences_button();
73 // Print title and header
74 print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $navigation,
75 '', '', true, $prefsbutton, user_login_string($site));
77 echo calendar_overlib_html();
79 // Layout the whole page as three big columns.
80 echo '<table id="calendar">';
81 echo '<tr>';
83 // START: Main column
85 echo '<td class="maincalendar">';
87 $username = $USER->username;
88 $usernameencoded = urlencode($USER->username);
89 $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
91 switch($action) {
92 case 'advanced':
93 break;
94 case '':
95 default:
96 // Let's populate some vars to let "common tasks" be somewhat smart...
97 // If today it's weekend, give the "next week" option
98 $allownextweek = CALENDAR_WEEKEND & (1 << $now['wday']);
99 // If it's the last week of the month, give the "next month" option
100 $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
101 // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
102 $allowthisweek = !((CALENDAR_WEEKEND & (1 << $now['wday'])) && !(CALENDAR_WEEKEND & (1 << (($now['wday'] + 1) % 7))));
103 echo '<div class="header">' . get_string('export', 'calendar') . '</div>';
104 include('export_basic.html');
109 echo '</td>';
111 // END: Main column
113 // START: Last column (3-month display)
114 echo '<td class="sidecalendar">';
115 echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
117 list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
118 list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
119 $getvars = 'cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
121 echo '<div class="minicalendarblock">';
122 echo calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
123 echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
124 echo '</div><div class="minicalendarblock">';
125 echo calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
126 echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
127 echo '</div><div class="minicalendarblock">';
128 echo calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
129 echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
130 echo '</div>';
132 echo '</td>';
134 echo '</tr></table>';
136 print_footer();