ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdminUserSearchGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once 'Services/Search/classes/class.ilSearchResult.php';
25 include_once 'Services/Search/classes/class.ilSearchSettings.php';
26 include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
27 
28 
44 {
45  var $search_type = 'usr';
46 
47 
48  public function __construct()
49  {
51 
52  $this->setTitle($this->lng->txt('search_user_extended'));
53  }
54 
55  function __clearSession()
56  {
57  unset($_SESSION['rep_search']);
58  unset($_SESSION['append_results']);
59  unset($_SESSION['rep_query']);
60  unset($_SESSION['rep_search_type']);
61  unset($_SESSION['usr_query_active']);
62  }
63 
64  function start()
65  {
66  // delete all session info
67  //$this->__clearSession();
68  $this->showExtended();
69 
70  return true;
71  }
72 
73  function startSimple()
74  {
75  // delete all session info
76  $this->__clearSession();
77  $_SESSION["usr_search_mode"] = "simple";
78  $this->performSearchSimple();
79 
80  return true;
81  }
82 
83  function startExtended()
84  {
85  // delete all session info
86  $this->__clearSession();
87  $_SESSION["usr_search_mode"] = "extended";
88  $this->showExtended();
89 
90  return true;
91  }
92 
93  function showExtended()
94  {
95  global $ilTabs;
96 
97  $this->setSubTabs();
98  $ilTabs->activateSubTab("searchform");
99 
100  $_SESSION["usr_search_mode"] = "extended";
101 
102  //add template for buttons
103  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
104 
105  // search extended
106  /*$this->tpl->setCurrentBlock("btn_cell");
107  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'show'));
108  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("search_user_simple"));
109  $this->tpl->parseCurrentBlock();*/
110 
111  /*$this->tpl->setCurrentBlock("btn_cell");
112  $this->tpl->setVariable("BTN_LINK",$this->callback_class->ctrl->getLinkTarget($this->callback_class, "importUserForm"));
113  $this->tpl->setVariable("BTN_TXT", $this->lng->txt("import_users"));
114  $this->tpl->parseCurrentBlock();*/
115  $this->__showSearch();
116  $this->__showSearchResults();
117  }
118 
119  function show()
120  {
121  global $ilTabs;
122 
123  $_SESSION["usr_search_mode"] = "simple";
124 
125  //add template for buttons
126  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
127 
128  $this->setSubTabs();
129  $ilTabs->activateSubTab("searchresults");
130 
131  // search extended
132  /*$this->tpl->setCurrentBlock("btn_cell");
133  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'showExtended'));
134  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("search_user_extended"));
135  $this->tpl->parseCurrentBlock();
136 
137  $this->tpl->setCurrentBlock("btn_cell");
138  $this->tpl->setVariable("BTN_LINK",$this->callback_class->ctrl->getLinkTarget($this->callback_class, "importUserForm"));
139  $this->tpl->setVariable("BTN_TXT", $this->lng->txt("import_users"));
140  $this->tpl->parseCurrentBlock();*/
141  $this->__showSearchSimple();
142  $this->__showSearchResults();
143  }
144 
149  {
150  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.usr_search_simple.html','Services/Search');
151 
152  $this->ctrl->setParameter($this,'search','1');
153 
154  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this,'startSimple'));
155  $this->tpl->setVariable("TXT_SEARCH",$this->lng->txt("search"));
156  if(count($_SESSION['rep_search']['usr']))
157  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt('append_results'));
158 
159  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search_user"));
160  }
161 
162  function __showSearch()
163  {
164  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.rep_search.html','Services/Search');
165  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this,'startExtended'));
166  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_usr.gif'));
167  $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_usr'));
168  $this->tpl->setVariable("SEARCH_MEMBERS_HEADER",$this->lng->txt("search_user_extended"));
169 
170 
171  // user search
172  $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("search_for_users"));
173  $this->tpl->setVariable("SEARCH_ROW_CHECK_USER",ilUtil::formRadioButton($this->search_type == 'usr',"search_for","usr"));
174  $this->__fillUserSearch();
175 
176 
177  // groups
178  $this->tpl->setVariable("SEARCH_ROW_TXT_GROUP",$this->lng->txt("search_for_grp_members"));
179  $this->tpl->setVariable("GROUP_TERM",$this->lng->txt('search_grp_title'));
180  $this->tpl->setVariable("SEARCH_ROW_CHECK_GROUP",ilUtil::formRadioButton($this->search_type == 'grp',"search_for","grp"));
181  $this->tpl->setVariable("GRP_VALUE",$_SESSION['rep_query']['grp']['title']);
182 
183 
184  // roles
185  $this->tpl->setVariable("SEARCH_ROW_TXT_ROLE",$this->lng->txt("search_for_role_members"));
186  $this->tpl->setVariable("ROLE_TERM",$this->lng->txt('search_role_title'));
187  $this->tpl->setVariable("SEARCH_ROW_CHECK_ROLE",ilUtil::formRadioButton($this->search_type == 'role',"search_for","role"));
188  $this->tpl->setVariable("ROLE_VALUE",$_SESSION['rep_query']['role']['title']);
189 
190 
191  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
192  if(count($_SESSION['rep_search']['usr']))
193  {
194  $this->tpl->setVariable("BTN3_VALUE",$this->lng->txt('append_results'));
195  }
196  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
197  }
198 
199  function appendSearch()
200  {
201  $_SESSION['search_append'] = true;
202  $this->performSearch();
203  }
204 
206  {
207  $_SESSION['search_append'] = true;
208  $this->performSearchSimple();
209  }
210 
212  {
213  $_SESSION["usr_search_mode"] = "simple";
214 
215  // unset search_append if called directly
216  if($_POST['cmd']['performSearchSimple'])
217  {
218  unset($_SESSION['search_append']);
219  }
220 
221  // fields to search in
222  $_POST["search_fields"] = array ("username","firstname","lastname","email");
223 
224  // search only for active users
225  $_POST['active'] = 1;
226 
227  $_POST["search_string"] = trim($_POST["search_string"]) ? trim($_POST["search_string"]) : trim(urldecode($_GET["search_string"]));
228  $_SESSION['us_active'] = isset($_POST['active']) ? $_POST['active'] : $_SESSION['us_active'];
229  $_SESSION['us_active'] = $_SESSION["user_filter"];
230 
231  if (empty($_POST["search_string"]))
232  {
233  $_POST["search_string"] = "%";
234  }
235 
236  // return if no user found
237  if (count($search_result = ilObjUser::searchUsers($_POST["search_string"],$_SESSION['us_active'],true, $_GET["user_filter"])) == 0)
238  {
239  if ($_POST["search_string"] == "%")
240  {
241  $_POST["search_string"] = "";
242  }
243 
244  $msg = $this->lng->txt("msg_no_search_result");
245 
246  if ($_POST["search_string"] != "")
247  {
248  $msg .= " ".$this->lng->txt("with")." '".htmlspecialchars($_POST["search_string"])."'";
249  }
250 
251  if ($_GET['search'])
252  {
253  global $ilErr;
254  $ilErr->raiseError($msg,$ilErr->MESSAGE);
255  }
256  else
257  {
258  ilUtil::sendInfo($msg, true);
259  $this->ctrl->setParameterByClass("ilobjuserfoldergui", "user_filter", $_GET["user_filter"]);
260  $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
261  }
262  }
263 
264  if(!$_SESSION['search_append'])
265  {
266  $_SESSION['rep_search']['usr'] = array();
267  }
268 
269  foreach($search_result as $result)
270  {
271  $_SESSION['rep_search']['usr'][] = $result;
272  }
273 
274  if(!$_SESSION['rep_search'][$this->search_type])
275  {
276  $_SESSION['rep_search'][$this->search_type] = array();
277  }
278  else
279  {
280  // remove duplicate entries
281  $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
282  }
283 
284  $this->show();
285  }
286 
287  function performSearch()
288  {
289  // unset search_append if called directly
290  if($_POST['cmd']['performSearch'])
291  {
292  unset($_SESSION['search_append']);
293  }
294 
295  switch($this->search_type)
296  {
297  case 'usr':
298  $this->__performUserSearch();
299  break;
300 
301  case 'grp':
302  $this->__performGroupSearch();
303  break;
304 
305  case 'role':
306  $this->__performRoleSearch();
307  break;
308 
309  default:
310  echo 'not defined';
311  }
312  $this->result_obj->addObserver($this, 'userFilter');
313  $this->result_obj->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
314 
315  if(!count($this->result_obj->getResults()))
316  {
317  ilUtil::sendInfo($this->lng->txt('search_no_match'));
318  #global $ilErr;
319  #$ilErr->raiseError($this->lng->txt('search_no_match'),$ilErr->MESSAGE);
320  }
321  $this->__updateResults();
322  if($this->result_obj->isLimitReached())
323  {
324  $message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
325  ilUtil::sendInfo($message);
326  }
327  // show results
328  if ($_SESSION["usr_search_mode"] == "extended")
329  $this->showExtended();
330  else
331  $this->show();
332  }
333 
335  {
336  include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
337  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
338 
339  foreach(ilUserSearchOptions::_getSearchableFieldsInfo(true) as $info)
340  {
341  $name = $info['db'];
342  $query_string = $_SESSION['rep_query']['usr'][$name];
343  $active_status = $_SESSION['usr_query_active'];
344 
345  // continue if no query string is given
346  if(!$query_string)
347  {
348  continue;
349  }
350 
351  if(!is_object($query_parser = $this->__parseQueryString($query_string)))
352  {
353  ilUtil::sendInfo($query_parser);
354  return false;
355  }
356  switch($info['type'])
357  {
359  case FIELD_TYPE_UDF_TEXT:
361  $udf_search->setFields(array($name));
362  $result_obj = $udf_search->performSearch();
363 
364  // Store entries
365  $this->__storeEntries($result_obj);
366  break;
367 
368  case FIELD_TYPE_SELECT:
369  case FIELD_TYPE_TEXT:
370  $user_search =& ilObjectSearchFactory::_getUserSearchInstance($query_parser);
371  $user_search->setFields(array($name));
372 
373  if ($active_status == 1)
374  $user_search->enableActiveCheck(true);
375  elseif ($active_status == 2)
376  $user_search->enableInactiveCheck(true);
377 
378  $result_obj = $user_search->performSearch();
379 
380  // store entries
381  $this->__storeEntries($result_obj);
382  break;
383  }
384  }
385  }
386 
388  {
389  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
390 
391  $query_string = $_SESSION['rep_query']['grp']['title'];
392  if(!is_object($query_parser = $this->__parseQueryString($query_string)))
393  {
394  ilUtil::sendInfo($query_parser,true);
395  return false;
396  }
397 
398  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
399  $object_search = new ilLikeObjectSearch($query_parser);
400  $object_search->setFilter(array('grp'));
401  $this->__storeEntries($object_search->performSearch());
402 
403  return true;
404  }
405 
407  {
408  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
409 
410  $query_string = $_SESSION['rep_query']['role']['title'];
411  if(!is_object($query_parser = $this->__parseQueryString($query_string)))
412  {
413  ilUtil::sendInfo($query_parser,true);
414  return false;
415  }
416 
417  // Perform like search
418  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
419  $object_search = new ilLikeObjectSearch($query_parser);
420  $object_search->setFilter(array('role'));
421  $this->__storeEntries($object_search->performSearch());
422 
423  return true;
424  }
425 
431  function &__parseQueryString($a_string)
432  {
433  include_once 'Services/Search/classes/class.ilQueryParser.php';
434 
435  $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
436  $query_parser->setCombination(QP_COMBINATION_OR);
437  $query_parser->setMinWordLength(1,true);
438  $query_parser->parse();
439 
440  if(!$query_parser->validate())
441  {
442  return $query_parser->getMessage();
443  }
444  return $query_parser;
445  }
446 
447  // Private
448  function __loadQueries()
449  {
450 
451  if(is_array($_POST['rep_query']))
452  {
453  $_SESSION['usr_query_active'] = ($_POST['usr_query_active']) ? $_POST['usr_query_active'] : 0;
454  $_SESSION['rep_query'] = $_POST['rep_query'];
455  }
456  }
457 
458 
459  function __setSearchType()
460  {
461  // Update search type. Default to user search
462  if($_POST['search_for'])
463  {
464  #echo 1;
465  $_SESSION['rep_search_type'] = $_POST['search_for'];
466  }
467  if(!$_POST['search_for'] and !$_SESSION['rep_search_type'])
468  {
469  #echo 2;
470  $_SESSION['rep_search_type'] = 'usr';
471  }
472 
473  $this->search_type = $_SESSION['rep_search_type'];
474  #echo $this->search_type;
475 
476  return true;
477  }
478 
479  function __fillUserSearch()
480  {
481  global $lng;
482 
483  include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
484 
485  // active flag
486  $values = array('0' => $lng->txt('please_choose'),
487  '1' => $lng->txt('active'),
488  '2' => $lng->txt('inactive'));
489 
490  $this->tpl->setCurrentBlock("select_field");
491  $this->tpl->setVariable("SELECT_NAME",$lng->txt('active'));
492 
493  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($_SESSION['usr_query_active'],
494  "usr_query_active",
495  $values,
496  false,
497  true));
498  $this->tpl->parseCurrentBlock();
499 
500  foreach(ilUserSearchOptions::_getSearchableFieldsInfo(true) as $info)
501  {
502  switch($info['type'])
503  {
505  case FIELD_TYPE_SELECT:
506  $this->tpl->setCurrentBlock("select_field");
507  $this->tpl->setVariable("SELECT_NAME",$info['lang']);
508 
509  $name = $info['db'];
510  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($_SESSION['rep_query']['usr'][$name],
511  "rep_query[usr][$name]",
512  $info['values'],
513  false,
514  true));
515  $this->tpl->parseCurrentBlock();
516  break;
517 
518  case FIELD_TYPE_UDF_TEXT:
519  case FIELD_TYPE_TEXT:
520  $this->tpl->setCurrentBlock("text_field");
521  $this->tpl->setVariable("TEXT_NAME",$info['lang']);
522 
523  $name = $info['db'];
524  $this->tpl->setVariable("USR_NAME","rep_query[usr][$name]");
525  $this->tpl->setVariable("USR_VALUE",$_SESSION['rep_query']['usr'][$name]);
526  $this->tpl->parseCurrentBlock();
527  break;
528  }
529  $this->tpl->setCurrentBlock("usr_rows");
530  $this->tpl->parseCurrentBlock();
531  }
532 
533  }
534 
535  function __updateResults()
536  {
537  if(!$_SESSION['search_append'])
538  {
539  $_SESSION['rep_search'] = array();
540  }
541  foreach($this->result_obj->getResults() as $result)
542  {
543  $_SESSION['rep_search'][$this->search_type][] = $result['obj_id'];
544  }
545  if(!$_SESSION['rep_search'][$this->search_type])
546  {
547  $_SESSION['rep_search'][$this->search_type] = array();
548  }
549  else
550  {
551  // remove duplicate entries
552  $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
553  }
554  return true;
555  }
556 
557  function __appendToStoredResults($a_usr_ids)
558  {
559  if(!$_SESSION['search_append'])
560  {
561  return $_SESSION['rep_search']['usr'] = $a_usr_ids;
562  }
563  foreach($a_usr_ids as $usr_id)
564  {
565  $_SESSION['rep_search']['usr'][] = $usr_id;
566  }
567  return $_SESSION['rep_search']['usr'] ? array_unique($_SESSION['rep_search']['usr']) : array();
568  }
569 
570  function __storeEntries(&$new_res)
571  {
572  if($this->stored == false)
573  {
574  $this->result_obj->mergeEntries($new_res);
575  $this->stored = true;
576  return true;
577  }
578  else
579  {
580  $this->result_obj->intersectEntries($new_res);
581  return true;
582  }
583  }
584 
585  function __fillUserTable($user_ids)
586  {
587  $user_ids = $user_ids ? $user_ids : array();
588 
589  $counter = 0;
590  foreach($user_ids as $usr_id)
591  {
592  if(!is_object($tmp_obj = ilObjectFactory::getInstanceByObjId($usr_id,false)))
593  {
594  continue;
595  }
596 
597  $user_ids[$counter] = $usr_id;
598 
599  // determine txt_access
600  // Note: If you do changes here, you have to change the corresponding
601  // code in ilObjUserFolderGUI::viewObject as well.
602  if ($tmp_obj->getActive())
603  {
604  if ($tmp_obj->getTimeLimitUnlimited())
605  {
606  $txt_access = $this->lng->txt("access_unlimited");
607  }
608  elseif ($tmp_obj->getTimeLimitUntil() < time())
609  {
610  $txt_access = $this->lng->txt("access_expired");
611  }
612  else
613  {
614  $txt_access = ilDatePresentation::formatDate(new ilDateTime($tmp_obj->getTimeLimitUntil(),IL_CAL_UNIX));
615  }
616  }
617  else
618  {
619  $txt_access = $this->lng->txt("inactive");
620  }
621 
622  $f_result[$counter][] = ilUtil::formCheckbox(0,"id[]",$usr_id);
623  $f_result[$counter][] = $tmp_obj->getLogin();
624  $f_result[$counter][] = $tmp_obj->getFirstname();
625  $f_result[$counter][] = $tmp_obj->getLastname();
626  $f_result[$counter][] = $tmp_obj->getEmail();
627  $f_result[$counter][] = $txt_access;
628  $f_result[$counter][] = $tmp_obj->getLastLogin();
629  $f_result[$counter][] = $usr_id;
630 
631  unset($tmp_obj);
632  ++$counter;
633  }
634  return $f_result ? $f_result : array();
635  }
636 
637  function __fillGroupTable($group_ids)
638  {
639  $group_ids = $group_ids ? $group_ids : array();
640 
641  $counter = 0;
642  foreach($group_ids as $group_id)
643  {
644  if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($ref_id = end(
645  $ref_ids = ilObject::_getAllReferences($group_id)),false))
646  {
647  continue;
648  }
649  $grp_ids[$counter] = $group_id;
650 
651  $f_result[$counter][] = ilUtil::formCheckbox(0,"group[]",$ref_id);
652  $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
653  $f_result[$counter][] = $tmp_obj->getCountMembers();
654 
655  unset($tmp_obj);
656  ++$counter;
657  }
658  return $f_result ? $f_result : array();
659  }
660 
661  function __fillRoleTable($role_ids)
662  {
663  $role_ids = $role_ids ? $role_ids : array();
664 
665  $counter = 0;
666  foreach($role_ids as $role_id)
667  {
668  // exclude anonymous role
669  if ($role_id == ANONYMOUS_ROLE_ID)
670  {
671  continue;
672  }
673  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($role_id,false))
674  {
675  continue;
676  }
677  // exclude roles with no users assigned to
678  if ($tmp_obj->getCountMembers() == 0)
679  {
680  continue;
681  }
682  $role_ids[$counter] = $role_id;
683 
684  $f_result[$counter][] = ilUtil::formCheckbox(0,"role[]",$role_id);
685  $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
686  $f_result[$counter][] = $tmp_obj->getCountMembers();
687 
688  unset($tmp_obj);
689  ++$counter;
690  }
691  return $f_result ? $f_result : array();
692  }
693 
694 
696  {
697  $counter = 0;
698  $f_result = array();
699  switch($this->search_type)
700  {
701  case "usr":
702  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
703  $this->__showSearchUserTable($result,$_SESSION['rep_search']['usr']);
704  break;
705 
706  case 'grp':
707  $result = $this->__fillGroupTable($_SESSION['rep_search']['grp']);
708  $this->__showSearchGroupTable($result,$_SESSION['rep_search']['grp']);
709  break;
710 
711  case 'role':
712  $result = $this->__fillRoleTable($_SESSION['rep_search']['role']);
713  $this->__showSearchRoleTable($result,$_SESSION['rep_search']['role']);
714  break;
715  }
716 
717  // Finally fill user table, if search type append
718  if($_SESSION['search_append'] and $this->search_type != 'usr')
719  {
720  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
721  $this->__showSearchUserTable($result,$_SESSION['rep_search']['usr'],'search','APPEND_TABLE');
722 
723  }
724  }
725  function __showSearchUserTable($a_result_set,$a_user_ids = NULL,$a_cmd = "performSearch",$tpl_var = 'RES_TABLE')
726  {
727  if(!$a_result_set)
728  {
729  return false;
730  }
731 
732  $tbl =& $this->__initTableGUI();
733  $tpl =& $tbl->getTemplateObject();
734 
735  // SET FORMACTION
736  $tpl->setCurrentBlock("tbl_form_header");
737  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
738  $tpl->parseCurrentBlock();
739 
740  $operations = array(
741  array("name" => "delete", "lng" => "delete"),
742  array("name" => "activate", "lng" => "activate"),
743  array("name" => "deactivate", "lng" => "deactivate"),
744  array("name" => "accessRestrict", "lng" => "accessRestrict"),
745  array("name" => "accessFree", "lng" => "accessFree"),
746  array("name" => "export", "lng" => "export")
747  );
748 
749  if (count($operations) > 0)
750  {
751  $select = "<select name=\"selectedAction\">\n";
752  foreach ($operations as $val)
753  {
754  $select .= "<option value=\"" . $val["name"] . "\"";
755  if (strcmp($_POST["selectedAction"], $val["name"]) == 0)
756  {
757  $select .= " selected=\"selected\"";
758  }
759  $select .= ">";
760  $select .= $this->lng->txt($val["lng"]);
761  $select .= "</option>";
762  }
763  $select .= "</select>";
764  $tpl->setCurrentBlock("tbl_action_select");
765  $tpl->setVariable("SELECT_ACTION", $select);
766  $tpl->setVariable("BTN_NAME", "userAction");
767  $tpl->setVariable("BTN_VALUE", $this->lng->txt("submit"));
768  $tpl->parseCurrentBlock();
769  }
770 
771  $tpl->setCurrentBlock("tbl_action_row");
772  $tpl->setVariable("COLUMN_COUNTS",7);
773  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
774  $tpl->parseCurrentBlock();
775 
776  $tbl->setTitle($this->lng->txt("search_results"),"icon_usr.gif",$this->lng->txt("search_results"));
777  $tbl->setHeaderNames(array("",
778  $this->lng->txt("username"),
779  $this->lng->txt("firstname"),
780  $this->lng->txt("lastname"),
781  $this->lng->txt("email"),
782  $this->lng->txt("access_until"),
783  $this->lng->txt("last_login")));
784  $tbl->setHeaderVars(array("",
785  "login",
786  "firstname",
787  "lastname",
788  "email",
789  "access_until",
790  "last_login"),
791  array("ref_id" => $_GET['ref_id'],
792  "cmd" => ($_SESSION['usr_search_mode'] == 'extended') ? 'showExtended' : 'show',
793  "cmdClass" => "iladminusersearchgui",
794  "cmdNode" => $_GET["cmdNode"],
795  "baseClass" => "ilAdministrationGUI"));
796 
797  $tbl->setColumnWidth(array("","15%","15%","15%","20%","15%","20%"));
798 
799  $this->__setTableGUIUserData($tbl,$a_result_set);
800  $tbl->render();
801 
802  $this->tpl->setVariable($tpl_var,$tbl->tpl->get());
803 
804  return true;
805  }
806 
807  function __showSearchGroupTable($a_result_set,$a_grp_ids = NULL)
808  {
809  if(!$a_result_set)
810  {
811  return false;
812  }
813 
814  $tbl =& $this->__initTableGUI();
815  $tpl =& $tbl->getTemplateObject();
816 
817  $tpl->setCurrentBlock("tbl_form_header");
818  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
819  $tpl->parseCurrentBlock();
820 
821  $tpl->setCurrentBlock("tbl_action_btn");
822  $tpl->setVariable("BTN_NAME","listUsersGroup");
823  $tpl->setVariable("BTN_VALUE",$this->lng->txt("crs_list_users"));
824  $tpl->parseCurrentBlock();
825 
826  if (!empty($a_grp_ids))
827  {
828  $tpl->setCurrentBlock("tbl_select_all");
829  $tpl->setVariable("COLUMN_COUNTS",4);
830  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
831  $tpl->parseCurrentBlock();
832  }
833 
834  $tpl->setCurrentBlock("tbl_action_row");
835  $tpl->setVariable("COLUMN_COUNTS",5);
836  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
837  $tpl->parseCurrentBlock();
838 
839  $tbl->setTitle($this->lng->txt("crs_header_edit_members"),"icon_grp.gif",$this->lng->txt("crs_header_edit_members"));
840  $tbl->setHeaderNames(array("",
841  $this->lng->txt("obj_grp"),
842  $this->lng->txt("crs_count_members")));
843  $tbl->setHeaderVars(array("",
844  "title",
845  "nr_members"),
846  array("ref_id" => $_GET['ref_id'],
847  "cmd" => "show",
848  "cmdClass" => "iladminusersearchgui",
849  "cmdNode" => $_GET["cmdNode"],
850  'baseClass' => 'ilAdministrationGUI'
851  )
852  );
853 
854 
855  $tbl->setColumnWidth(array("","80%","19%"));
856 
857 
858  $this->__setTableGUIBasicData($tbl,$a_result_set,"group");
859  $tbl->render();
860 
861  $this->tpl->setVariable("RES_TABLE",$tbl->tpl->get());
862 
863  return true;
864  }
865  function __showSearchRoleTable($a_result_set,$a_role_ids)
866  {
867  if(!$a_result_set)
868  {
869  return false;
870  }
871 
872  $tbl =& $this->__initTableGUI();
873  $tpl =& $tbl->getTemplateObject();
874 
875  $tpl->setCurrentBlock("tbl_form_header");
876  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
877  $tpl->parseCurrentBlock();
878 
879  $tpl->setCurrentBlock("tbl_action_btn");
880  $tpl->setVariable("BTN_NAME","listUsersRole");
881  $tpl->setVariable("BTN_VALUE",$this->lng->txt("crs_list_users"));
882  $tpl->parseCurrentBlock();
883 
884  if (!empty($a_role_ids))
885  {
886  $tpl->setCurrentBlock("tbl_select_all");
887  $tpl->setVariable("COLUMN_COUNTS",4);
888  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
889  $tpl->parseCurrentBlock();
890  }
891 
892  $tpl->setCurrentBlock("tbl_action_row");
893  $tpl->setVariable("COLUMN_COUNTS",5);
894  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
895  $tpl->parseCurrentBlock();
896 
897  $tbl->setTitle($this->lng->txt("crs_header_edit_members"),"icon_role.gif",$this->lng->txt("crs_header_edit_members"));
898  $tbl->setHeaderNames(array("",
899  $this->lng->txt("objs_role"),
900  $this->lng->txt("crs_count_members")));
901  $tbl->setHeaderVars(array("",
902  "title",
903  "nr_members"),
904  array("ref_id" => $_GET['ref_id'],
905  "cmd" => "show",
906  "cmdClass" => "iladminusersearchgui",
907  "cmdNode" => $_GET["cmdNode"]));
908 
909  $tbl->setColumnWidth(array("","80%","19%"));
910 
911  $this->__setTableGUIBasicData($tbl,$a_result_set,"role");
912  $tbl->disable("auto_sort");
913  $tbl->render();
914 
915  $this->tpl->setVariable("RES_TABLE",$tbl->tpl->get());
916 
917  return true;
918  }
919 
920 
921  function listUsersGroup()
922  {
923  global $rbacsystem,$tree;
924 
925  $_SESSION["crs_group"] = $_POST["group"] = $_POST["group"] ? $_POST["group"] : $_SESSION["crs_group"];
926 
927  if(!is_array($_POST["group"]))
928  {
929  ilUtil::sendInfo($this->lng->txt("crs_no_groups_selected"));
930  $this->show();
931 
932  return false;
933  }
934 
935  $this->__showSearch();
936 
937  // GET ALL MEMBERS
938  $members = array();
939  foreach($_POST["group"] as $group_id)
940  {
941  if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($group_id))
942  {
943  continue;
944  }
945  $members = array_merge($tmp_obj->getGroupMemberIds(),$members);
946 
947  unset($tmp_obj);
948  }
949  $this->__appendToStoredResults($members);
950 
951  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
952  $this->__showSearchUserTable($result,$_SESSION['rep_search']['usr'],"listUsersGroup");
953 
954  return true;
955  }
956  function listUsersRole()
957  {
958  global $rbacsystem,$rbacreview,$tree;
959 
960  $_SESSION["crs_role"] = $_POST["role"] = $_POST["role"] ? $_POST["role"] : $_SESSION["crs_role"];
961 
962  if(!is_array($_POST["role"]))
963  {
964  ilUtil::sendInfo($this->lng->txt("crs_no_roles_selected"));
965  $this->show();
966 
967  return false;
968  }
969 
970  $this->__showSearch();
971 
972  // GET ALL MEMBERS
973  $members = array();
974  foreach($_POST["role"] as $role_id)
975  {
976  $members = array_merge($rbacreview->assignedUsers($role_id),$members);
977  }
978  $members = $this->__appendToStoredResults($members);
979 
980  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
981  $this->__showSearchUserTable($result,$user_ids,"listUsersRole");
982 
983  return true;
984  }
985 
986 
987 
988  function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
989  {
990  global $ilUser;
991 
992  switch($from)
993  {
994  case "group":
995  $offset = $_GET["offset"];
996  $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
997  $direction = $_GET["sort_order"];
998  $tbl->setLimit(1000000);
999  break;
1000 
1001  case "role":
1002  $offset = $_GET["offset"];
1003  $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
1004  $direction = $_GET["sort_order"];
1005  $tbl->setLimit(1000000);
1006  break;
1007 
1008  default:
1009  $offset = $_GET["offset"];
1010  // init sort_by (unfortunatly sort_by is preset with 'title'
1011  if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"]))
1012  {
1013  $_GET["sort_by"] = "login";
1014  }
1015  $order = $_GET["sort_by"];
1016  $direction = $_GET["sort_order"];
1017  $tbl->setLimit($ilUser->getPref('hits_per_page'));
1018  break;
1019  }
1020 
1021  $tbl->setOrderColumn($order);
1022  $tbl->setOrderDirection($direction);
1023  $tbl->setOffset($offset);
1024  $tbl->setMaxCount(count($result_set));
1025  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1026  $tbl->setData($result_set);
1027  }
1028 
1029  function &__initTableGUI()
1030  {
1031  include_once "./Services/Table/classes/class.ilTableGUI.php";
1032 
1033  return new ilTableGUI(0,false);
1034  }
1035 
1036  function __setTableGUIUserData(&$tbl,&$result_set,$from = "")
1037  {
1038  global $ilUser;
1039 
1040  // remember link target to admin search gui (this)
1041  $_SESSION["usr_search_link"] = $this->ctrl->getLinkTarget($this,'show');
1042 
1043  $tbl->disable("auto_sort");
1044  $tbl->enable("select_all");
1045  $tbl->setFormName("cmd");
1046  $tbl->setSelectAllCheckbox("id");
1047 
1048  $offset = $_GET["offset"];
1049  // init sort_by (unfortunatly sort_by is preset with 'title'
1050  if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"]))
1051  {
1052  $_GET["sort_by"] = "login";
1053  }
1054  $order = $_GET["sort_by"];
1055  $direction = $_GET["sort_order"];
1056  $tbl->setLimit($ilUser->getPref('hits_per_page'));
1057 
1058  $tbl->setOrderColumn($order);
1059  $tbl->setOrderDirection($direction);
1060  $tbl->setOffset($offset);
1061  $tbl->setMaxCount(count($result_set));
1062  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1063 
1064  $order_key = 1;
1065 
1066  foreach ($tbl->header_vars as $key => $val)
1067  {
1068  if ($order == $val)
1069  {
1070  $order_key = $key;
1071  break;
1072  }
1073  }
1074 
1075  // sorting array
1076  $result_set = ilUtil::sortArray($result_set,$order_key,$direction);
1077  $result_set = array_slice($result_set,$offset,$ilUser->getPref('hits_per_page'));
1078 
1079  // add user link and access info color
1080  foreach ($result_set as $i => $row)
1081  {
1082  foreach ($row as $key => $cell)
1083  {
1084  if ($key == 1)
1085  {
1086  //build link
1087  // alex: this resulted in bug #5206 -> no cmdNode
1088  //$link = "ilias.php?ref_id=7&admin_mode=settings&obj_id=".$row[7]."&search=1&cmd=view&cmdClass=ilobjusergui&cmdNode=".$_SESSION["usergui_cmd_node"]."&baseClass=ilAdministrationGUI";
1089  $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
1090  $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $row[7]);
1091  $this->ctrl->setParameterByClass("ilobjusergui", "search", "1");
1092  $link = $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
1093  $result_set[$i][$key] = "<a href=\"".$link."\">".$cell."</a>";
1094  }
1095 
1096  if ($key == "5")
1097  {
1098  if ($cell == $this->lng->txt("access_unlimited"))
1099  {
1100  $result_set[$i][$key] = "<span class=\"smallgreen\">".$cell."</span>";
1101  }
1102  elseif (in_array($cell, array($this->lng->txt("access_expired"), $this->lng->txt("inactive"))))
1103  {
1104  $result_set[$i][$key] = "<span class=\"smallred\">".$cell."</span>";
1105  }
1106  else
1107  {
1108  $result_set[$i][$key] = "<span class=\"small\">".$cell."</span>";
1109  }
1110  }
1111 
1112  unset($result_set[$i][7]);
1113  }
1114  }
1115 
1116  $tbl->setData($result_set);
1117  }
1118 
1119  function userAction()
1120  {
1121  $_SESSION['user_" . $method . "_search'] = true;
1122  call_user_func(array($this->callback["class"], $this->callback["method"]),
1123  $_POST["selectedAction"], $_POST["id"]);
1124  }
1125 
1126  function setSubTabs()
1127  {
1128  global $ilTabs, $lng, $ilCtrl;
1129  $ilTabs->addSubTab("searchform", $lng->txt("search"),
1130  $ilCtrl->getLinkTarget($this, "showExtended"));
1131 
1132  if ($_SESSION['rep_search']['usr']) // last search result
1133  {
1134  $ilTabs->addSubTab("searchresults", $lng->txt("search_results"),
1135  $ilCtrl->getLinkTarget($this, "show"));
1136  }
1137  }
1138 
1145  public function userFilter($a_ref_id,$a_data)
1146  {
1147  if($a_data['type'] == 'usr')
1148  {
1149  if($a_data['obj_id'] == ANONYMOUS_USER_ID)
1150  {
1151  return false;
1152  }
1153  }
1154 
1155  return true;
1156  }
1157 
1158 }
1159 ?>