From f28f40f7a62b9a6fe939c05b10366b0d66c9ec1e Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Fri, 27 Feb 2009 12:50:34 -0500
Subject: [PATCH] Fixed amavisd socket path.

---
 interface/web/client/tools.inc.php |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/interface/web/client/tools.inc.php b/interface/web/client/tools.inc.php
index d98392f..4f757cc 100644
--- a/interface/web/client/tools.inc.php
+++ b/interface/web/client/tools.inc.php
@@ -28,13 +28,14 @@
 */
 
 function applyClientTemplates($clientId){
-	global $app;
+	global $app,$page;
 	/*
 	 * Get the master-template for the client
 	 */
-	$sql = "SELECT template_master FROM client WHERE client_id = " . intval($clientId);
+	$sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId);
 	$record = $app->db->queryOneRecord($sql);
 	$masterTemplateId = $record['template_master'];
+	$additionalTemplateStr = $record['template_additional'];
 
 	/*
 	 * if the master-Template is custom there is NO changing
@@ -42,20 +43,41 @@
 	if ($masterTemplateId > 0){
 		$sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId);
 		$limits = $app->db->queryOneRecord($sql);
+	} else {
+		$limits = $page->dataRecord;
 	}
 
 	/*
-	 * TODO: Process the additional tempaltes here (add them to the limits
+	 * Process the additional tempaltes here (add them to the limits
 	 * if != -1)
-	 * (like $limits['limit_database'] += $limitAdditional)
 	 */
+	$addTpl = explode('/', $additionalTemplateStr);
+	foreach ($addTpl as $item){
+		if (trim($item) != ''){
+			$sql = "SELECT * FROM client_template WHERE template_id = " . intval($item);
+			$addLimits = $app->db->queryOneRecord($sql);
+			/* maybe the template is deleted in the meantime */
+			if (is_array($addLimits)){
+				foreach($addLimits as $k => $v){
+					if ($limits[$k] > -1){
+						if ($v == -1) {
+							$limits[$k] = -1;
+						}
+						else {
+							$limits[$k] += $v;
+						}
+					}
+				}
+			}
+		}
+	}
 
 	/*
 	 * Write all back to the database
 	 */
 	$update = '';
 	foreach($limits as $k => $v){
-		if (strpos($k, 'limit') !== false){
+		if (strpos($k, 'limit') !== false && !is_array($v)){
 			if ($update != '') $update .= ', ';
 			$update .= '`' . $k . "`='" . $v . "'";
 		}

--
Gitblit v1.9.1