source: moodle/trunk/fuentes/calendar/export.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 7.5 KB
Line 
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
49require_once('../config.php');
50require_once($CFG->dirroot.'/course/lib.php');
51require_once($CFG->dirroot.'/calendar/lib.php');
52
53if (empty($CFG->enablecalendarexport)) {
54    die('no export');
55}
56
57$courseid = optional_param('course', SITEID, PARAM_INT);
58$action = optional_param('action', '', PARAM_ALPHA);
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);
63$generateurl = optional_param('generateurl', 0, PARAM_BOOL);
64
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
79if ($courseid != SITEID && !empty($courseid)) {
80    $course = $DB->get_record('course', array('id' => $courseid));
81    $courses = array($course->id => $course);
82    $issite = false;
83} else {
84    $course = get_site();
85    $courses = calendar_get_default_courses();
86    $issite = true;
87}
88require_course_login($course);
89
90$url = new moodle_url('/calendar/export.php', array('time' => $time));
91
92if ($action !== '') {
93    $url->param('action', $action);
94}
95
96if ($course !== NULL) {
97    $url->param('course', $course->id);
98}
99$PAGE->set_url($url);
100
101$calendar = new calendar_information(0, 0, 0, $time);
102$calendar->prepare_for_view($course, $courses);
103
104$pagetitle = get_string('export', 'calendar');
105
106// Print title and header
107if ($issite) {
108    $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
109}
110$link = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid));
111$PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time));
112$PAGE->navbar->add($pagetitle);
113
114$PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle);
115$PAGE->set_heading($course->fullname);
116$PAGE->set_pagelayout('standard');
117$PAGE->set_button(calendar_preferences_button($course));
118
119$renderer = $PAGE->get_renderer('core_calendar');
120$calendar->add_sidecalendar_blocks($renderer);
121
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);
125
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()) {
144    $password = $DB->get_record('user', array('id' => $USER->id), 'password');
145    $params = array();
146    $params['userid']      = $USER->id;
147    $params['authtoken']   = sha1($USER->id . (isset($password->password) ? $password->password : '') . $CFG->calendar_exportsalt);
148    $params['preset_what'] = $data->events['exportevents'];
149    $params['preset_time'] = $data->period['timeperiod'];
150
151    $link = new moodle_url('/calendar/export_execute.php', $params);
152    if (!empty($data->generateurl)) {
153        $urlclasses = array('class' => 'generalbox calendarurl');
154        $calendarurl = html_writer::tag( 'div', get_string('calendarurl', 'calendar', $link->out()), $urlclasses);
155    }
156
157    if (!empty($data->export)) {
158        redirect($link);
159    }
160}
161
162echo $OUTPUT->header();
163echo $renderer->start_layout();
164echo $OUTPUT->heading(get_string('exportcalendar', 'calendar'));
165
166if ($action != 'advanced') {
167    $exportform->display();
168}
169
170echo $calendarurl;
171
172echo $renderer->complete_layout();
173echo $OUTPUT->footer();
Note: See TracBrowser for help on using the repository browser.