| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2010 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, tels, profile_education, profile_binets, contacts, groupesx_ins, homonymes, identification_ax, photo |
| 30 | // delete in : profile_skills, emails, entreprises, profile_langskills, 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 | $user = User::getSilent($uid); |
| 37 | list($alias) = explode('@', $user->forlifeEmail()); |
| 38 | |
| 39 | // TODO: clear profile. |
| 40 | $tables_to_clear = array('uid' => array('profile_skills', 'profile_job', 'profile_langskills', 'profile_mentor_country', |
| 41 | 'profile_mentor_sector', 'profile_mentor', 'perte_pass', 'watch_sub'), |
| 42 | 'user_id' => array('requests', 'user_changes')); |
| 43 | |
| 44 | if ($really_del) { |
| 45 | array_push($tables_to_clear['uid'], 'emails', 'group_members', 'contacts', 'adresses', 'profile_phones', |
| 46 | 'photo', 'perte_pass', 'profile_langskills', 'forum_subs', 'forum_profiles'); |
| 47 | array_push($tables_to_clear['user_id'], 'newsletter_ins', 'profile_binets'); |
| 48 | $tables_to_clear['id'] = array('aliases'); |
| 49 | $tables_to_clear['contact'] = array('contacts'); |
| 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); |
| 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 accounts |
| 59 | SET password = NULL, weak_password = NULL, token = NULL |
| 60 | WHERE uid = {?}", $uid); |
| 61 | } |
| 62 | |
| 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 | |
| 66 | /* TODO: handle both account and profile |
| 67 | foreach ($tables_to_clear as $key=>&$tables) { |
| 68 | foreach ($tables as $table) { |
| 69 | XDB::execute("DELETE FROM $table WHERE $key={?}", $uid); |
| 70 | } |
| 71 | }*/ |
| 72 | |
| 73 | $mmlist = new MMList($user); |
| 74 | $mmlist->kill($alias, $really_del); |
| 75 | |
| 76 | // Deactivates, when available, the Google Apps account of the user. |
| 77 | if ($globals->mailstorage->googleapps_domain) { |
| 78 | require_once 'googleapps.inc.php'; |
| 79 | if (GoogleAppsAccount::account_status($uid)) { |
| 80 | $account = new GoogleAppsAccount($user); |
| 81 | $account->suspend(); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // }}} |
| 87 | |
| 88 | |
| 89 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 90 | ?> |