@@ -255,38 +255,6 @@ function onSubmit() {
255255 parent ::onSubmit ();
256256 }
257257
258- function onAfterInsert () {
259- global $ app , $ conf ;
260-
261- // make sure that the record belongs to the client group and not the admin group when a dmin inserts it
262- // also make sure that the user can not delete domain created by a admin
263- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' && isset ($ this ->dataRecord ["client_group_id " ])) {
264- $ client_group_id = $ app ->functions ->intval ($ this ->dataRecord ["client_group_id " ]);
265- $ app ->db ->query ("UPDATE mail_domain SET sys_groupid = $ client_group_id, sys_perm_group = 'ru' WHERE domain_id = " .$ this ->id );
266- }
267- if ($ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ]) && isset ($ this ->dataRecord ["client_group_id " ])) {
268- $ client_group_id = $ app ->functions ->intval ($ this ->dataRecord ["client_group_id " ]);
269- $ app ->db ->query ("UPDATE mail_domain SET sys_groupid = $ client_group_id, sys_perm_group = 'riud' WHERE domain_id = " .$ this ->id );
270- }
271-
272- // Spamfilter policy
273- $ policy_id = $ app ->functions ->intval ($ this ->dataRecord ["policy " ]);
274- if ($ policy_id > 0 ) {
275- $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = '@ " .$ app ->db ->quote ($ this ->dataRecord ["domain " ])."' " );
276- if ($ tmp_user ["id " ] > 0 ) {
277- // There is already a record that we will update
278- $ app ->db ->datalogUpdate ('spamfilter_users ' , "policy_id = $ ploicy_id " , 'id ' , $ tmp_user ["id " ]);
279- } else {
280- $ tmp_domain = $ app ->db ->queryOneRecord ("SELECT sys_groupid FROM mail_domain WHERE domain_id = " .$ this ->id );
281- // We create a new record
282- $ insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`)
283- VALUES ( " .$ _SESSION ["s " ]["user " ]["userid " ].", " .$ app ->functions ->intval ($ tmp_domain ["sys_groupid " ]).", 'riud', 'riud', '', " .$ app ->functions ->intval ($ this ->dataRecord ["server_id " ]).", 5, " .$ app ->functions ->intval ($ policy_id ).", '@ " .$ app ->db ->quote ($ this ->dataRecord ["domain " ])."', '@ " .$ app ->db ->quote ($ this ->dataRecord ["domain " ])."', 'Y') " ;
284- $ app ->db ->datalogInsert ('spamfilter_users ' , $ insert_data , 'id ' );
285- unset($ tmp_domain );
286- }
287- } // endif spamfilter policy
288- }
289-
290258 function onBeforeUpdate () {
291259 global $ app , $ conf ;
292260
@@ -313,97 +281,6 @@ function onBeforeUpdate() {
313281 }
314282 }
315283
316-
317-
318- function onAfterUpdate () {
319- global $ app , $ conf ;
320-
321- // make sure that the record belongs to the client group and not the admin group when admin inserts it
322- // also make sure that the user can not delete domain created by a admin
323- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' && isset ($ this ->dataRecord ["client_group_id " ])) {
324- $ client_group_id = $ app ->functions ->intval ($ this ->dataRecord ["client_group_id " ]);
325- $ tmp = $ app ->db ->queryOneRecord ("SELECT userid FROM sys_user WHERE default_group = $ client_group_id " );
326- $ client_user_id = ($ tmp ['userid ' ] > 0 )?$ tmp ['userid ' ]:1 ;
327- $ app ->db ->query ("UPDATE mail_domain SET sys_userid = $ client_user_id, sys_groupid = $ client_group_id, sys_perm_group = 'ru' WHERE domain_id = " .$ this ->id );
328- }
329- if ($ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ]) && isset ($ this ->dataRecord ["client_group_id " ])) {
330- $ client_group_id = $ app ->functions ->intval ($ this ->dataRecord ["client_group_id " ]);
331- $ tmp = $ app ->db ->queryOneRecord ("SELECT userid FROM sys_user WHERE default_group = $ client_group_id " );
332- $ client_user_id = ($ tmp ['userid ' ] > 0 )?$ tmp ['userid ' ]:1 ;
333- $ app ->db ->query ("UPDATE mail_domain SET sys_userid = $ client_user_id, sys_groupid = $ client_group_id, sys_perm_group = 'riud' WHERE domain_id = " .$ this ->id );
334- }
335-
336- // Spamfilter policy
337- $ policy_id = $ app ->functions ->intval ($ this ->dataRecord ["policy " ]);
338- $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = '@ " .$ app ->db ->quote ($ this ->dataRecord ["domain " ])."' " );
339- if ($ policy_id > 0 ) {
340- if ($ tmp_user ["id " ] > 0 ) {
341- // There is already a record that we will update
342- $ app ->db ->datalogUpdate ('spamfilter_users ' , "policy_id = $ policy_id " , 'id ' , $ tmp_user ["id " ]);
343- } else {
344- $ tmp_domain = $ app ->db ->queryOneRecord ("SELECT sys_groupid FROM mail_domain WHERE domain_id = " .$ this ->id );
345- // We create a new record
346- $ insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`)
347- VALUES ( " .$ _SESSION ["s " ]["user " ]["userid " ].", " .$ tmp_domain ["sys_groupid " ].", 'riud', 'riud', '', " .$ app ->functions ->intval ($ this ->dataRecord ["server_id " ]).", 5, " .$ app ->functions ->intval ($ policy_id ).", '@ " .$ app ->db ->quote ($ this ->dataRecord ["domain " ])."', '@ " .$ app ->db ->quote ($ this ->dataRecord ["domain " ])."', 'Y') " ;
348- $ app ->db ->datalogInsert ('spamfilter_users ' , $ insert_data , 'id ' );
349- unset($ tmp_domain );
350- }
351- } else {
352- if ($ tmp_user ["id " ] > 0 ) {
353- // There is already a record but the user shall have no policy, so we delete it
354- $ app ->db ->datalogDelete ('spamfilter_users ' , 'id ' , $ tmp_user ["id " ]);
355- }
356- } // endif spamfilter policy
357- //** If the domain name or owner has been changed, change the domain and owner in all mailbox records
358- if ($ this ->oldDataRecord ['domain ' ] != $ this ->dataRecord ['domain ' ] || (isset ($ this ->dataRecord ['client_group_id ' ]) && $ this ->oldDataRecord ['sys_groupid ' ] != $ this ->dataRecord ['client_group_id ' ])) {
359- $ app ->uses ('getconf ' );
360- $ mail_config = $ app ->getconf ->get_server_config ($ this ->dataRecord ["server_id " ], 'mail ' );
361-
362- //* Update the mailboxes
363- $ mailusers = $ app ->db ->queryAllRecords ("SELECT * FROM mail_user WHERE email like '%@ " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
364- $ sys_groupid = $ app ->functions ->intval ((isset ($ this ->dataRecord ['client_group_id ' ]))?$ this ->dataRecord ['client_group_id ' ]:$ this ->oldDataRecord ['sys_groupid ' ]);
365- $ tmp = $ app ->db ->queryOneRecord ("SELECT userid FROM sys_user WHERE default_group = $ client_group_id " );
366- $ client_user_id = $ app ->functions ->intval (($ tmp ['userid ' ] > 0 )?$ tmp ['userid ' ]:1 );
367- if (is_array ($ mailusers )) {
368- foreach ($ mailusers as $ rec ) {
369- // setting Maildir, Homedir, UID and GID
370- $ mail_parts = explode ("@ " , $ rec ['email ' ]);
371- $ maildir = str_replace ("[domain] " , $ this ->dataRecord ['domain ' ], $ mail_config ["maildir_path " ]);
372- $ maildir = str_replace ("[localpart] " , $ mail_parts [0 ], $ maildir );
373- $ maildir = $ app ->db ->quote ($ maildir );
374- $ email = $ app ->db ->quote ($ mail_parts [0 ].'@ ' .$ this ->dataRecord ['domain ' ]);
375- $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir', email = ' $ email', sys_userid = $ client_user_id, sys_groupid = ' $ sys_groupid' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
376- }
377- }
378-
379- //* Update the aliases
380- $ forwardings = $ app ->db ->queryAllRecords ("SELECT * FROM mail_forwarding WHERE source like '%@ " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' OR destination like '%@ " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
381- if (is_array ($ forwardings )) {
382- foreach ($ forwardings as $ rec ) {
383- $ destination = $ app ->db ->quote (str_replace ($ this ->oldDataRecord ['domain ' ], $ this ->dataRecord ['domain ' ], $ rec ['destination ' ]));
384- $ source = $ app ->db ->quote (str_replace ($ this ->oldDataRecord ['domain ' ], $ this ->dataRecord ['domain ' ], $ rec ['source ' ]));
385- $ app ->db ->datalogUpdate ('mail_forwarding ' , "source = ' $ source', destination = ' $ destination', sys_userid = $ client_user_id, sys_groupid = ' $ sys_groupid' " , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
386- }
387- }
388-
389- //* Update the mailinglist
390- $ app ->db ->query ("UPDATE mail_mailinglist SET sys_userid = $ client_user_id, sys_groupid = $ sys_groupid WHERE domain = ' " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
391-
392- //* Update the mailget records
393- $ app ->db ->query ("UPDATE mail_get SET destination=REPLACE(destination, ' " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."', ' " .$ app ->db ->quote ($ this ->dataRecord ['domain ' ])."'), sys_userid = $ client_user_id, sys_groupid = $ sys_groupid WHERE destination LIKE '%@ " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
394-
395- if ($ this ->oldDataRecord ["domain " ] != $ this ->dataRecord ['domain ' ]) {
396- //* Delete the old spamfilter record
397- $ tmp = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = '@ " .$ app ->db ->quote ($ this ->oldDataRecord ["domain " ])."' " );
398- $ app ->db ->datalogDelete ('spamfilter_users ' , 'id ' , $ tmp ["id " ]);
399- unset($ tmp );
400- }
401- $ app ->db ->query ("UPDATE spamfilter_users SET email=REPLACE(email, ' " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."', ' " .$ app ->db ->quote ($ this ->dataRecord ['domain ' ])."'), sys_userid = $ client_user_id, sys_groupid = $ sys_groupid WHERE email LIKE '%@ " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
402-
403- } // end if domain name changed
404-
405- }
406-
407284}
408285
409286$ page = new page_action ;
0 commit comments