3 /////////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Calendar extension //
9 // Copyright (C) 2003-2004 Greek School Network www.sch.gr //
12 // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
13 // Jon Papaioannou (pj@moodle.org) //
15 // Programming and development: //
16 // Jon Papaioannou (pj@moodle.org) //
18 // For bugs, suggestions, etc contact: //
19 // Jon Papaioannou (pj@moodle.org) //
21 // The current module was developed at the University of Macedonia //
22 // (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
23 // The aim of this project is to provide additional and improved //
24 // functionality to the Asynchronous Distance Education service that the //
25 // Greek School Network deploys. //
27 // This program is free software; you can redistribute it and/or modify //
28 // it under the terms of the GNU General Public License as published by //
29 // the Free Software Foundation; either version 2 of the License, or //
30 // (at your option) any later version. //
32 // This program is distributed in the hope that it will be useful, //
33 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
34 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
35 // GNU General Public License for more details: //
37 // http://www.gnu.org/copyleft/gpl.html //
39 /////////////////////////////////////////////////////////////////////////////
42 * This file is part of the User section Moodle
44 * @copyright 2003-2004 Jon Papaioannou (pj@moodle.org)
45 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
49 require_once('../config.php');
50 require_once($CFG->dirroot
.'/course/lib.php');
51 require_once($CFG->dirroot
.'/calendar/lib.php');
52 //require_once($CFG->libdir.'/bennu/bennu.inc.php');
54 $action = optional_param('action', '', PARAM_ALPHA
);
55 $day = optional_param('cal_d', 0, PARAM_INT
);
56 $mon = optional_param('cal_m', 0, PARAM_INT
);
57 $yr = optional_param('cal_y', 0, PARAM_INT
);
58 if ($courseid = optional_param('course', 0, PARAM_INT
)) {
59 $course = $DB->get_record('course', array('id'=>$courseid));
64 $url = new moodle_url('/calendar/export.php');
66 $url->param('action', $action);
69 $url->param('cal_d', $day);
72 $url->param('cal_m', $mon);
75 $url->param('cal_y', $yr);
77 if ($course !== NULL) {
78 $url->param('course', $course->id
);
82 require_login($course);
84 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM
)); //TODO: wrong
87 if (empty($CFG->enablecalendarexport
)) {
93 // Initialize the session variables
94 calendar_session_vars();
96 $pagetitle = get_string('export', 'calendar');
98 $now = usergetdate(time());
100 if (!empty($courseid) && $course->id
!= SITEID
) {
101 $PAGE->navbar
->add($course->shortname
, new moodle_url('/course/view.php', array('id'=>$course->id
)));
104 $calendar = new calendar_information($day, $mon, $yr);
105 $calendar->courseid
= $courseid;
108 if(!checkdate($mon, $day, $yr)) {
109 $day = intval($now['mday']);
110 $mon = intval($now['mon']);
111 $yr = intval($now['year']);
113 $time = make_timestamp($yr, $mon, $day);
115 if (!isloggedin() or isguestuser()) {
116 $defaultcourses = calendar_get_default_courses();
117 calendar_set_filters($calendar->courses
, $calendar->groups
, $calendar->users
, $defaultcourses, $defaultcourses);
119 calendar_set_filters($calendar->courses
, $calendar->groups
, $calendar->users
);
122 $strcalendar = get_string('calendar', 'calendar');
123 $prefsbutton = calendar_preferences_button();
125 // Print title and header
126 $link = new moodle_url(CALENDAR_URL
.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid
));
127 $PAGE->navbar
->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, $now['mday'], $now['mon'], $now['year']));
128 $PAGE->navbar
->add($pagetitle);
130 $PAGE->set_title($site->shortname
.': '.$strcalendar.': '.$pagetitle);
131 $PAGE->set_heading($COURSE->fullname
);
132 $PAGE->set_button($prefsbutton);
133 $PAGE->set_pagelayout('standard');
135 $renderer = $PAGE->get_renderer('core_calendar');
136 $calendar->add_sidecalendar_blocks($renderer);
138 echo $OUTPUT->header();
139 echo $renderer->start_layout();
145 $username = $USER->username
;
146 $authtoken = sha1($USER->username
. $USER->password
. $CFG->calendar_exportsalt
);
147 // Let's populate some vars to let "common tasks" be somewhat smart...
148 // If today it's weekend, give the "next week" option
149 $allownextweek = CALENDAR_WEEKEND
& (1 << $now['wday']);
150 // If it's the last week of the month, give the "next month" option
151 $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
152 // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
153 $allowthisweek = !((CALENDAR_WEEKEND
& (1 << $now['wday'])) && !(CALENDAR_WEEKEND
& (1 << (($now['wday'] +
1) %
7))));
154 echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken);
156 echo $renderer->complete_layout();
157 echo $OUTPUT->footer();