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 LSerror::addErrorCode('LSsearch_01','$key');
128 unset($this -> config['predefinedFilters'][$key]);
135 * Load default search parameters from configuration
137 * @retval boolean True on success or False
139 private function loadDefaultParameters() {
140 if (is_array($this -> config['params'])) {
141 return $this -> setParams($this -> config['params']);
147 * Load search parameters from session
149 * @retval boolean True if params has been loaded from session or False
151 private function loadParamsFromSession() {
152 LSdebug('LSsearch : load context params session '.$this -> context);
153 if (is_array($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context])) {
154 $params = $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context];
156 if ($params['filter']) {
157 $params['filter'] = Net_LDAP2_Filter::parse($params['filter']);
160 $this -> params = $params;
167 * Save search parameters in session
171 private function saveParamsInSession() {
172 LSdebug('LSsearch : save context params session '.$this -> context);
173 $params = $this -> params;
174 if ($params['filter'] instanceof Net_LDAP2_Filter) {
175 $params['filter'] = $params['filter'] -> asString();
178 foreach ($params as $param => $value) {
179 if ($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]!=$value) {
180 LSdebug("S: $param => $value");
181 $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]=$value;
187 * Purge parameters in session
189 * @param[in] $LSobject string The LSobject type
193 public function purgeParams($LSobject=NULL) {
194 if (is_null($LSobject)) {
195 $LSobject = $this -> LSobject;
197 unset($_SESSION['LSsession']['LSsearch'][$LSobject]['params']);
205 public function purgeCache($LSobject=NULL) {
206 if (is_null($LSobject))
207 $LSobject = $this -> LSobject;
208 unset($_SESSION['LSsession']['LSsearch'][$LSobject]);
216 private function purgeSession() {
217 unset($_SESSION['LSsession']['LSsearch']);
221 * Define one search parameter
223 * @param[in] $param string The parameter name
224 * @param[in] $value mixed The parameter value
226 * @retval boolean True on success or False
228 public function setParam($param,$value) {
229 return $this -> setParams(array($param => $value));
233 * Define search parameters
235 * @param[in] $params array Parameters of search
237 * @retval boolean True on success or False
239 public function setParams($params) {
243 if (is_string($params['filter'])) {
244 $filter = Net_LDAP2_Filter::parse($params['filter']);
245 if (!LSerror::isLdapError($filter)) {
246 $this -> params['filter'] = $filter;
249 LSerror :: addErrorCode('LSsearch_01',$params['filter']);
253 elseif($params['filter'] instanceof Net_LDAP2_Filter) {
254 $this -> params['filter'] =& $params['filter'];
258 if (isset($params['approx'])) {
259 if (is_bool($params['approx']) || $params['approx']==0 || $params['approx']==1) {
260 $this -> params['approx'] = (bool)$params['approx'];
263 LSerror :: addErrorCode('LSsearch_05','approx');
269 if (isset($params['withoutCache'])) {
270 if (is_bool($params['withoutCache']) || $params['withoutCache']==0 || $params['withoutCache']==1) {
271 $this -> params['withoutCache'] = (bool)$params['withoutCache'];
274 LSerror :: addErrorCode('LSsearch_05','withoutCache');
280 if (isset($params['pattern']) && $params['pattern']=="") {
281 $this -> params['pattern'] = NULL;
282 $this -> params['filter'] = NULL;
284 elseif (self :: isValidPattern($params['pattern'])) {
285 $this -> params['pattern'] = $params['pattern'];
286 if (!is_string($params['filter'])) {
287 $this -> params['filter']=NULL;
293 if (is_string($params['basedn'])) {
294 if (isCompatibleDNs(LSsession :: getRootDn(),$params['basedn'])) {
295 $this -> params['basedn'] = $params['basedn'];
298 LSerror :: addErrorCode('LSsearch_02',$params['basedn']);
304 if (is_string($params['subDn'])) {
305 if (LSsession :: validSubDnLdapServer($params['subDn'])) {
306 $this -> params['subDn'] = $params['subDn'];
309 LSerror :: addErrorCode('LSsearch_03','subDn');
315 if (is_string($params['scope'])) {
316 if (in_array($params['scope'],array('sub','one','base'))) {
317 $this -> params['scope'] = $params['scope'];
320 LSerror :: addErrorCode('LSsearch_03','scope');
326 if (isset($params['nbObjectsByPage'])) {
327 if (((int)$params['nbObjectsByPage'])>1 ) {
328 $this -> params['nbObjectsByPage'] = (int)$params['nbObjectsByPage'];
331 LSerror :: addErrorCode('LSsearch_03','nbObjectsByPage');
337 if (isset($params['sortlimit'])) {
338 if (is_int($params['sortlimit']) && $params['sortlimit']>=0 ) {
339 $this -> params['sortlimit'] = $params['sortlimit'];
341 elseif ((int)$params['sortlimit'] > 0) {
342 $this -> params['sortlimit'] = (int)$params['sortlimit'];
345 LSerror :: addErrorCode('LSsearch_03','sortlimit');
351 if (is_string($params['sortDirection'])) {
352 if (in_array($params['sortDirection'],array('ASC','DESC'))) {
353 $this -> params['sortDirection'] = $params['sortDirection'];
356 LSerror :: addErrorCode('LSsearch_03','sortDirection');
362 if (is_string($params['sortBy'])) {
363 if (in_array($params['sortBy'],array('displayName','subDn'))) {
364 if ($this -> params['sortBy'] == $params['sortBy']) {
365 $this -> toggleSortDirection();
368 $this -> params['sortBy'] = $params['sortBy'];
369 if (!is_string($params['sortDirection'])) {
370 $this -> params['sortDirection']='ASC';
375 LSerror :: addErrorCode('LSsearch_03','sortBy');
381 if (isset($params['sizelimit'])) {
382 if (((int)$params['sizelimit']) >= 0) {
383 $this -> params['sizelimit'] = $params['sizelimit'];
386 LSerror :: addErrorCode('LSsearch_04');
392 if (isset($params['attronly'])) {
393 if (is_bool($params['attronly']) || $params['attronly']==0 || $params['attronly']==1) {
394 $this -> params['attronly'] = (bool)$params['attronly'];
397 LSerror :: addErrorCode('LSsearch_05','attronly');
403 if (isset($params['recursive'])) {
404 if (is_bool($params['recursive']) || $params['recursive']==0 || $params['recursive']==1) {
405 $this -> params['recursive'] = (bool)$params['recursive'];
408 LSerror :: addErrorCode('LSsearch_05','recursive');
414 if (isset($params['displaySubDn'])) {
415 if (! LSsession :: isSubDnLSobject($this -> LSobject) ) {
416 if (is_bool($params['displaySubDn']) || $params['displaySubDn']==0 || $params['displaySubDn']==1) {
417 $this -> params['displaySubDn'] = (bool)$params['displaySubDn'];
420 LSerror :: addErrorCode('LSsearch_05','displaySubDn');
427 if (isset($params['attributes'])) {
428 if (is_string($params['attributes'])) {
429 $this -> params['attributes'] = array($params['attributes']);
431 elseif (is_array($params['attributes'])) {
432 $this -> params['attributes']=array();
433 foreach ($this -> params['attributes'] as $attr) {
434 if (is_string($attr)) {
435 if (LSconfig::get("LSobjects.".$this -> LSobject.".attrs.$attr")) {;
436 $this -> params['attributes'][] = $attr;
439 LSerror :: addErrorCode('LSsearch_11',$attr);
445 LSerror :: addErrorCode('LSsearch_06');
451 if (isset($params['predefinedFilter'])) {
452 if (is_string($params['predefinedFilter'])) {
453 if (empty($params['predefinedFilter'])) {
454 $this->params['predefinedFilter']=false;
456 elseif(is_array($this -> config['predefinedFilters'])) {
457 if(isset($this->config['predefinedFilters'][$params['predefinedFilter']])) {
458 $this -> params['predefinedFilter'] = $params['predefinedFilter'];
461 LSerror :: addErrorCode('LSsearch_03','predefinedFilter');
467 LSerror :: addErrorCode('LSsearch_03','predefinedFilter');
473 if (is_string($params['displayFormat'])) {
474 $this -> params['displayFormat'] = $params['displayFormat'];
478 if (is_array($params['customInfos'])) {
479 foreach($params['customInfos'] as $name => $data) {
480 if(is_array($data['function']) && is_string($data['function'][0])) {
481 LSsession::loadLSclass($data['function'][0]);
483 if (is_callable($data['function'])) {
484 $this -> params['customInfos'][$name] = array (
485 'function' => &$data['function'],
486 'args' => $data['args']
490 LSerror :: addErrorCode('LSsearch_14',$name);
495 $this -> saveParamsInSession();
500 * Return true only if the form is submited
502 * @retval boolean True only if the is submited
504 private function formIsSubmited() {
505 return isset($_REQUEST['LSsearch_submit']);
509 * Define search parameters by reading Post Data ($_REQUEST)
513 public function setParamsFormPostData() {
516 if (self::formIsSubmited()) {
518 if (is_null($data['recursive'])) {
519 $data['recursive']=false;
522 $data['recursive']=true;
526 if (is_null($data['approx'])) {
527 $data['approx']=false;
530 $data['approx']=true;
533 if (isset($data['ajax']) && !isset($data['pattern'])) {
538 $this -> setParams($data);
542 * Toggle the sort direction
546 private function toggleSortDirection() {
547 if ($this -> params['sortDirection']=="ASC") {
548 $this -> params['sortDirection'] = "DESC";
551 $this -> params['sortDirection'] = "ASC";
556 * Make a filter object with a pattern of search
558 * @param[in] $pattern The pattern of search. If is null, the pattern in params will be used.
560 * @retval mixed Net_LDAP2_Filter on success or False
562 function getFilterFromPattern($pattern=NULL) {
563 if ($pattern==NULL) {
564 $pattern=$this -> params['pattern'];
566 if (self :: isValidPattern($pattern)) {
567 $operator=( ($params['approx'])?'approx':'contains' );
568 $attrsList=LSconfig::get("LSobjects.".$this -> LSobject.".LSsearch.attrs");
569 if (!is_array($attrsList)) {
570 $attrsList = array_keys(LSconfig::get("LSobjects.".$this -> LSobject.".attrs"));
573 if (empty($attrsList)) {
574 LSerror :: addErrorCode('LSsearch_07');
579 foreach ($attrsList as $attr) {
580 $filter=Net_LDAP2_Filter::create($attr,$operator,$pattern);
581 if (!Net_LDAP2::isError($filter)) {
585 LSerror :: addErrorCode('LSsearch_08',array('attr' => $attr,'pattern' => $pattern));
589 if(!empty($filters)) {
590 $filter=LSldap::combineFilters('or',$filters);
595 LSerror :: addErrorCode('LSsearch_09');
600 LSerror :: addErrorCode('LSsearch_10');
606 * Check if search pattern is valid
608 * @param[in] $pattern string The pattern
610 * @retval boolean True if pattern is valid or False
612 static function isValidPattern($pattern) {
613 return (is_string($pattern) && $pattern!= "" && $pattern!="*");
617 * Check if cache is enabled
619 * @retval boolean True if cache is enabled or False
621 public function cacheIsEnabled() {
622 if (isset($this -> config['cache'])) {
623 $conf=$this -> config['cache'];
624 if (is_bool($conf) || $conf==0 || $conf==1) {
628 LSerror :: addErrorCode('LSsearch_03','cache');
631 return LSsession :: cacheSearch();
635 * Methode for parameters value access
637 * @param[in] $key string The parameter name
639 * @retval mixed The parameter value or NULL
641 public function getParam($key) {
642 if(in_array($key,array_keys($this -> params))) {
643 return $this -> params[$key];
649 * Return hidden fileds to add in search form
651 * @retval array The hield fields whith their values
653 public function getHiddenFieldForm() {
655 'LSobject' => $this -> LSobject
660 * Generate an array with search parameters, only parameters whitch have to be
661 * passed to Net_LDAP2 for the LDAP search. This array will be store in
662 * $this -> _searchParams private variable.
666 private function generateSearchParams() {
667 // Purge the cache of the hash
668 $this -> _hash = NULL;
672 'filter' => $this -> params['filter'],
673 'basedn' => $this -> params['basedn'],
674 'scope' => $this -> params['scope'],
675 'sizelimit' => $this -> params['sizelimit'],
676 'attronly' => $this -> params['attronly'],
677 'attributes' => $this -> params['attributes']
681 if (!is_null($this -> params['pattern'])) {
682 $filter=$this ->getFilterFromPattern();
683 if (is_null($retval['filter'])) {
684 $retval['filter']=$filter;
687 $retval['filter']=LSldap::combineFilters('and',array($retval['filter'],$filter));
692 if (is_string($this -> params['predefinedFilter'])) {
693 if (!is_null($retval['filter'])) {
694 $filter=LSldap::combineFilters('and',array($this -> params['predefinedFilter'],$retval['filter']));
696 $retval['filter']=$filter;
700 $retval['filter']=$this -> params['predefinedFilter'];
705 $objFilter=LSldapObject::getObjectFilter($this -> LSobject);
707 if (!is_null($retval['filter'])) {
708 $filter=LSldap::combineFilters('and',array($objFilter,$retval['filter']));
710 $retval['filter']=$filter;
714 $retval['filter']=$objFilter;
719 if (is_null($retval['basedn'])) {
720 if (!is_null($this -> params['subDn'])) {
721 if ($this -> params['recursive']) {
722 $retval['basedn'] = $this -> params['subDn'];
725 $retval['basedn'] = LSconfig::get("LSobjects.".$this -> LSobject.".container_dn").','.$this -> params['subDn'];
729 if ($this -> params['recursive']) {
730 $retval['basedn'] = LSsession :: getTopDn();
733 $retval['basedn'] = LSconfig::get("LSobjects.".$this -> LSobject.".container_dn").','.LSsession :: getTopDn();
737 if ($this -> params['recursive'] || !isset($retval['scope'])) {
738 $retval['scope'] = 'sub';
741 if (is_null($this -> params['displayFormat'])) {
742 $this -> params['displayFormat']=LSconfig::get("LSobjects.".$this -> LSobject.".display_name_format");
746 $attrs=getFieldInFormat($this -> params['displayFormat']);
747 if(is_array($retval['attributes'])) {
748 $retval['attributes']=array_merge($attrs,$retval['attributes']);
751 $retval['attributes']=$attrs;
754 $this -> _searchParams = $retval;
760 * @param[in] $cache boolean Define if the cache can be used
762 * @retval boolean True on success or False
764 public function run($cache=true) {
765 $this -> generateSearchParams();
766 if ($this -> _searchParams['filter'] instanceof Net_LDAP2_Filter) {
767 LSdebug('LSsearch : filter : '.$this -> _searchParams['filter']->asString());
769 LSdebug('LSsearch : basedn : '.$this -> _searchParams['basedn'].' - scope : '.$this -> _searchParams['scope']);
771 if( $cache && (!isset($_REQUEST['refresh'])) && (!$this -> params['withoutCache']) ) {
772 LSdebug('LSsearch : with the cache');
773 $this -> result = $this -> getResultFromCache();
776 LSdebug('LSsearch : without the cache');
777 $this -> setParam('withoutCache',false);
780 if (!$this -> result) {
781 LSdebug('LSsearch : Not in cache');
782 $this -> result=array(
784 'sortDirection' => NULL
786 $this -> result['list'] = LSldap :: search(
787 $this -> _searchParams['filter'],
788 $this -> _searchParams['basedn'],
789 $this -> _searchParams
791 if ($this -> result['list'] === false) {
792 LSerror :: addErrorCode('LSsearch_12');
793 unset($this -> result['list']);
796 $this -> addResultToCache();
805 * Return an hash corresponding to the parameters of the search
807 * @param[in] $searchParams array An optional search params array
809 * @retval string The hash of the parameters of the search
811 public function getHash($searchParams=null) {
812 if(is_null($searchParams)) {
813 $searchParams=$this -> _searchParams;
814 if ($this -> _hash) {
815 return $this -> _hash;
818 if ($searchParams['filter'] instanceof Net_LDAP_Filter) {
819 $searchParams['filter']=$searchParams['filter']->asString();
821 return hash('md5',print_r($searchParams,true));
825 * Add the result of the search to cache of the session
829 public function addResultToCache() {
830 if ($this -> cacheIsEnabled()) {
831 LSdebug('LSsearch : Save result in cache.');
832 $hash=$this->getHash();
833 $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash]=$this->result;
838 * Get the result of the search from cache of the session
840 * @retval array | False The array of the result of the search or False
842 private function getResultFromCache() {
843 if ($this -> cacheIsEnabled()) {
844 $hash=$this->getHash();
845 if (isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash])) {
846 LSdebug('LSsearch : Load result from cache.');
847 return $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash];
854 * Get page informations to display
856 * @param[in] $page integer The number of the page
858 * @retval array The information of the page
860 public function getPage($page=0) {
861 if (!LSsession::loadLSclass('LSsearchEntry')) {
862 LSerror::addErrorCode('LSsession_05',$this -> LSobject);
871 'total' => $this -> total
874 if ($retval['total']>0) {
875 LSdebug('Total : '.$retval['total']);
877 if (!$this->params['nbObjectsByPage']) {
878 $this->params['nbObjectsByPage']=NB_LSOBJECT_LIST;
880 $retval['nbPages']=ceil($retval['total']/$this->params['nbObjectsByPage']);
882 $sortTable=$this -> getSortTable();
886 ($page * $this->params['nbObjectsByPage']),
887 $this->params['nbObjectsByPage']
890 foreach ($list as $key => $id) {
891 $retval['list'][]=new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$id);
900 * @retval array The entries
902 public function getSearchEntries() {
903 if (!LSsession::loadLSclass('LSsearchEntry')) {
904 LSerror::addErrorCode('LSsession_05',$this -> LSobject);
908 if ($this -> total>0) {
909 $sortTable=$this -> getSortTable();
911 foreach ($sortTable as $key => $id) {
912 $retval[]=new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$id);
919 * Access to information of this object
921 * @param[in] $key string The key of the info
923 * @retval mixed The info
925 public function __get($key) {
930 if ($key=='LSobject') {
931 return $this -> LSobject;
933 elseif (in_array($key,$params)) {
934 return $this -> params[$key];
936 elseif ($key=='label_objectName') {
937 return LSldapObject::getLabel($this -> LSobject);
939 elseif ($key=='label_level') {
940 return LSsession :: getSubDnLabel();
942 elseif ($key=='label_actions') {
945 elseif ($key=='label_no_result') {
946 return _("This search didn't get any result.");
948 elseif ($key=='sort') {
949 if (isset($this -> params['sortlimit']) && ($this -> params['sortlimit']>0)) {
950 return ($this -> total < $this -> params['sortlimit']);
954 elseif ($key=='sortlimit') {
955 return $this -> params['sortlimit'];
957 elseif ($key=='total') {
958 return count($this -> result['list']);
960 elseif ($key=='label_total') {
961 return $this -> total." ".$this -> label_objectName;
963 elseif ($key=='displaySubDn') {
964 if (LSsession :: subDnIsEnabled()) {
965 if (!is_null($this -> params[$key])) {
966 return $this -> params[$key];
969 return (! LSsession :: isSubDnLSobject($this -> LSobject) );
974 elseif ($key=='canCopy') {
975 if (!is_null($this -> _canCopy))
976 return $this -> _canCopy;
977 $this -> _canCopy = LSsession :: canCreate($this -> LSobject);
978 return $this -> _canCopy;
980 elseif ($key=='predefinedFilters') {
982 if (is_array($this -> config['predefinedFilters'])) {
983 foreach($this -> config['predefinedFilters'] as $filter => $label) {
984 $retval[$filter]=__($label);
990 throw new Exception('Incorrect property !');
995 * Function use with uasort to sort two entry
997 * @param[in] $a array One line of result
998 * @param[in] $b array One line of result
1000 * @retval int Value for uasort
1002 private function _sortTwoEntry(&$a,&$b) {
1003 $sortBy = $this -> params['sortBy'];
1004 $sortDirection = $this -> params['sortDirection'];
1005 if ($sortDirection=='ASC') {
1011 $oa = new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$a);
1013 $ob = new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$b);
1016 if ($va == $vb) return 0;
1018 $val = array($va,$vb);
1028 * Function to run after using the result. It's update the cache
1030 * IT'S FUNCTION IS VERY IMPORTANT !!!
1034 function afterUsingResult() {
1035 $this -> addResultToCache();
1039 * Redirect user to object view if the search have only one result
1041 * @retval boolean True only if user have been redirected
1043 function redirectWhenOnlyOneResult() {
1044 if ($this -> total == 1 && $this -> result && self::formIsSubmited()) {
1045 LSsession :: redirect('view.php?LSobject='.$this -> LSobject.'&dn='.$this -> result['list'][0]['dn']);
1051 * Run the sort if it's enabled and if the result is not in the cache
1053 * @retval boolean True on success or false
1056 if (!$this -> sort) {
1057 LSdebug('doSort : sort is disabled');
1060 if (is_null($this -> params['sortBy'])) {
1063 if (is_null($this -> params['sortDirection'])) {
1064 $this -> params['sortDirection']='ASC';
1067 if ($this->total==0) {
1071 if (isset($this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']])) {
1072 LSdebug('doSort : from cache');
1076 LSdebug('doSort : '.$this -> params['sortBy'].' - '.$this -> params['sortDirection']);
1078 $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']]=range(0,($this -> total-1));
1080 if (!LSsession :: loadLSClass('LSsearchEntry')) {
1081 LSerror::addErrorCode('LSsession_05','LSsearchEntry');
1086 $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']],
1087 array($this,'_sortTwoEntry')
1089 LSerror :: addErrorCode('LSsearch_13');
1097 * Returns the id of table rows in the result sorted according to criteria
1098 * defined in the parameters
1100 * @retval array The Table of id lines of results sorted
1102 function getSortTable() {
1103 if ($this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']]) {
1104 return $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']];
1106 return range(0,($this -> total-1));
1112 * @retval Array DN associate with name
1114 public function listObjectsName() {
1115 if (!LSsession::loadLSclass('LSsearchEntry')) {
1116 LSerror::addErrorCode('LSsession_05',$this -> LSobject);
1122 if ($this -> total>0) {
1123 $sortTable=$this -> getSortTable();
1125 foreach ($sortTable as $key => $id) {
1126 $entry=new LSsearchEntry($this,$this -> LSobject,$this -> params,$this -> _hash,$this -> result['list'],$id);
1127 $retval[$entry->dn]=$entry->displayName;
1135 * List LSldapObjects
1137 * @retval Array of LSldapObjects
1139 public function listObjects() {
1142 if ($this -> total>0) {
1143 $sortTable=$this -> getSortTable();
1146 foreach ($sortTable as $key => $id) {
1147 $retval[$c]=new $this -> LSobject();
1148 $retval[$c] -> loadData($this -> result['list'][$id]['dn']);
1159 * @retval Array of DN
1161 public function listObjectsDn() {
1164 if ($this -> total>0) {
1165 $sortTable=$this -> getSortTable();
1168 foreach ($sortTable as $key => $id) {
1169 $retval[$c] = $this -> result['list'][$id]['dn'];
1182 LSerror :: defineError('LSsearch_01',
1183 _("LSsearch : Invalid filter : %{filter}.")
1185 LSerror :: defineError('LSsearch_02',
1186 _("LSsearch : Invalid basedn : %{basedn}.")
1188 LSerror :: defineError('LSsearch_03',
1189 _("LSsearch : Invalid value for %{param} parameter.")
1191 LSerror :: defineError('LSsearch_04',
1192 _("LSsearch : Invalid size limit. Must be an integer greater or equal to 0.")
1194 LSerror :: defineError('LSsearch_05',
1195 _("LSsearch : Invalid parameter %{attr}. Must be an boolean.")
1197 LSerror :: defineError('LSsearch_06',
1198 _("LSsearch : Invalid parameter attributes. Must be an string or an array of strings.")
1200 LSerror :: defineError('LSsearch_07',
1201 _("LSsearch : Can't build attributes list for make filter.")
1203 LSerror :: defineError('LSsearch_08',
1204 _("LSsearch : Error building filter with attribute '%{attr}' and pattern '%{pattern}'")
1206 LSerror :: defineError('LSsearch_09',
1207 _("LSsearch : Error combining filters.")
1209 LSerror :: defineError('LSsearch_10',
1210 _("LSsearch : Invalid pattern.")
1212 LSerror :: defineError('LSsearch_11',
1213 _("LSsearch : Invalid attribute %{attr} in parameters.")
1215 LSerror :: defineError('LSsearch_12',
1216 _("LSsearch : Error during the search.")
1218 LSerror :: defineError('LSsearch_13',
1219 _("LSsearch : Error sorting the search.")
1221 LSerror :: defineError('LSsearch_14',
1222 _("LSsearch : The function of the custum information %{name} is not callable.")