ILIAS  eassessment Revision 61809
 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->addObserver($this, 'userFilter');
372  $this->result_obj->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
373 
374  if(!count($this->result_obj->getResults()))
375  {
376  ilUtil::sendInfo($this->lng->txt('search_no_match'));
377  #global $ilErr;
378  #$ilErr->raiseError($this->lng->txt('search_no_match'),$ilErr->MESSAGE);
379  }
380  $this->__updateResults();
381  if($this->result_obj->isLimitReached())
382  {
383  $message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
384  ilUtil::sendInfo($message);
385  }
386  // show results
387  if ($_SESSION["usr_search_mode"] == "extended")
388  $this->showExtended();
389  else
390  $this->show();
391  }
392 
394  {
395  include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
396  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
397 
398  foreach(ilUserSearchOptions::_getSearchableFieldsInfo(true) as $info)
399  {
400  $name = $info['db'];
401  $query_string = $_SESSION['rep_query']['usr'][$name];
402  $active_status = $_SESSION['usr_query_active'];
403 
404  // continue if no query string is given
405  if(!$query_string)
406  {
407  continue;
408  }
409 
410  if(!is_object($query_parser = $this->__parseQueryString($query_string)))
411  {
412  ilUtil::sendInfo($query_parser);
413  return false;
414  }
415  switch($info['type'])
416  {
418  case FIELD_TYPE_UDF_TEXT:
420  $udf_search->setFields(array($name));
421  $result_obj = $udf_search->performSearch();
422 
423  // Store entries
424  $this->__storeEntries($result_obj);
425  break;
426 
427  case FIELD_TYPE_SELECT:
428  case FIELD_TYPE_TEXT:
429  $user_search =& ilObjectSearchFactory::_getUserSearchInstance($query_parser);
430  $user_search->setFields(array($name));
431 
432  if ($active_status == 1)
433  $user_search->enableActiveCheck(true);
434  elseif ($active_status == 2)
435  $user_search->enableInactiveCheck(true);
436 
437  $result_obj = $user_search->performSearch();
438 
439  // store entries
440  $this->__storeEntries($result_obj);
441  break;
442  }
443  }
444  }
445 
447  {
448  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
449 
450  $query_string = $_SESSION['rep_query']['grp']['title'];
451  if(!is_object($query_parser = $this->__parseQueryString($query_string)))
452  {
453  ilUtil::sendInfo($query_parser,true);
454  return false;
455  }
456 
457  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
458  $object_search = new ilLikeObjectSearch($query_parser);
459  $object_search->setFilter(array('grp'));
460  $this->__storeEntries($object_search->performSearch());
461 
462  return true;
463  }
464 
466  {
467  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
468 
469  $query_string = $_SESSION['rep_query']['role']['title'];
470  if(!is_object($query_parser = $this->__parseQueryString($query_string)))
471  {
472  ilUtil::sendInfo($query_parser,true);
473  return false;
474  }
475 
476  // Perform like search
477  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
478  $object_search = new ilLikeObjectSearch($query_parser);
479  $object_search->setFilter(array('role'));
480  $this->__storeEntries($object_search->performSearch());
481 
482  return true;
483  }
484 
490  function &__parseQueryString($a_string)
491  {
492  include_once 'Services/Search/classes/class.ilQueryParser.php';
493 
494  $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
495  $query_parser->setCombination(QP_COMBINATION_OR);
496  $query_parser->setMinWordLength(1,true);
497  $query_parser->parse();
498 
499  if(!$query_parser->validate())
500  {
501  return $query_parser->getMessage();
502  }
503  return $query_parser;
504  }
505 
506  // Private
507  function __loadQueries()
508  {
509 
510  if(is_array($_POST['rep_query']))
511  {
512  $_SESSION['usr_query_active'] = ($_POST['usr_query_active']) ? $_POST['usr_query_active'] : 0;
513  $_SESSION['rep_query'] = $_POST['rep_query'];
514  }
515  }
516 
517 
518  function __setSearchType()
519  {
520  // Update search type. Default to user search
521  if($_POST['search_for'])
522  {
523  #echo 1;
524  $_SESSION['rep_search_type'] = $_POST['search_for'];
525  }
526  if(!$_POST['search_for'] and !$_SESSION['rep_search_type'])
527  {
528  #echo 2;
529  $_SESSION['rep_search_type'] = 'usr';
530  }
531 
532  $this->search_type = $_SESSION['rep_search_type'];
533  #echo $this->search_type;
534 
535  return true;
536  }
537 
538  function __fillUserSearch()
539  {
540  global $lng;
541 
542  include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
543 
544  // active flag
545  $values = array('0' => $lng->txt('please_choose'),
546  '1' => $lng->txt('active'),
547  '2' => $lng->txt('inactive'));
548 
549  $this->tpl->setCurrentBlock("select_field");
550  $this->tpl->setVariable("SELECT_NAME",$lng->txt('active'));
551 
552  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($_SESSION['usr_query_active'],
553  "usr_query_active",
554  $values,
555  false,
556  true));
557  $this->tpl->parseCurrentBlock();
558 
559  foreach(ilUserSearchOptions::_getSearchableFieldsInfo(true) as $info)
560  {
561  switch($info['type'])
562  {
564  case FIELD_TYPE_SELECT:
565  $this->tpl->setCurrentBlock("select_field");
566  $this->tpl->setVariable("SELECT_NAME",$info['lang']);
567 
568  $name = $info['db'];
569  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($_SESSION['rep_query']['usr'][$name],
570  "rep_query[usr][$name]",
571  $info['values'],
572  false,
573  true));
574  $this->tpl->parseCurrentBlock();
575  break;
576 
577  case FIELD_TYPE_UDF_TEXT:
578  case FIELD_TYPE_TEXT:
579  $this->tpl->setCurrentBlock("text_field");
580  $this->tpl->setVariable("TEXT_NAME",$info['lang']);
581 
582  $name = $info['db'];
583  $this->tpl->setVariable("USR_NAME","rep_query[usr][$name]");
584  $this->tpl->setVariable("USR_VALUE",$_SESSION['rep_query']['usr'][$name]);
585  $this->tpl->parseCurrentBlock();
586  break;
587  }
588  $this->tpl->setCurrentBlock("usr_rows");
589  $this->tpl->parseCurrentBlock();
590  }
591 
592  }
593 
594  function __updateResults()
595  {
596  if(!$_SESSION['search_append'])
597  {
598  $_SESSION['rep_search'] = array();
599  }
600  foreach($this->result_obj->getResults() as $result)
601  {
602  $_SESSION['rep_search'][$this->search_type][] = $result['obj_id'];
603  }
604  if(!$_SESSION['rep_search'][$this->search_type])
605  {
606  $_SESSION['rep_search'][$this->search_type] = array();
607  }
608  else
609  {
610  // remove duplicate entries
611  $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
612  }
613  return true;
614  }
615 
616  function __appendToStoredResults($a_usr_ids)
617  {
618  if(!$_SESSION['search_append'])
619  {
620  return $_SESSION['rep_search']['usr'] = $a_usr_ids;
621  }
622  foreach($a_usr_ids as $usr_id)
623  {
624  $_SESSION['rep_search']['usr'][] = $usr_id;
625  }
626  return $_SESSION['rep_search']['usr'] ? array_unique($_SESSION['rep_search']['usr']) : array();
627  }
628 
629  function __storeEntries(&$new_res)
630  {
631  if($this->stored == false)
632  {
633  $this->result_obj->mergeEntries($new_res);
634  $this->stored = true;
635  return true;
636  }
637  else
638  {
639  $this->result_obj->intersectEntries($new_res);
640  return true;
641  }
642  }
643 
644  function __fillUserTable($user_ids)
645  {
646  $user_ids = $user_ids ? $user_ids : array();
647 
648  $counter = 0;
649  foreach($user_ids as $usr_id)
650  {
651  if(!is_object($tmp_obj = ilObjectFactory::getInstanceByObjId($usr_id,false)))
652  {
653  continue;
654  }
655 
656  $user_ids[$counter] = $usr_id;
657 
658  // determine txt_access
659  // Note: If you do changes here, you have to change the corresponding
660  // code in ilObjUserFolderGUI::viewObject as well.
661  if ($tmp_obj->getActive())
662  {
663  if ($tmp_obj->getTimeLimitUnlimited())
664  {
665  $txt_access = $this->lng->txt("access_unlimited");
666  }
667  elseif ($tmp_obj->getTimeLimitUntil() < time())
668  {
669  $txt_access = $this->lng->txt("access_expired");
670  }
671  else
672  {
673  $txt_access = ilDatePresentation::formatDate(new ilDateTime($tmp_obj->getTimeLimitUntil(),IL_CAL_UNIX));
674  }
675  }
676  else
677  {
678  $txt_access = $this->lng->txt("inactive");
679  }
680 
681  $f_result[$counter][] = ilUtil::formCheckbox(0,"id[]",$usr_id);
682  $f_result[$counter][] = $tmp_obj->getLogin();
683  $f_result[$counter][] = $tmp_obj->getFirstname();
684  $f_result[$counter][] = $tmp_obj->getLastname();
685  $f_result[$counter][] = $tmp_obj->getEmail();
686  $f_result[$counter][] = $txt_access;
687  $f_result[$counter][] = $tmp_obj->getLastLogin();
688  $f_result[$counter][] = $usr_id;
689 
690  unset($tmp_obj);
691  ++$counter;
692  }
693  return $f_result ? $f_result : array();
694  }
695 
696  function __fillGroupTable($group_ids)
697  {
698  $group_ids = $group_ids ? $group_ids : array();
699 
700  $counter = 0;
701  foreach($group_ids as $group_id)
702  {
703  if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($ref_id = end(
704  $ref_ids = ilObject::_getAllReferences($group_id)),false))
705  {
706  continue;
707  }
708  $grp_ids[$counter] = $group_id;
709 
710  $f_result[$counter][] = ilUtil::formCheckbox(0,"group[]",$ref_id);
711  $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
712  $f_result[$counter][] = $tmp_obj->getCountMembers();
713 
714  unset($tmp_obj);
715  ++$counter;
716  }
717  return $f_result ? $f_result : array();
718  }
719 
720  function __fillRoleTable($role_ids)
721  {
722  $role_ids = $role_ids ? $role_ids : array();
723 
724  $counter = 0;
725  foreach($role_ids as $role_id)
726  {
727  // exclude anonymous role
728  if ($role_id == ANONYMOUS_ROLE_ID)
729  {
730  continue;
731  }
732  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($role_id,false))
733  {
734  continue;
735  }
736  // exclude roles with no users assigned to
737  if ($tmp_obj->getCountMembers() == 0)
738  {
739  continue;
740  }
741  $role_ids[$counter] = $role_id;
742 
743  $f_result[$counter][] = ilUtil::formCheckbox(0,"role[]",$role_id);
744  $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
745  $f_result[$counter][] = $tmp_obj->getCountMembers();
746 
747  unset($tmp_obj);
748  ++$counter;
749  }
750  return $f_result ? $f_result : array();
751  }
752 
753 
755  {
756  $counter = 0;
757  $f_result = array();
758  switch($this->search_type)
759  {
760  case "usr":
761  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
762  $this->__showSearchUserTable($result,$_SESSION['rep_search']['usr']);
763  break;
764 
765  case 'grp':
766  $result = $this->__fillGroupTable($_SESSION['rep_search']['grp']);
767  $this->__showSearchGroupTable($result,$_SESSION['rep_search']['grp']);
768  break;
769 
770  case 'role':
771  $result = $this->__fillRoleTable($_SESSION['rep_search']['role']);
772  $this->__showSearchRoleTable($result,$_SESSION['rep_search']['role']);
773  break;
774  }
775 
776  // Finally fill user table, if search type append
777  if($_SESSION['search_append'] and $this->search_type != 'usr')
778  {
779  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
780  $this->__showSearchUserTable($result,$_SESSION['rep_search']['usr'],'search','APPEND_TABLE');
781 
782  }
783  }
784  function __showSearchUserTable($a_result_set,$a_user_ids = NULL,$a_cmd = "performSearch",$tpl_var = 'RES_TABLE')
785  {
786  if(!$a_result_set)
787  {
788  return false;
789  }
790 
791  $tbl =& $this->__initTableGUI();
792  $tpl =& $tbl->getTemplateObject();
793 
794  // SET FORMACTION
795  $tpl->setCurrentBlock("tbl_form_header");
796  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
797  $tpl->parseCurrentBlock();
798 
799  $operations = array(
800  array("name" => "delete", "lng" => "delete"),
801  array("name" => "activate", "lng" => "activate"),
802  array("name" => "deactivate", "lng" => "deactivate"),
803  array("name" => "accessRestrict", "lng" => "accessRestrict"),
804  array("name" => "accessFree", "lng" => "accessFree"),
805  array("name" => "export", "lng" => "export")
806  );
807 
808  if (count($operations) > 0)
809  {
810  $select = "<select name=\"selectedAction\">\n";
811  foreach ($operations as $val)
812  {
813  $select .= "<option value=\"" . $val["name"] . "\"";
814  if (strcmp($_POST["selectedAction"], $val["name"]) == 0)
815  {
816  $select .= " selected=\"selected\"";
817  }
818  $select .= ">";
819  $select .= $this->lng->txt($val["lng"]);
820  $select .= "</option>";
821  }
822  $select .= "</select>";
823  $tpl->setCurrentBlock("tbl_action_select");
824  $tpl->setVariable("SELECT_ACTION", $select);
825  $tpl->setVariable("BTN_NAME", "userAction");
826  $tpl->setVariable("BTN_VALUE", $this->lng->txt("submit"));
827  $tpl->parseCurrentBlock();
828  }
829 
830  $tpl->setCurrentBlock("tbl_action_row");
831  $tpl->setVariable("COLUMN_COUNTS",7);
832  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
833  $tpl->parseCurrentBlock();
834 
835  $tbl->setTitle($this->lng->txt("search_results"),"icon_usr.gif",$this->lng->txt("search_results"));
836  $tbl->setHeaderNames(array("",
837  $this->lng->txt("username"),
838  $this->lng->txt("firstname"),
839  $this->lng->txt("lastname"),
840  $this->lng->txt("email"),
841  $this->lng->txt("access_until"),
842  $this->lng->txt("last_login")));
843  $tbl->setHeaderVars(array("",
844  "login",
845  "firstname",
846  "lastname",
847  "email",
848  "access_until",
849  "last_login"),
850  array("ref_id" => $_GET['ref_id'],
851  "cmd" => ($_SESSION['usr_search_mode'] == 'extended') ? 'showExtended' : 'show',
852  "cmdClass" => "iladminusersearchgui",
853  "cmdNode" => $_GET["cmdNode"],
854  "baseClass" => "ilAdministrationGUI"));
855 
856  $tbl->setColumnWidth(array("","15%","15%","15%","20%","15%","20%"));
857 
858  $this->__setTableGUIUserData($tbl,$a_result_set);
859  $tbl->render();
860 
861  $this->tpl->setVariable($tpl_var,$tbl->tpl->get());
862 
863  return true;
864  }
865 
866  function __showSearchGroupTable($a_result_set,$a_grp_ids = NULL)
867  {
868  if(!$a_result_set)
869  {
870  return false;
871  }
872 
873  $tbl =& $this->__initTableGUI();
874  $tpl =& $tbl->getTemplateObject();
875 
876  $tpl->setCurrentBlock("tbl_form_header");
877  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
878  $tpl->parseCurrentBlock();
879 
880  $tpl->setCurrentBlock("tbl_action_btn");
881  $tpl->setVariable("BTN_NAME","listUsersGroup");
882  $tpl->setVariable("BTN_VALUE",$this->lng->txt("crs_list_users"));
883  $tpl->parseCurrentBlock();
884 
885  if (!empty($a_grp_ids))
886  {
887  $tpl->setCurrentBlock("tbl_select_all");
888  $tpl->setVariable("COLUMN_COUNTS",4);
889  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
890  $tpl->parseCurrentBlock();
891  }
892 
893  $tpl->setCurrentBlock("tbl_action_row");
894  $tpl->setVariable("COLUMN_COUNTS",5);
895  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
896  $tpl->parseCurrentBlock();
897 
898  $tbl->setTitle($this->lng->txt("crs_header_edit_members"),"icon_grp.gif",$this->lng->txt("crs_header_edit_members"));
899  $tbl->setHeaderNames(array("",
900  $this->lng->txt("obj_grp"),
901  $this->lng->txt("crs_count_members")));
902  $tbl->setHeaderVars(array("",
903  "title",
904  "nr_members"),
905  array("ref_id" => $_GET['ref_id'],
906  "cmd" => "show",
907  "cmdClass" => "iladminusersearchgui",
908  "cmdNode" => $_GET["cmdNode"],
909  'baseClass' => 'ilAdministrationGUI'
910  )
911  );
912 
913 
914  $tbl->setColumnWidth(array("","80%","19%"));
915 
916 
917  $this->__setTableGUIBasicData($tbl,$a_result_set,"group");
918  $tbl->render();
919 
920  $this->tpl->setVariable("RES_TABLE",$tbl->tpl->get());
921 
922  return true;
923  }
924  function __showSearchRoleTable($a_result_set,$a_role_ids)
925  {
926  if(!$a_result_set)
927  {
928  return false;
929  }
930 
931  $tbl =& $this->__initTableGUI();
932  $tpl =& $tbl->getTemplateObject();
933 
934  $tpl->setCurrentBlock("tbl_form_header");
935  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
936  $tpl->parseCurrentBlock();
937 
938  $tpl->setCurrentBlock("tbl_action_btn");
939  $tpl->setVariable("BTN_NAME","listUsersRole");
940  $tpl->setVariable("BTN_VALUE",$this->lng->txt("crs_list_users"));
941  $tpl->parseCurrentBlock();
942 
943  if (!empty($a_role_ids))
944  {
945  $tpl->setCurrentBlock("tbl_select_all");
946  $tpl->setVariable("COLUMN_COUNTS",4);
947  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
948  $tpl->parseCurrentBlock();
949  }
950 
951  $tpl->setCurrentBlock("tbl_action_row");
952  $tpl->setVariable("COLUMN_COUNTS",5);
953  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
954  $tpl->parseCurrentBlock();
955 
956  $tbl->setTitle($this->lng->txt("crs_header_edit_members"),"icon_role.gif",$this->lng->txt("crs_header_edit_members"));
957  $tbl->setHeaderNames(array("",
958  $this->lng->txt("objs_role"),
959  $this->lng->txt("crs_count_members")));
960  $tbl->setHeaderVars(array("",
961  "title",
962  "nr_members"),
963  array("ref_id" => $_GET['ref_id'],
964  "cmd" => "show",
965  "cmdClass" => "iladminusersearchgui",
966  "cmdNode" => $_GET["cmdNode"]));
967 
968  $tbl->setColumnWidth(array("","80%","19%"));
969 
970  $this->__setTableGUIBasicData($tbl,$a_result_set,"role");
971  $tbl->disable("auto_sort");
972  $tbl->render();
973 
974  $this->tpl->setVariable("RES_TABLE",$tbl->tpl->get());
975 
976  return true;
977  }
978 
979 
980  function listUsersGroup()
981  {
982  global $rbacsystem,$tree;
983 
984  $_SESSION["crs_group"] = $_POST["group"] = $_POST["group"] ? $_POST["group"] : $_SESSION["crs_group"];
985 
986  if(!is_array($_POST["group"]))
987  {
988  ilUtil::sendInfo($this->lng->txt("crs_no_groups_selected"));
989  $this->show();
990 
991  return false;
992  }
993 
994  $this->__showSearch();
995 
996  // GET ALL MEMBERS
997  $members = array();
998  foreach($_POST["group"] as $group_id)
999  {
1000  if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($group_id))
1001  {
1002  continue;
1003  }
1004  $members = array_merge($tmp_obj->getGroupMemberIds(),$members);
1005 
1006  unset($tmp_obj);
1007  }
1008  $this->__appendToStoredResults($members);
1009 
1010  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
1011  $this->__showSearchUserTable($result,$_SESSION['rep_search']['usr'],"listUsersGroup");
1012 
1013  return true;
1014  }
1015  function listUsersRole()
1016  {
1017  global $rbacsystem,$rbacreview,$tree;
1018 
1019  $_SESSION["crs_role"] = $_POST["role"] = $_POST["role"] ? $_POST["role"] : $_SESSION["crs_role"];
1020 
1021  if(!is_array($_POST["role"]))
1022  {
1023  ilUtil::sendInfo($this->lng->txt("crs_no_roles_selected"));
1024  $this->show();
1025 
1026  return false;
1027  }
1028 
1029  $this->__showSearch();
1030 
1031  // GET ALL MEMBERS
1032  $members = array();
1033  foreach($_POST["role"] as $role_id)
1034  {
1035  $members = array_merge($rbacreview->assignedUsers($role_id),$members);
1036  }
1037  $members = $this->__appendToStoredResults($members);
1038 
1039  $result = $this->__fillUserTable($_SESSION['rep_search']['usr']);
1040  $this->__showSearchUserTable($result,$user_ids,"listUsersRole");
1041 
1042  return true;
1043  }
1044 
1045 
1046 
1047  function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
1048  {
1049  global $ilUser;
1050 
1051  switch($from)
1052  {
1053  case "group":
1054  $offset = $_GET["offset"];
1055  $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
1056  $direction = $_GET["sort_order"];
1057  $tbl->setLimit(1000000);
1058  break;
1059 
1060  case "role":
1061  $offset = $_GET["offset"];
1062  $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
1063  $direction = $_GET["sort_order"];
1064  $tbl->setLimit(1000000);
1065  break;
1066 
1067  default:
1068  $offset = $_GET["offset"];
1069  // init sort_by (unfortunatly sort_by is preset with 'title'
1070  if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"]))
1071  {
1072  $_GET["sort_by"] = "login";
1073  }
1074  $order = $_GET["sort_by"];
1075  $direction = $_GET["sort_order"];
1076  $tbl->setLimit($ilUser->getPref('hits_per_page'));
1077  break;
1078  }
1079 
1080  $tbl->setOrderColumn($order);
1081  $tbl->setOrderDirection($direction);
1082  $tbl->setOffset($offset);
1083  $tbl->setMaxCount(count($result_set));
1084  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1085  $tbl->setData($result_set);
1086  }
1087 
1088  function &__initTableGUI()
1089  {
1090  include_once "./Services/Table/classes/class.ilTableGUI.php";
1091 
1092  return new ilTableGUI(0,false);
1093  }
1094 
1095  function __setTableGUIUserData(&$tbl,&$result_set,$from = "")
1096  {
1097  global $ilUser;
1098 
1099  // remember link target to admin search gui (this)
1100  $_SESSION["usr_search_link"] = $this->ctrl->getLinkTarget($this,'show');
1101 
1102  $tbl->disable("auto_sort");
1103  $tbl->enable("select_all");
1104  $tbl->setFormName("cmd");
1105  $tbl->setSelectAllCheckbox("id");
1106 
1107  $offset = $_GET["offset"];
1108  // init sort_by (unfortunatly sort_by is preset with 'title'
1109  if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"]))
1110  {
1111  $_GET["sort_by"] = "login";
1112  }
1113  $order = $_GET["sort_by"];
1114  $direction = $_GET["sort_order"];
1115  $tbl->setLimit($ilUser->getPref('hits_per_page'));
1116 
1117  $tbl->setOrderColumn($order);
1118  $tbl->setOrderDirection($direction);
1119  $tbl->setOffset($offset);
1120  $tbl->setMaxCount(count($result_set));
1121  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1122 
1123  $order_key = 1;
1124 
1125  foreach ($tbl->header_vars as $key => $val)
1126  {
1127  if ($order == $val)
1128  {
1129  $order_key = $key;
1130  break;
1131  }
1132  }
1133 
1134  // sorting array
1135  $result_set = ilUtil::sortArray($result_set,$order_key,$direction);
1136  $result_set = array_slice($result_set,$offset,$ilUser->getPref('hits_per_page'));
1137 
1138  // add user link and access info color
1139  foreach ($result_set as $i => $row)
1140  {
1141  foreach ($row as $key => $cell)
1142  {
1143  if ($key == 1)
1144  {
1145  //build link
1146  // alex: this resulted in bug #5206 -> no cmdNode
1147  //$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";
1148  $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
1149  $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $row[7]);
1150  $this->ctrl->setParameterByClass("ilobjusergui", "search", "1");
1151  $link = $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
1152  $result_set[$i][$key] = "<a href=\"".$link."\">".$cell."</a>";
1153  }
1154 
1155  if ($key == "5")
1156  {
1157  if ($cell == $this->lng->txt("access_unlimited"))
1158  {
1159  $result_set[$i][$key] = "<span class=\"smallgreen\">".$cell."</span>";
1160  }
1161  elseif (in_array($cell, array($this->lng->txt("access_expired"), $this->lng->txt("inactive"))))
1162  {
1163  $result_set[$i][$key] = "<span class=\"smallred\">".$cell."</span>";
1164  }
1165  else
1166  {
1167  $result_set[$i][$key] = "<span class=\"small\">".$cell."</span>";
1168  }
1169  }
1170 
1171  unset($result_set[$i][7]);
1172  }
1173  }
1174 
1175  $tbl->setData($result_set);
1176  }
1177 
1178  function setCallbackClass(&$class)
1179  {
1180  $this->callback_class = $class;
1181  }
1182 
1188  function cancelDelete()
1189  {
1190  session_unregister("saved_post");
1191  $class =& $this->callback_class;
1192 
1193  $script = $class->ctrl->getLinkTargetByClass('ilAdminUserSearchGUI','show', '', false, false);
1194  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
1195  ilUtil::redirect($script);
1196  }
1197 
1198  function userAction()
1199  {
1200  $method = $_POST["selectedAction"];
1201  $_SESSION['user_" . $method . "_search'] = true;
1202  $class =& $this->callback_class;
1203  $class->showActionConfirmation($method);
1204  }
1205 
1206  function delete()
1207  {
1208  $_SESSION['user_delete_search'] = true;
1209 
1210  // call callback if that function does give a return value => show error message
1211  $class =& $this->callback_class;
1212  // listener redirects if everything is ok.
1213  $class->deleteObject();
1214  }
1215 
1216  function cancel()
1217  {
1218  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
1219 
1220  $this->ctrl->returnToParent($this);
1221  }
1222 
1223  function setSubTabs()
1224  {
1225  global $ilTabs, $lng, $ilCtrl;
1226  $ilTabs->addSubTab("searchform", $lng->txt("search"),
1227  $ilCtrl->getLinkTarget($this, "showExtended"));
1228 
1229  if ($_SESSION['rep_search']['usr']) // last search result
1230  {
1231  $ilTabs->addSubTab("searchresults", $lng->txt("search_results"),
1232  $ilCtrl->getLinkTarget($this, "show"));
1233  }
1234  }
1235 
1242  public function userFilter($a_ref_id,$a_data)
1243  {
1244  if($a_data['type'] == 'usr')
1245  {
1246  if($a_data['obj_id'] == ANONYMOUS_USER_ID)
1247  {
1248  return false;
1249  }
1250  }
1251 
1252  return true;
1253  }
1254 
1255 }
1256 ?>