Non significant spaces suck.
[platal.git] / modules / search.php
index ea8491a..a4cd481 100644 (file)
@@ -80,7 +80,43 @@ class SearchModule extends PLModule
     {
         global $globals;
 
+        $res = XDB::query("SELECT  MIN(`diminutif`), MAX(`diminutif`)
+                             FROM  `groupex`.`asso`
+                            WHERE  `cat` = 'Promotions'");
+        list($min, $max) = $res->fetchOneRow();
+        $page->assign('promo_min', $min);
+        $page->assign('promo_max', $max);
+
         if (Env::has('quick') || $action == 'geoloc') {
+            $quick = trim(Env::v('quick'));
+            $list = 'profile|prf|fiche|fic|referent|ref|mentor';
+            if (S::has_perms()) {
+                $list .= '|admin|adm|ax';
+            }
+            if (preg_match('/^(' . $list . '):([-a-z]+(\.[-a-z]+(\.\d{2,4})?)?)$/', $quick, $matches)) {
+                $forlife = $matches[2];
+                switch($matches[1]) {
+                  case 'admin': case 'adm':
+                    $base = 'admin/user/';
+                    break;
+                  case 'ax':
+                    $base = 'profile/ax/';
+                    break;
+                  case 'profile': case 'prf': case 'fiche': case 'fic':
+                    $base = 'profile/';
+                    break;
+                  case 'referent': case 'ref': case 'mentor':
+                    $base = 'referent/';
+                    break;
+                }
+                pl_redirect($base . $forlife);
+            } elseif (strpos($quick, 'doc:') === 0) {
+                $url = 'Docs/Recherche?';
+                $url .= 'action=search&q=' . urlencode(substr($quick, 4));
+                $url .= '&group=' . urlencode('-Equipe,-Main,-PmWiki,-Site');
+                pl_redirect($url);
+            }
+
             $page->assign('formulaire', 0);
 
             require_once 'userset.inc.php';
@@ -88,7 +124,7 @@ class SearchModule extends PLModule
             $view->addMod('minifiche', 'Minifiches', true, array('with_score' => true));
             if (S::logged() && !Env::i('nonins')) {
                 $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true, 'with_score' => true));
-                $view->addMod('geoloc', 'Planisphère');
+                $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
             }
             $view->apply('search', $page, $action, $subaction);
 
@@ -104,20 +140,13 @@ class SearchModule extends PLModule
                 new ThrowError('il n\'existe personne correspondant à ces critères dans la base !');
             }
         } else {
-            $res = XDB::query("SELECT  MIN(`diminutif`), MAX(`diminutif`)
-                                 FROM  `groupex`.`asso`
-                                WHERE  `cat` = 'Promotions'");
-            list($min, $max) = $res->fetchOneRow();
-            $page->assign('promo_min', $min);
-            $page->assign('promo_max', $max); 
             $page->assign('formulaire',1);
             $page->addJsLink('ajax.js');
         }
 
         require_once dirname(__FILE__) . '/search/search.inc.php';
-        $page->changeTpl('search/index.tpl');            
+        $page->changeTpl('search/index.tpl');
         $page->assign('xorg_title','Polytechnique.org - Annuaire');
-        $page->assign('baseurl', $globals->baseurl);
     }
 
     function handler_advanced(&$page, $action = null, $subaction = null)
@@ -134,9 +163,9 @@ class SearchModule extends PLModule
             $view = new SearchSet(false, $action == 'geoloc' && substr($subaction, -3) == 'swf');
             $view->addMod('minifiche', 'Minifiches', true);
             $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true));
-            $view->addMod('geoloc', 'Planishpère');
-            $view->apply('search', $page, $action, $subaction);
-            
+            $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
+            $view->apply('search/adv', $page, $action, $subaction);
+
             if ($subaction) {
                 return;
             }
@@ -170,7 +199,7 @@ class SearchModule extends PLModule
                            $_REQUEST['q']);
         if (!$q) exit();
 
-        // try to look in cached results        
+        // try to look in cached results
         $cache = XDB::query('SELECT  `result`
                                FROM  `search_autocomplete`
                               WHERE  `name` = {?} AND
@@ -181,15 +210,16 @@ class SearchModule extends PLModule
             echo $res;
             die();
         }
-        
+
         // default search
+        $q = preg_quote($q);
         $unique = '`user_id`';
         $db = '`auth_user_md5`';
         $realid = false;
         $beginwith = true;
         $field2 = false;
         $qsearch = $q;
-        
+
         switch ($type) {
           case 'binetTxt':
             $db = '`binets_def` INNER JOIN
@@ -218,7 +248,7 @@ class SearchModule extends PLModule
             $field = '`entreprise`';
             $unique='`uid`';
             break;
-          case '`firstname`':
+          case 'firstname':
             $field = '`prenom`';
             $q = '(^|[ \\-])'.$q;
             $beginwith = false;
@@ -284,7 +314,7 @@ class SearchModule extends PLModule
             $beginwith = false;
             break;
           case 'sectionTxt':
-            $db = '`sections` INNER JOIN 
+            $db = '`sections` INNER JOIN
                    `auth_user_md5` ON(`auth_user_md5`.`section` = `sections`.`id`)';
             $field = '`sections`.`text`';
             $realid = '`sections`.`id`';
@@ -332,7 +362,7 @@ class SearchModule extends PLModule
         echo $res;
         exit();
     }
-    
+
     function handler_list(&$page, $type = null, $idVal = null)
     {
         // Give the list of all values possible of type and builds a select input for it
@@ -363,14 +393,15 @@ class SearchModule extends PLModule
             $db = '`groupesx_def`';
             break;
           case 'nationalite':
-            $db = '`geoloc_pays`';
+            $db = '`geoloc_pays` INNER JOIN
+                   `auth_user_md5` ON (`geoloc_pays`.`a2` = `auth_user_md5`.`nationalite`)';
             $field = 'IF(`nat`=\'\', `pays`, `nat`)';
             $id = '`a2`';
             break;
           case 'region':
             $db = '`geoloc_region`';
             $field = '`name`';
-            $id = '`region`'; 
+            $id = '`region`';
             if (isset($_REQUEST['country'])) {
                 $where .= ' WHERE `a2` = "'.$_REQUEST['country'].'"';
             }
@@ -395,11 +426,12 @@ class SearchModule extends PLModule
             exit();
         }
         header('Content-Type: text/xml; charset="UTF-8"');
-        $page->changeTpl('include/select.field.tpl', NO_SKIN);
+        $page->changeTpl('include/field.select.tpl', NO_SKIN);
         $page->assign('name', $type);
         $page->assign('list', XDB::iterator('SELECT  '.$field.' AS field,
                                                      '.$id.' AS id
                                                FROM  '.$db.$where.'
+                                           GROUP BY  '.$field.'
                                            ORDER BY  '.$field));
     }
 }