calendar/lib: calendar_set_filters() use pre-fetched context and course recs
[moodle-pu.git] / calendar / export.php
blob0edbaf3e107ed6005bb1183e14c060496bc8c612
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 $course = optional_param('course', 0);
10 $day = optional_param('cal_d', 0, PARAM_INT);
11 $mon = optional_param('cal_m', 0, PARAM_INT);
12 $yr = optional_param('cal_y', 0, PARAM_INT);
14 require_login();
16 if(!$site = get_site()) {
17 redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
20 // Initialize the session variables
21 calendar_session_vars();
23 $pagetitle = get_string('export', 'calendar');
24 $navlinks = array();
25 $now = usergetdate(time());
27 $navlinks[] = array('name' => get_string('calendar', 'calendar'),
28 'link' =>calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&amp;course='.$course.'&amp;',
29 $now['mday'], $now['mon'], $now['year']),
30 'type' => 'misc');
31 $navlinks[] = array('name' => $pagetitle, 'link' => null, 'type' => 'misc');
32 $navigation = build_navigation($navlinks);
34 if(!checkdate($mon, $day, $yr)) {
35 $day = intval($now['mday']);
36 $mon = intval($now['mon']);
37 $yr = intval($now['year']);
39 $time = make_timestamp($yr, $mon, $day);
41 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
42 calendar_set_referring_course(0);
44 if (empty($USER->id) or isguest()) {
45 $defaultcourses = calendar_get_default_courses();
46 calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
48 } else {
49 calendar_set_filters($courses, $groups, $users);
52 $strcalendar = get_string('calendar', 'calendar');
53 $prefsbutton = calendar_preferences_button();
55 // Print title and header
56 print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $navigation,
57 '', '', true, $prefsbutton, user_login_string($site));
59 echo calendar_overlib_html();
61 // Layout the whole page as three big columns.
62 echo '<table id="calendar">';
63 echo '<tr>';
65 // START: Main column
67 echo '<td class="maincalendar">';
69 $username = $USER->username;
70 $usernameencoded = urlencode($USER->username);
71 $authtoken = sha1($USER->username . $USER->password);
73 switch($action) {
74 case 'advanced':
75 break;
76 case '':
77 default:
78 // Let's populate some vars to let "common tasks" be somewhat smart...
79 // If today it's weekend, give the "next week" option
80 $allownextweek = CALENDAR_WEEKEND & (1 << $now['wday']);
81 // If it's the last week of the month, give the "next month" option
82 $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
83 // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
84 $allowthisweek = !((CALENDAR_WEEKEND & (1 << $now['wday'])) && !(CALENDAR_WEEKEND & (1 << (($now['wday'] + 1) % 7))));
85 echo '<div class="header">' . get_string('export', 'calendar') . '</div>';
86 include('export_basic.html');
91 echo '</td>';
93 // END: Main column
95 // START: Last column (3-month display)
96 echo '<td class="sidecalendar">';
97 echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
99 list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
100 list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
101 $getvars = 'cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
103 echo '<div class="minicalendarblock">';
104 echo calendar_top_controls('display', array('id' => $course, 'm' => $prevmon, 'y' => $prevyr));
105 echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
106 echo '</div><div class="minicalendarblock">';
107 echo calendar_top_controls('display', array('id' => $course, 'm' => $mon, 'y' => $yr));
108 echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
109 echo '</div><div class="minicalendarblock">';
110 echo calendar_top_controls('display', array('id' => $course, 'm' => $nextmon, 'y' => $nextyr));
111 echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
112 echo '</div>';
114 echo '</td>';
116 echo '</tr></table>';
118 print_footer();