MDL-27854 qformat_xml fix import/export of essay questions to include the new options.
[moodle.git] / calendar / set.php
blob039139efc40fb491bab87333d29dd190cb1f539e
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 require_once('../config.php');
42 require_once($CFG->dirroot.'/calendar/lib.php');
44 $from = required_param('from', PARAM_ALPHA);
45 $var = required_param('var', PARAM_ALPHA);
46 $id = optional_param('id', 0, PARAM_INT);
47 $cal_d = optional_param('cal_d', 0, PARAM_INT);
48 $cal_m = optional_param('cal_m', 0, PARAM_INT);
49 $cal_y = optional_param('cal_y', 0, PARAM_INT);
50 $action = optional_param('action', '', PARAM_ALPHA);
51 $type = optional_param('type', '', PARAM_ALPHA);
53 $url = new moodle_url('/calendar/set.php', array('from'=>$from,'var'=>$var));
54 if ($id !== 0) {
55 $url->param('id', $id);
57 if ($cal_d !== 0) {
58 $url->param('cal_d', $cal_d);
60 if ($cal_m !== 0) {
61 $url->param('cal_m', $cal_m);
63 if ($cal_y !== 0) {
64 $url->param('cal_y', $cal_y);
66 if ($action !== 0) {
67 $url->param('action', $action);
69 if ($type !== 0) {
70 $url->param('type', $type);
72 $PAGE->set_url($url);
73 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong
75 // Initialize the session variables
76 calendar_session_vars();
78 // Ensure course id passed if relevant
79 // Required due to changes in view/lib.php mainly (calendar_session_vars())
80 $courseid = '';
81 if (!empty($id)) {
82 $courseid = '&course='.$id;
85 switch($var) {
86 case 'setuser':
87 // Not implemented yet (or possibly at all)
88 break;
89 case 'setcourse':
90 $id = intval($id);
91 if($id == 0) {
92 $SESSION->cal_courses_shown = array();
93 calendar_set_referring_course(0);
95 else if($id == 1) {
96 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
97 calendar_set_referring_course(0);
99 else {
100 if($DB->get_record('course', array('id'=>$id)) === false) {
101 // There is no such course
102 $SESSION->cal_courses_shown = array();
103 calendar_set_referring_course(0);
105 else {
106 calendar_set_referring_course($id);
107 $SESSION->cal_courses_shown = $id;
110 break;
111 case 'showgroups':
112 $SESSION->cal_show_groups = !$SESSION->cal_show_groups;
113 set_user_preference('calendar_savedflt', calendar_get_filters_status());
114 break;
115 case 'showcourses':
116 $SESSION->cal_show_course = !$SESSION->cal_show_course;
117 set_user_preference('calendar_savedflt', calendar_get_filters_status());
118 break;
119 case 'showglobal':
120 $SESSION->cal_show_global = !$SESSION->cal_show_global;
121 set_user_preference('calendar_savedflt', calendar_get_filters_status());
122 break;
123 case 'showuser':
124 $SESSION->cal_show_user = !$SESSION->cal_show_user;
125 set_user_preference('calendar_savedflt', calendar_get_filters_status());
126 break;
129 switch($from) {
130 case 'event':
131 redirect(CALENDAR_URL.'event.php?action='.$action.'&amp;type='.$type.'&amp;id='.intval($id));
132 break;
133 case 'month':
134 redirect(CALENDAR_URL.'view.php?view=month'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y);
135 break;
136 case 'upcoming':
137 redirect(CALENDAR_URL.'view.php?view=upcoming'.$courseid);
138 break;
139 case 'day':
140 redirect(CALENDAR_URL.'view.php?view=day'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y);
141 break;
142 case 'course':
143 redirect($CFG->wwwroot.'/course/view.php?id='.intval($id));
144 break;
145 default: