ILIAS  Release_4_1_x_branch Revision 61804
 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  // title/description
334  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
335  $ti = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"), "query");
336  $ti->setMaxLength(64);
337  $ti->setSize(20);
338  $ti->setSubmitFormOnEnter(true);
339  $this->addFilterItem($ti);
340  $ti->readFromSession();
341  $this->filter["query"] = $ti->getValue();
342 
343  // activation
344  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
345  $options = array(
346  "" => $lng->txt("user_all"),
347  "active" => $lng->txt("active"),
348  "inactive" => $lng->txt("inactive"),
349  );
350  $si = new ilSelectInputGUI($this->lng->txt("user_activation"), "activation");
351  $si->setOptions($options);
352  $this->addFilterItem($si);
353  $si->readFromSession();
354  $this->filter["activation"] = $si->getValue();
355 
356  // limited access
357  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
358  $cb = new ilCheckboxInputGUI($this->lng->txt("user_limited_access"), "limited_access");
359  $this->addFilterItem($cb);
360  $cb->readFromSession();
361  $this->filter["limited_access"] = $cb->getChecked();
362 
363  // last login
364  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
365  $di = new ilDateTimeInputGUI($this->lng->txt("user_last_login_before"), "last_login");
366  $default_date = new ilDateTime(time(),IL_CAL_UNIX);
367  $default_date->increment(IL_CAL_DAY, 1);
368  $di->setDate($default_date);
369  $this->addFilterItem($di);
370  $di->readFromSession();
371  $this->filter["last_login"] = $di->getDate();
372 
373  if($this->getMode() == self::MODE_USER_FOLDER)
374  {
375  // no assigned courses
376  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
377  $cb = new ilCheckboxInputGUI($this->lng->txt("user_no_courses"), "no_courses");
378  $this->addFilterItem($cb);
379  $cb->readFromSession();
380  $this->filter["no_courses"] = $cb->getChecked();
381 
382  // course/group members
383  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
384  $rs = new ilRepositorySelectorInputGUI($lng->txt("user_member_of_course_group"), "course_group");
385  $rs->setSelectText($lng->txt("user_select_course_group"));
386  $rs->setHeaderMessage($lng->txt("user_please_select_course_group"));
387  $rs->setClickableTypes(array("crs", "grp"));
388  $this->addFilterItem($rs);
389  $rs->readFromSession();
390  $this->filter["course_group"] = $rs->getValue();
391  }
392 
393  // global roles
394  $options = array(
395  "" => $lng->txt("user_any"),
396  );
397  $roles = $rbacreview->getRolesByFilter(2, $ilUser->getId());
398  foreach ($roles as $role)
399  {
400  $options[$role["rol_id"]] = $role["title"];
401  }
402  $si = new ilSelectInputGUI($this->lng->txt("user_global_role"), "global_role");
403  $si->setOptions($options);
404  $this->addFilterItem($si);
405  $si->readFromSession();
406  $this->filter["global_role"] = $si->getValue();
407  }
408 
412  protected function fillRow($user)
413  {
414  global $ilCtrl, $lng;
415 
416  $ilCtrl->setParameterByClass("ilobjusergui", "letter", $_GET["letter"]);
417 
418  foreach ($this->getSelectedColumns() as $c)
419  {
420 
421  if ($c == "access_until")
422  {
423  $this->tpl->setCurrentBlock("access_until");
424  $this->tpl->setVariable("VAL_ACCESS_UNTIL", $user["access_until"]);
425  $this->tpl->setVariable("CLASS_ACCESS_UNTIL", $user["access_class"]);
426  }
427  else if ($c == "last_login")
428  {
429  $this->tpl->setCurrentBlock("last_login");
430  $this->tpl->setVariable("VAL_LAST_LOGIN",
432  }
433  else if (in_array($c, array("firstname", "lastname")))
434  {
435  $this->tpl->setCurrentBlock($c);
436  $this->tpl->setVariable("VAL_".strtoupper($c), (string) $user[$c]);
437  }
438  else // all other fields
439  {
440  $this->tpl->setCurrentBlock("user_field");
441  $val = (trim($user[$c]) == "")
442  ? " "
443  : $user[$c];
444 
445  if ($user[$c] != "")
446  {
447  switch ($c)
448  {
449  case "birthday":
451  break;
452 
453  case "gender":
454  $val = $lng->txt("gender_".$user[$c]);
455  break;
456  }
457  }
458  $this->tpl->setVariable("VAL_UF", $val);
459  }
460 
461  $this->tpl->parseCurrentBlock();
462  }
463 
464  if ($user["usr_id"] != 6)
465  {
466  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
467  {
468  $this->tpl->setCurrentBlock("checkb");
469  $this->tpl->setVariable("ID", $user["usr_id"]);
470  $this->tpl->parseCurrentBlock();
471  }
472  }
473 
474  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
475  {
476  $this->tpl->setVariable("VAL_LOGIN", $user["login"]);
477  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $user["usr_id"]);
478  $this->tpl->setVariable("HREF_LOGIN",
479  $ilCtrl->getLinkTargetByClass("ilobjusergui", "view"));
480  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", "");
481  }
482  else
483  {
484  $this->tpl->setVariable('VAL_LOGIN_PLAIN',$user['login']);
485  }
486 
487  if($this->getMode() == self::MODE_LOCAL_USER)
488  {
489  $this->tpl->setCurrentBlock('context');
490  $this->tpl->setVariable('VAL_CONTEXT', (string)ilObject::_lookupTitle(ilObject::_lookupObjId($user['time_limit_owner'])));
491  $this->tpl->parseCurrentBlock();
492 
493  $this->tpl->setCurrentBlock('roles');
494  $ilCtrl->setParameter($this->getParentObject(),'obj_id',$user['usr_id']);
495  $this->tpl->setVariable('ROLE_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'assignRoles'));
496  $this->tpl->setVariable('TXT_ROLES',$this->lng->txt('edit'));
497  $ilCtrl->clearParameters($this->getParentObject());
498  $this->tpl->parseCurrentBlock();
499 
500  }
501  }
502 }
503 ?>