Bug 130: Les pages ont toutes un titre different.
[platal.git] / htdocs / search.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once("xorg.inc.php");
23 require_once("search.inc.php");
24
25 new_skinned_page('search.tpl', AUTH_PUBLIC);
26 if (logged()) {
27 new_skinned_page('search.tpl', AUTH_COOKIE);
28 }
29
30 $page->assign('xorg_title','Polytechnique.org - Annuaire');
31 require_once("applis.func.inc.php");
32 require_once("geoloc.inc.php");
33
34 $page->assign('baseurl', $globals->baseurl);
35
36 if (Env::has('quick')) {
37 $page->assign('formulaire', 0);
38
39 // {{{ get_list
40 function get_list($offset, $limit, $order) {
41 global $globals;
42 $qSearch = new QuickSearch('quick');
43 $fields = new SFieldGroup(true, array($qSearch));
44
45 if ($qSearch->isempty()) {
46 new ThrowError('Recherche trop générale.');
47 }
48
49 $sql = 'SELECT SQL_CALC_FOUND_ROWS
50 UPPER(IF(u.nom!="",u.nom,u.nom_ini)) AS nom,
51 IF(u.prenom!="",u.prenom,u.prenom_ini) AS prenom,
52 '.$globals->search->result_fields.'
53 c.uid AS contact,
54 w.ni_id AS watch,
55 '.$qSearch->get_score_statement().'
56 FROM auth_user_md5 AS u
57 '.$fields->get_select_statement().'
58 LEFT JOIN auth_user_quick AS q ON (u.user_id = q.user_id)
59 LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie")
60 LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' AND c.contact=u.user_id)
61 LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.Session::getInt('uid').')
62 '.$globals->search->result_where_statement.'
63 WHERE '.$fields->get_where_statement().(logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : '').'
64 GROUP BY u.user_id
65 ORDER BY '.($order?($order.', '):'')
66 .implode(',',array_filter(array($fields->get_order_statement(), 'u.promo DESC, NomSortKey, prenom'))).'
67 LIMIT '.$offset * $globals->search->per_page.','.$globals->search->per_page;
68 $list = $globals->xdb->iterator($sql);
69 $res = $globals->xdb->query("SELECT FOUND_ROWS()");
70 $nb_tot = $res->fetchOneCell();
71 return array($list, $nb_tot);
72 }
73
74 // }}}
75
76 $search = new XOrgSearch(get_list);
77 $search->setNbLines($globals->search->per_page);
78 $search->addOrder('score', 'score', false, 'pertinence', AUTH_PUBLIC, true);
79
80 $nb_tot = $search->show();
81
82 if (!logged() && $nb_tot > $globals->search->public_max) {
83 new ThrowError('Votre recherche a généré trop de résultats pour un affichage public.');
84 } elseif ($nb_tot > $globals->search->private_max) {
85 new ThrowError('Recherche trop générale');
86 } elseif (empty($nb_tot)) {
87 new ThrowError('il n\'existe personne correspondant à ces critères dans la base !');
88 }
89
90 } else {
91 $page->assign('formulaire',1);
92 }
93
94 $page->register_modifier('display_lines', 'display_lines');
95 $page->run();
96
97 // vim:set et sws=4 sw=4 sts=4:
98 ?>