From 2ae285290508de108530203fb0e4f68469159283 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Mon, 14 Mar 2011 11:14:35 -0400
Subject: [PATCH] Fixed: FS#1127 - Reseller 'Traffic Quota' limits are not checked in client assignment.

---
 interface/web/sites/web_domain_edit.php |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index 28e233d..4ed306d 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -278,7 +278,7 @@
 			$client_group_id = $_SESSION["s"]["user"]["default_group"];
 			$client = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, parent_client_id, limit_web_quota FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
 
-			//* Check the website quota
+			//* Check the website quota of the client
 			if(isset($_POST["hd_quota"]) && $client["limit_web_quota"] >= 0) {
 				$tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
 				$webquota = $tmp["webquota"];
@@ -294,7 +294,7 @@
 				unset($tmp_quota);
 			}
 
-			//* Check the traffic quota
+			//* Check the traffic quota of the client
 			if(isset($_POST["traffic_quota"]) && $client["limit_traffic_quota"] > 0) {
 				$tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
 				$trafficquota = $tmp["trafficquota"];
@@ -309,6 +309,43 @@
 				unset($tmp);
 				unset($tmp_quota);
 			}
+			
+			if($client['parent_client_id'] > 0) {
+				// Get the limits of the reseller
+				$reseller = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, limit_web_quota FROM client WHERE client_id = ".$client['parent_client_id']);
+
+				//* Check the website quota of the client
+				if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0) {
+					$tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
+					$webquota = $tmp["webquota"];
+					$new_web_quota = intval($this->dataRecord["hd_quota"]);
+					if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) {
+						$max_free_quota = floor($reseller["limit_web_quota"] - $webquota);
+						if($max_free_quota < 0) $max_free_quota = 0;
+						$app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
+						// Set the quota field to the max free space
+						$this->dataRecord["hd_quota"] = $max_free_quota;
+					}
+					unset($tmp);
+					unset($tmp_quota);
+				}
+
+				//* Check the traffic quota of the client
+				if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0) {
+					$tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
+					$trafficquota = $tmp["trafficquota"];
+					$new_traffic_quota = intval($this->dataRecord["traffic_quota"]);
+					if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) {
+						$max_free_quota = floor($reseller["limit_traffic_quota"] - $trafficquota);
+						if($max_free_quota < 0) $max_free_quota = 0;
+						$app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
+						// Set the quota field to the max free space
+						$this->dataRecord["traffic_quota"] = $max_free_quota;
+					}
+					unset($tmp);
+					unset($tmp_quota);
+				}
+			}
 
 			// When the record is updated
 			if($this->id > 0) {

--
Gitblit v1.9.1