ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 require_once("./Services/Search/classes/class.ilRepositorySearchGUI.php");
4 require_once("class.ilOrgUnitStaffTableGUI.php");
5 require_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 $DIC;
62  $tpl = $DIC['tpl'];
63  $ilCtrl = $DIC['ilCtrl'];
64  $ilTabs = $DIC['ilTabs'];
65  $lng = $DIC['lng'];
66  $ilAccess = $DIC['ilAccess'];
67  $ilToolbar = $DIC['ilToolbar'];
68  $rbacreview = $DIC['rbacreview'];
69 
70  $this->tpl = $tpl;
71  $this->ctrl = $ilCtrl;
72  $this->parent_gui = $parent_gui;
73  $this->parent_object = $parent_gui->object;
74  $this->tabs_gui = $this->parent_gui->tabs_gui;
75  $this->toolbar = $ilToolbar;
76  $this->lng = $lng;
77  $this->ilAccess = $ilAccess;
78  $this->toolbar = $ilToolbar;
79  $this->rbacreview = $rbacreview;
80 
81  $this->tabs_gui->setTabActive("orgu_staff");
82  $this->setTabs();
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  switch ($cmd) {
99  case 'addUserFromAutoComplete':
100  if ($_GET['addusertype'] == "staff") {
101  $this->addStaff();
102  } elseif ($_GET['addusertype'] == "other") {
103  $this->addOtherRoles();
104  }
105  break;
106  default:
107  $repo = new ilRepositorySearchGUI();
108  $this->ctrl->forwardCommand($repo);
109  break;
110  }
111  break;
112  default:
113  switch ($cmd) {
114  case 'showStaff':
115  $this->tabs_gui->activateSubTab("show_staff");
116  $this->showStaff();
117  break;
118  case 'showOtherRoles':
119  $this->tabs_gui->activateSubTab("show_other_roles");
120  $this->showOtherRoles();
121  break;
122  case 'showStaffRec':
123  $this->tabs_gui->activateSubTab("show_staff_rec");
124  $this->showStaffRec();
125  break;
126  case 'confirmRemoveFromRole':
127  case 'confirmRemoveFromEmployees':
128  case 'confirmRemoveFromSuperiors':
129  $this->confirmRemoveUser($cmd);
130  break;
131  case 'addStaff':
132  case 'addOtherRoles':
133  case 'fromSuperiorToEmployee':
134  case 'fromEmployeeToSuperior':
135  case 'removeFromSuperiors':
136  case 'removeFromEmployees':
137  case 'removeFromRole':
138  $this->$cmd();
139  break;
140  default:
141  throw new ilException("Unknown command for command class ilOrgUnitStaffGUI: ".$cmd);
142  break;
143  }
144  break;
145  }
146 
147 
148  return true;
149  }
150 
151  public function showStaff() {
152  if(!ilObjOrgUnitAccess::_checkAccessStaff($this->parent_object->getRefId()))
153  {
154  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
155  $this->ctrl->redirect($this->parent_gui, "");
156  }
157  if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
158  $this->addStaffToolbar();
159  }
160  $this->ctrl->setParameter($this, "recursive", false);
161  $this->tpl->setContent($this->getStaffTableHTML(false, "showStaff"));
162  }
163 
164 
165  public function showOtherRoles() {
166  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
167  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
168  $this->ctrl->redirect($this->parent_gui, "");
169  }
170  if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
171  $this->addOtherRolesToolbar();
172  }
173  $this->tpl->setContent($this->getOtherRolesTableHTML());
174  }
175 
176 
177  public function showStaffRec() {
178  if(!ilObjOrgUnitAccess::_checkAccessStaffRec($this->parent_object->getRefId()))
179  {
180  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
181  $this->ctrl->redirect($this->parent_gui, "");
182  }
183  $this->ctrl->setParameter($this, "recursive", true);
184  $this->tpl->setContent($this->getStaffTableHTML(true, "showStaffRec"));
185  }
186 
187 
188  protected function addStaffToolbar() {
189  $types = array(
190  "employee" => $this->lng->txt("employee"),
191  "superior" => $this->lng->txt("superior")
192  );
193  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'staff');
195  'auto_complete_name' => $this->lng->txt('user'),
196  'user_type' => $types,
197  'submit_name' => $this->lng->txt('add')
198  ));
199  }
200 
201 
202  protected function addOtherRolesToolbar() {
203  $arrLocalRoles = $this->rbacreview->getLocalRoles($this->parent_object->getRefId());
204  $types = array();
205  foreach ($arrLocalRoles as $role_id) {
206  $ilObjRole = new ilObjRole($role_id);
207  if (! preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
208  $types[$role_id] = $ilObjRole->getPresentationTitle();
209  }
210  }
211  $this->ctrl->setParameterByClass('ilRepositorySearchGUI', 'addusertype', 'other');
213  'auto_complete_name' => $this->lng->txt('user'),
214  'user_type' => $types,
215  'submit_name' => $this->lng->txt('add')
216  ));
217  }
218 
219 
220  public function addStaff() {
221  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
222  ilUtil::sendFailure($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 
235  if(!count($user_ids)) {
236  ilUtil::sendFailure($this->lng->txt("user_not_found"), true);
237  $this->ctrl->redirect($this,"showStaff");
238  }
239 
240  $user_type = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
241  if ($user_type == "employee") {
242  $this->parent_object->assignUsersToEmployeeRole($user_ids);
243  } elseif ($user_type == "superior") {
244  $this->parent_object->assignUsersToSuperiorRole($user_ids);
245  } else {
246  throw new Exception("The post request didn't specify wether the user_ids should be assigned to the employee or the superior role.");
247  }
248 
249  ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
250  $this->ctrl->redirect($this,"showStaff");
251  }
252 
253  public function addOtherRoles() {
254  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
255  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
256  $this->ctrl->redirect($this->parent_gui, "");
257  }
258 
259  $users = explode(',', $_POST['user_login']);
260  $user_ids = array();
261  foreach ($users as $user) {
262  $user_id = ilObjUser::_lookupId($user);
263  if ($user_id) {
264  $user_ids[] = $user_id;
265  }
266  }
267  $role_id = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
268  foreach ($user_ids as $user_id) {
269  $this->parent_object->assignUserToLocalRole($role_id, $user_id);
270  }
271  ilUtil::sendSuccess($this->lng->txt("users_successfuly_added"), true);
272  $this->ctrl->redirect($this,"showOtherRoles");
273  }
274 
275 
282  public function getStaffTableHTML($recursive = false, $table_cmd = "showStaff") {
283  global $DIC;
284  $lng = $DIC['lng'];
285  $rbacreview = $DIC['rbacreview'];
286  $superior_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "superior", $recursive);
287  $superior_table->parseData();
288  $superior_table->setTitle($lng->txt("il_orgu_superior"));
289  $employee_table = new ilOrgUnitStaffTableGUI($this, $table_cmd, "employee", $recursive);
290  $employee_table->parseData();
291  $employee_table->setTitle($lng->txt("il_orgu_employee"));
292 
293  return $superior_table->getHTML() . $employee_table->getHTML();
294  }
295 
296 
297  public function getOtherRolesTableHTML() {
298  global $DIC;
299  $lng = $DIC['lng'];
300  $rbacreview = $DIC['rbacreview'];
301  $arrLocalRoles = $rbacreview->getLocalRoles($this->parent_object->getRefId());
302  $html = "";
303  foreach ($arrLocalRoles as $role_id) {
304  $ilObjRole = new ilObjRole($role_id);
305  if (! preg_match("/il_orgu_/", $ilObjRole->getUntranslatedTitle())) {
306  $other_roles_table = new ilOrgUnitOtherRolesTableGUI($this, 'other_role_' . $role_id, $role_id);
307  $other_roles_table->readData();
308  $html .= $other_roles_table->getHTML() . "<br/>";
309  }
310  }
311  if (! $html) {
312  $html = $lng->txt("no_roles");
313  }
314 
315  return $html;
316  }
317 
318  public function fromSuperiorToEmployee() {
319  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
320  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
321  $this->ctrl->redirect($this->parent_gui, "");
322  }
323  $this->parent_object->deassignUserFromSuperiorRole($_GET["obj_id"]);
324  $this->parent_object->assignUsersToEmployeeRole(array( $_GET["obj_id"] ));
325  ilUtil::sendSuccess($this->lng->txt("user_changed_successful"), true);
326  $this->ctrl->redirect($this, "showStaff");
327  }
328 
329 
330  public function fromEmployeeToSuperior() {
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 
342  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
343  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
344  $this->ctrl->redirect($this->parent_gui, "");
345  }
346  switch ($cmd) {
347  case "confirmRemoveFromRole":
348  $this->tabs_gui->activateSubTab("show_other_roles");
349  $nextcmd = "removeFromRole";
350  $paramname = "obj_id-role_id";
351  $param = $_GET["obj_id"] . '-' . $_GET["role_id"];
352  break;
353  case "confirmRemoveFromSuperiors":
354  $this->tabs_gui->activateSubTab("show_staff");
355  $nextcmd = "removeFromSuperiors";
356  $paramname = "obj_id";
357  $param = $_GET["obj_id"];
358  break;
359  case "confirmRemoveFromEmployees":
360  $this->tabs_gui->activateSubTab("show_staff");
361  $nextcmd = "removeFromEmployees";
362  $paramname = "obj_id";
363  $param = $_GET["obj_id"];
364  break;
365  }
366  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
367  $confirm = new ilConfirmationGUI();
368  $confirm->setFormAction($this->ctrl->getFormAction($this, $nextcmd));
369  $confirm->setHeaderText($this->lng->txt('orgu_staff_deassign'));
370  $confirm->setConfirm($this->lng->txt('confirm'), $nextcmd);
371  $confirm->setCancel($this->lng->txt('cancel'), 'showStaff');
372  $arrUser = ilObjUser::_lookupName($_GET["obj_id"]);
373  $confirm->addItem($paramname, $param,
374  $arrUser['lastname'] . ', ' . $arrUser['firstname'] . ' [' . $arrUser['login']
375  . ']', ilUtil::getImagePath('icon_usr.svg'));
376  $this->tpl->setContent($confirm->getHTML());
377  }
378 
379  public function removeFromSuperiors() {
380 
381  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
382  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
383  $this->ctrl->redirect($this->parent_gui, "");
384  }
385  $this->parent_object->deassignUserFromSuperiorRole($_POST["obj_id"]);
386  //if user is neither employee nor superior, remove orgunit from user->org_units
387  // The method ilObjUser::_removeOrgUnit is no longer available, see #20428
388  // if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getEmployeeRole())) {
389  // ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
390  // }
391  ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
392  $this->ctrl->redirect($this, "showStaff");
393  }
394 
395 
396  public function removeFromEmployees() {
397  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
398  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
399  $this->ctrl->redirect($this->parent_gui, "");
400  }
401  $this->parent_object->deassignUserFromEmployeeRole($_POST["obj_id"]);
402  //if user is neither employee nor superior, remove orgunit from user->org_units
403  // The method ilObjUser::_removeOrgUnit is no longer available, see #20428
404  // if (!$this->rbacreview->isAssigned($_POST["obj_id"], $this->parent_object->getSuperiorRole())) {
405  // ilObjUser::_removeOrgUnit($_POST["obj_id"], $this->parent_object->getRefId());
406  // }
407  ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
408  $this->ctrl->redirect($this, "showStaff");
409  }
410 
411 
412  public function removeFromRole() {
413  if (!$this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
414  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
415  $this->ctrl->redirect($this->parent_gui, "");
416  }
417  $arrObjIdRolId = explode("-", $_POST["obj_id-role_id"]);
418  $this->parent_object->deassignUserFromLocalRole($arrObjIdRolId[1], $arrObjIdRolId[0]);
419  ilUtil::sendSuccess($this->lng->txt("deassign_user_successful"), true);
420  $this->ctrl->redirect($this, "showOtherRoles");
421  }
422 
423 
424  public function setTabs() {
425  $this->tabs_gui->addSubTab("show_staff", sprintf($this->lng->txt("local_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaff"));
426  if ($this->ilAccess->checkAccess("view_learning_progress_rec", "", $this->parent_object->getRefId())) {
427  $this->tabs_gui->addSubTab("show_staff_rec", sprintf($this->lng->txt("rec_staff"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showStaffRec"));
428  }
429  if ($this->ilAccess->checkAccess("write", "", $this->parent_object->getRefId())) {
430  $this->tabs_gui->addSubTab("show_other_roles", sprintf($this->lng->txt("local_other_roles"), $this->parent_object->getTitle()), $this->ctrl->getLinkTarget($this, "showOtherRoles"));
431  }
432  }
433 
434 }
435 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilObjRole.
static _lookupName($a_user_id)
lookup user name
Base class for ILIAS Exception handling.
$_GET["client_id"]
static _checkAccessStaff($ref_id)
$cmd
Definition: sahs_server.php:35
static _lookupId($a_user_str)
Lookup id by login.
Class ilObjOrgUnit GUI class.
__construct(ilObjOrgUnitGUI $parent_gui)
global $ilCtrl
Definition: ilias.php:18
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Class ilOrgUnitStaffTableGUI.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilOrgUnitOtherRolesTableGUI.
Class ilOrgUnitStaffGUI.
global $DIC
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
getStaffTableHTML($recursive=false, $table_cmd="showStaff")
$_POST["username"]
$html
Definition: example_001.php:87
static _checkAccessStaffRec($ref_id)
Confirmation screen class.