Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
acbf53 1 <?php
T 2
3 /*
4 Copyright (c) 2005, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $list_def_file = "list/client.list.php";
36 $tform_def_file = "form/client.tform.php";
37
38 /******************************************
39 * End Form configuration
40 ******************************************/
41
b1a6a5 42 require_once '../../lib/config.inc.php';
MC 43 require_once '../../lib/app.inc.php';
acbf53 44
910093 45 //* Check permissions for module
T 46 $app->auth->check_module_permissions('client');
91624b 47 if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.');
acbf53 48
b5a23a 49 $app->uses('tpl,tform');
T 50 $app->load('tform_actions');
51
52 class page_action extends tform_actions {
b1a6a5 53
07ba80 54     function onDelete() {
b1a6a5 55         global $app, $conf, $list_def_file, $tform_def_file;
MC 56
fb3a98 57         // Loading tform framework
b1a6a5 58         if(!is_object($app->tform)) $app->uses('tform');
MC 59
07ba80 60         if($_POST["confirm"] == 'yes') {
T 61             parent::onDelete();
62         } else {
fb3a98 63
b1a6a5 64             $app->uses('tpl');
MC 65             $app->tpl->newTemplate("form.tpl.htm");
66             $app->tpl->setInclude('content_tpl', 'templates/client_del.htm');
67
68             include_once $list_def_file;
69
70             // Load table definition from file
71             $app->tform->loadFormDef($tform_def_file);
72
73             $this->id = $app->functions->intval($_REQUEST["id"]);
74
75             $this->dataRecord = $app->tform->getDataRecord($this->id);
76             $client_id = $app->functions->intval($this->dataRecord['client_id']);
9d9833 77             $client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client_id);
b1a6a5 78
MC 79             // Get all records (sub-clients, mail, web, etc....)  of this client.
c795df 80             $tables = 'cron,client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_traffic,domain';
b1a6a5 81             $tables_array = explode(',', $tables);
MC 82             $client_group_id = $app->functions->intval($client_group['groupid']);
83
84             $table_list = array();
85             if($client_group_id > 1) {
86                 foreach($tables_array as $table) {
87                     if($table != '') {
cc7a82 88                         $records = $app->db->queryAllRecords("SELECT * FROM ?? WHERE sys_groupid = ?", $table, $client_group_id);
b1a6a5 89                         $number = count($records);
MC 90                         if($number > 0) $table_list[] = array('table' => $table."(".$number.")");
91                     }
07ba80 92                 }
T 93             }
b1a6a5 94
MC 95             $app->tpl->setVar('id', $this->id);
96             $app->tpl->setVar('number_records', $number);
97             $app->tpl->setLoop('records', $table_list);
98
99             //* load language file
100             $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_client_del.lng';
101             include $lng_file;
102             $app->tpl->setVar($wb);
103
104             $app->tpl_defaults();
105             $app->tpl->pparse();
07ba80 106         }
T 107     }
b1a6a5 108
MC 109
110
111
72695f 112     function onBeforeDelete() {
b5a23a 113         global $app, $conf;
b1a6a5 114
65ea2e 115         $client_id = $app->functions->intval($this->dataRecord['client_id']);
b1a6a5 116
MC 117         if($client_id > 0) {
b5a23a 118             // remove the group of the client from the resellers group
65ea2e 119             $parent_client_id = $app->functions->intval($this->dataRecord['parent_client_id']);
cc7a82 120             $parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = ?", $parent_client_id);
MC 121             $client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client_id);
b1a6a5 122             $app->auth->remove_group_from_user($parent_user['userid'], $client_group['groupid']);
MC 123
b5a23a 124             // delete the group of the client
cc7a82 125             $app->db->query("DELETE FROM sys_group WHERE client_id = ?", $client_id);
b1a6a5 126
b5a23a 127             // delete the sys user(s) of the client
cc7a82 128             $app->db->query("DELETE FROM sys_user WHERE client_id = ?", $client_id);
b1a6a5 129
07ba80 130             // Delete all records (sub-clients, mail, web, etc....)  of this client.
5882e8 131             $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_folder,web_folder_user,domain,mail_mailinglist';
b1a6a5 132             $tables_array = explode(',', $tables);
65ea2e 133             $client_group_id = $app->functions->intval($client_group['groupid']);
07ba80 134             if($client_group_id > 1) {
T 135                 foreach($tables_array as $table) {
136                     if($table != '') {
cc7a82 137                         $records = $app->db->queryAllRecords("SELECT * FROM ?? WHERE sys_groupid = ?", $table, $client_group_id);
bfcdef 138                         //* find the primary ID of the table
07ba80 139                         $table_info = $app->db->tableInfo($table);
T 140                         $index_field = '';
141                         foreach($table_info as $tmp) {
142                             if($tmp['option'] == 'primary') $index_field = $tmp['name'];
143                         }
bfcdef 144                         //* Delete the records
07ba80 145                         if($index_field != '') {
T 146                             if(is_array($records)) {
147                                 foreach($records as $rec) {
148                                     $app->db->datalogDelete($table, $index_field, $rec[$index_field]);
dc2dca 149                                     //* Delete traffic records that dont have a sys_groupid column
T 150                                     if($table == 'web_domain') {
cc7a82 151                                         $app->db->query("DELETE FROM web_traffic WHERE hostname = ?", $rec['domain']);
dc2dca 152                                     }
T 153                                     //* Delete mail_traffic records that dont have a sys_groupid
154                                     if($table == 'mail_user') {
cc7a82 155                                         $app->db->query("DELETE FROM mail_traffic WHERE mailuser_id = ?", $rec['mailuser_id']);
dc2dca 156                                     }
07ba80 157                                 }
T 158                             }
159                         }
b1a6a5 160
07ba80 161                     }
T 162                 }
163             }
b1a6a5 164
d22277 165             $activation_letter_filename = ISPC_ROOT_PATH.'/pdf/activation_letters/c'.$client_id.'-'.$this->dataRecord['activation_code'].'.pdf';
MB 166             if(is_file($activation_letter_filename)) unlink($activation_letter_filename);
b5a23a 167         }
b1a6a5 168
b5a23a 169     }
b1a6a5 170
b5a23a 171 }
T 172
173 $page = new page_action;
174 $page->onDelete()
acbf53 175
a59731 176 ?>