From 838cc16a148b32896fe0b3baf7f6db6aa6d95741 Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Sat, 31 Mar 2007 10:57:24 +0000 Subject: [PATCH] autocompletion for advanced search git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1633 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 4 ++++ Makefile | 4 +++- htdocs/css/base.css | 37 +++++++++++++++++++++++++++++++++++++ modules/search.php | 36 ++++++++++++++++++++++++++++++++++++ templates/search/adv.form.tpl | 21 +++++++++++++++++---- templates/skin/common.header.tpl | 1 + 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 htdocs/css/base.css diff --git a/ChangeLog b/ChangeLog index 7a60b04..80f0429 100644 --- 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 diff --git a/Makefile b/Makefile index 4004963..047d482 100644 --- 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 index 0000000..1e7cc4c --- /dev/null +++ b/htdocs/css/base.css @@ -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: */ diff --git a/modules/search.php b/modules/search.php index 8aa13cf..300b65b 100644 --- a/modules/search.php +++ b/modules/search.php @@ -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: diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index 4399d7b..c5df906 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -23,12 +23,25 @@

Recherche dans l'annuaire

+ {javascript name="jquery"} + {javascript name="jquery.autocomplete"} @@ -41,19 +54,19 @@ @@ -174,7 +187,7 @@ checked="checked"{/if}/>chercher uniquement les adresses où les camarades sont - + diff --git a/templates/skin/common.header.tpl b/templates/skin/common.header.tpl index 9b12bdd..4b5251a 100644 --- a/templates/skin/common.header.tpl +++ b/templates/skin/common.header.tpl @@ -37,6 +37,7 @@ + {foreach from=$xorg_css item=css} {/foreach} -- 2.1.4
- +
Prénom - +
Surnom - +
Entreprise
Fonction