0337d704 |
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 | new_skinned_page('search.tpl', AUTH_COOKIE); |
25 | |
26 | $page->assign('advanced',1); |
27 | $page->assign('public_directory',0); |
28 | require_once("applis.func.inc.php"); |
29 | require_once("geoloc.inc.php"); |
30 | |
31 | // {{{ function form_prepare() |
32 | |
33 | function form_prepare() |
34 | { |
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')); |
44 | |
45 | if (Env::has('school')) { |
46 | $sql = 'SELECT type FROM applis_def WHERE id='.Env::getInt('school'); |
47 | } else { |
48 | $sql = 'DESCRIBE applis_def type'; |
49 | } |
50 | $res = $globals->xdb->query($sql); |
51 | $row = $res->fetchOneRow(); |
52 | if (Env::has('school')) { |
53 | $types = $row[0]; |
54 | } else { |
55 | $types = explode('(',$row[1]); |
56 | $types = str_replace("'","",substr($types[1],0,-1)); |
57 | } |
58 | $page->assign('choix_diplomas', explode(',',$types)); |
59 | } |
60 | |
61 | // }}} |
62 | |
63 | if (!Env::has('rechercher')) { |
64 | form_prepare(); |
65 | } else { |
66 | |
67 | // {{{ function get_list() |
68 | |
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'); |
73 | } else { |
74 | $nameField = new NameSField('name',array('u.nom','u.nom_usage'),''); |
75 | $firstnameField = new StringSField('firstname',array('u.prenom'),''); |
76 | } |
77 | $nicknameField = new StringSField('nickname',array('q.profile_nick'),''); |
78 | |
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'),'','',''); |
84 | |
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'); |
88 | |
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); |
94 | |
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'); |
101 | |
102 | $freeField = new RefSField('free',array('q.profile_freetext'),'','','',false); |
103 | |
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) |
111 | ); |
112 | |
113 | |
114 | if ($fields->too_large()) { |
115 | form_prepare(); |
116 | new ThrowError('Recherche trop générale.'); |
117 | } |
118 | global $globals; |
119 | |
120 | $where = $fields->get_where_statement(); |
121 | if ($where) { |
122 | $where = "WHERE $where"; |
123 | } |
124 | $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT |
125 | u.nom, u.prenom, |
126 | '.$globals->search->result_fields.' |
127 | c.uid AS contact, |
128 | w.ni_id AS watch |
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." |
137 | $where |
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); |
145 | } |
146 | |
147 | // }}} |
148 | |
149 | $search = new XOrgSearch('get_list'); |
150 | $search->setNbLines($globals->search->per_page); |
151 | |
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")); |
154 | |
155 | $nb_tot = $search->show(); |
156 | |
157 | if ($nb_tot > $globals->search->private_max) { |
158 | form_prepare(); |
159 | new ThrowError('Recherche trop générale'); |
160 | } |
161 | |
162 | } |
163 | |
164 | $page->register_modifier('display_lines', 'display_lines'); |
165 | $page->run(); |
166 | |
167 | // vim:set et sws=4 sw=4 sts=4: |
168 | ?> |