Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 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 | { | |
043bbacf | 29 | // keep datas in : aliases, adresses, tels, profile_education, binets_ins, contacts, groupesx_ins, homonymes, identification_ax, photo |
eab7c014 | 30 | // delete in : competences_ins, emails, entreprises, langues_ins, mentor, |
0337d704 | 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 | |
0c1e3a66 | 39 | // TODO: clear profile. |
f9cddbef | 40 | $tables_to_clear = array('uid' => array('competences_ins', 'profile_job', 'langues_ins', 'profile_mentor_country', |
5fecdf6d | 41 | 'profile_mentor_sector', 'profile_mentor', 'perte_pass', 'watch_sub'), |
425f432d | 42 | 'user_id' => array('requests', 'user_changes')); |
43 | ||
0337d704 | 44 | if ($really_del) { |
b235d980 | 45 | array_push($tables_to_clear['uid'], 'emails', 'groupex.membres', 'contacts', 'adresses', 'profile_phones', |
7d15f750 | 46 | 'photo', 'perte_pass', 'langues_ins', 'forum_subs', 'forum_profiles'); |
eab7c014 | 47 | array_push($tables_to_clear['user_id'], 'newsletter_ins', 'binets_ins'); |
787bb3d7 | 48 | $tables_to_clear['id'] = array('aliases'); |
425f432d | 49 | $tables_to_clear['contact'] = array('contacts'); |
0c1e3a66 FB |
50 | XDB::execute("UPDATE accounts |
51 | SET registration_date = 0, state = 'pending', password = NULL, weak_password = NULL, token = NULL, is_admin = 0 | |
52 | WHERE uid = {?}", $uid); | |
425f432d | 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 { | |
0c1e3a66 FB |
58 | XDB::execute("UPDATE accounts |
59 | SET password = NULL, weak_password = NULL, token = NULL | |
60 | WHERE uid = {?}", $uid); | |
0337d704 | 61 | } |
62 | ||
08cce2ff | 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); | |
65 | ||
0c1e3a66 | 66 | /* TODO: handle both account and profile |
425f432d | 67 | foreach ($tables_to_clear as $key=>&$tables) { |
68 | foreach ($tables as $table) { | |
69 | XDB::execute("DELETE FROM $table WHERE $key={?}", $uid); | |
70 | } | |
0c1e3a66 | 71 | }*/ |
9bb8bf21 | 72 | |
0c1e3a66 | 73 | $mmlist = new MMList($user); |
9bb8bf21 | 74 | $mmlist->kill($alias, $really_del); |
84270653 VZ |
75 | |
76 | // Deactivates, when available, the Google Apps account of the user. | |
77 | if ($globals->mailstorage->googleapps_domain) { | |
78 | require_once 'googleapps.inc.php'; | |
14870e88 | 79 | if (GoogleAppsAccount::account_status($uid)) { |
d56cb887 | 80 | $account = new GoogleAppsAccount($user); |
14870e88 VZ |
81 | $account->suspend(); |
82 | } | |
84270653 | 83 | } |
0337d704 | 84 | } |
85 | ||
86 | // }}} | |
0337d704 | 87 | // {{{ function _user_reindex |
88 | ||
6443c93d | 89 | function _user_reindex($uid, $keys) |
94f6c381 | 90 | { |
0337d704 | 91 | foreach ($keys as $i => $key) { |
6443c93d | 92 | if ($key['name'] == '') { |
0337d704 | 93 | continue; |
94 | } | |
6443c93d | 95 | $toks = preg_split('/[ \'\-]+/', $key['name']); |
0337d704 | 96 | $token = ""; |
97 | $first = 5; | |
98 | while ($toks) { | |
99 | $token = strtolower(replace_accent(array_pop($toks) . $token)); | |
6443c93d | 100 | $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10); |
c0c9f772 | 101 | XDB::execute("REPLACE INTO search_name (token, uid, soundex, score, flags) |
102 | VALUES ({?}, {?}, {?}, {?}, {?})", | |
6443c93d | 103 | $token, $uid, soundex_fr($token), $score, $key['public']); |
0337d704 | 104 | $first = 0; |
105 | } | |
106 | } | |
107 | } | |
108 | ||
109 | // }}} | |
110 | // {{{ function user_reindex | |
111 | ||
112 | function user_reindex($uid) { | |
6443c93d SJ |
113 | XDB::execute("DELETE FROM search_name |
114 | WHERE uid = {?}", | |
115 | $uid); | |
116 | $res = XDB::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score, | |
117 | FIND_IN_SET('public', e.flags) AS public | |
118 | FROM profile_name AS n | |
119 | INNER JOIN profile_name_enum AS e ON (n.typeid = e.id) | |
120 | WHERE n.pid = {?}", | |
121 | $uid); | |
122 | _user_reindex($uid, $res); | |
0337d704 | 123 | } |
124 | ||
125 | // }}} | |
433336f3 | 126 | // {{{ function get_X_mat |
127 | function get_X_mat($ourmat) | |
128 | { | |
787bb3d7 | 129 | if (!preg_match('/^[0-9]{8}$/', $ourmat)) { |
433336f3 | 130 | // le matricule de notre base doit comporter 8 chiffres |
131 | return 0; | |
787bb3d7 FB |
132 | } |
133 | ||
433336f3 | 134 | $year = intval(substr($ourmat, 0, 4)); |
135 | $rang = intval(substr($ourmat, 5, 3)); | |
136 | if ($year < 1996) { | |
787bb3d7 | 137 | return; |
433336f3 | 138 | } elseif ($year < 2000) { |
139 | $year = intval(substr(1900 - $year, 1, 3)); | |
140 | return sprintf('%02u0%03u', $year, $rang); | |
141 | } else { | |
142 | $year = intval(substr(1900 - $year, 1, 3)); | |
143 | return sprintf('%03u%03u', $year, $rang); | |
144 | } | |
787bb3d7 FB |
145 | } |
146 | ||
433336f3 | 147 | // }}} |
148 | ||
149 | ||
a7de4ef7 | 150 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 151 | ?> |