1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class UrlManager |
6
|
|
|
* This library provides functions for the access_url management. |
7
|
|
|
* Include/require it in your code to use its functionality. |
8
|
|
|
* |
9
|
|
|
* @package chamilo.library |
10
|
|
|
*/ |
11
|
|
|
class UrlManager |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Creates a new url access |
15
|
|
|
* |
16
|
|
|
* @author Julio Montoya <[email protected]>, |
17
|
|
|
* |
18
|
|
|
* @param string $url The URL of the site |
19
|
|
|
* @param string $description The description of the site |
20
|
|
|
* @param int $active is active or not |
21
|
|
|
* @return boolean if success |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
public static function add($url, $description, $active) |
24
|
|
|
{ |
25
|
|
|
$tms = time(); |
26
|
|
|
$table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
27
|
|
|
$sql = "INSERT INTO $table |
28
|
|
|
SET url = '".Database::escape_string($url)."', |
29
|
|
|
description = '".Database::escape_string($description)."', |
30
|
|
|
active = '".intval($active)."', |
31
|
|
|
created_by = '".api_get_user_id()."', |
32
|
|
|
tms = FROM_UNIXTIME(".$tms.")"; |
33
|
|
|
$result = Database::query($sql); |
34
|
|
|
|
35
|
|
|
return $result; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Updates an URL access |
40
|
|
|
* @author Julio Montoya <[email protected]>, |
41
|
|
|
* |
42
|
|
|
* @param int $url_id The url id |
43
|
|
|
* @param string $url |
44
|
|
|
* @param string $description The description of the site |
45
|
|
|
* @param int $active is active or not |
46
|
|
|
* @return boolean if success |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public static function update($url_id, $url, $description, $active) |
49
|
|
|
{ |
50
|
|
|
$url_id = intval($url_id); |
51
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
52
|
|
|
$sql = "UPDATE $table |
53
|
|
|
SET url = '".Database::escape_string($url)."', |
54
|
|
|
description = '".Database::escape_string($description)."', |
55
|
|
|
active = '".intval($active)."', |
56
|
|
|
created_by = '".api_get_user_id()."', |
57
|
|
|
tms = '".api_get_utc_datetime()."' |
58
|
|
|
WHERE id = '$url_id'"; |
59
|
|
|
|
60
|
|
|
$result = Database::query($sql); |
61
|
|
|
|
62
|
|
|
return $result; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Deletes an url |
67
|
|
|
* @author Julio Montoya |
68
|
|
|
* @param int $id url id |
69
|
|
|
* |
70
|
|
|
* @return boolean true if success |
71
|
|
|
* */ |
72
|
|
|
public static function delete($id) |
73
|
|
|
{ |
74
|
|
|
$id = intval($id); |
75
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
76
|
|
|
$tableUser = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
77
|
|
|
$tableCourse = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
78
|
|
|
$tableSession = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
79
|
|
|
$tableCourseCategory = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); |
80
|
|
|
$tableGroup = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
81
|
|
|
|
82
|
|
|
$sql = "DELETE FROM $tableCourse WHERE access_url_id = ".$id; |
83
|
|
|
$result = Database::query($sql); |
84
|
|
|
/* |
85
|
|
|
$sql = "DELETE FROM $tableCourseCategory WHERE access_url_id = ".$id; |
86
|
|
|
$result = Database::query($sql); |
87
|
|
|
*/ |
88
|
|
|
$sql = "DELETE FROM $tableSession WHERE access_url_id = ".$id; |
89
|
|
|
$result = Database::query($sql); |
90
|
|
|
$sql = "DELETE FROM $tableGroup WHERE access_url_id = ".$id; |
91
|
|
|
$result = Database::query($sql); |
92
|
|
|
$sql = "DELETE FROM $tableUser WHERE access_url_id = ".$id; |
93
|
|
|
$result = Database::query($sql); |
94
|
|
|
|
95
|
|
|
$sql= "DELETE FROM $table WHERE id = ".$id; |
96
|
|
|
$result = Database::query($sql); |
97
|
|
|
|
98
|
|
|
return $result; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $url |
103
|
|
|
* |
104
|
|
|
* @return int |
105
|
|
|
*/ |
106
|
|
|
public static function url_exist($url) |
107
|
|
|
{ |
108
|
|
|
$table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
109
|
|
|
$sql = "SELECT id FROM $table |
110
|
|
|
WHERE url = '".Database::escape_string($url)."' "; |
111
|
|
|
$res = Database::query($sql); |
112
|
|
|
$num = Database::num_rows($res); |
113
|
|
|
|
114
|
|
|
return $num; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $url |
119
|
|
|
* |
120
|
|
|
* @return int |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
public static function url_id_exist($url) |
123
|
|
|
{ |
124
|
|
|
if (empty($url)) { |
125
|
|
|
return false; |
126
|
|
|
} |
127
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
128
|
|
|
$sql = "SELECT id FROM $table WHERE id = ".intval($url).""; |
129
|
|
|
$res = Database::query($sql); |
130
|
|
|
$num = Database::num_rows($res); |
131
|
|
|
|
132
|
|
|
return $num; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* This function get the quantity of URLs |
137
|
|
|
* @author Julio Montoya |
138
|
|
|
* @return int count of urls |
139
|
|
|
* */ |
140
|
|
View Code Duplication |
public static function url_count() |
141
|
|
|
{ |
142
|
|
|
$table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
143
|
|
|
$sql = "SELECT count(id) as count_result FROM $table_access_url"; |
144
|
|
|
$res = Database::query($sql); |
145
|
|
|
$url = Database::fetch_array($res,'ASSOC'); |
146
|
|
|
$result = $url['count_result']; |
147
|
|
|
|
148
|
|
|
return $result; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Gets the id, url, description, and active status of ALL URLs |
153
|
|
|
* @author Julio Montoya |
154
|
|
|
* @return array |
155
|
|
|
* */ |
156
|
|
|
public static function get_url_data() |
157
|
|
|
{ |
158
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
159
|
|
|
$sql = "SELECT id, url, description, active |
160
|
|
|
FROM $table |
161
|
|
|
ORDER BY id"; |
162
|
|
|
$res = Database::query($sql); |
163
|
|
|
$urls = array (); |
164
|
|
|
while ($url = Database::fetch_array($res)) { |
165
|
|
|
$urls[] = $url; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $urls; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Gets the id, url, description, and active status of ALL URLs |
173
|
|
|
* @author Julio Montoya |
174
|
|
|
* @param int $url_id |
175
|
|
|
* @return array |
176
|
|
|
* */ |
177
|
|
View Code Duplication |
public static function get_url_data_from_id($url_id) |
178
|
|
|
{ |
179
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
180
|
|
|
$sql = "SELECT id, url, description, active |
181
|
|
|
FROM $table |
182
|
|
|
WHERE id = ".intval($url_id); |
183
|
|
|
$res = Database::query($sql); |
184
|
|
|
$row = Database::fetch_array($res); |
185
|
|
|
|
186
|
|
|
return $row; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Gets the inner join of users and urls table |
191
|
|
|
* @author Julio Montoya |
192
|
|
|
* @param int access url id |
193
|
|
|
* @param string $order_by |
194
|
|
|
* @return array Database::store_result of the result |
195
|
|
|
**/ |
196
|
|
|
public static function get_url_rel_user_data($access_url_id = null, $order_by = null) |
197
|
|
|
{ |
198
|
|
|
$where = ''; |
199
|
|
|
$table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
200
|
|
|
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
201
|
|
|
if (!empty($access_url_id)) { |
202
|
|
|
$where = "WHERE $table_url_rel_user.access_url_id = ".intval($access_url_id); |
203
|
|
|
} |
204
|
|
|
if (empty($order_by)) { |
205
|
|
|
$order_clause = api_sort_by_first_name( |
206
|
|
|
) ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; |
207
|
|
|
} else { |
208
|
|
|
$order_clause = $order_by; |
209
|
|
|
} |
210
|
|
|
$sql = "SELECT u.user_id, lastname, firstname, username, official_code, access_url_id |
211
|
|
|
FROM $tbl_user u |
212
|
|
|
INNER JOIN $table_url_rel_user |
213
|
|
|
ON $table_url_rel_user.user_id = u.user_id |
214
|
|
|
$where $order_clause"; |
215
|
|
|
$result = Database::query($sql); |
216
|
|
|
$users = Database::store_result($result); |
217
|
|
|
|
218
|
|
|
return $users; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Gets the inner join of access_url and the course table |
223
|
|
|
* |
224
|
|
|
* @author Julio Montoya |
225
|
|
|
* @param int access url id |
226
|
|
|
* @return array Database::store_result of the result |
227
|
|
|
**/ |
228
|
|
|
public static function get_url_rel_course_data($access_url_id = null) |
229
|
|
|
{ |
230
|
|
|
$where = ''; |
231
|
|
|
$table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
232
|
|
|
$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); |
233
|
|
|
|
234
|
|
|
if (!empty($access_url_id)) { |
235
|
|
|
$where = " WHERE uc.access_url_id = ".intval($access_url_id); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$sql = "SELECT u.id, c_id, title, uc.access_url_id |
239
|
|
|
FROM $tbl_course u |
240
|
|
|
INNER JOIN $table_url_rel_course uc |
241
|
|
|
ON uc.c_id = u.id |
242
|
|
|
$where |
243
|
|
|
ORDER BY title, code"; |
244
|
|
|
|
245
|
|
|
$result = Database::query($sql); |
246
|
|
|
$courses = Database::store_result($result); |
247
|
|
|
|
248
|
|
|
return $courses; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Gets the number of rows with a specific course_code in access_url_rel_course table |
253
|
|
|
* @author Yoselyn Castillo |
254
|
|
|
* @param int $courseId |
255
|
|
|
* |
256
|
|
|
* @return int Database::num_rows($res); |
257
|
|
|
**/ |
258
|
|
View Code Duplication |
public static function getCountUrlRelCourse($courseId) |
259
|
|
|
{ |
260
|
|
|
$courseId = intval($courseId); |
261
|
|
|
$tableUrlRelCourse = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
262
|
|
|
$sql = "SELECT * |
263
|
|
|
FROM $tableUrlRelCourse |
264
|
|
|
WHERE c_id = '$courseId'"; |
265
|
|
|
$res = Database::query($sql); |
266
|
|
|
|
267
|
|
|
return Database::num_rows($res); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Gets the inner join of access_url and the session table |
272
|
|
|
* @author Julio Montoya |
273
|
|
|
* @param int $access_url_id access url id |
274
|
|
|
* |
275
|
|
|
* @return array Database::store_result of the result |
276
|
|
|
* |
277
|
|
|
**/ |
278
|
|
|
public static function get_url_rel_session_data($access_url_id = null) |
279
|
|
|
{ |
280
|
|
|
$where =''; |
281
|
|
|
$table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
282
|
|
|
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); |
283
|
|
|
|
284
|
|
|
if (!empty($access_url_id)) |
285
|
|
|
$where ="WHERE $table_url_rel_session.access_url_id = ".intval($access_url_id); |
286
|
|
|
|
287
|
|
|
$sql = "SELECT id, name, access_url_id |
288
|
|
|
FROM $tbl_session u |
289
|
|
|
INNER JOIN $table_url_rel_session |
290
|
|
|
ON $table_url_rel_session.session_id = id |
291
|
|
|
$where |
292
|
|
|
ORDER BY name, id"; |
293
|
|
|
|
294
|
|
|
$result = Database::query($sql); |
295
|
|
|
$sessions = Database::store_result($result); |
296
|
|
|
|
297
|
|
|
return $sessions; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Gets the inner join of access_url and the usergroup table |
302
|
|
|
* |
303
|
|
|
* @author Julio Montoya |
304
|
|
|
* @param int $access_url_id |
305
|
|
|
* |
306
|
|
|
* @return array Database::store_result of the result |
307
|
|
|
**/ |
308
|
|
|
public static function get_url_rel_usergroup_data($access_url_id = null) |
309
|
|
|
{ |
310
|
|
|
$where = ''; |
311
|
|
|
$table_url_rel_usergroup = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
312
|
|
|
$table_user_group = Database::get_main_table(TABLE_USERGROUP); |
313
|
|
|
|
314
|
|
|
if (!empty($access_url_id)) { |
315
|
|
|
$where ="WHERE $table_url_rel_usergroup.access_url_id = ".intval($access_url_id); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
$sql = "SELECT id, name, access_url_id |
319
|
|
|
FROM $table_user_group u |
320
|
|
|
INNER JOIN $table_url_rel_usergroup |
321
|
|
|
ON $table_url_rel_usergroup.usergroup_id = u.id |
322
|
|
|
$where |
323
|
|
|
ORDER BY name"; |
324
|
|
|
|
325
|
|
|
$result = Database::query($sql); |
326
|
|
|
$courses = Database::store_result($result); |
327
|
|
|
|
328
|
|
|
return $courses; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Gets the inner join of access_url and the usergroup table |
333
|
|
|
* |
334
|
|
|
* @author Julio Montoya |
335
|
|
|
* @param int $access_url_id |
336
|
|
|
* @return array Database::store_result of the result |
337
|
|
|
**/ |
338
|
|
|
public static function getUrlRelCourseCategory($access_url_id = null) |
339
|
|
|
{ |
340
|
|
|
$table_url_rel = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); |
341
|
|
|
$table = Database::get_main_table(TABLE_MAIN_CATEGORY); |
342
|
|
|
$where = " WHERE 1=1 "; |
343
|
|
|
if (!empty($access_url_id)) { |
344
|
|
|
$where .= " AND $table_url_rel.access_url_id = ".intval($access_url_id); |
345
|
|
|
} |
346
|
|
|
$where .= " AND (parent_id IS NULL) "; |
347
|
|
|
|
348
|
|
|
$sql = "SELECT id, name, access_url_id |
349
|
|
|
FROM $table u |
350
|
|
|
INNER JOIN $table_url_rel |
351
|
|
|
ON $table_url_rel.course_category_id = u.id |
352
|
|
|
$where |
353
|
|
|
ORDER BY name"; |
354
|
|
|
|
355
|
|
|
$result = Database::query($sql); |
356
|
|
|
$courses = Database::store_result($result, 'ASSOC'); |
357
|
|
|
|
358
|
|
|
return $courses; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* Sets the status of an URL 1 or 0 |
363
|
|
|
* @author Julio Montoya |
364
|
|
|
* @param string lock || unlock |
365
|
|
|
* @param int url id |
366
|
|
|
* */ |
367
|
|
|
public static function set_url_status($status, $url_id) |
368
|
|
|
{ |
369
|
|
|
$url_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
370
|
|
|
if ($status == 'lock') { |
371
|
|
|
$status_db = '0'; |
372
|
|
|
} |
373
|
|
|
if ($status == 'unlock') { |
374
|
|
|
$status_db = '1'; |
375
|
|
|
} |
376
|
|
View Code Duplication |
if (($status_db == '1' || $status_db == '0') && is_numeric($url_id)) { |
377
|
|
|
$sql = "UPDATE $url_table SET active='".intval($status_db)."' |
378
|
|
|
WHERE id='".intval($url_id)."'"; |
379
|
|
|
Database::query($sql); |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Checks the relationship between an URL and a User (return the num_rows) |
385
|
|
|
* @author Julio Montoya |
386
|
|
|
* @param int user id |
387
|
|
|
* @param int url id |
388
|
|
|
* @return boolean true if success |
389
|
|
|
* */ |
390
|
|
|
public static function relation_url_user_exist($user_id, $url_id) |
391
|
|
|
{ |
392
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
393
|
|
|
$sql= "SELECT user_id FROM $table |
394
|
|
|
WHERE access_url_id = ".intval($url_id)." AND user_id = ".intval($user_id)." "; |
395
|
|
|
$result = Database::query($sql); |
396
|
|
|
$num = Database::num_rows($result); |
397
|
|
|
|
398
|
|
|
return $num; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Checks the relationship between an URL and a Course (return the num_rows) |
403
|
|
|
* @author Julio Montoya |
404
|
|
|
* @param int $courseId |
405
|
|
|
* @param int $urlId |
406
|
|
|
* @return boolean true if success |
407
|
|
|
* */ |
408
|
|
|
public static function relation_url_course_exist($courseId, $urlId) |
409
|
|
|
{ |
410
|
|
|
$table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
411
|
|
|
$sql= "SELECT c_id FROM $table_url_rel_course |
412
|
|
|
WHERE |
413
|
|
|
access_url_id = ".intval($urlId)." AND |
414
|
|
|
c_id = '".intval($courseId)."'"; |
415
|
|
|
$result = Database::query($sql); |
416
|
|
|
$num = Database::num_rows($result); |
417
|
|
|
|
418
|
|
|
return $num; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Checks the relationship between an URL and a UserGr |
423
|
|
|
* oup (return the num_rows) |
424
|
|
|
* @author Julio Montoya |
425
|
|
|
* @param int $userGroupId |
426
|
|
|
* @param int $urlId |
427
|
|
|
* @return boolean true if success |
428
|
|
|
* */ |
429
|
|
View Code Duplication |
public static function relationUrlUsergroupExist($userGroupId, $urlId) |
430
|
|
|
{ |
431
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
432
|
|
|
$sql= "SELECT usergroup_id FROM $table |
433
|
|
|
WHERE access_url_id = ".intval($urlId)." AND |
434
|
|
|
usergroup_id = ".intval($userGroupId); |
435
|
|
|
$result = Database::query($sql); |
436
|
|
|
$num = Database::num_rows($result); |
437
|
|
|
|
438
|
|
|
return $num; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Checks the relationship between an URL and a Session (return the num_rows) |
443
|
|
|
* @author Julio Montoya |
444
|
|
|
* @param int user id |
445
|
|
|
* @param int url id |
446
|
|
|
* @return boolean true if success |
447
|
|
|
* */ |
448
|
|
View Code Duplication |
public static function relation_url_session_exist($session_id, $url_id) |
449
|
|
|
{ |
450
|
|
|
$table_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
451
|
|
|
$session_id = intval($session_id); |
452
|
|
|
$url_id = intval($url_id); |
453
|
|
|
$sql = "SELECT session_id FROM $table_url_rel_session |
454
|
|
|
WHERE |
455
|
|
|
access_url_id = ".intval($url_id)." AND |
456
|
|
|
session_id = ".Database::escape_string($session_id); |
457
|
|
|
$result = Database::query($sql); |
458
|
|
|
$num = Database::num_rows($result); |
459
|
|
|
|
460
|
|
|
return $num; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Add a group of users into a group of URLs |
465
|
|
|
* @author Julio Montoya |
466
|
|
|
* @param array of user_ids |
467
|
|
|
* @param array of url_ids |
468
|
|
|
* @return array |
469
|
|
|
* */ |
470
|
|
View Code Duplication |
public static function add_users_to_urls($user_list, $url_list) |
471
|
|
|
{ |
472
|
|
|
$table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
473
|
|
|
$result_array = array(); |
474
|
|
|
|
475
|
|
|
if (is_array($user_list) && is_array($url_list)){ |
476
|
|
|
foreach ($url_list as $url_id) { |
477
|
|
|
foreach ($user_list as $user_id) { |
478
|
|
|
$count = UrlManager::relation_url_user_exist($user_id,$url_id); |
479
|
|
|
if ($count==0) { |
480
|
|
|
$sql = "INSERT INTO $table_url_rel_user |
481
|
|
|
SET user_id = ".intval($user_id).", access_url_id = ".intval($url_id); |
482
|
|
|
$result = Database::query($sql); |
483
|
|
|
if ($result) { |
484
|
|
|
$result_array[$url_id][$user_id] = 1; |
485
|
|
|
} else { |
486
|
|
|
$result_array[$url_id][$user_id] = 0; |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
return $result_array; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Add a group of courses into a group of URLs |
499
|
|
|
* @author Julio Montoya |
500
|
|
|
* @param array of course ids |
501
|
|
|
* @param array of url_ids |
502
|
|
|
* @return array |
503
|
|
|
**/ |
504
|
|
|
public static function add_courses_to_urls($course_list,$url_list) |
505
|
|
|
{ |
506
|
|
|
$table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
507
|
|
|
$result_array = array(); |
508
|
|
|
|
509
|
|
|
if (is_array($course_list) && is_array($url_list)){ |
510
|
|
|
foreach ($url_list as $url_id) { |
511
|
|
|
foreach ($course_list as $course_code) { |
512
|
|
|
$courseInfo = api_get_course_info($course_code); |
513
|
|
|
$courseId = $courseInfo['real_id']; |
514
|
|
|
|
515
|
|
|
$count = self::relation_url_course_exist($courseId, $url_id); |
516
|
|
|
if ($count==0) { |
517
|
|
|
$sql = "INSERT INTO $table_url_rel_course |
518
|
|
|
SET c_id = '".$courseId."', access_url_id = ".intval($url_id); |
519
|
|
|
$result = Database::query($sql); |
520
|
|
|
if ($result) { |
521
|
|
|
$result_array[$url_id][$course_code] = 1; |
522
|
|
|
} else { |
523
|
|
|
$result_array[$url_id][$course_code] = 0; |
524
|
|
|
} |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
return $result_array; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Add a group of user group into a group of URLs |
535
|
|
|
* @author Julio Montoya |
536
|
|
|
* @param array $userGroupList of course ids |
537
|
|
|
* @param array $urlList of url_ids |
538
|
|
|
* @return array |
539
|
|
|
**/ |
540
|
|
View Code Duplication |
public static function addUserGroupListToUrl($userGroupList, $urlList) |
541
|
|
|
{ |
542
|
|
|
$resultArray = array(); |
543
|
|
|
if (is_array($userGroupList) && is_array($urlList)) { |
544
|
|
|
foreach ($urlList as $urlId) { |
545
|
|
|
foreach ($userGroupList as $userGroupId) { |
546
|
|
|
$count = self::relationUrlUsergroupExist($userGroupId, $urlId); |
547
|
|
|
if ($count == 0) { |
548
|
|
|
$result = self::addUserGroupToUrl($userGroupId, $urlId); |
549
|
|
|
if ($result) { |
550
|
|
|
$resultArray[$urlId][$userGroupId] = 1; |
551
|
|
|
} else { |
552
|
|
|
$resultArray[$urlId][$userGroupId] = 0; |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
return $resultArray; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* Add a group of user group into a group of URLs |
564
|
|
|
* @author Julio Montoya |
565
|
|
|
* @param array of course ids |
566
|
|
|
* @param array of url_ids |
567
|
|
|
* @return array |
568
|
|
|
**/ |
569
|
|
View Code Duplication |
public static function addCourseCategoryListToUrl($courseCategoryList, $urlList) |
570
|
|
|
{ |
571
|
|
|
$resultArray = array(); |
572
|
|
|
if (is_array($courseCategoryList) && is_array($urlList)) { |
573
|
|
|
foreach ($urlList as $urlId) { |
574
|
|
|
foreach ($courseCategoryList as $categoryCourseId) { |
575
|
|
|
$count = self::relationUrlCourseCategoryExist($categoryCourseId, $urlId); |
576
|
|
|
if ($count == 0) { |
577
|
|
|
$result = self::addCourseCategoryToUrl($categoryCourseId, $urlId); |
578
|
|
|
if ($result) { |
579
|
|
|
$resultArray[$urlId][$categoryCourseId] = 1; |
580
|
|
|
} else { |
581
|
|
|
$resultArray[$urlId][$categoryCourseId] = 0; |
582
|
|
|
} |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
return $resultArray; |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* Checks the relationship between an URL and a UserGr |
593
|
|
|
* oup (return the num_rows) |
594
|
|
|
* @author Julio Montoya |
595
|
|
|
* @param int $categoryCourseId |
596
|
|
|
* @param int $urlId |
597
|
|
|
* @return boolean true if success |
598
|
|
|
* */ |
599
|
|
View Code Duplication |
public static function relationUrlCourseCategoryExist($categoryCourseId, $urlId) |
600
|
|
|
{ |
601
|
|
|
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); |
602
|
|
|
$sql= "SELECT course_category_id FROM $table |
603
|
|
|
WHERE access_url_id = ".intval($urlId)." AND |
604
|
|
|
course_category_id = ".intval($categoryCourseId); |
605
|
|
|
$result = Database::query($sql); |
606
|
|
|
$num = Database::num_rows($result); |
607
|
|
|
|
608
|
|
|
return $num; |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* @param int $userGroupId |
613
|
|
|
* @param int $urlId |
614
|
|
|
* @return int |
615
|
|
|
*/ |
616
|
|
|
public static function addUserGroupToUrl($userGroupId, $urlId) |
617
|
|
|
{ |
618
|
|
|
$urlRelUserGroupTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
619
|
|
|
$sql = "INSERT INTO $urlRelUserGroupTable |
620
|
|
|
SET |
621
|
|
|
usergroup_id = '".intval($userGroupId)."', |
622
|
|
|
access_url_id = ".intval($urlId); |
623
|
|
|
Database::query($sql); |
624
|
|
|
return Database::insert_id(); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @param int $categoryId |
629
|
|
|
* @param int $urlId |
630
|
|
|
* @return int |
631
|
|
|
*/ |
632
|
|
|
public static function addCourseCategoryToUrl($categoryId, $urlId) |
633
|
|
|
{ |
634
|
|
|
$exists = self::relationUrlCourseCategoryExist($categoryId, $urlId); |
635
|
|
|
if (empty($exists)) { |
636
|
|
|
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); |
637
|
|
|
|
638
|
|
|
$sql = "INSERT INTO $table |
639
|
|
|
SET |
640
|
|
|
course_category_id = '".intval($categoryId)."', |
641
|
|
|
access_url_id = ".intval($urlId); |
642
|
|
|
Database::query($sql); |
643
|
|
|
|
644
|
|
|
return Database::insert_id(); |
645
|
|
|
} |
646
|
|
|
return 0; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Add a group of sessions into a group of URLs |
651
|
|
|
* @author Julio Montoya |
652
|
|
|
* @param array of session ids |
653
|
|
|
* @param array of url_ids |
654
|
|
|
* @return array |
655
|
|
|
* */ |
656
|
|
View Code Duplication |
public static function add_sessions_to_urls($session_list, $url_list) |
657
|
|
|
{ |
658
|
|
|
$table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
659
|
|
|
$result_array = array(); |
660
|
|
|
|
661
|
|
|
if (is_array($session_list) && is_array($url_list)) { |
662
|
|
|
foreach ($url_list as $url_id) { |
663
|
|
|
foreach ($session_list as $session_id) { |
664
|
|
|
$count = UrlManager::relation_url_session_exist($session_id, $url_id); |
665
|
|
|
|
666
|
|
|
if ($count == 0) { |
667
|
|
|
$sql = "INSERT INTO $table_url_rel_session |
668
|
|
|
SET |
669
|
|
|
session_id = ".intval($session_id).", |
670
|
|
|
access_url_id = ".intval($url_id); |
671
|
|
|
$result = Database::query($sql); |
672
|
|
|
if ($result) { |
673
|
|
|
$result_array[$url_id][$session_id] = 1; |
674
|
|
|
} else { |
675
|
|
|
$result_array[$url_id][$session_id] = 0; |
676
|
|
|
} |
677
|
|
|
} |
678
|
|
|
} |
679
|
|
|
} |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
return $result_array; |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* Add a user into a url |
687
|
|
|
* @author Julio Montoya |
688
|
|
|
* @param $user_id |
689
|
|
|
* @param $url_id |
690
|
|
|
* |
691
|
|
|
* @return boolean true if success |
692
|
|
|
* */ |
693
|
|
|
public static function add_user_to_url($user_id, $url_id = 1) |
694
|
|
|
{ |
695
|
|
|
$table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
696
|
|
|
if (empty($url_id)) { |
697
|
|
|
$url_id = 1; |
698
|
|
|
} |
699
|
|
|
$count = UrlManager::relation_url_user_exist($user_id, $url_id); |
700
|
|
|
$result = true; |
701
|
|
|
if (empty($count)) { |
702
|
|
|
$sql = "INSERT INTO $table_url_rel_user (user_id, access_url_id) |
703
|
|
|
VALUES ('".intval($user_id)."', '".intval($url_id)."') "; |
704
|
|
|
$result = Database::query($sql); |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
return $result; |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
/** |
711
|
|
|
* @param int $courseId |
712
|
|
|
* @param int $url_id |
713
|
|
|
* |
714
|
|
|
* @return resource |
715
|
|
|
*/ |
716
|
|
|
public static function add_course_to_url($courseId, $url_id = 1) |
717
|
|
|
{ |
718
|
|
|
$table_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
719
|
|
|
if (empty($url_id)) { |
720
|
|
|
$url_id = 1; |
721
|
|
|
} |
722
|
|
|
$count = UrlManager::relation_url_course_exist($courseId, $url_id); |
723
|
|
|
if (empty($count)) { |
724
|
|
|
$sql = "INSERT INTO $table_url_rel_course |
725
|
|
|
SET c_id = '".intval($courseId)."', access_url_id = ".intval($url_id); |
726
|
|
|
Database::query($sql); |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
return true; |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* Inserts a session to a URL (access_url_rel_session table) |
734
|
|
|
* @param int Session ID |
735
|
|
|
* @param int URL ID |
736
|
|
|
* |
737
|
|
|
* @return bool True on success, false session already exists or insert failed |
738
|
|
|
*/ |
739
|
|
|
public static function add_session_to_url($session_id, $url_id = 1) |
740
|
|
|
{ |
741
|
|
|
$table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
742
|
|
|
if (empty($url_id)) { |
743
|
|
|
$url_id = 1; |
744
|
|
|
} |
745
|
|
|
$result = false; |
746
|
|
|
$count = UrlManager::relation_url_session_exist($session_id, $url_id); |
747
|
|
|
$session_id = intval($session_id); |
748
|
|
View Code Duplication |
if (empty($count) && !empty($session_id)) { |
749
|
|
|
$url_id = intval($url_id); |
750
|
|
|
$sql = "INSERT INTO $table_url_rel_session |
751
|
|
|
SET session_id = ".intval($session_id).", access_url_id = ".intval($url_id); |
752
|
|
|
$result = Database::query($sql); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
return $result; |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
/** |
759
|
|
|
* Deletes an url and user relationship |
760
|
|
|
* @author Julio Montoya |
761
|
|
|
* @param int user id |
762
|
|
|
* @param int url id |
763
|
|
|
* |
764
|
|
|
* @return boolean true if success |
765
|
|
|
* */ |
766
|
|
|
public static function delete_url_rel_user($user_id, $url_id) |
767
|
|
|
{ |
768
|
|
|
$table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
769
|
|
|
$result = true; |
770
|
|
View Code Duplication |
if (!empty($user_id) && !empty($url_id)) { |
771
|
|
|
$sql= "DELETE FROM $table_url_rel_user |
772
|
|
|
WHERE user_id = ".intval($user_id)." AND access_url_id = ".intval($url_id); |
773
|
|
|
$result = Database::query($sql); |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
return $result; |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
/** |
780
|
|
|
* Deletes user from all portals |
781
|
|
|
* @author Julio Montoya |
782
|
|
|
* @param int user id |
783
|
|
|
* |
784
|
|
|
* @return boolean true if success |
785
|
|
|
* */ |
786
|
|
View Code Duplication |
public static function deleteUserFromAllUrls($userId) |
787
|
|
|
{ |
788
|
|
|
$table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
789
|
|
|
$result = true; |
790
|
|
|
if (!empty($userId)) { |
791
|
|
|
$sql= "DELETE FROM $table_url_rel_user |
792
|
|
|
WHERE user_id = ".intval($userId); |
793
|
|
|
Database::query($sql); |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
return $result; |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
/** |
800
|
|
|
* Deletes an url and course relationship |
801
|
|
|
* @author Julio Montoya |
802
|
|
|
* @param int $courseId |
803
|
|
|
* @param int $urlId |
804
|
|
|
* |
805
|
|
|
* @return boolean true if success |
806
|
|
|
* */ |
807
|
|
|
public static function delete_url_rel_course($courseId, $urlId) |
808
|
|
|
{ |
809
|
|
|
$table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
810
|
|
|
$sql= "DELETE FROM $table_url_rel_course |
811
|
|
|
WHERE c_id = '".intval($courseId)."' AND access_url_id=".intval($urlId)." "; |
812
|
|
|
$result = Database::query($sql); |
813
|
|
|
|
814
|
|
|
return $result; |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
/** |
818
|
|
|
* Deletes an url and $userGroup relationship |
819
|
|
|
* @author Julio Montoya |
820
|
|
|
* @param int $userGroupId |
821
|
|
|
* @param int $urlId |
822
|
|
|
* |
823
|
|
|
* @return boolean true if success |
824
|
|
|
* */ |
825
|
|
|
public static function delete_url_rel_usergroup($userGroupId, $urlId) |
826
|
|
|
{ |
827
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
828
|
|
|
$sql= "DELETE FROM $table |
829
|
|
|
WHERE usergroup_id = '".intval($userGroupId)."' AND |
830
|
|
|
access_url_id=".intval($urlId)." "; |
831
|
|
|
$result = Database::query($sql); |
832
|
|
|
|
833
|
|
|
return $result; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
/** |
837
|
|
|
* Deletes an url and $userGroup relationship |
838
|
|
|
* @author Julio Montoya |
839
|
|
|
* @param int $userGroupId |
840
|
|
|
* @param int $urlId |
841
|
|
|
* |
842
|
|
|
* @return boolean true if success |
843
|
|
|
* */ |
844
|
|
|
public static function deleteUrlRelCourseCategory($userGroupId, $urlId) |
845
|
|
|
{ |
846
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); |
847
|
|
|
$sql= "DELETE FROM $table |
848
|
|
|
WHERE course_category_id = '".intval($userGroupId)."' AND |
849
|
|
|
access_url_id=".intval($urlId)." "; |
850
|
|
|
$result = Database::query($sql); |
851
|
|
|
|
852
|
|
|
return $result; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
/** |
856
|
|
|
* Deletes an url and session relationship |
857
|
|
|
* @author Julio Montoya |
858
|
|
|
* @param char course code |
859
|
|
|
* @param int url id |
860
|
|
|
* |
861
|
|
|
* @return boolean true if success |
862
|
|
|
* */ |
863
|
|
|
public static function delete_url_rel_session($session_id, $url_id) |
864
|
|
|
{ |
865
|
|
|
$table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
866
|
|
|
$sql= "DELETE FROM $table_url_rel_session |
867
|
|
|
WHERE session_id = ".intval($session_id)." AND access_url_id=".intval($url_id)." "; |
868
|
|
|
$result = Database::query($sql,'ASSOC'); |
869
|
|
|
|
870
|
|
|
return $result; |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
/** |
874
|
|
|
* Updates the access_url_rel_user table with a given user list |
875
|
|
|
* @author Julio Montoya |
876
|
|
|
* @param array user list |
877
|
|
|
* @param int access_url_id |
878
|
|
|
* */ |
879
|
|
|
public static function update_urls_rel_user($user_list, $access_url_id) |
880
|
|
|
{ |
881
|
|
|
$table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
882
|
|
|
$sql = "SELECT user_id FROM $table_url_rel_user WHERE access_url_id = ".intval($access_url_id); |
883
|
|
|
$result = Database::query($sql); |
884
|
|
|
$existing_users = array(); |
885
|
|
|
|
886
|
|
|
//Getting all users |
887
|
|
|
while ($row = Database::fetch_array($result)) { |
888
|
|
|
$existing_users[] = $row['user_id']; |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
// Adding users |
892
|
|
|
$users_added = array(); |
893
|
|
View Code Duplication |
foreach ($user_list as $user_id_to_add) { |
894
|
|
|
if (!in_array($user_id_to_add, $existing_users)) { |
895
|
|
|
$result = UrlManager::add_user_to_url($user_id_to_add, $access_url_id); |
896
|
|
|
if ($result) { |
897
|
|
|
$users_added[] = $user_id_to_add; |
898
|
|
|
} |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
$users_deleted = array(); |
903
|
|
|
// Deleting old users |
904
|
|
View Code Duplication |
foreach ($existing_users as $user_id_to_delete) { |
905
|
|
|
if (!in_array($user_id_to_delete, $user_list)) { |
906
|
|
|
$result = UrlManager::delete_url_rel_user($user_id_to_delete, $access_url_id); |
907
|
|
|
if ($result) { |
908
|
|
|
$users_deleted[] = $user_id_to_delete; |
909
|
|
|
} |
910
|
|
|
} |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
if (empty($users_added) && empty($users_deleted)) { |
914
|
|
|
return false; |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
return array('users_added' => $users_added, 'users_deleted' => $users_deleted); |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
/** |
921
|
|
|
* Updates the access_url_rel_course table with a given user list |
922
|
|
|
* @author Julio Montoya |
923
|
|
|
* @param array $course_list |
924
|
|
|
* @param int access_url_id |
925
|
|
|
* */ |
926
|
|
|
public static function update_urls_rel_course($course_list, $access_url_id) |
927
|
|
|
{ |
928
|
|
|
$table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
929
|
|
|
|
930
|
|
|
$sql = "SELECT c_id FROM $table_url_rel_course |
931
|
|
|
WHERE access_url_id = ".intval($access_url_id); |
932
|
|
|
$result = Database::query($sql); |
933
|
|
|
|
934
|
|
|
$existing_courses = array(); |
935
|
|
|
while ($row = Database::fetch_array($result)){ |
936
|
|
|
$existing_courses[] = $row['c_id']; |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
// Adding courses |
940
|
|
|
foreach ($course_list as $courseId) { |
941
|
|
|
UrlManager::add_course_to_url($courseId, $access_url_id); |
942
|
|
|
CourseManager::update_course_ranking($courseId, 0, $access_url_id); |
943
|
|
|
} |
944
|
|
|
|
945
|
|
|
// Deleting old courses |
946
|
|
|
foreach ($existing_courses as $courseId) { |
947
|
|
|
if (!in_array($courseId, $course_list)) { |
948
|
|
|
UrlManager::delete_url_rel_course($courseId, $access_url_id); |
949
|
|
|
CourseManager::update_course_ranking($courseId, 0, $access_url_id); |
950
|
|
|
} |
951
|
|
|
} |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
/** |
955
|
|
|
* Updates the access_url_rel_course table with a given user list |
956
|
|
|
* @author Julio Montoya |
957
|
|
|
* @param array user list |
958
|
|
|
* @param int access_url_id |
959
|
|
|
* */ |
960
|
|
|
public static function update_urls_rel_usergroup($userGroupList, $urlId) |
961
|
|
|
{ |
962
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
963
|
|
|
|
964
|
|
|
$sql = "SELECT usergroup_id FROM $table WHERE access_url_id = ".intval($urlId); |
965
|
|
|
$result = Database::query($sql); |
966
|
|
|
$existingItems = array(); |
967
|
|
|
|
968
|
|
|
while ($row = Database::fetch_array($result)){ |
969
|
|
|
$existingItems[] = $row['usergroup_id']; |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
// Adding |
973
|
|
|
foreach ($userGroupList as $userGroupId) { |
974
|
|
|
if (!in_array($userGroupId, $existingItems)) { |
975
|
|
|
UrlManager::addUserGroupToUrl($userGroupId, $urlId); |
976
|
|
|
} |
977
|
|
|
} |
978
|
|
|
|
979
|
|
|
// Deleting old items |
980
|
|
|
foreach ($existingItems as $userGroupId) { |
981
|
|
|
if (!in_array($userGroupId, $userGroupList)) { |
982
|
|
|
UrlManager::delete_url_rel_usergroup($userGroupId, $urlId); |
983
|
|
|
} |
984
|
|
|
} |
985
|
|
|
} |
986
|
|
|
|
987
|
|
|
/** |
988
|
|
|
* Updates the access_url_rel_course_category table with a given list |
989
|
|
|
* @author Julio Montoya |
990
|
|
|
* @param array course category list |
991
|
|
|
* @param int access_url_id |
992
|
|
|
**/ |
993
|
|
|
public static function updateUrlRelCourseCategory($list, $urlId) |
994
|
|
|
{ |
995
|
|
|
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); |
996
|
|
|
|
997
|
|
|
$sql = "SELECT course_category_id FROM $table WHERE access_url_id = ".intval($urlId); |
998
|
|
|
$result = Database::query($sql); |
999
|
|
|
$existingItems = array(); |
1000
|
|
|
|
1001
|
|
|
while ($row = Database::fetch_array($result)){ |
1002
|
|
|
$existingItems[] = $row['course_category_id']; |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
// Adding |
1006
|
|
|
|
1007
|
|
View Code Duplication |
foreach ($list as $id) { |
1008
|
|
|
UrlManager::addCourseCategoryToUrl($id, $urlId); |
1009
|
|
|
$categoryInfo = getCategoryById($id); |
1010
|
|
|
$children = getChildren($categoryInfo['code']); |
1011
|
|
|
if (!empty($children)) { |
1012
|
|
|
foreach ($children as $category) { |
1013
|
|
|
UrlManager::addCourseCategoryToUrl($category['id'], $urlId); |
1014
|
|
|
} |
1015
|
|
|
} |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
// Deleting old items |
1019
|
|
View Code Duplication |
foreach ($existingItems as $id) { |
1020
|
|
|
if (!in_array($id, $list)) { |
1021
|
|
|
UrlManager::deleteUrlRelCourseCategory($id, $urlId); |
1022
|
|
|
$categoryInfo = getCategoryById($id); |
1023
|
|
|
|
1024
|
|
|
$children = getChildren($categoryInfo['code']); |
1025
|
|
|
if (!empty($children)) { |
1026
|
|
|
foreach ($children as $category) { |
1027
|
|
|
UrlManager::deleteUrlRelCourseCategory($category['id'], $urlId); |
1028
|
|
|
} |
1029
|
|
|
} |
1030
|
|
|
} |
1031
|
|
|
} |
1032
|
|
|
} |
1033
|
|
|
|
1034
|
|
|
|
1035
|
|
|
|
1036
|
|
|
/** |
1037
|
|
|
* Updates the access_url_rel_session table with a given user list |
1038
|
|
|
* @author Julio Montoya |
1039
|
|
|
* @param array user list |
1040
|
|
|
* @param int access_url_id |
1041
|
|
|
* */ |
1042
|
|
|
public static function update_urls_rel_session($session_list,$access_url_id) |
1043
|
|
|
{ |
1044
|
|
|
$table_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
1045
|
|
|
|
1046
|
|
|
$sql = "SELECT session_id FROM $table_url_rel_session WHERE access_url_id=".intval($access_url_id); |
1047
|
|
|
$result = Database::query($sql); |
1048
|
|
|
$existing_sessions = array(); |
1049
|
|
|
|
1050
|
|
|
while ($row = Database::fetch_array($result)){ |
1051
|
|
|
$existing_sessions[] = $row['session_id']; |
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
// Adding users |
1055
|
|
View Code Duplication |
foreach ($session_list as $session) { |
1056
|
|
|
if (!in_array($session, $existing_sessions)) { |
1057
|
|
|
if (!empty($session) && !empty($access_url_id)) { |
1058
|
|
|
UrlManager::add_session_to_url($session, $access_url_id); |
1059
|
|
|
} |
1060
|
|
|
} |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
// Deleting old users |
1064
|
|
View Code Duplication |
foreach ($existing_sessions as $existing_session) { |
1065
|
|
|
if (!in_array($existing_session, $session_list)) { |
1066
|
|
|
if (!empty($existing_session) && !empty($access_url_id)) { |
1067
|
|
|
UrlManager::delete_url_rel_session($existing_session, $access_url_id); |
1068
|
|
|
} |
1069
|
|
|
} |
1070
|
|
|
} |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
/** |
1074
|
|
|
* @param int $user_id |
1075
|
|
|
* @return array |
1076
|
|
|
*/ |
1077
|
|
|
public static function get_access_url_from_user($user_id) |
1078
|
|
|
{ |
1079
|
|
|
$table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
1080
|
|
|
$table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
1081
|
|
|
$sql = "SELECT url, access_url_id FROM $table_url_rel_user url_rel_user INNER JOIN $table_url u |
1082
|
|
|
ON (url_rel_user.access_url_id = u.id) |
1083
|
|
|
WHERE user_id = ".intval($user_id); |
1084
|
|
|
$result = Database::query($sql); |
1085
|
|
|
$url_list = Database::store_result($result,'ASSOC'); |
1086
|
|
|
return $url_list; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* @param int $courseId |
1091
|
|
|
* @return array |
1092
|
|
|
*/ |
1093
|
|
|
public static function get_access_url_from_course($courseId) |
1094
|
|
|
{ |
1095
|
|
|
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
1096
|
|
|
$table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
1097
|
|
|
$sql = "SELECT url, access_url_id FROM $table c INNER JOIN $table_url u |
1098
|
|
|
ON (c.access_url_id = u.id) |
1099
|
|
|
WHERE c_id = ".intval($courseId); |
1100
|
|
|
|
1101
|
|
|
$result = Database::query($sql); |
1102
|
|
|
$url_list = Database::store_result($result,'ASSOC'); |
1103
|
|
|
return $url_list; |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
/** |
1107
|
|
|
* @param $session_id |
1108
|
|
|
* @return array |
1109
|
|
|
*/ |
1110
|
|
|
public static function get_access_url_from_session($session_id) |
1111
|
|
|
{ |
1112
|
|
|
$table_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
1113
|
|
|
$table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
1114
|
|
|
$sql = "SELECT url, access_url_id FROM $table_url_rel_session url_rel_session INNER JOIN $table_url u |
1115
|
|
|
ON (url_rel_session.access_url_id = u.id) |
1116
|
|
|
WHERE session_id = ".intval($session_id); |
1117
|
|
|
$result = Database::query($sql); |
1118
|
|
|
$url_list = Database::store_result($result); |
1119
|
|
|
|
1120
|
|
|
return $url_list; |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
/** |
1124
|
|
|
* @param string $url |
1125
|
|
|
* @return bool|mixed|null |
1126
|
|
|
*/ |
1127
|
|
|
public static function get_url_id($url) |
1128
|
|
|
{ |
1129
|
|
|
$table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
1130
|
|
|
$sql = "SELECT id FROM $table_access_url WHERE url = '".Database::escape_string($url)."'"; |
1131
|
|
|
$result = Database::query($sql); |
1132
|
|
|
$access_url_id = Database::result($result, 0, 0); |
1133
|
|
|
return $access_url_id; |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
/** |
1137
|
|
|
* |
1138
|
|
|
* @param string $needle |
1139
|
|
|
* @return XajaxResponse |
1140
|
|
|
*/ |
1141
|
|
View Code Duplication |
public static function searchCourseCategoryAjax($needle) |
1142
|
|
|
{ |
1143
|
|
|
$response = new xajaxResponse(); |
1144
|
|
|
$return = ''; |
1145
|
|
|
|
1146
|
|
|
if (!empty($needle)) { |
1147
|
|
|
// xajax send utf8 datas... datas in db can be non-utf8 datas |
1148
|
|
|
$charset = api_get_system_encoding(); |
1149
|
|
|
$needle = api_convert_encoding($needle, $charset, 'utf-8'); |
1150
|
|
|
$needle = Database::escape_string($needle); |
1151
|
|
|
// search courses where username or firstname or lastname begins likes $needle |
1152
|
|
|
$sql = 'SELECT id, name FROM '.Database::get_main_table(TABLE_MAIN_CATEGORY).' u |
1153
|
|
|
WHERE name LIKE "'.$needle.'%" AND (parent_id IS NULL or parent_id = 0) |
1154
|
|
|
ORDER BY name |
1155
|
|
|
LIMIT 11'; |
1156
|
|
|
$result = Database::query($sql); |
1157
|
|
|
$i = 0; |
1158
|
|
|
while ($data = Database::fetch_array($result)) { |
1159
|
|
|
$i++; |
1160
|
|
|
if ($i <= 10) { |
1161
|
|
|
$return .= '<a |
1162
|
|
|
href="javascript: void(0);" |
1163
|
|
|
onclick="javascript: add_user_to_url(\''.addslashes($data['id']).'\',\''.addslashes($data['name']).' \')">'.$data['name'].' </a><br />'; |
1164
|
|
|
} else { |
1165
|
|
|
$return .= '...<br />'; |
1166
|
|
|
} |
1167
|
|
|
} |
1168
|
|
|
} |
1169
|
|
|
$response->addAssign('ajax_list_courses', 'innerHTML', api_utf8_encode($return)); |
1170
|
|
|
return $response; |
1171
|
|
|
} |
1172
|
|
|
} |
1173
|
|
|
|