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 ID must be valid and existing. 81 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); 82 $courses = array($course->id => $course); 83 $issite = false; 84} else { 85 $course = get_site(); 86 $courses = calendar_get_default_courses(); 87 $issite = true; 88} 89require_login($course, false); 90 91$url = new moodle_url('/calendar/export.php', array('time' => $time)); 92 93if ($action !== '') { 94 $url->param('action', $action); 95} 96 97if ($course !== NULL) { 98 $url->param('course', $course->id); 99} 100$PAGE->set_url($url); 101 102$calendar = new calendar_information(0, 0, 0, $time); 103$calendar->set_sources($course, $courses); 104 105$pagetitle = get_string('export', 'calendar'); 106 107// Print title and header 108if ($issite) { 109 $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id))); 110} 111$link = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid)); 112$PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time)); 113$PAGE->navbar->add($pagetitle); 114 115$PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle); 116$PAGE->set_heading($course->fullname); 117$PAGE->set_pagelayout('standard'); 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 142// Disable submit protection so that the submit buttons continue working after being pressed. 143$exportform = new core_calendar_export_form($FULLME, $formdata, 'POST', '', ['data-double-submit-protection' => 'off']); 144$calendarurl = ''; 145if ($data = $exportform->get_data()) { 146 $params = array(); 147 $params['userid'] = $USER->id; 148 $params['authtoken'] = calendar_get_export_token($USER); 149 $params['preset_what'] = $data->events['exportevents']; 150 $params['preset_time'] = $data->period['timeperiod']; 151 152 $link = new moodle_url('/calendar/export_execute.php', $params); 153 if (!empty($data->generateurl)) { 154 $urlclasses = array('class' => 'generalbox calendarurl'); 155 $calendarurl = html_writer::tag( 'div', get_string('calendarurl', 'calendar', $link->out()), $urlclasses); 156 } 157 158 if (!empty($data->export)) { 159 redirect($link); 160 } 161} 162 163echo $OUTPUT->header(); 164echo $renderer->start_layout(); 165echo $OUTPUT->heading(get_string('exportcalendar', 'calendar')); 166 167if ($action != 'advanced') { 168 $exportform->display(); 169} 170 171echo $calendarurl; 172 173echo $renderer->complete_layout(); 174 175echo $OUTPUT->footer(); 176