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