@@ -60,7 +60,48 @@ function onBeforeDelete() {
6060 $ client_id = $ app ->functions ->intval ($ this ->dataRecord ['client_id ' ]);
6161
6262 $ tmp = $ app ->db ->queryOneRecord ("SELECT count(client_id) as number FROM client WHERE parent_client_id = ? " , $ client_id );
63- if ($ tmp ["number " ] > 0 ) $ app ->error ($ app ->lng ('error_has_clients ' ));
63+ if ($ tmp ["number " ] > 0 ) {
64+ $ app ->error ($ app ->lng ('error_has_clients ' ));
65+ } else {
66+ $ parent_client_id = $ app ->functions ->intval ($ this ->dataRecord ['parent_client_id ' ]);
67+ $ parent_user = $ app ->db ->queryOneRecord ("SELECT userid FROM sys_user WHERE client_id = ? " , $ parent_client_id );
68+ $ client_group = $ app ->db ->queryOneRecord ("SELECT groupid FROM sys_group WHERE client_id = ? " , $ client_id );
69+
70+ // Delete all records (mail, web, etc....) of this reseller.
71+ $ tables = 'cron,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,spamfilter_wblist ' ;
72+ $ tables_array = explode (', ' , $ tables );
73+ $ client_group_id = $ app ->functions ->intval ($ client_group ['groupid ' ]);
74+ if ($ client_group_id > 1 ) {
75+ foreach ($ tables_array as $ table ) {
76+ if ($ table != '' ) {
77+ //* find the primary ID of the table
78+ $ table_info = $ app ->db ->tableInfo ($ table );
79+ $ index_field = '' ;
80+ foreach ($ table_info as $ tmp ) {
81+ if ($ tmp ['option ' ] == 'primary ' ) $ index_field = $ tmp ['name ' ];
82+ }
83+ //* Delete the records
84+ if ($ index_field != '' ) {
85+ $ records = $ app ->db ->queryAllRecords ("SELECT * FROM ?? WHERE sys_groupid = ? ORDER BY ?? DESC " , $ table , $ client_group_id , $ index_field );
86+ if (is_array ($ records )) {
87+ foreach ($ records as $ rec ) {
88+ $ app ->db ->datalogDelete ($ table , $ index_field , $ rec [$ index_field ]);
89+ //* Delete traffic records that dont have a sys_groupid column
90+ if ($ table == 'web_domain ' ) {
91+ $ app ->db ->query ("DELETE FROM web_traffic WHERE hostname = ? " , $ rec ['domain ' ]);
92+ }
93+ //* Delete mail_traffic records that dont have a sys_groupid
94+ if ($ table == 'mail_user ' ) {
95+ $ app ->db ->query ("DELETE FROM mail_traffic WHERE mailuser_id = ? " , $ rec ['mailuser_id ' ]);
96+ }
97+ }
98+ }
99+ }
100+
101+ }
102+ }
103+ }
104+ }
64105
65106 }
66107
0 commit comments