remove fail() that is not used
[platal.git] / include / search.inc.php
index d40856b..296eaa1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 require_once('xorg.plugin.inc.php');
 require_once("search/classes.inc.php");
 
+// {{{ function advancedSearchFromInput
+function getadr_join($table) {
+    return 'u.user_id='.$table.'.uid'.(Env::get('only_current',false)?' AND FIND_IN_SET(\'active\','.$table.'.statut)':'');
+}
+function advancedSearchFromInput()
+{
+    if ($with_soundex = Env::has('with_soundex')) {
+        $nameField      = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule');
+        $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule');
+    } else {
+        $nameField      = new NameSField('name',array('u.nom','u.nom_usage'),'');
+        $firstnameField = new StringSField('firstname',array('u.prenom'),'');
+    }
+    $nicknameField   = new StringSField('nickname',array('q.profile_nick'),'');
+    
+    $promo1Field     = new PromoSField('promo1','egal1',array('u.promo'),'');
+    $promo2Field     = new PromoSField('promo2','egal2',array('u.promo'),'');
+    $womanField      = new RefSField('woman',array('FIND_IN_SET(u.flags,\'femme\')+1'),'','','');
+    $subscriberField = new RefSField('subscriber',array('!(u.perms IN (\'admin\',\'user\'))+1'),'','','');
+    $aliveField      = new RefSField('alive',array('(u.deces!=0)+1'),'','','');
+
+    $townField      = new RefSField('city',array('ac.city'),'adresses','ac',getadr_join('ac'),false);
+    $cityIdField    = new RefSField('cityid',array('av.cityid'),'adresses','av',getadr_join('av'));
+    $countryField   = new RefSField('country',array('ap.country'),'adresses','ap',getadr_join('ap'));
+    $regionField    = new RefSField('region',array('ar.region'),'adresses','ar',getadr_join('ar'));
+    $mapField       = new MapSField('mapid', array('gcim.map_id'), array('adresses','geoloc_city_in_maps'), array('am','gcim'), array(getadr_join('am'), 'am.cityid = gcim.city_id'));
+   
+    $entrepriseField = new RefSField('entreprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid',false);
+    $posteField      = new RefSField('poste',array('ep.poste'),'entreprises','ep','u.user_id=ep.uid', false);
+    $fonctionField   = new RefSField('fonction',array('en.fonction'),'entreprises','en','u.user_id=en.uid');
+    $secteurField    = new RefSField('secteur',array('fm.secteur'),'entreprises','fm','u.user_id=fm.uid');
+    $cvField         = new RefSField('cv',array('u.cv'),'','','',false);
+   
+    $natField        = new RefSField('nationalite',array('u.nationalite'),'','','');
+    $binetField      = new RefSField('binet',array('b.binet_id'),'binets_ins','b','u.user_id=b.user_id');
+    $groupexField    = new RefSField('groupex',array('g.gid'),'groupesx_ins','g','u.user_id=g.guid');
+    $sectionField    = new RefSField('section',array('u.section'),'','','');
+    $schoolField     = new RefSField('school',array('as.aid'),'applis_ins','`as`','u.user_id=as.uid');
+    $diplomaField    = new RefSField('diploma',array('ad.type'),'applis_ins','ad','u.user_id=ad.uid');
+  
+    $freeField       = new RefSField('free',array('q.profile_freetext'),'','','',false);
+  
+    return array( 
+                $nameField, $firstnameField, $nicknameField, $promo1Field,
+                $promo2Field, $womanField, $subscriberField, $aliveField,
+                $townField, $countryField, $regionField, $entrepriseField,
+                $posteField, $secteurField, $cvField, $natField, $binetField,
+                $groupexField, $sectionField, $schoolField, $diplomaField,
+                $freeField, $fonctionField, $cityIdField, $mapField);
+}
+
+// }}}
+
 // {{{ class XOrgSearch
 
 class XOrgSearch extends XOrgPlugin
@@ -51,11 +104,11 @@ class XOrgSearch extends XOrgPlugin
     {
         foreach ($this->orders as $key=>$o) {
             if ($o[3] == AUTH_COOKIE) {
-                $this->orders[$key][3] = logged();
+                $this->orders[$key][3] = S::logged();
             } elseif ($o[3] == AUTH_PUBLIC) {
                 $this->orders[$key][3] = true;
             } else {
-                $this->orders[$key][3] = identified();
+                $this->orders[$key][3] = S::identified();
             }
         }
     }
@@ -98,7 +151,7 @@ class XOrgSearch extends XOrgPlugin
         list($list, $total) = call_user_func($this->_callback, $offset, $this->limit, $sql_order);
         
        $page_max = intval(($total-1)/$this->limit);
-        if(!logged() && $page_max > $globals->search->public_max)
+        if(!S::logged() && $page_max > $globals->search->public_max)
             $page_max = $globals->search->public_max;
 
        $links = Array();