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