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