| 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 | |
| 90 | list($mbox, $fqdn) = split('@', $data); |
| 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()) { |
| 111 | list($alias) = split('@', $redir); |
| 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 | // }}} |
| 153 | // {{{ function get_user_details() |
| 154 | |
| 155 | function &get_user_details($login, $from_uid = '') |
| 156 | { |
| 157 | global $globals; |
| 158 | $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv, |
| 159 | u.perms IN ('admin','user') AS inscrit, FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces, |
| 160 | q.profile_nick AS nickname, q.profile_from_ax, q.profile_mobile AS mobile, q.profile_web AS web, q.profile_freetext AS freetext, |
| 161 | q.profile_mobile_pub AS mobile_pub, q.profile_web_pub AS web_pub, q.profile_freetext_pub AS freetext_pub, |
| 162 | q.profile_medals_pub AS medals_pub, |
| 163 | IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166, |
| 164 | a.alias AS forlife, a2.alias AS bestalias, |
| 165 | c.uid IS NOT NULL AS is_contact, |
| 166 | s.text AS section, p.x, p.y, p.pub AS photo_pub, |
| 167 | m.expertise != '' AS is_referent |
| 168 | |
| 169 | FROM auth_user_md5 AS u |
| 170 | INNER JOIN auth_user_quick AS q USING(user_id) |
| 171 | INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') |
| 172 | INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags)) |
| 173 | LEFT JOIN contacts AS c ON (c.uid = {?} and c.contact = u.user_id) |
| 174 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) |
| 175 | INNER JOIN sections AS s ON (s.id = u.section) |
| 176 | LEFT JOIN photo AS p ON (p.uid = u.user_id) |
| 177 | LEFT JOIN mentor AS m ON (m.uid = u.user_id) |
| 178 | WHERE a.alias = {?}"; |
| 179 | $res = $globals->xdb->query($reqsql, $from_uid, $login); |
| 180 | $user = $res->fetchOneAssoc(); |
| 181 | $uid = $user['user_id']; |
| 182 | |
| 183 | $sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, |
| 184 | e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, |
| 185 | gp.pays AS countrytxt, gr.name AS region, e.tel, e.fax, e.mobile, e.entrid, |
| 186 | e.pub, e.adr_pub, e.tel_pub, e.email, e.email_pub, e.web |
| 187 | FROM entreprises AS e |
| 188 | LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) |
| 189 | LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) |
| 190 | LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) |
| 191 | LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country) |
| 192 | LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region) |
| 193 | WHERE e.uid = {?} |
| 194 | ORDER BY e.entrid"; |
| 195 | $res = $globals->xdb->query($sql, $uid); |
| 196 | $user['adr_pro'] = $res->fetchAllAssoc(); |
| 197 | |
| 198 | $sql = "SELECT a.adr1,a.adr2,a.adr3,a.postcode,a.city, |
| 199 | gp.pays AS countrytxt,gr.name AS region,a.tel,a.fax, |
| 200 | FIND_IN_SET('active', a.statut) AS active, a.adrid, |
| 201 | FIND_IN_SET('res-secondaire', a.statut) AS secondaire, |
| 202 | a.pub, a.tel_pub |
| 203 | FROM adresses AS a |
| 204 | LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) |
| 205 | LEFT JOIN geoloc_region AS gr ON (gr.a2=a.country and gr.region=a.region) |
| 206 | WHERE uid= {?} AND NOT FIND_IN_SET('pro',a.statut) |
| 207 | ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; |
| 208 | $res = $globals->xdb->query($sql, $uid); |
| 209 | $user['adr'] = $res->fetchAllAssoc(); |
| 210 | |
| 211 | $sql = "SELECT text |
| 212 | FROM binets_ins |
| 213 | LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id |
| 214 | WHERE user_id = {?}"; |
| 215 | $res = $globals->xdb->query($sql, $uid); |
| 216 | $user['binets'] = $res->fetchColumn(); |
| 217 | $user['binets_join'] = join(', ', $user['binets']); |
| 218 | |
| 219 | $res = $globals->xdb->iterRow("SELECT text, url |
| 220 | FROM groupesx_ins |
| 221 | LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id |
| 222 | WHERE guid = {?}", $uid); |
| 223 | $user['gpxs'] = Array(); |
| 224 | while (list($gxt, $gxu) = $res->next()) { |
| 225 | $user['gpxs'][] = $gxu ? "<a href=\"$gxu\">$gxt</a>" : $gxt; |
| 226 | } |
| 227 | $user['gpxs_join'] = join(', ', $user['gpxs']); |
| 228 | |
| 229 | $res = $globals->xdb->iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type |
| 230 | FROM applis_ins |
| 231 | INNER JOIN applis_def ON applis_def.id = applis_ins.aid |
| 232 | WHERE uid={?} |
| 233 | ORDER BY ordre", $uid); |
| 234 | |
| 235 | $user['applis_fmt'] = Array(); |
| 236 | while (list($txt, $url, $type) = $res->next()) { |
| 237 | require_once('applis.func.inc.php'); |
| 238 | $user['applis_fmt'][] = applis_fmt($type, $txt, $url); |
| 239 | } |
| 240 | $user['applis_join'] = join(', ', $user['applis_fmt']); |
| 241 | |
| 242 | $res = $globals->xdb->iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade |
| 243 | FROM profile_medals_sub AS s |
| 244 | INNER JOIN profile_medals AS m ON ( s.mid = m.id ) |
| 245 | LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) |
| 246 | WHERE s.uid = {?}", $uid); |
| 247 | $user['medals'] = Array(); |
| 248 | while ($tmp = $res->next()) { |
| 249 | $user['medals'][] = $tmp; |
| 250 | } |
| 251 | |
| 252 | return $user; |
| 253 | } |
| 254 | |
| 255 | // }}} |
| 256 | // {{{ function _user_reindex |
| 257 | |
| 258 | function _user_reindex($uid, $keys, $muls) { |
| 259 | global $globals; |
| 260 | foreach ($keys as $i => $key) { |
| 261 | if ($key == '') { |
| 262 | continue; |
| 263 | } |
| 264 | $toks = preg_split('/[ \'\-]+/', $key); |
| 265 | $token = ""; |
| 266 | $first = 5; |
| 267 | while ($toks) { |
| 268 | $token = strtolower(replace_accent(array_pop($toks) . $token)); |
| 269 | $score = ($toks ? 0 : 10 + $first) * $muls[$i]; |
| 270 | mysql_query("REPLACE INTO search_name (token, uid, score) VALUES('$token',$uid,$score)"); |
| 271 | $first = 0; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // }}} |
| 277 | // {{{ function user_reindex |
| 278 | |
| 279 | function user_reindex($uid) { |
| 280 | global $globals; |
| 281 | $globals->xdb->execute("DELETE FROM search_name WHERE uid={?}", $uid); |
| 282 | $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); |
| 283 | _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2)); |
| 284 | } |
| 285 | |
| 286 | // }}} |
| 287 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
| 288 | ?> |