Proof of concept:
[platal.git] / htdocs / advanced_search.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 if (Env::get('display')!='mini')
25 new_skinned_page('search.tpl', AUTH_COOKIE);
26 else
27 new_simple_page('search.tpl', AUTH_COOKIE);
28 $page->assign('advanced',1);
29 $page->assign('public_directory',0);
30 $page->assign('use_map', $globals->geoloc->use_map());
31 require_once("applis.func.inc.php");
32 require_once("geoloc.inc.php");
33
34 // {{{ function form_prepare()
35
36 function form_prepare()
37 {
38 global $page,$globals;
39 $page->assign('formulaire',1);
40 $page->assign('choix_nats', $globals->xdb->iterator('SELECT a2 AS id,IF(nat=\'\',pays,nat) AS text FROM geoloc_pays ORDER BY text'));
41 $page->assign('choix_postes', $globals->xdb->iterator('SELECT id,fonction_fr FROM fonctions_def ORDER BY fonction_fr'));
42 $page->assign('choix_binets', $globals->xdb->iterator('SELECT id,text FROM binets_def ORDER BY text'));
43 $page->assign('choix_groupesx', $globals->xdb->iterator('SELECT id,text FROM groupesx_def ORDER BY text'));
44 $page->assign('choix_sections', $globals->xdb->iterator('SELECT id,text FROM sections ORDER BY text'));
45 $page->assign('choix_schools', $globals->xdb->iterator('SELECT id,text FROM applis_def ORDER BY text'));
46 $page->assign('choix_secteurs', $globals->xdb->iterator('SELECT id,label FROM emploi_secteur ORDER BY label'));
47
48 if (Env::has('school')) {
49 $sql = 'SELECT type FROM applis_def WHERE id='.Env::getInt('school');
50 } else {
51 $sql = 'DESCRIBE applis_def type';
52 }
53 $res = $globals->xdb->query($sql);
54 $row = $res->fetchOneRow();
55 if (Env::has('school')) {
56 $types = $row[0];
57 } else {
58 $types = explode('(',$row[1]);
59 $types = str_replace("'","",substr($types[1],0,-1));
60 }
61 $page->assign('choix_diplomas', explode(',',$types));
62 }
63
64 // }}}
65
66 if (!Env::has('rechercher')) {
67 form_prepare();
68 } else {
69
70 // {{{ function get_list()
71
72 function get_list($offset, $limit, $order) {
73 $fields = new SFieldGroup(true, advancedSearchFromInput());
74 if ($fields->too_large()) {
75 form_prepare();
76 new ThrowError('Recherche trop générale.');
77 }
78 global $globals, $page;
79
80 $page->assign('search_vars', $fields->get_url());
81
82 $where = $fields->get_where_statement();
83 if ($where) {
84 $where = "WHERE $where";
85 }
86 $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT
87 u.nom, u.prenom,
88 '.$globals->search->result_fields.'
89 c.uid AS contact,
90 w.ni_id AS watch
91 FROM auth_user_md5 AS u
92 LEFT JOIN auth_user_quick AS q USING(user_id)
93 '.$fields->get_select_statement().'
94 '.(Env::has('only_referent') ? ' INNER JOIN mentor AS m ON (m.uid = u.user_id)' : '').'
95 LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie")
96 LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' AND c.contact=u.user_id)
97 LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.Session::getInt('uid').')
98 '.$globals->search->result_where_statement."
99 $where
100 ORDER BY ".($order?($order.', '):'')
101 .implode(',',array_filter(array($fields->get_order_statement(), 'promo DESC, NomSortKey, prenom'))).'
102 LIMIT '.($offset * $limit).','.$limit;
103 $liste = $globals->xdb->iterator($sql);
104 $res = $globals->xdb->query("SELECT FOUND_ROWS()");
105 $nb_tot = $res->fetchOneCell();
106 return Array($liste, $nb_tot);
107 }
108
109 // }}}
110
111 $search = new XOrgSearch('get_list');
112 $search->setNbLines($globals->search->per_page);
113
114 $page->assign('url_search_form', $search->make_url(Array('rechercher'=>0)));
115 $page->assign('with_soundex', Env::has('with_soundex')?"":($search->make_url(Array())."&with_soundex=1"));
116
117 $nb_tot = $search->show();
118
119 if ($nb_tot > $globals->search->private_max) {
120 form_prepare();
121 new ThrowError('Recherche trop générale');
122 }
123
124 }
125
126 $page->register_modifier('display_lines', 'display_lines');
127 $page->run();
128
129 // vim:set et sws=4 sw=4 sts=4:
130 ?>