2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class SearchModule
extends PLModule
27 'search' => $this->make_hook('quick', AUTH_PUBLIC
),
28 'search/adv' => $this->make_hook('advanced', AUTH_COOKIE
),
29 'advanced_search.php' => $this->make_hook('redir_advanced', AUTH_PUBLIC
),
30 'search/autocomplete' => $this->make_hook('autocomplete', AUTH_COOKIE
, 'user', NO_AUTH
),
31 'search/list' => $this->make_hook('list', AUTH_COOKIE
, 'user', NO_AUTH
),
35 function handler_redir_advanced(&$page, $mode = null
)
37 pl_redirect('search/adv');
41 function form_prepare()
43 Platal
::page()->assign('formulaire',1);
46 function handler_quick(&$page, $action = null
, $subaction = null
)
50 $res = XDB
::query("SELECT MIN(diminutif), MAX(diminutif)
52 WHERE cat = 'Promotions'");
53 list($min, $max) = $res->fetchOneRow();
54 $page->assign('promo_min', $min);
55 $page->assign('promo_max', $max);
57 if (Env
::has('quick') ||
$action == 'geoloc') {
58 $quick = trim(Env
::v('quick'));
59 if (S
::logged() && !Env
::has('page')) {
60 S
::logger()->log('search', 'quick=' . $quick);
62 $list = 'profile|prf|fiche|fic|referent|ref|mentor';
64 $list .= '|admin|adm|ax';
66 if (preg_match('/^(' . $list . '):([-a-z]+(\.[-a-z]+(\.\d{2,4})?)?)$/', replace_accent($quick), $matches)) {
69 case 'admin': case 'adm':
70 $base = 'admin/user/';
73 $base = 'profile/ax/';
75 case 'profile': case 'prf': case 'fiche': case 'fic':
78 case 'referent': case 'ref': case 'mentor':
83 $user = User
::getSilent($login);
85 pl_redirect($base . $user->login());
87 $_REQUEST['quick'] = $login;
88 $_GET['quick'] = $login;
89 } elseif (strpos($quick, 'doc:') === 0) {
90 $url = 'Docs/Recherche?';
91 $url .= 'action=search&q=' . urlencode(substr($quick, 4));
92 $url .= '&group=' . urlencode('-Equipe,-Main,-PmWiki,-Site,-Review');
96 $page->assign('formulaire', 0);
98 require_once 'userset.inc.php';
99 $view = new SearchSet(true
, $action == 'geoloc' && substr($subaction, -3) == 'swf');
100 $view->addMod('minifiche', 'Mini-fiches', true
, array('with_score' => true
));
101 if (S
::logged() && !Env
::i('nonins')) {
102 $view->addMod('trombi', 'Trombinoscope', false
, array('with_promo' => true
, 'with_score' => true
));
103 // TODO: Reactivate when the new map is completed.
104 // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
106 $view->apply('search', $page, $action, $subaction);
108 $nb_tot = $view->count();
109 $page->assign('search_results_nb', $nb_tot);
113 if (!S
::logged() && $nb_tot > $globals->search
->public_max
) {
114 $page->trigError('Votre recherche a généré trop de résultats pour un affichage public.');
115 } elseif ($nb_tot > $globals->search
->private_max
) {
116 $page->trigError('Recherche trop générale. Une <a href="search/adv">recherche avancée</a> permet de préciser la recherche.');
117 } elseif (empty($nb_tot)) {
118 $page->trigError('Il n\'existe personne correspondant à ces critères dans la base !');
121 $page->assign('formulaire',1);
122 $page->addJsLink('ajax.js');
125 $this->load('search.inc.php');
126 $page->changeTpl('search/index.tpl');
127 $page->setTitle('Annuaire');
130 function handler_advanced(&$page, $action = null
, $subaction = null
)
133 require_once 'geocoding.inc.php';
134 $this->load('search.inc.php');
135 $page->assign('advanced',1);
136 $page->addJsLink('jquery.autocomplete.js');
138 if (!Env
::has('rechercher') && $action != 'geoloc') {
139 $this->form_prepare();
141 if (!Env
::has('page')) {
142 S
::logger()->log('search', 'adv=' . var_export($_GET, true
));
145 require_once 'userset.inc.php';
146 $view = new SearchSet(false
, $action == 'geoloc' && substr($subaction, -3) == 'swf');
147 $view->addMod('minifiche', 'Mini-fiches', true
);
148 $view->addMod('trombi', 'Trombinoscope', false
, array('with_promo' => true
));
149 // TODO: Reactivate when the new map is completed.
150 // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
151 $view->apply('search/adv', $page, $action, $subaction);
156 $nb_tot = $view->count();
157 if ($nb_tot > $globals->search
->private_max
) {
158 $this->form_prepare();
159 $page->trigError('Recherche trop générale.');
163 $page->changeTpl('search/index.tpl', $action == 'mini' ? SIMPLE
: SKINNED
);
164 $page->addJsLink('ajax.js');
165 $page->assign('public_directory',0);
168 function handler_autocomplete(&$page, $type = null
)
170 // Autocompletion : according to type required, return
171 // a list of results matching with the number of matches.
172 // The output format is :
176 pl_content_headers("text/plain");
177 $q = preg_replace(array('/\*+$/', // always look for $q*
178 '/([\^\$\[\]])/', // escape special regexp char
179 '/\*/'), // replace joker by regexp joker
186 // try to look in cached results
187 $cache = XDB
::query('SELECT result
188 FROM search_autocomplete
191 generated > NOW() - INTERVAL 1 DAY',
193 if ($res = $cache->fetchOneCell()) {
198 require_once 'directory.enums.inc.php';
200 'binetTxt' => DirEnum
::BINETS
,
201 'groupexTxt' => DirEnum
::GROUPESX
,
202 'sectionTxt' => DirEnum
::SECTIONS
,
203 'networking_typeTxt' => DirEnum
::NETWORKS
,
204 'city' => DirEnum
::LOCALITIES
,
205 'countryTxt' => DirEnum
::COUNTRIES
,
206 'entreprise' => DirEnum
::COMPANIES
,
207 'secteurTxt' => DirEnum
::SECTORS
,
208 'description' => DirEnum
::JOBDESCRIPTION
,
209 'nationaliteTxt' => DirEnum
::NATIONALITIES
,
210 'schoolTxt' => DirEnum
::EDUSCHOOLS
,
212 if (!array_key_exists($enums, $type)) {
216 $enum = $enums[$type];
218 $list = DirEnum
::getAutoComplete($enum, $q);
221 while ($result = $list->next()) {
223 if ($nbResults == 11) {
226 $res .= $result['field'].'|';
227 if (isset($result['nb'])) {
228 $res .= $result['nb'];
230 if (isset($result['id'])) {
231 $res .= '|'.$result['id'];
236 XDB
::query('REPLACE INTO search_autocomplete
237 VALUES ({?}, {?}, {?}, NOW())',
243 function handler_list(&$page, $type = null
, $idVal = null
)
245 // Give the list of all values possible of type and builds a select input for it
247 require_once 'directory.enums.inc.php';
251 $ids = DirEnum
::getOptions(DirEnum
::BINETS
);
253 case 'networking_type':
254 $ids = DirEnum
::getOptions(DirEnum
::NETWORKS
);
257 $ids = DirEnum
::getOptions(DirEnum
::COUNTRIES
);
258 $page->assign('onchange', 'changeCountry(this.value)');
261 if (Env
::has('school') && Env
::i('school') != 0) {
262 $ids = DirEnum
::getOptions(DirEnum
::EDUDEGREES
, Env
::i('school'));
264 $ids = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
268 $ids = DirEnum
::getOptions(DirEnum
::GROUPESX
);
271 $ids = DirEnum
::getOptions(DirEnum
::NATIONALITIES
);
274 if ($isset($_REQUEST['country'])) {
275 $ids = DirEnum
::getOptions(DirEnum
::ADMINAREAS
, $_REQUEST['country']);
277 $ids = DirEnum
::getOptions(DirEnum
::ADMINAREAS
);
281 $ids = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
282 $page->assign('onchange', 'changeSchool(this.value)');
285 $ids = DirEnum
::getOptions(DirEnum
::SECTIONS
);
288 $ids = DirEnum
::getOptions(DirEnum
::SECTORS
);
293 pl_content_headers("text/plain");
297 pl_content_headers("text/xml");
298 $page->changeTpl('include/field.select.tpl', NO_SKIN
);
299 $page->assign('name', $type);
300 $page->assign('list', $ids);
301 $page->assign('with_text_value', true
);
302 $page->assign('onchange', "document.forms.recherche.{$type}Txt.value = this.options[this.selectedIndex].text");
306 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: