0337d704 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 Polytechnique.org * |
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 | { |
29 | // keep datas in : aliases, adresses, 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 |
32 | // + delete maillists |
33 | |
34 | global $globals; |
35 | $uid = intval($user_id); |
36 | $res = $globals->xdb->query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $uid); |
37 | $alias = $res->fetchOneCell(); |
38 | |
39 | if ($really_del) { |
40 | $globals->xdb->execute("DELETE FROM emails WHERE uid={?}", $uid); |
41 | $globals->xdb->execute("DELETE FROM newsletter_ins WHERE user_id={?}", $uid); |
42 | } |
43 | |
44 | $globals->xdb->execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain); |
45 | $globals->xdb->execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain2); |
46 | |
47 | $globals->xdb->execute("UPDATE auth_user_md5 SET password='',smtppass='' WHERE user_id={?}", $uid); |
48 | $globals->xdb->execute("UPDATE auth_user_quick SET watch_flags='' WHERE user_id={?}", $uid); |
49 | |
50 | $globals->xdb->execute("DELETE FROM competences_ins WHERE uid={?}", $uid); |
51 | $globals->xdb->execute("DELETE FROM entreprises WHERE uid={?}", $uid); |
52 | $globals->xdb->execute("DELETE FROM langues_ins WHERE uid={?}", $uid); |
53 | $globals->xdb->execute("DELETE FROM mentor_pays WHERE uid={?}", $uid); |
54 | $globals->xdb->execute("DELETE FROM mentor_secteur WHERE uid={?}", $uid); |
55 | $globals->xdb->execute("DELETE FROM mentor WHERE uid={?}", $uid); |
56 | $globals->xdb->execute("DELETE FROM perte_pass WHERE uid={?}", $uid); |
57 | $globals->xdb->execute("DELETE FROM requests WHERE user_id={?}", $uid); |
58 | $globals->xdb->execute("DELETE FROM user_changes WHERE user_id={?}", $uid); |
59 | $globals->xdb->execute("DELETE FROM watch_sub WHERE uid={?}", $uid); |
60 | |
61 | include_once('lists.inc.php'); |
62 | if (function_exists(lists_xmlrpc)) { |
63 | $client =& lists_xmlrpc(Session::getInt('id'), Session::get('password')); |
64 | $client->kill($alias, $really_del); |
65 | } |
66 | } |
67 | |
68 | // }}} |
69 | // {{{ function get_user_login() |
70 | |
71 | function get_user_login($data, $get_forlife = false) { |
72 | global $globals, $page; |
73 | |
74 | if (preg_match(',^[0-9]*$,', $data)) { |
75 | $res = $globals->xdb->query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $data); |
76 | if ($res->numRows()) { |
77 | return $res->fetchOneCell(); |
78 | } else { |
79 | $page->trig("il n'y a pas d'utilisateur avec cet id"); |
80 | return false; |
81 | } |
82 | } |
83 | |
84 | $data = trim(strtolower($data)); |
85 | |
86 | if (strstr($data, '@')===false) { |
87 | $data = $data.'@'.$globals->mail->domain; |
88 | } |
89 | |
575dd9be |
90 | list($mbox, $fqdn) = explode('@', $data); |
0337d704 |
91 | if ($fqdn == $globals->mail->domain || $fqdn == $globals->mail->domain2) { |
92 | |
93 | $res = $globals->xdb->query("SELECT a.alias |
94 | FROM aliases AS a |
95 | INNER JOIN aliases AS b ON (a.id = b.id AND b.type IN ('alias', 'a_vie') AND b.alias={?}) |
96 | WHERE a.type = 'a_vie'", $mbox); |
97 | if ($res->numRows()) { |
98 | return $get_forlife ? $res->fetchOneCell() : $mbox; |
99 | } else { |
100 | $page->trig("il n'y a pas d'utilisateur avec ce login"); |
101 | return false; |
102 | } |
103 | |
104 | } elseif ($fqdn == $globals->mail->alias_dom || $fqdn == $globals->mail->alias_dom2) { |
105 | |
106 | $res = $globals->xdb->query("SELECT redirect |
107 | FROM virtual_redirect |
108 | INNER JOIN virtual USING(vid) |
109 | WHERE alias={?}", $mbox.'@'.$globals->mail->alias_dom); |
110 | if ($redir = $res->fetchOneCell()) { |
575dd9be |
111 | list($alias) = explode('@', $redir); |
0337d704 |
112 | } else { |
113 | $page->trig("il n'y a pas d'utilisateur avec cet alias"); |
114 | $alias = false; |
115 | } |
116 | return $alias; |
117 | |
118 | } else { |
119 | |
120 | $res = $globals->xdb->query("SELECT alias |
121 | FROM aliases AS a |
122 | INNER JOIN emails AS e ON e.uid=a.id |
123 | WHERE e.email={?} AND a.type='a_vie'", $data); |
124 | switch ($i = $res->numRows()) { |
125 | case 0: |
126 | $page->trig("il n'y a pas d'utilisateur avec cette addresse mail"); |
127 | return false; |
128 | |
129 | case 1: |
130 | return $res->fetchOneCell(); |
131 | |
132 | default: |
133 | if (has_perms()) { |
134 | $aliases = $res->fetchColumn(); |
135 | $page->trig("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases)); |
136 | } else { |
137 | $res->free(); |
138 | } |
139 | } |
140 | } |
141 | |
142 | return false; |
143 | } |
144 | |
145 | // }}} |
146 | // {{{ function get_user_forlife() |
147 | |
148 | function get_user_forlife($data) { |
149 | return get_user_login($data, true); |
150 | } |
151 | |
152 | // }}} |
9039c94d |
153 | // {{{ function get_user_details_pro() |
154 | |
155 | function get_user_details_pro($uid) |
156 | { |
157 | global $globals; |
158 | $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, |
159 | e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, |
160 | gp.pays AS countrytxt, gr.name AS region, e.tel, e.fax, e.mobile, e.entrid, |
161 | e.pub, e.adr_pub, e.tel_pub, e.email, e.email_pub, e.web |
162 | FROM entreprises AS e |
163 | LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) |
164 | LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) |
165 | LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) |
166 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country) |
167 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region) |
168 | WHERE e.uid = {?} |
169 | ORDER BY e.entrid"; |
170 | $res = $globals->xdb->query($sql, $uid); |
171 | return $res->fetchAllAssoc(); |
172 | } |
173 | |
174 | // }}} |
0337d704 |
175 | // {{{ function get_user_details() |
176 | |
177 | function &get_user_details($login, $from_uid = '') |
178 | { |
179 | global $globals; |
180 | $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv, |
181 | u.perms IN ('admin','user') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces, |
182 | q.profile_nick AS nickname, q.profile_from_ax, q.profile_mobile AS mobile, q.profile_web AS web, q.profile_freetext AS freetext, |
183 | q.profile_mobile_pub AS mobile_pub, q.profile_web_pub AS web_pub, q.profile_freetext_pub AS freetext_pub, |
184 | q.profile_medals_pub AS medals_pub, |
185 | IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166, |
186 | a.alias AS forlife, a2.alias AS bestalias, |
187 | c.uid IS NOT NULL AS is_contact, |
188 | s.text AS section, p.x, p.y, p.pub AS photo_pub, |
189 | m.expertise != '' AS is_referent |
190 | |
191 | FROM auth_user_md5 AS u |
192 | INNER JOIN auth_user_quick AS q USING(user_id) |
193 | INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') |
194 | INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags)) |
195 | LEFT JOIN contacts AS c ON (c.uid = {?} and c.contact = u.user_id) |
196 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) |
197 | INNER JOIN sections AS s ON (s.id = u.section) |
198 | LEFT JOIN photo AS p ON (p.uid = u.user_id) |
199 | LEFT JOIN mentor AS m ON (m.uid = u.user_id) |
200 | WHERE a.alias = {?}"; |
201 | $res = $globals->xdb->query($reqsql, $from_uid, $login); |
202 | $user = $res->fetchOneAssoc(); |
203 | $uid = $user['user_id']; |
204 | |
9039c94d |
205 | $user['adr_pro'] = get_user_details_pro($uid); |
0337d704 |
206 | |
207 | $sql = "SELECT a.adr1,a.adr2,a.adr3,a.postcode,a.city, |
80ca1b4e |
208 | gp.pays AS countrytxt,a.region, a.regiontxt, a.tel,a.fax, |
0337d704 |
209 | FIND_IN_SET('active', a.statut) AS active, a.adrid, |
210 | FIND_IN_SET('res-secondaire', a.statut) AS secondaire, |
80ca1b4e |
211 | a.pub, a.tel_pub, gp.display |
0337d704 |
212 | FROM adresses AS a |
213 | LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) |
0337d704 |
214 | WHERE uid= {?} AND NOT FIND_IN_SET('pro',a.statut) |
215 | ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; |
216 | $res = $globals->xdb->query($sql, $uid); |
217 | $user['adr'] = $res->fetchAllAssoc(); |
218 | |
219 | $sql = "SELECT text |
220 | FROM binets_ins |
221 | LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id |
222 | WHERE user_id = {?}"; |
223 | $res = $globals->xdb->query($sql, $uid); |
224 | $user['binets'] = $res->fetchColumn(); |
225 | $user['binets_join'] = join(', ', $user['binets']); |
226 | |
227 | $res = $globals->xdb->iterRow("SELECT text, url |
228 | FROM groupesx_ins |
229 | LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id |
230 | WHERE guid = {?}", $uid); |
231 | $user['gpxs'] = Array(); |
232 | while (list($gxt, $gxu) = $res->next()) { |
233 | $user['gpxs'][] = $gxu ? "<a href=\"$gxu\">$gxt</a>" : $gxt; |
234 | } |
235 | $user['gpxs_join'] = join(', ', $user['gpxs']); |
236 | |
237 | $res = $globals->xdb->iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type |
238 | FROM applis_ins |
239 | INNER JOIN applis_def ON applis_def.id = applis_ins.aid |
240 | WHERE uid={?} |
241 | ORDER BY ordre", $uid); |
242 | |
243 | $user['applis_fmt'] = Array(); |
244 | while (list($txt, $url, $type) = $res->next()) { |
245 | require_once('applis.func.inc.php'); |
246 | $user['applis_fmt'][] = applis_fmt($type, $txt, $url); |
247 | } |
248 | $user['applis_join'] = join(', ', $user['applis_fmt']); |
249 | |
250 | $res = $globals->xdb->iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade |
251 | FROM profile_medals_sub AS s |
252 | INNER JOIN profile_medals AS m ON ( s.mid = m.id ) |
253 | LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) |
254 | WHERE s.uid = {?}", $uid); |
255 | $user['medals'] = Array(); |
256 | while ($tmp = $res->next()) { |
257 | $user['medals'][] = $tmp; |
258 | } |
259 | |
260 | return $user; |
261 | } |
262 | |
263 | // }}} |
264 | // {{{ function _user_reindex |
265 | |
266 | function _user_reindex($uid, $keys, $muls) { |
267 | global $globals; |
268 | foreach ($keys as $i => $key) { |
269 | if ($key == '') { |
270 | continue; |
271 | } |
272 | $toks = preg_split('/[ \'\-]+/', $key); |
273 | $token = ""; |
274 | $first = 5; |
275 | while ($toks) { |
276 | $token = strtolower(replace_accent(array_pop($toks) . $token)); |
277 | $score = ($toks ? 0 : 10 + $first) * $muls[$i]; |
278 | mysql_query("REPLACE INTO search_name (token, uid, score) VALUES('$token',$uid,$score)"); |
279 | $first = 0; |
280 | } |
281 | } |
282 | } |
283 | |
284 | // }}} |
285 | // {{{ function user_reindex |
286 | |
287 | function user_reindex($uid) { |
288 | global $globals; |
289 | $globals->xdb->execute("DELETE FROM search_name WHERE uid={?}", $uid); |
290 | $res = $globals->xdb->query("SELECT prenom, nom, nom_usage, profile_nick FROM auth_user_md5 INNER JOIN auth_user_quick USING(user_id) WHERE auth_user_md5.user_id = {?}", $uid); |
291 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2)); |
292 | } |
293 | |
294 | // }}} |
295 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
296 | ?> |