ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 */
14{
15
19 protected $tabs_gui;
23 protected $toolbar;
27 protected $ctrl;
31 protected $tpl;
35 protected $parent_gui;
39 protected $parent_obj;
43 protected $lng;
47 protected $ilAccess;
51 protected $rbacreview;
52
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
90 public function executeCommand()
91 {
92 $next_class = $this->ctrl->getNextClass($this);
93 $cmd = $this->ctrl->getCmd();
94
95 switch ($next_class) {
96 case 'ilrepositorysearchgui':
97 $repo = new ilRepositorySearchGUI();
98 $this->ctrl->forwardCommand($repo);
99 break;
100 default:
101 switch ($cmd) {
102 case 'showStaff':
103 $this->tabs_gui->activateSubTab("show_staff");
104 $this->showStaff();
105 break;
106 case 'showOtherRoles':
107 $this->tabs_gui->activateSubTab("show_other_roles");
108 $this->showOtherRoles();
109 break;
110 case 'showStaffRec':
111 $this->tabs_gui->activateSubTab("show_staff_rec");
112 $this->showStaffRec();
113 break;
114 case 'confirmRemoveFromRole':
115 case 'confirmRemoveFromEmployees':
116 case 'confirmRemoveFromSuperiors':
117 $this->confirmRemoveUser($cmd);
118 break;
119 case 'addStaff':
120 case 'addOtherRoles':
121 case 'fromSuperiorToEmployee':
122 case 'fromEmployeeToSuperior':
123 case 'removeFromSuperiors':
124 case 'removeFromEmployees':
125 case 'removeFromRole':
126 $this->$cmd();
127 break;
128 default:
129 throw new ilException("Unknown command for command class ilOrgUnitStaffGUI: " . $cmd);
130 break;
131 }
132 break;
133 }
134
135
136 return true;
137 }
138
139 public function showStaff()
140 {
141 if (!ilObjOrgUnitAccess::_checkAccessStaff($this->parent_object->getRefId())) {
142 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
143 $this->ctrl->redirect($this->parent_gui, "");
144 }
145 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
146 $this->addStaffToolbar();
147 }
148 $this->ctrl->setParameter($this, "recursive", false);
149 $this->tpl->setContent($this->getStaffTableHTML(false, "showStaff"));
150 }
151
152
153 public function showOtherRoles()
154 {
155 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
156 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
157 $this->ctrl->redirect($this->parent_gui, "");
158 }
159 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
160 $this->addOtherRolesToolbar();
161 }
162 $this->tpl->setContent($this->getOtherRolesTableHTML());
163 }
164
165
166 public function showStaffRec()
167 {
168 if (!ilObjOrgUnitAccess::_checkAccessStaffRec($this->parent_object->getRefId())) {
169 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
170 $this->ctrl->redirect($this->parent_gui, "");
171 }
172 $this->ctrl->setParameter($this, "recursive", true);
173 $this->tpl->setContent($this->getStaffTableHTML(true, "showStaffRec"));
174 }
175
176
177 protected function addStaffToolbar()
178 {
179 $types = array(
180 "employee" => $this->lng->txt("employee"),
181 "superior" => $this->lng->txt("superior")
182 );
183 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'staff');
184 ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->toolbar, array(
185 'auto_complete_name' => $this->lng->txt('user'),
186 'user_type' => $types,
187 'submit_name' => $this->lng->txt('add')
188 ));
189 }
190
191
192 protected function addOtherRolesToolbar()
193 {
194 $arrLocalRoles = $this->rbacreview->getLocalRoles($this->parent_object->getRefId());
195 $types = array();
196 foreach ($arrLocalRoles as $role_id) {
197 $ilObjRole = new ilObjRole($role_id);
198 if (!preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
199 $types[$role_id] = $ilObjRole->getPresentationTitle();
200 }
201 }
202 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'other');
203 ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->toolbar, array(
204 'auto_complete_name' => $this->lng->txt('user'),
205 'user_type' => $types,
206 'submit_name' => $this->lng->txt('add')
207 ));
208 }
209
210
211 public function addStaff()
212 {
213 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
214 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
215 $this->ctrl->redirect($this->parent_gui, "");
216 }
217
218 $users = explode(',', $_POST['user_login']);
219 $user_ids = array();
220 foreach ($users as $user) {
221 $user_id = ilObjUser::_lookupId($user);
222 if ($user_id) {
223 $user_ids[] = $user_id;
224 }
225 }
226
227 if (!count($user_ids)) {
228 ilUtil::sendFailure($this->lng->txt("user_not_found"), true);
229 $this->ctrl->redirect($this, "showStaff");
230 }
231
232 $user_type = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
233 if ($user_type == "employee") {
234 $this->parent_object->assignUsersToEmployeeRole($user_ids);
235 } elseif ($user_type == "superior") {
236 $this->parent_object->assignUsersToSuperiorRole($user_ids);
237 } else {
238 throw new Exception("The post request didn't specify wether the user_ids should be assigned to the employee or the superior role.");
239 }
240
241 ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
242 $this->ctrl->redirect($this, "showStaff");
243 }
244
245 public function addOtherRoles()
246 {
247 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
248 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
249 $this->ctrl->redirect($this->parent_gui, "");
250 }
251
252 $users = explode(',', $_POST['user_login']);
253 $user_ids = array();
254 foreach ($users as $user) {
255 $user_id = ilObjUser::_lookupId($user);
256 if ($user_id) {
257 $user_ids[] = $user_id;
258 }
259 }
260 $role_id = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
261 foreach ($user_ids as $user_id) {
262 $this->parent_object->assignUserToLocalRole($role_id, $user_id);
263 }
264 ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
265 $this->ctrl->redirect($this, "showOtherRoles");
266 }
267
268
275 public function getStaffTableHTML($recursive = false, $table_cmd = "showStaff")
276 {
277 global $DIC;
278 $lng = $DIC['lng'];
279 $rbacreview = $DIC['rbacreview'];
280 $superior_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "superior", $recursive);
281 $superior_table->parseData();
282 $superior_table->setTitle($lng->txt("il_orgu_superior"));
283 $employee_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "employee", $recursive);
284 $employee_table->parseData();
285 $employee_table->setTitle($lng->txt("il_orgu_employee"));
286
287 return $superior_table->getHTML() . $employee_table->getHTML();
288 }
289
290
291 public function getOtherRolesTableHTML()
292 {
293 global $DIC;
294 $lng = $DIC['lng'];
295 $rbacreview = $DIC['rbacreview'];
296 $arrLocalRoles = $rbacreview->getLocalRoles($this->parent_object->getRefId());
297 $html = "";
298 foreach ($arrLocalRoles as $role_id) {
299 $ilObjRole = new ilObjRole($role_id);
300 if (!preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
301 $other_roles_table = new ilOrgUnitOtherRolesTableGUI($this, 'other_role_' . $role_id, $role_id);
302 $other_roles_table->readData();
303 $html .= $other_roles_table->getHTML() . "<br/>";
304 }
305 }
306 if (!$html) {
307 $html = $lng->txt("no_roles");
308 }
309
310 return $html;
311 }
312
313 public function fromSuperiorToEmployee()
314 {
315 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
316 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
317 $this->ctrl->redirect($this->parent_gui, "");
318 }
319 $this->parent_object->deassignUserFromSuperiorRole($_GET["obj_id"]);
320 $this->parent_object->assignUsersToEmployeeRole(array( $_GET["obj_id"] ));
321 ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
322 $this->ctrl->redirect($this, "showStaff");
323 }
324
325
326 public function fromEmployeeToSuperior()
327 {
328 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
329 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
330 $this->ctrl->redirect($this->parent_gui, "");
331 }
332 $this->parent_object->deassignUserFromEmployeeRole($_GET["obj_id"]);
333 $this->parent_object->assignUsersToSuperiorRole(array( $_GET["obj_id"] ));
334 ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
335 $this->ctrl->redirect($this, "showStaff");
336 }
337
338 public function confirmRemoveUser($cmd)
339 {
340 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
341 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
342 $this->ctrl->redirect($this->parent_gui, "");
343 }
344 switch ($cmd) {
345 case "confirmRemoveFromRole":
346 $this->tabs_gui->activateSubTab("show_other_roles");
347 $nextcmd = "removeFromRole";
348 $paramname = "obj_id-role_id";
349 $param = $_GET["obj_id"] . '-' . $_GET["role_id"];
350 break;
351 case "confirmRemoveFromSuperiors":
352 $this->tabs_gui->activateSubTab("show_staff");
353 $nextcmd = "removeFromSuperiors";
354 $paramname = "obj_id";
355 $param = $_GET["obj_id"];
356 break;
357 case "confirmRemoveFromEmployees":
358 $this->tabs_gui->activateSubTab("show_staff");
359 $nextcmd = "removeFromEmployees";
360 $paramname = "obj_id";
361 $param = $_GET["obj_id"];
362 break;
363 }
364 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
365 $confirm = new ilConfirmationGUI();
366 $confirm->setFormAction($this->ctrl->getFormAction($this, $nextcmd));
367 $confirm->setHeaderText($this->lng->txt('orgu_staff_deassign'));
368 $confirm->setConfirm($this->lng->txt('confirm'), $nextcmd);
369 $confirm->setCancel($this->lng->txt('cancel'), 'showStaff');
370 $arrUser = ilObjUser::_lookupName($_GET["obj_id"]);
371 $confirm->addItem(
372 $paramname,
373 $param,
374 $arrUser['lastname'] . ', ' . $arrUser['firstname'] . ' [' . $arrUser['login']
375 . ']',
376 ilUtil::getImagePath('icon_usr.svg')
377 );
378 $this->tpl->setContent($confirm->getHTML());
379 }
380
381 public function removeFromSuperiors()
382 {
383 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
384 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
385 $this->ctrl->redirect($this->parent_gui, "");
386 }
387 $this->parent_object->deassignUserFromSuperiorRole($_POST["obj_id"]);
388 //if user is neither employee nor superior, remove orgunit from user->org_units
389 if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getEmployeeRole())) {
390 ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
391 }
392 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
393 $this->ctrl->redirect($this, "showStaff");
394 }
395
396
397 public function removeFromEmployees()
398 {
399 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
400 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
401 $this->ctrl->redirect($this->parent_gui, "");
402 }
403 $this->parent_object->deassignUserFromEmployeeRole($_POST["obj_id"]);
404 //if user is neither employee nor superior, remove orgunit from user->org_units
405 if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getSuperiorRole())) {
406 ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
407 }
408 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
409 $this->ctrl->redirect($this, "showStaff");
410 }
411
412
413 public function removeFromRole()
414 {
415 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
416 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
417 $this->ctrl->redirect($this->parent_gui, "");
418 }
419 $arrObjIdRolId = explode("-", $_POST["obj_id-role_id"]);
420 $this->parent_object->deassignUserFromLocalRole($arrObjIdRolId[1], $arrObjIdRolId[0]);
421 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
422 $this->ctrl->redirect($this, "showOtherRoles");
423 }
424
425
426 public function setTabs()
427 {
428 $this->tabs_gui->addSubTab("show_staff", sprintf($this->lng->txt("local_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaff"));
429 if ($this->ilAccess->checkAccess("view_learning_progress_rec", "", $this->parent_object->getRefId())) {
430 $this->tabs_gui->addSubTab("show_staff_rec", sprintf($this->lng->txt("rec_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaffRec"));
431 }
432 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
433 $this->tabs_gui->addSubTab("show_other_roles", sprintf($this->lng->txt("local_other_roles"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showOtherRoles"));
434 }
435 }
436}
sprintf('%.4f', $callTime)
$users
Definition: authpage.php:44
$_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.
Base class for ILIAS Exception handling.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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)
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7