Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of the Zoom plugin for Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Export ical file for a zoom meeting.
19
 *
20
 * @package    mod_zoom
21
 * @copyright  2015 UC Regents
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require(__DIR__ . '/../../config.php');
26
require_once($CFG->libdir . '/moodlelib.php');
27
require_once(__DIR__ . '/locallib.php');
28
require_once($CFG->libdir . '/bennu/bennu.inc.php');
29
 
30
// Course_module ID.
31
$id = required_param('id', PARAM_INT);
32
if ($id) {
33
    $cm = get_coursemodule_from_id('zoom', $id, 0, false, MUST_EXIST);
34
    $course = get_course($cm->course);
35
    $zoom = $DB->get_record('zoom', ['id' => $cm->instance], '*', MUST_EXIST);
36
} else {
37
    throw new moodle_exception('zoomerr_id_missing', 'mod_zoom');
38
}
39
 
40
require_login($course, true, $cm);
41
 
42
$context = context_module::instance($cm->id);
43
$PAGE->set_context($context);
44
 
45
require_capability('mod/zoom:view', $context);
46
 
47
// Get config.
48
$config = get_config('zoom');
49
 
50
// Check if the admin did not disable the feature.
51
if ($config->showdownloadical == ZOOM_DOWNLOADICAL_DISABLE) {
52
    $disabledredirecturl = new moodle_url('/mod/zoom/view.php', ['id' => $id]);
53
    throw new moodle_exception('err_downloadicaldisabled', 'mod_zoom', $disabledredirecturl);
54
}
55
 
56
// Check if we are dealing with a recurring meeting with no fixed time.
57
if ($zoom->recurring && $zoom->recurrence_type == ZOOM_RECURRINGTYPE_NOTIME) {
58
    $errorredirecturl = new moodle_url('/mod/zoom/view.php', ['id' => $id]);
59
    throw new moodle_exception('err_downloadicalrecurringnofixed', 'mod_zoom', $errorredirecturl);
60
}
61
 
62
// Start ical file.
63
$ical = new iCalendar();
64
$ical->add_property('method', 'PUBLISH');
65
$ical->add_property('prodid', '-//Moodle Pty Ltd//NONSGML Moodle Version ' . $CFG->version . '//EN');
66
 
67
// Get the meeting invite note to add to the description property.
68
$meetinginvite = zoom_webservice()->get_meeting_invitation($zoom)->get_display_string($cm->id);
69
 
70
// Compute and add description property to event.
71
$convertedtext = html_to_text($zoom->intro);
72
$descriptiontext = get_string('calendardescriptionURL', 'mod_zoom', $CFG->wwwroot . '/mod/zoom/view.php?id=' . $cm->id);
73
if (!empty($convertedtext)) {
74
    $descriptiontext .= get_string('calendardescriptionintro', 'mod_zoom', $convertedtext);
75
}
76
 
77
if (!empty($meetinginvite)) {
78
    $descriptiontext .= "\n\n" . $meetinginvite;
79
}
80
 
81
// Get all occurrences of the meeting from the DB.
82
$params = ['modulename' => 'zoom', 'instance' => $zoom->id];
83
$events = $DB->get_records('event', $params, 'timestart ASC');
84
 
85
// If we haven't got at least a single occurrence.
86
if (empty($events)) {
87
    // We could handle this case in a nicer way ans return an empty iCal file without events,
88
    // but as this case should not happen in real life anyway, return a fatal error to make clear that something is wrong.
89
    $errorredirecturl = new moodle_url('/mod/zoom/view.php', ['id' => $id]);
90
    throw new moodle_exception('err_downloadicalrecurringempty', 'mod_zoom', $errorredirecturl);
91
}
92
 
93
// Iterate over all events.
94
// We will add each event as an individual iCal event.
95
foreach ($events as $event) {
96
    $icalevent = zoom_helper_icalendar_event($event, $descriptiontext);
97
    // Add the event to the iCal file.
98
    $ical->add_component($icalevent);
99
}
100
 
101
// Start output of iCal file.
102
$serialized = $ical->serialize();
103
$filename = 'icalexport.ics';
104
 
105
// Create headers.
106
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
107
header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
108
header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . 'GMT');
109
header('Pragma: no-cache');
110
header('Accept-Ranges: none'); // Comment out if PDFs do not work...
111
header('Content-disposition: attachment; filename=' . $filename);
112
header('Content-length: ' . strlen($serialized));
113
header('Content-type: text/calendar; charset=utf-8');
114
 
115
echo $serialized;