Close #656: PlSet and Ajax for mentor search
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 14 Apr 2007 09:48:58 +0000 (09:48 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 14 Apr 2007 09:48:58 +0000 (09:48 +0000)
Coding rules for search autocompletion

 ChangeLog                      |    3
 classes/plset.php              |    3
 include/userset.inc.php        |   25 ++
 modules/profile.php            |  159 +++++----------
 modules/search.php             |  415 +++++++++++++++++++----------------------
 templates/profile/referent.tpl |  143 +++++---------
 6 files changed, 338 insertions(+), 410 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1696 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
classes/plset.php
include/userset.inc.php
modules/profile.php
modules/search.php
templates/include/plview.referent.tpl [new file with mode: 0644]
templates/include/select.field.tpl [moved from templates/search/adv.list.form.tpl with 98% similarity]
templates/profile/referent.tpl

index eb687ab..1e37ccc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,6 +28,9 @@ New:
         - Add soundex search for quick search                              -FRU
         - Add autocompletion for advanced search                           -Car
 
+    * Survey:
+        - New module                                                       -PIK
+
     * Xnetgrp:
         - Direct access to the group forum (if exists)                     -FRU
 
index aa5bfa6..83322a6 100644 (file)
@@ -138,7 +138,8 @@ class PlSet
     {
         $view = strtolower($view);
         if (!$view || !class_exists($view . 'View') || !isset($this->mods[$view])) {
-            $view = $this->default ? $this->default : $this->mods[0];
+            reset($this->mods);
+            $view = $this->default ? $this->default : key($this->mods);
         }
         $this->mod = $view;
         $class = $view . 'View';
index f96ccfb..48d5878 100644 (file)
@@ -204,6 +204,31 @@ class MinificheView extends MultipageView
     }
 }
 
+class MentorView extends MultipageView
+{
+    public function __construct(PlSet &$set, $data, array $params)
+    {
+        $this->entriesPerPage = 10; 
+        $this->addSortKey('rand', array('RAND(' . S::i('uid') . ')'), 'aléatoirement');
+        $this->addSortKey('name', array('nom', 'prenom'), 'nom'); 
+        $this->addSortKey('promo', array('-promo', 'nom', 'prenom'), 'promotion'); 
+        $this->addSortKey('date', array('-watch_last', '-promo', 'nom', 'prenom'), 'dernière modification'); 
+        parent::__construct($set, $data, $params); 
+    }
+
+    public function fields()
+    {
+        return "m.uid, u.prenom, u.nom, u.promo,
+                a.alias AS bestalias, m.expertise, mp.pid,
+                ms.secteur, ms.ss_secteur";
+    }
+
+    public function templateName()
+    {
+        return 'include/plview.referent.tpl';
+    }
+}
+
 class TrombiView extends MultipageView
 {
     public function __construct(PlSet &$set, $data, array $params)
index 07dd95e..f766844 100644 (file)
@@ -36,6 +36,8 @@ class ProfileModule extends PLModule
 
             'referent'         => $this->make_hook('referent',   AUTH_COOKIE),
             'referent/search'  => $this->make_hook('ref_search', AUTH_COOKIE),
+            'referent/ssect'   => $this->make_hook('ref_sect',   AUTH_COOKIE, 'user', NO_AUTH),
+            'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH),
 
             'groupes-x'        => $this->make_hook('xnet',      AUTH_COOKIE),
 
@@ -57,30 +59,6 @@ class ProfileModule extends PLModule
         return $this->handler_profile($page, Env::v('user'));
     }
 
-
-    function _trombi_getlist($offset, $limit)
-    {
-        $where  = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" );
-
-        $res = XDB::query(
-                "SELECT  COUNT(*)
-                   FROM  auth_user_md5 AS u
-             RIGHT JOIN  photo         AS p ON u.user_id=p.uid
-             $where");
-        $pnb = $res->fetchOneCell();
-
-        $res = XDB::query(
-                "SELECT  promo, user_id, a.alias AS forlife,
-                         IF (nom_usage='', nom, nom_usage) AS nom, prenom
-                   FROM  photo         AS p
-             INNER JOIN  auth_user_md5 AS u ON u.user_id=p.uid
-             INNER JOIN  aliases       AS a ON ( u.user_id=a.id AND a.type='a_vie' )
-                  $where
-               ORDER BY  promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit);
-
-        return array($pnb, $res->fetchAllAssoc());
-    }
-
     function handler_photo(&$page, $x = null, $req = null)
     {
         if (is_null($x)) {
@@ -513,22 +491,10 @@ class ProfileModule extends PLModule
         $page->addJsLink('close_on_esc.js');
     }
 
-    function handler_ref_search(&$page)
+    function handler_ref_search(&$page, $action = null, $subaction = null)
     {
-        $page->changeTpl('profile/referent.tpl');
-
         $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro');
 
-        $secteur_sel     = Post::v('secteur');
-        $ss_secteur_sel  = Post::v('ss_secteur');
-        $pays_sel        = Post::v('pays', '00');
-        $expertise_champ = Post::v('expertise');
-
-        $page->assign('pays_sel', $pays_sel);
-        $page->assign('expertise_champ', $expertise_champ);
-        $page->assign('secteur_sel', $secteur_sel);
-        $page->assign('ss_secteur_sel', $ss_secteur_sel);
-
         //recuperation des noms de secteurs
         $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
         $secteurs[''] = '';
@@ -537,92 +503,73 @@ class ProfileModule extends PLModule
         }
         $page->assign_by_ref('secteurs', $secteurs);
 
-        //on recupere les sous-secteurs si necessaire
-        $ss_secteurs[''] = '';
-        if (!empty($secteur_sel)) {
-            $res = XDB::iterRow("SELECT id, label FROM emploi_ss_secteur
-                                          WHERE secteur = {?}", $secteur_sel);
-            while (list($tmp_id, $tmp_label) = $res->next()) {
-                $ss_secteurs[$tmp_id] = $tmp_label;
-            }
-        }
-        $page->assign_by_ref('ss_secteurs', $ss_secteurs);
-
-        //recuperation des noms de pays
-        $res = XDB::iterRow("SELECT a2, pays FROM geoloc_pays
-                                      WHERE pays <> '' ORDER BY pays");
-        $pays['00'] = '';
-        while (list($tmp_id, $tmp_label) = $res->next()) {
-            $pays[$tmp_id] = $tmp_label;
-        }
-        $page->assign_by_ref('pays', $pays);
-
         // nb de mentors
         $res = XDB::query("SELECT count(*) FROM mentor");
         $page->assign('mentors_number', $res->fetchOneCell());
 
-        if (!Env::has('Chercher')) {
-            return;
-        }
-
         // On vient d'un formulaire
-        $where = array();
-
-        if ($pays_sel != '00') {
-            $where[] = "mp.pid = '".addslashes($pays_sel)."'";
-        }
-        if ($secteur_sel) {
-            $where[] = "ms.secteur = '".addslashes($secteur_sel)."'";
-            if ($ss_secteur_sel) {
-                $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'";
+        $where           = array();
+        $pays_sel        = XDB::escape(Env::v('pays_sel'));
+        $secteur_sel     = XDB::escape(Env::v('secteur'));
+        $ss_secteur_sel  = XDB::escape(Env::v('ss_secteur'));
+        $expertise_champ = XDB::escape(Env::v('expertise'));
+
+        if ($pays_sel != "''") {
+            $where[] = "mp.pid = $pays_sel";
+        }
+        if ($secteur_sel != "''") {
+            $where[] = "ms.secteur = $secteur_sel";
+            if ($ss_secteur_sel != "''") {
+                $where[] = "ms.ss_secteur = $ss_secteur_sel";
             }
         }
-        if ($expertise_champ) {
-            $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')";
+        if ($expertise_champ != "''") {
+            $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
         }
 
         if ($where) {
             $where = join(' AND ', $where);
 
-            $sql = "SELECT  m.uid, a.prenom, a.nom, a.promo,
-                            l.alias AS bestalias, m.expertise, mp.pid,
-                            ms.secteur, ms.ss_secteur
-                      FROM  mentor        AS m
-                 LEFT JOIN  auth_user_md5 AS a ON(m.uid = a.user_id)
-                INNER JOIN  aliases       AS l ON (a.user_id=l.id AND
-                                                   FIND_IN_SET('bestalias', l.flags))
-                 LEFT JOIN  mentor_pays   AS mp ON(m.uid = mp.uid)
-                 LEFT JOIN  mentor_secteurs AS ms ON(m.uid = ms.uid)
-                     WHERE  $where
-                  GROUP BY  uid
-                  ORDER BY  RAND({?})";
-            $res = XDB::iterator($sql, S::v('uid'));
-
-            if ($res->total() == 0) {
-                $page->assign('recherche_trop_large', true);
-                return;
+            $set = new UserSet("INNER JOIN  mentor          AS m ON (m.uid = u.user_id) 
+                                 LEFT JOIN  mentor_pays     AS mp ON (mp.uid = m.uid) 
+                                 LEFT JOIN  mentor_secteurs AS ms ON (ms.uid = m.uid)",
+                               $where);
+            $set->addMod('mentor', 'Référents');
+            $set->apply('referent/search', $page, $action, $subaction);
+            if ($set->count() > 100) {
+                $page->assign('recherche_trop_large', true); 
             }
+        }
+        $page->changeTpl('profile/referent.tpl'); 
+    }
 
-            $nb_max_res_total = 100;
-            $nb_max_res_ppage = 10;
-
-            $curpage   = Env::i('curpage', 1);
-            $personnes = array();
-            $i         = 0;
-
-            while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) {
-                $the_page = intval($i / $nb_max_res_ppage) + 1;
-                if ($the_page == $curpage) {
-                    $personnes[] = $pers;
-                }
-                $i ++;
-            }
+    function handler_ref_sect(&$page, $sect) 
+    {
+        header('Content-Type: text/html; charset=utf-8');
+        $page->changeTpl('include/select.field.tpl', NO_SKIN);
+        $page->assign('onchange', 'setSSecteurs()');
+        $page->assign('id', 'ssect_field');
+        $page->assign('name', 'ss_secteur');
+        $it = XDB::iterator("SELECT  id,label AS field
+                               FROM  emploi_ss_secteur 
+                              WHERE  secteur = {?}", $sect);
+        $page->assign('list', $it);
+    }
 
-            $page->assign('personnes', $personnes);
-            $page->assign('curpage',   $curpage);
-            $page->assign('nb_pages_total',
-                          intval($res->total() / $nb_max_res_ppage) + 1);
-        }
+    function handler_ref_country(&$page, $sect, $ssect = '')
+    {
+        header('Content-Type: text/html; charset=utf-8');
+        $page->changeTpl('include/select.field.tpl', NO_SKIN);
+        $page->assign('name', 'pays_sel');
+        $where = ($ssect ? ' AND ms.ss_secteur = {?}' : '');
+        $it = XDB::iterator("SELECT  a2 AS id, pays AS field
+                              FROM  geoloc_pays AS g
+                        INNER JOIN  mentor_pays AS mp ON (mp.pid = g.a2)
+                        INNER JOIN  mentor_secteurs AS ms ON (ms.uid = mp.uid)
+                             WHERE  ms.secteur = {?} $where
+                          GROUP BY  a2
+                          ORDER BY  pays", $sect, $ssect);
+        $page->assign('list', $it);
     }
 
     function handler_p_usage(&$page)
index e54df37..ea8491a 100644 (file)
@@ -161,30 +161,25 @@ class SearchModule extends PLModule
         //   result2|nb2
         //   ...
         header('Content-Type: text/plain; charset="UTF-8"');
-        $q = preg_replace(
-                                               array(
-                                                               '/\*+$/', // always look for $q*
-                                                               '/([\^\$\[\]])/', // escape special regexp char
-                                                               '/\*/'), // replace joker by regexp joker
-                                               array(
-                                                               '',
-                                                               '\\\\\1',
-                                                               '.*'),
-                                               $_REQUEST['q']);
+        $q = preg_replace(array('/\*+$/', // always look for $q*
+                                '/([\^\$\[\]])/', // escape special regexp char
+                                '/\*/'), // replace joker by regexp joker
+                           array('',
+                                 '\\\\\1',
+                                 '.*'),
+                           $_REQUEST['q']);
         if (!$q) exit();
 
-                               // try to look in cached results        
-        $cache = XDB::query('
-                                               SELECT `result`
-                                               FROM `search_autocomplete`
-                                               WHERE
-                                                               `name` = {?} AND
-                                                               `query` = {?} AND
-                                                               `generated` > NOW() - INTERVAL 1 DAY',
-                       $type, $q);
+        // try to look in cached results        
+        $cache = XDB::query('SELECT  `result`
+                               FROM  `search_autocomplete`
+                              WHERE  `name` = {?} AND
+                                     `query` = {?} AND
+                                     `generated` > NOW() - INTERVAL 1 DAY',
+                             $type, $q);
         if ($res = $cache->fetchOneCell()) {
-                       echo $res;
-                       die();
+            echo $res;
+            die();
         }
         
         // default search
@@ -196,131 +191,126 @@ class SearchModule extends PLModule
         $qsearch = $q;
         
         switch ($type) {
-        case 'binetTxt':
-                                               $db = '`binets_def` INNER JOIN
-                                                               `binets_ins` ON(`binets_def`.`id` = `binets_ins`.`binet_id`)';
-                                               $field='`binets_def`.`text`';
-                                               if (strlen($q) > 2)
-                                                               $beginwith = false;
-                                               $realid = '`binets_def`.`id`';
-                                               break;
-        case 'city':
-                                               $db = '`geoloc_city` INNER JOIN
-                                                               `adresses` ON(`geoloc_city`.`id` = `adresses`.`cityid`)';
-                                               $unique='`uid`';
-                                               $field='`geoloc_city`.`name`';
-                                               break;
-        case 'countryTxt':
-                                               $db = '`geoloc_pays` INNER JOIN
-                                                               `adresses` ON(`geoloc_pays`.`a2` = `adresses`.`country`)';
-                                               $unique='`uid`';
-                                               $field = '`geoloc_pays`.`pays`';
-                                               $field2 = '`geoloc_pays`.`country`';
-                                               $realid='`geoloc_pays`.`a2`';
-                                               break;
-        case 'entreprise':
-                                               $db = '`entreprises`';
-                                               $field = '`entreprise`';
-                                               $unique='`uid`';
-                                               break;
-        case '`firstname`':
-                                               $field = '`prenom`';
-                                               $q = '(^|[ \\-])'.$q;
-                                               $beginwith = false;
-                                               break;
-        case 'fonctionTxt':
-                       $db = '`fonctions_def` INNER JOIN
-                                                               `entreprises` ON(`entreprises`.`fonction` = `fonctions_def`.`id`)';
-                       $field = '`fonction_fr`';
-                       $unique = '`uid`';
-                       $realid = '`fonctions_def`.`id`';
-                                               $qsearch = '(^|[ /\\-])'.$q;
-                                               $beginwith = false;
-                       break;
-        case 'groupexTxt':
-                                               $db = '`groupesx_def` INNER JOIN
-                                                               `groupesx_ins` ON(`groupesx_def`.`id` = `groupesx_ins`.`gid`)';
-                                               $field='`groupesx_def`.`text`';
-                                               if (strlen($q) > 2)
-                                                               $beginwith = false;
-                                               $realid = '`groupesx_def`.`id`';
-                                               $unique = '`guid`';
-                                               break;
-        case 'name':
-                                               $field = '`nom`';
-                                               $field2 = '`nom_usage`';
-                                               $qsearch = '(^|[ \\-])'.$q;
-                                               $beginwith = false;
-                                               break;
-               case 'nationaliteTxt':
-                               $db = '`geoloc_pays` INNER JOIN
-                                                               `auth_user_md5` ON(`geoloc_pays`.`a2` = `auth_user_md5`.`nationalite`)';
-                               $field = 'IF(`geoloc_pays`.`nat`=\'\',
-                                                               `geoloc_pays`.`pays`,
-                                                               `geoloc_pays`.`nat`)';
-                               $realid = '`geoloc_pays`.`a2`';
-                               break;
-        case 'nickname':
-                                               $field = '`profile_nick`';
-                                               $db = '`auth_user_quick`';
-                                               $qsearch = '(^|[ \\-])'.$q;
-                                               $beginwith = false;
-                                               break;
-        case 'poste':
-                                               $db = '`entreprises`';
-                                               $field = '`poste`';
-                                               $unique='`uid`';
-                                               break;
-                               case 'schoolTxt':
-                                               $db = '`applis_def` INNER JOIN
-                                                               `applis_ins` ON(`applis_def`.`id` = `applis_ins`.`aid`)';
-                                               $field='`applis_def`.`text`';
-                                               $unique = '`uid`';
-                                               $realid = '`applis_def`.`id`';
-                                               if (strlen($q) > 2)
-                                                               $beginwith = false;
-                                               break;
-               case 'secteurTxt':
-                               $db = '`emploi_secteur` INNER JOIN
-                                                               `entreprises` ON(`entreprises`.`secteur` = `emploi_secteur`.`id`)';
-                               $field = '`emploi_secteur`.`label`';
-                               $realid = '`emploi_secteur`.`id`';
-                               $unique = '`uid`';
-                                               $beginwith = false;
-                               break;
-               case 'sectionTxt':
-                               $db = '`sections` INNER JOIN 
-                                                               `auth_user_md5` ON(`auth_user_md5`.`section` = `sections`.`id`)';
-                               $field = '`sections`.`text`';
-                               $realid = '`sections`.`id`';
-                                               $beginwith = false;
-                               break;
-        default: exit();
+          case 'binetTxt':
+            $db = '`binets_def` INNER JOIN
+                   `binets_ins` ON(`binets_def`.`id` = `binets_ins`.`binet_id`)';
+            $field='`binets_def`.`text`';
+            if (strlen($q) > 2)
+                $beginwith = false;
+            $realid = '`binets_def`.`id`';
+            break;
+          case 'city':
+            $db = '`geoloc_city` INNER JOIN
+                   `adresses` ON(`geoloc_city`.`id` = `adresses`.`cityid`)';
+            $unique='`uid`';
+            $field='`geoloc_city`.`name`';
+            break;
+          case 'countryTxt':
+            $db = '`geoloc_pays` INNER JOIN
+                   `adresses` ON(`geoloc_pays`.`a2` = `adresses`.`country`)';
+            $unique='`uid`';
+            $field = '`geoloc_pays`.`pays`';
+            $field2 = '`geoloc_pays`.`country`';
+            $realid='`geoloc_pays`.`a2`';
+            break;
+          case 'entreprise':
+            $db = '`entreprises`';
+            $field = '`entreprise`';
+            $unique='`uid`';
+            break;
+          case '`firstname`':
+            $field = '`prenom`';
+            $q = '(^|[ \\-])'.$q;
+            $beginwith = false;
+            break;
+          case 'fonctionTxt':
+            $db = '`fonctions_def` INNER JOIN
+                   `entreprises` ON(`entreprises`.`fonction` = `fonctions_def`.`id`)';
+            $field = '`fonction_fr`';
+            $unique = '`uid`';
+            $realid = '`fonctions_def`.`id`';
+            $qsearch = '(^|[ /\\-])'.$q;
+            $beginwith = false;
+            break;
+          case 'groupexTxt':
+            $db = '`groupesx_def` INNER JOIN
+                   `groupesx_ins` ON(`groupesx_def`.`id` = `groupesx_ins`.`gid`)';
+            $field='`groupesx_def`.`text`';
+            if (strlen($q) > 2)
+                $beginwith = false;
+            $realid = '`groupesx_def`.`id`';
+            $unique = '`guid`';
+            break;
+          case 'name':
+            $field = '`nom`';
+            $field2 = '`nom_usage`';
+            $qsearch = '(^|[ \\-])'.$q;
+            $beginwith = false;
+            break;
+          case 'nationaliteTxt':
+            $db = '`geoloc_pays` INNER JOIN
+                   `auth_user_md5` ON(`geoloc_pays`.`a2` = `auth_user_md5`.`nationalite`)';
+            $field = 'IF(`geoloc_pays`.`nat`=\'\',
+                                       `geoloc_pays`.`pays`,
+                                       `geoloc_pays`.`nat`)';
+            $realid = '`geoloc_pays`.`a2`';
+            break;
+          case 'nickname':
+            $field = '`profile_nick`';
+            $db = '`auth_user_quick`';
+            $qsearch = '(^|[ \\-])'.$q;
+            $beginwith = false;
+            break;
+          case 'poste':
+            $db = '`entreprises`';
+            $field = '`poste`';
+            $unique='`uid`';
+            break;
+          case 'schoolTxt':
+            $db = '`applis_def` INNER JOIN
+                   `applis_ins` ON(`applis_def`.`id` = `applis_ins`.`aid`)';
+            $field='`applis_def`.`text`';
+            $unique = '`uid`';
+            $realid = '`applis_def`.`id`';
+            if (strlen($q) > 2)
+                $beginwith = false;
+            break;
+          case 'secteurTxt':
+            $db = '`emploi_secteur` INNER JOIN
+                   `entreprises` ON(`entreprises`.`secteur` = `emploi_secteur`.`id`)';
+            $field = '`emploi_secteur`.`label`';
+            $realid = '`emploi_secteur`.`id`';
+            $unique = '`uid`';
+            $beginwith = false;
+            break;
+          case 'sectionTxt':
+            $db = '`sections` INNER JOIN 
+                   `auth_user_md5` ON(`auth_user_md5`.`section` = `sections`.`id`)';
+            $field = '`sections`.`text`';
+            $realid = '`sections`.`id`';
+            $beginwith = false;
+            break;
+          default: exit();
         }
 
-                               $field_select = $field;
-                               if ($field2) {
-                                               $field_select = 'IF('.$field.' REGEXP {?}, '.$field.', '.$field2.')';
-                               }
-                               
-                               if ($beginwith) {
-                                               $qsearch = '^'.$qsearch;
-                               }
-        $list = XDB::iterator('
-                                               SELECT
-                                                               '.$field_select.' AS field,
-                                                               COUNT(DISTINCT '.$unique.') AS nb
-                                                               '.($realid?(', '.$realid.' AS id'):'').'
-                                               FROM '.$db.'
-                                               WHERE '.$field.' REGEXP {?}'.
-                                               ($field2?(' OR '.$field2.' REGEXP {?}'):'').'
-                                               GROUP BY '.$field_select.'
-                                               ORDER BY nb DESC
-                                               LIMIT 11',
-                                               $qsearch, 
-                                               $qsearch,
-                                               $qsearch,
-                                               $qsearch);
+        $field_select = $field;
+        if ($field2) {
+            $field_select = 'IF('.$field.' REGEXP {?}, '.$field.', '.$field2.')';
+        }
+
+        if ($beginwith) {
+            $qsearch = '^'.$qsearch;
+        }
+        $list = XDB::iterator('SELECT  '.$field_select.' AS field,
+                                       COUNT(DISTINCT '.$unique.') AS nb
+                                       '.($realid?(', '.$realid.' AS id'):'').'
+                                 FROM  '.$db.'
+                                WHERE  '.$field.' REGEXP {?}'.
+                                        ($field2?(' OR '.$field2.' REGEXP {?}'):'').'
+                             GROUP BY  '.$field_select.'
+                             ORDER BY  nb DESC
+                                LIMIT  11',
+                               $qsearch, $qsearch, $qsearch, $qsearch);
         $nbResults = 0;
         $res = "";
         while ($result = $list->next()) {
@@ -329,91 +319,88 @@ class SearchModule extends PLModule
                 $res .= '...|1'."\n";
             } else {
                 $res .= $result['field'].'|';
-                                                               $res .= $result['nb'];
-                                                               if (isset($result['id'])) {
-                                                                               $res  .= '|'.$result['id'];
-                                                               }
-                                                               $res .= "\n";
+                $res .= $result['nb'];
+                if (isset($result['id'])) {
+                    $res  .= '|'.$result['id'];
+                }
+                $res .= "\n";
             }
         }
-        XDB::query('
-                                               REPLACE INTO `search_autocomplete`
-                                               VALUES ({?}, {?}, {?}, NOW())',
-                       $type, $q, $res);
+        XDB::query('REPLACE INTO  `search_autocomplete`
+                          VALUES  ({?}, {?}, {?}, NOW())',
+                    $type, $q, $res);
         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
-                               $field = '`text`';
-                               $id = '`id`';
-                               $where = '';
-                               
-               switch ($type) {
-               case 'binet':
-                               $db = '`binets_def`';
-                               break;
-               case 'country':
-                               $db = '`geoloc_pays`';
-                               $field = '`pays`';
-                               $id = '`a2`';
-                       $page->assign('onchange', 'changeCountry(this.value)');
-                               break;
-               case 'fonction':
-                               $db = '`fonctions_def`';
-                               $field = '`fonction_fr`';
-                               break;
-               case 'diploma':
+        // Give the list of all values possible of type and builds a select input for it
+        $field = '`text`';
+        $id = '`id`';
+        $where = '';
+
+        switch ($type) {
+          case 'binet':
+            $db = '`binets_def`';
+            break;
+          case 'country':
+            $db = '`geoloc_pays`';
+            $field = '`pays`';
+            $id = '`a2`';
+            $page->assign('onchange', 'changeCountry(this.value)');
+            break;
+          case 'fonction':
+            $db = '`fonctions_def`';
+            $field = '`fonction_fr`';
+            break;
+          case 'diploma':
             header('Content-Type: text/xml; charset="UTF-8"');
-                   $this->get_diplomas();
-                   $page->changeTpl('search/adv.grade.form.tpl', NO_SKIN);
-                   return;
-               case 'groupex':
-                               $db = '`groupesx_def`';
-                               break;
-               case 'nationalite':
-                               $db = '`geoloc_pays`';
-                               $field = 'IF(`nat`=\'\', `pays`, `nat`)';
-                               $id = '`a2`';
-                               break;
-               case 'region':
-                   $db = '`geoloc_region`';
-                   $field = '`name`';
+            $this->get_diplomas();
+            $page->changeTpl('search/adv.grade.form.tpl', NO_SKIN);
+            return;
+          case 'groupex':
+            $db = '`groupesx_def`';
+            break;
+          case 'nationalite':
+            $db = '`geoloc_pays`';
+            $field = 'IF(`nat`=\'\', `pays`, `nat`)';
+            $id = '`a2`';
+            break;
+          case 'region':
+            $db = '`geoloc_region`';
+            $field = '`name`';
             $id = '`region`'; 
             if (isset($_REQUEST['country'])) {
                 $where .= ' WHERE `a2` = "'.$_REQUEST['country'].'"';
             }
-                   break;
-               case 'school':
-                               $db = '`applis_def`';
-                       $page->assign('onchange', 'changeSchool(this.value)');
-                               break;
-               case 'section':
-                               $db = '`sections`';
-                               break;
-               case 'secteur':
-                               $db = '`emploi_secteur`';
-                               $field = '`label`';
-                               break;
-               default: exit();
-               }
-               if (isset($idVal)) {
-                               header('Content-Type: text/plain; charset="UTF-8"');
-                               $result = XDB::query('SELECT '.$field.' AS field FROM '.$db.' WHERE '.$id.' = {?} LIMIT 1',$idVal);
-                               echo $result->fetchOneCell();
-                               exit();
-               }
+            break;
+          case 'school':
+            $db = '`applis_def`';
+            $page->assign('onchange', 'changeSchool(this.value)');
+            break;
+          case 'section':
+            $db = '`sections`';
+            break;
+          case 'secteur':
+            $db = '`emploi_secteur`';
+            $field = '`label`';
+            break;
+          default: exit();
+        }
+        if (isset($idVal)) {
+            header('Content-Type: text/plain; charset="UTF-8"');
+            $result = XDB::query('SELECT '.$field.' AS field FROM '.$db.' WHERE '.$id.' = {?} LIMIT 1',$idVal);
+            echo $result->fetchOneCell();
+            exit();
+        }
         header('Content-Type: text/xml; charset="UTF-8"');
-        $page->changeTpl('search/adv.list.form.tpl', NO_SKIN);
+        $page->changeTpl('include/select.field.tpl', NO_SKIN);
         $page->assign('name', $type);
-               $page->assign('list', XDB::iterator('
-                               SELECT
-                                               '.$field.' AS field,
-                                               '.$id.' AS id
-                               FROM '.$db.$where.'
-                               ORDER BY '.$field));
+        $page->assign('list', XDB::iterator('SELECT  '.$field.' AS field,
+                                                     '.$id.' AS id
+                                               FROM  '.$db.$where.'
+                                           ORDER BY  '.$field));
     }
 }
 
diff --git a/templates/include/plview.referent.tpl b/templates/include/plview.referent.tpl
new file mode 100644 (file)
index 0000000..60190e3
--- /dev/null
@@ -0,0 +1,51 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<div class="contact-list" style="clear: both">
+{iterate from=$set item=p} 
+  <div class="contact"> 
+    <div class="nom"> 
+      {$p.nom} {$p.prenom} 
+    </div> 
+    <div class="appli"> 
+      X{$p.promo} 
+    </div> 
+    <div class="bits" style="width: 40%;"> 
+      <span class='smaller'> 
+      <a href="profile/{$p.bestalias}" class="popup2"> 
+        {icon name=user_suit title="Voir sa fiche"}</a> - 
+        <a href="referent/{$p.bestalias}" class="popup2">Voir sa fiche référent</a> 
+      </span> 
+    </div> 
+    <div class="long"> 
+     <table cellspacing="0" cellpadding="0"> 
+      <tr> 
+        <td class="lt">Expertise :</td> 
+        <td class="rt" colspan="2">{$p.expertise|nl2br}</td> 
+      </tr> 
+     </table> 
+    </div> 
+  </div> 
+{/iterate}
+</div>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
similarity index 98%
rename from templates/search/adv.list.form.tpl
rename to templates/include/select.field.tpl
index 504d29b..51a99be 100644 (file)
@@ -20,7 +20,7 @@
 {*                                                                        *}
 {**************************************************************************}
 
-<select name="{$name}"{if $onchange} onchange="{$onchange}"{/if}>
+<select name="{$name}"{if $onchange} onchange="{$onchange}"{/if}{if $id} id="{$id}"{/if}>
     <option value=""> - </option>
   {iterate from=$list item='option'}
     <option value="{$option.id}">{$option.field|htmlspecialchars}</option>
index d7f6dbb..a7397ab 100644 (file)
 {**************************************************************************}
 
 
-{literal}
-<script type="text/javascript">
-  <!-- Begin
-  function showPage(pNumber) {
-    document.forms.form_result.curpage.value = pNumber;
-    document.forms.form_result.submit();
-  }
-  // End -->
-</script>
-{/literal}
-
-<h1>
-  Rechercher un camarade pouvant m'aider à orienter mon parcours professionnel
-</h1>
-{if $recherche_trop_large}
-<p>
-Les critères de recherche que tu as rentrés n'ont pas produit de résultats,
-sans doute car ta requête était trop générale. Nous t'invitons à
-<a href="referent/search">procéder à une nouvelle recherche</a>, en essayant
-d'être plus précis.
-</p>
-{elseif $personnes}
-<div class="contact-list" style="clear:both" >
-{foreach from=$personnes item=p}
-  <div class="contact">
-    <div class="nom">
-      {$p.nom} {$p.prenom}
-    </div>
-    <div class="appli">
-      X{$p.promo}
-    </div>
-    <div class="bits" style="width: 40%;">
-      <span class='smaller'>
-      <a href="profile/{$p.bestalias}" class="popup2">
-        {icon name=user_suit title="Voir sa fiche"}</a> -
-        <a href="referent/{$p.bestalias}" class="popup2">Voir sa fiche référent</a>
-      </span>
-    </div>
-    <div class="long">
-     <table cellspacing="0" cellpadding="0">
-      <tr>
-        <td class="lt">Expertise :</td>
-        <td class="rt" colspan="2">{$p.expertise|nl2br}</td>
-      </tr>
-     </table>
-    </div>
-  </div>
-{/foreach}
-</div>
-<form action="referent/search" method="post" id="form_result">
-  <p>
-    <input type="hidden" name="secteur"    value="{$secteur_sel}" />
-    <input type="hidden" name="ss_secteur" value="{$ss_secteur_sel}" />
-    <input type="hidden" name="pays"       value="{$pays_sel}" />
-    <input type="hidden" name="expertise"  value="{$expertise_champ}" />
-    <input type="hidden" name="curpage"    value="{$curpage}" />
-    <input type="hidden" name="Chercher"   value="1" />
+{if $plset_count}
+{include file="core/plset.tpl"}
+{else}
+<h1> 
+  Rechercher un camarade pouvant m'aider à orienter mon parcours professionnel 
+</h1> 
 
-    Pages&nbsp;:&nbsp;
-    {section name="page_number" start=1 loop=$nb_pages_total+1}
-    {if $smarty.section.page_number.index == $curpage}
-    {$curpage} {else}
-    <a href="javascript:showPage({$smarty.section.page_number.index})">{$smarty.section.page_number.index} </a> 
-    {/if}
-    {/section}
-  </p>
-</form>
+{if $recherche_trop_large} 
+<p> 
+Les critères de recherche que tu as rentrés n'ont pas produit de résultats, 
+sans doute car ta requête était trop générale.
+</p> 
 {else}
-<span class="erreur">
+<p class="erreur">
   Si tu utilises ce service pour la première fois, lis attentivement le texte
   qui suit.
-</span>
+</p>
 <p>
 En <a href="profile/edit">renseignant sa fiche dans l'annuaire</a>, chacun
 d'entre nous a la possibilité de renseigner, dans la section "Mentoring",
@@ -133,49 +78,71 @@ une recherche par mots-clefs.<br />
 Nous t'incitons à prendre plutôt 2 ou 3 contacts qu'un seul, cela te
 permettant certainement d'avoir une vision des choses plus complète.
 </p>
+{/if}
+{/if}
 
 <p>
 Actuellement, {$mentors_number} mentors et référents se sont déclarés sur {#globals.core.sitename#}.
 </p>
 
-<form action="{$smarty.server.REQUEST_URI}" method="post">
+{javascript name=ajax}
+<script type="text/javascript">//<![CDATA[
+{literal}
+
+var Ajax2 = new AjaxEngine();
+
+function setSecteur(secteur)
+{
+    if (secteur == '') {
+        document.getElementById('scat').style.display = 'none';
+        document.getElementById('country').style.display = 'none';
+        document.getElementById('keywords').style.display = 'none';
+    } else {
+        Ajax.update_html('ssect_chg', 'referent/ssect/' + secteur);
+        Ajax2.update_html('country_chg', 'referent/country/' + secteur);
+        document.getElementById('scat').style.display = ''; 
+        document.getElementById('country').style.display = ''; 
+        document.getElementById('keywords').style.display = ''; 
+    }
+}
+
+function setSSecteurs()
+{
+    var sect  = document.getElementById('sect_field').value;
+    var ssect = document.getElementById('ssect_field').value;
+    Ajax2.update_html('country_chg', 'referent/country/' + sect + '/' + ssect);
+}
+
+{/literal}
+//]]></script>
+
+<form action="{$smarty.server.REQUEST_URI}" method="get">
   <table cellpadding="0" cellspacing="0" summary="Formulaire de recherche de referents" class="bicol">
     <tr class="impair">
       <td class="titre">
         Secteur de compétence <br /> du référent
       </td>
-      <td >
-        <select name="secteur" onchange="javascript:submit()">
+      <td>
+        <select name="secteur" id="sect_field" onchange="setSecteur(this.value)">
           {html_options options=$secteurs selected=$secteur_sel}
         </select>
       </td>
     </tr>
-    <tr class="pair">
+    <tr class="impair" style="display: none" id="scat">
       <td class="titre">
         Sous-Secteur
       </td>
-      <td >
-        <select name="ss_secteur">
-          {html_options options=$ss_secteurs selected=$ss_secteur_sel}
-        </select>
+      <td id="ssect_chg">
       </td>
     </tr>
-    <tr class="impair">
+    <tr class="pair" style="display: none" id="country">
       <td class="titre">
         Pays bien connu du référent
       </td>
-      <td >
-        <select name="pays">
-          {html_options options=$pays selected=$pays_sel}
-        </select>
-      </td>
-    </tr>
-    <tr class="pair">
-      <td colspan="2">
-        &nbsp;
+      <td id="country_chg">
       </td>
     </tr>
-    <tr class="impair">
+    <tr class="impair" style="display: none" id="keywords">
       <td class="titre">
         Expertise (rentre un ou plusieurs mots clés)
       </td>
@@ -189,6 +156,4 @@ Actuellement, {$mentors_number} mentors et référents se sont déclarés sur {#
   </div>
 </form>
 
-{/if}
-
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}