2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 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
);
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");
34 // {{{ function form_prepare()
36 function form_prepare()
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'));
48 if (Env
::has('school')) {
49 $sql = 'SELECT type FROM applis_def WHERE id='.Env
::getInt('school');
51 $sql = 'DESCRIBE applis_def type';
53 $res = $globals->xdb
->query($sql);
54 $row = $res->fetchOneRow();
55 if (Env
::has('school')) {
58 $types = explode('(',$row[1]);
59 $types = str_replace("'","",substr($types[1],0,-1));
61 $page->assign('choix_diplomas', explode(',',$types));
66 if (!Env
::has('rechercher')) {
70 // {{{ function get_list()
72 function get_list($offset, $limit, $order) {
73 $fields = new SFieldGroup(true
, advancedSearchFromInput());
74 if ($fields->too_large()) {
76 new ThrowError('Recherche trop générale.');
78 global $globals, $page;
80 $page->assign('search_vars', $fields->get_url());
82 $where = $fields->get_where_statement();
84 $where = "WHERE $where";
86 $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT
88 '.$globals->search
->result_fields
.'
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
."
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);
111 $search = new XOrgSearch('get_list');
112 $search->setNbLines($globals->search
->per_page
);
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"));
117 $nb_tot = $search->show();
119 if ($nb_tot > $globals->search
->private_max
) {
121 new ThrowError('Recherche trop générale');
126 $page->register_modifier('display_lines', 'display_lines');
129 // vim:set et sws=4 sw=4 sts=4: