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