|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This script shows a list of courses and allows searching for courses codes |
|
7
|
|
|
* and names. |
|
8
|
|
|
*/ |
|
9
|
|
|
$cidReset = true; |
|
10
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
|
11
|
|
|
$this_section = SECTION_PLATFORM_ADMIN; |
|
12
|
|
|
api_protect_admin_script(); |
|
13
|
|
|
$sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null; |
|
14
|
|
|
$addTeacherColumn = api_get_configuration_value('add_teachers_in_course_list'); |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the number of courses which will be displayed. |
|
18
|
|
|
* |
|
19
|
|
|
* @throws Exception |
|
20
|
|
|
* |
|
21
|
|
|
* @return int The number of matching courses |
|
22
|
|
|
*/ |
|
23
|
|
|
function get_number_of_courses() |
|
24
|
|
|
{ |
|
25
|
|
|
return get_course_data(0, 0, 0, 0, null, true); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get course data to display. |
|
30
|
|
|
* |
|
31
|
|
|
* @param int $from |
|
32
|
|
|
* @param int $number_of_items |
|
33
|
|
|
* @param int $column |
|
34
|
|
|
* @param string $direction |
|
35
|
|
|
* |
|
36
|
|
|
* @throws Exception |
|
37
|
|
|
* |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
function get_course_data($from, $number_of_items, $column, $direction, $dataFunctions = [], $getCount = false) |
|
41
|
|
|
{ |
|
42
|
|
|
$addTeacherColumn = api_get_configuration_value('add_teachers_in_course_list'); |
|
43
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE); |
|
44
|
|
|
|
|
45
|
|
|
$teachers = ''; |
|
46
|
|
|
if ($addTeacherColumn) { |
|
47
|
|
|
$teachers = " GROUP_CONCAT(cu.user_id SEPARATOR ',') as col7, "; |
|
48
|
|
|
} |
|
49
|
|
|
$select = "SELECT |
|
50
|
|
|
code AS col0, |
|
51
|
|
|
title AS col1, |
|
52
|
|
|
code AS col2, |
|
53
|
|
|
course_language AS col3, |
|
54
|
|
|
category_code AS col4, |
|
55
|
|
|
subscribe AS col5, |
|
56
|
|
|
unsubscribe AS col6, |
|
57
|
|
|
$teachers |
|
58
|
|
|
visibility, |
|
59
|
|
|
directory, |
|
60
|
|
|
visual_code, |
|
61
|
|
|
course.code, |
|
62
|
|
|
course.id "; |
|
63
|
|
|
|
|
64
|
|
|
if ($getCount) { |
|
65
|
|
|
$select = 'SELECT COUNT(DISTINCT(course.id)) as count '; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$sql = "$select FROM $table course"; |
|
69
|
|
|
|
|
70
|
|
|
if ((api_is_platform_admin() || api_is_session_admin()) && |
|
71
|
|
|
api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1 |
|
72
|
|
|
) { |
|
73
|
|
|
$access_url_rel_course_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
|
74
|
|
|
$sql .= " INNER JOIN $access_url_rel_course_table url_rel_course |
|
75
|
|
|
ON (course.id = url_rel_course.c_id)"; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ($addTeacherColumn) { |
|
79
|
|
|
$tableCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
|
80
|
|
|
$sql .= " |
|
81
|
|
|
LEFT JOIN $tableCourseRelUser cu |
|
82
|
|
|
ON (course.id = cu.c_id AND cu.status = ".COURSEMANAGER.") |
|
83
|
|
|
"; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (isset($_GET['keyword'])) { |
|
87
|
|
|
$keyword = Database::escape_string("%".trim($_GET['keyword'])."%"); |
|
88
|
|
|
$sql .= " WHERE ( |
|
89
|
|
|
title LIKE '".$keyword."' OR |
|
90
|
|
|
code LIKE '".$keyword."' OR |
|
91
|
|
|
visual_code LIKE '".$keyword."' |
|
92
|
|
|
) |
|
93
|
|
|
"; |
|
94
|
|
|
} elseif (isset($_GET['keyword_code'])) { |
|
95
|
|
|
$keyword_code = Database::escape_string("%".$_GET['keyword_code']."%"); |
|
96
|
|
|
$keyword_title = Database::escape_string("%".$_GET['keyword_title']."%"); |
|
97
|
|
|
$keyword_category = isset($_GET['keyword_category']) |
|
98
|
|
|
? Database::escape_string("%".$_GET['keyword_category']."%") |
|
99
|
|
|
: null; |
|
100
|
|
|
$keyword_language = Database::escape_string("%".$_GET['keyword_language']."%"); |
|
101
|
|
|
$keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%"); |
|
102
|
|
|
$keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']); |
|
103
|
|
|
$keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']); |
|
104
|
|
|
|
|
105
|
|
|
$sql .= " WHERE |
|
106
|
|
|
(code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND |
|
107
|
|
|
title LIKE '".$keyword_title."' AND |
|
108
|
|
|
course_language LIKE '".$keyword_language."' AND |
|
109
|
|
|
visibility LIKE '".$keyword_visibility."' AND |
|
110
|
|
|
subscribe LIKE '".$keyword_subscribe."' AND |
|
111
|
|
|
unsubscribe LIKE '".$keyword_unsubscribe."'"; |
|
112
|
|
|
|
|
113
|
|
|
if (!empty($keyword_category)) { |
|
114
|
|
|
$sql .= " AND category_code LIKE '".$keyword_category."' "; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
// Adding the filter to see the user's only of the current access_url. |
|
119
|
|
|
if ((api_is_platform_admin() || api_is_session_admin()) && |
|
120
|
|
|
api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1 |
|
121
|
|
|
) { |
|
122
|
|
|
$sql .= " AND url_rel_course.access_url_id = ".api_get_current_access_url_id(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
if ($addTeacherColumn) { |
|
126
|
|
|
$teachers = isset($_GET['course_teachers']) ? $_GET['course_teachers'] : []; |
|
127
|
|
|
if (!empty($teachers)) { |
|
128
|
|
|
$teachers = array_map('intval', $teachers); |
|
129
|
|
|
$addNull = ''; |
|
130
|
|
|
foreach ($teachers as $key => $teacherId) { |
|
131
|
|
|
if (0 === $teacherId) { |
|
132
|
|
|
$addNull = 'OR cu.user_id IS NULL '; |
|
133
|
|
|
unset($key); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
$sql .= ' AND ( cu.user_id IN ("'.implode('", "', $teachers).'") '.$addNull.' ) '; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if (false === $getCount) { |
|
140
|
|
|
$sql .= " GROUP BY course.id "; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
if ($getCount) { |
|
145
|
|
|
$res = Database::query($sql); |
|
146
|
|
|
$row = Database::fetch_array($res); |
|
147
|
|
|
if ($row) { |
|
148
|
|
|
return (int) $row['count']; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
return 0; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$sql .= " ORDER BY col$column $direction "; |
|
155
|
|
|
$sql .= " LIMIT $from, $number_of_items"; |
|
156
|
|
|
|
|
157
|
|
|
$res = Database::query($sql); |
|
158
|
|
|
$courses = []; |
|
159
|
|
|
$languages = api_get_languages_to_array(); |
|
160
|
|
|
$path = api_get_path(WEB_CODE_PATH); |
|
161
|
|
|
$coursePath = api_get_path(WEB_COURSE_PATH); |
|
162
|
|
|
|
|
163
|
|
|
while ($course = Database::fetch_array($res)) { |
|
164
|
|
|
$courseId = $course['id']; |
|
165
|
|
|
$courseCode = $course['code']; |
|
166
|
|
|
|
|
167
|
|
|
// Place colour icons in front of courses. |
|
168
|
|
|
$showVisualCode = $course['visual_code'] != $courseCode ? Display::label($course['visual_code'], 'info') : null; |
|
169
|
|
|
$course[1] = get_course_visibility_icon($course['visibility']).PHP_EOL |
|
170
|
|
|
.Display::url(Security::remove_XSS($course[1]), $coursePath.$course['directory'].'/index.php').PHP_EOL |
|
171
|
|
|
.$showVisualCode; |
|
172
|
|
|
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); |
|
173
|
|
|
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); |
|
174
|
|
|
$language = isset($languages[$course[3]]) ? $languages[$course[3]] : $course[3]; |
|
175
|
|
|
|
|
176
|
|
|
$actions = []; |
|
177
|
|
|
$actions[] = Display::url( |
|
178
|
|
|
Display::return_icon('info2.png', get_lang('Info')), |
|
179
|
|
|
"course_information.php?code=$courseCode" |
|
180
|
|
|
); |
|
181
|
|
|
$actions[] = Display::url( |
|
182
|
|
|
Display::return_icon('course_home.png', get_lang('CourseHomepage')), |
|
183
|
|
|
$coursePath.$course['directory'].'/index.php' |
|
184
|
|
|
); |
|
185
|
|
|
$actions[] = Display::url( |
|
186
|
|
|
Display::return_icon('statistics.png', get_lang('Tracking')), |
|
187
|
|
|
$path.'tracking/courseLog.php?'.api_get_cidreq_params($courseCode) |
|
188
|
|
|
); |
|
189
|
|
|
$actions[] = Display::url( |
|
190
|
|
|
Display::return_icon('edit.png', get_lang('Edit')), |
|
191
|
|
|
$path.'admin/course_edit.php?id='.$courseId |
|
192
|
|
|
); |
|
193
|
|
|
$actions[] = Display::url( |
|
194
|
|
|
Display::return_icon('backup.png', get_lang('CreateBackup')), |
|
195
|
|
|
$path.'coursecopy/create_backup.php?'.api_get_cidreq_params($courseCode) |
|
196
|
|
|
); |
|
197
|
|
|
$actions[] = Display::url( |
|
198
|
|
|
Display::return_icon('delete.png', get_lang('Delete')), |
|
199
|
|
|
$path.'admin/course_list.php?delete_course='.$courseCode, |
|
200
|
|
|
[ |
|
201
|
|
|
'onclick' => "javascript: if (!confirm('" |
|
202
|
|
|
.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."')) return false;", |
|
203
|
|
|
] |
|
204
|
|
|
); |
|
205
|
|
|
$courseItem = [ |
|
206
|
|
|
$course[0], |
|
207
|
|
|
$course[1], |
|
208
|
|
|
$course[2], |
|
209
|
|
|
$language, |
|
210
|
|
|
$course[4], |
|
211
|
|
|
$course[5], |
|
212
|
|
|
$course[6], |
|
213
|
|
|
]; |
|
214
|
|
|
|
|
215
|
|
|
if ($addTeacherColumn) { |
|
216
|
|
|
$teacherIdList = array_filter(explode(',', $course[7])); |
|
217
|
|
|
$teacherList = []; |
|
218
|
|
|
if (!empty($teacherIdList)) { |
|
219
|
|
|
foreach ($teacherIdList as $teacherId) { |
|
220
|
|
|
$userInfo = api_get_user_info($teacherId); |
|
221
|
|
|
if ($userInfo) { |
|
222
|
|
|
$teacherList[] = $userInfo['complete_name']; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
$courseItem[] = implode(', ', $teacherList); |
|
227
|
|
|
} |
|
228
|
|
|
$courseItem[] =implode(PHP_EOL, $actions); |
|
229
|
|
|
$courses[] = $courseItem; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
return $courses; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Get course data to display filtered by session name. |
|
237
|
|
|
* |
|
238
|
|
|
* @param int $from |
|
239
|
|
|
* @param int $number_of_items |
|
240
|
|
|
* @param int $column |
|
241
|
|
|
* @param string $direction |
|
242
|
|
|
* |
|
243
|
|
|
* @throws Exception |
|
244
|
|
|
* |
|
245
|
|
|
* @return array |
|
246
|
|
|
*/ |
|
247
|
|
|
function get_course_data_by_session($from, $number_of_items, $column, $direction) |
|
248
|
|
|
{ |
|
249
|
|
|
$course_table = Database::get_main_table(TABLE_MAIN_COURSE); |
|
250
|
|
|
$session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
251
|
|
|
$session = Database::get_main_table(TABLE_MAIN_SESSION); |
|
252
|
|
|
|
|
253
|
|
|
$sql = "SELECT |
|
254
|
|
|
c.code AS col0, |
|
255
|
|
|
c.title AS col1, |
|
256
|
|
|
c.code AS col2, |
|
257
|
|
|
c.course_language AS col3, |
|
258
|
|
|
c.category_code AS col4, |
|
259
|
|
|
c.subscribe AS col5, |
|
260
|
|
|
c.unsubscribe AS col6, |
|
261
|
|
|
c.code AS col7, |
|
262
|
|
|
c.visibility AS col8, |
|
263
|
|
|
c.directory as col9, |
|
264
|
|
|
c.visual_code |
|
265
|
|
|
FROM $course_table c |
|
266
|
|
|
INNER JOIN $session_rel_course r |
|
267
|
|
|
ON c.id = r.c_id |
|
268
|
|
|
INNER JOIN $session s |
|
269
|
|
|
ON r.session_id = s.id |
|
270
|
|
|
"; |
|
271
|
|
|
|
|
272
|
|
|
if (isset($_GET['session_id']) && !empty($_GET['session_id'])) { |
|
273
|
|
|
$sessionId = (int) $_GET['session_id']; |
|
274
|
|
|
$sql .= " WHERE s.id = ".$sessionId; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
$sql .= " ORDER BY col$column $direction "; |
|
278
|
|
|
$sql .= " LIMIT $from,$number_of_items"; |
|
279
|
|
|
$res = Database::query($sql); |
|
280
|
|
|
|
|
281
|
|
|
$courseUrl = api_get_path(WEB_COURSE_PATH); |
|
282
|
|
|
$courses = []; |
|
283
|
|
|
while ($course = Database::fetch_array($res)) { |
|
284
|
|
|
// Place colour icons in front of courses. |
|
285
|
|
|
$showVisualCode = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null; |
|
286
|
|
|
$course[1] = get_course_visibility_icon($course[8]). |
|
287
|
|
|
'<a href="'.$courseUrl.$course[9].'/index.php">'. |
|
288
|
|
|
$course[1]. |
|
289
|
|
|
'</a> '. |
|
290
|
|
|
$showVisualCode; |
|
291
|
|
|
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); |
|
292
|
|
|
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); |
|
293
|
|
|
$row = [ |
|
294
|
|
|
$course[0], |
|
295
|
|
|
$course[1], |
|
296
|
|
|
$course[2], |
|
297
|
|
|
$course[3], |
|
298
|
|
|
$course[4], |
|
299
|
|
|
$course[5], |
|
300
|
|
|
$course[6], |
|
301
|
|
|
$course[7], |
|
302
|
|
|
]; |
|
303
|
|
|
$courses[] = $row; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
return $courses; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Return an icon representing the visibility of the course. |
|
311
|
|
|
* |
|
312
|
|
|
* @param string $visibility |
|
313
|
|
|
* |
|
314
|
|
|
* @return string |
|
315
|
|
|
*/ |
|
316
|
|
|
function get_course_visibility_icon($visibility) |
|
317
|
|
|
{ |
|
318
|
|
|
$style = 'margin-bottom:0;margin-right:5px;'; |
|
319
|
|
|
switch ($visibility) { |
|
320
|
|
|
case 0: |
|
321
|
|
|
return Display::return_icon( |
|
322
|
|
|
'bullet_red.png', |
|
323
|
|
|
get_lang('CourseVisibilityClosed'), |
|
324
|
|
|
['style' => $style] |
|
325
|
|
|
); |
|
326
|
|
|
break; |
|
|
|
|
|
|
327
|
|
|
case 1: |
|
328
|
|
|
return Display::return_icon( |
|
329
|
|
|
'bullet_orange.png', |
|
330
|
|
|
get_lang('Private'), |
|
331
|
|
|
['style' => $style] |
|
332
|
|
|
); |
|
333
|
|
|
break; |
|
334
|
|
|
case 2: |
|
335
|
|
|
return Display::return_icon( |
|
336
|
|
|
'bullet_green.png', |
|
337
|
|
|
get_lang('OpenToThePlatform'), |
|
338
|
|
|
['style' => $style] |
|
339
|
|
|
); |
|
340
|
|
|
break; |
|
341
|
|
|
case 3: |
|
342
|
|
|
return Display::return_icon( |
|
343
|
|
|
'bullet_blue.png', |
|
344
|
|
|
get_lang('OpenToTheWorld'), |
|
345
|
|
|
['style' => $style] |
|
346
|
|
|
); |
|
347
|
|
|
break; |
|
348
|
|
|
case 4: |
|
349
|
|
|
return Display::return_icon( |
|
350
|
|
|
'bullet_grey.png', |
|
351
|
|
|
get_lang('CourseVisibilityHidden'), |
|
352
|
|
|
['style' => $style] |
|
353
|
|
|
); |
|
354
|
|
|
break; |
|
355
|
|
|
default: |
|
356
|
|
|
return ''; |
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
if (isset($_POST['action'])) { |
|
361
|
|
|
switch ($_POST['action']) { |
|
362
|
|
|
// Delete selected courses |
|
363
|
|
|
case 'delete_courses': |
|
364
|
|
|
if (!empty($_POST['course'])) { |
|
365
|
|
|
$course_codes = $_POST['course']; |
|
366
|
|
|
if (count($course_codes) > 0) { |
|
367
|
|
|
foreach ($course_codes as $course_code) { |
|
368
|
|
|
CourseManager::delete_course($course_code); |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
Display::addFlash(Display::return_message(get_lang('Deleted'))); |
|
373
|
|
|
} |
|
374
|
|
|
break; |
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
$content = ''; |
|
378
|
|
|
$message = ''; |
|
379
|
|
|
$actions = ''; |
|
380
|
|
|
|
|
381
|
|
|
if (isset($_GET['search']) && $_GET['search'] === 'advanced') { |
|
382
|
|
|
// Get all course categories |
|
383
|
|
|
$interbreadcrumb[] = [ |
|
384
|
|
|
'url' => 'index.php', |
|
385
|
|
|
'name' => get_lang('PlatformAdmin'), |
|
386
|
|
|
]; |
|
387
|
|
|
$interbreadcrumb[] = [ |
|
388
|
|
|
'url' => 'course_list.php', |
|
389
|
|
|
'name' => get_lang('CourseList'), |
|
390
|
|
|
]; |
|
391
|
|
|
$tool_name = get_lang('SearchACourse'); |
|
392
|
|
|
$form = new FormValidator('advanced_course_search', 'get'); |
|
393
|
|
|
$form->addElement('header', $tool_name); |
|
394
|
|
|
$form->addText('keyword_code', get_lang('CourseCode'), false); |
|
395
|
|
|
$form->addText('keyword_title', get_lang('Title'), false); |
|
396
|
|
|
|
|
397
|
|
|
// Category code |
|
398
|
|
|
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category'; |
|
399
|
|
|
|
|
400
|
|
|
$form->addElement( |
|
401
|
|
|
'select_ajax', |
|
402
|
|
|
'keyword_category', |
|
403
|
|
|
get_lang('CourseFaculty'), |
|
404
|
|
|
null, |
|
405
|
|
|
[ |
|
406
|
|
|
'url' => $url, |
|
407
|
|
|
] |
|
408
|
|
|
); |
|
409
|
|
|
|
|
410
|
|
|
$el = $form->addSelectLanguage('keyword_language', get_lang('CourseLanguage')); |
|
411
|
|
|
$el->addOption(get_lang('All'), '%'); |
|
412
|
|
|
|
|
413
|
|
|
if ($addTeacherColumn) { |
|
414
|
|
|
$form->addSelectAjax( |
|
415
|
|
|
'course_teachers', |
|
416
|
|
|
get_lang('CourseTeachers'), |
|
417
|
|
|
[0 => get_lang('None')], |
|
418
|
|
|
[ |
|
419
|
|
|
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course', |
|
420
|
|
|
'id' => 'course_teachers', |
|
421
|
|
|
'multiple' => 'multiple', |
|
422
|
|
|
] |
|
423
|
|
|
); |
|
424
|
|
|
$form->addLabel('', '<button id="set_none_teacher" class="btn ">'.get_lang('None').'</button>'); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
$form->addElement('radio', 'keyword_visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD); |
|
428
|
|
|
$form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM); |
|
429
|
|
|
$form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED); |
|
430
|
|
|
$form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED); |
|
431
|
|
|
$form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN); |
|
432
|
|
|
$form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%'); |
|
433
|
|
|
$form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1); |
|
434
|
|
|
$form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0); |
|
435
|
|
|
$form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%'); |
|
436
|
|
|
$form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1); |
|
437
|
|
|
$form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0); |
|
438
|
|
|
$form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%'); |
|
439
|
|
|
$form->addButtonSearch(get_lang('SearchCourse')); |
|
440
|
|
|
$defaults['keyword_language'] = '%'; |
|
441
|
|
|
$defaults['keyword_visibility'] = '%'; |
|
442
|
|
|
$defaults['keyword_subscribe'] = '%'; |
|
443
|
|
|
$defaults['keyword_unsubscribe'] = '%'; |
|
444
|
|
|
$form->setDefaults($defaults); |
|
445
|
|
|
$content .= $form->returnForm(); |
|
446
|
|
|
} else { |
|
447
|
|
|
$interbreadcrumb[] = [ |
|
448
|
|
|
'url' => 'index.php', |
|
449
|
|
|
'name' => get_lang('PlatformAdmin'), |
|
450
|
|
|
]; |
|
451
|
|
|
$tool_name = get_lang('CourseList'); |
|
452
|
|
|
if (isset($_GET['delete_course'])) { |
|
453
|
|
|
$result = CourseManager::delete_course($_GET['delete_course']); |
|
454
|
|
|
if ($result) { |
|
455
|
|
|
Display::addFlash(Display::return_message(get_lang('Deleted'))); |
|
456
|
|
|
} |
|
457
|
|
|
} |
|
458
|
|
|
// Create a search-box |
|
459
|
|
|
$form = new FormValidator( |
|
460
|
|
|
'search_simple', |
|
461
|
|
|
'get', |
|
462
|
|
|
'', |
|
463
|
|
|
'', |
|
464
|
|
|
[], |
|
465
|
|
|
FormValidator::LAYOUT_INLINE |
|
466
|
|
|
); |
|
467
|
|
|
$form->addElement( |
|
468
|
|
|
'text', |
|
469
|
|
|
'keyword', |
|
470
|
|
|
null, |
|
471
|
|
|
['id' => 'course-search-keyword', 'aria-label' => get_lang('SearchCourse')] |
|
472
|
|
|
); |
|
473
|
|
|
$form->addButtonSearch(get_lang('SearchCourse')); |
|
474
|
|
|
$advanced = '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/course_list.php?search=advanced"> |
|
475
|
|
|
<em class="fa fa-search"></em> '. |
|
476
|
|
|
get_lang('AdvancedSearch').'</a>'; |
|
477
|
|
|
|
|
478
|
|
|
// Create a filter by session |
|
479
|
|
|
$sessionFilter = new FormValidator( |
|
480
|
|
|
'course_filter', |
|
481
|
|
|
'get', |
|
482
|
|
|
'', |
|
483
|
|
|
'', |
|
484
|
|
|
[], |
|
485
|
|
|
FormValidator::LAYOUT_INLINE |
|
486
|
|
|
); |
|
487
|
|
|
$url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session'; |
|
488
|
|
|
$sessionSelect = $sessionFilter->addElement( |
|
489
|
|
|
'select_ajax', |
|
490
|
|
|
'session_name', |
|
491
|
|
|
get_lang('SearchCourseBySession'), |
|
492
|
|
|
null, |
|
493
|
|
|
['id' => 'session_name', 'url' => $url] |
|
494
|
|
|
); |
|
495
|
|
|
|
|
496
|
|
|
if (!empty($sessionId)) { |
|
497
|
|
|
$sessionInfo = SessionManager::fetch($sessionId); |
|
498
|
|
|
$sessionSelect->addOption( |
|
499
|
|
|
$sessionInfo['name'], |
|
500
|
|
|
$sessionInfo['id'], |
|
501
|
|
|
['selected' => 'selected'] |
|
502
|
|
|
); |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
$courseListUrl = api_get_self(); |
|
506
|
|
|
$actions1 = Display::url( |
|
507
|
|
|
Display::return_icon( |
|
508
|
|
|
'new_course.png', |
|
509
|
|
|
get_lang('AddCourse'), |
|
510
|
|
|
[], |
|
511
|
|
|
ICON_SIZE_MEDIUM |
|
512
|
|
|
), |
|
513
|
|
|
api_get_path(WEB_CODE_PATH).'admin/course_add.php' |
|
514
|
|
|
); |
|
515
|
|
|
|
|
516
|
|
|
if (api_get_setting('course_validation') === 'true') { |
|
517
|
|
|
$actions1 .= Display::url( |
|
518
|
|
|
Display::return_icon( |
|
519
|
|
|
'course_request_pending.png', |
|
520
|
|
|
get_lang('ReviewCourseRequests'), |
|
521
|
|
|
[], |
|
522
|
|
|
ICON_SIZE_MEDIUM |
|
523
|
|
|
), |
|
524
|
|
|
api_get_path(WEB_CODE_PATH).'admin/course_request_review.php' |
|
525
|
|
|
); |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
$actions2 = $form->returnForm(); |
|
529
|
|
|
$actions3 = $sessionFilter->returnForm(); |
|
530
|
|
|
$actions4 = $advanced; |
|
531
|
|
|
$actions4 .= ' |
|
532
|
|
|
<script> |
|
533
|
|
|
$(function() { |
|
534
|
|
|
$("#session_name").on("change", function() { |
|
535
|
|
|
var sessionId = $(this).val(); |
|
536
|
|
|
if (!sessionId) { |
|
537
|
|
|
return; |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
window.location = "'.$courseListUrl.'?session_id="+sessionId; |
|
541
|
|
|
}); |
|
542
|
|
|
}); |
|
543
|
|
|
</script>'; |
|
544
|
|
|
|
|
545
|
|
|
$actions = Display::toolbarAction( |
|
546
|
|
|
'toolbar', |
|
547
|
|
|
[$actions1, $actions2, $actions3, $actions4], |
|
548
|
|
|
[2, 4, 3, 3] |
|
549
|
|
|
); |
|
550
|
|
|
|
|
551
|
|
|
if (!empty($sessionId)) { |
|
552
|
|
|
// Create a sortable table with the course data filtered by session |
|
553
|
|
|
$table = new SortableTable( |
|
554
|
|
|
'courses', |
|
555
|
|
|
'get_number_of_courses', |
|
556
|
|
|
'get_course_data_by_session', |
|
557
|
|
|
2 |
|
558
|
|
|
); |
|
559
|
|
|
} else { |
|
560
|
|
|
// Create a sortable table with the course data |
|
561
|
|
|
$table = new SortableTable( |
|
562
|
|
|
'courses', |
|
563
|
|
|
'get_number_of_courses', |
|
564
|
|
|
'get_course_data', |
|
565
|
|
|
2, |
|
566
|
|
|
20, |
|
567
|
|
|
'ASC', |
|
568
|
|
|
'course-list' |
|
569
|
|
|
); |
|
570
|
|
|
} |
|
571
|
|
|
|
|
572
|
|
|
$parameters = []; |
|
573
|
|
|
if (isset($_GET['keyword'])) { |
|
574
|
|
|
$parameters = ['keyword' => Security::remove_XSS($_GET['keyword'])]; |
|
575
|
|
|
} elseif (isset($_GET['keyword_code'])) { |
|
576
|
|
|
$parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']); |
|
577
|
|
|
$parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']); |
|
578
|
|
|
if (isset($_GET['keyword_category'])) { |
|
579
|
|
|
$parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']); |
|
580
|
|
|
} |
|
581
|
|
|
$parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']); |
|
582
|
|
|
$parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']); |
|
583
|
|
|
$parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']); |
|
584
|
|
|
$parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']); |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
if (isset($_GET['course_teachers'])) { |
|
588
|
|
|
$parsed = array_map('intval', $_GET['course_teachers']); |
|
589
|
|
|
$parameters["course_teachers"] = ''; |
|
590
|
|
|
foreach ($parsed as $key=>$teacherId) { |
|
591
|
|
|
$parameters["course_teachers[$key]"] = $teacherId; |
|
592
|
|
|
} |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
$table->set_additional_parameters($parameters); |
|
596
|
|
|
$column = 0; |
|
597
|
|
|
$table->set_header($column++, '', false, 'width="8px"'); |
|
598
|
|
|
$table->set_header($column++, get_lang('Title'), true, null, ['class' => 'title']); |
|
599
|
|
|
$table->set_header($column++, get_lang('Code')); |
|
600
|
|
|
$table->set_header($column++, get_lang('Language'), false, 'width="70px"'); |
|
601
|
|
|
$table->set_header($column++, get_lang('Category')); |
|
602
|
|
|
$table->set_header($column++, get_lang('SubscriptionAllowed'), true, 'width="60px"'); |
|
603
|
|
|
$table->set_header($column++, get_lang('UnsubscriptionAllowed'), false, 'width="50px"'); |
|
604
|
|
|
if ($addTeacherColumn) { |
|
605
|
|
|
$table->set_header($column++, get_lang('Teachers'), true); |
|
606
|
|
|
} |
|
607
|
|
|
$table->set_header( |
|
608
|
|
|
$column++, |
|
609
|
|
|
get_lang('Action'), |
|
610
|
|
|
false, |
|
611
|
|
|
null, |
|
612
|
|
|
['class' => 'td_actions'] |
|
613
|
|
|
); |
|
614
|
|
|
$table->set_form_actions( |
|
615
|
|
|
['delete_courses' => get_lang('DeleteCourse')], |
|
616
|
|
|
'course' |
|
617
|
|
|
); |
|
618
|
|
|
$content .= $table->return_table(); |
|
619
|
|
|
} |
|
620
|
|
|
|
|
621
|
|
|
$htmlHeadXtra[] = ' |
|
622
|
|
|
<script> |
|
623
|
|
|
$(function() { |
|
624
|
|
|
$("#set_none_teacher").on("click", function () { |
|
625
|
|
|
$("#course_teachers").val("0").trigger("change"); |
|
626
|
|
|
|
|
627
|
|
|
return false; |
|
628
|
|
|
}); |
|
629
|
|
|
}); |
|
630
|
|
|
</script>'; |
|
631
|
|
|
|
|
632
|
|
|
$tpl = new Template($tool_name); |
|
633
|
|
|
$tpl->assign('actions', $actions); |
|
634
|
|
|
$tpl->assign('message', $message); |
|
635
|
|
|
$tpl->assign('content', $content); |
|
636
|
|
|
$tpl->display_one_col_template(); |
|
637
|
|
|
|
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.