MDL-70237 payment: Allow html tags in gateway description
[moodle.git] / calendar / export.php
CommitLineData
93c91ee4 1<?php
2
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/////////////////////////////////////////////////////////////////////////////
40
41/**
42 * This file is part of the User section Moodle
43 *
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
47 */
b5f1b8b1 48
49require_once('../config.php');
50require_once($CFG->dirroot.'/course/lib.php');
51require_once($CFG->dirroot.'/calendar/lib.php');
b5f1b8b1 52
797cedc7
SH
53if (empty($CFG->enablecalendarexport)) {
54 die('no export');
55}
56
57$courseid = optional_param('course', SITEID, PARAM_INT);
b5f1b8b1 58$action = optional_param('action', '', PARAM_ALPHA);
da304137
MN
59$day = optional_param('cal_d', 0, PARAM_INT);
60$mon = optional_param('cal_m', 0, PARAM_INT);
61$year = optional_param('cal_y', 0, PARAM_INT);
62$time = optional_param('time', 0, PARAM_INT);
d52777b4 63$generateurl = optional_param('generateurl', 0, PARAM_BOOL);
797cedc7 64
da304137
MN
65
66// If a day, month and year were passed then convert it to a timestamp. If these were passed
67// then we can assume the day, month and year are passed as Gregorian, as no where in core
68// should we be passing these values rather than the time. This is done for BC.
69if (!empty($day) && !empty($mon) && !empty($year)) {
70 if (checkdate($mon, $day, $year)) {
71 $time = make_timestamp($year, $mon, $day);
72 } else {
73 $time = time();
74 }
75} else if (empty($time)) {
76 $time = time();
77}
78
797cedc7 79if ($courseid != SITEID && !empty($courseid)) {
fb1a615d
JP
80 // Course ID must be valid and existing.
81 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
797cedc7
SH
82 $courses = array($course->id => $course);
83 $issite = false;
04f1715e 84} else {
797cedc7
SH
85 $course = get_site();
86 $courses = calendar_get_default_courses();
87 $issite = true;
9ba76792 88}
fb1a615d 89require_login($course, false);
2cc649ee 90
da304137
MN
91$url = new moodle_url('/calendar/export.php', array('time' => $time));
92
93c91ee4 93if ($action !== '') {
94 $url->param('action', $action);
95}
da304137 96
36dc3b71
SH
97if ($course !== NULL) {
98 $url->param('course', $course->id);
93c91ee4 99}
100$PAGE->set_url($url);
101
da304137 102$calendar = new calendar_information(0, 0, 0, $time);
d0e56d84 103$calendar->set_sources($course, $courses);
37d87d11 104
b5f1b8b1 105$pagetitle = get_string('export', 'calendar');
e295df44 106
797cedc7
SH
107// Print title and header
108if ($issite) {
a6855934 109 $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
9ba76792 110}
0f927f1e 111$link = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid));
da304137 112$PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time));
f22f1333 113$PAGE->navbar->add($pagetitle);
114
797cedc7
SH
115$PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle);
116$PAGE->set_heading($course->fullname);
14c992b4 117$PAGE->set_pagelayout('standard');
f22f1333 118
36dc3b71
SH
119$renderer = $PAGE->get_renderer('core_calendar');
120$calendar->add_sidecalendar_blocks($renderer);
b5f1b8b1 121
d592ccd7
BB
122// Get the calendar type we are using.
123$calendartype = \core_calendar\type_factory::get_calendar_instance();
124$now = $calendartype->timestamp_to_date_array($time);
797cedc7 125
d592ccd7
BB
126$weekend = CALENDAR_DEFAULT_WEEKEND;
127if (isset($CFG->calendar_weekend)) {
128 $weekend = intval($CFG->calendar_weekend);
129}
130$numberofdaysinweek = $calendartype->get_num_weekdays();
131
132$formdata = array(
133 // Let's populate some vars to let "common tasks" be somewhat smart...
134 // If today it's weekend, give the "next week" option.
135 'allownextweek' => $weekend & (1 << $now['wday']),
136 // If it's the last week of the month, give the "next month" option.
137 'allownextmonth' => calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek,
138 // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option.
139 'allowthisweek' => !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % $numberofdaysinweek))))
140);
141$exportform = new core_calendar_export_form(null, $formdata);
142$calendarurl = '';
143if ($data = $exportform->get_data()) {
d592ccd7
BB
144 $params = array();
145 $params['userid'] = $USER->id;
ea9c822f 146 $params['authtoken'] = calendar_get_export_token($USER);
d592ccd7
BB
147 $params['preset_what'] = $data->events['exportevents'];
148 $params['preset_time'] = $data->period['timeperiod'];
d52777b4
RW
149
150 $link = new moodle_url('/calendar/export_execute.php', $params);
d592ccd7
BB
151 if (!empty($data->generateurl)) {
152 $urlclasses = array('class' => 'generalbox calendarurl');
153 $calendarurl = html_writer::tag( 'div', get_string('calendarurl', 'calendar', $link->out()), $urlclasses);
154 }
155
156 if (!empty($data->export)) {
157 redirect($link);
158 }
d52777b4
RW
159}
160
d592ccd7
BB
161echo $OUTPUT->header();
162echo $renderer->start_layout();
163echo $OUTPUT->heading(get_string('exportcalendar', 'calendar'));
164
165if ($action != 'advanced') {
166 $exportform->display();
167}
168
169echo $calendarurl;
170
36dc3b71 171echo $renderer->complete_layout();
1a1a09d8 172
9314a6be 173echo $OUTPUT->footer();