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