From 4569cae57f127afd093794310ccd290d2d9fdf36 Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Wed, 20 Apr 2016 10:58:46 -0400
Subject: [PATCH] Merge branch 'stable-3.1'

---
 interface/lib/classes/client_templates.inc.php |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/interface/lib/classes/client_templates.inc.php b/interface/lib/classes/client_templates.inc.php
index e3141d7..d88628b 100644
--- a/interface/lib/classes/client_templates.inc.php
+++ b/interface/lib/classes/client_templates.inc.php
@@ -101,8 +101,6 @@
 	function apply_client_templates($clientId) {
 		global $app;
 
-		include '../client/form/client.tform.php';
-
 		/*
          * Get the master-template for the client
          */
@@ -110,6 +108,8 @@
 		$record = $app->db->queryOneRecord($sql, $clientId);
 		$masterTemplateId = $record['template_master'];
 		$is_reseller = ($record['limit_client'] != 0)?true:false;
+
+		include '../client/form/' . ($is_reseller ? 'reseller' : 'client') . '.tform.php';
 
 		if($record['template_additional'] != '') {
 			// we have to call the update_client_templates function
@@ -124,6 +124,8 @@
 		if ($masterTemplateId > 0){
 			$sql = "SELECT * FROM client_template WHERE template_id = ?";
 			$limits = $app->db->queryOneRecord($sql, $masterTemplateId);
+			if($is_reseller == true && $limits['limit_client'] == 0) $limits['limit_client'] = -1;
+			elseif($is_reseller == false && $limits['limit_client'] != 0) $limits['limit_client'] = 0;
 		} else {
 			// if there is no master template it makes NO SENSE adding sub templates.
 			// adding subtemplates are stored in client limits, so they would add up
@@ -132,7 +134,7 @@
 		}
 
 		/*
-         * Process the additional tempaltes here (add them to the limits
+         * Process the additional templates here (add them to the limits
          * if != -1)
          */
 		$addTpl = explode('/', $additionalTemplateStr);
@@ -145,6 +147,11 @@
 			/* maybe the template is deleted in the meantime */
 			if (is_array($addLimits)){
 				foreach($addLimits as $k => $v){
+					if($k == 'limit_client') {
+						if($is_reseller == true && $v == 0) continue;
+						elseif($is_reseller == false && $v != 0) continue;
+					}
+					
 					/* we can remove this condition, but it is easier to debug with it (don't add ids and other non-limit values) */
 					if (strpos($k, 'limit') !== false or strpos($k, 'default') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec'){
 						$app->log('Template processing key ' . $k . ' for client ' . $clientId, LOGLEVEL_DEBUG);

--
Gitblit v1.9.1