2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
26 * @author Benjamin Renard <brenard@easter-eggs.com>
30 // The LdapObject type of search
31 private $LSobject=NULL;
33 // The configuration of search
36 // The context of search
39 // The parameters of the search
40 private $params=array (
44 'predefinedFilter' => false,
49 'attronly' => false, // If true, only attribute names are returned
52 'attributes' => array(),
54 'sortDirection' => NULL,
57 'displaySubDn' => NULL,
58 'displayFormat' => NULL,
59 'nbObjectsByPage' => NB_LSOBJECT_LIST,
60 'nbPageLinkByPage' => 10,
61 'customInfos' => array(),
62 'withoutCache' => false
65 // The cache of search parameters
66 private $_searchParams = NULL;
68 // The cache of the hash of the search parameters
69 private $_hash = NULL;
71 // The result of the search
75 private $_canCopy=NULL;
80 * @param[in] $LSobject string The LdapObject type of search
81 * @param[in] $context string Context of search (LSrelation / LSldapObject/ ...)
82 * @param[in] $params array Parameters of search
83 * @param[in] $purgeParams boolean If params in session have to be purged
86 function LSsearch($LSobject,$context,$params=null,$purgeParams=false) {
87 if (!LSsession :: loadLSobject($LSobject)) {
90 $this -> LSobject = $LSobject;
92 $this -> loadConfig();
94 if (isset($_REQUEST['LSsearchPurgeSession'])) {
95 $this -> purgeSession();
98 $this -> context = $context;
101 if (! $this -> loadParamsFromSession()) {
102 LSdebug('LSsearch : load default parameters');
103 $this -> loadDefaultParameters();
107 $this -> purgeParams();
108 $this -> loadDefaultParameters();
111 if (is_array($params)) {
112 $this -> setParams($params);
118 * Load configuration from LSconfig
122 private function loadConfig() {
123 $this -> config = LSconfig::get("LSobjects.".$this -> LSobject.".LSsearch");
124 if (is_array($this -> config['predefinedFilters'])) {
125 foreach(array_keys($this -> config['predefinedFilters']) as $key) {
126 if(!LSldap::isValidFilter($key)) {
127 unset($this -> config['predefinedFilters'][$key]);
134 * Load default search parameters from configuration
136 * @retval boolean True on success or False
138 private function loadDefaultParameters() {
139 if (is_array($this -> config['params'])) {
140 return $this -> setParams($this -> config['params']);
146 * Load search parameters from session
148 * @retval boolean True if params has been loaded from session or False
150 private function loadParamsFromSession() {
151 LSdebug('LSsearch : load context params session '.$this -> context);
152 if (is_array($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context])) {
153 $params = $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context];
155 if ($params['filter']) {
156 $params['filter'] = Net_LDAP2_Filter::parse($params['filter']);
159 $this -> params = $params;
166 * Save search parameters in session
170 private function saveParamsInSession() {
171 LSdebug('LSsearch : save context params session '.$this -> context);
172 $params = $this -> params;
173 if ($params['filter'] instanceof Net_LDAP2_Filter) {
174 $params['filter'] = $params['filter'] -> asString();
177 foreach ($params as $param => $value) {
178 if ($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]!=$value) {
179 LSdebug("S: $param => $value");
180 $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]=$value;
186 * Purge parameters in session
188 * @param[in] $LSobject string The LSobject type
192 public function purgeParams($LSobject=NULL) {
193 if (is_null($LSobject)) {
194 $LSobject = $this -> LSobject;
196 unset($_SESSION['LSsession']['LSsearch'][$LSobject]['params']);
204 public function purgeCache($LSobject=NULL) {
205 if (is_null($LSobject))
206 $LSobject = $this -> LSobject;
207 unset($_SESSION['LSsession']['LSsearch'][$LSobject]);
215 private function purgeSession() {
216 unset($_SESSION['LSsession']['LSsearch']);
220 * Define one search parameter
222 * @param[in] $param string The parameter name
223 * @param[in] $value mixed The parameter value
225 * @retval boolean True on success or False
227 public function setParam($param,$value) {
228 return $this -> setParams(array($param => $value));
232 * Define search parameters
234 * @param[in] $params array Parameters of search
236 * @retval boolean True on success or False
238 public function setParams($params) {
242 if (is_string($params['filter'])) {
243 $filter = Net_LDAP2_Filter::parse($params['filter']);
244 if (!LSerror::isLdapError($filter)) {
245 $this -> params['filter'] = $filter;
248 LSerror :: addErrorCode('LSsearch_01',$params['filter']);
252 elseif($params['filter'] instanceof Net_LDAP2_Filter) {
253 $this -> params['filter'] =& $params['filter'];
257 if (isset($params['approx'])) {
258 if (is_bool($params['approx']) || $params['approx']==0 || $params['approx']==1) {
259 $this -> params['approx'] = (bool)$params['approx'];
262 LSerror :: addErrorCode('LSsearch_05','approx');
268 if (isset($params['withoutCache'])) {
269 if (is_bool($params['withoutCache']) || $params['withoutCache']==0 || $params['withoutCache']==1) {
270 $this -> params['withoutCache'] = (bool)$params['withoutCache'];
273 LSerror :: addErrorCode('LSsearch_05','withoutCache');
279 if (isset($params['pattern']) && $params['pattern']=="") {
280 $this -> params['pattern'] = NULL;
281 $this -> params['filter'] = NULL;
283 elseif (self :: isValidPattern($params['pattern'])) {
284 $this -> params['pattern'] = $params['pattern'];
285 if (!is_string($params['filter'])) {
286 $this -> params['filter']=NULL;
292 if (is_string($params['basedn'])) {
293 if (isCompatibleDNs(LSsession :: getRootDn(),$params['basedn'])) {
294 $this -> params['basedn'] = $params['basedn'];
297 LSerror :: addErrorCode('LSsearch_02',$params['basedn']);
303 if (is_string($params['subDn'])) {
304 if (LSsession :: validSubDnLdapServer($params['subDn'])) {
305 $this -> params['subDn'] = $params['subDn'];
308 LSerror :: addErrorCode('LSsearch_03','subDn');
314 if (is_string($params['scope'])) {
315 if (in_array($params['scope'],array('sub','one','base'))) {
316 $this -> params['scope'] = $params['scope'];
319 LSerror :: addErrorCode('LSsearch_03','scope');
325 if (isset($params['nbObjectsByPage'])) {
326 if (((int)$params['nbObjectsByPage'])>1 ) {
327 $this -> params['nbObjectsByPage'] = (int)$params['nbObjectsByPage'];
330 LSerror :: addErrorCode('LSsearch_03','nbObjectsByPage');
336 if (isset($params['sortlimit'])) {
337 if (is_int($params['sortlimit']) && $params['sortlimit']>=0 ) {
338 $this -> params['sortlimit'] = $params['sortlimit'];
340 elseif ((int)$params['sortlimit'] > 0) {
341 $this -> params['sortlimit'] = (int)$params['sortlimit'];
344 LSerror :: addErrorCode('LSsearch_03','sortlimit');
350 if (is_string($params['sortDirection'])) {
351 if (in_array($params['sortDirection'],array('ASC','DESC'))) {
352 $this -> params['sortDirection'] = $params['sortDirection'];
355 LSerror :: addErrorCode('LSsearch_03','sortDirection');
361 if (is_string($params['sortBy'])) {
362 if (in_array($params['sortBy'],array('displayName','subDn'))) {
363 if ($this -> params['sortBy'] == $params['sortBy']) {
364 $this -> toggleSortDirection();
367 $this -> params['sortBy'] = $params['sortBy'];
368 if (!is_string($params['sortDirection'])) {
369 $this -> params['sortDirection']='ASC';
374 LSerror :: addErrorCode('LSsearch_03','sortBy');
380 if (isset($params['sizelimit'])) {
381 if (((int)$params['sizelimit']) >= 0) {
382 $this -> params['sizelimit'] = $params['sizelimit'];
385 LSerror :: addErrorCode('LSsearch_04');
391 if (isset($params['attronly'])) {
392 if (is_bool($params['attronly']) || $params['attronly']==0 || $params['attronly']==1) {
393 $this -> params['attronly'] = (bool)$params['attronly'];
396 LSerror :: addErrorCode('LSsearch_05','attronly');
402 if (isset($params['recursive'])) {
403 if (is_bool($params['recursive']) || $params['recursive']==0 || $params['recursive']==1) {
404 $this -> params['recursive'] = (bool)$params['recursive'];
407 LSerror :: addErrorCode('LSsearch_05','recursive');
413 if (isset($params['displaySubDn'])) {
414 if (! LSsession :: isSubDnLSobject($this -> LSobject) ) {
415 if (is_bool($params['displaySubDn']) || $params['displaySubDn']==0 || $params['displaySubDn']==1) {
416 $this -> params['displaySubDn'] = (bool)$params['displaySubDn'];
419 LSerror :: addErrorCode('LSsearch_05','displaySubDn');
426 if (isset($params['attributes'])) {
427 if (is_string($params['attributes'])) {
428 $this -> params['attributes'] = array($params['attributes']);
430 elseif (is_array($params['attributes'])) {
431 $this -> params['attributes']=array();
432 foreach ($this -> params['attributes'] as $attr) {
433 if (is_string($attr)) {
434 if (LSconfig::get("LSobjects.".$this -> LSobject.".attrs.$attr")) {;
435 $this -> params['attributes'][] = $attr;
438 LSerror :: addErrorCode('LSsearch_11',$attr);
444 LSerror :: addErrorCode('LSsearch_06');
450 if (isset($params['predefinedFilter'])) {
451 if (is_string($params['predefinedFilter'])) {
452 if (empty($params['predefinedFilter'])) {
453 $this->params['predefinedFilter']=false;
455 elseif(is_array($this -> config['predefinedFilters'])) {
456 if(isset($this->config['predefinedFilters'][$params['predefinedFilter']])) {
457 $this -> params['predefinedFilter'] = $params['predefinedFilter'];
460 LSerror :: addErrorCode('LSsearch_03','predefinedFilter');
466 LSerror :: addErrorCode('LSsearch_03','predefinedFilter');
472 if (is_string($params['displayFormat'])) {
473 $this -> params['displayFormat'] = $params['displayFormat'];
477 if (is_array($params['customInfos'])) {
478 foreach($params['customInfos'] as $name => $data) {
479 if(is_array($data['function']) && is_string($data['function'][0])) {
480 LSsession::loadLSclass($data['function'][0]);
482 if (is_callable($data['function'])) {
483 $this -> params['customInfos'][$name] = array (
484 'function' => &$data['function'],
485 'args' => $data['args']
489 LSerror :: addErrorCode('LSsearch_14',$name);
494 $this -> saveParamsInSession();
499 * Define search parameters by reading Post Data ($_REQUEST)
503 public function setParamsFormPostData() {
506 if (isset($data['LSsearch_submit'])) {
508 if (is_null($data['recursive'])) {
509 $data['recursive']=false;
512 $data['recursive']=true;
516 if (is_null($data['approx'])) {
517 $data['approx']=false;
520 $data['approx']=true;
523 if (isset($data['ajax']) && !isset($data['pattern'])) {
528 $this -> setParams($data);
532 * Toggle the sort direction
536 private function toggleSortDirection() {
537 if ($this -> params['sortDirection']=="ASC") {
538 $this -> params['sortDirection'] = "DESC";
541 $this -> params['sortDirection'] = "ASC";
546 * Make a filter object with a pattern of search
548 * @param[in] $pattern The pattern of search. If is null, the pattern in params will be used.
550 * @retval mixed Net_LDAP2_Filter on success or False
552 function getFilterFromPattern($pattern=NULL) {
553 if ($pattern==NULL) {
554 $pattern=$this -> params['pattern'];
556 if (self :: isValidPattern($pattern)) {
557 $operator=( ($params['approx'])?'approx':'contains' );
558 $attrsList=LSconfig::get("LSobjects.".$this -> LSobject.".LSsearch.attrs");
559 if (!is_array($attrsList)) {
560 $attrsList = array_keys(LSconfig::get("LSobjects.".$this -> LSobject.".attrs"));
563 if (empty($attrsList)) {
564 LSerror :: addErrorCode('LSsearch_07');
569 foreach ($attrsList as $attr) {
570 $filter=Net_LDAP2_Filter::create($attr,$operator,$pattern);
571 if (!Net_LDAP2::isError($filter)) {
575 LSerror :: addErrorCode('LSsearch_08',array('attr' => $attr,'pattern' => $pattern));
579 if(!empty($filters)) {
580 $filter=LSldap::combineFilters('or',$filters);
585 LSerror :: addErrorCode('LSsearch_09');
590 LSerror :: addErrorCode('LSsearch_10');
596 * Check if search pattern is valid
598 * @param[in] $pattern string The pattern
600 * @retval boolean True if pattern is valid or False
602 static function isValidPattern($pattern) {
603 return (is_string($pattern) && $pattern!= "" && $pattern!="*");
607 * Check if cache is enabled
609 * @retval boolean True if cache is enabled or False
611 public function cacheIsEnabled() {
612 if (isset($this -> config['cache'])) {
613 $conf=$this -> config['cache'];
614 if (is_bool($conf) || $conf==0 || $conf==1) {
618 LSerror :: addErrorCode('LSsearch_03','cache');
621 return LSsession :: cacheSearch();
625 * Methode for parameters value access
627 * @param[in] $key string The parameter name
629 * @retval mixed The parameter value or NULL
631 public function getParam($key) {
632 if(in_array($key,array_keys($this -> params))) {
633 return $this -> params[$key];
639 * Return hidden fileds to add in search form
641 * @retval array The hield fields whith their values
643 public function getHiddenFieldForm() {
645 'LSobject' => $this -> LSobject
650 * Generate an array with search parameters, only parameters whitch have to be
651 * passed to Net_LDAP2 for the LDAP search. This array will be store in
652 * $this -> _searchParams private variable.
656 private function generateSearchParams() {
657 // Purge the cache of the hash
658 $this -> _hash = NULL;
662 'filter' => $this -> params['filter'],
663 'basedn' => $this -> params['basedn'],
664 'scope' => $this -> params['scope'],
665 'sizelimit' => $this -> params['sizelimit'],
666 'attronly' => $this -> params['attronly'],
667 'attributes' => $this -> params['attributes']
671 if (!is_null($this -> params['pattern'])) {
672 $filter=$this ->getFilterFromPattern();
673 if (is_null($retval['filter'])) {
674 $retval['filter']=$filter;
677 $retval['filter']=LSldap::combineFilters('and',array($retval['filter'],$filter));
682 if (is_string($this -> params['predefinedFilter'])) {
683 if (!is_null($retval['filter'])) {
684 $filter=LSldap::combineFilters('and',array($this -> params['predefinedFilter'],$retval['filter']));
686 $retval['filter']=$filter;
690 $retval['filter']=$this -> params['predefinedFilter'];
695 $objFilter=LSldapObject::getObjectFilter($this -> LSobject);
697 if (!is_null($retval['filter'])) {
698 $filter=LSldap::combineFilters('and',array($objFilter,$retval['filter']));
700 $retval['filter']=$filter;
704 $retval['filter']=$objFilter;
709 if (is_null($retval['basedn'])) {
710 if (!is_null($this -> params['subDn'])) {
711 if ($this -> params['recursive']) {
712 $retval['basedn'] = $this -> params['subDn'];
715 $retval['basedn'] = LSconfig::get("LSobjects.".$this -> LSobject.".container_dn").','.$this -> params['subDn'];
719 if ($this -> params['recursive']) {
720 $retval['basedn'] = LSsession :: getTopDn();
723 $retval['basedn'] = LSconfig::get("LSobjects.".$this -> LSobject.".container_dn").','.LSsession :: getTopDn();
727 if ($this -> params['recursive'] || !isset($retval['scope'])) {
728 $retval['scope'] = 'sub';
731 if (is_null($this -> params['displayFormat'])) {
732 $this -> params['displayFormat']=LSconfig::get("LSobjects.".$this -> LSobject.".display_name_format");
736 $attrs=getFieldInFormat($this -> params['displayFormat']);
737 if(is_array($retval['attributes'])) {
738 $retval['attributes']=array_merge($attrs,$retval['attributes']);
741 $retval['attributes']=$attrs;
744 $this -> _searchParams = $retval;
750 * @param[in] $cache boolean Define if the cache can be used
752 * @retval boolean True on success or False
754 public function run($cache=true) {
755 $this -> generateSearchParams();
756 if ($this -> _searchParams['filter'] instanceof Net_LDAP2_Filter) {
757 LSdebug('LSsearch : filter : '.$this -> _searchParams['filter']->asString());
759 LSdebug('LSsearch : basedn : '.$this -> _searchParams['basedn'].' - scope : '.$this -> _searchParams['scope']);
761 if( $cache && (!isset($_REQUEST['refresh'])) && (!$this -> params['withoutCache']) ) {
762 LSdebug('LSsearch : with the cache');
763 $this -> result = $this -> getResultFromCache();
766 LSdebug('LSsearch : without the cache');
767 $this -> setParam('withoutCache',false);
770 if (!$this -> result) {
771 LSdebug('LSsearch : Not in cache');
772 $this -> result=array(
774 'sortDirection' => NULL
776 $this -> result['list'] = LSldap :: search(
777 $this -> _searchParams['filter'],
778 $this -> _searchParams['basedn'],
779 $this -> _searchParams
781 if ($this -> result['list'] === false) {
782 LSerror :: addErrorCode('LSsearch_12');
783 unset($this -> result['list']);
786 $this -> addResultToCache();
795 * Return an hash corresponding to the parameters of the search
797 * @param[in] $searchParams array An optional search params array
799 * @retval string The hash of the parameters of the search
801 public function getHash($searchParams=null) {
802 if(is_null($searchParams)) {
803 $searchParams=$this -> _searchParams;
804 if ($this -> _hash) {
805 return $this -> _hash;
808 if ($searchParams['filter'] instanceof Net_LDAP_Filter) {
809 $searchParams['filter']=$searchParams['filter']->asString();
811 return hash('md5',print_r($searchParams,true));
815 * Add the result of the search to cache of the session
819 public function addResultToCache() {
820 if ($this -> cacheIsEnabled()) {
821 LSdebug('LSsearch : Save result in cache.');
822 $hash=$this->getHash();
823 $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash]=$this->result;
828 * Get the result of the search from cache of the session
830 * @retval array | False The array of the result of the search or False
832 private function getResultFromCache() {
833 if ($this -> cacheIsEnabled()) {
834 $hash=$this->getHash();
835 if (isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash])) {
836 LSdebug('LSsearch : Load result from cache.');
837 return $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash];
844 * Get page informations to display
846 * @param[in] $page integer The number of the page
848 * @retval array The information of the page
850 public function getPage($page=0) {
851 if (!LSsession::loadLSclass('LSsearchEntry')) {
852 LSerror::addErrorCode('LSsession_05',$this -> LSobject);
861 'total' => $this -> total
864 if ($retval['total']>0) {
865 LSdebug('Total : '.$retval['total']);
867 if (!$this->params['nbObjectsByPage']) {
868 $this->params['nbObjectsByPage']=NB_LSOBJECT_LIST;
870 $retval['nbPages']=ceil($retval['total']/$this->params['nbObjectsByPage']);
872 $sortTable=$this -> getSortTable();
876 ($page * $this->params['nbObjectsByPage']),
877 $this->params['nbObjectsByPage']
880 foreach ($list as $key => $id) {
881 $retval['list'][]=new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$id);
890 * @retval array The entries
892 public function getSearchEntries() {
893 if (!LSsession::loadLSclass('LSsearchEntry')) {
894 LSerror::addErrorCode('LSsession_05',$this -> LSobject);
898 if ($this -> total>0) {
899 $sortTable=$this -> getSortTable();
901 foreach ($sortTable as $key => $id) {
902 $retval[]=new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$id);
909 * Access to information of this object
911 * @param[in] $key string The key of the info
913 * @retval mixed The info
915 public function __get($key) {
920 if ($key=='LSobject') {
921 return $this -> LSobject;
923 elseif (in_array($key,$params)) {
924 return $this -> params[$key];
926 elseif ($key=='label_objectName') {
927 return LSldapObject::getLabel($this -> LSobject);
929 elseif ($key=='label_level') {
930 return LSsession :: getSubDnLabel();
932 elseif ($key=='label_actions') {
935 elseif ($key=='label_no_result') {
936 return _("This search didn't get any result.");
938 elseif ($key=='sort') {
939 if (isset($this -> params['sortlimit']) && ($this -> params['sortlimit']>0)) {
940 return ($this -> total < $this -> params['sortlimit']);
944 elseif ($key=='sortlimit') {
945 return $this -> params['sortlimit'];
947 elseif ($key=='total') {
948 return count($this -> result['list']);
950 elseif ($key=='label_total') {
951 return $this -> total." ".$this -> label_objectName;
953 elseif ($key=='displaySubDn') {
954 if (LSsession :: subDnIsEnabled()) {
955 if (!is_null($this -> params[$key])) {
956 return $this -> params[$key];
959 return (! LSsession :: isSubDnLSobject($this -> LSobject) );
964 elseif ($key=='canCopy') {
965 if (!is_null($this -> _canCopy))
966 return $this -> _canCopy;
967 $this -> _canCopy = LSsession :: canCreate($this -> LSobject);
968 return $this -> _canCopy;
970 elseif ($key=='predefinedFilters') {
971 return ((is_array($this -> config['predefinedFilters']))?$this -> config['predefinedFilters']:array());
974 throw new Exception('Incorrect property !');
979 * Function use with uasort to sort two entry
981 * @param[in] $a array One line of result
982 * @param[in] $b array One line of result
984 * @retval int Value for uasort
986 private function _sortTwoEntry(&$a,&$b) {
987 $sortBy = $this -> params['sortBy'];
988 $sortDirection = $this -> params['sortDirection'];
989 if ($sortDirection=='ASC') {
995 $oa = new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$a);
997 $ob = new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$b);
1000 if ($va == $vb) return 0;
1002 $val = array($va,$vb);
1012 * Function to run after using the result. It's update the cache
1014 * IT'S FUNCTION IS VERY IMPORTANT !!!
1018 function afterUsingResult() {
1019 $this -> addResultToCache();
1023 * Run the sort if it's enabled and if the result is not in the cache
1025 * @retval boolean True on success or false
1028 if (!$this -> sort) {
1029 LSdebug('doSort : sort is disabled');
1032 if (is_null($this -> params['sortBy'])) {
1035 if (is_null($this -> params['sortDirection'])) {
1036 $this -> params['sortDirection']='ASC';
1039 if ($this->total==0) {
1043 if (isset($this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']])) {
1044 LSdebug('doSort : from cache');
1048 LSdebug('doSort : '.$this -> params['sortBy'].' - '.$this -> params['sortDirection']);
1050 $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']]=range(0,($this -> total-1));
1052 if (!LSsession :: loadLSClass('LSsearchEntry')) {
1053 LSerror::addErrorCode('LSsession_05','LSsearchEntry');
1058 $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']],
1059 array($this,'_sortTwoEntry')
1061 LSerror :: addErrorCode('LSsearch_13');
1069 * Returns the id of table rows in the result sorted according to criteria
1070 * defined in the parameters
1072 * @retval array The Table of id lines of results sorted
1074 function getSortTable() {
1075 if ($this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']]) {
1076 return $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']];
1078 return range(0,($this -> total-1));
1084 * @retval Array DN associate with name
1086 public function listObjectsName() {
1087 if (!LSsession::loadLSclass('LSsearchEntry')) {
1088 LSerror::addErrorCode('LSsession_05',$this -> LSobject);
1094 if ($this -> total>0) {
1095 $sortTable=$this -> getSortTable();
1097 foreach ($sortTable as $key => $id) {
1098 $entry=new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$id);
1099 $retval[$entry->dn]=$entry->displayName;
1107 * List LSldapObjects
1109 * @retval Array of LSldapObjects
1111 public function listObjects() {
1114 if ($this -> total>0) {
1115 $sortTable=$this -> getSortTable();
1118 foreach ($sortTable as $key => $id) {
1119 $retval[$c]=new $this -> LSobject();
1120 $retval[$c] -> loadData($this -> result['list'][$id]['dn']);
1131 * @retval Array of DN
1133 public function listObjectsDn() {
1136 if ($this -> total>0) {
1137 $sortTable=$this -> getSortTable();
1140 foreach ($sortTable as $key => $id) {
1141 $retval[$c] = $this -> result['list'][$id]['dn'];
1154 LSerror :: defineError('LSsearch_01',
1155 _("LSsearch : Invalid filter : %{filter}.")
1157 LSerror :: defineError('LSsearch_02',
1158 _("LSsearch : Invalid basedn : %{basedn}.")
1160 LSerror :: defineError('LSsearch_03',
1161 _("LSsearch : Invalid value for %{param} parameter.")
1163 LSerror :: defineError('LSsearch_04',
1164 _("LSsearch : Invalid size limit. Must be an integer greater or equal to 0.")
1166 LSerror :: defineError('LSsearch_05',
1167 _("LSsearch : Invalid parameter %{attr}. Must be an boolean.")
1169 LSerror :: defineError('LSsearch_06',
1170 _("LSsearch : Invalid parameter attributes. Must be an string or an array of strings.")
1172 LSerror :: defineError('LSsearch_07',
1173 _("LSsearch : Can't build attributes list for make filter.")
1175 LSerror :: defineError('LSsearch_08',
1176 _("LSsearch : Error building filter with attribute '%{attr}' and pattern '%{pattern}'")
1178 LSerror :: defineError('LSsearch_09',
1179 _("LSsearch : Error combining filters.")
1181 LSerror :: defineError('LSsearch_10',
1182 _("LSsearch : Invalid pattern.")
1184 LSerror :: defineError('LSsearch_11',
1185 _("LSsearch : Invalid attribute %{attr} in parameters.")
1187 LSerror :: defineError('LSsearch_12',
1188 _("LSsearch : Error during the search.")
1190 LSerror :: defineError('LSsearch_13',
1191 _("LSsearch : Error sorting the search.")
1193 LSerror :: defineError('LSsearch_14',
1194 _("LSsearch : The function of the custum information %{name} is not callable.")