-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathview.php
executable file
·197 lines (171 loc) · 6.94 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
// This file is part of mod_organizer for Moodle - http://moodle.org/
//
// It is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// It is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* view.php
*
* @package mod_organizer
* @author Andreas Hruska (andreas.hruska@tuwien.ac.at)
* @author Katarzyna Potocka (katarzyna.potocka@tuwien.ac.at)
* @author Andreas Windbichler
* @author Ivan Šakić
* @copyright 2014 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("ORGANIZER_TAB_APPOINTMENTS_VIEW", 1);
define("ORGANIZER_TAB_STUDENT_VIEW", 2);
define("ORGANIZER_TAB_REGISTRATION_STATUS_VIEW", 3);
define("ORGANIZER_ASSIGNMENT_VIEW", 4);
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once(dirname(__FILE__) . '/../../calendar/lib.php');
require_once(dirname(__FILE__) . '/lib.php');
require_once(dirname(__FILE__) . '/view_lib.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once($CFG->libdir.'/completionlib.php');
$instance = organizer_get_course_module_data_new();
require_login($instance->course, false, $instance->cm);
$params = organizer_load_params($instance);
if (isset($_SESSION["organizer_new_instance"])) {
if ($params['mode'] == ORGANIZER_TAB_APPOINTMENTS_VIEW &&
("".$_SESSION["organizer_new_instance"] == "".$instance->organizer->id)) {
$_SESSION["organizer_new_instance"] = null;
$redirecturl = new moodle_url('/mod/organizer/slots_add.php', array('id' => $params['id']));
redirect($redirecturl);
}
}
$url = organizer_create_url($params);
$PAGE->set_url($url);
$PAGE->set_context($instance->context);
$PAGE->set_title($instance->organizer->name);
$PAGE->set_heading($instance->course->shortname);
$PAGE->set_activity_record($instance->organizer);
if ($instance->organizer->hidecalendar != 1) {
organizer_add_calendar();
}
// Completion.
$completion = new completion_info($instance->course);
$completion->set_module_viewed($instance->cm);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($instance->organizer->name), 2, null);
echo $OUTPUT->box_start('', 'organizer_main_cointainer');
switch ($params['mode']) {
case ORGANIZER_TAB_APPOINTMENTS_VIEW:
if (has_capability('mod/organizer:viewallslots', $instance->context)) {
$event = \mod_organizer\event\slot_viewed::create(
array(
'objectid' => $PAGE->cm->id,
'context' => $PAGE->context
)
);
$event->trigger();
echo organizer_generate_appointments_view($params, $instance);
} else {
print_error('You do not have the permission to view this page!');
}
break;
case ORGANIZER_TAB_STUDENT_VIEW:
if (has_capability('mod/organizer:viewstudentview', $instance->context)) {
$event = \mod_organizer\event\course_module_viewed::create(
array(
'objectid' => $PAGE->cm->instance,
'context' => $PAGE->context,
)
);
$event->add_record_snapshot('course', $PAGE->course);
$event->trigger();
echo organizer_generate_student_view($params, $instance);
} else {
print_error('You do not have the permission to view this page!');
}
break;
case ORGANIZER_TAB_REGISTRATION_STATUS_VIEW:
if (has_capability('mod/organizer:viewregistrations', $instance->context)) {
$event = \mod_organizer\event\registrations_viewed::create(
array(
'objectid' => $PAGE->cm->id,
'context' => $PAGE->context
)
);
$event->trigger();
echo organizer_generate_registration_status_view($params, $instance);
} else {
print_error('You do not have the permission to view this page!');
}
break;
case ORGANIZER_ASSIGNMENT_VIEW:
if (has_capability('mod/organizer:assignslots', $instance->context)) {
echo organizer_generate_assignment_view($params, $instance);
} else {
print_error('You do not have the permission to view this page!');
}
break;
default:
print_error("Invalid view mode: {$params['mode']}");
break;
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
die;
// Utility functions.
function organizer_create_url($params, $short = false) {
$url = new moodle_url('/mod/organizer/view.php');
$url->param('id', $params['id']);
if (!$short) {
if ($params['mode'] !== 0) {
$url->param('mode', $params['mode']);
}
if ($params['sort'] !== 'datetime') {
$url->param('sort', $params['sort']);
}
if ($params['dir'] !== 'ASC') {
$url->param('dir', $params['dir']);
}
}
return $url;
}
function organizer_load_params($instance) {
$params = array();
$params['id'] = required_param('id', PARAM_INT);
$params['mode'] = optional_param('mode', 0, PARAM_INT);
if ($params['mode'] == 0) {
if (has_capability('mod/organizer:addslots', $instance->context, null, true)) {
$params['mode'] = ORGANIZER_TAB_APPOINTMENTS_VIEW;
} else {
$params['mode'] = ORGANIZER_TAB_STUDENT_VIEW;
}
}
switch ($params['mode']) {
case ORGANIZER_TAB_APPOINTMENTS_VIEW:
case ORGANIZER_TAB_STUDENT_VIEW:
$params['sort'] = optional_param('sort', 'datetime', PARAM_ALPHA);
break;
case ORGANIZER_TAB_REGISTRATION_STATUS_VIEW:
$params['sort'] = optional_param('sort', '', PARAM_ALPHA);
break;
case ORGANIZER_ASSIGNMENT_VIEW:
$params['assignid'] = required_param('assignid', PARAM_INT);
$params['sort'] = optional_param('sort', 'datetime', PARAM_ALPHA);
break;
}
$params['slots'] = organizer_get_param_slots();
$params['pdir'] = optional_param('pdir', 'ASC', PARAM_ALPHA);
$params['psort'] = optional_param('psort', 'name', PARAM_ALPHA);
$params['dir'] = optional_param('dir', 'ASC', PARAM_ALPHA);
$params['data'] = optional_param_array('data', array(), PARAM_INT);
$params['messages'] = optional_param_array('messages', array(), PARAM_ALPHAEXT);
$params['xmessages'] = optional_param_array('xmessages', array(), PARAM_ALPHAEXT);
$params['usersort'] = optional_param('usersort', 'name', PARAM_ALPHA);
return $params;
}