ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5
16{
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 {
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 // #18795
172 $caption = $fd["lang_var"]
173 ? $fd["lang_var"]
174 : $f;
175 $cols[$f] = array(
176 "txt" => $lng->txt($caption),
177 "default" => false);
178 }
179 }
180
181 // fields that are always shown
182 unset($cols["username"]);
183
184 return $cols;
185 }
186
190 function getItems()
191 {
192 global $lng;
193//if ($GLOBALS["kk"]++ == 1) nj();
194
196
197 if($this->getMode() == self::MODE_USER_FOLDER)
198 {
199 // All accessible users
200 include_once './Services/User/classes/class.ilLocalUser.php';
201 $user_filter = ilLocalUser::_getFolderIds();
202 }
203 else
204 {
205 if($this->filter['time_limit_owner'])
206 {
207 $user_filter = array($this->filter['time_limit_owner']);
208 }
209 else
210 {
211 // All accessible users
212 include_once './Services/User/classes/class.ilLocalUser.php';
213 $user_filter = ilLocalUser::_getFolderIds();
214 }
215 }
216
217 //#13221 don't show all users if user filter is empty!
218 if(!count($user_filter))
219 {
220 $this->setMaxCount(0);
221 $this->setData(array());
222 return;
223 }
224
225 include_once("./Services/User/classes/class.ilUserQuery.php");
226
227 $additional_fields = $this->getSelectedColumns();
228 unset($additional_fields["firstname"]);
229 unset($additional_fields["lastname"]);
230 unset($additional_fields["email"]);
231 unset($additional_fields["last_login"]);
232 unset($additional_fields["access_until"]);
233
234 $query = new ilUserQuery();
235 $query->setOrderField($this->getOrderField());
236 $query->setOrderDirection($this->getOrderDirection());
237 $query->setOffset($this->getOffset());
238 $query->setLimit($this->getLimit());
239 $query->setTextFilter($this->filter['query']);
240 $query->setActionFilter($this->filter['activation']);
241 $query->setLastLogin($this->filter['last_login']);
242 $query->setLimitedAccessFilter($this->filter['limited_access']);
243 $query->setNoCourseFilter($this->filter['no_courses']);
244 $query->setNoGroupFilter($this->filter['no_groups']);
245 $query->setCourseGroupFilter($this->filter['course_group']);
246 $query->setRoleFilter($this->filter['global_role']);
247 $query->setAdditionalFields($additional_fields);
248 $query->setUserFolder($user_filter);
249 $query->setFirstLetterLastname(ilUtil::stripSlashes($_GET['letter']));
250
251 $usr_data = $query->query();
252
253
254 if (count($usr_data["set"]) == 0 && $this->getOffset() > 0)
255 {
256 $this->resetOffset();
257 $query->setOffset($this->getOffset());
258 $usr_data = $query->query();
259 }
260
261 foreach ($usr_data["set"] as $k => $user)
262 {
263 $current_time = time();
264 if ($user['active'])
265 {
266 if ($user["time_limit_unlimited"])
267 {
268 $txt_access = $lng->txt("access_unlimited");
269 $usr_data["set"][$k]["access_class"] = "smallgreen";
270 }
271 elseif ($user["time_limit_until"] < $current_time)
272 {
273 $txt_access = $lng->txt("access_expired");
274 $usr_data["set"][$k]["access_class"] = "smallred";
275 }
276 else
277 {
278 $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
279 $usr_data["set"][$k]["access_class"] = "small";
280 }
281 }
282 else
283 {
284 $txt_access = $lng->txt("inactive");
285 $usr_data["set"][$k]["access_class"] = "smallred";
286 }
287 $usr_data["set"][$k]["access_until"] = $txt_access;
288 }
289
290 $this->setMaxCount($usr_data["cnt"]);
291 $this->setData($usr_data["set"]);
292 }
293
294 public function getUserIdsForFilter()
295 {
296 if($this->getMode() == self::MODE_USER_FOLDER)
297 {
298 // All accessible users
299 include_once './Services/User/classes/class.ilLocalUser.php';
300 $user_filter = ilLocalUser::_getFolderIds();
301 }
302 else
303 {
304 if($this->filter['time_limit_owner'])
305 {
306 $user_filter = array($this->filter['time_limit_owner']);
307 }
308 else
309 {
310 // All accessible users
311 include_once './Services/User/classes/class.ilLocalUser.php';
312 $user_filter = ilLocalUser::_getFolderIds();
313 }
314 }
315
316 include_once("./Services/User/classes/class.ilUserQuery.php");
317 $query = new ilUserQuery();
318 $query->setOffset(0);
319 $query->setLimit(self::getAllCommandLimit());
320 $query->setTextFilter($this->filter['query']);
321 $query->setActionFilter($this->filter['activation']);
322 $query->setLastLogin($this->filter['last_login']);
323 $query->setLimitedAccessFilter($this->filter['limited_access']);
324 $query->setNoCourseFilter($this->filter['no_courses']);
325 $query->setNoGroupFilter($this->filter['no_groups']);
326 $query->setCourseGroupFilter($this->filter['course_group']);
327 $query->setRoleFilter($this->filter['global_role']);
328 $query->setUserFolder($user_filter);
329 $query->setFirstLetterLastname(ilUtil::stripSlashes($_GET['letter']));
330
331 if($this->getOrderField())
332 {
333 $query->setOrderField(ilUtil::stripSlashes($this->getOrderField()));
334 $query->setOrderDirection(ilUtil::stripSlashes($this->getOrderDirection()));
335 }
336
337 $usr_data = $query->query();
338
339 $user_ids = array();
340 foreach($usr_data["set"] as $item)
341 {
342 // #11632
343 if($item["usr_id"] != SYSTEM_USER_ID)
344 {
345 $user_ids[] = $item["usr_id"];
346 }
347 }
348 return $user_ids;
349 }
350
351
355 function initFilter()
356 {
357 global $lng, $rbacreview, $ilUser, $ilCtrl;
358
359
360 // Show context filter
361 if($this->getMode() == self::MODE_LOCAL_USER)
362 {
363 include_once './Services/User/classes/class.ilLocalUser.php';
364 $parent_ids = ilLocalUser::_getFolderIds();
365
366 if(count($parent_ids) > 1)
367 {
368 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
369 $co = new ilSelectInputGUI($lng->txt('context'),'time_limit_owner');
370
371 $ref_id = $this->getUserFolderId();
372
373 $opt[0] = $this->lng->txt('all_users');
374 $opt[$this->getUserFolderId()] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($this->getUserFolderId())).')';
375
376 foreach($parent_ids as $parent_id)
377 {
378 if($parent_id == $this->getUserFolderId())
379 {
380 continue;
381 }
382 switch($parent_id)
383 {
384 case USER_FOLDER_ID:
385 $opt[USER_FOLDER_ID] = $lng->txt('global_user');
386 break;
387
388 default:
389 $opt[$parent_id] = $lng->txt('users').' ('.ilObject::_lookupTitle(ilObject::_lookupObjId($parent_id)).')';
390 break;
391 }
392 }
393 $co->setOptions($opt);
394 $this->addFilterItem($co);
395 $co->readFromSession();
396 $this->filter['time_limit_owner'] = $co->getValue();
397 }
398 }
399
400 // User name, login, email filter
401 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
402 $ul = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".
403 $lng->txt("name"), "query");
404 $ul->setDataSource($ilCtrl->getLinkTarget($this->getParentObject(),
405 "addUserAutoComplete", "", true));
406 $ul->setSize(20);
407 $ul->setSubmitFormOnEnter(true);
408 $this->addFilterItem($ul);
409 $ul->readFromSession();
410 $this->filter["query"] = $ul->getValue();
411
412 /*
413 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
414 $ti = new ilTextInputGUI($lng->txt("login")."/".$lng->txt("email")."/".$lng->txt("name"), "query");
415 $ti->setMaxLength(64);
416 $ti->setSize(20);
417 $ti->setSubmitFormOnEnter(true);
418 $this->addFilterItem($ti);
419 $ti->readFromSession();
420 $this->filter["query"] = $ti->getValue();
421 */
422
423 // activation
424 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
425 $options = array(
426 "" => $lng->txt("user_all"),
427 "active" => $lng->txt("active"),
428 "inactive" => $lng->txt("inactive"),
429 );
430 $si = new ilSelectInputGUI($this->lng->txt("user_activation"), "activation");
431 $si->setOptions($options);
432 $this->addFilterItem($si);
433 $si->readFromSession();
434 $this->filter["activation"] = $si->getValue();
435
436 // limited access
437 include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
438 $cb = new ilCheckboxInputGUI($this->lng->txt("user_limited_access"), "limited_access");
439 $this->addFilterItem($cb);
440 $cb->readFromSession();
441 $this->filter["limited_access"] = $cb->getChecked();
442
443 // last login
444 include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
445 $di = new ilDateTimeInputGUI($this->lng->txt("user_last_login_before"), "last_login");
446 $default_date = new ilDateTime(time(),IL_CAL_UNIX);
447 $default_date->increment(IL_CAL_DAY, 1);
448 $di->setDate($default_date);
449 $this->addFilterItem($di);
450 $di->readFromSession();
451 $this->filter["last_login"] = $di->getDate();
452
453 if($this->getMode() == self::MODE_USER_FOLDER)
454 {
455 // no assigned courses
456 include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
457 $cb = new ilCheckboxInputGUI($this->lng->txt("user_no_courses"), "no_courses");
458 $this->addFilterItem($cb);
459 $cb->readFromSession();
460 $this->filter["no_courses"] = $cb->getChecked();
461
462 // no assigned groups
463 include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
464 $ng = new ilCheckboxInputGUI($this->lng->txt("user_no_groups"), "no_groups");
465 $this->addFilterItem($ng);
466 $ng->readFromSession();
467 $this->filter['no_groups'] = $ng->getChecked();
468
469 // course/group members
470 include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
471 $rs = new ilRepositorySelectorInputGUI($lng->txt("user_member_of_course_group"), "course_group");
472 $rs->setSelectText($lng->txt("user_select_course_group"));
473 $rs->setHeaderMessage($lng->txt("user_please_select_course_group"));
474 $rs->setClickableTypes(array("crs", "grp"));
475 $this->addFilterItem($rs);
476 $rs->readFromSession();
477 $this->filter["course_group"] = $rs->getValue();
478 }
479
480 // global roles
481 $options = array(
482 "" => $lng->txt("user_any"),
483 );
484 $roles = $rbacreview->getRolesByFilter(2, $ilUser->getId());
485 foreach ($roles as $role)
486 {
487 $options[$role["rol_id"]] = $role["title"];
488 }
489 $si = new ilSelectInputGUI($this->lng->txt("user_global_role"), "global_role");
490 $si->setOptions($options);
491 $this->addFilterItem($si);
492 $si->readFromSession();
493 $this->filter["global_role"] = $si->getValue();
494 }
495
499 protected function fillRow($user)
500 {
501 global $ilCtrl, $lng;
502
503 $ilCtrl->setParameterByClass("ilobjusergui", "letter", $_GET["letter"]);
504
505 foreach ($this->getSelectedColumns() as $c)
506 {
507 if ($c == "access_until")
508 {
509 $this->tpl->setCurrentBlock("access_until");
510 $this->tpl->setVariable("VAL_ACCESS_UNTIL", $user["access_until"]);
511 $this->tpl->setVariable("CLASS_ACCESS_UNTIL", $user["access_class"]);
512 }
513 else if ($c == "last_login")
514 {
515 $this->tpl->setCurrentBlock("last_login");
516 $this->tpl->setVariable("VAL_LAST_LOGIN",
518 }
519 else if (in_array($c, array("firstname", "lastname")))
520 {
521 $this->tpl->setCurrentBlock($c);
522 $this->tpl->setVariable("VAL_".strtoupper($c), (string) $user[$c]);
523 }
524 else // all other fields
525 {
526 $this->tpl->setCurrentBlock("user_field");
527 $val = (trim($user[$c]) == "")
528 ? " "
529 : $user[$c];
530
531 if ($user[$c] != "")
532 {
533 switch ($c)
534 {
535 case "birthday":
537 break;
538
539 case "gender":
540 $val = $lng->txt("gender_".$user[$c]);
541 break;
542
543 case "create_date":
544 case "agree_date":
545 case "approve_date":
546 // $val = ilDatePresentation::formatDate(new ilDateTime($val,IL_CAL_DATETIME));
548 break;
549 }
550 }
551 $this->tpl->setVariable("VAL_UF", $val);
552 }
553
554 $this->tpl->parseCurrentBlock();
555 }
556
557 if ($user["usr_id"] != 6)
558 {
559 if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
560 {
561 $this->tpl->setCurrentBlock("checkb");
562 $this->tpl->setVariable("ID", $user["usr_id"]);
563 $this->tpl->parseCurrentBlock();
564 }
565 }
566
567 if($this->getMode() == self::MODE_USER_FOLDER or $user['time_limit_owner'] == $this->getUserFolderId())
568 {
569 $this->tpl->setVariable("VAL_LOGIN", $user["login"]);
570 $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $user["usr_id"]);
571 $this->tpl->setVariable("HREF_LOGIN",
572 $ilCtrl->getLinkTargetByClass("ilobjusergui", "view"));
573 $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", "");
574 }
575 else
576 {
577 $this->tpl->setVariable('VAL_LOGIN_PLAIN',$user['login']);
578 }
579
580 if($this->getMode() == self::MODE_LOCAL_USER)
581 {
582 $this->tpl->setCurrentBlock('context');
583 $this->tpl->setVariable('VAL_CONTEXT',(string)ilObject::_lookupTitle(ilObject::_lookupObjId($user['time_limit_owner'])));
584 $this->tpl->parseCurrentBlock();
585
586 $this->tpl->setCurrentBlock('roles');
587 $ilCtrl->setParameter($this->getParentObject(),'obj_id',$user['usr_id']);
588 $this->tpl->setVariable('ROLE_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'assignRoles'));
589 $this->tpl->setVariable('TXT_ROLES',$this->lng->txt('edit'));
590 $ilCtrl->clearParameters($this->getParentObject());
591 $this->tpl->parseCurrentBlock();
592
593 }
594 }
595}
596?>
$_GET["client_id"]
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
const USER_FOLDER_ID
Class ilObjUserFolder.
This class represents a checkbox property in a property form.
static formatDate(ilDateTime $date)
Format a date @access public.
This class represents a date/time property in a property form.
@classDescription Date and time handling
Class for single dates.
static _getFolderIds()
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
This class represents a repository selector in a property form.
This class represents a selection list property in a property form.
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
setEnableHeader($a_enableheader)
Set Enable Header.
setExternalSorting($a_val)
Set external sorting.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getParentObject()
Get parent object.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setEnableAllCommand($a_value)
Enable actions for all entries in current result.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
getLimit()
Get limit.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
resetOffset($a_in_determination=false)
Reset offset.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
getOffset()
Get offset.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
This class represents a text property in a property form.
Class ilUserProfile.
User query class.
TableGUI class for user administration.
initFilter()
Init filter.
__construct($a_parent_obj, $a_parent_cmd, $a_mode=self::MODE_USER_FOLDER, $a_load_items=true)
Constructor.
getSelectableColumns()
Get selectable columns.
getItems()
Get user items.
fillRow($user)
Fill table row.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15