Merge remote branch 'origin/platal-1.0.0'
[platal.git] / modules / search.php
index 7b4b302..67b4ba3 100644 (file)
@@ -25,10 +25,10 @@ class SearchModule extends PLModule
     {
         return array(
             'search'              => $this->make_hook('quick',          AUTH_PUBLIC),
-            'search/adv'          => $this->make_hook('advanced',       AUTH_COOKIE),
+            'search/adv'          => $this->make_hook('advanced',       AUTH_COOKIE, 'directory_ax'),
             'advanced_search.php' => $this->make_hook('redir_advanced', AUTH_PUBLIC),
-            'search/autocomplete' => $this->make_hook('autocomplete',   AUTH_COOKIE, 'user', NO_AUTH),
-            'search/list'         => $this->make_hook('list',           AUTH_COOKIE, 'user', NO_AUTH),
+            'search/autocomplete' => $this->make_hook('autocomplete',   AUTH_COOKIE, 'directory_ax', NO_AUTH),
+            'search/list'         => $this->make_hook('list',           AUTH_COOKIE, 'directory_ax', NO_AUTH),
         );
     }
 
@@ -48,10 +48,20 @@ class SearchModule extends PLModule
         global $globals;
 
         if (Env::has('quick') || $action == 'geoloc') {
-            $quick = trim(Env::t('quick'));
+            $quick = Env::t('quick');
             if (S::logged() && !Env::has('page')) {
                 S::logger()->log('search', 'quick=' . $quick);
             }
+
+            if ($quick == '') {
+                $page->trigWarning('Aucun critère de recherche n\'est spécifié.');
+                $page->changeTpl('search/index.tpl');
+                $page->setTitle('Annuaire');
+                $page->assign('formulaire', 1);
+                $page->addJsLink('ajax.js');
+                return;
+            }
+
             $list = 'profile|prf|fiche|fic|referent|ref|mentor';
             if (S::admin()) {
                 $list .= '|admin|adm|ax';
@@ -159,6 +169,9 @@ class SearchModule extends PLModule
             if ($nb_tot > $globals->search->private_max) {
                 $this->form_prepare();
                 $page->trigError('Recherche trop générale.');
+            } else if ($nb_tot == 0) {
+                $this->form_prepare();
+                $page->trigError('Il n\'existe personne correspondant à ces critères dans la base !');
             }
         }
 
@@ -243,6 +256,10 @@ class SearchModule extends PLModule
 
     function handler_list(&$page, $type = null, $idVal = null)
     {
+        $page->assign('name', $type);
+        $page->assign('with_text_value', true);
+        $page->assign('onchange', "document.forms.recherche.{$type}Txt.value = this.options[this.selectedIndex].text");
+
         // Give the list of all values possible of type and builds a select input for it
         $ids = null;
 
@@ -270,9 +287,9 @@ class SearchModule extends PLModule
           case 'nationalite':
             $ids = DirEnum::getOptionsIter(DirEnum::NATIONALITIES);
             break;
-        case 'region':
-            if ($isset($_REQUEST['country'])) {
-                $ids = DirEnum::getOptionsIter(DirEnum::ADMINAREAS, $_REQUEST['country']);
+          case 'region':
+            if (Env::has('country')) {
+                $ids = DirEnum::getOptionsIter(DirEnum::ADMINAREAS, Env::v('country'));
             } else {
                 $ids = DirEnum::getOptionsIter(DirEnum::ADMINAREAS);
             }
@@ -296,10 +313,7 @@ class SearchModule extends PLModule
         }
         pl_content_headers("text/xml");
         $page->changeTpl('include/field.select.tpl', NO_SKIN);
-        $page->assign('name', $type);
         $page->assign('list', $ids);
-        $page->assign('with_text_value', true);
-        $page->assign('onchange', "document.forms.recherche.{$type}Txt.value = this.options[this.selectedIndex].text");
     }
 }