MDL-23479 scorm restore code - correct time shifting
[moodle.git] / calendar / export.php
blob6d57e57da3d371e97be0d5c64d3eacdccec740a8
1 <?php
3 /////////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Calendar extension //
8 // //
9 // Copyright (C) 2003-2004 Greek School Network www.sch.gr //
10 // //
11 // Designed by: //
12 // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
13 // Jon Papaioannou (pj@moodle.org) //
14 // //
15 // Programming and development: //
16 // Jon Papaioannou (pj@moodle.org) //
17 // //
18 // For bugs, suggestions, etc contact: //
19 // Jon Papaioannou (pj@moodle.org) //
20 // //
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. //
26 // //
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. //
31 // //
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: //
36 // //
37 // http://www.gnu.org/copyleft/gpl.html //
38 // //
39 /////////////////////////////////////////////////////////////////////////////
41 /**
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
46 * @package calendar
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));
60 } else {
61 $course = NULL;
64 $url = new moodle_url('/calendar/export.php');
65 if ($action !== '') {
66 $url->param('action', $action);
68 if ($day !== 0) {
69 $url->param('cal_d', $day);
71 if ($mon !== 0) {
72 $url->param('cal_m', $mon);
74 if ($yr !== 0) {
75 $url->param('cal_y', $yr);
77 if ($course !== NULL) {
78 $url->param('course', $course->id);
80 $PAGE->set_url($url);
82 require_login();
84 if (empty($CFG->enablecalendarexport)) {
85 die('no export');
88 $site = get_site();
90 // Initialize the session variables
91 calendar_session_vars();
93 $pagetitle = get_string('export', 'calendar');
94 $navlinks = array();
95 $now = usergetdate(time());
97 if (!empty($courseid) && $course->id != SITEID) {
98 $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
101 $calendar = new calendar_information($day, $mon, $yr);
102 $calendar->courseid = $courseid;
105 if(!checkdate($mon, $day, $yr)) {
106 $day = intval($now['mday']);
107 $mon = intval($now['mon']);
108 $yr = intval($now['year']);
110 $time = make_timestamp($yr, $mon, $day);
112 if (!isloggedin() or isguestuser()) {
113 $defaultcourses = calendar_get_default_courses();
114 calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users, $defaultcourses, $defaultcourses);
115 } else {
116 calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users);
119 $strcalendar = get_string('calendar', 'calendar');
120 $prefsbutton = calendar_preferences_button();
122 // Print title and header
123 $link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&amp;course='.$calendar->courseid.'&amp;',
124 $now['mday'], $now['mon'], $now['year']);
125 $PAGE->navbar->add(get_string('calendar', 'calendar'), new moodle_url($link));
126 $PAGE->navbar->add($pagetitle);
128 $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$pagetitle);
129 $PAGE->set_heading($COURSE->fullname);
130 $PAGE->set_button($prefsbutton);
131 $PAGE->set_pagelayout('standard');
133 $renderer = $PAGE->get_renderer('core_calendar');
134 $calendar->add_sidecalendar_blocks($renderer);
136 echo $OUTPUT->header();
137 echo $renderer->start_layout();
138 switch($action) {
139 case 'advanced':
140 break;
141 case '':
142 default:
143 $username = $USER->username;
144 $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
145 // Let's populate some vars to let "common tasks" be somewhat smart...
146 // If today it's weekend, give the "next week" option
147 $allownextweek = CALENDAR_WEEKEND & (1 << $now['wday']);
148 // If it's the last week of the month, give the "next month" option
149 $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
150 // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
151 $allowthisweek = !((CALENDAR_WEEKEND & (1 << $now['wday'])) && !(CALENDAR_WEEKEND & (1 << (($now['wday'] + 1) % 7))));
152 echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken);
154 echo $renderer->complete_layout();
155 echo $OUTPUT->footer();