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