Merge branch 'w40_MDL-41999_m26_userpw' of https://github.com/skodak/moodle
[moodle.git] / calendar / export.php
1 <?php
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 /////////////////////////////////////////////////////////////////////////////
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  */
49 require_once('../config.php');
50 require_once($CFG->dirroot.'/course/lib.php');
51 require_once($CFG->dirroot.'/calendar/lib.php');
53 if (empty($CFG->enablecalendarexport)) {
54     die('no export');
55 }
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 $yr   = optional_param('cal_y', 0, PARAM_INT);
62 $generateurl = optional_param('generateurl', 0, PARAM_BOOL);
64 if ($courseid != SITEID && !empty($courseid)) {
65     $course = $DB->get_record('course', array('id' => $courseid));
66     $courses = array($course->id => $course);
67     $issite = false;
68 } else {
69     $course = get_site();
70     $courses = calendar_get_default_courses();
71     $issite = true;
72 }
73 require_course_login($course);
75 $url = new moodle_url('/calendar/export.php');
76 if ($action !== '') {
77     $url->param('action', $action);
78 }
79 if ($day !== 0) {
80     $url->param('cal_d', $day);
81 }
82 if ($mon !== 0) {
83     $url->param('cal_m', $mon);
84 }
85 if ($yr !== 0) {
86     $url->param('cal_y', $yr);
87 }
88 if ($course !== NULL) {
89     $url->param('course', $course->id);
90 }
91 $PAGE->set_url($url);
93 $calendar = new calendar_information($day, $mon, $yr);
94 $calendar->prepare_for_view($course, $courses);
96 $pagetitle = get_string('export', 'calendar');
97 $now = usergetdate(time());
99 // Print title and header
100 if ($issite) {
101     $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
103 $link = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid));
104 $PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, $now['mday'], $now['mon'], $now['year']));
105 $PAGE->navbar->add($pagetitle);
107 $PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle);
108 $PAGE->set_heading($course->fullname);
109 $PAGE->set_pagelayout('standard');
110 $PAGE->set_button(calendar_preferences_button($course));
112 $renderer = $PAGE->get_renderer('core_calendar');
113 $calendar->add_sidecalendar_blocks($renderer);
115 echo $OUTPUT->header();
116 echo $renderer->start_layout();
117 switch($action) {
118     case 'advanced':
119         // Why nothing?
120         break;
121     case '':
122     default:
123         $weekend = CALENDAR_DEFAULT_WEEKEND;
124         if (isset($CFG->calendar_weekend)) {
125             $weekend = intval($CFG->calendar_weekend);
126         }
128         $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id'=>$USER->id)). $CFG->calendar_exportsalt);
129         // Let's populate some vars to let "common tasks" be somewhat smart...
130         // If today it's weekend, give the "next week" option
131         $allownextweek  = $weekend & (1 << $now['wday']);
132         // If it's the last week of the month, give the "next month" option
133         $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
134         // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
135         $allowthisweek  = !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % 7))));
136         echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $USER->id, $authtoken);
137         break;
140 if (!empty($generateurl)) {
141     $params['userid']      = optional_param('userid', 0, PARAM_INT);
142     $params['authtoken']   = optional_param('authtoken', '', PARAM_ALPHANUM);
143     $params['preset_what'] = optional_param('preset_what', 'all', PARAM_ALPHA);
144     $params['preset_time'] = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
146     $link = new moodle_url('/calendar/export_execute.php', $params);
147     print html_writer::tag('div', get_string('calendarurl', 'calendar', $link->out()), array('class' => 'generalbox calendarurl'));
150 echo $renderer->complete_layout();
151 echo $OUTPUT->footer();