diff --git a/public_html/includes/class/class.LSsearch.php b/public_html/includes/class/class.LSsearch.php index e575a25e..8f8703df 100644 --- a/public_html/includes/class/class.LSsearch.php +++ b/public_html/includes/class/class.LSsearch.php @@ -495,6 +495,15 @@ class LSsearch { return $OK; } + /** + * Return true only if the form is submited + * + * @retval boolean True only if the is submited + **/ + private function formIsSubmited() { + return isset($_REQUEST['LSsearch_submit']); + } + /** * Define search parameters by reading Post Data ($_REQUEST) * @@ -503,7 +512,7 @@ class LSsearch { public function setParamsFormPostData() { $data = $_REQUEST; - if (isset($data['LSsearch_submit'])) { + if (self::formIsSubmited()) { // Recursive if (is_null($data['recursive'])) { $data['recursive']=false; @@ -1019,6 +1028,18 @@ class LSsearch { $this -> addResultToCache(); } + /** + * Redirect user to object view if the search have only one result + * + * @retval boolean True only if user have been redirected + **/ + function redirectWhenOnlyOneResult() { + if ($this -> total == 1 && $this -> result && self::formIsSubmited()) { + LSsession :: redirect('view.php?LSobject='.$this -> LSobject.'&dn='.$this -> result['list'][0]['dn']); + } + return; + } + /** * Run the sort if it's enabled and if the result is not in the cache * diff --git a/public_html/view.php b/public_html/view.php index 0d06d32d..97d4559d 100644 --- a/public_html/view.php +++ b/public_html/view.php @@ -137,6 +137,9 @@ if(LSsession :: startLSsession()) { $GLOBALS['Smarty']->assign('LSview_actions',$LSview_actions); $LSsearch -> run(); + + $LSsearch -> redirectWhenOnlyOneResult(); + $page=(int)$_REQUEST['page']; $page = $LSsearch -> getPage($page); $GLOBALS['Smarty']->assign('page',$page);