@@ -153,7 +153,7 @@ function onSubmit() {
153153 if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) { // if user is not admin
154154 // Get the limits of the client
155155 $ client_group_id = $ app ->functions ->intval ($ _SESSION ["s " ]["user " ]["default_group " ]);
156- $ client = $ app ->db ->queryOneRecord ("SELECT limit_mailbox, limit_mailquota FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
156+ $ client = $ app ->db ->queryOneRecord ("SELECT limit_mailbox, limit_mailquota, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $ client_group_id " );
157157
158158
159159 // Check if the user may add another mailbox.
@@ -179,6 +179,28 @@ function onSubmit() {
179179 unset($ tmp );
180180 unset($ tmp_quota );
181181 }
182+
183+ if ($ client ['parent_client_id ' ] > 0 ) {
184+ // Get the limits of the reseller
185+ $ reseller = $ app ->db ->queryOneRecord ("SELECT limit_mailquota, limit_maildomain FROM client WHERE client_id = " .$ client ['parent_client_id ' ]);
186+
187+ //* Check the website quota of the client
188+ if (isset ($ _POST ["quota " ]) && $ reseller ["limit_mailquota " ] >= 0 && $ app ->functions ->intval ($ this ->dataRecord ["quota " ]) * 1024 * 1024 != $ this ->oldDataRecord ['quota ' ]) {
189+ $ tmp = $ app ->db ->queryOneRecord ("SELECT sum(quota) as mailquota FROM mail_user, sys_group, client WHERE mail_user.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND " .$ client ['parent_client_id ' ]." IN (client.parent_client_id, client.client_id) AND mailuser_id != " .$ app ->functions ->intval ($ this ->id ));
190+
191+ $ mailquota = $ tmp ["mailquota " ] / 1024 / 1024 ;
192+ $ new_mailbox_quota = $ app ->functions ->intval ($ this ->dataRecord ["quota " ]);
193+ if (($ mailquota + $ new_mailbox_quota > $ reseller ["limit_mailquota " ]) || ($ new_mailbox_quota == 0 && $ reseller ["limit_mailquota " ] != -1 )) {
194+ $ max_free_quota = $ reseller ["limit_mailquota " ] - $ mailquota ;
195+ if ($ max_free_quota < 0 ) $ max_free_quota = 0 ;
196+ $ app ->tform ->errorMessage .= $ app ->tform ->lng ("limit_mailquota_txt " ).": " .$ max_free_quota ."<br> " ;
197+ // Set the quota field to the max free space
198+ $ this ->dataRecord ["quota " ] = $ max_free_quota ;
199+ }
200+ unset($ tmp );
201+ unset($ tmp_quota );
202+ }
203+ }
182204 } // end if user is not admin
183205
184206
0 commit comments