Skip to content

Commit 07ba800

Browse files
committed
Fixed: FS#1012 - Delete all records (domains, ftp users, etc.) of a client when the client gets deleted.
1 parent 6e2a8db commit 07ba800

File tree

4 files changed

+128
-11
lines changed

4 files changed

+128
-11
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,15 @@ public function getTables($database_name = '')
482482

483483

484484
public function tableInfo($table_name) {
485-
global $go_api,$go_info;
486485
//* Tabellenfelder einlesen ?
487-
if($rows = $go_api->db->queryAllRecords("SHOW FIELDS FROM $table_name")){
486+
if($rows = $this->queryAllRecords("SHOW FIELDS FROM $table_name")){
488487
foreach($rows as $row) {
489-
$name = $row[0];
490-
$default = $row[4];
491-
$key = $row[3];
492-
$extra = $row[5];
493-
$isnull = $row[2];
494-
$type = $row[1];
488+
$name = $row['Field'];
489+
$default = $row['Default'];
490+
$key = $row['Key'];
491+
$extra = $row['Extra'];
492+
$isnull = $row['Null'];
493+
$type = $row['Type'];
495494

496495
$column = array('name' => $name, 'defaultValue' => $default);
497496
//$column["type"] = $type;

interface/web/client/client_del.php

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,71 @@
4949
$app->load('tform_actions');
5050

5151
class page_action extends tform_actions {
52+
53+
function onDelete() {
54+
global $app, $conf,$list_def_file,$tform_def_file;
55+
56+
if($_POST["confirm"] == 'yes') {
57+
parent::onDelete();
58+
} else {
59+
60+
$app->uses('tpl');
61+
$app->tpl->newTemplate("form.tpl.htm");
62+
$app->tpl->setInclude('content_tpl', 'templates/client_del.htm');
63+
64+
include_once($list_def_file);
65+
66+
// Loading tform framework
67+
if(!is_object($app->tform)) $app->uses('tform');
68+
69+
// Load table definition from file
70+
$app->tform->loadFormDef($tform_def_file);
71+
72+
$this->id = intval($_REQUEST["id"]);
73+
74+
$this->dataRecord = $app->tform->getDataRecord($this->id);
75+
$client_id = intval($this->dataRecord['client_id']);
76+
//$parent_client_id = intval($this->dataRecord['parent_client_id']);
77+
//$parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = $parent_client_id");
78+
$client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
79+
80+
// Get all records (sub-clients, mail, web, etc....) of this client.
81+
$tables = 'client,dns_rr,dns_soa,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_domain,web_traffic';
82+
$tables_array = explode(',',$tables);
83+
$client_group_id = intval($client_group['groupid']);
84+
$table_list = array();
85+
if($client_group_id > 1) {
86+
foreach($tables_array as $table) {
87+
if($table != '') {
88+
$records = $app->db->queryAllRecords("SELECT * FROM $table WHERE sys_groupid = ".$client_group_id);
89+
$number = count($records);
90+
if($number > 0) $table_list[] = array('table' => $table."(".$number.")");
91+
}
92+
}
93+
}
94+
95+
$app->tpl->setVar('id',$this->id);
96+
$app->tpl->setLoop('records', $table_list);
97+
98+
//* load language file
99+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_client_del.lng';
100+
include($lng_file);
101+
$app->tpl->setVar($wb);
102+
103+
$app->tpl_defaults();
104+
$app->tpl->pparse();
105+
}
106+
}
107+
108+
109+
110+
52111
function onAfterDelete() {
53112
global $app, $conf;
54113

55114
$client_id = intval($this->dataRecord['client_id']);
56115

57-
if($client_id > 0) {
58-
// TODO: Delete all records (sub-clients, mail, web, etc....) of this client.
59-
116+
if($client_id > 0) {
60117
// remove the group of the client from the resellers group
61118
$parent_client_id = intval($this->dataRecord['parent_client_id']);
62119
$parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = $parent_client_id");
@@ -68,6 +125,36 @@ function onAfterDelete() {
68125

69126
// delete the sys user(s) of the client
70127
$app->db->query("DELETE FROM sys_user WHERE client_id = $client_id");
128+
129+
// Delete all records (sub-clients, mail, web, etc....) of this client.
130+
$tables = 'client,dns_rr,dns_soa,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_domain,web_traffic';
131+
$tables_array = explode(',',$tables);
132+
$client_group_id = intval($client_group['groupid']);
133+
if($client_group_id > 1) {
134+
foreach($tables_array as $table) {
135+
if($table != '') {
136+
$records = $app->db->queryAllRecords("SELECT * FROM $table WHERE sys_groupid = ".$client_group_id);
137+
// find the primary ID of the table
138+
$table_info = $app->db->tableInfo($table);
139+
$index_field = '';
140+
foreach($table_info as $tmp) {
141+
if($tmp['option'] == 'primary') $index_field = $tmp['name'];
142+
}
143+
// Delete the records
144+
if($index_field != '') {
145+
if(is_array($records)) {
146+
foreach($records as $rec) {
147+
$app->db->datalogDelete($table, $index_field, $rec[$index_field]);
148+
}
149+
}
150+
}
151+
152+
}
153+
}
154+
}
155+
156+
157+
71158
}
72159

73160
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$wb["confirm_action_txt"] = 'Confirm action';
3+
$wb["delete_explanation"] = 'This action will delete the following number of records associated with this client';
4+
$wb["btn_save_txt"] = 'Delete the client';
5+
$wb["btn_cancel_txt"] = 'Cancel without deleting the client';
6+
?>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<h2><tmpl_var name="list_head_txt"></h2>
2+
<p><tmpl_var name="list_desc_txt"></p>
3+
4+
<div class="panel panel_client_del">
5+
6+
<div class="pnl_formsarea">
7+
8+
<div id="OKMsg">
9+
<tmpl_var name="delete_explanation">:<br /><br />
10+
<tmpl_loop name="records">
11+
<tmpl_var name="table">,
12+
</tmpl_loop>
13+
</div>
14+
15+
<input type="checkbox" name="confirm" value="yes" /> <b><tmpl_var name="confirm_action_txt"></b>
16+
17+
<input type="hidden" name="id" value="{tmpl_var name='id'}">
18+
19+
<div class="buttonHolder buttons">
20+
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','client/client_del.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
21+
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('client/client_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
22+
</div>
23+
</div>
24+
25+
</div>

0 commit comments

Comments
 (0)