ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 */
3require_once("./Services/Search/classes/class.ilRepositorySearchGUI.php");
4require_once("class.ilOrgUnitStaffTableGUI.php");
5require_once("class.ilOrgUnitOtherRolesTableGUI.php");
17
21 protected $tabs_gui;
25 protected $toolbar;
29 protected $ctrl;
33 protected $tpl;
37 protected $parent_gui;
41 protected $parent_obj;
45 protected $lng;
49 protected $ilAccess;
53 protected $rbacreview;
54
55
56
61 global $tpl, $ilCtrl, $ilTabs, $lng, $ilAccess, $ilToolbar, $rbacreview;
62
63 $this->tpl = $tpl;
64 $this->ctrl = $ilCtrl;
65 $this->parent_gui = $parent_gui;
66 $this->parent_object = $parent_gui->object;
67 $this->tabs_gui = $this->parent_gui->tabs_gui;
68 $this->toolbar = $ilToolbar;
69 $this->lng = $lng;
70 $this->ilAccess = $ilAccess;
71 $this->toolbar = $ilToolbar;
72 $this->rbacreview = $rbacreview;
73
74 $this->tabs_gui->setTabActive("orgu_staff");
75 $this->setTabs();
76 }
77
84 public function executeCommand()
85 {
86 $next_class = $this->ctrl->getNextClass($this);
87 $cmd = $this->ctrl->getCmd();
88
89 switch ($next_class) {
90 case 'ilrepositorysearchgui':
91 switch ($cmd) {
92 case 'addUserFromAutoComplete':
93 if ($_GET['addusertype'] == "staff") {
94 $this->addStaff();
95 } elseif ($_GET['addusertype'] == "other") {
96 $this->addOtherRoles();
97 }
98 break;
99 default:
100 $repo = new ilRepositorySearchGUI();
101 $this->ctrl->forwardCommand($repo);
102 break;
103 }
104 break;
105 default:
106 switch ($cmd) {
107 case 'showStaff':
108 $this->tabs_gui->activateSubTab("show_staff");
109 $this->showStaff();
110 break;
111 case 'showOtherRoles':
112 $this->tabs_gui->activateSubTab("show_other_roles");
113 $this->showOtherRoles();
114 break;
115 case 'showStaffRec':
116 $this->tabs_gui->activateSubTab("show_staff_rec");
117 $this->showStaffRec();
118 break;
119 case 'confirmRemoveFromRole':
120 case 'confirmRemoveFromEmployees':
121 case 'confirmRemoveFromSuperiors':
122 $this->confirmRemoveUser($cmd);
123 break;
124 case 'addStaff':
125 case 'addOtherRoles':
126 case 'fromSuperiorToEmployee':
127 case 'fromEmployeeToSuperior':
128 case 'removeFromSuperiors':
129 case 'removeFromEmployees':
130 case 'removeFromRole':
131 $this->$cmd();
132 break;
133 default:
134 throw new ilException("Unknown command for command class ilOrgUnitStaffGUI: ".$cmd);
135 break;
136 }
137 break;
138 }
139
140
141 return true;
142 }
143
144 public function showStaff() {
145 if(!ilObjOrgUnitAccess::_checkAccessStaff($this->parent_object->getRefId()))
146 {
147 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
148 $this->ctrl->redirect($this->parent_gui, "");
149 }
150 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
151 $this->addStaffToolbar();
152 }
153 $this->ctrl->setParameter($this, "recursive", false);
154 $this->tpl->setContent($this->getStaffTableHTML(false, "showStaff"));
155 }
156
157
158 public function showOtherRoles() {
159 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
160 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
161 $this->ctrl->redirect($this->parent_gui, "");
162 }
163 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
164 $this->addOtherRolesToolbar();
165 }
166 $this->tpl->setContent($this->getOtherRolesTableHTML());
167 }
168
169
170 public function showStaffRec() {
171 if(!ilObjOrgUnitAccess::_checkAccessStaffRec($this->parent_object->getRefId()))
172 {
173 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
174 $this->ctrl->redirect($this->parent_gui, "");
175 }
176 $this->ctrl->setParameter($this, "recursive", true);
177 $this->tpl->setContent($this->getStaffTableHTML(true, "showStaffRec"));
178 }
179
180
181 protected function addStaffToolbar() {
182 $types = array(
183 "employee" => $this->lng->txt("employee"),
184 "superior" => $this->lng->txt("superior")
185 );
186 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'staff');
187 ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->toolbar, array(
188 'auto_complete_name' => $this->lng->txt('user'),
189 'user_type' => $types,
190 'submit_name' => $this->lng->txt('add')
191 ));
192 }
193
194
195 protected function addOtherRolesToolbar() {
196 $arrLocalRoles = $this->rbacreview->getLocalRoles($this->parent_object->getRefId());
197 $types = array();
198 foreach ($arrLocalRoles as $role_id) {
199 $ilObjRole = new ilObjRole($role_id);
200 if (! preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
201 $types[$role_id] = $ilObjRole->getPresentationTitle();
202 }
203 }
204 $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'other');
205 ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->toolbar, array(
206 'auto_complete_name' => $this->lng->txt('user'),
207 'user_type' => $types,
208 'submit_name' => $this->lng->txt('add')
209 ));
210 }
211
212
213 public function addStaff() {
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 ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
242 $this->ctrl->redirect($this,"showStaff");
243 }
244
245
246 public function addOtherRoles() {
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 global $lng, $rbacreview;
277 $superior_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "superior", $recursive);
278 $superior_table->parseData();
279 $superior_table->setTitle($lng->txt("il_orgu_superior"));
280 $employee_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "employee", $recursive);
281 $employee_table->parseData();
282 $employee_table->setTitle($lng->txt("il_orgu_employee"));
283
284 return $superior_table->getHTML() . $employee_table->getHTML();
285 }
286
287
288 public function getOtherRolesTableHTML() {
289 global $lng, $rbacreview;
290 $arrLocalRoles = $rbacreview->getLocalRoles($this->parent_object->getRefId());
291 $html = "";
292 foreach ($arrLocalRoles as $role_id) {
293 $ilObjRole = new ilObjRole($role_id);
294 if (! preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
295 $other_roles_table = new ilOrgUnitOtherRolesTableGUI($this, 'other_role_' . $role_id, $role_id);
296 $other_roles_table->readData();
297 $html .= $other_roles_table->getHTML() . "<br/>";
298 }
299 }
300 if (! $html) {
301 $html = $lng->txt("no_roles");
302 }
303
304 return $html;
305 }
306
307 public function fromSuperiorToEmployee() {
308 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
309 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
310 $this->ctrl->redirect($this->parent_gui, "");
311 }
312 $this->parent_object->deassignUserFromSuperiorRole($_GET["obj_id"]);
313 $this->parent_object->assignUsersToEmployeeRole(array( $_GET["obj_id"] ));
314 ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
315 $this->ctrl->redirect($this, "showStaff");
316 }
317
318
319 public function fromEmployeeToSuperior() {
320 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
321 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
322 $this->ctrl->redirect($this->parent_gui, "");
323 }
324 $this->parent_object->deassignUserFromEmployeeRole($_GET["obj_id"]);
325 $this->parent_object->assignUsersToSuperiorRole(array( $_GET["obj_id"] ));
326 ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
327 $this->ctrl->redirect($this, "showStaff");
328 }
329
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 switch ($cmd) {
336 case "confirmRemoveFromRole":
337 $this->tabs_gui->activateSubTab("show_other_roles");
338 $nextcmd = "removeFromRole";
339 $paramname = "obj_id-role_id";
340 $param = $_GET["obj_id"] . '-' . $_GET["role_id"];
341 break;
342 case "confirmRemoveFromSuperiors":
343 $this->tabs_gui->activateSubTab("show_staff");
344 $nextcmd = "removeFromSuperiors";
345 $paramname = "obj_id";
346 $param = $_GET["obj_id"];
347 break;
348 case "confirmRemoveFromEmployees":
349 $this->tabs_gui->activateSubTab("show_staff");
350 $nextcmd = "removeFromEmployees";
351 $paramname = "obj_id";
352 $param = $_GET["obj_id"];
353 break;
354 }
355 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
356 $confirm = new ilConfirmationGUI();
357 $confirm->setFormAction($this->ctrl->getFormAction($this, $nextcmd));
358 $confirm->setHeaderText($this->lng->txt('orgu_staff_deassign'));
359 $confirm->setConfirm($this->lng->txt('confirm'), $nextcmd);
360 $confirm->setCancel($this->lng->txt('cancel'), 'showStaff');
361 $arrUser = ilObjUser::_lookupName($_GET["obj_id"]);
362 $confirm->addItem($paramname, $param,
363 $arrUser['lastname'] . ', ' . $arrUser['firstname'] . ' [' . $arrUser['login']
364 . ']', ilUtil::getImagePath('icon_usr.svg'));
365 $this->tpl->setContent($confirm->getHTML());
366 }
367
368 public function removeFromSuperiors() {
369 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
370 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
371 $this->ctrl->redirect($this->parent_gui, "");
372 }
373 $this->parent_object->deassignUserFromSuperiorRole($_POST["obj_id"]);
374 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
375 $this->ctrl->redirect($this, "showStaff");
376 }
377
378
379 public function removeFromEmployees() {
380 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
381 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
382 $this->ctrl->redirect($this->parent_gui, "");
383 }
384 $this->parent_object->deassignUserFromEmployeeRole($_POST["obj_id"]);
385 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
386 $this->ctrl->redirect($this, "showStaff");
387 }
388
389
390 public function removeFromRole() {
391 if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
392 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
393 $this->ctrl->redirect($this->parent_gui, "");
394 }
395 $arrObjIdRolId = explode("-", $_POST["obj_id-role_id"]);
396 $this->parent_object->deassignUserFromLocalRole($arrObjIdRolId[1], $arrObjIdRolId[0]);
397 ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
398 $this->ctrl->redirect($this, "showOtherRoles");
399 }
400
401
402 public function setTabs() {
403 $this->tabs_gui->addSubTab("show_staff", sprintf($this->lng->txt("local_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaff"));
404 if ($this->ilAccess->checkAccess("view_learning_progress_rec", "", $this->parent_object->getRefId())) {
405 $this->tabs_gui->addSubTab("show_staff_rec", sprintf($this->lng->txt("rec_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaffRec"));
406 }
407 if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
408 $this->tabs_gui->addSubTab("show_other_roles", sprintf($this->lng->txt("local_other_roles"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showOtherRoles"));
409 }
410 }
411
412}
413?>
$_GET["client_id"]
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)
$_POST['username']
Definition: cron.php:12
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35