Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
0337d704 | 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 | // {{{ function user_clear_all_subs() | |
23 | /** kills the inscription of a user. | |
24 | * we still keep his birthdate, adresses, and personnal stuff | |
25 | * kills the entreprises, mentor, emails and lists subscription stuff | |
26 | */ | |
27 | function user_clear_all_subs($user_id, $really_del=true) | |
28 | { | |
dd502514 | 29 | // keep datas in : aliases, adresses, tels, applis_ins, binets_ins, contacts, groupesx_ins, homonymes, identification_ax, photo |
0337d704 | 30 | // delete in : auth_user_md5, auth_user_quick, competences_ins, emails, entreprises, langues_ins, mentor, |
31 | // mentor_pays, mentor_secteurs, newsletter_ins, perte_pass, requests, user_changes, virtual_redirect, watch_sub | |
32 | // + delete maillists | |
33 | ||
34 | global $globals; | |
35 | $uid = intval($user_id); | |
08cce2ff | 36 | $res = XDB::query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $uid); |
0337d704 | 37 | $alias = $res->fetchOneCell(); |
38 | ||
425f432d | 39 | $tables_to_clear = array('uid' => array('competences_ins', 'entreprises', 'langues_ins', 'mentor_pays', |
40 | 'mentor_secteurs', 'mentor', 'perte_pass', 'watch_sub'), | |
41 | 'user_id' => array('requests', 'user_changes')); | |
42 | ||
0337d704 | 43 | if ($really_del) { |
b235d980 | 44 | array_push($tables_to_clear['uid'], 'emails', 'groupex.membres', 'contacts', 'adresses', 'profile_phones', |
425f432d | 45 | 'photo', 'perte_pass', 'langues_ins', 'forums.abos', 'forums.profils'); |
46 | array_push($tables_to_clear['user_id'], 'newsletter_ins', 'auth_user_quick', 'binets_ins'); | |
787bb3d7 | 47 | $tables_to_clear['id'] = array('aliases'); |
425f432d | 48 | $tables_to_clear['contact'] = array('contacts'); |
425f432d | 49 | XDB::execute("UPDATE auth_user_md5 |
50 | SET date_ins = 0, promo_sortie = 0, nom_usage = '', password = '', perms = 'pending', | |
0e5ec860 | 51 | nationalite = '', cv = '', section = 0, date = 0, smtppass = '', mail_storage = '' |
425f432d | 52 | WHERE user_id = {?}", $uid); |
53 | XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}", | |
54 | $alias.'@'.$globals->mail->domain); | |
55 | XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}", | |
56 | $alias.'@'.$globals->mail->domain2); | |
57 | } else { | |
58 | XDB::execute("UPDATE auth_user_md5 SET password='',smtppass='' WHERE user_id={?}", $uid); | |
59 | XDB::execute("UPDATE auth_user_quick SET watch_flags='' WHERE user_id={?}", $uid); | |
0337d704 | 60 | } |
61 | ||
08cce2ff | 62 | XDB::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain); |
63 | XDB::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain2); | |
64 | ||
425f432d | 65 | foreach ($tables_to_clear as $key=>&$tables) { |
66 | foreach ($tables as $table) { | |
67 | XDB::execute("DELETE FROM $table WHERE $key={?}", $uid); | |
68 | } | |
69 | } | |
9bb8bf21 | 70 | |
c53b5964 | 71 | $mmlist = new MMList(S::v('uid'), S::v('password')); |
9bb8bf21 | 72 | $mmlist->kill($alias, $really_del); |
84270653 VZ |
73 | |
74 | // Deactivates, when available, the Google Apps account of the user. | |
75 | if ($globals->mailstorage->googleapps_domain) { | |
76 | require_once 'googleapps.inc.php'; | |
14870e88 VZ |
77 | if (GoogleAppsAccount::account_status($uid)) { |
78 | $account = new GoogleAppsAccount($uid, $alias); | |
79 | $account->suspend(); | |
80 | } | |
84270653 | 81 | } |
0337d704 | 82 | } |
83 | ||
84 | // }}} | |
85 | // {{{ function get_user_login() | |
86 | ||
0baf0741 | 87 | // Defaut callback to call when a login is not found |
88 | function _default_user_callback($login) | |
89 | { | |
90 | global $page; | |
a7d35093 | 91 | $page->trigError("Il n'y a pas d'utilisateur avec l'identifiant : $login"); |
0baf0741 | 92 | return; |
93 | } | |
94 | ||
1cc0afe7 | 95 | function _silent_user_callback($login) |
96 | { | |
97 | return; | |
98 | } | |
99 | ||
0baf0741 | 100 | function get_user_login($data, $get_forlife = false, $callback = '_default_user_callback') |
101 | { | |
0337d704 | 102 | global $globals, $page; |
103 | ||
3ab288a6 | 104 | if (is_numeric($data)) { |
08cce2ff | 105 | $res = XDB::query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $data); |
0337d704 | 106 | if ($res->numRows()) { |
107 | return $res->fetchOneCell(); | |
108 | } else { | |
0baf0741 | 109 | call_user_func($callback, $data); |
0337d704 | 110 | return false; |
111 | } | |
112 | } | |
113 | ||
114 | $data = trim(strtolower($data)); | |
115 | ||
116 | if (strstr($data, '@')===false) { | |
117 | $data = $data.'@'.$globals->mail->domain; | |
118 | } | |
787bb3d7 | 119 | |
575dd9be | 120 | list($mbox, $fqdn) = explode('@', $data); |
0337d704 | 121 | if ($fqdn == $globals->mail->domain || $fqdn == $globals->mail->domain2) { |
122 | ||
08cce2ff | 123 | $res = XDB::query("SELECT a.alias |
3ab288a6 | 124 | FROM aliases AS a |
125 | INNER JOIN aliases AS b ON (a.id = b.id AND b.type IN ('alias', 'a_vie') AND b.alias={?}) | |
126 | WHERE a.type = 'a_vie'", $mbox); | |
0337d704 | 127 | if ($res->numRows()) { |
128 | return $get_forlife ? $res->fetchOneCell() : $mbox; | |
0337d704 | 129 | } |
130 | ||
a14159bf | 131 | if (preg_match('/^(.*)\.([0-9]{4})$/u', $mbox, $matches)) { |
3ab288a6 | 132 | $res = XDB::query("SELECT a.alias |
133 | FROM aliases AS a | |
134 | INNER JOIN aliases AS b ON (a.id = b.id AND b.type IN ('alias', 'a_vie') AND b.alias={?}) | |
135 | INNER JOIN auth_user_md5 AS u ON (a.id = u.user_id AND promo = {?}) | |
136 | WHERE a.type = 'a_vie'", $matches[1], $matches[2]); | |
137 | if ($res->numRows() == 1) { | |
138 | return $res->fetchOneCell(); | |
139 | } | |
140 | } | |
0baf0741 | 141 | call_user_func($callback, $data); |
3ab288a6 | 142 | return false; |
143 | ||
0337d704 | 144 | } elseif ($fqdn == $globals->mail->alias_dom || $fqdn == $globals->mail->alias_dom2) { |
787bb3d7 | 145 | |
08cce2ff | 146 | $res = XDB::query("SELECT redirect |
3ab288a6 | 147 | FROM virtual_redirect |
148 | INNER JOIN virtual USING(vid) | |
149 | WHERE alias={?}", $mbox.'@'.$globals->mail->alias_dom); | |
0337d704 | 150 | if ($redir = $res->fetchOneCell()) { |
575dd9be | 151 | list($alias) = explode('@', $redir); |
0337d704 | 152 | } else { |
0baf0741 | 153 | call_user_func($callback, $data); |
0337d704 | 154 | $alias = false; |
155 | } | |
156 | return $alias; | |
0337d704 | 157 | } else { |
158 | ||
08cce2ff | 159 | $res = XDB::query("SELECT alias |
0337d704 | 160 | FROM aliases AS a |
161 | INNER JOIN emails AS e ON e.uid=a.id | |
162 | WHERE e.email={?} AND a.type='a_vie'", $data); | |
163 | switch ($i = $res->numRows()) { | |
164 | case 0: | |
0baf0741 | 165 | call_user_func($callback, $data); |
0337d704 | 166 | return false; |
787bb3d7 | 167 | |
0337d704 | 168 | case 1: |
169 | return $res->fetchOneCell(); | |
787bb3d7 | 170 | |
0337d704 | 171 | default: |
cab08090 | 172 | if (S::has_perms()) { |
0337d704 | 173 | $aliases = $res->fetchColumn(); |
a7d35093 | 174 | $page->trigError("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases)); |
0337d704 | 175 | } else { |
176 | $res->free(); | |
177 | } | |
178 | } | |
179 | } | |
787bb3d7 | 180 | |
0337d704 | 181 | return false; |
182 | } | |
183 | ||
184 | // }}} | |
185 | // {{{ function get_user_forlife() | |
186 | ||
0baf0741 | 187 | function get_user_forlife($data, $callback = '_default_user_callback') |
188 | { | |
189 | return get_user_login($data, true, $callback); | |
0337d704 | 190 | } |
191 | ||
192 | // }}} | |
e7545178 | 193 | // {{{ function get_users_forlife_list() |
194 | ||
0baf0741 | 195 | function get_users_forlife_list($members, $strict = false, $callback = '_default_user_callback') |
e7545178 | 196 | { |
1cc0afe7 | 197 | if (!is_array($members)) { |
198 | if (strlen(trim($members)) == 0) { | |
199 | return null; | |
200 | } | |
201 | $members = explode(' ', $members); | |
e7545178 | 202 | } |
e7545178 | 203 | if ($members) { |
204 | $list = array(); | |
205 | foreach ($members as $i => $alias) { | |
0baf0741 | 206 | if (($login = get_user_forlife($alias, $callback)) !== false) { |
e7545178 | 207 | $list[$i] = $login; |
208 | } else if(!$strict) { | |
209 | $list[$i] = $alias; | |
210 | } | |
211 | } | |
212 | return $list; | |
213 | } | |
214 | return null; | |
215 | } | |
216 | ||
217 | // }}} | |
8b10988d | 218 | // {{{ function has_user_right() |
219 | function has_user_right($pub, $view = 'private') { | |
220 | if ($pub == $view) return true; | |
787bb3d7 | 221 | // all infos available for private |
8b10988d | 222 | if ($view == 'private') return true; |
787bb3d7 | 223 | // public infos available for all |
8b10988d | 224 | if ($pub == 'public') return true; |
225 | // here we have view = ax or public, and pub = ax or private, and pub != view | |
787bb3d7 | 226 | return false; |
8b10988d | 227 | } |
228 | // }}} | |
0baf0741 | 229 | // {{{ function get_not_registered_user() |
230 | ||
231 | function get_not_registered_user($login, $iterator = false) | |
232 | { | |
233 | global $globals; | |
234 | @list($login, $domain) = explode('@', $login); | |
235 | if ($domain && $domain != $globals->mail->domain && $domain != $globals->mail->domain2) { | |
236 | return null; | |
237 | } | |
238 | @list($prenom, $nom, $promo) = explode('.', $login); | |
239 | $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%") | |
240 | AND REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%")'; | |
241 | if ($promo) { | |
242 | if (preg_match('/^[0-9]{2}$/', $promo)) { | |
243 | $where .= 'AND MOD(promo, 100) = {?}'; | |
244 | } elseif (preg_match('/^[0-9]{4}$/', $promo)) { | |
245 | $where .= 'AND promo = {?}'; | |
246 | } | |
247 | } | |
248 | $sql = "SELECT user_id, nom, prenom, promo | |
249 | FROM auth_user_md5 | |
250 | WHERE $where | |
787bb3d7 | 251 | ORDER BY promo, nom, prenom"; |
0baf0741 | 252 | if ($iterator) { |
253 | return XDB::iterator($sql, $nom, $prenom, $promo); | |
254 | } else { | |
255 | $res = XDB::query($sql, $nom, $prenom, $promo); | |
256 | return $res->fetchAllAssoc(); | |
257 | } | |
258 | } | |
259 | ||
260 | // }}} | |
9039c94d | 261 | // {{{ function get_user_details_pro() |
262 | ||
8b10988d | 263 | function get_user_details_pro($uid, $view = 'private') |
9039c94d | 264 | { |
9039c94d | 265 | $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, |
dd502514 | 266 | e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.entrid, |
bde2be3b GB |
267 | gp.pays AS countrytxt, gr.name AS region, e.entrid, |
268 | e.pub, e.adr_pub, e.email, e.email_pub, e.web | |
9039c94d | 269 | FROM entreprises AS e |
270 | LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) | |
271 | LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) | |
272 | LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) | |
273 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country) | |
274 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region) | |
275 | WHERE e.uid = {?} | |
276 | ORDER BY e.entrid"; | |
08cce2ff | 277 | $res = XDB::query($sql, $uid); |
8b10988d | 278 | $all_pro = $res->fetchAllAssoc(); |
279 | foreach ($all_pro as $i => $pro) { | |
280 | if (!has_user_right($pro['pub'], $view)) | |
281 | unset($all_pro[$i]); | |
282 | else { | |
283 | if (!has_user_right($pro['adr_pub'], $view)) { | |
dd502514 | 284 | if ($pro['adr1'] == '' && |
285 | $pro['adr2'] == '' && | |
286 | $pro['adr3'] == '' && | |
287 | $pro['postcode'] == '' && | |
288 | $pro['city'] == '' && | |
289 | $pro['countrytxt'] == '' && | |
290 | $pro['region'] == '') { | |
291 | $all_pro[$i]['adr_pub'] = $view; | |
292 | } else { | |
293 | $all_pro[$i]['adr1'] = ''; | |
294 | $all_pro[$i]['adr2'] = ''; | |
295 | $all_pro[$i]['adr3'] = ''; | |
296 | $all_pro[$i]['postcode'] = ''; | |
297 | $all_pro[$i]['city'] = ''; | |
298 | $all_pro[$i]['countrytxt'] = ''; | |
299 | $all_pro[$i]['region'] = ''; | |
300 | } | |
8b10988d | 301 | } |
bde2be3b GB |
302 | $sql = "SELECT pub AS tel_pub, tel_type, display_tel AS tel, comment |
303 | FROM profile_phones AS t | |
304 | WHERE uid = {?} AND link_type = 'pro' AND link_id = {?} | |
305 | ORDER BY link_id, tel_type DESC, tel_id"; | |
306 | $restel = XDB::iterator($sql, $uid, $pro['entrid']); | |
307 | while ($nexttel = $restel->next()) { | |
308 | if (has_user_right($nexttel['tel_pub'], $view)) { | |
309 | if (!isset($all_pro[$i]['tels'])) { | |
310 | $all_pro[$i]['tels'] = array($nexttel); | |
311 | } else { | |
312 | $all_pro[$i]['tels'][] = $nexttel; | |
313 | } | |
dd502514 | 314 | } |
8b10988d | 315 | } |
316 | if (!has_user_right($pro['email_pub'], $view)) { | |
dd502514 | 317 | if ($pro['email'] == '') |
318 | $all_pro[$i]['email_pub'] = $view; | |
319 | else | |
320 | $all_pro[$i]['email'] = ''; | |
8b10988d | 321 | } |
322 | if ($all_pro[$i]['adr1'] == '' && | |
323 | $all_pro[$i]['adr2'] == '' && | |
324 | $all_pro[$i]['adr3'] == '' && | |
325 | $all_pro[$i]['postcode'] == '' && | |
326 | $all_pro[$i]['city'] == '' && | |
327 | $all_pro[$i]['countrytxt'] == '' && | |
328 | $all_pro[$i]['region'] == '' && | |
329 | $all_pro[$i]['entreprise'] == '' && | |
330 | $all_pro[$i]['fonction'] == '' && | |
331 | $all_pro[$i]['secteur'] == '' && | |
332 | $all_pro[$i]['poste'] == '' && | |
bde2be3b | 333 | (!isset($all_pro[$i]['tels'])) && |
8b10988d | 334 | $all_pro[$i]['email'] == '') |
335 | unset($all_pro[$i]); | |
336 | } | |
337 | } | |
338 | if (!count($all_pro)) return false; | |
339 | return $all_pro; | |
9039c94d | 340 | } |
341 | ||
342 | // }}} | |
433336f3 | 343 | // {{{ function get_user_details_adr() |
344 | ||
8b10988d | 345 | function get_user_details_adr($uid, $view = 'private') { |
8b10988d | 346 | $sql = "SELECT a.adrid, a.adr1,a.adr2,a.adr3,a.postcode,a.city, |
347 | gp.pays AS countrytxt,a.region, a.regiontxt, | |
348 | FIND_IN_SET('active', a.statut) AS active, a.adrid, | |
349 | FIND_IN_SET('res-secondaire', a.statut) AS secondaire, | |
646a4582 | 350 | a.pub, gp.display, a.comment |
8b10988d | 351 | FROM adresses AS a |
352 | LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) | |
353 | WHERE uid= {?} AND NOT FIND_IN_SET('pro',a.statut) | |
354 | ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; | |
08cce2ff | 355 | $res = XDB::query($sql, $uid); |
8b10988d | 356 | $all_adr = $res->fetchAllAssoc(); |
357 | $adrid_index = array(); | |
358 | foreach ($all_adr as $i => $adr) { | |
359 | if (!has_user_right($adr['pub'], $view)) | |
360 | unset($all_adr[$i]); | |
361 | else | |
362 | $adrid_index[$adr['adrid']] = $i; | |
363 | } | |
787bb3d7 | 364 | |
bde2be3b | 365 | $sql = "SELECT link_id AS adrid, pub AS tel_pub, tel_type, display_tel AS tel, tel_id AS telid, comment |
b235d980 | 366 | FROM profile_phones AS t |
5e4417a9 GB |
367 | WHERE uid = {?} AND link_type = 'address' |
368 | ORDER BY link_id, tel_type DESC, tel_id"; | |
08cce2ff | 369 | $restel = XDB::iterator($sql, $uid); |
8b10988d | 370 | while ($nexttel = $restel->next()) { |
371 | if (has_user_right($nexttel['tel_pub'], $view)) { | |
372 | $adrid = $nexttel['adrid']; | |
373 | unset($nexttel['adrid']); | |
374 | if (isset($adrid_index[$adrid])) { | |
787bb3d7 | 375 | if (!isset($all_adr[$adrid_index[$adrid]]['tels'])) |
8b10988d | 376 | $all_adr[$adrid_index[$adrid]]['tels'] = array($nexttel); |
377 | else | |
378 | $all_adr[$adrid_index[$adrid]]['tels'][] = $nexttel; | |
379 | } | |
380 | } | |
381 | } | |
382 | return $all_adr; | |
383 | } | |
433336f3 | 384 | |
385 | // }}} | |
0337d704 | 386 | // {{{ function get_user_details() |
387 | ||
8b10988d | 388 | function &get_user_details($login, $from_uid = '', $view = 'private') |
0337d704 | 389 | { |
0337d704 | 390 | $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv, |
f6c71069 | 391 | u.perms IN ('admin','user','disabled') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces, |
bde2be3b GB |
392 | q.profile_nick AS nickname, q.profile_from_ax, q.profile_freetext AS freetext, |
393 | q.profile_freetext_pub AS freetext_pub, | |
0337d704 | 394 | q.profile_medals_pub AS medals_pub, |
395 | IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166, | |
396 | a.alias AS forlife, a2.alias AS bestalias, | |
397 | c.uid IS NOT NULL AS is_contact, | |
398 | s.text AS section, p.x, p.y, p.pub AS photo_pub, | |
dd502514 | 399 | u.matricule_ax, |
d9caac6f | 400 | m.expertise != '' AS is_referent, |
cd5bd7dc PC |
401 | (COUNT(e.email) > 0 OR FIND_IN_SET('googleapps', u.mail_storage) > 0) AS actif, |
402 | nd.display AS name_display, nd.tooltip AS name_tooltip | |
0337d704 | 403 | FROM auth_user_md5 AS u |
404 | INNER JOIN auth_user_quick AS q USING(user_id) | |
405 | INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') | |
406 | INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags)) | |
407 | LEFT JOIN contacts AS c ON (c.uid = {?} and c.contact = u.user_id) | |
408 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) | |
409 | INNER JOIN sections AS s ON (s.id = u.section) | |
787bb3d7 | 410 | LEFT JOIN photo AS p ON (p.uid = u.user_id) |
0337d704 | 411 | LEFT JOIN mentor AS m ON (m.uid = u.user_id) |
d9caac6f | 412 | LEFT JOIN emails AS e ON (e.uid = u.user_id AND e.flags='active') |
cd5bd7dc | 413 | INNER JOIN profile_names_display AS nd ON (nd.user_id = u.user_id) |
d9caac6f | 414 | WHERE a.alias = {?} |
415 | GROUP BY u.user_id"; | |
08cce2ff | 416 | $res = XDB::query($reqsql, $from_uid, $login); |
0337d704 | 417 | $user = $res->fetchOneAssoc(); |
418 | $uid = $user['user_id']; | |
8b10988d | 419 | // hide orange status, cv, nickname, section |
420 | if (!has_user_right('private', $view)) { | |
421 | $user['promo_sortie'] = $user['promo'] + 3; | |
422 | $user['cv'] = ''; | |
423 | $user['nickname'] = ''; | |
424 | $user['section'] = ''; | |
425 | } | |
1052148d | 426 | |
8b10988d | 427 | // hide freetext |
dd502514 | 428 | if (!has_user_right($user['freetext_pub'], $view)) { |
429 | if ($user['freetext'] == '') | |
430 | $user['freetext_pub'] = $view; | |
431 | else | |
432 | $user['freetext'] = ''; | |
433 | } | |
0337d704 | 434 | |
bde2be3b GB |
435 | $sql = "SELECT pub AS tel_pub, tel_type, display_tel AS tel, comment |
436 | FROM profile_phones AS t | |
437 | WHERE uid = {?} AND link_type = 'user' | |
438 | ORDER BY tel_type DESC, tel_id"; | |
439 | $restel = XDB::iterator($sql, $uid); | |
440 | while ($nexttel = $restel->next()) { | |
441 | if (has_user_right($nexttel['tel_pub'], $view)) { | |
442 | if (!isset($user['tels'])) { | |
443 | $user['tels'] = array($nexttel); | |
444 | } else { | |
445 | $user['tels'][] = $nexttel; | |
446 | } | |
447 | } | |
448 | } | |
449 | ||
8b10988d | 450 | $user['adr_pro'] = get_user_details_pro($uid, $view); |
451 | $user['adr'] = get_user_details_adr($uid, $view); | |
0337d704 | 452 | |
8b10988d | 453 | if (has_user_right('private', $view)) { |
454 | $sql = "SELECT text | |
455 | FROM binets_ins | |
456 | LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id | |
457 | WHERE user_id = {?}"; | |
08cce2ff | 458 | $res = XDB::query($sql, $uid); |
8b10988d | 459 | $user['binets'] = $res->fetchColumn(); |
460 | $user['binets_join'] = join(', ', $user['binets']); | |
787bb3d7 | 461 | |
b37aacd9 FB |
462 | $res = XDB::iterRow("SELECT a.diminutif, a.nom, a.site |
463 | FROM groupex.asso AS a | |
464 | LEFT JOIN groupex.membres AS m ON (m.asso_id = a.id) | |
465 | WHERE m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions') | |
466 | AND pub = 'public'", $uid); | |
8b10988d | 467 | $user['gpxs'] = Array(); |
ae2f9e35 | 468 | $user['gpxs_name'] = Array(); |
b37aacd9 FB |
469 | while (list($gxd, $gxt, $gxu) = $res->next()) { |
470 | if (!$gxu) { | |
471 | $gxu = 'http://www.polytechnique.net/' . $gxd; | |
472 | } | |
473 | $user['gpxs'][] = '<span title="' . pl_entities($gxt) . "\"><a href=\"$gxu\">$gxd</a></span>"; | |
ae2f9e35 | 474 | $user['gpxs_name'][] = $gxt; |
787bb3d7 | 475 | } |
8b10988d | 476 | $user['gpxs_join'] = join(', ', $user['gpxs']); |
79a5acea | 477 | } |
0337d704 | 478 | |
08cce2ff | 479 | $res = XDB::iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type |
ae2f9e35 | 480 | FROM applis_ins |
481 | INNER JOIN applis_def ON applis_def.id = applis_ins.aid | |
482 | WHERE uid={?} | |
483 | ORDER BY ordre", $uid); | |
787bb3d7 | 484 | |
0337d704 | 485 | $user['applis_fmt'] = Array(); |
dd502514 | 486 | $user['formation'] = Array(); |
0337d704 | 487 | while (list($txt, $url, $type) = $res->next()) { |
dd502514 | 488 | $user['formation'][] = $txt." ".$type; |
0337d704 | 489 | require_once('applis.func.inc.php'); |
490 | $user['applis_fmt'][] = applis_fmt($type, $txt, $url); | |
491 | } | |
492 | $user['applis_join'] = join(', ', $user['applis_fmt']); | |
493 | ||
8b10988d | 494 | if (has_user_right($user['medals_pub'], $view)) { |
5e70bf24 | 495 | $res = XDB::iterator("SELECT m.id, m.text AS medal, m.type, s.gid, g.text AS grade |
ae2f9e35 | 496 | FROM profile_medals_sub AS s |
497 | INNER JOIN profile_medals AS m ON ( s.mid = m.id ) | |
498 | LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) | |
499 | WHERE s.uid = {?}", $uid); | |
8b10988d | 500 | $user['medals'] = Array(); |
501 | while ($tmp = $res->next()) { | |
502 | $user['medals'][] = $tmp; | |
503 | } | |
0337d704 | 504 | } |
505 | ||
d1a2252a | 506 | $user['networking'] = Array(); |
dc6378df | 507 | $res = XDB::iterator("SELECT n.address, n.pub, m.network_type AS type, m.name, m.filter, m.link |
d1a2252a GB |
508 | FROM profile_networking AS n |
509 | INNER JOIN profile_networking_enum AS m ON (n.network_type = m.network_type) | |
510 | WHERE n.uid = {?}", $uid); | |
511 | while($network = $res->next()) | |
512 | { | |
513 | if (has_user_right($network['pub'], $view)) { | |
dc6378df | 514 | $network['link'] = str_replace('%s', $network['address'], $network['link']); |
d1a2252a GB |
515 | $user['networking'][] = $network; |
516 | } | |
517 | } | |
518 | ||
0337d704 | 519 | return $user; |
520 | } | |
dd502514 | 521 | // }}} |
522 | // {{{ function add_user_address() | |
523 | function add_user_address($uid, $adrid, $adr) { | |
08cce2ff | 524 | XDB::execute( |
dd502514 | 525 | "INSERT INTO adresses (`uid`, `adrid`, `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `datemaj`, `pub`) ( |
526 | SELECT u.user_id, {?}, {?}, {?}, {?}, {?}, {?}, gp.a2, NOW(), {?} | |
527 | FROM auth_user_md5 AS u | |
528 | LEFT JOIN geoloc_pays AS gp ON (gp.pays LIKE {?} OR gp.country LIKE {?} OR gp.a2 LIKE {?}) | |
529 | WHERE u.user_id = {?} | |
530 | LIMIT 1)", | |
531 | $adrid, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], $adr['pub'], $adr['countrytxt'], $adr['countrytxt'], $adr['countrytxt'], $uid); | |
532 | if (isset($adr['tels']) && is_array($adr['tels'])) { | |
533 | $telid = 0; | |
534 | foreach ($adr['tels'] as $tel) if ($tel['tel']) { | |
b235d980 | 535 | add_user_tel($uid, 'address', $adrid, $telid, $tel); |
dd502514 | 536 | $telid ++; |
537 | } | |
538 | } | |
539 | } | |
540 | // }}} | |
541 | // {{{ function update_user_address() | |
542 | function update_user_address($uid, $adrid, $adr) { | |
dd502514 | 543 | // update address |
08cce2ff | 544 | XDB::execute( |
787bb3d7 | 545 | "UPDATE adresses AS a LEFT JOIN geoloc_pays AS gp ON (gp.pays = {?}) |
dd502514 | 546 | SET `adr1` = {?}, `adr2` = {?}, `adr3` = {?}, |
547 | `postcode` = {?}, `city` = {?}, a.`country` = gp.a2, `datemaj` = NOW(), `pub` = {?} | |
548 | WHERE adrid = {?} AND uid = {?}", | |
549 | $adr['country_txt'], | |
550 | $adr['adr1'], $adr['adr2'], $adr['adr3'], | |
551 | $adr['postcode'], $adr['city'], $adr['pub'], $adrid, $uid); | |
552 | if (isset($adr['tels']) && is_array($adr['tels'])) { | |
b235d980 | 553 | $res = XDB::query("SELECT tel_id FROM profile_phones WHERE uid = {?} AND link_type = 'address' AND link_id = {?} ORDER BY tel_id", $uid, $adrid); |
dd502514 | 554 | $telids = $res->fetchColumn(); |
555 | foreach ($adr['tels'] as $tel) { | |
556 | if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) { | |
b235d980 | 557 | remove_user_tel($uid, 'address', $adrid, $tel['telid']); |
dd502514 | 558 | if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]); |
559 | } else if (isset($tel['telid'])) { | |
b235d980 | 560 | update_user_tel($uid, 'address', $adrid, $tel['telid'], $tel); |
dd502514 | 561 | } else { |
562 | for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++); | |
b235d980 | 563 | add_user_tel($uid, 'address', $adrid, $telid, $tel); |
dd502514 | 564 | } |
565 | } | |
566 | } | |
567 | } | |
568 | // }}} | |
569 | // {{{ function remove_user_address() | |
570 | function remove_user_address($uid, $adrid) { | |
08cce2ff | 571 | XDB::execute("DELETE FROM adresses WHERE adrid = {?} AND uid = {?}", $adrid, $uid); |
b235d980 | 572 | XDB::execute("DELETE FROM profile_phones WHERE link_id = {?} AND uid = {?} AND link_type = 'address'", $adrid, $uid); |
dd502514 | 573 | } |
574 | // }}} | |
575 | // {{{ function add_user_tel() | |
b235d980 | 576 | function add_user_tel($uid, $link_type, $link_id, $telid, $tel) { |
5e4417a9 GB |
577 | require('profil.func.inc.php'); |
578 | $fmt_phone = format_phone_number($tel['tel']); | |
579 | $disp_phone = format_display_number($fmt_phone, $error); | |
b235d980 GB |
580 | XDB::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, search_tel, display_tel, pub) |
581 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
582 | $uid, $link_type, $link_id, $telid, $tel['tel_type'], $fmt_phone, $disp_phone, $tel['tel_pub']); | |
dd502514 | 583 | } |
584 | // }}} | |
585 | // {{{ function update_user_tel() | |
b235d980 | 586 | function update_user_tel($uid, $link_type, $link_id, $telid, $tel) { |
5e4417a9 GB |
587 | require('profil.func.inc.php'); |
588 | $fmt_phone = format_phone_number($tel['tel']); | |
589 | $disp_phone = format_display_number($fmt_phone, $error); | |
b235d980 GB |
590 | XDB::execute("UPDATE profile_phones SET search_tel = {?}, display_tel = {?}, tel_type = {?}, pub = {?} |
591 | WHERE link_type = {?} AND tel_id = {?} AND link_id = {?} AND uid = {?}", | |
5e4417a9 | 592 | $fmt_phone, $disp_phone, $tel['tel_type'], $tel['tel_pub'], |
b235d980 | 593 | $link_type, $telid, $link_id, $uid); |
dd502514 | 594 | } |
595 | // }}} | |
596 | // {{{ function remove_user_tel() | |
b235d980 GB |
597 | function remove_user_tel($uid, $link_type, $link_id, $telid) { |
598 | XDB::execute("DELETE FROM profile_phones WHERE tel_id = {?} AND link_id = {?} AND uid = {?} AND link_type = {?}", | |
599 | $telid, $link_id, $uid, $link_type); | |
dd502514 | 600 | } |
601 | // }}} | |
602 | // {{{ function add_user_pro() | |
603 | function add_user_pro($uid, $entrid, $pro) { | |
08cce2ff | 604 | XDB::execute( |
dd502514 | 605 | "INSERT INTO entreprises (`uid`, `entrid`, `entreprise`, `poste`, `secteur`, `ss_secteur`, `fonction`, |
b235d980 | 606 | `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `region`, `email`, `web`, `pub`, `adr_pub`, `email_pub`) |
dd502514 | 607 | SELECT u.user_id, {?}, {?}, {?}, s.id, ss.id, f.id, |
608 | {?}, {?}, {?}, {?}, {?}, gp.a2, gr.region, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?} | |
609 | FROM auth_user_md5 AS u | |
610 | LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?}) | |
611 | LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?}) | |
612 | LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?}) | |
613 | LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?}) | |
614 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?}) | |
615 | WHERE u.user_id = {?} | |
616 | LIMIT 1", | |
617 | $entrid, $pro['entreprise'], $pro['poste'], | |
b235d980 | 618 | $pro['adr1'], $pro['adr2'], $pro['adr3'], $pro['postcode'], $pro['city'], $pro['email'], $pro['web'], $pro['pub'], $pro['adr_pub'], $pro['email_pub'], |
dd502514 | 619 | $pro['secteur'], $pro['sous_secteur'], $pro['fonction'], $pro['fonction'], |
620 | $pro['countrytxt'], $pro['countrytxt'], $pro['region'], | |
621 | $uid); | |
b235d980 GB |
622 | if (isset($pro['tels']) && is_array($pro['tels'])) { |
623 | $telid = 0; | |
624 | foreach ($pro['tels'] as $tel) { | |
625 | if ($pro['tel']) { | |
626 | add_user_tel($uid, 'pro', $entrid, $telid, $tel); | |
627 | $telid ++; | |
628 | } | |
629 | } | |
630 | } | |
dd502514 | 631 | } |
632 | // }}} | |
633 | // {{{ function update_user_pro() | |
634 | function update_user_pro($uid, $entrid, $pro) { | |
dd502514 | 635 | $join = ""; |
636 | $set = ""; | |
637 | $args_join = array(); | |
638 | $args_set = array(); | |
787bb3d7 | 639 | |
dd502514 | 640 | $join .= "LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?}) |
641 | LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?}) | |
642 | LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})"; | |
643 | $args_join[] = $pro['secteur']; | |
644 | $args_join[] = $pro['sous_secteur']; | |
645 | $args_join[] = $pro['fonction']; | |
646 | $args_join[] = $pro['fonction']; | |
647 | $set .= ", e.`entreprise` = {?}, e.`secteur` = s.id, e.`ss_secteur` = ss.id, e.`fonction` = f.id, e.`poste`= {?}, e.`web` = {?}, e.`pub` = {?}"; | |
648 | $args_set[] = $pro['entreprise']; | |
649 | $args_set[] = $pro['poste']; | |
650 | $args_set[] = $pro['web']; | |
651 | $args_set[] = $pro['pub']; | |
787bb3d7 | 652 | |
dd502514 | 653 | if (isset($pro['adr1'])) { |
654 | $join .= "LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?}) | |
655 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?})"; | |
656 | $args_join[] = $pro['countrytxt']; | |
657 | $args_join[] = $pro['countrytxt']; | |
658 | $args_join[] = $pro['region']; | |
659 | $set .= ", e.`adr1` = {?}, e.`adr2` = {?}, e.`adr3` = {?}, e.`postcode` = {?}, e.`city` = {?}, e.`country` = gp.a2, e.`region` = gr.region, e.`adr_pub` = {?}"; | |
660 | $args_set[] = $pro['adr1']; | |
661 | $args_set[] = $pro['adr2']; | |
662 | $args_set[] = $pro['adr3']; | |
663 | $args_set[] = $pro['postcode']; | |
664 | $args_set[] = $pro['city']; | |
665 | $args_set[] = $pro['adr_pub']; | |
666 | } | |
787bb3d7 | 667 | |
dd502514 | 668 | if (isset($pro['email'])) { |
669 | $set .= ", e.`email` = {?}, e.`email_pub` = {?}"; | |
670 | $args_set[] = $pro['email']; | |
671 | $args_set[] = $pro['email_pub']; | |
787bb3d7 | 672 | } |
dd502514 | 673 | $query = "UPDATE entreprises AS e ".$join." SET ".substr($set,1)." WHERE e.uid = {?} AND e.entrid = {?}"; |
674 | $args_where = array($uid, $entrid); | |
675 | $args = array_merge(array($query), $args_join, $args_set, $args_where); | |
a3a049fc | 676 | call_user_func_array(array('XDB', 'execute'), $args); |
b235d980 GB |
677 | |
678 | ||
679 | if (isset($pro['tels']) && is_array($pro['tels'])) { | |
680 | $res = XDB::query("SELECT tel_id FROM profile_phones WHERE uid = {?} AND link_type = 'pro' AND link_id = {?} ORDER BY tel_id", $uid, $entrid); | |
681 | $telids = $res->fetchColumn(); | |
682 | foreach ($pro['tels'] as $tel) { | |
683 | if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) { | |
684 | remove_user_tel($uid, 'pro', $entrid, $tel['telid']); | |
685 | if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]); | |
686 | } else if (isset($tel['telid'])) { | |
687 | update_user_tel($uid, 'pro', $entrid, $tel['telid'], $tel); | |
688 | } else { | |
689 | for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++); | |
690 | add_user_tel($uid, 'pro', $entrid, $telid, $tel); | |
691 | } | |
692 | } | |
693 | } | |
dd502514 | 694 | } |
695 | // }}} | |
696 | // {{{ function remove_user_pro() | |
697 | function remove_user_pro($uid, $entrid) { | |
08cce2ff | 698 | XDB::execute("DELETE FROM entreprises WHERE entrid = {?} AND uid = {?}", $entrid, $uid); |
b235d980 | 699 | XDB::execute("DELETE FROM profile_phones WHERE link_id = {?} AND uid = {?} AND link_type = 'pro'", $entrid, $uid); |
dd502514 | 700 | } |
701 | // }}} | |
b235d980 | 702 | // {{{ function set_user_details_addresses() |
dd502514 | 703 | function set_user_details_addresses($uid, $adrs) { |
08cce2ff | 704 | $res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid); |
dd502514 | 705 | $adrids = $res->fetchColumn(); |
706 | foreach ($adrs as $adr) { | |
707 | if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) { | |
708 | remove_user_address($uid, $adr['adrid']); | |
709 | if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]); | |
710 | } else if (isset($adr['adrid'])) { | |
711 | update_user_address($uid, $adr['adrid'], $adr); | |
712 | } else { | |
713 | for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++); | |
714 | add_user_address($uid, $adrid, $adr); | |
715 | $adrids[$adrid-1] = $adrid; | |
716 | } | |
717 | } | |
718 | require_once 'geoloc.inc.php'; | |
719 | localize_addresses($uid); | |
720 | } | |
721 | // }}} | |
722 | // {{{ function set_user_details_pro() | |
723 | ||
724 | function set_user_details_pro($uid, $pros) | |
725 | { | |
08cce2ff | 726 | $res = XDB::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid); |
dd502514 | 727 | $entrids = $res->fetchColumn(); |
728 | foreach ($pros as $pro) { | |
729 | if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) { | |
730 | remove_user_pro($uid, $pro['entrid']); | |
731 | if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]); | |
732 | } else if (isset($pro['entrid'])) { | |
733 | update_user_pro($uid, $pro['entrid'], $pro); | |
734 | } else { | |
735 | for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++); | |
736 | add_user_pro($uid, $entrid, $pro); | |
737 | } | |
738 | } | |
739 | } | |
0337d704 | 740 | |
741 | // }}} | |
dd502514 | 742 | // {{{ function set_user_details() |
743 | function set_user_details($uid, $details) { | |
dd502514 | 744 | if (isset($details['nom_usage'])) { |
08cce2ff | 745 | XDB::execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($details['nom_usage']), $uid); |
dd502514 | 746 | } |
dd502514 | 747 | if (isset($details['nationalite'])) { |
08cce2ff | 748 | XDB::execute( |
dd502514 | 749 | "UPDATE auth_user_md5 AS u |
750 | INNER JOIN geoloc_pays AS gp | |
751 | SET u.nationalite = gp.a2 | |
752 | WHERE (gp.a2 = {?} OR gp.nat = {?}) | |
753 | AND u.user_id = {?}", $details['nationalite'], $details['nationalite'], $uid); | |
754 | } | |
755 | if (isset($details['adr']) && is_array($details['adr'])) | |
756 | set_user_details_addresses($uid, $details['adr']); | |
757 | if (isset($details['adr_pro']) && is_array($details['adr_pro'])) | |
758 | set_user_details_pro($uid, $details['adr_pro']); | |
759 | if (isset($details['binets']) && is_array($details['binets'])) { | |
08cce2ff | 760 | XDB::execute("DELETE FROM binets_ins WHERE user_id = {?}", $uid); |
dd502514 | 761 | foreach ($details['binets'] as $binet) |
08cce2ff | 762 | XDB::execute( |
dd502514 | 763 | "INSERT INTO binets_ins (`user_id`, `binet_id`) |
764 | SELECT {?}, id FROM binets_def WHERE text = {?} LIMIT 1", | |
787bb3d7 | 765 | $uid, $binet); |
dd502514 | 766 | } |
767 | if (isset($details['gpxs']) && is_array($details['gpxs'])) { | |
08cce2ff | 768 | XDB::execute("DELETE FROM groupesx_ins WHERE user_id = {?}", $uid); |
dd502514 | 769 | foreach ($details['gpxs'] as $groupex) { |
a14159bf | 770 | if (preg_match('/<a href="[^"]*">([^<]+)</a>/u', $groupex, $a)) $groupex = $a[1]; |
08cce2ff | 771 | XDB::execute( |
dd502514 | 772 | "INSERT INTO groupesx_ins (`user_id`, `binet_id`) |
773 | SELECT {?}, id FROM groupesx_def WHERE text = {?} LIMIT 1", | |
774 | $uid, $groupex); | |
787bb3d7 | 775 | } |
dd502514 | 776 | } |
b235d980 GB |
777 | if (isset($details['tels']) && is_array($details['tels'])) { |
778 | $res = XDB::query("SELECT tel_id FROM profile_phones WHERE uid = {?} AND link_type = 'user' ORDER BY tel_id", $uid); | |
779 | $telids = $res->fetchColumn(); | |
780 | foreach ($details['tels'] as $tel) { | |
781 | if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) { | |
782 | remove_user_tel($uid, 'user', 0, $tel['telid']); | |
783 | if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]); | |
784 | } else if (isset($tel['telid'])) { | |
785 | update_user_tel($uid, 'user', 0, $tel['telid'], $tel); | |
786 | } else { | |
787 | for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++); | |
788 | add_user_tel($uid, 'user', 0, $telid, $tel); | |
789 | } | |
790 | } | |
791 | } | |
792 | ||
dd502514 | 793 | // applis |
794 | // medals | |
795 | } | |
796 | // }}} | |
0337d704 | 797 | // {{{ function _user_reindex |
798 | ||
c0c9f772 | 799 | function _user_reindex($uid, $keys, $muls, $pubs) |
94f6c381 | 800 | { |
0337d704 | 801 | foreach ($keys as $i => $key) { |
802 | if ($key == '') { | |
803 | continue; | |
804 | } | |
805 | $toks = preg_split('/[ \'\-]+/', $key); | |
806 | $token = ""; | |
807 | $first = 5; | |
808 | while ($toks) { | |
809 | $token = strtolower(replace_accent(array_pop($toks) . $token)); | |
810 | $score = ($toks ? 0 : 10 + $first) * $muls[$i]; | |
c0c9f772 | 811 | XDB::execute("REPLACE INTO search_name (token, uid, soundex, score, flags) |
812 | VALUES ({?}, {?}, {?}, {?}, {?})", | |
813 | $token, $uid, soundex_fr($token), $score, $pubs[$i] ? 'public' : ''); | |
0337d704 | 814 | $first = 0; |
815 | } | |
816 | } | |
94f6c381 | 817 | $res = XDB::query("SELECT nom_ini, nom, nom_usage, prenom_ini, prenom, promo, matricule |
818 | FROM auth_user_md5 | |
819 | WHERE user_id = {?}", $uid); | |
820 | if (!$res->numRows()) { | |
821 | unset($res); | |
822 | return; | |
823 | } | |
824 | $array = $res->fetchOneRow(); | |
825 | $promo = intval(array_pop($array)); | |
826 | $mat = array_shift($array); | |
827 | array_walk($array, 'soundex_fr'); | |
828 | XDB::execute("REPLACE INTO recherche_soundex | |
829 | SET matricule = {?}, nom1_soundex = {?}, nom2_soundex= {?}, nom3_soundex = {?}, | |
830 | prenom1_soundex = {?}, prenom2_soundex= {?}, promo = {?}", | |
831 | $mat, $array[0], $array[1], $array[2], $array[3], $array[4], $promo); | |
832 | unset($res); | |
833 | unset($array); | |
0337d704 | 834 | } |
835 | ||
836 | // }}} | |
837 | // {{{ function user_reindex | |
838 | ||
839 | function user_reindex($uid) { | |
08cce2ff | 840 | XDB::execute("DELETE FROM search_name WHERE uid={?}", $uid); |
841 | $res = XDB::query("SELECT prenom, nom, nom_usage, profile_nick FROM auth_user_md5 INNER JOIN auth_user_quick USING(user_id) WHERE auth_user_md5.user_id = {?}", $uid); | |
36f58fcf | 842 | if ($res->numRows()) { |
c0c9f772 | 843 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2), array(true, true, true, false)); |
36f58fcf | 844 | } else { // not in auth_user_quick => still "pending" |
845 | $res = XDB::query("SELECT prenom, nom, nom_usage FROM auth_user_md5 WHERE auth_user_md5.user_id = {?}", $uid); | |
846 | if ($res->numRows()) { | |
c0c9f772 | 847 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1), array(true, true, true)); |
36f58fcf | 848 | } |
849 | } | |
0337d704 | 850 | } |
851 | ||
852 | // }}} | |
433336f3 | 853 | // {{{ function set_new_usage() |
74c55fd6 | 854 | |
a11b5424 | 855 | function set_new_usage($uid, $usage, $alias=false) |
787bb3d7 | 856 | { |
74c55fd6 | 857 | XDB::execute("UPDATE auth_user_md5 set nom_usage={?} WHERE user_id={?}",$usage ,$uid); |
858 | XDB::execute("DELETE FROM aliases WHERE FIND_IN_SET('usage',flags) AND id={?}", $uid); | |
859 | if ($alias && $usage) { | |
860 | XDB::execute("UPDATE aliases SET flags=flags & 255-1 WHERE id={?}", $uid); | |
861 | XDB::execute("INSERT INTO aliases VALUES({?}, 'alias', 'usage,bestalias', {?}, null)", | |
862 | $alias, $uid); | |
863 | } | |
864 | $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid); | |
a11b5424 | 865 | if ($r->numRows() == "") { |
74c55fd6 | 866 | XDB::execute("UPDATE aliases SET flags = 1 | flags WHERE id = {?} LIMIT 1", $uid); |
a11b5424 | 867 | $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid); |
74c55fd6 | 868 | } |
74c55fd6 | 869 | user_reindex($uid); |
a11b5424 | 870 | return $r->fetchOneCell(); |
74c55fd6 | 871 | } |
872 | ||
433336f3 | 873 | // }}} |
874 | // {{{ function get_X_mat | |
875 | function get_X_mat($ourmat) | |
876 | { | |
787bb3d7 | 877 | if (!preg_match('/^[0-9]{8}$/', $ourmat)) { |
433336f3 | 878 | // le matricule de notre base doit comporter 8 chiffres |
879 | return 0; | |
787bb3d7 FB |
880 | } |
881 | ||
433336f3 | 882 | $year = intval(substr($ourmat, 0, 4)); |
883 | $rang = intval(substr($ourmat, 5, 3)); | |
884 | if ($year < 1996) { | |
787bb3d7 | 885 | return; |
433336f3 | 886 | } elseif ($year < 2000) { |
887 | $year = intval(substr(1900 - $year, 1, 3)); | |
888 | return sprintf('%02u0%03u', $year, $rang); | |
889 | } else { | |
890 | $year = intval(substr(1900 - $year, 1, 3)); | |
891 | return sprintf('%03u%03u', $year, $rang); | |
892 | } | |
787bb3d7 FB |
893 | } |
894 | ||
433336f3 | 895 | // }}} |
896 | ||
897 | ||
a7de4ef7 | 898 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 899 | ?> |