2 /***************************************************************************
3 * Copyright (C) 2003-2004 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 new_skinned_page('search.tpl', AUTH_COOKIE
);
26 $page->assign('advanced',1);
27 $page->assign('public_directory',0);
28 require_once("applis.func.inc.php");
29 require_once("geoloc.inc.php");
31 // {{{ function form_prepare()
33 function form_prepare()
35 global $page,$globals;
36 $page->assign('formulaire',1);
37 $page->assign('choix_nats', $globals->xdb
->iterator('SELECT a2 AS id,IF(nat=\'\',pays,nat) AS text FROM geoloc_pays ORDER BY text'));
38 $page->assign('choix_postes', $globals->xdb
->iterator('SELECT id,fonction_fr FROM fonctions_def ORDER BY fonction_fr'));
39 $page->assign('choix_binets', $globals->xdb
->iterator('SELECT id,text FROM binets_def ORDER BY text'));
40 $page->assign('choix_groupesx', $globals->xdb
->iterator('SELECT id,text FROM groupesx_def ORDER BY text'));
41 $page->assign('choix_sections', $globals->xdb
->iterator('SELECT id,text FROM sections ORDER BY text'));
42 $page->assign('choix_schools', $globals->xdb
->iterator('SELECT id,text FROM applis_def ORDER BY text'));
43 $page->assign('choix_secteurs', $globals->xdb
->iterator('SELECT id,label FROM emploi_secteur ORDER BY label'));
45 if (Env
::has('school')) {
46 $sql = 'SELECT type FROM applis_def WHERE id='.Env
::getInt('school');
48 $sql = 'DESCRIBE applis_def type';
50 $res = $globals->xdb
->query($sql);
51 $row = $res->fetchOneRow();
52 if (Env
::has('school')) {
55 $types = explode('(',$row[1]);
56 $types = str_replace("'","",substr($types[1],0,-1));
58 $page->assign('choix_diplomas', explode(',',$types));
63 if (!Env
::has('rechercher')) {
67 // {{{ function get_list()
69 function get_list($offset, $limit, $order) {
70 if ($with_soundex = Env
::has('with_soundex')) {
71 $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule');
72 $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule');
74 $nameField = new NameSField('name',array('u.nom','u.nom_usage'),'');
75 $firstnameField = new StringSField('firstname',array('u.prenom'),'');
77 $nicknameField = new StringSField('nickname',array('q.profile_nick'),'');
79 $promo1Field = new PromoSField('promo1','egal1',array('u.promo'),'');
80 $promo2Field = new PromoSField('promo2','egal2',array('u.promo'),'');
81 $womanField = new RefSField('woman',array('FIND_IN_SET(u.flags,\'femme\')+1'),'','','');
82 $subscriberField = new RefSField('subscriber',array('!(u.perms IN (\'admin\',\'user\'))+1'),'','','');
83 $aliveField = new RefSField('alive',array('(u.deces!=0)+1'),'','','');
85 $townField = new RefSField('city',array('av.city'),'adresses','av','u.user_id=av.uid',false
);
86 $countryField = new RefSField('country',array('ap.country'),'adresses','ap','u.user_id=ap.uid');
87 $regionField = new RefSField('region',array('ar.region'),'adresses','ar','u.user_id=ar.uid');
89 $entrepriseField = new RefSField('entreprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid',false
);
90 $posteField = new RefSField('poste',array('ep.poste'),'entreprises','ep','u.user_id=ep.uid', false
);
91 $fonctionField = new RefSField('fonction',array('en.fonction'),'entreprises','en','u.user_id=en.uid');
92 $secteurField = new RefSField('secteur',array('fm.secteur'),'entreprises','fm','u.user_id=fm.uid');
93 $cvField = new RefSField('cv',array('u.cv'),'','','',false
);
95 $natField = new RefSField('nationalite',array('u.nationalite'),'','','');
96 $binetField = new RefSField('binet',array('b.binet_id'),'binets_ins','b','u.user_id=b.user_id');
97 $groupexField = new RefSField('groupex',array('g.gid'),'groupesx_ins','g','u.user_id=g.guid');
98 $sectionField = new RefSField('section',array('u.section'),'','','');
99 $schoolField = new RefSField('school',array('as.aid'),'applis_ins','`as`','u.user_id=as.uid');
100 $diplomaField = new RefSField('diploma',array('ad.type'),'applis_ins','ad','u.user_id=ad.uid');
102 $freeField = new RefSField('free',array('q.profile_freetext'),'','','',false
);
104 $fields = new SFieldGroup(true
, array(
105 $nameField, $firstnameField, $nicknameField, $promo1Field,
106 $promo2Field, $womanField, $subscriberField, $aliveField,
107 $townField, $countryField, $regionField, $entrepriseField,
108 $posteField, $secteurField, $cvField, $natField, $binetField,
109 $groupexField, $sectionField, $schoolField, $diplomaField,
110 $freeField, $fonctionField)
114 if ($fields->too_large()) {
116 new ThrowError('Recherche trop générale.');
120 $where = $fields->get_where_statement();
122 $where = "WHERE $where";
124 $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT
126 '.$globals->search
->result_fields
.'
129 FROM auth_user_md5 AS u
130 LEFT JOIN auth_user_quick AS q USING(user_id)
131 '.$fields->get_select_statement().'
132 '.(Env
::has('only_referent') ?
' INNER JOIN mentor AS m ON (m.uid = u.user_id)' : '').'
133 LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie")
134 LEFT JOIN contacts AS c ON (c.uid='.Session
::getInt('uid').' AND c.contact=u.user_id)
135 LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.Session
::getInt('uid').')
136 '.$globals->search
->result_where_statement
."
138 ORDER BY ".($order?
($order.', '):'')
139 .implode(',',array_filter(array($fields->get_order_statement(), 'promo DESC, NomSortKey, prenom'))).'
140 LIMIT '.($offset * $limit).','.$limit;
141 $liste = $globals->xdb
->iterator($sql);
142 $res = $globals->xdb
->query("SELECT FOUND_ROWS()");
143 $nb_tot = $res->fetchOneCell();
144 return Array($liste, $nb_tot);
149 $search = new XOrgSearch('get_list');
150 $search->setNbLines($globals->search
->per_page
);
152 $page->assign('url_search_form', $search->make_url(Array('rechercher'=>0)));
153 $page->assign('with_soundex', Env
::has('with_soundex')?
"":($search->make_url(Array())."&with_soundex=1"));
155 $nb_tot = $search->show();
157 if ($nb_tot > $globals->search
->private_max
) {
159 new ThrowError('Recherche trop générale');
164 $page->register_modifier('display_lines', 'display_lines');
167 // vim:set et sws=4 sw=4 sts=4: