ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUserTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
16 {
17  const MODE_USER_FOLDER = 1;
18  const MODE_LOCAL_USER = 2;
19 
20  private $mode = null;
21  private $user_folder_id = 0;
22 
26  function __construct($a_parent_obj, $a_parent_cmd, $a_mode = self::MODE_USER_FOLDER)
27  {
28  global $ilCtrl, $lng, $ilAccess, $lng, $rbacsystem;
29 
30  $this->user_folder_id = $a_parent_obj->object->getRefId();
31 
32  $this->setMode($a_mode);
33  $this->setId("user".$this->getUserFolderId());
34 
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36 // $this->setTitle($this->lng->txt("users"));
37 
38  $this->addColumn("", "", "1", true);
39  $this->addColumn($this->lng->txt("login"), "login");
40 
41  foreach ($this->getSelectedColumns() as $c)
42  {
43  $this->addColumn($this->lng->txt($c), $c);
44  }
45 
46  if($this->getMode() == self::MODE_LOCAL_USER)
47  {
48  $this->addColumn($this->lng->txt('context'),'time_limit_owner');
49  $this->addColumn($this->lng->txt('role_assignment'));
50  }
51 
52  $this->setShowRowsSelector(true);
53  $this->setExternalSorting(true);
54  $this->setExternalSegmentation(true);
55  $this->setEnableHeader(true);
56  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj, "applyFilter"));
57  $this->setRowTemplate("tpl.user_list_row.html", "Services/User");
58  //$this->disable("footer");
59  $this->setEnableTitle(true);
60  $this->initFilter();
61  $this->setFilterCommand("applyFilter");
62  $this->setDefaultOrderField("login");
63  $this->setDefaultOrderDirection("asc");
64 
65  $this->setSelectAllCheckbox("id[]");
66  $this->setTopCommands(true);
67 
68 
69  if($this->getMode() == self::MODE_USER_FOLDER)
70  {
71  if ($rbacsystem->checkAccess('delete', $a_parent_obj->object->getRefId()))
72  {
73  $this->addMultiCommand("deleteUsers", $lng->txt("delete"));
74  }
75  $this->addMultiCommand("activateUsers", $lng->txt("activate"));
76  $this->addMultiCommand("deactivateUsers", $lng->txt("deactivate"));
77  $this->addMultiCommand("restrictAccess", $lng->txt("accessRestrict"));
78  $this->addMultiCommand("freeAccess", $lng->txt("accessFree"));
79  $this->addMultiCommand("exportUsers", $lng->txt("export"));
80  }
81  else
82  {
83  $this->addMultiCommand("deleteUsers", $lng->txt("delete"));
84  }
85  $this->getItems();
86  }
87 
88  protected function setMode($a_mode)
89  {
90  $this->mode = $a_mode;
91  }
92 
93  protected function getMode()
94  {
95  return $this->mode;
96  }
97 
98  protected function getUserFolderId()
99  {
100  return $this->user_folder_id;
101  }
102 
103 
104 
112  {
113  global $lng;
114 
115  include_once("./Services/User/classes/class.ilUserProfile.php");
116  $up = new ilUserProfile();
117  $up->skipGroup("preferences");
118  $up->skipGroup("settings");
119 
120  // default fields
121  $cols = array();
122 
123  // first and last name cannot be hidden
124  $cols["firstname"] = array(
125  "txt" => $lng->txt("firstname"),
126  "default" => true);
127  $cols["lastname"] = array(
128  "txt" => $lng->txt("lastname"),
129  "default" => true);
130 
131  if($this->getMode() == self::MODE_USER_FOLDER)
132  {
133  $ufs = $up->getStandardFields();
134 
135  $cols["access_until"] = array(
136  "txt" => $lng->txt("access_until"),
137  "default" => true);
138  $cols["last_login"] = array(
139  "txt" => $lng->txt("last_login"),
140  "default" => true);
141  }
142  else
143  {
144  $ufs = $up->getLocalUserAdministrationFields();
145  }
146 
147  // email should be the 1st "optional" field (can be hidden)
148  if(isset($ufs["email"]))
149  {
150  $cols["email"] = array(
151  "txt" => $lng->txt("email"),
152  "default" => true);
153  }
154 
155  // other user profile fields
156  foreach ($ufs as $f => $fd)
157  {
158  if (!isset($cols[$f]) && !$fd["lists_hide"])
159  {
160  $cols[$f] = array(
161  "txt" => $lng->txt($f),
162  "default" => false);
163  }
164  }
165 
166  // fields that are always shown
167  unset($cols["username"]);
168 
169  return $cols;
170  }
171 
175  function getItems()
176  {
177  global $lng;
178 //if ($GLOBALS["kk"]++ == 1) nj();
179 
180  $this->determineOffsetAndOrder();
181 
182  if($this->getMode() == self::MODE_USER_FOLDER)
183  {
184  // All accessible users
185  include_once './Services/User/classes/class.ilLocalUser.php';
186  $user_filter = ilLocalUser::_getFolderIds();
187  }
188  else
189  {
190  if($this->filter['time_limit_owner'])
191  {
192  $user_filter = array($this->filter['time_limit_owner']);
193  }
194  else
195  {
196  // All accessible users
197  include_once './Services/User/classes/class.ilLocalUser.php';
198  $user_filter = ilLocalUser::_getFolderIds();
199  }
200  }
201 
202  include_once("./Services/User/classes/class.ilUserQuery.php");
203 
204  $additional_fields = $this->getSelectedColumns();
205  unset($additional_fields["firstname"]);
206  unset($additional_fields["lastname"]);
207  unset($additional_fields["email"]);
208  unset($additional_fields["last_login"]);
209  unset($additional_fields["access_until"]);
210 
211  $usr_data = ilUserQuery::getUserListData(
215  ilUtil::stripSlashes($this->getLimit()),
216  $this->filter["query"],
217  $this->filter["activation"],
218  $this->filter["last_login"],
219  $this->filter["limited_access"],
220  $this->filter["no_courses"],
221  $this->filter["course_group"],
222  $this->filter["global_role"],
223  $user_filter,
224  $additional_fields,
225  null,
226  ilUtil::stripSlashes($_GET["letter"])
227  );
228 
229  if (count($usr_data["set"]) == 0 && $this->getOffset() > 0)
230  {
231  $this->resetOffset();
232  $usr_data = ilUserQuery::getUserListData(
236  ilUtil::stripSlashes($this->getLimit()),
237  $this->filter["query"],
238  $this->filter["activation"],
239  $this->filter["last_login"],
240  $this->filter["limited_access"],
241  $this->filter["no_courses"],
242  $this->filter["course_group"],
243  $this->filter["global_role"],
244  $user_filter,
245  $additional_fields,
246  null,
247  ilUtil::stripSlashes($_GET["letter"])
248  );
249  }
250 
251  foreach ($usr_data["set"] as $k => $user)
252  {
253  $current_time = time();
254  if ($user['active'])
255  {
256  if ($user["time_limit_unlimited"])
257  {
258  $txt_access = $lng->txt("access_unlimited");
259  $usr_data["set"][$k]["access_class"] = "smallgreen";
260  }
261  elseif ($user["time_limit_until"] < $current_time)
262  {
263  $txt_access = $lng->txt("access_expired");
264  $usr_data["set"][$k]["access_class"] = "smallred";
265  }
266  else
267  {
268  $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
269  $usr_data["set"][$k]["access_class"] = "small";
270  }
271  }
272  else
273  {
274  $txt_access = $lng->txt("inactive");
275  $usr_data["set"][$k]["access_class"] = "smallred";
276  }
277  $usr_data["set"][$k]["access_until"] = $txt_access;
278  }
279 
280  $this->setMaxCount($usr_data["cnt"]);
281  $this->setData($usr_data["set"]);
282  }
283 
284 
288  function initFilter()
289  {
290  global $lng, $rbacreview, $ilUser;
291 
292 
293  // Show context filter
294  if($this->getMode() == self::MODE_LOCAL_USER)
295  {
296  include_once './Services/User/classes/class.ilLocalUser.php';
297  $parent_ids = ilLocalUser::_getFolderIds();
298 
299  if(count($parent_ids) > 1)
300  {
301  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
302  $co = new ilSelectInputGUI($lng->txt('context'),'time_limit_owner');
303 
304  $ref_id = $this->getUserFolderId();
305 
306  $opt[0] = $this->lng->txt('all_users');
307  $opt[$this->getUserFolderId()] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($this->getUserFolderId())).')';
308 
309  foreach($parent_ids as $parent_id)
310  {
311  if($parent_id == $this->getUserFolderId())
312  {
313  continue;
314  }
315  switch($parent_id)
316  {
317  case USER_FOLDER_ID:
318  $opt[USER_FOLDER_ID] = $lng->txt('global_user');
319  break;
320 
321  default:
322  $opt[$parent_id] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($parent_id)).')';
323  break;
324  }
325  }
326  $co->setOptions($opt);
327  $this->addFilterItem($co);
328  $co->readFromSession();
329  $this->filter['time_limit_owner'] = $co->getValue();
330  }
331  }
332 
333  // User name, login, email filter
334  include_once("./Services/Form/classes/class.ilUserLoginAutoCompleteInputGUI.php");
336  $lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"),
337  "query",
338  $this->getParentObject(),
339  "addUserAutoComplete"
340  );
341  $ul->setSize(20);
342  $ul->setSubmitFormOnEnter(true);
343  $this->addFilterItem($ul);
344  $ul->readFromSession();
345  $this->filter["query"] = $ul->getValue();
346 
347  /*
348  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
349  $ti = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"), "query");
350  $ti->setMaxLength(64);
351  $ti->setSize(20);
352  $ti->setSubmitFormOnEnter(true);
353  $this->addFilterItem($ti);
354  $ti->readFromSession();
355  $this->filter["query"] = $ti->getValue();
356  */
357 
358  // activation
359  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
360  $options = array(
361  "" => $lng->txt("user_all"),
362  "active" => $lng->txt("active"),
363  "inactive" => $lng->txt("inactive"),
364  );
365  $si = new ilSelectInputGUI($this->lng->txt("user_activation"), "activation");
366  $si->setOptions($options);
367  $this->addFilterItem($si);
368  $si->readFromSession();
369  $this->filter["activation"] = $si->getValue();
370 
371  // limited access
372  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
373  $cb = new ilCheckboxInputGUI($this->lng->txt("user_limited_access"), "limited_access");
374  $this->addFilterItem($cb);
375  $cb->readFromSession();
376  $this->filter["limited_access"] = $cb->getChecked();
377 
378  // last login
379  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
380  $di = new ilDateTimeInputGUI($this->lng->txt("user_last_login_before"), "last_login");
381  $default_date = new ilDateTime(time(),IL_CAL_UNIX);
382  $default_date->increment(IL_CAL_DAY, 1);
383  $di->setDate($default_date);
384  $this->addFilterItem($di);
385  $di->readFromSession();
386  $this->filter["last_login"] = $di->getDate();
387 
388  if($this->getMode() == self::MODE_USER_FOLDER)
389  {
390  // no assigned courses
391  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
392  $cb = new ilCheckboxInputGUI($this->lng->txt("user_no_courses"), "no_courses");
393  $this->addFilterItem($cb);
394  $cb->readFromSession();
395  $this->filter["no_courses"] = $cb->getChecked();
396 
397  // course/group members
398  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
399  $rs = new ilRepositorySelectorInputGUI($lng->txt("user_member_of_course_group"), "course_group");
400  $rs->setSelectText($lng->txt("user_select_course_group"));
401  $rs->setHeaderMessage($lng->txt("user_please_select_course_group"));
402  $rs->setClickableTypes(array("crs", "grp"));
403  $this->addFilterItem($rs);
404  $rs->readFromSession();
405  $this->filter["course_group"] = $rs->getValue();
406  }
407 
408  // global roles
409  $options = array(
410  "" => $lng->txt("user_any"),
411  );
412  $roles = $rbacreview->getRolesByFilter(2, $ilUser->getId());
413  foreach ($roles as $role)
414  {
415  $options[$role["rol_id"]] = $role["title"];
416  }
417  $si = new ilSelectInputGUI($this->lng->txt("user_global_role"), "global_role");
418  $si->setOptions($options);
419  $this->addFilterItem($si);
420  $si->readFromSession();
421  $this->filter["global_role"] = $si->getValue();
422  }
423 
427  protected function fillRow($user)
428  {
429  global $ilCtrl, $lng;
430 
431  $ilCtrl->setParameterByClass("ilobjusergui", "letter", $_GET["letter"]);
432 
433  foreach ($this->getSelectedColumns() as $c)
434  {
435 
436  if ($c == "access_until")
437  {
438  $this->tpl->setCurrentBlock("access_until");
439  $this->tpl->setVariable("VAL_ACCESS_UNTIL", $user["access_until"]);
440  $this->tpl->setVariable("CLASS_ACCESS_UNTIL", $user["access_class"]);
441  }
442  else if ($c == "last_login")
443  {
444  $this->tpl->setCurrentBlock("last_login");
445  $this->tpl->setVariable("VAL_LAST_LOGIN",
446  ilDatePresentation::formatDate(new ilDateTime($user['last_login'],IL_CAL_DATETIME)));
447  }
448  else if (in_array($c, array("firstname", "lastname")))
449  {
450  $this->tpl->setCurrentBlock($c);
451  $this->tpl->setVariable("VAL_".strtoupper($c), (string) $user[$c]);
452  }
453  else // all other fields
454  {
455  $this->tpl->setCurrentBlock("user_field");
456  $val = (trim($user[$c]) == "")
457  ? " "
458  : $user[$c];
459 
460  if ($user[$c] != "")
461  {
462  switch ($c)
463  {
464  case "birthday":
466  break;
467 
468  case "gender":
469  $val = $lng->txt("gender_".$user[$c]);
470  break;
471  }
472  }
473  $this->tpl->setVariable("VAL_UF", $val);
474  }
475 
476  $this->tpl->parseCurrentBlock();
477  }
478 
479  if ($user["usr_id"] != 6)
480  {
481  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
482  {
483  $this->tpl->setCurrentBlock("checkb");
484  $this->tpl->setVariable("ID", $user["usr_id"]);
485  $this->tpl->parseCurrentBlock();
486  }
487  }
488 
489  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
490  {
491  $this->tpl->setVariable("VAL_LOGIN", $user["login"]);
492  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $user["usr_id"]);
493  $this->tpl->setVariable("HREF_LOGIN",
494  $ilCtrl->getLinkTargetByClass("ilobjusergui", "view"));
495  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", "");
496  }
497  else
498  {
499  $this->tpl->setVariable('VAL_LOGIN_PLAIN',$user['login']);
500  }
501 
502  if($this->getMode() == self::MODE_LOCAL_USER)
503  {
504  $this->tpl->setCurrentBlock('context');
505  $this->tpl->setVariable('VAL_CONTEXT',(string)ilObject::_lookupTitle(ilObject::_lookupObjId($user['time_limit_owner'])));
506  $this->tpl->parseCurrentBlock();
507 
508  $this->tpl->setCurrentBlock('roles');
509  $ilCtrl->setParameter($this->getParentObject(),'obj_id',$user['usr_id']);
510  $this->tpl->setVariable('ROLE_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'assignRoles'));
511  $this->tpl->setVariable('TXT_ROLES',$this->lng->txt('edit'));
512  $ilCtrl->clearParameters($this->getParentObject());
513  $this->tpl->parseCurrentBlock();
514 
515  }
516  }
517 }
518 ?>