Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
0337d704 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | // {{{ function user_clear_all_subs() | |
23 | /** kills the inscription of a user. | |
24 | * we still keep his birthdate, adresses, and personnal stuff | |
25 | * kills the entreprises, mentor, emails and lists subscription stuff | |
26 | */ | |
27 | function user_clear_all_subs($user_id, $really_del=true) | |
28 | { | |
dd502514 | 29 | // keep datas in : aliases, adresses, tels, applis_ins, binets_ins, contacts, groupesx_ins, homonymes, identification_ax, photo |
0337d704 | 30 | // delete in : auth_user_md5, auth_user_quick, competences_ins, emails, entreprises, langues_ins, mentor, |
31 | // mentor_pays, mentor_secteurs, newsletter_ins, perte_pass, requests, user_changes, virtual_redirect, watch_sub | |
32 | // + delete maillists | |
33 | ||
34 | global $globals; | |
d56cb887 VZ |
35 | $uid = intval($user_id); |
36 | $user = User::getSilent($uid); | |
37 | list($alias) = explode('@', $user->forlifeEmail()); | |
0337d704 | 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'); | |
787bb3d7 | 47 | $tables_to_clear['id'] = array('aliases'); |
425f432d | 48 | $tables_to_clear['contact'] = array('contacts'); |
425f432d | 49 | XDB::execute("UPDATE auth_user_md5 |
50 | SET date_ins = 0, promo_sortie = 0, nom_usage = '', password = '', perms = 'pending', | |
0e5ec860 | 51 | nationalite = '', cv = '', section = 0, date = 0, smtppass = '', mail_storage = '' |
425f432d | 52 | WHERE user_id = {?}", $uid); |
53 | XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}", | |
54 | $alias.'@'.$globals->mail->domain); | |
55 | XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}", | |
56 | $alias.'@'.$globals->mail->domain2); | |
57 | } else { | |
58 | XDB::execute("UPDATE auth_user_md5 SET password='',smtppass='' WHERE user_id={?}", $uid); | |
59 | XDB::execute("UPDATE auth_user_quick SET watch_flags='' WHERE user_id={?}", $uid); | |
0337d704 | 60 | } |
61 | ||
08cce2ff | 62 | XDB::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain); |
63 | XDB::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain2); | |
64 | ||
425f432d | 65 | foreach ($tables_to_clear as $key=>&$tables) { |
66 | foreach ($tables as $table) { | |
67 | XDB::execute("DELETE FROM $table WHERE $key={?}", $uid); | |
68 | } | |
69 | } | |
9bb8bf21 | 70 | |
c53b5964 | 71 | $mmlist = new MMList(S::v('uid'), S::v('password')); |
9bb8bf21 | 72 | $mmlist->kill($alias, $really_del); |
84270653 VZ |
73 | |
74 | // Deactivates, when available, the Google Apps account of the user. | |
75 | if ($globals->mailstorage->googleapps_domain) { | |
76 | require_once 'googleapps.inc.php'; | |
14870e88 | 77 | if (GoogleAppsAccount::account_status($uid)) { |
d56cb887 | 78 | $account = new GoogleAppsAccount($user); |
14870e88 VZ |
79 | $account->suspend(); |
80 | } | |
84270653 | 81 | } |
0337d704 | 82 | } |
83 | ||
84 | // }}} | |
8b10988d | 85 | // {{{ function has_user_right() |
86 | function has_user_right($pub, $view = 'private') { | |
87 | if ($pub == $view) return true; | |
787bb3d7 | 88 | // all infos available for private |
8b10988d | 89 | if ($view == 'private') return true; |
787bb3d7 | 90 | // public infos available for all |
8b10988d | 91 | if ($pub == 'public') return true; |
92 | // here we have view = ax or public, and pub = ax or private, and pub != view | |
787bb3d7 | 93 | return false; |
8b10988d | 94 | } |
95 | // }}} | |
0baf0741 | 96 | // {{{ function get_not_registered_user() |
97 | ||
98 | function get_not_registered_user($login, $iterator = false) | |
99 | { | |
100 | global $globals; | |
101 | @list($login, $domain) = explode('@', $login); | |
102 | if ($domain && $domain != $globals->mail->domain && $domain != $globals->mail->domain2) { | |
103 | return null; | |
104 | } | |
105 | @list($prenom, $nom, $promo) = explode('.', $login); | |
106 | $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%") | |
107 | AND REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%")'; | |
108 | if ($promo) { | |
109 | if (preg_match('/^[0-9]{2}$/', $promo)) { | |
110 | $where .= 'AND MOD(promo, 100) = {?}'; | |
111 | } elseif (preg_match('/^[0-9]{4}$/', $promo)) { | |
112 | $where .= 'AND promo = {?}'; | |
113 | } | |
114 | } | |
115 | $sql = "SELECT user_id, nom, prenom, promo | |
116 | FROM auth_user_md5 | |
1555e55e | 117 | WHERE $where AND perms = 'pending' |
787bb3d7 | 118 | ORDER BY promo, nom, prenom"; |
0baf0741 | 119 | if ($iterator) { |
120 | return XDB::iterator($sql, $nom, $prenom, $promo); | |
121 | } else { | |
122 | $res = XDB::query($sql, $nom, $prenom, $promo); | |
123 | return $res->fetchAllAssoc(); | |
124 | } | |
125 | } | |
126 | ||
127 | // }}} | |
9039c94d | 128 | // {{{ function get_user_details_pro() |
129 | ||
8b10988d | 130 | function get_user_details_pro($uid, $view = 'private') |
9039c94d | 131 | { |
9039c94d | 132 | $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, |
dd502514 | 133 | e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.entrid, |
9039c94d | 134 | gp.pays AS countrytxt, gr.name AS region, e.tel, e.fax, e.mobile, e.entrid, |
135 | e.pub, e.adr_pub, e.tel_pub, e.email, e.email_pub, e.web | |
136 | FROM entreprises AS e | |
137 | LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) | |
138 | LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) | |
139 | LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) | |
140 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country) | |
141 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region) | |
142 | WHERE e.uid = {?} | |
143 | ORDER BY e.entrid"; | |
08cce2ff | 144 | $res = XDB::query($sql, $uid); |
8b10988d | 145 | $all_pro = $res->fetchAllAssoc(); |
146 | foreach ($all_pro as $i => $pro) { | |
147 | if (!has_user_right($pro['pub'], $view)) | |
148 | unset($all_pro[$i]); | |
149 | else { | |
150 | if (!has_user_right($pro['adr_pub'], $view)) { | |
dd502514 | 151 | if ($pro['adr1'] == '' && |
152 | $pro['adr2'] == '' && | |
153 | $pro['adr3'] == '' && | |
154 | $pro['postcode'] == '' && | |
155 | $pro['city'] == '' && | |
156 | $pro['countrytxt'] == '' && | |
157 | $pro['region'] == '') { | |
158 | $all_pro[$i]['adr_pub'] = $view; | |
159 | } else { | |
160 | $all_pro[$i]['adr1'] = ''; | |
161 | $all_pro[$i]['adr2'] = ''; | |
162 | $all_pro[$i]['adr3'] = ''; | |
163 | $all_pro[$i]['postcode'] = ''; | |
164 | $all_pro[$i]['city'] = ''; | |
165 | $all_pro[$i]['countrytxt'] = ''; | |
166 | $all_pro[$i]['region'] = ''; | |
167 | } | |
8b10988d | 168 | } |
169 | if (!has_user_right($pro['tel_pub'], $view)) { | |
dd502514 | 170 | // if no tel was defined, then the viewer will be able to write it |
787bb3d7 | 171 | if ($pro['tel'] == '' && |
dd502514 | 172 | $pro['fax'] == '' && |
173 | $pro['mobile'] == '') { | |
174 | $all_pro[$i]['tel_pub'] = $view; | |
175 | } else { | |
176 | $all_pro[$i]['tel'] = ''; | |
177 | $all_pro[$i]['fax'] = ''; | |
178 | $all_pro[$i]['mobile'] = ''; | |
179 | } | |
8b10988d | 180 | } |
181 | if (!has_user_right($pro['email_pub'], $view)) { | |
dd502514 | 182 | if ($pro['email'] == '') |
183 | $all_pro[$i]['email_pub'] = $view; | |
184 | else | |
185 | $all_pro[$i]['email'] = ''; | |
8b10988d | 186 | } |
187 | if ($all_pro[$i]['adr1'] == '' && | |
188 | $all_pro[$i]['adr2'] == '' && | |
189 | $all_pro[$i]['adr3'] == '' && | |
190 | $all_pro[$i]['postcode'] == '' && | |
191 | $all_pro[$i]['city'] == '' && | |
192 | $all_pro[$i]['countrytxt'] == '' && | |
193 | $all_pro[$i]['region'] == '' && | |
194 | $all_pro[$i]['entreprise'] == '' && | |
195 | $all_pro[$i]['fonction'] == '' && | |
196 | $all_pro[$i]['secteur'] == '' && | |
197 | $all_pro[$i]['poste'] == '' && | |
198 | $all_pro[$i]['tel'] == '' && | |
199 | $all_pro[$i]['fax'] == '' && | |
200 | $all_pro[$i]['mobile'] == '' && | |
201 | $all_pro[$i]['email'] == '') | |
202 | unset($all_pro[$i]); | |
203 | } | |
204 | } | |
205 | if (!count($all_pro)) return false; | |
206 | return $all_pro; | |
9039c94d | 207 | } |
208 | ||
209 | // }}} | |
433336f3 | 210 | // {{{ function get_user_details_adr() |
211 | ||
8b10988d | 212 | function get_user_details_adr($uid, $view = 'private') { |
8b10988d | 213 | $sql = "SELECT a.adrid, a.adr1,a.adr2,a.adr3,a.postcode,a.city, |
214 | gp.pays AS countrytxt,a.region, a.regiontxt, | |
215 | FIND_IN_SET('active', a.statut) AS active, a.adrid, | |
216 | FIND_IN_SET('res-secondaire', a.statut) AS secondaire, | |
5d42c993 | 217 | FIND_IN_SET('courrier', a.statut) AS courier, |
8b10988d | 218 | a.pub, gp.display |
219 | FROM adresses AS a | |
220 | LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) | |
221 | WHERE uid= {?} AND NOT FIND_IN_SET('pro',a.statut) | |
222 | ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; | |
08cce2ff | 223 | $res = XDB::query($sql, $uid); |
8b10988d | 224 | $all_adr = $res->fetchAllAssoc(); |
225 | $adrid_index = array(); | |
226 | foreach ($all_adr as $i => $adr) { | |
227 | if (!has_user_right($adr['pub'], $view)) | |
228 | unset($all_adr[$i]); | |
229 | else | |
230 | $adrid_index[$adr['adrid']] = $i; | |
231 | } | |
787bb3d7 | 232 | |
8b10988d | 233 | $sql = "SELECT t.adrid, t.tel_pub, t.tel_type, t.tel, t.telid |
234 | FROM tels AS t | |
235 | INNER JOIN adresses AS a ON (a.uid = t.uid) AND (a.adrid = t.adrid) | |
236 | WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',a.statut) | |
237 | ORDER BY t.adrid, t.tel_type DESC, t.telid"; | |
08cce2ff | 238 | $restel = XDB::iterator($sql, $uid); |
8b10988d | 239 | while ($nexttel = $restel->next()) { |
240 | if (has_user_right($nexttel['tel_pub'], $view)) { | |
241 | $adrid = $nexttel['adrid']; | |
242 | unset($nexttel['adrid']); | |
243 | if (isset($adrid_index[$adrid])) { | |
787bb3d7 | 244 | if (!isset($all_adr[$adrid_index[$adrid]]['tels'])) |
8b10988d | 245 | $all_adr[$adrid_index[$adrid]]['tels'] = array($nexttel); |
246 | else | |
247 | $all_adr[$adrid_index[$adrid]]['tels'][] = $nexttel; | |
248 | } | |
249 | } | |
250 | } | |
251 | return $all_adr; | |
252 | } | |
433336f3 | 253 | |
254 | // }}} | |
0337d704 | 255 | // {{{ function get_user_details() |
256 | ||
8b10988d | 257 | function &get_user_details($login, $from_uid = '', $view = 'private') |
0337d704 | 258 | { |
0337d704 | 259 | $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv, |
f6c71069 | 260 | u.perms IN ('admin','user','disabled') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces, |
0337d704 | 261 | q.profile_nick AS nickname, q.profile_from_ax, q.profile_mobile AS mobile, q.profile_web AS web, q.profile_freetext AS freetext, |
262 | q.profile_mobile_pub AS mobile_pub, q.profile_web_pub AS web_pub, q.profile_freetext_pub AS freetext_pub, | |
263 | q.profile_medals_pub AS medals_pub, | |
264 | IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166, | |
265 | a.alias AS forlife, a2.alias AS bestalias, | |
266 | c.uid IS NOT NULL AS is_contact, | |
267 | s.text AS section, p.x, p.y, p.pub AS photo_pub, | |
dd502514 | 268 | u.matricule_ax, |
d9caac6f | 269 | m.expertise != '' AS is_referent, |
0e5ec860 | 270 | (COUNT(e.email) > 0 OR FIND_IN_SET('googleapps', u.mail_storage) > 0) AS actif |
0337d704 | 271 | FROM auth_user_md5 AS u |
272 | INNER JOIN auth_user_quick AS q USING(user_id) | |
273 | INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') | |
274 | INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags)) | |
275 | LEFT JOIN contacts AS c ON (c.uid = {?} and c.contact = u.user_id) | |
276 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) | |
277 | INNER JOIN sections AS s ON (s.id = u.section) | |
787bb3d7 | 278 | LEFT JOIN photo AS p ON (p.uid = u.user_id) |
0337d704 | 279 | LEFT JOIN mentor AS m ON (m.uid = u.user_id) |
d9caac6f | 280 | LEFT JOIN emails AS e ON (e.uid = u.user_id AND e.flags='active') |
281 | WHERE a.alias = {?} | |
282 | GROUP BY u.user_id"; | |
08cce2ff | 283 | $res = XDB::query($reqsql, $from_uid, $login); |
0337d704 | 284 | $user = $res->fetchOneAssoc(); |
285 | $uid = $user['user_id']; | |
8b10988d | 286 | // hide orange status, cv, nickname, section |
287 | if (!has_user_right('private', $view)) { | |
288 | $user['promo_sortie'] = $user['promo'] + 3; | |
289 | $user['cv'] = ''; | |
290 | $user['nickname'] = ''; | |
291 | $user['section'] = ''; | |
292 | } | |
293 | // hide mobile | |
dd502514 | 294 | if (!has_user_right($user['mobile_pub'], $view)) { |
295 | if ($user['mobile'] == '') | |
296 | $user['mobile_pub'] = $view; | |
297 | else | |
298 | $user['mobile'] = ''; | |
299 | } | |
8b10988d | 300 | // hide web |
dd502514 | 301 | if (!has_user_right($user['web_pub'], $view)) { |
302 | if ($user['web'] == '') | |
303 | $user['web_pub'] = $view; | |
304 | else | |
305 | $user['web'] = ''; | |
306 | } | |
8b10988d | 307 | // hide freetext |
dd502514 | 308 | if (!has_user_right($user['freetext_pub'], $view)) { |
309 | if ($user['freetext'] == '') | |
310 | $user['freetext_pub'] = $view; | |
311 | else | |
312 | $user['freetext'] = ''; | |
313 | } | |
0337d704 | 314 | |
8b10988d | 315 | $user['adr_pro'] = get_user_details_pro($uid, $view); |
316 | $user['adr'] = get_user_details_adr($uid, $view); | |
0337d704 | 317 | |
8b10988d | 318 | if (has_user_right('private', $view)) { |
319 | $sql = "SELECT text | |
320 | FROM binets_ins | |
321 | LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id | |
322 | WHERE user_id = {?}"; | |
08cce2ff | 323 | $res = XDB::query($sql, $uid); |
8b10988d | 324 | $user['binets'] = $res->fetchColumn(); |
325 | $user['binets_join'] = join(', ', $user['binets']); | |
787bb3d7 | 326 | |
b37aacd9 FB |
327 | $res = XDB::iterRow("SELECT a.diminutif, a.nom, a.site |
328 | FROM groupex.asso AS a | |
329 | LEFT JOIN groupex.membres AS m ON (m.asso_id = a.id) | |
330 | WHERE m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions') | |
331 | AND pub = 'public'", $uid); | |
8b10988d | 332 | $user['gpxs'] = Array(); |
ae2f9e35 | 333 | $user['gpxs_name'] = Array(); |
b37aacd9 FB |
334 | while (list($gxd, $gxt, $gxu) = $res->next()) { |
335 | if (!$gxu) { | |
336 | $gxu = 'http://www.polytechnique.net/' . $gxd; | |
337 | } | |
338 | $user['gpxs'][] = '<span title="' . pl_entities($gxt) . "\"><a href=\"$gxu\">$gxd</a></span>"; | |
ae2f9e35 | 339 | $user['gpxs_name'][] = $gxt; |
787bb3d7 | 340 | } |
8b10988d | 341 | $user['gpxs_join'] = join(', ', $user['gpxs']); |
79a5acea | 342 | } |
0337d704 | 343 | |
08cce2ff | 344 | $res = XDB::iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type |
ae2f9e35 | 345 | FROM applis_ins |
346 | INNER JOIN applis_def ON applis_def.id = applis_ins.aid | |
347 | WHERE uid={?} | |
348 | ORDER BY ordre", $uid); | |
787bb3d7 | 349 | |
0337d704 | 350 | $user['applis_fmt'] = Array(); |
dd502514 | 351 | $user['formation'] = Array(); |
0337d704 | 352 | while (list($txt, $url, $type) = $res->next()) { |
dd502514 | 353 | $user['formation'][] = $txt." ".$type; |
0337d704 | 354 | require_once('applis.func.inc.php'); |
355 | $user['applis_fmt'][] = applis_fmt($type, $txt, $url); | |
356 | } | |
357 | $user['applis_join'] = join(', ', $user['applis_fmt']); | |
358 | ||
8b10988d | 359 | if (has_user_right($user['medals_pub'], $view)) { |
5e70bf24 | 360 | $res = XDB::iterator("SELECT m.id, m.text AS medal, m.type, s.gid, g.text AS grade |
ae2f9e35 | 361 | FROM profile_medals_sub AS s |
362 | INNER JOIN profile_medals AS m ON ( s.mid = m.id ) | |
363 | LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) | |
364 | WHERE s.uid = {?}", $uid); | |
8b10988d | 365 | $user['medals'] = Array(); |
366 | while ($tmp = $res->next()) { | |
367 | $user['medals'][] = $tmp; | |
368 | } | |
0337d704 | 369 | } |
370 | ||
371 | return $user; | |
372 | } | |
dd502514 | 373 | // }}} |
374 | // {{{ function add_user_address() | |
375 | function add_user_address($uid, $adrid, $adr) { | |
08cce2ff | 376 | XDB::execute( |
dd502514 | 377 | "INSERT INTO adresses (`uid`, `adrid`, `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `datemaj`, `pub`) ( |
378 | SELECT u.user_id, {?}, {?}, {?}, {?}, {?}, {?}, gp.a2, NOW(), {?} | |
379 | FROM auth_user_md5 AS u | |
380 | LEFT JOIN geoloc_pays AS gp ON (gp.pays LIKE {?} OR gp.country LIKE {?} OR gp.a2 LIKE {?}) | |
381 | WHERE u.user_id = {?} | |
382 | LIMIT 1)", | |
383 | $adrid, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], $adr['pub'], $adr['countrytxt'], $adr['countrytxt'], $adr['countrytxt'], $uid); | |
384 | if (isset($adr['tels']) && is_array($adr['tels'])) { | |
385 | $telid = 0; | |
386 | foreach ($adr['tels'] as $tel) if ($tel['tel']) { | |
387 | add_user_tel($uid, $adrid, $telid, $tel); | |
388 | $telid ++; | |
389 | } | |
390 | } | |
391 | } | |
392 | // }}} | |
393 | // {{{ function update_user_address() | |
394 | function update_user_address($uid, $adrid, $adr) { | |
dd502514 | 395 | // update address |
08cce2ff | 396 | XDB::execute( |
787bb3d7 | 397 | "UPDATE adresses AS a LEFT JOIN geoloc_pays AS gp ON (gp.pays = {?}) |
dd502514 | 398 | SET `adr1` = {?}, `adr2` = {?}, `adr3` = {?}, |
399 | `postcode` = {?}, `city` = {?}, a.`country` = gp.a2, `datemaj` = NOW(), `pub` = {?} | |
400 | WHERE adrid = {?} AND uid = {?}", | |
401 | $adr['country_txt'], | |
402 | $adr['adr1'], $adr['adr2'], $adr['adr3'], | |
403 | $adr['postcode'], $adr['city'], $adr['pub'], $adrid, $uid); | |
404 | if (isset($adr['tels']) && is_array($adr['tels'])) { | |
08cce2ff | 405 | $res = XDB::query("SELECT telid FROM tels WHERE uid = {?} AND adrid = {?} ORDER BY telid", $uid, $adrid); |
dd502514 | 406 | $telids = $res->fetchColumn(); |
407 | foreach ($adr['tels'] as $tel) { | |
408 | if (isset($tel['telid']) && isset($tel['remove']) && $tel['remove']) { | |
409 | remove_user_tel($uid, $adrid, $tel['telid']); | |
410 | if (isset($telids[$tel['telid']])) unset($telids[$tel['telid']]); | |
411 | } else if (isset($tel['telid'])) { | |
412 | update_user_tel($uid, $adrid, $tel['telid'], $tel); | |
413 | } else { | |
414 | for ($telid = 0; isset($telids[$telid]) && ($telids[$telid] == $telid); $telid++); | |
415 | add_user_tel($uid, $adrid, $telid, $tel); | |
416 | } | |
417 | } | |
418 | } | |
419 | } | |
420 | // }}} | |
421 | // {{{ function remove_user_address() | |
422 | function remove_user_address($uid, $adrid) { | |
08cce2ff | 423 | XDB::execute("DELETE FROM adresses WHERE adrid = {?} AND uid = {?}", $adrid, $uid); |
424 | XDB::execute("DELETE FROM tels WHERE adrid = {?} AND uid = {?}", $adrid, $uid); | |
dd502514 | 425 | } |
426 | // }}} | |
427 | // {{{ function add_user_tel() | |
428 | function add_user_tel($uid, $adrid, $telid, $tel) { | |
08cce2ff | 429 | XDB::execute( |
dd502514 | 430 | "INSERT INTO tels SET uid = {?}, adrid = {?}, telid = {?}, tel = {?}, tel_type = {?}, tel_pub = {?}", |
431 | $uid, $adrid, $telid, $tel['tel'], $tel['tel_type'], $tel['tel_pub']); | |
432 | } | |
433 | // }}} | |
434 | // {{{ function update_user_tel() | |
435 | function update_user_tel($uid, $adrid, $telid, $tel) { | |
08cce2ff | 436 | XDB::execute( |
dd502514 | 437 | "UPDATE tels SET tel = {?}, tel_type = {?}, tel_pub = {?} |
438 | WHERE telid = {?} AND adrid = {?} AND uid = {?}", | |
439 | $tel['tel'], $tel['tel_type'], $tel['tel_pub'], | |
440 | $telid, $adrid, $uid); | |
441 | } | |
442 | // }}} | |
443 | // {{{ function remove_user_tel() | |
444 | function remove_user_tel($uid, $adrid, $telid) { | |
a3a049fc | 445 | XDB::execute("DELETE FROM tels WHERE telid = {?} AND adrid = {?} AND uid = {?}", |
446 | $telid, $adrid, $uid); | |
dd502514 | 447 | } |
448 | // }}} | |
449 | // {{{ function add_user_pro() | |
450 | function add_user_pro($uid, $entrid, $pro) { | |
08cce2ff | 451 | XDB::execute( |
dd502514 | 452 | "INSERT INTO entreprises (`uid`, `entrid`, `entreprise`, `poste`, `secteur`, `ss_secteur`, `fonction`, |
453 | `adr1`, `adr2`, `adr3`, `postcode`, `city`, `country`, `region`, `tel`, `fax`, `mobile`, `email`, `web`, `pub`, `adr_pub`, `tel_pub`, `email_pub`) | |
454 | SELECT u.user_id, {?}, {?}, {?}, s.id, ss.id, f.id, | |
455 | {?}, {?}, {?}, {?}, {?}, gp.a2, gr.region, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?} | |
456 | FROM auth_user_md5 AS u | |
457 | LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?}) | |
458 | LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?}) | |
459 | LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?}) | |
460 | LEFT JOIN geoloc_pays AS gp ON (gp.country LIKE {?} OR gp.pays LIKE {?}) | |
461 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = gp.a2 AND gr.name LIKE {?}) | |
462 | WHERE u.user_id = {?} | |
463 | LIMIT 1", | |
464 | $entrid, $pro['entreprise'], $pro['poste'], | |
465 | $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'], | |
466 | $pro['secteur'], $pro['sous_secteur'], $pro['fonction'], $pro['fonction'], | |
467 | $pro['countrytxt'], $pro['countrytxt'], $pro['region'], | |
468 | $uid); | |
469 | } | |
470 | // }}} | |
471 | // {{{ function update_user_pro() | |
472 | function update_user_pro($uid, $entrid, $pro) { | |
dd502514 | 473 | $join = ""; |
474 | $set = ""; | |
475 | $args_join = array(); | |
476 | $args_set = array(); | |
787bb3d7 | 477 | |
dd502514 | 478 | $join .= "LEFT JOIN emploi_secteur AS s ON(s.label LIKE {?}) |
479 | LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND ss.label LIKE {?}) | |
480 | LEFT JOIN fonctions_def AS f ON(f.fonction_fr LIKE {?} OR f.fonction_en LIKE {?})"; | |
481 | $args_join[] = $pro['secteur']; | |
482 | $args_join[] = $pro['sous_secteur']; | |
483 | $args_join[] = $pro['fonction']; | |
484 | $args_join[] = $pro['fonction']; | |
485 | $set .= ", e.`entreprise` = {?}, e.`secteur` = s.id, e.`ss_secteur` = ss.id, e.`fonction` = f.id, e.`poste`= {?}, e.`web` = {?}, e.`pub` = {?}"; | |
486 | $args_set[] = $pro['entreprise']; | |
487 | $args_set[] = $pro['poste']; | |
488 | $args_set[] = $pro['web']; | |
489 | $args_set[] = $pro['pub']; | |
787bb3d7 | 490 | |
dd502514 | 491 | if (isset($pro['adr1'])) { |
492 | $join .= "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 | $args_join[] = $pro['countrytxt']; | |
495 | $args_join[] = $pro['countrytxt']; | |
496 | $args_join[] = $pro['region']; | |
497 | $set .= ", e.`adr1` = {?}, e.`adr2` = {?}, e.`adr3` = {?}, e.`postcode` = {?}, e.`city` = {?}, e.`country` = gp.a2, e.`region` = gr.region, e.`adr_pub` = {?}"; | |
498 | $args_set[] = $pro['adr1']; | |
499 | $args_set[] = $pro['adr2']; | |
500 | $args_set[] = $pro['adr3']; | |
501 | $args_set[] = $pro['postcode']; | |
502 | $args_set[] = $pro['city']; | |
503 | $args_set[] = $pro['adr_pub']; | |
504 | } | |
787bb3d7 | 505 | |
dd502514 | 506 | if (isset($pro['tel'])) { |
507 | $set .= ", e.`tel` = {?}, e.`fax` = {?}, e.`mobile` = {?}, e.tel_pub = {?}"; | |
508 | $args_set[] = $pro['tel']; | |
509 | $args_set[] = $pro['fax']; | |
510 | $args_set[] = $pro['mobile']; | |
511 | $args_set[] = $pro['tel_pub']; | |
512 | } | |
513 | if (isset($pro['email'])) { | |
514 | $set .= ", e.`email` = {?}, e.`email_pub` = {?}"; | |
515 | $args_set[] = $pro['email']; | |
516 | $args_set[] = $pro['email_pub']; | |
787bb3d7 | 517 | } |
dd502514 | 518 | $query = "UPDATE entreprises AS e ".$join." SET ".substr($set,1)." WHERE e.uid = {?} AND e.entrid = {?}"; |
519 | $args_where = array($uid, $entrid); | |
520 | $args = array_merge(array($query), $args_join, $args_set, $args_where); | |
a3a049fc | 521 | call_user_func_array(array('XDB', 'execute'), $args); |
dd502514 | 522 | } |
523 | // }}} | |
524 | // {{{ function remove_user_pro() | |
525 | function remove_user_pro($uid, $entrid) { | |
08cce2ff | 526 | XDB::execute("DELETE FROM entreprises WHERE entrid = {?} AND uid = {?}", $entrid, $uid); |
dd502514 | 527 | } |
528 | // }}} | |
529 | // {{{ function set_user_details() | |
530 | function set_user_details_addresses($uid, $adrs) { | |
08cce2ff | 531 | $res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid); |
dd502514 | 532 | $adrids = $res->fetchColumn(); |
533 | foreach ($adrs as $adr) { | |
534 | if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) { | |
535 | remove_user_address($uid, $adr['adrid']); | |
536 | if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]); | |
537 | } else if (isset($adr['adrid'])) { | |
538 | update_user_address($uid, $adr['adrid'], $adr); | |
539 | } else { | |
540 | for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++); | |
541 | add_user_address($uid, $adrid, $adr); | |
542 | $adrids[$adrid-1] = $adrid; | |
543 | } | |
544 | } | |
545 | require_once 'geoloc.inc.php'; | |
546 | localize_addresses($uid); | |
547 | } | |
548 | // }}} | |
549 | // {{{ function set_user_details_pro() | |
550 | ||
551 | function set_user_details_pro($uid, $pros) | |
552 | { | |
08cce2ff | 553 | $res = XDB::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid); |
dd502514 | 554 | $entrids = $res->fetchColumn(); |
555 | foreach ($pros as $pro) { | |
556 | if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) { | |
557 | remove_user_pro($uid, $pro['entrid']); | |
558 | if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]); | |
559 | } else if (isset($pro['entrid'])) { | |
560 | update_user_pro($uid, $pro['entrid'], $pro); | |
561 | } else { | |
562 | for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++); | |
563 | add_user_pro($uid, $entrid, $pro); | |
564 | } | |
565 | } | |
566 | } | |
0337d704 | 567 | |
568 | // }}} | |
dd502514 | 569 | // {{{ function set_user_details() |
570 | function set_user_details($uid, $details) { | |
dd502514 | 571 | if (isset($details['nom_usage'])) { |
08cce2ff | 572 | XDB::execute("UPDATE auth_user_md5 SET nom_usage = {?} WHERE user_id = {?}", strtoupper($details['nom_usage']), $uid); |
dd502514 | 573 | } |
574 | if (isset($details['mobile'])) { | |
08cce2ff | 575 | XDB::execute("UPDATE auth_user_quick SET profile_mobile = {?} WHERE user_id = {?}", $details['mobile'], $uid); |
dd502514 | 576 | } |
577 | if (isset($details['nationalite'])) { | |
08cce2ff | 578 | XDB::execute( |
dd502514 | 579 | "UPDATE auth_user_md5 AS u |
580 | INNER JOIN geoloc_pays AS gp | |
581 | SET u.nationalite = gp.a2 | |
582 | WHERE (gp.a2 = {?} OR gp.nat = {?}) | |
583 | AND u.user_id = {?}", $details['nationalite'], $details['nationalite'], $uid); | |
584 | } | |
585 | if (isset($details['adr']) && is_array($details['adr'])) | |
586 | set_user_details_addresses($uid, $details['adr']); | |
587 | if (isset($details['adr_pro']) && is_array($details['adr_pro'])) | |
588 | set_user_details_pro($uid, $details['adr_pro']); | |
589 | if (isset($details['binets']) && is_array($details['binets'])) { | |
08cce2ff | 590 | XDB::execute("DELETE FROM binets_ins WHERE user_id = {?}", $uid); |
dd502514 | 591 | foreach ($details['binets'] as $binet) |
08cce2ff | 592 | XDB::execute( |
dd502514 | 593 | "INSERT INTO binets_ins (`user_id`, `binet_id`) |
594 | SELECT {?}, id FROM binets_def WHERE text = {?} LIMIT 1", | |
787bb3d7 | 595 | $uid, $binet); |
dd502514 | 596 | } |
597 | if (isset($details['gpxs']) && is_array($details['gpxs'])) { | |
08cce2ff | 598 | XDB::execute("DELETE FROM groupesx_ins WHERE user_id = {?}", $uid); |
dd502514 | 599 | foreach ($details['gpxs'] as $groupex) { |
a14159bf | 600 | if (preg_match('/<a href="[^"]*">([^<]+)</a>/u', $groupex, $a)) $groupex = $a[1]; |
08cce2ff | 601 | XDB::execute( |
dd502514 | 602 | "INSERT INTO groupesx_ins (`user_id`, `binet_id`) |
603 | SELECT {?}, id FROM groupesx_def WHERE text = {?} LIMIT 1", | |
604 | $uid, $groupex); | |
787bb3d7 | 605 | } |
dd502514 | 606 | } |
607 | // applis | |
608 | // medals | |
609 | } | |
610 | // }}} | |
0337d704 | 611 | // {{{ function _user_reindex |
612 | ||
c0c9f772 | 613 | function _user_reindex($uid, $keys, $muls, $pubs) |
94f6c381 | 614 | { |
0337d704 | 615 | foreach ($keys as $i => $key) { |
616 | if ($key == '') { | |
617 | continue; | |
618 | } | |
619 | $toks = preg_split('/[ \'\-]+/', $key); | |
620 | $token = ""; | |
621 | $first = 5; | |
622 | while ($toks) { | |
623 | $token = strtolower(replace_accent(array_pop($toks) . $token)); | |
624 | $score = ($toks ? 0 : 10 + $first) * $muls[$i]; | |
c0c9f772 | 625 | XDB::execute("REPLACE INTO search_name (token, uid, soundex, score, flags) |
626 | VALUES ({?}, {?}, {?}, {?}, {?})", | |
627 | $token, $uid, soundex_fr($token), $score, $pubs[$i] ? 'public' : ''); | |
0337d704 | 628 | $first = 0; |
629 | } | |
630 | } | |
94f6c381 | 631 | $res = XDB::query("SELECT nom_ini, nom, nom_usage, prenom_ini, prenom, promo, matricule |
632 | FROM auth_user_md5 | |
633 | WHERE user_id = {?}", $uid); | |
634 | if (!$res->numRows()) { | |
635 | unset($res); | |
636 | return; | |
637 | } | |
638 | $array = $res->fetchOneRow(); | |
639 | $promo = intval(array_pop($array)); | |
640 | $mat = array_shift($array); | |
641 | array_walk($array, 'soundex_fr'); | |
642 | XDB::execute("REPLACE INTO recherche_soundex | |
643 | SET matricule = {?}, nom1_soundex = {?}, nom2_soundex= {?}, nom3_soundex = {?}, | |
644 | prenom1_soundex = {?}, prenom2_soundex= {?}, promo = {?}", | |
645 | $mat, $array[0], $array[1], $array[2], $array[3], $array[4], $promo); | |
646 | unset($res); | |
647 | unset($array); | |
0337d704 | 648 | } |
649 | ||
650 | // }}} | |
651 | // {{{ function user_reindex | |
652 | ||
653 | function user_reindex($uid) { | |
08cce2ff | 654 | XDB::execute("DELETE FROM search_name WHERE uid={?}", $uid); |
655 | $res = XDB::query("SELECT prenom, nom, nom_usage, profile_nick FROM auth_user_md5 INNER JOIN auth_user_quick USING(user_id) WHERE auth_user_md5.user_id = {?}", $uid); | |
36f58fcf | 656 | if ($res->numRows()) { |
c0c9f772 | 657 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2), array(true, true, true, false)); |
36f58fcf | 658 | } else { // not in auth_user_quick => still "pending" |
659 | $res = XDB::query("SELECT prenom, nom, nom_usage FROM auth_user_md5 WHERE auth_user_md5.user_id = {?}", $uid); | |
660 | if ($res->numRows()) { | |
c0c9f772 | 661 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1), array(true, true, true)); |
36f58fcf | 662 | } |
663 | } | |
0337d704 | 664 | } |
665 | ||
666 | // }}} | |
433336f3 | 667 | // {{{ function set_new_usage() |
74c55fd6 | 668 | |
a11b5424 | 669 | function set_new_usage($uid, $usage, $alias=false) |
787bb3d7 | 670 | { |
74c55fd6 | 671 | XDB::execute("UPDATE auth_user_md5 set nom_usage={?} WHERE user_id={?}",$usage ,$uid); |
672 | XDB::execute("DELETE FROM aliases WHERE FIND_IN_SET('usage',flags) AND id={?}", $uid); | |
673 | if ($alias && $usage) { | |
674 | XDB::execute("UPDATE aliases SET flags=flags & 255-1 WHERE id={?}", $uid); | |
675 | XDB::execute("INSERT INTO aliases VALUES({?}, 'alias', 'usage,bestalias', {?}, null)", | |
676 | $alias, $uid); | |
677 | } | |
678 | $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid); | |
a11b5424 | 679 | if ($r->numRows() == "") { |
74c55fd6 | 680 | XDB::execute("UPDATE aliases SET flags = 1 | flags WHERE id = {?} LIMIT 1", $uid); |
a11b5424 | 681 | $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid); |
74c55fd6 | 682 | } |
74c55fd6 | 683 | user_reindex($uid); |
a11b5424 | 684 | return $r->fetchOneCell(); |
74c55fd6 | 685 | } |
686 | ||
433336f3 | 687 | // }}} |
688 | // {{{ function get_X_mat | |
689 | function get_X_mat($ourmat) | |
690 | { | |
787bb3d7 | 691 | if (!preg_match('/^[0-9]{8}$/', $ourmat)) { |
433336f3 | 692 | // le matricule de notre base doit comporter 8 chiffres |
693 | return 0; | |
787bb3d7 FB |
694 | } |
695 | ||
433336f3 | 696 | $year = intval(substr($ourmat, 0, 4)); |
697 | $rang = intval(substr($ourmat, 5, 3)); | |
698 | if ($year < 1996) { | |
787bb3d7 | 699 | return; |
433336f3 | 700 | } elseif ($year < 2000) { |
701 | $year = intval(substr(1900 - $year, 1, 3)); | |
702 | return sprintf('%02u0%03u', $year, $rang); | |
703 | } else { | |
704 | $year = intval(substr(1900 - $year, 1, 3)); | |
705 | return sprintf('%03u%03u', $year, $rang); | |
706 | } | |
787bb3d7 FB |
707 | } |
708 | ||
433336f3 | 709 | // }}} |
710 | ||
711 | ||
a7de4ef7 | 712 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 713 | ?> |