19d7a34cb57def03151294767c092042fdaa478f
2 /***************************************************************************
3 * Copyright (C) 2003-2007 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();
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'));
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
);
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);
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
);
66 foreach ($tables_to_clear as $key=>&$tables) {
67 foreach ($tables as $table) {
68 XDB
::execute("DELETE FROM $table WHERE $key={?}", $uid);
72 $mmlist = new MMList(S
::v('uid'), S
::v('password'));
73 $mmlist->kill($alias, $really_del);
77 // {{{ function get_user_login()
79 function get_user_login($data, $get_forlife = false
) {
80 global $globals, $page;
82 if (is_numeric($data)) {
83 $res = XDB
::query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $data);
84 if ($res->numRows()) {
85 return $res->fetchOneCell();
87 $page->trig("il n'y a pas d'utilisateur avec cet id");
92 $data = trim(strtolower($data));
94 if (strstr($data, '@')===false
) {
95 $data = $data.'@'.$globals->mail
->domain
;
98 list($mbox, $fqdn) = explode('@', $data);
99 if ($fqdn == $globals->mail
->domain ||
$fqdn == $globals->mail
->domain2
) {
101 $res = XDB
::query("SELECT a.alias
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);
105 if ($res->numRows()) {
106 return $get_forlife ?
$res->fetchOneCell() : $mbox;
109 if (preg_match('/^(.*)\.([0-9]{4})$/', $mbox, $matches)) {
110 $res = XDB
::query("SELECT a.alias
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();
119 $page->trig("il n'y a pas d'utilisateur avec ce login");
122 } elseif ($fqdn == $globals->mail
->alias_dom ||
$fqdn == $globals->mail
->alias_dom2
) {
124 $res = XDB
::query("SELECT redirect
125 FROM virtual_redirect
126 INNER JOIN virtual USING(vid)
127 WHERE alias={?}", $mbox.'@'.$globals->mail
->alias_dom
);
128 if ($redir = $res->fetchOneCell()) {
129 list($alias) = explode('@', $redir);
131 $page->trig("il n'y a pas d'utilisateur avec cet alias");
138 $res = XDB
::query("SELECT alias
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()) {
144 $page->trig("il n'y a pas d'utilisateur avec cette addresse mail");
148 return $res->fetchOneCell();
151 if (S
::has_perms()) {
152 $aliases = $res->fetchColumn();
153 $page->trig("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases));
164 // {{{ function get_user_forlife()
166 function get_user_forlife($data) {
167 return get_user_login($data, true
);
171 // {{{ function get_users_forlife_list()
173 function get_users_forlife_list($members, $strict = false
)
175 if (strlen(trim($members)) == 0) {
178 $members = explode(' ', $members);
181 foreach ($members as $i => $alias) {
182 if (($login = get_user_forlife($alias)) !== false
) {
184 } else if(!$strict) {
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
205 // {{{ function get_user_details_pro()
207 function get_user_details_pro($uid, $view = 'private')
209 $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction,
210 e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.entrid,
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)
221 $res = XDB
::query($sql, $uid);
222 $all_pro = $res->fetchAllAssoc();
223 foreach ($all_pro as $i => $pro) {
224 if (!has_user_right($pro['pub'], $view))
227 if (!has_user_right($pro['adr_pub'], $view)) {
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;
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'] = '';
246 if (!has_user_right($pro['tel_pub'], $view)) {
247 // if no tel was defined, then the viewer will be able to write it
248 if ($pro['tel'] == '' &&
250 $pro['mobile'] == '') {
251 $all_pro[$i]['tel_pub'] = $view;
253 $all_pro[$i]['tel'] = '';
254 $all_pro[$i]['fax'] = '';
255 $all_pro[$i]['mobile'] = '';
258 if (!has_user_right($pro['email_pub'], $view)) {
259 if ($pro['email'] == '')
260 $all_pro[$i]['email_pub'] = $view;
262 $all_pro[$i]['email'] = '';
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'] == '')
282 if (!count($all_pro)) return false
;
287 // {{{ function get_user_details_adr()
289 function get_user_details_adr($uid, $view = 'private') {
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,
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)";
299 $res = XDB
::query($sql, $uid);
300 $all_adr = $res->fetchAllAssoc();
301 $adrid_index = array();
302 foreach ($all_adr as $i => $adr) {
303 if (!has_user_right($adr['pub'], $view))
306 $adrid_index[$adr['adrid']] = $i;
309 $sql = "SELECT t.adrid, t.tel_pub, t.tel_type, t.tel, t.telid
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";
314 $restel = XDB
::iterator($sql, $uid);
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);
323 $all_adr[$adrid_index[$adrid]]['tels'][] = $nexttel;
331 // {{{ function get_user_details()
333 function &get_user_details($login, $from_uid = '', $view = 'private')
335 $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv,
336 u.perms IN ('admin','user','disabled') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces,
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,
345 m.expertise != '' AS is_referent,
346 COUNT(e.email) > 0 AS actif
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)
356 LEFT JOIN emails AS e ON (e.uid = u.user_id AND e.flags='active')
359 $res = XDB
::query($reqsql, $from_uid, $login);
360 $user = $res->fetchOneAssoc();
361 $uid = $user['user_id'];
362 // hide orange status, cv, nickname, section
363 if (!has_user_right('private', $view)) {
364 $user['promo_sortie'] = $user['promo'] +
3;
366 $user['nickname'] = '';
367 $user['section'] = '';
370 if (!has_user_right($user['mobile_pub'], $view)) {
371 if ($user['mobile'] == '')
372 $user['mobile_pub'] = $view;
374 $user['mobile'] = '';
377 if (!has_user_right($user['web_pub'], $view)) {
378 if ($user['web'] == '')
379 $user['web_pub'] = $view;
384 if (!has_user_right($user['freetext_pub'], $view)) {
385 if ($user['freetext'] == '')
386 $user['freetext_pub'] = $view;
388 $user['freetext'] = '';
391 $user['adr_pro'] = get_user_details_pro($uid, $view);
392 $user['adr'] = get_user_details_adr($uid, $view);
394 if (has_user_right('private', $view)) {
397 LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id
398 WHERE user_id = {?}";
399 $res = XDB
::query($sql, $uid);
400 $user['binets'] = $res->fetchColumn();
401 $user['binets_join'] = join(', ', $user['binets']);
403 $res = XDB
::iterRow("SELECT text, url
405 LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id
406 WHERE guid = {?}", $uid);
407 $user['gpxs'] = Array();
408 $user['gpxs_name'] = Array();
409 while (list($gxt, $gxu) = $res->next()) {
410 $user['gpxs'][] = $gxu ?
"<a href=\"$gxu\">$gxt</a>" : $gxt;
411 $user['gpxs_name'][] = $gxt;
413 $user['gpxs_join'] = join(', ', $user['gpxs']);
416 $res = XDB
::iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type
418 INNER JOIN applis_def ON applis_def.id = applis_ins.aid
420 ORDER BY ordre", $uid);
422 $user['applis_fmt'] = Array();
423 $user['formation'] = Array();
424 while (list($txt, $url, $type) = $res->next()) {
425 $user['formation'][] = $txt." ".$type;
426 require_once('applis.func.inc.php');
427 $user['applis_fmt'][] = applis_fmt($type, $txt, $url);
429 $user['applis_join'] = join(', ', $user['applis_fmt']);
431 if (has_user_right($user['medals_pub'], $view)) {
432 $res = XDB
::iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade
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);
437 $user['medals'] = Array();
438 while ($tmp = $res->next()) {
439 $user['medals'][] = $tmp;
446 // {{{ function add_user_address()
447 function add_user_address($uid, $adrid, $adr) {
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 = {?}
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'])) {
458 foreach ($adr['tels'] as $tel) if ($tel['tel']) {
459 add_user_tel($uid, $adrid, $telid, $tel);
465 // {{{ function update_user_address()
466 function update_user_address($uid, $adrid, $adr) {
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 = {?}",
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'])) {
477 $res = XDB
::query("SELECT telid FROM tels WHERE uid = {?} AND adrid = {?} ORDER BY telid", $uid, $adrid);
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);
486 for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++
);
487 add_user_tel($uid, $adrid, $telid, $tel);
493 // {{{ function remove_user_address()
494 function remove_user_address($uid, $adrid) {
495 XDB
::execute("DELETE FROM adresses WHERE adrid = {?} AND uid = {?}", $adrid, $uid);
496 XDB
::execute("DELETE FROM tels WHERE adrid = {?} AND uid = {?}", $adrid, $uid);
499 // {{{ function add_user_tel()
500 function add_user_tel($uid, $adrid, $telid, $tel) {
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']);
506 // {{{ function update_user_tel()
507 function update_user_tel($uid, $adrid, $telid, $tel) {
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);
515 // {{{ function remove_user_tel()
516 function remove_user_tel($uid, $adrid, $telid) {
517 XDB
::execute("DELETE FROM tels WHERE telid = {?} AND adrid = {?} AND uid = {?}",
518 $telid, $adrid, $uid);
521 // {{{ function add_user_pro()
522 function add_user_pro($uid, $entrid, $pro) {
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 = {?}
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'],
543 // {{{ function update_user_pro()
544 function update_user_pro($uid, $entrid, $pro) {
547 $args_join = array();
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'];
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'];
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'];
585 if (isset($pro['email'])) {
586 $set .= ", e.`email` = {?}, e.`email_pub` = {?}";
587 $args_set[] = $pro['email'];
588 $args_set[] = $pro['email_pub'];
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);
593 call_user_func_array(array('XDB', 'execute'), $args);
596 // {{{ function remove_user_pro()
597 function remove_user_pro($uid, $entrid) {
598 XDB
::execute("DELETE FROM entreprises WHERE entrid = {?} AND uid = {?}", $entrid, $uid);
601 // {{{ function set_user_details()
602 function set_user_details_addresses($uid, $adrs) {
603 $res = XDB
::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid);
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);
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;
617 require_once 'geoloc.inc.php';
618 localize_addresses($uid);
621 // {{{ function set_user_details_pro()
623 function set_user_details_pro($uid, $pros)
625 $res = XDB
::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid);
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);
634 for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++
);
635 add_user_pro($uid, $entrid, $pro);
641 // {{{ function set_user_details()
642 function set_user_details($uid, $details) {
643 if (isset($details['nom_usage'])) {
644 XDB
::execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($details['nom_usage']), $uid);
646 if (isset($details['mobile'])) {
647 XDB
::execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $details['mobile'], $uid);
649 if (isset($details['nationalite'])) {
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);
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'])) {
662 XDB
::execute("DELETE FROM binets_ins WHERE user_id = {?}", $uid);
663 foreach ($details['binets'] as $binet)
665 "INSERT INTO binets_ins (`user_id`, `binet_id`)
666 SELECT {?}, id FROM binets_def WHERE text = {?} LIMIT 1",
669 if (isset($details['gpxs']) && is_array($details['gpxs'])) {
670 XDB
::execute("DELETE FROM groupesx_ins WHERE user_id = {?}", $uid);
671 foreach ($details['gpxs'] as $groupex) {
672 if (preg_match('/<a href="[^"]*">([^<]+)</a>/', $groupex, $a)) $groupex = $a[1];
674 "INSERT INTO groupesx_ins (`user_id`, `binet_id`)
675 SELECT {?}, id FROM groupesx_def WHERE text = {?} LIMIT 1",
683 // {{{ function _user_reindex
685 function _user_reindex($uid, $keys, $muls) {
686 foreach ($keys as $i => $key) {
690 $toks = preg_split('/[ \'\-]+/', $key);
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)");
703 // {{{ function user_reindex
705 function user_reindex($uid) {
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);
708 _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2));
712 // {{{ function set_new_usage()
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)",
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);
726 require_once 'user.func.inc.php';
731 // {{{ function get_X_mat
732 function get_X_mat($ourmat)
734 if (!preg_match('/^[0-9]{8}$/', $ourmat)) {
735 // le matricule de notre base doit comporter 8 chiffres
739 $year = intval(substr($ourmat, 0, 4));
740 $rang = intval(substr($ourmat, 5, 3));
743 } elseif ($year < 2000) {
744 $year = intval(substr(1900 - $year, 1, 3));
745 return sprintf('%02u0%03u', $year, $rang);
747 $year = intval(substr(1900 - $year, 1, 3));
748 return sprintf('%03u%03u', $year, $rang);
755 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: