ILIAS  Release_4_4_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("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  // #13967
145  $cols["create_date"] = array(
146  "txt" => $lng->txt("create_date"));
147  $cols["approve_date"] = array(
148  "txt" => $lng->txt("approve_date"));
149  $cols["agree_date"] = array(
150  "txt" => $lng->txt("agree_date"));
151  }
152  else
153  {
154  $ufs = $up->getLocalUserAdministrationFields();
155  }
156 
157  // email should be the 1st "optional" field (can be hidden)
158  if(isset($ufs["email"]))
159  {
160  $cols["email"] = array(
161  "txt" => $lng->txt("email"),
162  "default" => true);
163  }
164 
165  // other user profile fields
166  foreach ($ufs as $f => $fd)
167  {
168  if (!isset($cols[$f]) && !$fd["lists_hide"])
169  {
170  $cols[$f] = array(
171  "txt" => $lng->txt($f),
172  "default" => false);
173  }
174  }
175 
176  // fields that are always shown
177  unset($cols["username"]);
178 
179  return $cols;
180  }
181 
185  function getItems()
186  {
187  global $lng;
188 //if ($GLOBALS["kk"]++ == 1) nj();
189 
190  $this->determineOffsetAndOrder();
191 
192  if($this->getMode() == self::MODE_USER_FOLDER)
193  {
194  // All accessible users
195  include_once './Services/User/classes/class.ilLocalUser.php';
196  $user_filter = ilLocalUser::_getFolderIds();
197  }
198  else
199  {
200  if($this->filter['time_limit_owner'])
201  {
202  $user_filter = array($this->filter['time_limit_owner']);
203  }
204  else
205  {
206  // All accessible users
207  include_once './Services/User/classes/class.ilLocalUser.php';
208  $user_filter = ilLocalUser::_getFolderIds();
209  }
210  }
211 
212  //#13221 don't show all users if user filter is empty!
213  if(!count($user_filter))
214  {
215  $this->setMaxCount(0);
216  $this->setData(array());
217  return;
218  }
219 
220  include_once("./Services/User/classes/class.ilUserQuery.php");
221 
222  $additional_fields = $this->getSelectedColumns();
223  unset($additional_fields["firstname"]);
224  unset($additional_fields["lastname"]);
225  unset($additional_fields["email"]);
226  unset($additional_fields["last_login"]);
227  unset($additional_fields["access_until"]);
228 
229  $query = new ilUserQuery();
230  $query->setOrderField($this->getOrderField());
231  $query->setOrderDirection($this->getOrderDirection());
232  $query->setOffset($this->getOffset());
233  $query->setLimit($this->getLimit());
234  $query->setTextFilter($this->filter['query']);
235  $query->setActionFilter($this->filter['activation']);
236  $query->setLastLogin($this->filter['last_login']);
237  $query->setLimitedAccessFilter($this->filter['limited_access']);
238  $query->setNoCourseFilter($this->filter['no_courses']);
239  $query->setNoGroupFilter($this->filter['no_groups']);
240  $query->setCourseGroupFilter($this->filter['course_group']);
241  $query->setRoleFilter($this->filter['global_role']);
242  $query->setAdditionalFields($additional_fields);
243  $query->setUserFolder($user_filter);
244  $query->setFirstLetterLastname(ilUtil::stripSlashes($_GET['letter']));
245 
246  $usr_data = $query->query();
247 
248 
249  if (count($usr_data["set"]) == 0 && $this->getOffset() > 0)
250  {
251  $this->resetOffset();
252  $query->setOffset($this->getOffset());
253  $usr_data = $query->query();
254  }
255 
256  foreach ($usr_data["set"] as $k => $user)
257  {
258  $current_time = time();
259  if ($user['active'])
260  {
261  if ($user["time_limit_unlimited"])
262  {
263  $txt_access = $lng->txt("access_unlimited");
264  $usr_data["set"][$k]["access_class"] = "smallgreen";
265  }
266  elseif ($user["time_limit_until"] < $current_time)
267  {
268  $txt_access = $lng->txt("access_expired");
269  $usr_data["set"][$k]["access_class"] = "smallred";
270  }
271  else
272  {
273  $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
274  $usr_data["set"][$k]["access_class"] = "small";
275  }
276  }
277  else
278  {
279  $txt_access = $lng->txt("inactive");
280  $usr_data["set"][$k]["access_class"] = "smallred";
281  }
282  $usr_data["set"][$k]["access_until"] = $txt_access;
283  }
284 
285  $this->setMaxCount($usr_data["cnt"]);
286  $this->setData($usr_data["set"]);
287  }
288 
289  public function getUserIdsForFilter()
290  {
291  if($this->getMode() == self::MODE_USER_FOLDER)
292  {
293  // All accessible users
294  include_once './Services/User/classes/class.ilLocalUser.php';
295  $user_filter = ilLocalUser::_getFolderIds();
296  }
297  else
298  {
299  if($this->filter['time_limit_owner'])
300  {
301  $user_filter = array($this->filter['time_limit_owner']);
302  }
303  else
304  {
305  // All accessible users
306  include_once './Services/User/classes/class.ilLocalUser.php';
307  $user_filter = ilLocalUser::_getFolderIds();
308  }
309  }
310 
311  include_once("./Services/User/classes/class.ilUserQuery.php");
312  $query = new ilUserQuery();
313  $query->setOffset(0);
314  $query->setLimit(self::getAllCommandLimit());
315  $query->setTextFilter($this->filter['query']);
316  $query->setActionFilter($this->filter['activation']);
317  $query->setLastLogin($this->filter['last_login']);
318  $query->setLimitedAccessFilter($this->filter['limited_access']);
319  $query->setNoCourseFilter($this->filter['no_courses']);
320  $query->setNoGroupFilter($this->filter['no_groups']);
321  $query->setCourseGroupFilter($this->filter['course_group']);
322  $query->setRoleFilter($this->filter['global_role']);
323  $query->setUserFolder($user_filter);
324  $query->setFirstLetterLastname(ilUtil::stripSlashes($_GET['letter']));
325 
326  if($this->getOrderField())
327  {
328  $query->setOrderField(ilUtil::stripSlashes($this->getOrderField()));
329  $query->setOrderDirection(ilUtil::stripSlashes($this->getOrderDirection()));
330  }
331 
332  $usr_data = $query->query();
333 
334  $user_ids = array();
335  foreach($usr_data["set"] as $item)
336  {
337  // #11632
338  if($item["usr_id"] != SYSTEM_USER_ID)
339  {
340  $user_ids[] = $item["usr_id"];
341  }
342  }
343  return $user_ids;
344  }
345 
346 
350  function initFilter()
351  {
352  global $lng, $rbacreview, $ilUser, $ilCtrl;
353 
354 
355  // Show context filter
356  if($this->getMode() == self::MODE_LOCAL_USER)
357  {
358  include_once './Services/User/classes/class.ilLocalUser.php';
359  $parent_ids = ilLocalUser::_getFolderIds();
360 
361  if(count($parent_ids) > 1)
362  {
363  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
364  $co = new ilSelectInputGUI($lng->txt('context'),'time_limit_owner');
365 
366  $ref_id = $this->getUserFolderId();
367 
368  $opt[0] = $this->lng->txt('all_users');
369  $opt[$this->getUserFolderId()] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($this->getUserFolderId())).')';
370 
371  foreach($parent_ids as $parent_id)
372  {
373  if($parent_id == $this->getUserFolderId())
374  {
375  continue;
376  }
377  switch($parent_id)
378  {
379  case USER_FOLDER_ID:
380  $opt[USER_FOLDER_ID] = $lng->txt('global_user');
381  break;
382 
383  default:
384  $opt[$parent_id] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($parent_id)).')';
385  break;
386  }
387  }
388  $co->setOptions($opt);
389  $this->addFilterItem($co);
390  $co->readFromSession();
391  $this->filter['time_limit_owner'] = $co->getValue();
392  }
393  }
394 
395  // User name, login, email filter
396  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
397  $ul = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".
398  $lng->txt("name"), "query");
399  $ul->setDataSource($ilCtrl->getLinkTarget($this->getParentObject(),
400  "addUserAutoComplete", "", true));
401  $ul->setSize(20);
402  $ul->setSubmitFormOnEnter(true);
403  $this->addFilterItem($ul);
404  $ul->readFromSession();
405  $this->filter["query"] = $ul->getValue();
406 
407  /*
408  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
409  $ti = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"), "query");
410  $ti->setMaxLength(64);
411  $ti->setSize(20);
412  $ti->setSubmitFormOnEnter(true);
413  $this->addFilterItem($ti);
414  $ti->readFromSession();
415  $this->filter["query"] = $ti->getValue();
416  */
417 
418  // activation
419  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
420  $options = array(
421  "" => $lng->txt("user_all"),
422  "active" => $lng->txt("active"),
423  "inactive" => $lng->txt("inactive"),
424  );
425  $si = new ilSelectInputGUI($this->lng->txt("user_activation"), "activation");
426  $si->setOptions($options);
427  $this->addFilterItem($si);
428  $si->readFromSession();
429  $this->filter["activation"] = $si->getValue();
430 
431  // limited access
432  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
433  $cb = new ilCheckboxInputGUI($this->lng->txt("user_limited_access"), "limited_access");
434  $this->addFilterItem($cb);
435  $cb->readFromSession();
436  $this->filter["limited_access"] = $cb->getChecked();
437 
438  // last login
439  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
440  $di = new ilDateTimeInputGUI($this->lng->txt("user_last_login_before"), "last_login");
441  $default_date = new ilDateTime(time(),IL_CAL_UNIX);
442  $default_date->increment(IL_CAL_DAY, 1);
443  $di->setDate($default_date);
444  $this->addFilterItem($di);
445  $di->readFromSession();
446  $this->filter["last_login"] = $di->getDate();
447 
448  if($this->getMode() == self::MODE_USER_FOLDER)
449  {
450  // no assigned courses
451  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
452  $cb = new ilCheckboxInputGUI($this->lng->txt("user_no_courses"), "no_courses");
453  $this->addFilterItem($cb);
454  $cb->readFromSession();
455  $this->filter["no_courses"] = $cb->getChecked();
456 
457  // no assigned groups
458  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
459  $ng = new ilCheckboxInputGUI($this->lng->txt("user_no_groups"), "no_groups");
460  $this->addFilterItem($ng);
461  $ng->readFromSession();
462  $this->filter['no_groups'] = $ng->getChecked();
463 
464  // course/group members
465  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
466  $rs = new ilRepositorySelectorInputGUI($lng->txt("user_member_of_course_group"), "course_group");
467  $rs->setSelectText($lng->txt("user_select_course_group"));
468  $rs->setHeaderMessage($lng->txt("user_please_select_course_group"));
469  $rs->setClickableTypes(array("crs", "grp"));
470  $this->addFilterItem($rs);
471  $rs->readFromSession();
472  $this->filter["course_group"] = $rs->getValue();
473  }
474 
475  // global roles
476  $options = array(
477  "" => $lng->txt("user_any"),
478  );
479  $roles = $rbacreview->getRolesByFilter(2, $ilUser->getId());
480  foreach ($roles as $role)
481  {
482  $options[$role["rol_id"]] = $role["title"];
483  }
484  $si = new ilSelectInputGUI($this->lng->txt("user_global_role"), "global_role");
485  $si->setOptions($options);
486  $this->addFilterItem($si);
487  $si->readFromSession();
488  $this->filter["global_role"] = $si->getValue();
489  }
490 
494  protected function fillRow($user)
495  {
496  global $ilCtrl, $lng;
497 
498  $ilCtrl->setParameterByClass("ilobjusergui", "letter", $_GET["letter"]);
499 
500  foreach ($this->getSelectedColumns() as $c)
501  {
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 ?>