ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilOrgUnitStaffGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
16
20 protected $tabs_gui;
24 protected $toolbar;
28 protected $ctrl;
32 protected $tpl;
36 protected $parent_gui;
40 protected $parent_obj;
44 protected $lng;
48 protected $ilAccess;
52 protected $rbacreview;
53
54
59 {
60 global $DIC;
61 $tpl = $DIC['tpl'];
62 $ilCtrl = $DIC['ilCtrl'];
63 $ilTabs = $DIC['ilTabs'];
64 $lng = $DIC['lng'];
65 $ilAccess = $DIC['ilAccess'];
66 $ilToolbar = $DIC['ilToolbar'];
67 $rbacreview = $DIC['rbacreview'];
68
69 $this->tpl = $tpl;
70 $this->ctrl = $ilCtrl;
71 $this->parent_gui = $parent_gui;
72 $this->parent_object = $parent_gui->object;
73 $this->tabs_gui = $this->parent_gui->tabs_gui;
74 $this->toolbar = $ilToolbar;
75 $this->lng = $lng;
76 $this->ilAccess = $ilAccess;
77 $this->toolbar = $ilToolbar;
78 $this->rbacreview = $rbacreview;
79
80 $this->tabs_gui->setTabActive("orgu_staff");
81 $this->setTabs();
82 }
83
84
91 public function executeCommand()
92 {
93 $next_class = $this->ctrl->getNextClass($this);
94 $cmd = $this->ctrl->getCmd();
95
96 switch ($next_class) {
97 case 'ilrepositorysearchgui':
98 $repo = new ilRepositorySearchGUI();
99 $this->ctrl->forwardCommand($repo);
100 break;
101 default:
102 switch ($cmd) {
103 case 'showStaff':
104 $this->tabs_gui->activateSubTab("show_staff");
105 $this->showStaff();
106 break;
107 case 'showOtherRoles':
108 $this->tabs_gui->activateSubTab("show_other_roles");
109 $this->showOtherRoles();
110 break;
111 case 'showStaffRec':
112 $this->tabs_gui->activateSubTab("show_staff_rec");
113 $this->showStaffRec();
114 break;
115 case 'confirmRemoveFromRole':
116 case 'confirmRemoveFromEmployees':
117 case 'confirmRemoveFromSuperiors':
118 $this->confirmRemoveUser($cmd);
119 break;
120 case 'addStaff':
121 case 'addOtherRoles':
122 case 'fromSuperiorToEmployee':
123 case 'fromEmployeeToSuperior':
124 case 'removeFromSuperiors':
125 case 'removeFromEmployees':
126 case 'removeFromRole':
127 $this->$cmd();
128 break;
129 default:
130 throw new ilException("Unknown command for command class ilOrgUnitStaffGUI: " . $cmd);
131 break;
132 }
133 break;
134 }
135
136 return true;
137 }
138
139
140 public function showStaff()
141 {
142 if (!ilObjOrgUnitAccess::_checkAccessStaff($this->parent_object->getRefId())) {
143 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
144 $this->ctrl->redirect($this->parent_gui, "");
145 }
146 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
147 $this->addStaffToolbar();
148 }
149 $this->ctrl->setParameter($this, "recursive", false);
150 $this->tpl->setContent($this->getStaffTableHTML(false, "showStaff"));
151 }
152
153
154 public function showOtherRoles()
155 {
156 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
157 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
158 $this->ctrl->redirect($this->parent_gui, "");
159 }
160 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
161 $this->addOtherRolesToolbar();
162 }
163 $this->tpl->setContent($this->getOtherRolesTableHTML());
164 }
165
166
167 public function showStaffRec()
168 {
169 if (!ilObjOrgUnitAccess::_checkAccessStaffRec($this->parent_object->getRefId())) {
170 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
171 $this->ctrl->redirect($this->parent_gui, "");
172 }
173 $this->ctrl->setParameter($this, "recursive", true);
174 $this->tpl->setContent($this->getStaffTableHTML(true, "showStaffRec"));
175 }
176
177
178 protected function addStaffToolbar()
179 {
180 $types = array(
181 "employee" => $this->lng->txt("employee"),
182 "superior" => $this->lng->txt("superior"),
183 );
184 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'staff');
185 ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->toolbar, array(
186 'auto_complete_name' => $this->lng->txt('user'),
187 'user_type' => $types,
188 'submit_name' => $this->lng->txt('add'),
189 ));
190 }
191
192
193 protected function addOtherRolesToolbar()
194 {
195 $arrLocalRoles = $this->rbacreview->getLocalRoles($this->parent_object->getRefId());
196 $types = array();
197 foreach ($arrLocalRoles as $role_id) {
198 $ilObjRole = new ilObjRole($role_id);
199 if (!preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
200 $types[$role_id] = $ilObjRole->getPresentationTitle();
201 }
202 }
203 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'other');
204 ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->toolbar, array(
205 'auto_complete_name' => $this->lng->txt('user'),
206 'user_type' => $types,
207 'submit_name' => $this->lng->txt('add'),
208 ));
209 }
210
211
212 public function addStaff()
213 {
214 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
215 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
216 $this->ctrl->redirect($this->parent_gui, "");
217 }
218
219 $users = explode(',', $_POST['user_login']);
220 $user_ids = array();
221 foreach ($users as $user) {
222 $user_id = ilObjUser::_lookupId($user);
223 if ($user_id) {
224 $user_ids[] = $user_id;
225 }
226 }
227
228 if (!count($user_ids)) {
229 ilUtil::sendFailure($this->lng->txt("user_not_found"), true);
230 $this->ctrl->redirect($this, "showStaff");
231 }
232
233 $user_type = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
234 if ($user_type == "employee") {
235 $this->parent_object->assignUsersToEmployeeRole($user_ids);
236 } elseif ($user_type == "superior") {
237 $this->parent_object->assignUsersToSuperiorRole($user_ids);
238 } else {
239 throw new Exception("The post request didn't specify wether the user_ids should be assigned to the employee or the superior role.");
240 }
241
242 ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
243 $this->ctrl->redirect($this, "showStaff");
244 }
245
246
247 public function addOtherRoles()
248 {
249 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
250 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
251 $this->ctrl->redirect($this->parent_gui, "");
252 }
253
254 $users = explode(',', $_POST['user_login']);
255 $user_ids = array();
256 foreach ($users as $user) {
257 $user_id = ilObjUser::_lookupId($user);
258 if ($user_id) {
259 $user_ids[] = $user_id;
260 }
261 }
262 $role_id = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
263 foreach ($user_ids as $user_id) {
264 $this->parent_object->assignUserToLocalRole($role_id, $user_id);
265 }
266 ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
267 $this->ctrl->redirect($this, "showOtherRoles");
268 }
269
270
277 public function getStaffTableHTML($recursive = false, $table_cmd = "showStaff")
278 {
279 global $DIC;
280 $lng = $DIC['lng'];
281 $rbacreview = $DIC['rbacreview'];
282 $superior_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "superior", $recursive);
283 $superior_table->parseData();
284 $superior_table->setTitle($lng->txt("orgu_superior"));
285 $employee_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "employee", $recursive);
286 $employee_table->parseData();
287 $employee_table->setTitle($lng->txt("orgu_employee"));
288
289 return $superior_table->getHTML() . $employee_table->getHTML();
290 }
291
292
293 public function getOtherRolesTableHTML()
294 {
295 global $DIC;
296 $lng = $DIC['lng'];
297 $rbacreview = $DIC['rbacreview'];
298 $arrLocalRoles = $rbacreview->getLocalRoles($this->parent_object->getRefId());
299 $html = "";
300 foreach ($arrLocalRoles as $role_id) {
301 $ilObjRole = new ilObjRole($role_id);
302 if (!preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
303 $other_roles_table = new ilOrgUnitOtherRolesTableGUI($this, 'other_role_' . $role_id, $role_id);
304 $other_roles_table->readData();
305 $html .= $other_roles_table->getHTML() . "<br/>";
306 }
307 }
308 if (!$html) {
309 $html = $lng->txt("no_roles");
310 }
311
312 return $html;
313 }
314
315
316 public function fromSuperiorToEmployee()
317 {
318 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
319 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
320 $this->ctrl->redirect($this->parent_gui, "");
321 }
322 $this->parent_object->deassignUserFromSuperiorRole($_GET["obj_id"]);
323 $this->parent_object->assignUsersToEmployeeRole(array($_GET["obj_id"]));
324 ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
325 $this->ctrl->redirect($this, "showStaff");
326 }
327
328
329 public function fromEmployeeToSuperior()
330 {
331 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
332 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
333 $this->ctrl->redirect($this->parent_gui, "");
334 }
335 $this->parent_object->deassignUserFromEmployeeRole($_GET["obj_id"]);
336 $this->parent_object->assignUsersToSuperiorRole(array($_GET["obj_id"]));
337 ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
338 $this->ctrl->redirect($this, "showStaff");
339 }
340
341
342 public function confirmRemoveUser($cmd)
343 {
344 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
345 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
346 $this->ctrl->redirect($this->parent_gui, "");
347 }
348 switch ($cmd) {
349 case "confirmRemoveFromRole":
350 $this->tabs_gui->activateSubTab("show_other_roles");
351 $nextcmd = "removeFromRole";
352 $paramname = "obj_id-role_id";
353 $param = $_GET["obj_id"] . '-' . $_GET["role_id"];
354 break;
355 case "confirmRemoveFromSuperiors":
356 $this->tabs_gui->activateSubTab("show_staff");
357 $nextcmd = "removeFromSuperiors";
358 $paramname = "obj_id";
359 $param = $_GET["obj_id"];
360 break;
361 case "confirmRemoveFromEmployees":
362 $this->tabs_gui->activateSubTab("show_staff");
363 $nextcmd = "removeFromEmployees";
364 $paramname = "obj_id";
365 $param = $_GET["obj_id"];
366 break;
367 }
368 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
369 $confirm = new ilConfirmationGUI();
370 $confirm->setFormAction($this->ctrl->getFormAction($this, $nextcmd));
371 $confirm->setHeaderText($this->lng->txt('orgu_staff_deassign'));
372 $confirm->setConfirm($this->lng->txt('confirm'), $nextcmd);
373 $confirm->setCancel($this->lng->txt('cancel'), 'showStaff');
374 $arrUser = ilObjUser::_lookupName($_GET["obj_id"]);
375 $confirm->addItem(
376 $paramname,
377 $param,
378 $arrUser['lastname'] . ', ' . $arrUser['firstname'] . ' [' . $arrUser['login']
379 . ']',
380 ilUtil::getImagePath('icon_usr.svg')
381 );
382 $this->tpl->setContent($confirm->getHTML());
383 }
384
385
386 public function removeFromSuperiors()
387 {
388 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
389 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
390 $this->ctrl->redirect($this->parent_gui, "");
391 }
392 $this->parent_object->deassignUserFromSuperiorRole($_POST["obj_id"]);
393 //if user is neither employee nor superior, remove orgunit from user->org_units
394 if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getEmployeeRole())) {
395 ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
396 }
397 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
398 $this->ctrl->redirect($this, "showStaff");
399 }
400
401
402 public function removeFromEmployees()
403 {
404 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
405 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
406 $this->ctrl->redirect($this->parent_gui, "");
407 }
408 $this->parent_object->deassignUserFromEmployeeRole($_POST["obj_id"]);
409 //if user is neither employee nor superior, remove orgunit from user->org_units
410 if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getSuperiorRole())) {
411 ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
412 }
413 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
414 $this->ctrl->redirect($this, "showStaff");
415 }
416
417
418 public function removeFromRole()
419 {
420 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
421 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
422 $this->ctrl->redirect($this->parent_gui, "");
423 }
424 $arrObjIdRolId = explode("-", $_POST["obj_id-role_id"]);
425 $this->parent_object->deassignUserFromLocalRole($arrObjIdRolId[1], $arrObjIdRolId[0]);
426 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
427 $this->ctrl->redirect($this, "showOtherRoles");
428 }
429
430
431 public function setTabs()
432 {
433 $this->tabs_gui->addSubTab("show_staff", sprintf($this->lng->txt("local_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaff"));
434 if ($this->ilAccess->checkAccess("view_learning_progress_rec", "", $this->parent_object->getRefId())) {
435 $this->tabs_gui->addSubTab("show_staff_rec", sprintf($this->lng->txt("rec_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaffRec"));
436 }
437 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
438 $this->tabs_gui->addSubTab("show_other_roles", sprintf($this->lng->txt("local_other_roles"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showOtherRoles"));
439 }
440 }
441}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
checkAccess($a_permission, $a_cmd, $a_ref_id, $a_type="", $a_obj_id="", $a_tree_id="")
check access for an object (provide $a_type and $a_obj_id if available for better performance)
Confirmation screen class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _checkAccessStaffRec($ref_id)
static _checkAccessStaff($ref_id)
Class ilObjOrgUnit GUI class.
Class ilObjRole.
static _lookupId($a_user_str)
Lookup id by login.
static _lookupName($a_user_id)
lookup user name
Class ilOrgUnitOtherRolesTableGUI.
Class ilOrgUnitStaffGUI.
__construct(ilObjOrgUnitGUI $parent_gui)
getStaffTableHTML($recursive=false, $table_cmd="showStaff")
Class ilOrgUnitStaffTableGUI.
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
$param
Definition: xapitoken.php:29