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