1 |
efrain |
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 |
*/
|
|
|
48 |
|
|
|
49 |
require_once('../config.php');
|
|
|
50 |
require_once($CFG->dirroot.'/course/lib.php');
|
|
|
51 |
require_once($CFG->dirroot.'/calendar/lib.php');
|
|
|
52 |
|
|
|
53 |
if (empty($CFG->enablecalendarexport)) {
|
|
|
54 |
die('no export');
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
$courseid = optional_param('course', SITEID, PARAM_INT);
|
|
|
58 |
$categoryid = optional_param('category', null, PARAM_INT);
|
|
|
59 |
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
60 |
$day = optional_param('cal_d', 0, PARAM_INT);
|
|
|
61 |
$mon = optional_param('cal_m', 0, PARAM_INT);
|
|
|
62 |
$year = optional_param('cal_y', 0, PARAM_INT);
|
|
|
63 |
$time = optional_param('time', 0, PARAM_INT);
|
|
|
64 |
$generateurl = optional_param('generateurl', 0, PARAM_BOOL);
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
// If a day, month and year were passed then convert it to a timestamp. If these were passed
|
|
|
68 |
// then we can assume the day, month and year are passed as Gregorian, as no where in core
|
|
|
69 |
// should we be passing these values rather than the time. This is done for BC.
|
|
|
70 |
if (!empty($day) && !empty($mon) && !empty($year)) {
|
|
|
71 |
if (checkdate($mon, $day, $year)) {
|
|
|
72 |
$time = make_timestamp($year, $mon, $day);
|
|
|
73 |
} else {
|
|
|
74 |
$time = time();
|
|
|
75 |
}
|
|
|
76 |
} else if (empty($time)) {
|
|
|
77 |
$time = time();
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
$url = new moodle_url('/calendar/export.php', array('time' => $time));
|
|
|
81 |
$managesubscriptionsurl = new moodle_url('/calendar/managesubscriptions.php');
|
|
|
82 |
|
|
|
83 |
if ($courseid != SITEID && !empty($courseid)) {
|
|
|
84 |
// Course ID must be valid and existing.
|
|
|
85 |
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
|
|
|
86 |
$courses = array($course->id => $course);
|
|
|
87 |
$url->param('course', $course->id);
|
|
|
88 |
$managesubscriptionsurl->param('course', $course->id);
|
|
|
89 |
|
|
|
90 |
navigation_node::override_active_url(new moodle_url('/course/view.php', ['id' => $course->id]));
|
|
|
91 |
$PAGE->navbar->add(
|
|
|
92 |
get_string('calendar', 'calendar'),
|
|
|
93 |
new moodle_url('/calendar/view.php', ['view' => 'month', 'course' => $course->id])
|
|
|
94 |
);
|
|
|
95 |
} else {
|
|
|
96 |
$course = get_site();
|
|
|
97 |
$courses = calendar_get_default_courses();
|
|
|
98 |
|
|
|
99 |
if (!empty($categoryid)) {
|
|
|
100 |
$managesubscriptionsurl->param('category', $categoryid);
|
|
|
101 |
|
|
|
102 |
navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid]));
|
|
|
103 |
$PAGE->set_category_by_id($categoryid);
|
|
|
104 |
$PAGE->navbar->add(
|
|
|
105 |
get_string('calendar', 'calendar'),
|
|
|
106 |
new moodle_url('/calendar/view.php', ['view' => 'month', 'category' => $categoryid])
|
|
|
107 |
);
|
|
|
108 |
} else {
|
|
|
109 |
$PAGE->navbar->add(get_string('calendar', 'calendar'), new moodle_url('/calendar/view.php', ['view' => 'month']));
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
require_login($course, false);
|
|
|
113 |
|
|
|
114 |
if ($action !== '') {
|
|
|
115 |
$url->param('action', $action);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$PAGE->set_url($url);
|
|
|
119 |
|
|
|
120 |
$calendar = new calendar_information(0, 0, 0, $time);
|
|
|
121 |
$calendar->set_sources($course, $courses);
|
|
|
122 |
|
|
|
123 |
$pagetitle = get_string('export', 'calendar');
|
|
|
124 |
|
|
|
125 |
$PAGE->navbar->add(get_string('managesubscriptions', 'calendar'), $managesubscriptionsurl);
|
|
|
126 |
$PAGE->navbar->add(get_string('exportcalendar', 'calendar'), $url);
|
|
|
127 |
|
|
|
128 |
// Print title and header.
|
|
|
129 |
$headingstr = get_string('calendar', 'core_calendar');
|
|
|
130 |
$headingstr = ($courseid != SITEID && !empty($courseid)) ? "{$headingstr}: {$COURSE->shortname}" : $headingstr;
|
|
|
131 |
$PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle);
|
|
|
132 |
$PAGE->set_heading($headingstr);
|
|
|
133 |
$PAGE->set_pagelayout('standard');
|
|
|
134 |
$PAGE->set_secondary_navigation(false);
|
|
|
135 |
|
|
|
136 |
$renderer = $PAGE->get_renderer('core_calendar');
|
|
|
137 |
$calendar->add_sidecalendar_blocks($renderer);
|
|
|
138 |
|
|
|
139 |
// Get the calendar type we are using.
|
|
|
140 |
$calendartype = \core_calendar\type_factory::get_calendar_instance();
|
|
|
141 |
$now = $calendartype->timestamp_to_date_array($time);
|
|
|
142 |
|
|
|
143 |
$weekend = CALENDAR_DEFAULT_WEEKEND;
|
|
|
144 |
if (isset($CFG->calendar_weekend)) {
|
|
|
145 |
$weekend = intval($CFG->calendar_weekend);
|
|
|
146 |
}
|
|
|
147 |
$numberofdaysinweek = $calendartype->get_num_weekdays();
|
|
|
148 |
|
|
|
149 |
$formdata = array(
|
|
|
150 |
// Let's populate some vars to let "common tasks" be somewhat smart...
|
|
|
151 |
// If today it's weekend, give the "next week" option.
|
|
|
152 |
'allownextweek' => $weekend & (1 << $now['wday']),
|
|
|
153 |
// If it's the last week of the month, give the "next month" option.
|
|
|
154 |
'allownextmonth' => calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek,
|
|
|
155 |
// If today it's weekend but tomorrow it isn't, do NOT give the "this week" option.
|
|
|
156 |
'allowthisweek' => !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % $numberofdaysinweek))))
|
|
|
157 |
);
|
|
|
158 |
|
|
|
159 |
// Disable submit protection so that the submit buttons continue working after being pressed.
|
|
|
160 |
$exportform = new core_calendar_export_form($FULLME, $formdata, 'POST', '', ['data-double-submit-protection' => 'off']);
|
|
|
161 |
$calendarurl = '';
|
|
|
162 |
if ($data = $exportform->get_data()) {
|
|
|
163 |
$params = array();
|
|
|
164 |
$params['userid'] = $USER->id;
|
|
|
165 |
$params['authtoken'] = calendar_get_export_token($USER);
|
|
|
166 |
$params['preset_what'] = $data->events['exportevents'];
|
|
|
167 |
$params['preset_time'] = $data->period['timeperiod'];
|
|
|
168 |
|
|
|
169 |
$link = new moodle_url('/calendar/export_execute.php', $params);
|
|
|
170 |
if (!empty($data->generateurl)) {
|
|
|
171 |
$exporturlcontext = ['calendarexporturl' => $link->out(false)];
|
|
|
172 |
$exporturl = $OUTPUT->render_from_template('core_calendar/export_calendar_url', $exporturlcontext);
|
|
|
173 |
$calendarurl = html_writer::div($exporturl, 'generalbox calendarurl mt-3');
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
if (!empty($data->export)) {
|
|
|
177 |
redirect($link);
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
echo $OUTPUT->header();
|
|
|
182 |
echo $renderer->start_layout();
|
|
|
183 |
echo $OUTPUT->heading(get_string('exportcalendar', 'calendar'));
|
|
|
184 |
|
|
|
185 |
if ($action != 'advanced') {
|
|
|
186 |
$exportform->display();
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
echo $calendarurl;
|
|
|
190 |
|
|
|
191 |
echo $renderer->complete_layout();
|
|
|
192 |
|
|
|
193 |
echo $OUTPUT->footer();
|