ILIAS  eassessment Revision 61809
 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  if($this->getMode() == self::MODE_USER_FOLDER)
124  {
125  $ufs = $up->getStandardFields();
126 
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  $cols["email"] = array(
134  "txt" => $lng->txt("email"),
135  "default" => true);
136  $cols["access_until"] = array(
137  "txt" => $lng->txt("access_until"),
138  "default" => true);
139  $cols["last_login"] = array(
140  "txt" => $lng->txt("last_login"),
141  "default" => true);
142  }
143  else
144  {
145  $ufs = $up->getLocalUserAdministrationFields();
146  }
147 
148  // other user profile fields
149  foreach ($ufs as $f => $fd)
150  {
151  if (!isset($cols[$f]) && !$fd["lists_hide"])
152  {
153  $cols[$f] = array(
154  "txt" => $lng->txt($f),
155  "default" => false);
156  }
157  }
158 
159  // fields that are always shown
160  unset($cols["username"]);
161 
162  return $cols;
163  }
164 
168  function getItems()
169  {
170  global $lng;
171 //if ($GLOBALS["kk"]++ == 1) nj();
172 
173  $this->determineOffsetAndOrder();
174 
175  if($this->getMode() == self::MODE_USER_FOLDER)
176  {
177  // All accessible users
178  include_once './Services/User/classes/class.ilLocalUser.php';
179  $user_filter = ilLocalUser::_getFolderIds();
180  }
181  else
182  {
183  if($this->filter['time_limit_owner'])
184  {
185  $user_filter = array($this->filter['time_limit_owner']);
186  }
187  else
188  {
189  // All accessible users
190  include_once './Services/User/classes/class.ilLocalUser.php';
191  $user_filter = ilLocalUser::_getFolderIds();
192  }
193  }
194 
195  include_once("./Services/User/classes/class.ilUserQuery.php");
196 
197  $additional_fields = $this->getSelectedColumns();
198  unset($additional_fields["firstname"]);
199  unset($additional_fields["lastname"]);
200  unset($additional_fields["email"]);
201  unset($additional_fields["last_login"]);
202  unset($additional_fields["access_until"]);
203 
204  $usr_data = ilUserQuery::getUserListData(
208  ilUtil::stripSlashes($this->getLimit()),
209  $this->filter["query"],
210  $this->filter["activation"],
211  $this->filter["last_login"],
212  $this->filter["limited_access"],
213  $this->filter["no_courses"],
214  $this->filter["course_group"],
215  $this->filter["global_role"],
216  $user_filter,
217  $additional_fields,
218  null,
219  ilUtil::stripSlashes($_GET["letter"])
220  );
221 
222  if (count($usr_data["set"]) == 0 && $this->getOffset() > 0)
223  {
224  $this->resetOffset();
225  $usr_data = ilUserQuery::getUserListData(
229  ilUtil::stripSlashes($this->getLimit()),
230  $this->filter["query"],
231  $this->filter["activation"],
232  $this->filter["last_login"],
233  $this->filter["limited_access"],
234  $this->filter["no_courses"],
235  $this->filter["course_group"],
236  $this->filter["global_role"],
237  $user_filter,
238  $additional_fields,
239  null,
240  ilUtil::stripSlashes($_GET["letter"])
241  );
242  }
243 
244  foreach ($usr_data["set"] as $k => $user)
245  {
246  $current_time = time();
247  if ($user['active'])
248  {
249  if ($user["time_limit_unlimited"])
250  {
251  $txt_access = $lng->txt("access_unlimited");
252  $usr_data["set"][$k]["access_class"] = "smallgreen";
253  }
254  elseif ($user["time_limit_until"] < $current_time)
255  {
256  $txt_access = $lng->txt("access_expired");
257  $usr_data["set"][$k]["access_class"] = "smallred";
258  }
259  else
260  {
261  $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
262  $usr_data["set"][$k]["access_class"] = "small";
263  }
264  }
265  else
266  {
267  $txt_access = $lng->txt("inactive");
268  $usr_data["set"][$k]["access_class"] = "smallred";
269  }
270  $usr_data["set"][$k]["access_until"] = $txt_access;
271  }
272 
273  $this->setMaxCount($usr_data["cnt"]);
274  $this->setData($usr_data["set"]);
275  }
276 
277 
281  function initFilter()
282  {
283  global $lng, $rbacreview, $ilUser;
284 
285 
286  // Show context filter
287  if($this->getMode() == self::MODE_LOCAL_USER)
288  {
289  include_once './Services/User/classes/class.ilLocalUser.php';
290  $parent_ids = ilLocalUser::_getFolderIds();
291 
292  if(count($parent_ids) > 1)
293  {
294  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
295  $co = new ilSelectInputGUI($lng->txt('context'),'time_limit_owner');
296 
297  $ref_id = $this->getUserFolderId();
298 
299  $opt[0] = $this->lng->txt('all_users');
300  $opt[$this->getUserFolderId()] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($this->getUserFolderId())).')';
301 
302  foreach($parent_ids as $parent_id)
303  {
304  if($parent_id == $this->getUserFolderId())
305  {
306  continue;
307  }
308  switch($parent_id)
309  {
310  case USER_FOLDER_ID:
311  $opt[USER_FOLDER_ID] = $lng->txt('global_user');
312  break;
313 
314  default:
315  $opt[$parent_id] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($parent_id)).')';
316  break;
317  }
318  }
319  $co->setOptions($opt);
320  $this->addFilterItem($co);
321  $co->readFromSession();
322  $this->filter['time_limit_owner'] = $co->getValue();
323  }
324  }
325 
326  // title/description
327  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
328  $ti = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"), "query");
329  $ti->setMaxLength(64);
330  $ti->setSize(20);
331  $ti->setSubmitFormOnEnter(true);
332  $this->addFilterItem($ti);
333  $ti->readFromSession();
334  $this->filter["query"] = $ti->getValue();
335 
336  // activation
337  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
338  $options = array(
339  "" => $lng->txt("user_all"),
340  "active" => $lng->txt("active"),
341  "inactive" => $lng->txt("inactive"),
342  );
343  $si = new ilSelectInputGUI($this->lng->txt("user_activation"), "activation");
344  $si->setOptions($options);
345  $this->addFilterItem($si);
346  $si->readFromSession();
347  $this->filter["activation"] = $si->getValue();
348 
349  // limited access
350  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
351  $cb = new ilCheckboxInputGUI($this->lng->txt("user_limited_access"), "limited_access");
352  $this->addFilterItem($cb);
353  $cb->readFromSession();
354  $this->filter["limited_access"] = $cb->getChecked();
355 
356  // last login
357  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
358  $di = new ilDateTimeInputGUI($this->lng->txt("user_last_login_before"), "last_login");
359  $default_date = new ilDateTime(time(),IL_CAL_UNIX);
360  $default_date->increment(IL_CAL_DAY, 1);
361  $di->setDate($default_date);
362  $this->addFilterItem($di);
363  $di->readFromSession();
364  $this->filter["last_login"] = $di->getDate();
365 
366  if($this->getMode() == self::MODE_USER_FOLDER)
367  {
368  // no assigned courses
369  include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
370  $cb = new ilCheckboxInputGUI($this->lng->txt("user_no_courses"), "no_courses");
371  $this->addFilterItem($cb);
372  $cb->readFromSession();
373  $this->filter["no_courses"] = $cb->getChecked();
374 
375  // course/group members
376  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
377  $rs = new ilRepositorySelectorInputGUI($lng->txt("user_member_of_course_group"), "course_group");
378  $rs->setSelectText($lng->txt("user_select_course_group"));
379  $rs->setHeaderMessage($lng->txt("user_please_select_course_group"));
380  $rs->setClickableTypes(array("crs", "grp"));
381  $this->addFilterItem($rs);
382  $rs->readFromSession();
383  $this->filter["course_group"] = $rs->getValue();
384  }
385 
386  // global roles
387  $options = array(
388  "" => $lng->txt("user_any"),
389  );
390  $roles = $rbacreview->getRolesByFilter(2, $ilUser->getId());
391  foreach ($roles as $role)
392  {
393  $options[$role["rol_id"]] = $role["title"];
394  }
395  $si = new ilSelectInputGUI($this->lng->txt("user_global_role"), "global_role");
396  $si->setOptions($options);
397  $this->addFilterItem($si);
398  $si->readFromSession();
399  $this->filter["global_role"] = $si->getValue();
400  }
401 
405  protected function fillRow($user)
406  {
407  global $ilCtrl, $lng;
408 
409  $ilCtrl->setParameterByClass("ilobjusergui", "letter", $_GET["letter"]);
410 
411  foreach ($this->getSelectedColumns() as $c)
412  {
413 
414  if ($c == "access_until")
415  {
416  $this->tpl->setCurrentBlock("access_until");
417  $this->tpl->setVariable("VAL_ACCESS_UNTIL", $user["access_until"]);
418  $this->tpl->setVariable("CLASS_ACCESS_UNTIL", $user["access_class"]);
419  }
420  else if ($c == "last_login")
421  {
422  $this->tpl->setCurrentBlock("last_login");
423  $this->tpl->setVariable("VAL_LAST_LOGIN",
424  ilDatePresentation::formatDate(new ilDateTime($user['last_login'],IL_CAL_DATETIME)));
425  }
426  else if (in_array($c, array("email", "firstname", "lastname")))
427  {
428  $this->tpl->setCurrentBlock($c);
429  $this->tpl->setVariable("VAL_".strtoupper($c), (string) $user[$c]);
430  }
431  else // all other fields
432  {
433  $this->tpl->setCurrentBlock("user_field");
434  $val = (trim($user[$c]) == "")
435  ? " "
436  : $user[$c];
437 
438  if ($user[$c] != "")
439  {
440  switch ($c)
441  {
442  case "gender":
443  $val = $lng->txt("gender_".$user[$c]);
444  break;
445  }
446  }
447  $this->tpl->setVariable("VAL_UF", $val);
448  }
449 
450  $this->tpl->parseCurrentBlock();
451  }
452 
453  if ($user["usr_id"] != 6)
454  {
455  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
456  {
457  $this->tpl->setCurrentBlock("checkb");
458  $this->tpl->setVariable("ID", $user["usr_id"]);
459  $this->tpl->parseCurrentBlock();
460  }
461  }
462 
463  if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
464  {
465  $this->tpl->setVariable("VAL_LOGIN", $user["login"]);
466  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $user["usr_id"]);
467  $this->tpl->setVariable("HREF_LOGIN",
468  $ilCtrl->getLinkTargetByClass("ilobjusergui", "view"));
469  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", "");
470  }
471  else
472  {
473  $this->tpl->setVariable('VAL_LOGIN_PLAIN',$user['login']);
474  }
475 
476  if($this->getMode() == self::MODE_LOCAL_USER)
477  {
478  $this->tpl->setCurrentBlock('context');
479  $this->tpl->setVariable('VAL_CONTEXT',ilObject::_lookupTitle(ilObject::_lookupObjId($user['time_limit_owner'])));
480  $this->tpl->parseCurrentBlock();
481 
482  $this->tpl->setCurrentBlock('roles');
483  $ilCtrl->setParameter($this->getParentObject(),'obj_id',$user['usr_id']);
484  $this->tpl->setVariable('ROLE_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'assignRoles'));
485  $this->tpl->setVariable('TXT_ROLES',$this->lng->txt('edit'));
486  $ilCtrl->clearParameters($this->getParentObject());
487  $this->tpl->parseCurrentBlock();
488 
489  }
490  }
491 }
492 ?>