forked from kordan/moodle-mod_surveypro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs.php
executable file
·308 lines (258 loc) · 13 KB
/
tabs.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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/>.
/**
* @package mod_surveypro
* @copyright 2013 onwards kordan <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
// do not prevent direct user input
// prevention is done in each working page according to actions
$riskyediting = ($surveypro->riskyeditdeadline > time());
$hassubmissions = surveypro_count_submissions($surveypro->id);
$context = context_module::instance($cm->id);
$cansubmit = has_capability('mod/surveypro:submit', $context, null, true);
$canmanageitems = has_capability('mod/surveypro:manageitems', $context, null, true);
$canmanageusertemplates = has_capability('mod/surveypro:manageusertemplates', $context, null, true);
$cansavemastertemplates = has_capability('mod/surveypro:savemastertemplates', $context, null, true);
$canapplymastertemplates = has_capability('mod/surveypro:applymastertemplates', $context, null, true);
$whereparams = array('surveyproid' => $surveypro->id);
$countparents = $DB->count_records_select('surveypro_item', 'surveyproid = :surveyproid AND parentid <> 0', $whereparams);
$inactive = null;
$activetwo = null;
// **********************************************
// TABS
// **********************************************
$paramurl = array('id' => $cm->id);
// ==> tab row definition
$row = array();
// ----------------------------------------
// TAB ITEMS
// ----------------------------------------
$tabitemsname = get_string('tabitemsname', 'surveypro');
if ($canmanageitems) {
$elementurl = new moodle_url('/mod/surveypro/items_manage.php', $paramurl);
$row[] = new tabobject($tabitemsname, $elementurl->out(), $tabitemsname);
}
// ----------------------------------------
// TAB SUBMISSIONS
// ----------------------------------------
$tabsubmissionsname = get_string('tabsubmissionsname', 'surveypro');
$localparamurl = array('id' => $cm->id, 'cover' => 0);
$elementurl = new moodle_url('/mod/surveypro/view.php', $localparamurl);
$row[] = new tabobject($tabsubmissionsname, $elementurl->out(), $tabsubmissionsname);
// ----------------------------------------
// TAB USER TEMPLATES
// ----------------------------------------
$tabutemplatename = get_string('tabutemplatename', 'surveypro');
if (empty($surveypro->template)) {
if ($moduletab == SURVEYPRO_TABUTEMPLATES) {
if ($canmanageusertemplates) {
$elementurl = new moodle_url('/mod/surveypro/utemplates_create.php', $paramurl);
$row[] = new tabobject($tabutemplatename, $elementurl->out(), $tabutemplatename);
}
}
}
// ----------------------------------------
// TAB MASTER TEMPLATES
// ----------------------------------------
$tabmtemplatename = get_string('tabmtemplatename', 'surveypro');
if ($moduletab == SURVEYPRO_TABMTEMPLATES) {
if ($cansavemastertemplates || ((!$hassubmissions || $riskyediting) && $canapplymastertemplates)) {
$elementurl = new moodle_url('/mod/surveypro/mtemplates_create.php', $paramurl);
$row[] = new tabobject($tabmtemplatename, $elementurl->out(), $tabmtemplatename);
}
}
// ----------------------------------------
// ==> tab row definition
// ----------------------------------------
$tabs = array();
$tabs[] = $row; // Array of tabs. Closes the tab row element definition
// next tabs element is going to define the pages row
// echo '$modulepage = '.$modulepage.'<br />';
$pageid = 'idpage'.$modulepage;
// $pageid is here because I leave the door open to override it during next switch
// **********************************************
// PAGES
// **********************************************
// echo '$moduletab = '.$moduletab.'<br />';
// echo '$modulepage = '.$modulepage.'<br />';
switch ($moduletab) {
case SURVEYPRO_TABITEMS:
// permissions
$canpreview = has_capability('mod/surveypro:preview', $context, null, true);
$inactive = array($tabitemsname);
$activetwo = array($tabitemsname);
$row = array();
if ($canpreview) { // preview
$localparamurl = array('id' => $cm->id, 'view' => SURVEYPRO_PREVIEWSURVEYFORM);
$elementurl = new moodle_url('/mod/surveypro/view_userform.php', $localparamurl);
$strlabel = get_string('tabitemspage1', 'surveypro');
$row[] = new tabobject('idpage1', $elementurl->out(), $strlabel);
}
if ($canmanageitems) { // manage
$elementurl = new moodle_url('/mod/surveypro/items_manage.php', $paramurl);
$strlabel = get_string('tabitemspage2', 'surveypro');
$row[] = new tabobject('idpage2', $elementurl->out(), $strlabel);
if (empty($surveypro->template)) {
if ($modulepage == SURVEYPRO_ITEMS_SETUP) { // setup
$elementurl = new moodle_url('/mod/surveypro/items_setup.php', $paramurl);
$strlabel = get_string('tabitemspage3', 'surveypro');
$row[] = new tabobject('idpage3', $elementurl->out(), $strlabel);
}
if ($countparents) { // verify parent child relations
$elementurl = new moodle_url('/mod/surveypro/items_validate.php', $paramurl);
$strlabel = get_string('tabitemspage4', 'surveypro');
$row[] = new tabobject('idpage4', $elementurl->out(), $strlabel);
}
}
}
$tabs[] = $row;
break;
case SURVEYPRO_TABSUBMISSIONS:
// permissions
$canview = has_capability('mod/surveypro:view', $context, null, true);
$cansearch = has_capability('mod/surveypro:searchsubmissions', $context, null, true);
$canaccessreports = has_capability('mod/surveypro:accessreports', $context, null, true);
$canimportdata = has_capability('mod/surveypro:importdata', $context, null, true);
$canexportdata = has_capability('mod/surveypro:exportdata', $context, null, true);
$inactive = array($tabsubmissionsname);
$activetwo = array($tabsubmissionsname);
$row = array();
// Cover page
if ($canview) {
$elementurl = new moodle_url('/mod/surveypro/view_cover.php', $paramurl);
$strlabel = get_string('tabsubmissionspage1', 'surveypro');
$row[] = new tabobject('idpage1', $elementurl->out(), $strlabel);
}
// Responses
if (!is_guest($context)) {
$localparamurl = array('id' => $cm->id, 'cover' => 0);
$elementurl = new moodle_url('/mod/surveypro/view.php', $localparamurl);
$strlabel = get_string('tabsubmissionspage2', 'surveypro');
$row[] = new tabobject('idpage2', $elementurl->out(), $strlabel);
}
// Insert
if ($modulepage == SURVEYPRO_SUBMISSION_INSERT) {
$localparamurl = array('id' => $cm->id, 'view' => SURVEYPRO_NEWRESPONSE);
$elementurl = new moodle_url('/mod/surveypro/view_userform.php', $localparamurl);
$strlabel = get_string('tabsubmissionspage3', 'surveypro');
$row[] = new tabobject('idpage3', $elementurl->out(), $strlabel);
}
if ($modulepage == SURVEYPRO_SUBMISSION_EDIT) { // edit
$localparamurl = array('id' => $cm->id, 'view' => SURVEYPRO_EDITRESPONSE);
$elementurl = new moodle_url('/mod/surveypro/view_userform.php', $localparamurl);
$strlabel = get_string('tabsubmissionspage4', 'surveypro'); // edit
$row[] = new tabobject('idpage4', $elementurl->out(), $strlabel);
}
if ($modulepage == SURVEYPRO_SUBMISSION_READONLY) { // read only
$localparamurl = array('id' => $cm->id, 'view' => SURVEYPRO_READONLYRESPONSE);
$elementurl = new moodle_url('/mod/surveypro/view_userform.php', $localparamurl);
$strlabel = get_string('tabsubmissionspage5', 'surveypro'); // read only
$row[] = new tabobject('idpage5', $elementurl->out(), $strlabel);
}
if ($cansearch) { // search
$elementurl = new moodle_url('/mod/surveypro/view_search.php', $paramurl);
$strlabel = get_string('tabsubmissionspage6', 'surveypro');
$row[] = new tabobject('idpage6', $elementurl->out(), $strlabel);
}
if ($modulepage == SURVEYPRO_SUBMISSION_REPORT) { // report
if ($canaccessreports) {
$elementurl = new moodle_url('/mod/surveypro/view_report.php', $paramurl);
$strlabel = get_string('tabsubmissionspage7', 'surveypro');
$row[] = new tabobject('idpage7', $elementurl->out(), $strlabel);
}
}
if ($modulepage == SURVEYPRO_SUBMISSION_IMPORT) { // import
if ($canimportdata) { // import
$elementurl = new moodle_url('/mod/surveypro/view_import.php', $paramurl);
$strlabel = get_string('tabsubmissionspage8', 'surveypro');
$row[] = new tabobject('idpage8', $elementurl->out(), $strlabel);
}
}
if ($modulepage == SURVEYPRO_SUBMISSION_EXPORT) { // export
if ($canexportdata) { // export
$elementurl = new moodle_url('/mod/surveypro/view_export.php', $paramurl);
$strlabel = get_string('tabsubmissionspage9', 'surveypro');
$row[] = new tabobject('idpage9', $elementurl->out(), $strlabel);
}
}
$tabs[] = $row;
break;
case SURVEYPRO_TABUTEMPLATES:
// permissions
$cansaveusertemplates = has_capability('mod/surveypro:saveusertemplates', $context, null, true);
$canimportusertemplates = has_capability('mod/surveypro:importusertemplates', $context, null, true);
$canapplyusertemplates = has_capability('mod/surveypro:applyusertemplates', $context, null, true);
if (!empty($surveypro->template)) {
break;
}
$inactive = array($tabutemplatename);
$activetwo = array($tabutemplatename);
if ($canmanageusertemplates) {
$row = array();
$elementurl = new moodle_url('/mod/surveypro/utemplates_manage.php', $paramurl); // manage
$strlabel = get_string('tabutemplatepage1', 'surveypro');
$row[] = new tabobject('idpage1', $elementurl->out(), $strlabel);
if ($cansaveusertemplates) { // create
$elementurl = new moodle_url('/mod/surveypro/utemplates_create.php', $paramurl);
$strlabel = get_string('tabutemplatepage2', 'surveypro');
$row[] = new tabobject('idpage2', $elementurl->out(), $strlabel);
}
if ($canimportusertemplates) { // import
$elementurl = new moodle_url('/mod/surveypro/utemplates_import.php', $paramurl);
$strlabel = get_string('tabutemplatepage3', 'surveypro');
$row[] = new tabobject('idpage3', $elementurl->out(), $strlabel);
}
if ( (!$hassubmissions || $riskyediting) && $canapplyusertemplates ) {
$elementurl = new moodle_url('/mod/surveypro/utemplates_apply.php', $paramurl); // apply
$strlabel = get_string('tabutemplatepage4', 'surveypro');
$row[] = new tabobject('idpage4', $elementurl->out(), $strlabel);
}
}
$tabs[] = $row;
break;
case SURVEYPRO_TABMTEMPLATES:
$inactive = array($tabmtemplatename);
$activetwo = array($tabmtemplatename);
$row = array();
if ($cansavemastertemplates) { // create
$elementurl = new moodle_url('/mod/surveypro/mtemplates_create.php', $paramurl);
$strlabel = get_string('tabmtemplatepage1', 'surveypro');
$row[] = new tabobject('idpage1', $elementurl->out(), $strlabel);
}
if ( (!$hassubmissions || $riskyediting) && $canapplymastertemplates ) { // if submissions were done, do not change the list of fields
$elementurl = new moodle_url('/mod/surveypro/mtemplates_apply.php', $paramurl); // apply
$strlabel = get_string('tabmtemplatepage2', 'surveypro');
$row[] = new tabobject('idpage2', $elementurl->out(), $strlabel);
}
$tabs[] = $row;
break;
default:
print_error('incorrectaccessdetected', 'surveypro');
}
// echo '$tabs:';
// var_dump($tabs);
//
// echo '$pageid:';
// var_dump($pageid);
//
// echo '$inactive:';
// var_dump($inactive);
//
// echo '$activetwo:';
// var_dump($activetwo);
print_tabs($tabs, $pageid, $inactive, $activetwo);