1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | use Chamilo\CoreBundle\Entity\UserRelUser; |
||
5 | use Chamilo\UserBundle\Entity\User; |
||
6 | |||
7 | $cidReset = true; |
||
8 | |||
9 | require_once __DIR__.'/../inc/global.inc.php'; |
||
10 | |||
11 | api_protect_admin_script(); |
||
12 | |||
13 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
||
14 | $hrmId = isset($_GET['hrm']) ? intval($_GET['hrm']) : 0; |
||
15 | $assignedId = isset($_GET['u']) ? intval($_GET['u']) : 0; |
||
16 | $hrm = $hrmId ? api_get_user_entity($hrmId) : null; |
||
17 | |||
18 | $em = Database::getManager(); |
||
19 | |||
20 | if (!empty($action) && $hrm && $assignedId) { |
||
21 | switch ($action) { |
||
22 | case 'accept': |
||
23 | /** @var UserRelUser $request */ |
||
24 | $request = $em->getRepository('ChamiloCoreBundle:UserRelUser') |
||
25 | ->findOneBy([ |
||
26 | 'userId' => $assignedId, |
||
27 | 'friendUserId' => $hrm->getId(), |
||
28 | 'relationType' => USER_RELATION_TYPE_HRM_REQUEST, |
||
29 | ]); |
||
30 | |||
31 | if ($request) { |
||
32 | $request->setRelationType(USER_RELATION_TYPE_RRHH); |
||
33 | $request->setLastEdit(api_get_utc_datetime(null, null, true)); |
||
34 | $em->persist($request); |
||
35 | $em->flush(); |
||
36 | |||
37 | Display::addFlash( |
||
38 | Display::return_message(get_lang('UserLinkingRequestAccepted'), 'success') |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | header('Location: '.api_get_self().'?hrm='.$hrm->getId()); |
||
43 | exit; |
||
44 | case 'reject': |
||
45 | /** @var UserRelUser $request */ |
||
46 | $request = $em->getRepository('ChamiloCoreBundle:UserRelUser') |
||
47 | ->findOneBy([ |
||
48 | 'userId' => $assignedId, |
||
49 | 'friendUserId' => $hrm->getId(), |
||
50 | 'relationType' => USER_RELATION_TYPE_HRM_REQUEST, |
||
51 | ]); |
||
52 | |||
53 | if ($request) { |
||
54 | $em->remove($request); |
||
55 | $em->flush(); |
||
56 | |||
57 | Display::addFlash( |
||
58 | Display::return_message(get_lang('UserLinkingRequestRejected'), 'success') |
||
59 | ); |
||
60 | } |
||
61 | /** Todo: notify the HRM that the request was rejected */ |
||
62 | header('Location: '.api_get_self().'?hrm='.$hrm->getId()); |
||
63 | exit; |
||
64 | case 'remove': |
||
65 | /** @var UserRelUser $request */ |
||
66 | $request = $em->getRepository('ChamiloCoreBundle:UserRelUser') |
||
67 | ->findOneBy([ |
||
68 | 'userId' => $assignedId, |
||
69 | 'friendUserId' => $hrm->getId(), |
||
70 | 'relationType' => USER_RELATION_TYPE_RRHH, |
||
71 | ]); |
||
72 | |||
73 | if ($request) { |
||
74 | $em->remove($request); |
||
75 | $em->flush(); |
||
76 | |||
77 | Display::addFlash( |
||
78 | Display::return_message(get_lang('UserLinkRemoved'), 'success') |
||
79 | ); |
||
80 | } |
||
81 | /** Todo: notify the HRM that the request was rejected */ |
||
82 | header('Location: '.api_get_self().'?hrm='.$hrm->getId()); |
||
83 | exit; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get the data to fill the tables on screen. |
||
89 | * |
||
90 | * @param int $status |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | function getData(User $hrm, $status = HRM_REQUEST) |
||
95 | { |
||
96 | $requests = UserManager::getUsersFollowedByUser( |
||
97 | $hrm->getId(), |
||
98 | null, |
||
99 | false, |
||
100 | false, |
||
101 | false, |
||
102 | null, |
||
103 | null, |
||
104 | null, |
||
105 | null, |
||
106 | null, |
||
107 | null, |
||
108 | $status |
||
109 | ); |
||
110 | |||
111 | $result = []; |
||
112 | |||
113 | $iconAccept = Display::return_icon('accept.png', get_lang('Accept')); |
||
114 | $urlAccept = api_get_self().'?action=accept&hrm='.$hrm->getId().'&u='; |
||
115 | $iconReject = Display::return_icon('delete.png', get_lang('Reject')); |
||
116 | $urlReject = api_get_self().'?action=reject&hrm='.$hrm->getId().'&u='; |
||
117 | $iconRemove = Display::return_icon('delete.png', get_lang('Remove')); |
||
118 | $urlRemove = api_get_self().'?action=remove&hrm='.$hrm->getId().'&u='; |
||
119 | |||
120 | foreach ($requests as $request) { |
||
121 | $line = []; |
||
122 | $studentLink = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$request['user_id']; |
||
123 | $line[] = '<a href="'.$studentLink.'">'.api_get_person_name($request['firstname'], $request['lastname']).'</a>'; |
||
124 | if ($status == HRM_REQUEST) { |
||
125 | $line[] = Display::url( |
||
126 | $iconAccept, |
||
127 | $urlAccept.$request['user_id'] |
||
128 | ). |
||
129 | Display::url( |
||
130 | $iconReject, |
||
131 | $urlReject.$request['user_id'] |
||
132 | ); |
||
133 | } else { |
||
134 | $line[] = Display::url( |
||
135 | $iconRemove, |
||
136 | $urlRemove.$request['user_id'] |
||
137 | ); |
||
138 | } |
||
139 | $result[] = $line; |
||
140 | } |
||
141 | |||
142 | return $result; |
||
143 | } |
||
144 | |||
145 | $form = new FormValidator('user_linking_requests', 'get'); |
||
146 | $form->addSelectAjax( |
||
147 | 'hrm', |
||
148 | get_lang('DRH'), |
||
149 | $hrm ? [$hrm->getId() => UserManager::formatUserFullName($hrm)] : [], |
||
150 | ['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role'] |
||
151 | ); |
||
152 | $form->addButtonFilter(get_lang('Filter')); |
||
153 | |||
154 | $content = $form->returnForm(); |
||
155 | |||
156 | if ($hrm) { |
||
157 | $requests = getData($hrm); |
||
0 ignored issues
–
show
|
|||
158 | |||
159 | if ($requests) { |
||
160 | $content .= Display::table( |
||
161 | [get_lang('UserLinkingRequests'), get_lang('Actions')], |
||
162 | $requests |
||
163 | ); |
||
164 | } else { |
||
165 | $content .= Display::table( |
||
166 | [get_lang('UserLinkingRequests')], |
||
167 | [get_lang('NoResults')] |
||
168 | ); |
||
169 | } |
||
170 | |||
171 | $approved = getData($hrm, DRH); |
||
172 | if ($approved) { |
||
173 | $content .= Display::table( |
||
174 | [get_lang('UserLinkingTo'), get_lang('Actions')], |
||
175 | $approved |
||
176 | ); |
||
177 | } else { |
||
178 | $content .= Display::table( |
||
179 | [get_lang('UserLinkingTo')], |
||
180 | [get_lang('NoResults')] |
||
181 | ); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')]; |
||
186 | |||
187 | $toolName = get_lang('UserLinkingRequests'); |
||
188 | |||
189 | $view = new Template($toolName); |
||
190 | $view->assign('header', $toolName); |
||
191 | $view->assign('content', $content); |
||
192 | $view->display_one_col_template(); |
||
193 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.