autocompletion for advanced search
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 31 Mar 2007 10:57:24 +0000 (10:57 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 31 Mar 2007 10:57:24 +0000 (10:57 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1633 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
Makefile
htdocs/css/base.css [new file with mode: 0644]
modules/search.php
templates/search/adv.form.tpl
templates/skin/common.header.tpl

index 7a60b04..80f0429 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@ New:
     * Admin:
         - Fold/unfold wiki folders                                         -Car
 
+    * Banana:
+        - Fold/unfold threads                                              -Car
+
     * Core:
         - UTF-8                                                            -FRU
         - New Backtrace tool                                               -FRU
@@ -21,6 +24,7 @@ New:
     * Search:
         - Search Engine IE7 compatible                                     -FRU
         - Add soundex search for quick search                              -FRU
+        - Add autocompletion for advanced search                           -Car
 
     * Xnetgrp:
         - Direct access to the group forum (if exists)                     -FRU
index 4004963..047d482 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -106,9 +106,11 @@ htdocs/css/banana.css:
 ## jquery
 ##
 
-jquery: htdocs/javascript/jquery.js
+jquery: htdocs/javascript/jquery.js htdocs/javascript/jquery.autocomplete.js
 htdocs/javascript/jquery.js:
        wget http://jquery.com/src/jquery-latest.pack.js -O htdocs/javascript/jquery.js -q
+htdocs/javascript/jquery.autocomplete.js:
+       wget http://www.dyve.net/jquery/js/jquery.autocomplete.js -O htdocs/javascript/jquery.autocomplete.js -q
 
 ################################################################################
 
diff --git a/htdocs/css/base.css b/htdocs/css/base.css
new file mode 100644 (file)
index 0000000..1e7cc4c
--- /dev/null
@@ -0,0 +1,37 @@
+/***************************************************************************
+ *  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                *
+ ***************************************************************************/
+
+.ac_results ul {
+    padding:0px;
+    margin:0px;
+}
+
+.ac_results li {
+    display:block;
+    padding: 2px;
+    background: white;
+    color: black;
+    cursor:pointer;
+}
+.ac_results .over {
+    background: yellow;
+}
+
+/* vim: set et ts=4 sts=4 sw=4: */
index 8aa13cf..300b65b 100644 (file)
@@ -29,6 +29,7 @@ class SearchModule extends PLModule
             'search/ajax/region'  => $this->make_hook('region', AUTH_COOKIE, 'user', NO_AUTH),
             'search/ajax/grade'   => $this->make_hook('grade',  AUTH_COOKIE, 'user', NO_AUTH),
             'advanced_search.php' => $this->make_hook('redir_advanced', AUTH_PUBLIC),
+            'search/autocomplete' => $this->make_hook('autocomplete', AUTH_PUBLIC),
         );
     }
 
@@ -277,6 +278,41 @@ class SearchModule extends PLModule
         $page->assign('grade', '');
         $this->get_diplomas($school);
     }
+
+    function handler_autocomplete(&$page, $type = null)
+    {
+        // Autocompletion : according to type required, return
+        // a list of results matching with the number of matches.
+        // The output format is :
+        //   result1|nb1
+        //   result2|nb2
+        //   ...
+        header('Content-Type: text/plain; charset="UTF-8"');
+        $q = $_REQUEST['q'];
+        if (!$q) exit();
+        $unique = 'user_id';
+        $db = 'auth_user_md5';
+        switch ($type) {
+        case 'firstname': $field = 'prenom'; break;
+        case 'name': $field = 'nom'; break;
+        case 'nickname': $field = 'profile_nick'; break;
+        case 'entreprise': $db = 'entreprises'; $field = 'entreprise'; $unique='uid'; break;
+        default: exit();
+        }
+
+        $liste = XDB::iterator('SELECT '.$field.' AS field, COUNT(DISTINCT '.$unique.') AS nb FROM '.$db.' WHERE '.$field.' LIKE {?} GROUP BY '.$field.' LIMIT 11', $q.'%');
+        $nbResults = 0;
+        while ($result = $liste->next()) {
+            $nbResults++;
+            if ($nbResults == 11) {
+                echo '...|1'."\n";
+            } else {
+                echo $result['field'].'|'.$result['nb']."\n";
+            }
+        }
+
+        exit();
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 4399d7b..c5df906 100644 (file)
 <h1>Recherche dans l'annuaire</h1>
 
 <form id="recherche" action="search/adv" method="get">
+  {javascript name="jquery"}
+  {javascript name="jquery.autocomplete"}
   <script type="text/javascript">{literal}
     function launch_form(url) {
       var f = document.getElementById('recherche');
       f.action = url;
       f.submit();
     }
+    function format_autocomplete(row) {
+      if (row[1] == 1) {
+        return row[0];
+      }
+      return row[0] + ' ('+ row[1] + ')';
+    }
+    $(document).ready(function() {
+      $(".autocomplete").each(function() {
+        $(this).autocomplete("search/autocomplete/"+this.name,{selectOnly:1,formatItem:format_autocomplete});
+      });
+    });
   {/literal}</script>
   <table class="bicol" cellpadding="3" summary="Recherche">
     <tr>
       <td>
        <input type="hidden" name="rechercher" value="Chercher"/>
        <input type="submit" style="display:none"/>
-        <input type="text" name="name" size="32" value="{$smarty.request.name}" />
+        <input type="text" class="autocomplete" name="name" size="32" value="{$smarty.request.name}" />
       </td>
     </tr>
     <tr>
       <td>Prénom</td>
       <td>
-        <input type="text" name="firstname" size="32" value="{$smarty.request.firstname}" />
+        <input class="autocomplete" type="text" name="firstname" size="32" value="{$smarty.request.firstname}" />
       </td>
     </tr>
     <tr>
       <td>Surnom</td>
       <td>
-        <input type="text" name="nickname" size="32" value="{$smarty.request.nickname}" />
+        <input class="autocomplete" type="text" name="nickname" size="32" value="{$smarty.request.nickname}" />
       </td>
     </tr>
     <tr>
@@ -174,7 +187,7 @@ checked="checked"{/if}/>chercher uniquement les adresses où les camarades sont
     </tr>
     <tr>
       <td>Entreprise</td>
-      <td><input type="text" name="entreprise" size="32" value="{$smarty.request.entreprise}" /></td>
+      <td><input type="text" class="autocomplete" name="entreprise" size="32" value="{$smarty.request.entreprise}" /></td>
     </tr>
     <tr>
       <td>Fonction</td>
index 9b12bdd..4b5251a 100644 (file)
@@ -37,6 +37,7 @@
     <link rel="bookmark" href="http://www.polytechnique.org/"       title="| Polytechnique.org" />
     <link rel="bookmark" href="http://www.polytechnique.fr/eleves/" title="| Site d'élèves" />
 
+    <link rel="stylesheet" type="text/css" href="css/base.css" media="all"/>
     {foreach from=$xorg_css item=css}
     <link rel="stylesheet" type="text/css" href="css/{$css}" media="all"/>
     {/foreach}