@@ -284,15 +284,19 @@ function onBeforeUpdate() {
284284 function onAfterUpdate () {
285285 global $ app , $ conf ;
286286
287- // make sure that the record belongs to the clinet group and not the admin group when admin inserts it
287+ // make sure that the record belongs to the client group and not the admin group when admin inserts it
288288 // also make sure that the user can not delete domain created by a admin
289289 if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' && isset ($ this ->dataRecord ["client_group_id " ])) {
290290 $ client_group_id = intval ($ this ->dataRecord ["client_group_id " ]);
291- $ app ->db ->query ("UPDATE mail_domain SET sys_groupid = $ client_group_id, sys_perm_group = 'ru' WHERE domain_id = " .$ this ->id );
291+ $ tmp = $ app ->db ->queryOneRecord ("SELECT userid FROM sys_user WHERE default_group = $ client_group_id " );
292+ $ client_user_id = ($ tmp ['userid ' ] > 0 )?$ tmp ['userid ' ]:1 ;
293+ $ 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 );
292294 }
293295 if ($ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ]) && isset ($ this ->dataRecord ["client_group_id " ])) {
294296 $ client_group_id = intval ($ this ->dataRecord ["client_group_id " ]);
295- $ app ->db ->query ("UPDATE mail_domain SET sys_groupid = $ client_group_id, sys_perm_group = 'riud' WHERE domain_id = " .$ this ->id );
297+ $ tmp = $ app ->db ->queryOneRecord ("SELECT userid FROM sys_user WHERE default_group = $ client_group_id " );
298+ $ client_user_id = ($ tmp ['userid ' ] > 0 )?$ tmp ['userid ' ]:1 ;
299+ $ 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 );
296300 }
297301
298302 // Spamfilter policy
@@ -324,6 +328,8 @@ function onAfterUpdate() {
324328 //* Update the mailboxes
325329 $ mailusers = $ app ->db ->queryAllRecords ("SELECT * FROM mail_user WHERE email like '%@ " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
326330 $ sys_groupid = (isset ($ this ->dataRecord ['client_group_id ' ]))?$ this ->dataRecord ['client_group_id ' ]:$ this ->oldDataRecord ['sys_groupid ' ];
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 ;
327333 if (is_array ($ mailusers )) {
328334 foreach ($ mailusers as $ rec ) {
329335 // setting Maildir, Homedir, UID and GID
@@ -332,7 +338,7 @@ function onAfterUpdate() {
332338 $ maildir = str_replace ("[localpart] " ,$ mail_parts [0 ],$ maildir );
333339 $ maildir = $ app ->db ->quote ($ maildir );
334340 $ email = $ app ->db ->quote ($ mail_parts [0 ].'@ ' .$ this ->dataRecord ['domain ' ]);
335- $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir', email = ' $ email', sys_groupid = ' $ sys_groupid' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
341+ $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir', email = ' $ email', sys_userid = $ client_user_id , sys_groupid = '$ sys_groupid' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
336342 }
337343 }
338344
@@ -342,12 +348,12 @@ function onAfterUpdate() {
342348 foreach ($ forwardings as $ rec ) {
343349 $ destination = $ app ->db ->quote (str_replace ($ this ->oldDataRecord ['domain ' ],$ this ->dataRecord ['domain ' ],$ rec ['destination ' ]));
344350 $ source = $ app ->db ->quote (str_replace ($ this ->oldDataRecord ['domain ' ],$ this ->dataRecord ['domain ' ],$ rec ['source ' ]));
345- $ app ->db ->datalogUpdate ('mail_forwarding ' , "source = ' $ source', destination = ' $ destination', sys_groupid = ' $ sys_groupid' " , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
351+ $ app ->db ->datalogUpdate ('mail_forwarding ' , "source = ' $ source', destination = ' $ destination', sys_userid = $ client_user_id , sys_groupid = '$ sys_groupid' " , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
346352 }
347353 }
348354
349355 //* Update the mailinglist
350- $ app ->db ->query ("UPDATE mail_mailinglist SET sys_groupid = $ sys_groupid WHERE domain = ' " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
356+ $ app ->db ->query ("UPDATE mail_mailinglist SET sys_userid = $ client_user_id , sys_groupid = $ sys_groupid WHERE domain = ' " .$ app ->db ->quote ($ this ->oldDataRecord ['domain ' ])."' " );
351357
352358 //* Delete the old spamfilter record
353359 $ tmp = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = '@ " .$ app ->db ->quote ($ this ->oldDataRecord ["domain " ])."' " );
0 commit comments