Fix search failures
[platal.git] / include / userset.inc.php
CommitLineData
8c4a0c30 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2007 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
8c4a0c30 22require_once('xorg.misc.inc.php');
23require_once('user.func.inc.php');
24
25global $globals;
26
35fa92e8 27@$globals->search->result_where_statement = '
8c4a0c30 28 LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0)
29 LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid)
30 LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1)
31 LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid)
32 LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id)
33 LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id)
34 LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
35 LEFT JOIN geoloc_pays AS n ON (u.nationalite = n.a2)
36 LEFT JOIN adresses AS adr ON (u.user_id = adr.uid AND FIND_IN_SET(\'active\',adr.statut))
37 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
38 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
39 LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = \'active\')';
40
41class UserSet extends PlSet
42{
43 public function __construct($joins = '', $where = '')
44 {
45 global $globals;
46 parent::__construct('auth_user_md5 AS u',
47 (!empty($GLOBALS['IS_XNET_SITE']) ?
48 'INNER JOIN groupex.membres AS gxm ON (u.user_id = gxm.uid
49 AND gxm.asso_id = ' . $globals->asso('id') . ') ' : '')
50 . 'LEFT JOIN auth_user_quick AS q USING (user_id)
51 LEFT JOIN aliases AS a ON (a.id = u.user_id AND type = \'a_vie\')
52 ' . $joins,
53 $where,
54 'u.user_id');
55 }
56}
57
58class SearchSet extends UserSet
59{
35fa92e8 60 private $score = null;
8c4a0c30 61 private $order = null;
62 private $quick = false;
63
64 public function __construct($quick = false, $no_search = false)
65 {
66 require_once dirname(__FILE__).'/../modules/search/search.inc.php';
67
68 if ($no_search) {
69 return;
70 }
71
72 $this->quick = $quick;
73 if ($quick) {
74 $this->getQuick();
75 } else {
76 $this->getAdvanced();
77 }
78 }
79
80 private function getQuick()
81 {
82 require_once dirname(__FILE__).'/../modules/search/search.inc.php';
83 global $globals;
84 if (!S::logged()) {
85 Env::kill('with_soundex');
86 }
87 $qSearch = new QuickSearch('quick');
88 $fields = new SFieldGroup(true, array($qSearch));
89 if ($qSearch->isEmpty()) {
90 new ThrowError('Recherche trop générale.');
91 }
35fa92e8 92 $this->score = $qSearch->get_score_statement();
93 parent::__construct("{$fields->get_select_statement()}
94 {$globals->search->result_where_statement}",
8c4a0c30 95 $fields->get_where_statement() .
96 (S::logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : ''));
97
98 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
99 'u.promo DESC, NomSortKey, prenom')));
100 }
101
102 private function getAdvanced()
103 {
104 global $globals;
105 $fields = new SFieldGroup(true, advancedSearchFromInput());
106 if ($fields->too_large()) {
107 new ThrowError('Recherche trop générale.');
108 }
109 parent::__construct($fields->get_select_statement() . ' ' . $globals->search->result_where_statement,
110 $fields->get_where_statement());
111 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
112 'promo DESC, NomSortKey, prenom')));
113 }
35fa92e8 114
115 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null)
116 {
117 if ($this->score) {
118 $fields .= ', ' . $this->score;
119 }
120 return parent::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom);
121 }
8c4a0c30 122}
123
124class MinificheView extends MultipageView
125{
126 public function __construct(PlSet &$set, $data, array $params)
127 {
128 require_once 'applis.func.inc.php';
129 global $globals;
130 $this->entriesPerPage = $globals->search->per_page;
35fa92e8 131 if (@$params['with_score']) {
132 $this->addSortKey('score', array('-score', '-watch_last', '-promo', 'nom', 'prenom'), 'pertinence');
133 }
134 $this->addSortKey('name', array('nom', 'prenom'), 'nom');
135 $this->addSortKey('promo', array('-promo', 'nom', 'prenom'), 'promotion');
136 $this->addSortKey('date', array('-watch_last', '-promo', 'nom', 'prenom'), 'dernière modification');
8c4a0c30 137 parent::__construct($set, $data, $params);
138 }
139
140 public function fields()
141 {
142 return "u.user_id AS id,
143 u.*, a.alias AS forlife,
144 u.perms != 'pending' AS inscrit,
145 u.perms != 'pending' AS wasinscrit,
146 u.deces != 0 AS dcd, u.deces, u.matricule_ax,
147 FIND_IN_SET('femme', u.flags) AS sexe,
148 e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction,
149 IF(n.nat='',n.pays,n.nat) AS nat, n.a2 AS iso3166,
150 ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
151 ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
152 adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region,
153 IF(u.nom_usage<>'',u.nom_usage,u.nom) AS sortkey,
154 COUNT(em.email) > 0 AS actif" . (S::logged() ? ", c.contact AS contact" : '');
155 }
156
157 public function joins()
158 {
159 return ($this->set instanceof SearchSet ? "" :
160 "LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id)
161 LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id)
162 LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
163 LEFT JOIN geoloc_pays AS n ON (u.nationalite = n.a2)
164 LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0)
165 LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid)
166 LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1)
167 LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid)
168 LEFT JOIN adresses AS adr ON (u.user_id = adr.uid
169 AND FIND_IN_SET('active', adr.statut))
170 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
171 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
172 LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active')
173 ") . (S::logged() ?
174 "LEFT JOIN contacts AS c On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")"
175 : "");
176 }
177
178 public function templateName()
179 {
180 return 'include/plview.minifiche.tpl';
181 }
182}
183
184class TrombiView extends MultipageView
185{
186 public function __construct(PlSet &$set, $data, array $params)
187 {
188 $this->entriesPerPage = 24;
189 $this->order = explode(',', Env::v('order', 'nom,prenom,promo'));
35fa92e8 190 if (@$params['with_score']) {
191 $this->addSortKey('score', array('-score', '-watch_last', '-promo', 'nom', 'prenom'), 'pertinence');
192 }
193 $this->addSortKey('name', array('nom', 'prenom'), 'nom');
194 $this->addSortKey('promo', array('-promo', 'nom', 'prenom'), 'promotion');
195 $this->addSortKey('date', array('-watch_last', '-promo', 'nom', 'prenom'), 'dernière modification');
8c4a0c30 196 parent::__construct($set, $data, $params);
197 }
198
199 public function fields()
200 {
201 return "u.user_id, IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo, a.alias AS forlife ";
202 }
203
204 public function joins()
205 {
206 return "INNER JOIN photo AS p ON (p.uid = u.user_id) ";
207 }
208
209 public function templateName()
210 {
211 return 'include/plview.trombi.tpl';
212 }
213
214 public function apply(PlatalPage &$page)
215 {
216 if (!empty($GLOBALS['IS_XNET_SITE'])) {
217 global $globals;
218 $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/');
219 }
220 return parent::apply($page);
221 }
222}
223
224class GeolocView implements PlView
225{
226 private $set;
227 private $type;
228 private $params;
229
230 public function __construct(PlSet &$set, $data, array $params)
231 {
232 $this->params = $params;
233 $this->set =& $set;
234 $this->type = $data;
235 }
236
237 private function use_map()
238 {
239 return is_file(dirname(__FILE__) . '/../modules/geoloc/dynamap.swf') &&
240 is_file(dirname(__FILE__) . '/../modules/geoloc/icon.swf');
241 }
242
35fa92e8 243 public function args()
8c4a0c30 244 {
35fa92e8 245 $args = $this->set->args();
246 unset($args['initfile']);
247 unset($args['mapid']);
248 return $args;
8c4a0c30 249 }
250
251 public function apply(PlatalPage &$page)
252 {
253 require_once 'geoloc.inc.php';
254 require_once '../modules/search/search.inc.php';
255
256 switch ($this->type) {
257 case 'icon.swf':
258 header("Content-type: application/x-shockwave-flash");
259 header("Pragma:");
260 readfile(dirname(__FILE__).'/../modules/geoloc/icon.swf');
261 exit;
262
263 case 'dynamap.swf':
264 header("Content-type: application/x-shockwave-flash");
265 header("Pragma:");
266 readfile(dirname(__FILE__).'/../modules/geoloc/dynamap.swf');
267 exit;
268
269 case 'init':
270 $page->changeTpl('geoloc/init.tpl', NO_SKIN);
271 header('Content-Type: text/xml');
272 header('Pragma:');
273 if (!empty($GLOBALS['IS_XNET_SITE'])) {
274 $page->assign('background', 0xF2E9D0);
275 }
8c4a0c30 276 break;
277
278 case 'city':
279 $page->changeTpl('geoloc/city.tpl', NO_SKIN);
280 header('Content-Type: text/xml');
281 header('Pragma:');
282 $it =& $this->set->get('u.user_id AS id, u.prenom, u.nom, u.promo, al.alias',
283 "INNER JOIN adresses AS adrf ON (adrf.uid = u.user_id)
284 LEFT JOIN aliases AS al ON (u.user_id = al.id
285 AND FIND_IN_SET(al.flags, 'bestalias'))
286 INNER JOIN adresses AS av ON (" . getadr_join('av') . ")",
287 'adrf.cityid = ' . Env::i('cityid'), null, null, 11);
288 $page->assign('users', $it);
289 break;
290
291 case 'country':
292 if (Env::has('debug')) {
293 $page->changeTpl('geoloc/country.tpl', SIMPLE);
294 } else {
295 $page->changeTpl('geoloc/country.tpl', NO_SKIN);
296 header('Content-Type: text/xml');
297 header('Pragma:');
298 }
8c4a0c30 299 $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false;
300 list($countries, $cities) = geoloc_getData_subcountries($mapid, $this->set, 10);
301 $page->assign('countries', $countries);
302 $page->assign('cities', $cities);
303 break;
304
305 default:
306 global $globals;
307 if (!$this->use_map()) {
308 $page->assign('request_geodesix', true);
309 }
310 if (!empty($GLOBALS['IS_XNET_SITE'])) {
311 $page->assign('no_annu', true);
312 }
313 $page->assign('protocole', @$_SERVER['HTTPS'] ? 'https' : 'http');
314 $this->set->get('u.user_id', null, "u.perms != 'pending' AND u.deces = 0", "u.user_id", null);
8c4a0c30 315 return 'include/plview.geoloc.tpl';
316 }
317 }
318}
319
320// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
321?>