ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLocalUserGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12 
16  protected $tabs_gui;
20  protected $form;
24  protected $toolbar;
28  protected $ctrl;
32  protected $tpl;
36  public $object;
40  protected $lng;
44  protected $ilAccess;
48  //TODO MST 14.11.2013 - we should split this class into ilLocalUserTableGUI and ilLocalUserRoleGUI
49  public function __construct($parent_gui)
50  {
51  global $DIC;
52  $tpl = $DIC['tpl'];
53  $ilCtrl = $DIC['ilCtrl'];
54  $ilTabs = $DIC['ilTabs'];
55  $ilToolbar = $DIC['ilToolbar'];
56  $lng = $DIC['lng'];
57  $rbacsystem = $DIC['rbacsystem'];
58  $ilAccess = $DIC['ilAccess'];
59  $this->tpl = $tpl;
60  $this->ctrl = $ilCtrl;
61  $this->parent_gui = $parent_gui;
62  $this->object = $parent_gui->object;
63  $this->tabs_gui = $this->parent_gui->tabs_gui;
64  $this->toolbar = $ilToolbar;
65  $this->lng = $lng;
66  $this->ilAccess = $ilAccess;
67  $this->lng->loadLanguageModule('user');
68  if (!$rbacsystem->checkAccess("cat_administrate_users", $this->parent_gui->object->getRefId())) {
69  ilUtil::sendFailure($this->lng->txt("msg_no_perm_admin_users"), true);
70  }
71  }
72 
73 
77  public function executeCommand()
78  {
79  $cmd = $this->ctrl->getCmd();
80  switch ($cmd) {
81  case "assignRoles":
82  case "assignSave":
83  $this->tabs_gui->clearTargets();
84  $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass("illocalusergui", 'index'));
85  $this->$cmd();
86  break;
87  default:
88  $this->$cmd();
89  break;
90  }
91 
92  return true;
93  }
94 
95 
100  protected function resetFilter()
101  {
102  $table = new ilUserTableGUI($this, "index", ilUserTableGUI::MODE_LOCAL_USER);
103  $table->resetOffset();
104  $table->resetFilter();
105  $this->index();
106  }
107 
108 
114  protected function applyFilter()
115  {
116  $table = new ilUserTableGUI($this, "index", ilUserTableGUI::MODE_LOCAL_USER);
117  $table->resetOffset();
118  $table->writeFilterToSession();
119  $this->index();
120  }
121 
122 
123  public function index($show_delete = false)
124  {
125  global $DIC;
126  $ilUser = $DIC['ilUser'];
127  $rbacreview = $DIC['rbacreview'];
128  $rbacsystem = $DIC['rbacsystem'];
129  $this->tpl->addBlockfile(
130  'ADM_CONTENT',
131  'adm_content',
132  'tpl.cat_admin_users.html',
133  "Modules/Category"
134  );
135  if (count($rbacreview->getGlobalAssignableRoles())
136  or in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))
137  ) {
138  $this->toolbar->addButton(
139  $this->lng->txt('add_user'),
140  $this->ctrl->getLinkTargetByClass('ilobjusergui', 'create')
141  );
142  $this->toolbar->addButton(
143  $this->lng->txt('import_users'),
144  $this->ctrl->getLinkTargetByClass('ilobjuserfoldergui', 'importUserForm')
145  );
146  } else {
147  ilUtil::sendInfo($this->lng->txt('no_roles_user_can_be_assigned_to'));
148  }
149  if ($show_delete) {
150  $this->tpl->setCurrentBlock("confirm_delete");
151  $this->tpl->setVariable("CONFIRM_FORMACTION", $this->ctrl->getFormAction($this));
152  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt('cancel'));
153  $this->tpl->setVariable("CONFIRM_CMD", 'performDeleteUsers');
154  $this->tpl->setVariable("TXT_CONFIRM", $this->lng->txt('delete'));
155  $this->tpl->parseCurrentBlock();
156  }
157  $table = new ilUserTableGUI($this, 'index', ilUserTableGUI::MODE_LOCAL_USER);
158  $this->tpl->setVariable('USERS_TABLE', $table->getHTML());
159 
160  return true;
161  }
162 
163 
167  protected function addUserAutoCompleteObject()
168  {
169  $auto = new ilUserAutoComplete();
170  $auto->setSearchFields(array('login', 'firstname', 'lastname', 'email'));
171  $auto->enableFieldSearchableCheck(true);
172  $auto->setMoreLinkAvailable(true);
173 
174  if (($_REQUEST['fetchall'])) {
175  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
176  }
177 
178  echo $auto->getList($_REQUEST['term']);
179  exit();
180  }
181 
182 
186  public function performDeleteUsers()
187  {
188  global $DIC;
189  $ilLog = $DIC['ilLog'];
190  $this->checkPermission("cat_administrate_users");
191  foreach ($_POST['user_ids'] as $user_id) {
192  if (!in_array($user_id, ilLocalUser::_getAllUserIds($_GET['ref_id']))) {
193  $ilLog->write(__FILE__ . ":" . __LINE__ . " User with id $user_id could not be found.");
194  ilUtil::sendFailure($this->lng->txt('user_not_found_to_delete'));
195  }
196  if (!$tmp_obj = &ilObjectFactory::getInstanceByObjId($user_id, false)) {
197  continue;
198  }
199  $tmp_obj->delete();
200  }
201  ilUtil::sendSuccess($this->lng->txt('deleted_users'), true);
202  $this->ctrl->redirect($this, 'index');
203 
204  return true;
205  }
206 
207 
208  public function deleteUsers()
209  {
210  $this->checkPermission("cat_administrate_users");
211  if (!count($_POST['id'])) {
212  ilUtil::sendFailure($this->lng->txt('no_users_selected'));
213  $this->index();
214 
215  return true;
216  }
217  $confirm = new ilConfirmationGUI();
218  $confirm->setFormAction($this->ctrl->getFormAction($this));
219  $confirm->setHeaderText($this->lng->txt('sure_delete_selected_users'));
220  $confirm->setConfirm($this->lng->txt('delete'), 'performDeleteUsers');
221  $confirm->setCancel($this->lng->txt('cancel'), 'index');
222  foreach ($_POST['id'] as $user) {
223  $name = ilObjUser::_lookupName($user);
224  $confirm->addItem(
225  'user_ids[]',
226  $user,
227  $name['lastname'] . ', ' . $name['firstname'] . ' [' . $name['login'] . ']'
228  );
229  }
230  $this->tpl->setContent($confirm->getHTML());
231  }
232 
233 
234  public function assignRoles()
235  {
236  global $DIC;
237  $rbacreview = $DIC['rbacreview'];
238  if (!$this->ilAccess->checkAccess("cat_administrate_users", "", $_GET["ref_id"])) {
239  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
240  $this->ctrl->redirect($this, "");
241  }
242  $offset = $_GET["offset"];
243  // init sort_by (unfortunatly sort_by is preset with 'title'
244  if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"])) {
245  $_GET["sort_by"] = "login";
246  }
247  $order = $_GET["sort_by"];
248  $direction = $_GET["sort_order"];
249  if (!isset($_GET['obj_id'])) {
250  ilUtil::sendFailure('no_user_selected');
251  $this->index();
252 
253  return true;
254  }
255  $roles = $this->__getAssignableRoles();
256  $this->tpl->addBlockfile(
257  'ADM_CONTENT',
258  'adm_content',
259  'tpl.cat_role_assignment.html',
260  "Modules/Category"
261  );
262  $ass_roles = $rbacreview->assignedRoles($_GET['obj_id']);
263  $counter = 0;
264  foreach ($roles as $role) {
265  $role_obj = &ilObjectFactory::getInstanceByObjId($role['obj_id']);
266  $disabled = false;
267  $f_result[$counter][] = ilUtil::formCheckbox(
268  in_array($role['obj_id'], $ass_roles) ? 1 : 0,
269  'role_ids[]',
270  $role['obj_id'],
271  $disabled
272  );
273  $f_result[$counter][] = $role_obj->getTitle();
274  $f_result[$counter][] = $role_obj->getDescription() ? $role_obj->getDescription() : '';
275  $f_result[$counter][] = $role['role_type'] == 'global'
276  ?
277  $this->lng->txt('global')
278  :
279  $this->lng->txt('local');
280  unset($role_obj);
281  ++$counter;
282  }
283  $this->__showRolesTable($f_result, "assignRolesObject");
284  }
285 
286 
287  public function assignSave()
288  {
289  global $DIC;
290  $rbacreview = $DIC['rbacreview'];
291  $rbacadmin = $DIC['rbacadmin'];
292  if (!$this->ilAccess->checkAccess("cat_administrate_users", "", $_GET["ref_id"])) {
293  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
294  $this->ctrl->redirect($this, "");
295  }
296  // check hack
297  if (!isset($_GET['obj_id']) or !in_array($_REQUEST['obj_id'], ilLocalUser::_getAllUserIds())) {
298  ilUtil::sendFailure('no_user_selected');
299  $this->index();
300 
301  return true;
302  }
303  $roles = $this->__getAssignableRoles();
304  // check minimum one global role
305  if (!$this->__checkGlobalRoles($_POST['role_ids'])) {
306  ilUtil::sendFailure($this->lng->txt('no_global_role_left'));
307  $this->assignRolesObject();
308 
309  return false;
310  }
311  $new_role_ids = $_POST['role_ids'] ? $_POST['role_ids'] : array();
312  $assigned_roles = $rbacreview->assignedRoles((int) $_REQUEST['obj_id']);
313  foreach ($roles as $role) {
314  if (in_array($role['obj_id'], $new_role_ids) and !in_array($role['obj_id'], $assigned_roles)) {
315  $rbacadmin->assignUser($role['obj_id'], (int) $_REQUEST['obj_id']);
316  }
317  if (in_array($role['obj_id'], $assigned_roles) and !in_array($role['obj_id'], $new_role_ids)) {
318  $rbacadmin->deassignUser($role['obj_id'], (int) $_REQUEST['obj_id']);
319  }
320  }
321  ilUtil::sendSuccess($this->lng->txt('role_assignment_updated'));
322  $this->assignRoles();
323 
324  return true;
325  }
326 
327 
328  public function __checkGlobalRoles($new_assigned)
329  {
330  global $DIC;
331  $rbacreview = $DIC['rbacreview'];
332  $ilUser = $DIC['ilUser'];
333  if (!$this->ilAccess->checkAccess("cat_administrate_users", "", $_GET["ref_id"])) {
334  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
335  $this->ctrl->redirect($this, "");
336  }
337  // return true if it's not a local user
338  $tmp_obj = &ilObjectFactory::getInstanceByObjId($_REQUEST['obj_id']);
339  if ($tmp_obj->getTimeLimitOwner() != $this->object->getRefId() and
340  !in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))
341  ) {
342  return true;
343  }
344  // new assignment by form
345  $new_assigned = $new_assigned ? $new_assigned : array();
346  $assigned = $rbacreview->assignedRoles((int) $_GET['obj_id']);
347  // all assignable globals
348  if (!in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))) {
349  $ga = $rbacreview->getGlobalAssignableRoles();
350  } else {
351  $ga = $rbacreview->getGlobalRolesArray();
352  }
353  $global_assignable = array();
354  foreach ($ga as $role) {
355  $global_assignable[] = $role['obj_id'];
356  }
357  $new_visible_assigned_roles = array_intersect($new_assigned, $global_assignable);
358  $all_assigned_roles = array_intersect($assigned, $rbacreview->getGlobalRoles());
359  $main_assigned_roles = array_diff($all_assigned_roles, $global_assignable);
360  if (!count($new_visible_assigned_roles) and !count($main_assigned_roles)) {
361  return false;
362  }
363 
364  return true;
365  }
366 
367 
368  public function __getAssignableRoles()
369  {
370  global $DIC;
371  $rbacreview = $DIC['rbacreview'];
372  $ilUser = $DIC['ilUser'];
373  // check local user
374  $tmp_obj = &ilObjectFactory::getInstanceByObjId($_REQUEST['obj_id']);
375  // Admin => all roles
376  if (in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))) {
377  $global_roles = $rbacreview->getGlobalRolesArray();
378  } elseif ($tmp_obj->getTimeLimitOwner() == $this->object->getRefId()) {
379  $global_roles = $rbacreview->getGlobalAssignableRoles();
380  } else {
381  $global_roles = array();
382  }
383 
384  return $roles = array_merge($global_roles, $rbacreview->getAssignableChildRoles($this->object->getRefId()));
385  }
386 
387 
388  public function __showRolesTable($a_result_set, $a_from = "")
389  {
390  if (!$this->ilAccess->checkAccess("cat_administrate_users", "", $_GET["ref_id"])) {
391  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
392  $this->ctrl->redirect($this, "");
393  }
394  $tbl = &$this->parent_gui->__initTableGUI();
395  $tpl = &$tbl->getTemplateObject();
396  // SET FORMAACTION
397  $tpl->setCurrentBlock("tbl_form_header");
398  $this->ctrl->setParameter($this, 'obj_id', $_GET['obj_id']);
399  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
400  $tpl->parseCurrentBlock();
401  // SET FOOTER BUTTONS
402  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
403  $tpl->setVariable("BTN_NAME", "assignSave");
404  $tpl->setVariable("BTN_VALUE", $this->lng->txt("change_assignment"));
405  $tpl->setCurrentBlock("tbl_action_row");
406  $tpl->setVariable("TPLPATH", $this->tpl->tplPath);
407  $tpl->parseCurrentBlock();
408  $tmp_obj = &ilObjectFactory::getInstanceByObjId($_GET['obj_id']);
409  $title = $this->lng->txt('role_assignment') . ' (' . $tmp_obj->getFullname() . ')';
410  $tbl->setTitle($title, "icon_role.svg", $this->lng->txt("role_assignment"));
411  $tbl->setHeaderNames(array(
412  '',
413  $this->lng->txt("title"),
414  $this->lng->txt('description'),
415  $this->lng->txt("type"),
416  ));
417  $tbl->setHeaderVars(array(
418  "",
419  "title",
420  "description",
421  "type",
422  ), (get_class($this->parent_gui) == 'ilObjOrgUnitGUI')
423  ? array(
424  "ref_id" => $this->object->getRefId(),
425  "cmd" => "assignRoles",
426  "obj_id" => $_GET['obj_id'],
427  "cmdNode" => $_GET["cmdNode"],
428  "baseClass" => 'ilAdministrationGUI',
429  "admin_mode" => "settings",
430  )
431  : array(
432  "ref_id" => $this->object->getRefId(),
433  "cmd" => "assignRoles",
434  "obj_id" => $_GET['obj_id'],
435  "cmdClass" => "ilobjcategorygui",
436  "baseClass" => 'ilRepositoryGUI',
437  "cmdNode" => $_GET["cmdNode"],
438  ));
439  $tbl->setColumnWidth(array("4%", "35%", "45%", "16%"));
440  $this->set_unlimited = true;
441  $this->parent_gui->__setTableGUIBasicData($tbl, $a_result_set, $a_from, true);
442  $tbl->render();
443  $this->tpl->setVariable('OBJECTS', $tbl->getTemplateObject()->get());
444 
445  return true;
446  }
447 
448 
452  protected function checkPermission($permission)
453  {
454  if (!$this->ilAccess->checkAccess($permission, "", $_GET["ref_id"])) {
455  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
456  $this->ctrl->redirect($this, "");
457  }
458  }
459 }
static _lookupName($a_user_id)
lookup user name
__showRolesTable($a_result_set, $a_from="")
performDeleteUsers()
Delete User.
exit
Definition: login.php:29
$_GET["client_id"]
const SYSTEM_ROLE_ID
Definition: constants.php:27
Class ilLocalUserGUI.
__construct($parent_gui)
Auto completion class for user lists.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
__checkGlobalRoles($new_assigned)
if($format !==null) $name
Definition: metadata.php:230
TableGUI class for user administration.
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
static _getAllUserIds($a_filter=0)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
index($show_delete=false)
applyFilter()
Apply filter.
resetFilter()
Reset filter (note: this function existed before data table filter has been introduced.
addUserAutoCompleteObject()
Show auto complete results.
$ilUser
Definition: imgupload.php:18
$_POST["username"]
checkPermission($permission)
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public
Confirmation screen class.