4949$ app ->load ('tform_actions ' );
5050
5151class 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 }
0 commit comments