chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Responses to AJAX calls. |
||
| 7 | */ |
||
| 8 | |||
| 9 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
|
0 ignored issues
–
show
|
|||
| 10 | |||
| 11 | require_once __DIR__.'/../global.inc.php'; |
||
| 12 | |||
| 13 | $httpRequest = HttpRequest::createFromGlobals(); |
||
| 14 | |||
| 15 | $action = $httpRequest->query->has('a') ? $httpRequest->query->get('a') : $httpRequest->request->get('a'); |
||
| 16 | |||
| 17 | $isAllowedToEdit = api_is_allowed_to_edit(); |
||
| 18 | |||
| 19 | switch ($action) { |
||
| 20 | case 'get_class_by_keyword': |
||
| 21 | $keyword = $httpRequest->query->has('q') ? $httpRequest->query->get('q') : $httpRequest->request->get('q'); |
||
| 22 | $allow = api_is_platform_admin() || api_is_session_admin(); |
||
| 23 | |||
| 24 | if ($allow && !empty($keyword)) { |
||
| 25 | $userGroup = new UserGroup(); |
||
| 26 | $where = ['where' => ['name like ?' => "%$keyword%"], 'order' => 'name ']; |
||
| 27 | $items = []; |
||
| 28 | $list = $userGroup->get_all($where); |
||
| 29 | foreach ($list as $class) { |
||
| 30 | $items[] = [ |
||
| 31 | 'id' => $class['id'], |
||
| 32 | 'text' => $class['name'], |
||
| 33 | ]; |
||
| 34 | } |
||
| 35 | echo json_encode(['items' => $items]); |
||
| 36 | } |
||
| 37 | break; |
||
| 38 | case 'delete_user_in_usergroup': |
||
| 39 | if ($isAllowedToEdit) { |
||
| 40 | $userGroup = new UserGroup(); |
||
| 41 | $userId = $httpRequest->query->has('id') |
||
| 42 | ? $httpRequest->query->getInt('id') |
||
| 43 | : $httpRequest->request->getInt('id'); |
||
| 44 | $userIdList = explode(',', $userId); |
||
| 45 | $groupId = $httpRequest->query->has('group_id') |
||
| 46 | ? $httpRequest->query->getInt('group_id') |
||
| 47 | : $httpRequest->request->getInt('group_id'); |
||
| 48 | foreach ($userIdList as $userId) { |
||
| 49 | $userGroup->delete_user_rel_group($userId, $groupId); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | break; |
||
| 53 | default: |
||
| 54 | echo ''; |
||
| 55 | break; |
||
| 56 | } |
||
| 57 | exit; |
||
| 58 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: