ILIAS  release_4-3 Revision
 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, $a_load_items = true)
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  $this->setEnableAllCommand(true);
72 
73  $cmds = $a_parent_obj->getUserMultiCommands();
74  foreach($cmds as $cmd => $caption)
75  {
76  $this->addMultiCommand($cmd, $caption);
77  }
78  }
79  else
80  {
81  $this->addMultiCommand("deleteUsers", $lng->txt("delete"));
82  }
83 
84  if($a_load_items)
85  {
86  $this->getItems();
87  }
88  }
89 
90  protected function setMode($a_mode)
91  {
92  $this->mode = $a_mode;
93  }
94 
95  protected function getMode()
96  {
97  return $this->mode;
98  }
99 
100  protected function getUserFolderId()
101  {
102  return $this->user_folder_id;
103  }
104 
105 
106 
114  {
115  global $lng;
116 
117  include_once("./Services/User/classes/class.ilUserProfile.php");
118  $up = new ilUserProfile();
119  $up->skipGroup("preferences");
120  $up->skipGroup("settings");
121 
122  // default fields
123  $cols = array();
124 
125  // first and last name cannot be hidden
126  $cols["firstname"] = array(
127  "txt" => $lng->txt("firstname"),
128  "default" => true);
129  $cols["lastname"] = array(
130  "txt" => $lng->txt("lastname"),
131  "default" => true);
132 
133  if($this->getMode() == self::MODE_USER_FOLDER)
134  {
135  $ufs = $up->getStandardFields();
136 
137  $cols["access_until"] = array(
138  "txt" => $lng->txt("access_until"),
139  "default" => true);
140  $cols["last_login"] = array(
141  "txt" => $lng->txt("last_login"),
142  "default" => true);
143  }
144  else
145  {
146  $ufs = $up->getLocalUserAdministrationFields();
147  }
148 
149  // email should be the 1st "optional" field (can be hidden)
150  if(isset($ufs["email"]))
151  {
152  $cols["email"] = array(
153  "txt" => $lng->txt("email"),
154  "default" => true);
155  }
156 
157  // other user profile fields
158  foreach ($ufs as $f => $fd)
159  {
160  if (!isset($cols[$f]) && !$fd["lists_hide"])
161  {
162  $cols[$f] = array(
163  "txt" => $lng->txt($f),
164  "default" => false);
165  }
166  }
167 
168  // fields that are always shown
169  unset($cols["username"]);
170 
171  return $cols;
172  }
173 
177  function getItems()
178  {
179  global $lng;
180 //if ($GLOBALS["kk"]++ == 1) nj();
181 
182  $this->determineOffsetAndOrder();
183 
184  if($this->getMode() == self::MODE_USER_FOLDER)
185  {
186  // All accessible users
187  include_once './Services/User/classes/class.ilLocalUser.php';
188  $user_filter = ilLocalUser::_getFolderIds();
189  }
190  else
191  {
192  if($this->filter['time_limit_owner'])
193  {
194  $user_filter = array($this->filter['time_limit_owner']);
195  }
196  else
197  {
198  // All accessible users
199  include_once './Services/User/classes/class.ilLocalUser.php';
200  $user_filter = ilLocalUser::_getFolderIds();
201  }
202  }
203 
204  include_once("./Services/User/classes/class.ilUserQuery.php");
205 
206  $additional_fields = $this->getSelectedColumns();
207  unset($additional_fields["firstname"]);
208  unset($additional_fields["lastname"]);
209  unset($additional_fields["email"]);
210  unset($additional_fields["last_login"]);
211  unset($additional_fields["access_until"]);
212 
213  $usr_data = ilUserQuery::getUserListData(
217  ilUtil::stripSlashes($this->getLimit()),
218  $this->filter["query"],
219  $this->filter["activation"],
220  $this->filter["last_login"],
221  $this->filter["limited_access"],
222  $this->filter["no_courses"],
223  $this->filter["course_group"],
224  $this->filter["global_role"],
225  $user_filter,
226  $additional_fields,
227  null,
228  ilUtil::stripSlashes($_GET["letter"])
229  );
230 
231  if (count($usr_data["set"]) == 0 && $this->getOffset() > 0)
232  {
233  $this->resetOffset();
234  $usr_data = ilUserQuery::getUserListData(
238  ilUtil::stripSlashes($this->getLimit()),
239  $this->filter["query"],
240  $this->filter["activation"],
241  $this->filter["last_login"],
242  $this->filter["limited_access"],
243  $this->filter["no_courses"],
244  $this->filter["course_group"],
245  $this->filter["global_role"],
246  $user_filter,
247  $additional_fields,
248  null,
249  ilUtil::stripSlashes($_GET["letter"])
250  );
251  }
252 
253  foreach ($usr_data["set"] as $k => $user)
254  {
255  $current_time = time();
256  if ($user['active'])
257  {
258  if ($user["time_limit_unlimited"])
259  {
260  $txt_access = $lng->txt("access_unlimited");
261  $usr_data["set"][$k]["access_class"] = "smallgreen";
262  }
263  elseif ($user["time_limit_until"] < $current_time)
264  {
265  $txt_access = $lng->txt("access_expired");
266  $usr_data["set"][$k]["access_class"] = "smallred";
267  }
268  else
269  {
270  $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
271  $usr_data["set"][$k]["access_class"] = "small";
272  }
273  }
274  else
275  {
276  $txt_access = $lng->txt("inactive");
277  $usr_data["set"][$k]["access_class"] = "smallred";
278  }
279  $usr_data["set"][$k]["access_until"] = $txt_access;
280  }
281 
282  $this->setMaxCount($usr_data["cnt"]);
283  $this->setData($usr_data["set"]);
284  }
285 
286  public function getUserIdsForFilter()
287  {
288  if($this->getMode() == self::MODE_USER_FOLDER)
289  {
290  // All accessible users
291  include_once './Services/User/classes/class.ilLocalUser.php';
292  $user_filter = ilLocalUser::_getFolderIds();
293  }
294  else
295  {
296  if($this->filter['time_limit_owner'])
297  {
298  $user_filter = array($this->filter['time_limit_owner']);
299  }
300  else
301  {
302  // All accessible users
303  include_once './Services/User/classes/class.ilLocalUser.php';
304  $user_filter = ilLocalUser::_getFolderIds();
305  }
306  }
307 
308  include_once("./Services/User/classes/class.ilUserQuery.php");
309  $usr_data = ilUserQuery::getUserListData(
312  0,
313  self::getAllCommandLimit(),
314  $this->filter["query"],
315  $this->filter["activation"],
316  $this->filter["last_login"],
317  $this->filter["limited_access"],
318  $this->filter["no_courses"],
319  $this->filter["course_group"],
320  $this->filter["global_role"],
321  $user_filter,
322  null,
323  null,
324  ilUtil::stripSlashes($_GET["letter"])
325  );
326 
327  $user_ids = array();
328  foreach($usr_data["set"] as $item)
329  {
330  // #11632
331  if($item["usr_id"] != SYSTEM_USER_ID)
332  {
333  $user_ids[] = $item["usr_id"];
334  }
335  }
336  return $user_ids;
337  }
338 
339 
343  function initFilter()
344  {
345  global $lng, $rbacreview, $ilUser, $ilCtrl;
346 
347 
348  // Show context filter
349  if($this->getMode() == self::MODE_LOCAL_USER)
350  {
351  include_once './Services/User/classes/class.ilLocalUser.php';
352  $parent_ids = ilLocalUser::_getFolderIds();
353 
354  if(count($parent_ids) > 1)
355  {
356  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
357  $co = new ilSelectInputGUI($lng->txt('context'),'time_limit_owner');
358 
359  $ref_id = $this->getUserFolderId();
360 
361  $opt[0] = $this->lng->txt('all_users');
362  $opt[$this->getUserFolderId()] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($this->getUserFolderId())).')';
363 
364  foreach($parent_ids as $parent_id)
365  {
366  if($parent_id == $this->getUserFolderId())
367  {
368  continue;
369  }
370  switch($parent_id)
371  {
372  case USER_FOLDER_ID:
373  $opt[USER_FOLDER_ID] = $lng->txt('global_user');
374  break;
375 
376  default:
377  $opt[$parent_id] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($parent_id)).')';
378  break;
379  }
380  }
381  $co->setOptions($opt);
382  $this->addFilterItem($co);
383  $co->readFromSession();
384  $this->filter['time_limit_owner'] = $co->getValue();
385  }
386  }
387 
388  // User name, login, email filter
389  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
390  $ul = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".
391  $lng->txt("name"), "query");
392  $ul->setDataSource($ilCtrl->getLinkTarget($this->getParentObject(),
393  "addUserAutoComplete", "", true));
394  $ul->setSize(20);
395  $ul->setSubmitFormOnEnter(true);
396  $this->addFilterItem($ul);
397  $ul->readFromSession();
398  $this->filter["query"] = $ul->getValue();
399 
400  /*
401  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
402  $ti = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"), "query");
403  $ti->setMaxLength(64);
404  $ti->setSize(20);
405  $ti->setSubmitFormOnEnter(true);
406  $this->addFilterItem($ti);
407  $ti->readFromSession();
408  $this->filter["query"] = $ti->getValue();
409  */
410 
411  // activation
412  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
413  $options = array(
414  "" => $lng->txt("user_all"),
415  "active" => $lng->txt("active"),
416  "inactive" => $lng->txt("inactive"),
417  );
418  $si = new ilSelectInputGUI($this->lng->txt("user_activation"), "activation");
419  $si->setOptions($options);
420  $this->addFilterItem($si);
421  $si->readFromSession();
422  $this->filter["activation"] = $si->getValue();
423 
424  // limited access
425  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
426  $cb = new ilCheckboxInputGUI($this->lng->txt("user_limited_access"), "limited_access");
427  $this->addFilterItem($cb);
428  $cb->readFromSession();
429  $this->filter["limited_access"] = $cb->getChecked();
430 
431  // last login
432  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
433  $di = new ilDateTimeInputGUI($this->lng->txt("user_last_login_before"), "last_login");
434  $default_date = new ilDateTime(time(),IL_CAL_UNIX);
435  $default_date->increment(IL_CAL_DAY, 1);
436  $di->setDate($default_date);
437  $this->addFilterItem($di);
438  $di->readFromSession();
439  $this->filter["last_login"] = $di->getDate();
440 
441  if($this->getMode() == self::MODE_USER_FOLDER)
442  {
443  // no assigned courses
444  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
445  $cb = new ilCheckboxInputGUI($this->lng->txt("user_no_courses"), "no_courses");
446  $this->addFilterItem($cb);
447  $cb->readFromSession();
448  $this->filter["no_courses"] = $cb->getChecked();
449 
450  // course/group members
451  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
452  $rs = new ilRepositorySelectorInputGUI($lng->txt("user_member_of_course_group"), "course_group");
453  $rs->setSelectText($lng->txt("user_select_course_group"));
454  $rs->setHeaderMessage($lng->txt("user_please_select_course_group"));
455  $rs->setClickableTypes(array("crs", "grp"));
456  $this->addFilterItem($rs);
457  $rs->readFromSession();
458  $this->filter["course_group"] = $rs->getValue();
459  }
460 
461  // global roles
462  $options = array(
463  "" => $lng->txt("user_any"),
464  );
465  $roles = $rbacreview->getRolesByFilter(2, $ilUser->getId());
466  foreach ($roles as $role)
467  {
468  $options[$role["rol_id"]] = $role["title"];
469  }
470  $si = new ilSelectInputGUI($this->lng->txt("user_global_role"), "global_role");
471  $si->setOptions($options);
472  $this->addFilterItem($si);
473  $si->readFromSession();
474  $this->filter["global_role"] = $si->getValue();
475  }
476 
480  protected function fillRow($user)
481  {
482  global $ilCtrl, $lng;
483 
484  $ilCtrl->setParameterByClass("ilobjusergui", "letter", $_GET["letter"]);
485 
486  foreach ($this->getSelectedColumns() as $c)
487  {
488 
489  if ($c == "access_until")
490  {
491  $this->tpl->setCurrentBlock("access_until");
492  $this->tpl->setVariable("VAL_ACCESS_UNTIL", $user["access_until"]);
493  $this->tpl->setVariable("CLASS_ACCESS_UNTIL", $user["access_class"]);
494  }
495  else if ($c == "last_login")
496  {
497  $this->tpl->setCurrentBlock("last_login");
498  $this->tpl->setVariable("VAL_LAST_LOGIN",
499  ilDatePresentation::formatDate(new ilDateTime($user['last_login'],IL_CAL_DATETIME)));
500  }
501  else if (in_array($c, array("firstname", "lastname")))
502  {
503  $this->tpl->setCurrentBlock($c);
504  $this->tpl->setVariable("VAL_".strtoupper($c), (string) $user[$c]);
505  }
506  else // all other fields
507  {
508  $this->tpl->setCurrentBlock("user_field");
509  $val = (trim($user[$c]) == "")
510  ? " "
511  : $user[$c];
512 
513  if ($user[$c] != "")
514  {
515  switch ($c)
516  {
517  case "birthday":
519  break;
520 
521  case "gender":
522  $val = $lng->txt("gender_".$user[$c]);
523  break;
524  }
525  }
526  $this->tpl->setVariable("VAL_UF", $val);
527  }
528 
529  $this->tpl->parseCurrentBlock();
530  }
531 
532  if ($user["usr_id"] != 6)
533  {
534  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
535  {
536  $this->tpl->setCurrentBlock("checkb");
537  $this->tpl->setVariable("ID", $user["usr_id"]);
538  $this->tpl->parseCurrentBlock();
539  }
540  }
541 
542  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
543  {
544  $this->tpl->setVariable("VAL_LOGIN", $user["login"]);
545  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $user["usr_id"]);
546  $this->tpl->setVariable("HREF_LOGIN",
547  $ilCtrl->getLinkTargetByClass("ilobjusergui", "view"));
548  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", "");
549  }
550  else
551  {
552  $this->tpl->setVariable('VAL_LOGIN_PLAIN',$user['login']);
553  }
554 
555  if($this->getMode() == self::MODE_LOCAL_USER)
556  {
557  $this->tpl->setCurrentBlock('context');
558  $this->tpl->setVariable('VAL_CONTEXT',(string)ilObject::_lookupTitle(ilObject::_lookupObjId($user['time_limit_owner'])));
559  $this->tpl->parseCurrentBlock();
560 
561  $this->tpl->setCurrentBlock('roles');
562  $ilCtrl->setParameter($this->getParentObject(),'obj_id',$user['usr_id']);
563  $this->tpl->setVariable('ROLE_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'assignRoles'));
564  $this->tpl->setVariable('TXT_ROLES',$this->lng->txt('edit'));
565  $ilCtrl->clearParameters($this->getParentObject());
566  $this->tpl->parseCurrentBlock();
567 
568  }
569  }
570 }
571 ?>