ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilOrgUnitStaffGUI.php
Go to the documentation of this file.
1<?php
18/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
19
29{
32 protected ilCtrl $ctrl;
34 protected object $parent_gui;
35 protected object $parent_object;
36 protected ilLanguage $lng;
39
44 {
45 global $DIC;
46 $this->tpl = $DIC->ui()->mainTemplate();
47 $this->ctrl = $DIC->ctrl();
48 $this->parent_gui = $parent_gui;
49 $this->parent_object = $parent_gui->object;
50 $this->tabs_gui = $this->parent_gui->tabs_gui;
51 $this->toolbar = $DIC->toolbar();
52 $this->lng = $DIC->language();
53 $this->ilAccess = $DIC->access();
54 $this->toolbar = $DIC->toolbar();
55 $this->rbacreview = $DIC->rbac()->review();
56
57 $this->tabs_gui->setTabActive("orgu_staff");
58 $this->setTabs();
59 }
60
67 public function executeCommand(): bool
68 {
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd();
71
72 switch ($next_class) {
73 case 'ilrepositorysearchgui':
74 $repo = new ilRepositorySearchGUI();
75 $this->ctrl->forwardCommand($repo);
76 break;
77 default:
78 switch ($cmd) {
79 case 'showStaff':
80 $this->tabs_gui->activateSubTab("show_staff");
81 $this->showStaff();
82 break;
83 case 'showOtherRoles':
84 $this->tabs_gui->activateSubTab("show_other_roles");
85 $this->showOtherRoles();
86 break;
87 case 'showStaffRec':
88 $this->tabs_gui->activateSubTab("show_staff_rec");
89 $this->showStaffRec();
90 break;
91 case 'confirmRemoveFromRole':
92 case 'confirmRemoveFromEmployees':
93 case 'confirmRemoveFromSuperiors':
94 $this->confirmRemoveUser($cmd);
95 break;
96 case 'addStaff':
97 case 'addOtherRoles':
98 case 'fromSuperiorToEmployee':
99 case 'fromEmployeeToSuperior':
100 case 'removeFromSuperiors':
101 case 'removeFromEmployees':
102 case 'removeFromRole':
103 $this->$cmd();
104 break;
105 default:
106 throw new ilException("Unknown command for command class ilOrgUnitStaffGUI: " . $cmd);
107 break;
108 }
109 break;
110 }
111
112 return true;
113 }
114
118 public function showStaff(): void
119 {
120 if (!ilObjOrgUnitAccess::_checkAccessStaff($this->parent_object->getRefId())) {
121 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
122 $this->ctrl->redirect($this->parent_gui, "");
123 }
124 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
125 $this->addStaffToolbar();
126 }
127 $this->ctrl->setParameter($this, "recursive", false);
128 $this->tpl->setContent($this->getStaffTableHTML(false, "showStaff"));
129 }
130
131 public function showOtherRoles(): void
132 {
133 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
134 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
135 $this->ctrl->redirect($this->parent_gui, "");
136 }
137 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
138 $this->addOtherRolesToolbar();
139 }
140 $this->tpl->setContent($this->getOtherRolesTableHTML());
141 }
142
143 public function showStaffRec(): void
144 {
145 if (!ilObjOrgUnitAccess::_checkAccessStaffRec($this->parent_object->getRefId())) {
146 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
147 $this->ctrl->redirect($this->parent_gui, "");
148 }
149 $this->ctrl->setParameter($this, "recursive", true);
150 $this->tpl->setContent($this->getStaffTableHTML(true, "showStaffRec"));
151 }
152
153 private function addStaffToolbar(): void
154 {
155 $types = array(
156 "employee" => $this->lng->txt("employee"),
157 "superior" => $this->lng->txt("superior"),
158 );
159 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'staff');
161 'auto_complete_name' => $this->lng->txt('user'),
162 'user_type' => $types,
163 'submit_name' => $this->lng->txt('add'),
164 ));
165 }
166
167 private function addOtherRolesToolbar(): void
168 {
169 $arrLocalRoles = $this->rbacreview->getLocalRoles($this->parent_object->getRefId());
170 $types = array();
171 foreach ($arrLocalRoles as $role_id) {
172 $ilObjRole = new ilObjRole($role_id);
173 if (!preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
174 $types[$role_id] = $ilObjRole->getPresentationTitle();
175 }
176 }
177 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'other');
179 'auto_complete_name' => $this->lng->txt('user'),
180 'user_type' => $types,
181 'submit_name' => $this->lng->txt('add'),
182 ));
183 }
184
185 public function addStaff()
186 {
187 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
188 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
189 $this->ctrl->redirect($this->parent_gui, "");
190 }
191
192 $users = explode(',', $_POST['user_login']);
193 $user_ids = array();
194 foreach ($users as $user) {
195 $user_id = ilObjUser::_lookupId($user);
196 if ($user_id) {
197 $user_ids[] = $user_id;
198 }
199 }
200
201 if (!count($user_ids)) {
202 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("user_not_found"), true);
203 $this->ctrl->redirect($this, "showStaff");
204 }
205
206 $user_type = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
207 if ($user_type == "employee") {
208 $this->parent_object->assignUsersToEmployeeRole($user_ids);
209 } elseif ($user_type == "superior") {
210 $this->parent_object->assignUsersToSuperiorRole($user_ids);
211 } else {
212 throw new Exception("The post request didn't specify wether the user_ids should be assigned to the employee or the superior role.");
213 }
214
215 $this->tpl->setOnScreenMessage('success', $this->lng->txt("users_successfuly_added"), true);
216 $this->ctrl->redirect($this, "showStaff");
217 }
218
219 public function addOtherRoles()
220 {
221 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
222 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
223 $this->ctrl->redirect($this->parent_gui, "");
224 }
225
226 $users = explode(',', $_POST['user_login']);
227 $user_ids = array();
228 foreach ($users as $user) {
229 $user_id = ilObjUser::_lookupId($user);
230 if ($user_id) {
231 $user_ids[] = $user_id;
232 }
233 }
234 $role_id = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
235 foreach ($user_ids as $user_id) {
236 $this->parent_object->assignUserToLocalRole($role_id, $user_id);
237 }
238 $this->tpl->setOnScreenMessage('success', $this->lng->txt("users_successfuly_added"), true);
239 $this->ctrl->redirect($this, "showOtherRoles");
240 }
241
247 public function getStaffTableHTML($recursive = false, $table_cmd = "showStaff")
248 {
249 global $DIC;
250 $lng = $DIC['lng'];
251 $rbacreview = $DIC['rbacreview'];
252 $superior_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "superior", $recursive);
253 $superior_table->parseData();
254 $superior_table->setTitle($lng->txt("il_orgu_superior"));
255 $employee_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "employee", $recursive);
256 $employee_table->parseData();
257 $employee_table->setTitle($lng->txt("il_orgu_employee"));
258
259 return $superior_table->getHTML() . $employee_table->getHTML();
260 }
261
262 public function getOtherRolesTableHTML()
263 {
264 global $DIC;
265 $lng = $DIC['lng'];
266 $rbacreview = $DIC['rbacreview'];
267 $arrLocalRoles = $rbacreview->getLocalRoles($this->parent_object->getRefId());
268 $html = "";
269 foreach ($arrLocalRoles as $role_id) {
270 $ilObjRole = new ilObjRole($role_id);
271 if (!preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
272 $other_roles_table = new ilOrgUnitOtherRolesTableGUI($this, 'other_role_' . $role_id, $role_id);
273 $other_roles_table->readData();
274 $html .= $other_roles_table->getHTML() . "<br/>";
275 }
276 }
277 if (!$html) {
278 $html = $lng->txt("no_roles");
279 }
280
281 return $html;
282 }
283
284 public function fromSuperiorToEmployee()
285 {
286 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
287 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
288 $this->ctrl->redirect($this->parent_gui, "");
289 }
290 $this->parent_object->deassignUserFromSuperiorRole($_GET["obj_id"]);
291 $this->parent_object->assignUsersToEmployeeRole(array($_GET["obj_id"]));
292 $this->tpl->setOnScreenMessage('success', $this->lng->txt("user_changed_successful"), true);
293 $this->ctrl->redirect($this, "showStaff");
294 }
295
296 public function fromEmployeeToSuperior()
297 {
298 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
299 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
300 $this->ctrl->redirect($this->parent_gui, "");
301 }
302 $this->parent_object->deassignUserFromEmployeeRole($_GET["obj_id"]);
303 $this->parent_object->assignUsersToSuperiorRole(array($_GET["obj_id"]));
304 $this->tpl->setOnScreenMessage('success', $this->lng->txt("user_changed_successful"), true);
305 $this->ctrl->redirect($this, "showStaff");
306 }
307
308 public function confirmRemoveUser($cmd)
309 {
310 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
311 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
312 $this->ctrl->redirect($this->parent_gui, "");
313 }
314 switch ($cmd) {
315 case "confirmRemoveFromRole":
316 $this->tabs_gui->activateSubTab("show_other_roles");
317 $nextcmd = "removeFromRole";
318 $paramname = "obj_id-role_id";
319 $param = $_GET["obj_id"] . '-' . $_GET["role_id"];
320 break;
321 case "confirmRemoveFromSuperiors":
322 $this->tabs_gui->activateSubTab("show_staff");
323 $nextcmd = "removeFromSuperiors";
324 $paramname = "obj_id";
325 $param = $_GET["obj_id"];
326 break;
327 case "confirmRemoveFromEmployees":
328 $this->tabs_gui->activateSubTab("show_staff");
329 $nextcmd = "removeFromEmployees";
330 $paramname = "obj_id";
331 $param = $_GET["obj_id"];
332 break;
333 }
334 $confirm = new ilConfirmationGUI();
335 $confirm->setFormAction($this->ctrl->getFormAction($this, $nextcmd));
336 $confirm->setHeaderText($this->lng->txt('orgu_staff_deassign'));
337 $confirm->setConfirm($this->lng->txt('confirm'), $nextcmd);
338 $confirm->setCancel($this->lng->txt('cancel'), 'showStaff');
339 $arrUser = ilObjUser::_lookupName($_GET["obj_id"]);
340 $confirm->addItem(
341 $paramname,
342 $param,
343 $arrUser['lastname'] . ', ' . $arrUser['firstname'] . ' [' . $arrUser['login']
344 . ']',
345 ilUtil::getImagePath('icon_usr.svg')
346 );
347 $this->tpl->setContent($confirm->getHTML());
348 }
349
350 public function removeFromSuperiors()
351 {
352 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
353 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
354 $this->ctrl->redirect($this->parent_gui, "");
355 }
356 $this->parent_object->deassignUserFromSuperiorRole($_POST["obj_id"]);
357 //if user is neither employee nor superior, remove orgunit from user->org_units
358 if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getEmployeeRole())) {
359 ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
360 }
361 $this->tpl->setOnScreenMessage('success', $this->lng->txt("deassign_user_successful"), true);
362 $this->ctrl->redirect($this, "showStaff");
363 }
364
365 public function removeFromEmployees()
366 {
367 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
368 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
369 $this->ctrl->redirect($this->parent_gui, "");
370 }
371 $this->parent_object->deassignUserFromEmployeeRole($_POST["obj_id"]);
372 //if user is neither employee nor superior, remove orgunit from user->org_units
373 if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getSuperiorRole())) {
374 ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
375 }
376 $this->tpl->setOnScreenMessage('success', $this->lng->txt("deassign_user_successful"), true);
377 $this->ctrl->redirect($this, "showStaff");
378 }
379
380 public function removeFromRole()
381 {
382 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
383 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
384 $this->ctrl->redirect($this->parent_gui, "");
385 }
386 $arrObjIdRolId = explode("-", $_POST["obj_id-role_id"]);
387 $this->parent_object->deassignUserFromLocalRole($arrObjIdRolId[1], $arrObjIdRolId[0]);
388 $this->tpl->setOnScreenMessage('success', $this->lng->txt("deassign_user_successful"), true);
389 $this->ctrl->redirect($this, "showOtherRoles");
390 }
391
392 public function setTabs()
393 {
394 $this->tabs_gui->addSubTab(
395 "show_staff",
396 sprintf($this->lng->txt("local_staff"), $this->parent_object->getTitle()),
397 $this->ctrl->getLinkTarget($this, "showStaff")
398 );
399 if ($this->ilAccess->checkAccess("view_learning_progress_rec", "", $this->parent_object->getRefId())) {
400 $this->tabs_gui->addSubTab(
401 "show_staff_rec",
402 sprintf($this->lng->txt("rec_staff"), $this->parent_object->getTitle()),
403 $this->ctrl->getLinkTarget($this, "showStaffRec")
404 );
405 }
406 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
407 $this->tabs_gui->addSubTab(
408 "show_other_roles",
409 sprintf($this->lng->txt("local_other_roles"), $this->parent_object->getTitle()),
410 $this->ctrl->getLinkTarget($this, "showOtherRoles")
411 );
412 }
413 }
414}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _checkAccessStaffRec(int $ref_id)
static _checkAccessStaff(int $ref_id)
Class ilObjOrgUnit GUI class.
Class ilObjRole.
static _lookupId($a_user_str)
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjOrgUnitGUI $parent_gui)
ilGlobalTemplateInterface $tpl
getStaffTableHTML($recursive=false, $table_cmd="showStaff")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilRbacReview Contains Review functions of core Rbac.
getLocalRoles(int $a_ref_id)
Get local roles of object.
static fillAutoCompleteToolbar(object $parent_object, ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt('user'), auto_complete_size = 15, user_type = array(ilCoursePar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$_GET['client_id']
Definition: saml1-acs.php:21
$param
Definition: xapitoken.php:46