0337d704 |
1 | <?php |
2 | /*************************************************************************** |
8b10988d |
3 | * Copyright (C) 2003-2006 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); |
36 | $res = $globals->xdb->query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $uid); |
37 | $alias = $res->fetchOneCell(); |
38 | |
39 | if ($really_del) { |
40 | $globals->xdb->execute("DELETE FROM emails WHERE uid={?}", $uid); |
41 | $globals->xdb->execute("DELETE FROM newsletter_ins WHERE user_id={?}", $uid); |
42 | } |
43 | |
44 | $globals->xdb->execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain); |
45 | $globals->xdb->execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain2); |
46 | |
47 | $globals->xdb->execute("UPDATE auth_user_md5 SET password='',smtppass='' WHERE user_id={?}", $uid); |
48 | $globals->xdb->execute("UPDATE auth_user_quick SET watch_flags='' WHERE user_id={?}", $uid); |
49 | |
50 | $globals->xdb->execute("DELETE FROM competences_ins WHERE uid={?}", $uid); |
51 | $globals->xdb->execute("DELETE FROM entreprises WHERE uid={?}", $uid); |
52 | $globals->xdb->execute("DELETE FROM langues_ins WHERE uid={?}", $uid); |
53 | $globals->xdb->execute("DELETE FROM mentor_pays WHERE uid={?}", $uid); |
54 | $globals->xdb->execute("DELETE FROM mentor_secteur WHERE uid={?}", $uid); |
55 | $globals->xdb->execute("DELETE FROM mentor WHERE uid={?}", $uid); |
56 | $globals->xdb->execute("DELETE FROM perte_pass WHERE uid={?}", $uid); |
57 | $globals->xdb->execute("DELETE FROM requests WHERE user_id={?}", $uid); |
58 | $globals->xdb->execute("DELETE FROM user_changes WHERE user_id={?}", $uid); |
59 | $globals->xdb->execute("DELETE FROM watch_sub WHERE uid={?}", $uid); |
60 | |
61 | include_once('lists.inc.php'); |
62 | if (function_exists(lists_xmlrpc)) { |
63 | $client =& lists_xmlrpc(Session::getInt('id'), Session::get('password')); |
64 | $client->kill($alias, $really_del); |
65 | } |
66 | } |
67 | |
68 | // }}} |
69 | // {{{ function get_user_login() |
70 | |
71 | function get_user_login($data, $get_forlife = false) { |
72 | global $globals, $page; |
73 | |
74 | if (preg_match(',^[0-9]*$,', $data)) { |
75 | $res = $globals->xdb->query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $data); |
76 | if ($res->numRows()) { |
77 | return $res->fetchOneCell(); |
78 | } else { |
79 | $page->trig("il n'y a pas d'utilisateur avec cet id"); |
80 | return false; |
81 | } |
82 | } |
83 | |
84 | $data = trim(strtolower($data)); |
85 | |
86 | if (strstr($data, '@')===false) { |
87 | $data = $data.'@'.$globals->mail->domain; |
88 | } |
89 | |
575dd9be |
90 | list($mbox, $fqdn) = explode('@', $data); |
0337d704 |
91 | if ($fqdn == $globals->mail->domain || $fqdn == $globals->mail->domain2) { |
92 | |
93 | $res = $globals->xdb->query("SELECT a.alias |
94 | FROM aliases AS a |
95 | INNER JOIN aliases AS b ON (a.id = b.id AND b.type IN ('alias', 'a_vie') AND b.alias={?}) |
96 | WHERE a.type = 'a_vie'", $mbox); |
97 | if ($res->numRows()) { |
98 | return $get_forlife ? $res->fetchOneCell() : $mbox; |
99 | } else { |
100 | $page->trig("il n'y a pas d'utilisateur avec ce login"); |
101 | return false; |
102 | } |
103 | |
104 | } elseif ($fqdn == $globals->mail->alias_dom || $fqdn == $globals->mail->alias_dom2) { |
105 | |
106 | $res = $globals->xdb->query("SELECT redirect |
107 | FROM virtual_redirect |
108 | INNER JOIN virtual USING(vid) |
109 | WHERE alias={?}", $mbox.'@'.$globals->mail->alias_dom); |
110 | if ($redir = $res->fetchOneCell()) { |
575dd9be |
111 | list($alias) = explode('@', $redir); |
0337d704 |
112 | } else { |
113 | $page->trig("il n'y a pas d'utilisateur avec cet alias"); |
114 | $alias = false; |
115 | } |
116 | return $alias; |
117 | |
118 | } else { |
119 | |
120 | $res = $globals->xdb->query("SELECT alias |
121 | FROM aliases AS a |
122 | INNER JOIN emails AS e ON e.uid=a.id |
123 | WHERE e.email={?} AND a.type='a_vie'", $data); |
124 | switch ($i = $res->numRows()) { |
125 | case 0: |
126 | $page->trig("il n'y a pas d'utilisateur avec cette addresse mail"); |
127 | return false; |
128 | |
129 | case 1: |
130 | return $res->fetchOneCell(); |
131 | |
132 | default: |
133 | if (has_perms()) { |
134 | $aliases = $res->fetchColumn(); |
135 | $page->trig("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases)); |
136 | } else { |
137 | $res->free(); |
138 | } |
139 | } |
140 | } |
141 | |
142 | return false; |
143 | } |
144 | |
145 | // }}} |
146 | // {{{ function get_user_forlife() |
147 | |
148 | function get_user_forlife($data) { |
149 | return get_user_login($data, true); |
150 | } |
151 | |
152 | // }}} |
8b10988d |
153 | // {{{ function has_user_right() |
154 | function has_user_right($pub, $view = 'private') { |
155 | if ($pub == $view) return true; |
156 | // all infos available for private |
157 | if ($view == 'private') return true; |
158 | // public infos available for all |
159 | if ($pub == 'public') return true; |
160 | // here we have view = ax or public, and pub = ax or private, and pub != view |
161 | return false; |
162 | } |
163 | // }}} |
9039c94d |
164 | // {{{ function get_user_details_pro() |
165 | |
8b10988d |
166 | function get_user_details_pro($uid, $view = 'private') |
9039c94d |
167 | { |
168 | global $globals; |
169 | $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, |
dd502514 |
170 | e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.entrid, |
9039c94d |
171 | gp.pays AS countrytxt, gr.name AS region, e.tel, e.fax, e.mobile, e.entrid, |
172 | e.pub, e.adr_pub, e.tel_pub, e.email, e.email_pub, e.web |
173 | FROM entreprises AS e |
174 | LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) |
175 | LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) |
176 | LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) |
177 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country) |
178 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region) |
179 | WHERE e.uid = {?} |
180 | ORDER BY e.entrid"; |
181 | $res = $globals->xdb->query($sql, $uid); |
8b10988d |
182 | $all_pro = $res->fetchAllAssoc(); |
183 | foreach ($all_pro as $i => $pro) { |
184 | if (!has_user_right($pro['pub'], $view)) |
185 | unset($all_pro[$i]); |
186 | else { |
187 | if (!has_user_right($pro['adr_pub'], $view)) { |
dd502514 |
188 | if ($pro['adr1'] == '' && |
189 | $pro['adr2'] == '' && |
190 | $pro['adr3'] == '' && |
191 | $pro['postcode'] == '' && |
192 | $pro['city'] == '' && |
193 | $pro['countrytxt'] == '' && |
194 | $pro['region'] == '') { |
195 | $all_pro[$i]['adr_pub'] = $view; |
196 | } else { |
197 | $all_pro[$i]['adr1'] = ''; |
198 | $all_pro[$i]['adr2'] = ''; |
199 | $all_pro[$i]['adr3'] = ''; |
200 | $all_pro[$i]['postcode'] = ''; |
201 | $all_pro[$i]['city'] = ''; |
202 | $all_pro[$i]['countrytxt'] = ''; |
203 | $all_pro[$i]['region'] = ''; |
204 | } |
8b10988d |
205 | } |
206 | if (!has_user_right($pro['tel_pub'], $view)) { |
dd502514 |
207 | // if no tel was defined, then the viewer will be able to write it |
208 | if ($pro['tel'] == '' && |
209 | $pro['fax'] == '' && |
210 | $pro['mobile'] == '') { |
211 | $all_pro[$i]['tel_pub'] = $view; |
212 | } else { |
213 | $all_pro[$i]['tel'] = ''; |
214 | $all_pro[$i]['fax'] = ''; |
215 | $all_pro[$i]['mobile'] = ''; |
216 | } |
8b10988d |
217 | } |
218 | if (!has_user_right($pro['email_pub'], $view)) { |
dd502514 |
219 | if ($pro['email'] == '') |
220 | $all_pro[$i]['email_pub'] = $view; |
221 | else |
222 | $all_pro[$i]['email'] = ''; |
8b10988d |
223 | } |
224 | if ($all_pro[$i]['adr1'] == '' && |
225 | $all_pro[$i]['adr2'] == '' && |
226 | $all_pro[$i]['adr3'] == '' && |
227 | $all_pro[$i]['postcode'] == '' && |
228 | $all_pro[$i]['city'] == '' && |
229 | $all_pro[$i]['countrytxt'] == '' && |
230 | $all_pro[$i]['region'] == '' && |
231 | $all_pro[$i]['entreprise'] == '' && |
232 | $all_pro[$i]['fonction'] == '' && |
233 | $all_pro[$i]['secteur'] == '' && |
234 | $all_pro[$i]['poste'] == '' && |
235 | $all_pro[$i]['tel'] == '' && |
236 | $all_pro[$i]['fax'] == '' && |
237 | $all_pro[$i]['mobile'] == '' && |
238 | $all_pro[$i]['email'] == '') |
239 | unset($all_pro[$i]); |
240 | } |
241 | } |
242 | if (!count($all_pro)) return false; |
243 | return $all_pro; |
9039c94d |
244 | } |
245 | |
246 | // }}} |
8b10988d |
247 | function get_user_details_adr($uid, $view = 'private') { |
248 | global $globals; |
249 | $sql = "SELECT a.adrid, a.adr1,a.adr2,a.adr3,a.postcode,a.city, |
250 | gp.pays AS countrytxt,a.region, a.regiontxt, |
251 | FIND_IN_SET('active', a.statut) AS active, a.adrid, |
252 | FIND_IN_SET('res-secondaire', a.statut) AS secondaire, |
253 | a.pub, gp.display |
254 | FROM adresses AS a |
255 | LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) |
256 | WHERE uid= {?} AND NOT FIND_IN_SET('pro',a.statut) |
257 | ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; |
258 | $res = $globals->xdb->query($sql, $uid); |
259 | $all_adr = $res->fetchAllAssoc(); |
260 | $adrid_index = array(); |
261 | foreach ($all_adr as $i => $adr) { |
262 | if (!has_user_right($adr['pub'], $view)) |
263 | unset($all_adr[$i]); |
264 | else |
265 | $adrid_index[$adr['adrid']] = $i; |
266 | } |
267 | |
268 | $sql = "SELECT t.adrid, t.tel_pub, t.tel_type, t.tel, t.telid |
269 | FROM tels AS t |
270 | INNER JOIN adresses AS a ON (a.uid = t.uid) AND (a.adrid = t.adrid) |
271 | WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',a.statut) |
272 | ORDER BY t.adrid, t.tel_type DESC, t.telid"; |
273 | $restel = $globals->xdb->iterator($sql, $uid); |
274 | while ($nexttel = $restel->next()) { |
275 | if (has_user_right($nexttel['tel_pub'], $view)) { |
276 | $adrid = $nexttel['adrid']; |
277 | unset($nexttel['adrid']); |
278 | if (isset($adrid_index[$adrid])) { |
279 | if (!isset($all_adr[$adrid_index[$adrid]]['tels'])) |
280 | $all_adr[$adrid_index[$adrid]]['tels'] = array($nexttel); |
281 | else |
282 | $all_adr[$adrid_index[$adrid]]['tels'][] = $nexttel; |
283 | } |
284 | } |
285 | } |
286 | return $all_adr; |
287 | } |
0337d704 |
288 | // {{{ function get_user_details() |
289 | |
8b10988d |
290 | function &get_user_details($login, $from_uid = '', $view = 'private') |
0337d704 |
291 | { |
292 | global $globals; |
293 | $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv, |
294 | u.perms IN ('admin','user') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces, |
295 | q.profile_nick AS nickname, q.profile_from_ax, q.profile_mobile AS mobile, q.profile_web AS web, q.profile_freetext AS freetext, |
296 | q.profile_mobile_pub AS mobile_pub, q.profile_web_pub AS web_pub, q.profile_freetext_pub AS freetext_pub, |
297 | q.profile_medals_pub AS medals_pub, |
298 | IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166, |
299 | a.alias AS forlife, a2.alias AS bestalias, |
300 | c.uid IS NOT NULL AS is_contact, |
301 | s.text AS section, p.x, p.y, p.pub AS photo_pub, |
dd502514 |
302 | u.matricule_ax, |
0337d704 |
303 | m.expertise != '' AS is_referent |
304 | |
305 | FROM auth_user_md5 AS u |
306 | INNER JOIN auth_user_quick AS q USING(user_id) |
307 | INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') |
308 | INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags)) |
309 | LEFT JOIN contacts AS c ON (c.uid = {?} and c.contact = u.user_id) |
310 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) |
311 | INNER JOIN sections AS s ON (s.id = u.section) |
312 | LEFT JOIN photo AS p ON (p.uid = u.user_id) |
313 | LEFT JOIN mentor AS m ON (m.uid = u.user_id) |
314 | WHERE a.alias = {?}"; |
315 | $res = $globals->xdb->query($reqsql, $from_uid, $login); |
316 | $user = $res->fetchOneAssoc(); |
317 | $uid = $user['user_id']; |
8b10988d |
318 | // hide orange status, cv, nickname, section |
319 | if (!has_user_right('private', $view)) { |
320 | $user['promo_sortie'] = $user['promo'] + 3; |
321 | $user['cv'] = ''; |
322 | $user['nickname'] = ''; |
323 | $user['section'] = ''; |
324 | } |
325 | // hide mobile |
dd502514 |
326 | if (!has_user_right($user['mobile_pub'], $view)) { |
327 | if ($user['mobile'] == '') |
328 | $user['mobile_pub'] = $view; |
329 | else |
330 | $user['mobile'] = ''; |
331 | } |
8b10988d |
332 | // hide web |
dd502514 |
333 | if (!has_user_right($user['web_pub'], $view)) { |
334 | if ($user['web'] == '') |
335 | $user['web_pub'] = $view; |
336 | else |
337 | $user['web'] = ''; |
338 | } |
8b10988d |
339 | // hide freetext |
dd502514 |
340 | if (!has_user_right($user['freetext_pub'], $view)) { |
341 | if ($user['freetext'] == '') |
342 | $user['freetext_pub'] = $view; |
343 | else |
344 | $user['freetext'] = ''; |
345 | } |
0337d704 |
346 | |
8b10988d |
347 | $user['adr_pro'] = get_user_details_pro($uid, $view); |
348 | $user['adr'] = get_user_details_adr($uid, $view); |
0337d704 |
349 | |
8b10988d |
350 | if (has_user_right('private', $view)) { |
351 | $sql = "SELECT text |
352 | FROM binets_ins |
353 | LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id |
354 | WHERE user_id = {?}"; |
355 | $res = $globals->xdb->query($sql, $uid); |
356 | $user['binets'] = $res->fetchColumn(); |
357 | $user['binets_join'] = join(', ', $user['binets']); |
79a5acea |
358 | |
8b10988d |
359 | $res = $globals->xdb->iterRow("SELECT text, url |
360 | FROM groupesx_ins |
361 | LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id |
362 | WHERE guid = {?}", $uid); |
363 | $user['gpxs'] = Array(); |
364 | while (list($gxt, $gxu) = $res->next()) { |
365 | $user['gpxs'][] = $gxu ? "<a href=\"$gxu\">$gxt</a>" : $gxt; |
366 | } |
367 | $user['gpxs_join'] = join(', ', $user['gpxs']); |
79a5acea |
368 | } |
0337d704 |
369 | |
0337d704 |
370 | $res = $globals->xdb->iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type |
371 | FROM applis_ins |
372 | INNER JOIN applis_def ON applis_def.id = applis_ins.aid |
373 | WHERE uid={?} |
374 | ORDER BY ordre", $uid); |
375 | |
376 | $user['applis_fmt'] = Array(); |
dd502514 |
377 | $user['formation'] = Array(); |
0337d704 |
378 | while (list($txt, $url, $type) = $res->next()) { |
dd502514 |
379 | $user['formation'][] = $txt." ".$type; |
0337d704 |
380 | require_once('applis.func.inc.php'); |
381 | $user['applis_fmt'][] = applis_fmt($type, $txt, $url); |
382 | } |
383 | $user['applis_join'] = join(', ', $user['applis_fmt']); |
384 | |
8b10988d |
385 | if (has_user_right($user['medals_pub'], $view)) { |
386 | $res = $globals->xdb->iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade |
387 | FROM profile_medals_sub AS s |
388 | INNER JOIN profile_medals AS m ON ( s.mid = m.id ) |
389 | LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) |
390 | WHERE s.uid = {?}", $uid); |
391 | $user['medals'] = Array(); |
392 | while ($tmp = $res->next()) { |
393 | $user['medals'][] = $tmp; |
394 | } |
0337d704 |
395 | } |
396 | |
397 | return $user; |
398 | } |
dd502514 |
399 | // }}} |
400 | // {{{ function add_user_address() |
401 | function add_user_address($uid, $adrid, $adr) { |
402 | global $globals; |
403 | $globals->xdb->execute( |
404 | "INSERT INTO adresses (`uid`, `adrid`, `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `datemaj`, `pub`) ( |
405 | SELECT u.user_id, {?}, {?}, {?}, {?}, {?}, {?}, gp.a2, NOW(), {?} |
406 | FROM auth_user_md5 AS u |
407 | LEFT JOIN geoloc_pays AS gp ON (gp.pays LIKE {?} OR gp.country LIKE {?} OR gp.a2 LIKE {?}) |
408 | WHERE u.user_id = {?} |
409 | LIMIT 1)", |
410 | $adrid, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], $adr['pub'], $adr['countrytxt'], $adr['countrytxt'], $adr['countrytxt'], $uid); |
411 | if (isset($adr['tels']) && is_array($adr['tels'])) { |
412 | $telid = 0; |
413 | foreach ($adr['tels'] as $tel) if ($tel['tel']) { |
414 | add_user_tel($uid, $adrid, $telid, $tel); |
415 | $telid ++; |
416 | } |
417 | } |
418 | } |
419 | // }}} |
420 | // {{{ function update_user_address() |
421 | function update_user_address($uid, $adrid, $adr) { |
422 | global $globals; |
423 | // update address |
424 | $globals->xdb->execute( |
425 | "UPDATE adresses AS a LEFT JOIN geoloc_pays AS gp ON (gp.pays = {?}) |
426 | SET `adr1` = {?}, `adr2` = {?}, `adr3` = {?}, |
427 | `postcode` = {?}, `city` = {?}, a.`country` = gp.a2, `datemaj` = NOW(), `pub` = {?} |
428 | WHERE adrid = {?} AND uid = {?}", |
429 | $adr['country_txt'], |
430 | $adr['adr1'], $adr['adr2'], $adr['adr3'], |
431 | $adr['postcode'], $adr['city'], $adr['pub'], $adrid, $uid); |
432 | if (isset($adr['tels']) && is_array($adr['tels'])) { |
433 | $res = $globals->xdb->query("SELECT telid FROM tels WHERE uid = {?} AND adrid = {?} ORDER BY telid", $uid, $adrid); |
434 | $telids = $res->fetchColumn(); |
435 | foreach ($adr['tels'] as $tel) { |
436 | if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) { |
437 | remove_user_tel($uid, $adrid, $tel['telid']); |
438 | if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]); |
439 | } else if (isset($tel['telid'])) { |
440 | update_user_tel($uid, $adrid, $tel['telid'], $tel); |
441 | } else { |
442 | for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++); |
443 | add_user_tel($uid, $adrid, $telid, $tel); |
444 | } |
445 | } |
446 | } |
447 | } |
448 | // }}} |
449 | // {{{ function remove_user_address() |
450 | function remove_user_address($uid, $adrid) { |
451 | global $globals; |
452 | $globals->xdb->execute("DELETE FROM adresses WHERE adrid = {?} AND uid = {?}", $adrid, $uid); |
453 | $globals->xdb->execute("DELETE FROM tels WHERE adrid = {?} AND uid = {?}", $adrid, $uid); |
454 | } |
455 | // }}} |
456 | // {{{ function add_user_tel() |
457 | function add_user_tel($uid, $adrid, $telid, $tel) { |
458 | global $globals; |
459 | $globals->xdb->execute( |
460 | "INSERT INTO tels SET uid = {?}, adrid = {?}, telid = {?}, tel = {?}, tel_type = {?}, tel_pub = {?}", |
461 | $uid, $adrid, $telid, $tel['tel'], $tel['tel_type'], $tel['tel_pub']); |
462 | } |
463 | // }}} |
464 | // {{{ function update_user_tel() |
465 | function update_user_tel($uid, $adrid, $telid, $tel) { |
466 | global $globals; |
467 | $globals->xdb->execute( |
468 | "UPDATE tels SET tel = {?}, tel_type = {?}, tel_pub = {?} |
469 | WHERE telid = {?} AND adrid = {?} AND uid = {?}", |
470 | $tel['tel'], $tel['tel_type'], $tel['tel_pub'], |
471 | $telid, $adrid, $uid); |
472 | } |
473 | // }}} |
474 | // {{{ function remove_user_tel() |
475 | function remove_user_tel($uid, $adrid, $telid) { |
476 | global $globals; |
477 | $globals->xdb->execute("DELETE FROM tels WHERE telid = {?} AND adrid = {?} AND uid = {?}", $telid, $adrid, $uid); |
478 | } |
479 | // }}} |
480 | // {{{ function add_user_pro() |
481 | function add_user_pro($uid, $entrid, $pro) { |
482 | global $globals; |
483 | $globals->xdb->execute( |
484 | "INSERT INTO entreprises (`uid`, `entrid`, `entreprise`, `poste`, `secteur`, `ss_secteur`, `fonction`, |
485 | `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `region`, `tel`, `fax`, `mobile`, `email`, `web`, `pub`, `adr_pub`, `tel_pub`, `email_pub`) |
486 | SELECT u.user_id, {?}, {?}, {?}, s.id, ss.id, f.id, |
487 | {?}, {?}, {?}, {?}, {?}, gp.a2, gr.region, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?} |
488 | FROM auth_user_md5 AS u |
489 | LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?}) |
490 | LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?}) |
491 | LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?}) |
492 | LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?}) |
493 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?}) |
494 | WHERE u.user_id = {?} |
495 | LIMIT 1", |
496 | $entrid, $pro['entreprise'], $pro['poste'], |
497 | $pro['adr1'], $pro['adr2'], $pro['adr3'], $pro['postcode'], $pro['city'], $pro['tel'], $pro['fax'], $pro['mobile'], $pro['email'], $pro['web'], $pro['pub'], $pro['adr_pub'], $pro['tel_pub'], $pro['email_pub'], |
498 | $pro['secteur'], $pro['sous_secteur'], $pro['fonction'], $pro['fonction'], |
499 | $pro['countrytxt'], $pro['countrytxt'], $pro['region'], |
500 | $uid); |
501 | } |
502 | // }}} |
503 | // {{{ function update_user_pro() |
504 | function update_user_pro($uid, $entrid, $pro) { |
505 | global $globals; |
506 | $join = ""; |
507 | $set = ""; |
508 | $args_join = array(); |
509 | $args_set = array(); |
510 | |
511 | $join .= "LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?}) |
512 | LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?}) |
513 | LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})"; |
514 | $args_join[] = $pro['secteur']; |
515 | $args_join[] = $pro['sous_secteur']; |
516 | $args_join[] = $pro['fonction']; |
517 | $args_join[] = $pro['fonction']; |
518 | $set .= ", e.`entreprise` = {?}, e.`secteur` = s.id, e.`ss_secteur` = ss.id, e.`fonction` = f.id, e.`poste`= {?}, e.`web` = {?}, e.`pub` = {?}"; |
519 | $args_set[] = $pro['entreprise']; |
520 | $args_set[] = $pro['poste']; |
521 | $args_set[] = $pro['web']; |
522 | $args_set[] = $pro['pub']; |
523 | |
524 | if (isset($pro['adr1'])) { |
525 | $join .= "LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?}) |
526 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?})"; |
527 | $args_join[] = $pro['countrytxt']; |
528 | $args_join[] = $pro['countrytxt']; |
529 | $args_join[] = $pro['region']; |
530 | $set .= ", e.`adr1` = {?}, e.`adr2` = {?}, e.`adr3` = {?}, e.`postcode` = {?}, e.`city` = {?}, e.`country` = gp.a2, e.`region` = gr.region, e.`adr_pub` = {?}"; |
531 | $args_set[] = $pro['adr1']; |
532 | $args_set[] = $pro['adr2']; |
533 | $args_set[] = $pro['adr3']; |
534 | $args_set[] = $pro['postcode']; |
535 | $args_set[] = $pro['city']; |
536 | $args_set[] = $pro['adr_pub']; |
537 | } |
538 | |
539 | if (isset($pro['tel'])) { |
540 | $set .= ", e.`tel` = {?}, e.`fax` = {?}, e.`mobile` = {?}, e.tel_pub = {?}"; |
541 | $args_set[] = $pro['tel']; |
542 | $args_set[] = $pro['fax']; |
543 | $args_set[] = $pro['mobile']; |
544 | $args_set[] = $pro['tel_pub']; |
545 | } |
546 | if (isset($pro['email'])) { |
547 | $set .= ", e.`email` = {?}, e.`email_pub` = {?}"; |
548 | $args_set[] = $pro['email']; |
549 | $args_set[] = $pro['email_pub']; |
550 | } |
551 | $query = "UPDATE entreprises AS e ".$join." SET ".substr($set,1)." WHERE e.uid = {?} AND e.entrid = {?}"; |
552 | $args_where = array($uid, $entrid); |
553 | $args = array_merge(array($query), $args_join, $args_set, $args_where); |
554 | $globals->db->query($globals->xdb->_prepare($args)); |
555 | } |
556 | // }}} |
557 | // {{{ function remove_user_pro() |
558 | function remove_user_pro($uid, $entrid) { |
559 | global $globals; |
560 | $globals->xdb->execute("DELETE FROM entreprises WHERE entrid = {?} AND uid = {?}", $entrid, $uid); |
561 | } |
562 | // }}} |
563 | // {{{ function set_user_details() |
564 | function set_user_details_addresses($uid, $adrs) { |
565 | global $globals; |
566 | $res = $globals->xdb->query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid); |
567 | $adrids = $res->fetchColumn(); |
568 | foreach ($adrs as $adr) { |
569 | if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) { |
570 | remove_user_address($uid, $adr['adrid']); |
571 | if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]); |
572 | } else if (isset($adr['adrid'])) { |
573 | update_user_address($uid, $adr['adrid'], $adr); |
574 | } else { |
575 | for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++); |
576 | add_user_address($uid, $adrid, $adr); |
577 | $adrids[$adrid-1] = $adrid; |
578 | } |
579 | } |
580 | require_once 'geoloc.inc.php'; |
581 | localize_addresses($uid); |
582 | } |
583 | // }}} |
584 | // {{{ function set_user_details_pro() |
585 | |
586 | function set_user_details_pro($uid, $pros) |
587 | { |
588 | global $globals; |
589 | $res = $globals->xdb->query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid); |
590 | $entrids = $res->fetchColumn(); |
591 | foreach ($pros as $pro) { |
592 | if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) { |
593 | remove_user_pro($uid, $pro['entrid']); |
594 | if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]); |
595 | } else if (isset($pro['entrid'])) { |
596 | update_user_pro($uid, $pro['entrid'], $pro); |
597 | } else { |
598 | for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++); |
599 | add_user_pro($uid, $entrid, $pro); |
600 | } |
601 | } |
602 | } |
0337d704 |
603 | |
604 | // }}} |
dd502514 |
605 | // {{{ function set_user_details() |
606 | function set_user_details($uid, $details) { |
607 | global $globals; |
608 | if (isset($details['nom_usage'])) { |
609 | $globals->xdb->execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($details['nom_usage']), $uid); |
610 | } |
611 | if (isset($details['mobile'])) { |
612 | $globals->xdb->execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $details['mobile'], $uid); |
613 | } |
614 | if (isset($details['nationalite'])) { |
615 | $globals->xdb->execute( |
616 | "UPDATE auth_user_md5 AS u |
617 | INNER JOIN geoloc_pays AS gp |
618 | SET u.nationalite = gp.a2 |
619 | WHERE (gp.a2 = {?} OR gp.nat = {?}) |
620 | AND u.user_id = {?}", $details['nationalite'], $details['nationalite'], $uid); |
621 | } |
622 | if (isset($details['adr']) && is_array($details['adr'])) |
623 | set_user_details_addresses($uid, $details['adr']); |
624 | if (isset($details['adr_pro']) && is_array($details['adr_pro'])) |
625 | set_user_details_pro($uid, $details['adr_pro']); |
626 | if (isset($details['binets']) && is_array($details['binets'])) { |
627 | $globals->xdb->execute("DELETE FROM binets_ins WHERE user_id = {?}", $uid); |
628 | foreach ($details['binets'] as $binet) |
629 | $globals->xdb->execute( |
630 | "INSERT INTO binets_ins (`user_id`, `binet_id`) |
631 | SELECT {?}, id FROM binets_def WHERE text = {?} LIMIT 1", |
632 | $uid, $binet); |
633 | } |
634 | if (isset($details['gpxs']) && is_array($details['gpxs'])) { |
635 | $globals->xdb->execute("DELETE FROM groupesx_ins WHERE user_id = {?}", $uid); |
636 | foreach ($details['gpxs'] as $groupex) { |
637 | if (preg_match('/<a href="[^"]*">([^<]+)</a>/', $groupex, $a)) $groupex = $a[1]; |
638 | $globals->xdb->execute( |
639 | "INSERT INTO groupesx_ins (`user_id`, `binet_id`) |
640 | SELECT {?}, id FROM groupesx_def WHERE text = {?} LIMIT 1", |
641 | $uid, $groupex); |
642 | } |
643 | } |
644 | // applis |
645 | // medals |
646 | } |
647 | // }}} |
0337d704 |
648 | // {{{ function _user_reindex |
649 | |
650 | function _user_reindex($uid, $keys, $muls) { |
651 | global $globals; |
652 | foreach ($keys as $i => $key) { |
653 | if ($key == '') { |
654 | continue; |
655 | } |
656 | $toks = preg_split('/[ \'\-]+/', $key); |
657 | $token = ""; |
658 | $first = 5; |
659 | while ($toks) { |
660 | $token = strtolower(replace_accent(array_pop($toks) . $token)); |
661 | $score = ($toks ? 0 : 10 + $first) * $muls[$i]; |
662 | mysql_query("REPLACE INTO search_name (token, uid, score) VALUES('$token',$uid,$score)"); |
663 | $first = 0; |
664 | } |
665 | } |
666 | } |
667 | |
668 | // }}} |
669 | // {{{ function user_reindex |
670 | |
671 | function user_reindex($uid) { |
672 | global $globals; |
673 | $globals->xdb->execute("DELETE FROM search_name WHERE uid={?}", $uid); |
674 | $res = $globals->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); |
675 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2)); |
676 | } |
677 | |
678 | // }}} |
679 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
680 | ?> |