2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
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
27 function user_clear_all_subs($user_id, $really_del=true
)
29 // keep datas in : aliases, adresses, tels, applis_ins, binets_ins, contacts, groupesx_ins, homonymes, identification_ax, photo
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
35 $uid = intval($user_id);
36 $res = XDB
::query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $uid);
37 $alias = $res->fetchOneCell();
40 XDB
::execute("DELETE FROM emails WHERE uid={?}", $uid);
41 XDB
::execute("DELETE FROM newsletter_ins WHERE user_id={?}", $uid);
44 XDB
::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail
->domain
);
45 XDB
::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail
->domain2
);
47 XDB
::execute("UPDATE auth_user_md5 SET password='',smtppass='' WHERE user_id={?}", $uid);
48 XDB
::execute("UPDATE auth_user_quick SET watch_flags='' WHERE user_id={?}", $uid);
50 XDB
::execute("DELETE FROM competences_ins WHERE uid={?}", $uid);
51 XDB
::execute("DELETE FROM entreprises WHERE uid={?}", $uid);
52 XDB
::execute("DELETE FROM langues_ins WHERE uid={?}", $uid);
53 XDB
::execute("DELETE FROM mentor_pays WHERE uid={?}", $uid);
54 XDB
::execute("DELETE FROM mentor_secteur WHERE uid={?}", $uid);
55 XDB
::execute("DELETE FROM mentor WHERE uid={?}", $uid);
56 XDB
::execute("DELETE FROM perte_pass WHERE uid={?}", $uid);
57 XDB
::execute("DELETE FROM requests WHERE user_id={?}", $uid);
58 XDB
::execute("DELETE FROM user_changes WHERE user_id={?}", $uid);
59 XDB
::execute("DELETE FROM watch_sub WHERE uid={?}", $uid);
61 $mmlist = new MMList(S
::v('id'), S
::v('password'));
62 $mmlist->kill($alias, $really_del);
66 // {{{ function get_user_login()
68 function get_user_login($data, $get_forlife = false
) {
69 global $globals, $page;
71 if (is_numeric($data)) {
72 $res = XDB
::query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $data);
73 if ($res->numRows()) {
74 return $res->fetchOneCell();
76 $page->trig("il n'y a pas d'utilisateur avec cet id");
81 $data = trim(strtolower($data));
83 if (strstr($data, '@')===false
) {
84 $data = $data.'@'.$globals->mail
->domain
;
87 list($mbox, $fqdn) = explode('@', $data);
88 if ($fqdn == $globals->mail
->domain ||
$fqdn == $globals->mail
->domain2
) {
90 $res = XDB
::query("SELECT a.alias
92 INNER JOIN aliases AS b ON (a.id = b.id AND b.type IN ('alias', 'a_vie') AND b.alias={?})
93 WHERE a.type = 'a_vie'", $mbox);
94 if ($res->numRows()) {
95 return $get_forlife ?
$res->fetchOneCell() : $mbox;
98 if (preg_match('/^(.*)\.([0-9]{4})$/', $mbox, $matches)) {
99 $res = XDB
::query("SELECT a.alias
101 INNER JOIN aliases AS b ON (a.id = b.id AND b.type IN ('alias', 'a_vie') AND b.alias={?})
102 INNER JOIN auth_user_md5 AS u ON (a.id = u.user_id AND promo = {?})
103 WHERE a.type = 'a_vie'", $matches[1], $matches[2]);
104 if ($res->numRows() == 1) {
105 return $res->fetchOneCell();
108 $page->trig("il n'y a pas d'utilisateur avec ce login");
111 } elseif ($fqdn == $globals->mail
->alias_dom ||
$fqdn == $globals->mail
->alias_dom2
) {
113 $res = XDB
::query("SELECT redirect
114 FROM virtual_redirect
115 INNER JOIN virtual USING(vid)
116 WHERE alias={?}", $mbox.'@'.$globals->mail
->alias_dom
);
117 if ($redir = $res->fetchOneCell()) {
118 list($alias) = explode('@', $redir);
120 $page->trig("il n'y a pas d'utilisateur avec cet alias");
127 $res = XDB
::query("SELECT alias
129 INNER JOIN emails AS e ON e.uid=a.id
130 WHERE e.email={?} AND a.type='a_vie'", $data);
131 switch ($i = $res->numRows()) {
133 $page->trig("il n'y a pas d'utilisateur avec cette addresse mail");
137 return $res->fetchOneCell();
140 if (S
::has_perms()) {
141 $aliases = $res->fetchColumn();
142 $page->trig("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases));
153 // {{{ function get_user_forlife()
155 function get_user_forlife($data) {
156 return get_user_login($data, true
);
160 // {{{ function get_users_forlife_list()
162 function get_users_forlife_list($members, $strict = false
)
164 if (strlen(trim($members)) == 0) {
167 $members = explode(' ', $members);
170 foreach ($members as $i => $alias) {
171 if (($login = get_user_forlife($alias)) !== false
) {
173 } else if(!$strict) {
183 // {{{ function has_user_right()
184 function has_user_right($pub, $view = 'private') {
185 if ($pub == $view) return true
;
186 // all infos available for private
187 if ($view == 'private') return true
;
188 // public infos available for all
189 if ($pub == 'public') return true
;
190 // here we have view = ax or public, and pub = ax or private, and pub != view
194 // {{{ function get_user_details_pro()
196 function get_user_details_pro($uid, $view = 'private')
198 $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction,
199 e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.entrid,
200 gp.pays AS countrytxt, gr.name AS region, e.tel, e.fax, e.mobile, e.entrid,
201 e.pub, e.adr_pub, e.tel_pub, e.email, e.email_pub, e.web
202 FROM entreprises AS e
203 LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id)
204 LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur)
205 LEFT JOIN fonctions_def AS f ON(e.fonction = f.id)
206 LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country)
207 LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region)
210 $res = XDB
::query($sql, $uid);
211 $all_pro = $res->fetchAllAssoc();
212 foreach ($all_pro as $i => $pro) {
213 if (!has_user_right($pro['pub'], $view))
216 if (!has_user_right($pro['adr_pub'], $view)) {
217 if ($pro['adr1'] == '' &&
218 $pro['adr2'] == '' &&
219 $pro['adr3'] == '' &&
220 $pro['postcode'] == '' &&
221 $pro['city'] == '' &&
222 $pro['countrytxt'] == '' &&
223 $pro['region'] == '') {
224 $all_pro[$i]['adr_pub'] = $view;
226 $all_pro[$i]['adr1'] = '';
227 $all_pro[$i]['adr2'] = '';
228 $all_pro[$i]['adr3'] = '';
229 $all_pro[$i]['postcode'] = '';
230 $all_pro[$i]['city'] = '';
231 $all_pro[$i]['countrytxt'] = '';
232 $all_pro[$i]['region'] = '';
235 if (!has_user_right($pro['tel_pub'], $view)) {
236 // if no tel was defined, then the viewer will be able to write it
237 if ($pro['tel'] == '' &&
239 $pro['mobile'] == '') {
240 $all_pro[$i]['tel_pub'] = $view;
242 $all_pro[$i]['tel'] = '';
243 $all_pro[$i]['fax'] = '';
244 $all_pro[$i]['mobile'] = '';
247 if (!has_user_right($pro['email_pub'], $view)) {
248 if ($pro['email'] == '')
249 $all_pro[$i]['email_pub'] = $view;
251 $all_pro[$i]['email'] = '';
253 if ($all_pro[$i]['adr1'] == '' &&
254 $all_pro[$i]['adr2'] == '' &&
255 $all_pro[$i]['adr3'] == '' &&
256 $all_pro[$i]['postcode'] == '' &&
257 $all_pro[$i]['city'] == '' &&
258 $all_pro[$i]['countrytxt'] == '' &&
259 $all_pro[$i]['region'] == '' &&
260 $all_pro[$i]['entreprise'] == '' &&
261 $all_pro[$i]['fonction'] == '' &&
262 $all_pro[$i]['secteur'] == '' &&
263 $all_pro[$i]['poste'] == '' &&
264 $all_pro[$i]['tel'] == '' &&
265 $all_pro[$i]['fax'] == '' &&
266 $all_pro[$i]['mobile'] == '' &&
267 $all_pro[$i]['email'] == '')
271 if (!count($all_pro)) return false
;
276 function get_user_details_adr($uid, $view = 'private') {
277 $sql = "SELECT a.adrid, a.adr1,a.adr2,a.adr3,a.postcode,a.city,
278 gp.pays AS countrytxt,a.region, a.regiontxt,
279 FIND_IN_SET('active', a.statut) AS active, a.adrid,
280 FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
283 LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country)
284 WHERE uid= {?} AND NOT FIND_IN_SET('pro',a.statut)
285 ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)";
286 $res = XDB
::query($sql, $uid);
287 $all_adr = $res->fetchAllAssoc();
288 $adrid_index = array();
289 foreach ($all_adr as $i => $adr) {
290 if (!has_user_right($adr['pub'], $view))
293 $adrid_index[$adr['adrid']] = $i;
296 $sql = "SELECT t.adrid, t.tel_pub, t.tel_type, t.tel, t.telid
298 INNER JOIN adresses AS a ON (a.uid = t.uid) AND (a.adrid = t.adrid)
299 WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',a.statut)
300 ORDER BY t.adrid, t.tel_type DESC, t.telid";
301 $restel = XDB
::iterator($sql, $uid);
302 while ($nexttel = $restel->next()) {
303 if (has_user_right($nexttel['tel_pub'], $view)) {
304 $adrid = $nexttel['adrid'];
305 unset($nexttel['adrid']);
306 if (isset($adrid_index[$adrid])) {
307 if (!isset($all_adr[$adrid_index[$adrid]]['tels']))
308 $all_adr[$adrid_index[$adrid]]['tels'] = array($nexttel);
310 $all_adr[$adrid_index[$adrid]]['tels'][] = $nexttel;
316 // {{{ function get_user_details()
318 function &get_user_details($login, $from_uid = '', $view = 'private')
320 $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv,
321 u.perms IN ('admin','user','disabled') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces,
322 q.profile_nick AS nickname, q.profile_from_ax, q.profile_mobile AS mobile, q.profile_web AS web, q.profile_freetext AS freetext,
323 q.profile_mobile_pub AS mobile_pub, q.profile_web_pub AS web_pub, q.profile_freetext_pub AS freetext_pub,
324 q.profile_medals_pub AS medals_pub,
325 IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166,
326 a.alias AS forlife, a2.alias AS bestalias,
327 c.uid IS NOT NULL AS is_contact,
328 s.text AS section, p.x, p.y, p.pub AS photo_pub,
330 m.expertise != '' AS is_referent,
331 COUNT(e.email) > 0 AS actif
332 FROM auth_user_md5 AS u
333 INNER JOIN auth_user_quick AS q USING(user_id)
334 INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie')
335 INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags))
336 LEFT JOIN contacts AS c ON (c.uid = {?} and c.contact = u.user_id)
337 LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite)
338 INNER JOIN sections AS s ON (s.id = u.section)
339 LEFT JOIN photo AS p ON (p.uid = u.user_id)
340 LEFT JOIN mentor AS m ON (m.uid = u.user_id)
341 LEFT JOIN emails AS e ON (e.uid = u.user_id AND e.flags='active')
344 $res = XDB
::query($reqsql, $from_uid, $login);
345 $user = $res->fetchOneAssoc();
346 $uid = $user['user_id'];
347 // hide orange status, cv, nickname, section
348 if (!has_user_right('private', $view)) {
349 $user['promo_sortie'] = $user['promo'] +
3;
351 $user['nickname'] = '';
352 $user['section'] = '';
355 if (!has_user_right($user['mobile_pub'], $view)) {
356 if ($user['mobile'] == '')
357 $user['mobile_pub'] = $view;
359 $user['mobile'] = '';
362 if (!has_user_right($user['web_pub'], $view)) {
363 if ($user['web'] == '')
364 $user['web_pub'] = $view;
369 if (!has_user_right($user['freetext_pub'], $view)) {
370 if ($user['freetext'] == '')
371 $user['freetext_pub'] = $view;
373 $user['freetext'] = '';
376 $user['adr_pro'] = get_user_details_pro($uid, $view);
377 $user['adr'] = get_user_details_adr($uid, $view);
379 if (has_user_right('private', $view)) {
382 LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id
383 WHERE user_id = {?}";
384 $res = XDB
::query($sql, $uid);
385 $user['binets'] = $res->fetchColumn();
386 $user['binets_join'] = join(', ', $user['binets']);
388 $res = XDB
::iterRow("SELECT text, url
390 LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id
391 WHERE guid = {?}", $uid);
392 $user['gpxs'] = Array();
393 while (list($gxt, $gxu) = $res->next()) {
394 $user['gpxs'][] = $gxu ?
"<a href=\"$gxu\">$gxt</a>" : $gxt;
396 $user['gpxs_join'] = join(', ', $user['gpxs']);
399 $res = XDB
::iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type
401 INNER JOIN applis_def ON applis_def.id = applis_ins.aid
403 ORDER BY ordre", $uid);
405 $user['applis_fmt'] = Array();
406 $user['formation'] = Array();
407 while (list($txt, $url, $type) = $res->next()) {
408 $user['formation'][] = $txt." ".$type;
409 require_once('applis.func.inc.php');
410 $user['applis_fmt'][] = applis_fmt($type, $txt, $url);
412 $user['applis_join'] = join(', ', $user['applis_fmt']);
414 if (has_user_right($user['medals_pub'], $view)) {
415 $res = XDB
::iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade
416 FROM profile_medals_sub AS s
417 INNER JOIN profile_medals AS m ON ( s.mid = m.id )
418 LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid )
419 WHERE s.uid = {?}", $uid);
420 $user['medals'] = Array();
421 while ($tmp = $res->next()) {
422 $user['medals'][] = $tmp;
429 // {{{ function add_user_address()
430 function add_user_address($uid, $adrid, $adr) {
432 "INSERT INTO adresses (`uid`, `adrid`, `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `datemaj`, `pub`) (
433 SELECT u.user_id, {?}, {?}, {?}, {?}, {?}, {?}, gp.a2, NOW(), {?}
434 FROM auth_user_md5 AS u
435 LEFT JOIN geoloc_pays AS gp ON (gp.pays LIKE {?} OR gp.country LIKE {?} OR gp.a2 LIKE {?})
436 WHERE u.user_id = {?}
438 $adrid, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], $adr['pub'], $adr['countrytxt'], $adr['countrytxt'], $adr['countrytxt'], $uid);
439 if (isset($adr['tels']) && is_array($adr['tels'])) {
441 foreach ($adr['tels'] as $tel) if ($tel['tel']) {
442 add_user_tel($uid, $adrid, $telid, $tel);
448 // {{{ function update_user_address()
449 function update_user_address($uid, $adrid, $adr) {
452 "UPDATE adresses AS a LEFT JOIN geoloc_pays AS gp ON (gp.pays = {?})
453 SET `adr1` = {?}, `adr2` = {?}, `adr3` = {?},
454 `postcode` = {?}, `city` = {?}, a.`country` = gp.a2, `datemaj` = NOW(), `pub` = {?}
455 WHERE adrid = {?} AND uid = {?}",
457 $adr['adr1'], $adr['adr2'], $adr['adr3'],
458 $adr['postcode'], $adr['city'], $adr['pub'], $adrid, $uid);
459 if (isset($adr['tels']) && is_array($adr['tels'])) {
460 $res = XDB
::query("SELECT telid FROM tels WHERE uid = {?} AND adrid = {?} ORDER BY telid", $uid, $adrid);
461 $telids = $res->fetchColumn();
462 foreach ($adr['tels'] as $tel) {
463 if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) {
464 remove_user_tel($uid, $adrid, $tel['telid']);
465 if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]);
466 } else if (isset($tel['telid'])) {
467 update_user_tel($uid, $adrid, $tel['telid'], $tel);
469 for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++
);
470 add_user_tel($uid, $adrid, $telid, $tel);
476 // {{{ function remove_user_address()
477 function remove_user_address($uid, $adrid) {
478 XDB
::execute("DELETE FROM adresses WHERE adrid = {?} AND uid = {?}", $adrid, $uid);
479 XDB
::execute("DELETE FROM tels WHERE adrid = {?} AND uid = {?}", $adrid, $uid);
482 // {{{ function add_user_tel()
483 function add_user_tel($uid, $adrid, $telid, $tel) {
485 "INSERT INTO tels SET uid = {?}, adrid = {?}, telid = {?}, tel = {?}, tel_type = {?}, tel_pub = {?}",
486 $uid, $adrid, $telid, $tel['tel'], $tel['tel_type'], $tel['tel_pub']);
489 // {{{ function update_user_tel()
490 function update_user_tel($uid, $adrid, $telid, $tel) {
492 "UPDATE tels SET tel = {?}, tel_type = {?}, tel_pub = {?}
493 WHERE telid = {?} AND adrid = {?} AND uid = {?}",
494 $tel['tel'], $tel['tel_type'], $tel['tel_pub'],
495 $telid, $adrid, $uid);
498 // {{{ function remove_user_tel()
499 function remove_user_tel($uid, $adrid, $telid) {
500 XDB
::execute("DELETE FROM tels WHERE telid = {?} AND adrid = {?} AND uid = {?}",
501 $telid, $adrid, $uid);
504 // {{{ function add_user_pro()
505 function add_user_pro($uid, $entrid, $pro) {
507 "INSERT INTO entreprises (`uid`, `entrid`, `entreprise`, `poste`, `secteur`, `ss_secteur`, `fonction`,
508 `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `region`, `tel`, `fax`, `mobile`, `email`, `web`, `pub`, `adr_pub`, `tel_pub`, `email_pub`)
509 SELECT u.user_id, {?}, {?}, {?}, s.id, ss.id, f.id,
510 {?}, {?}, {?}, {?}, {?}, gp.a2, gr.region, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}
511 FROM auth_user_md5 AS u
512 LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?})
513 LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?})
514 LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})
515 LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?})
516 LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?})
517 WHERE u.user_id = {?}
519 $entrid, $pro['entreprise'], $pro['poste'],
520 $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'],
521 $pro['secteur'], $pro['sous_secteur'], $pro['fonction'], $pro['fonction'],
522 $pro['countrytxt'], $pro['countrytxt'], $pro['region'],
526 // {{{ function update_user_pro()
527 function update_user_pro($uid, $entrid, $pro) {
530 $args_join = array();
533 $join .= "LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?})
534 LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?})
535 LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})";
536 $args_join[] = $pro['secteur'];
537 $args_join[] = $pro['sous_secteur'];
538 $args_join[] = $pro['fonction'];
539 $args_join[] = $pro['fonction'];
540 $set .= ", e.`entreprise` = {?}, e.`secteur` = s.id, e.`ss_secteur` = ss.id, e.`fonction` = f.id, e.`poste`= {?}, e.`web` = {?}, e.`pub` = {?}";
541 $args_set[] = $pro['entreprise'];
542 $args_set[] = $pro['poste'];
543 $args_set[] = $pro['web'];
544 $args_set[] = $pro['pub'];
546 if (isset($pro['adr1'])) {
547 $join .= "LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?})
548 LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?})";
549 $args_join[] = $pro['countrytxt'];
550 $args_join[] = $pro['countrytxt'];
551 $args_join[] = $pro['region'];
552 $set .= ", e.`adr1` = {?}, e.`adr2` = {?}, e.`adr3` = {?}, e.`postcode` = {?}, e.`city` = {?}, e.`country` = gp.a2, e.`region` = gr.region, e.`adr_pub` = {?}";
553 $args_set[] = $pro['adr1'];
554 $args_set[] = $pro['adr2'];
555 $args_set[] = $pro['adr3'];
556 $args_set[] = $pro['postcode'];
557 $args_set[] = $pro['city'];
558 $args_set[] = $pro['adr_pub'];
561 if (isset($pro['tel'])) {
562 $set .= ", e.`tel` = {?}, e.`fax` = {?}, e.`mobile` = {?}, e.tel_pub = {?}";
563 $args_set[] = $pro['tel'];
564 $args_set[] = $pro['fax'];
565 $args_set[] = $pro['mobile'];
566 $args_set[] = $pro['tel_pub'];
568 if (isset($pro['email'])) {
569 $set .= ", e.`email` = {?}, e.`email_pub` = {?}";
570 $args_set[] = $pro['email'];
571 $args_set[] = $pro['email_pub'];
573 $query = "UPDATE entreprises AS e ".$join." SET ".substr($set,1)." WHERE e.uid = {?} AND e.entrid = {?}";
574 $args_where = array($uid, $entrid);
575 $args = array_merge(array($query), $args_join, $args_set, $args_where);
576 call_user_func_array(array('XDB', 'execute'), $args);
579 // {{{ function remove_user_pro()
580 function remove_user_pro($uid, $entrid) {
581 XDB
::execute("DELETE FROM entreprises WHERE entrid = {?} AND uid = {?}", $entrid, $uid);
584 // {{{ function set_user_details()
585 function set_user_details_addresses($uid, $adrs) {
586 $res = XDB
::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid);
587 $adrids = $res->fetchColumn();
588 foreach ($adrs as $adr) {
589 if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) {
590 remove_user_address($uid, $adr['adrid']);
591 if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]);
592 } else if (isset($adr['adrid'])) {
593 update_user_address($uid, $adr['adrid'], $adr);
595 for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++
);
596 add_user_address($uid, $adrid, $adr);
597 $adrids[$adrid-1] = $adrid;
600 require_once 'geoloc.inc.php';
601 localize_addresses($uid);
604 // {{{ function set_user_details_pro()
606 function set_user_details_pro($uid, $pros)
608 $res = XDB
::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid);
609 $entrids = $res->fetchColumn();
610 foreach ($pros as $pro) {
611 if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) {
612 remove_user_pro($uid, $pro['entrid']);
613 if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]);
614 } else if (isset($pro['entrid'])) {
615 update_user_pro($uid, $pro['entrid'], $pro);
617 for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++
);
618 add_user_pro($uid, $entrid, $pro);
624 // {{{ function set_user_details()
625 function set_user_details($uid, $details) {
626 if (isset($details['nom_usage'])) {
627 XDB
::execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($details['nom_usage']), $uid);
629 if (isset($details['mobile'])) {
630 XDB
::execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $details['mobile'], $uid);
632 if (isset($details['nationalite'])) {
634 "UPDATE auth_user_md5 AS u
635 INNER JOIN geoloc_pays AS gp
636 SET u.nationalite = gp.a2
637 WHERE (gp.a2 = {?} OR gp.nat = {?})
638 AND u.user_id = {?}", $details['nationalite'], $details['nationalite'], $uid);
640 if (isset($details['adr']) && is_array($details['adr']))
641 set_user_details_addresses($uid, $details['adr']);
642 if (isset($details['adr_pro']) && is_array($details['adr_pro']))
643 set_user_details_pro($uid, $details['adr_pro']);
644 if (isset($details['binets']) && is_array($details['binets'])) {
645 XDB
::execute("DELETE FROM binets_ins WHERE user_id = {?}", $uid);
646 foreach ($details['binets'] as $binet)
648 "INSERT INTO binets_ins (`user_id`, `binet_id`)
649 SELECT {?}, id FROM binets_def WHERE text = {?} LIMIT 1",
652 if (isset($details['gpxs']) && is_array($details['gpxs'])) {
653 XDB
::execute("DELETE FROM groupesx_ins WHERE user_id = {?}", $uid);
654 foreach ($details['gpxs'] as $groupex) {
655 if (preg_match('/<a href="[^"]*">([^<]+)</a>/', $groupex, $a)) $groupex = $a[1];
657 "INSERT INTO groupesx_ins (`user_id`, `binet_id`)
658 SELECT {?}, id FROM groupesx_def WHERE text = {?} LIMIT 1",
666 // {{{ function _user_reindex
668 function _user_reindex($uid, $keys, $muls) {
669 foreach ($keys as $i => $key) {
673 $toks = preg_split('/[ \'\-]+/', $key);
677 $token = strtolower(replace_accent(array_pop($toks) . $token));
678 $score = ($toks ?
0 : 10 +
$first) * $muls[$i];
679 mysql_query("REPLACE INTO search_name (token, uid, score) VALUES('$token',$uid,$score)");
686 // {{{ function user_reindex
688 function user_reindex($uid) {
689 XDB
::execute("DELETE FROM search_name WHERE uid={?}", $uid);
690 $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);
691 _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2));
696 function set_new_usage($uid, $usage, $alias=false
) {
697 XDB
::execute("UPDATE auth_user_md5 set nom_usage={?} WHERE user_id={?}",$usage ,$uid);
698 XDB
::execute("DELETE FROM aliases WHERE FIND_IN_SET('usage',flags) AND id={?}", $uid);
699 if ($alias && $usage) {
700 XDB
::execute("UPDATE aliases SET flags=flags & 255-1 WHERE id={?}", $uid);
701 XDB
::execute("INSERT INTO aliases VALUES({?}, 'alias', 'usage,bestalias', {?}, null)",
704 $r = XDB
::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid);
705 if ($r->fetchOneCell() == "") {
706 XDB
::execute("UPDATE aliases SET flags = 1 | flags WHERE id = {?} LIMIT 1", $uid);
708 require_once 'user.func.inc.php';
712 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: