From 23229cb35203ab59a8d9771cc7a22f56215be01e Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Fri, 10 Jan 2014 08:12:33 -0500
Subject: [PATCH] Fixed client / reseller number increment function.

---
 interface/web/client/client_edit.php |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php
index b3c0ac5..402b0db 100644
--- a/interface/web/client/client_edit.php
+++ b/interface/web/client/client_edit.php
@@ -189,9 +189,11 @@
 					$app->tpl->setVar('customer_no',$customer_no_string);
 				
 					//* save new counter value
+					/*
 					$system_config['misc']['customer_no_counter']++;
 					$system_config_str = $app->ini_parser->get_ini_string($system_config);
 					$app->db->datalogUpdate('sys_ini', "config = '".$app->db->quote($system_config_str)."'", 'sysini_id', 1);
+					*/
 				}
 			} else {
 				//* Logged in user must be a reseller
@@ -206,8 +208,10 @@
 					$app->tpl->setVar('customer_no',$customer_no_string);
 					
 					//* save new counter value
+					/*
 					$customer_no_counter = $app->functions->intval($reseller['customer_no_counter']+1);
 					$app->db->query("UPDATE client SET customer_no_counter = $customer_no_counter WHERE client_id = ".$app->functions->intval($reseller['client_id']));
+					*/
 				}
 			}
 		}
@@ -272,6 +276,33 @@
 			$app->uses('client_templates');
 			$app->client_templates->update_client_templates($this->id, $this->_template_additional);
 		}
+		
+		if($this->dataRecord['customer_no'] == $this->dataRecord['customer_no_org']) {
+			if($app->auth->is_admin()) {
+				//* Logged in User is admin
+				//* get the system config
+				$app->uses('getconf');
+				$system_config = $app->getconf->get_global_config();
+				if($system_config['misc']['customer_no_template'] != '') {
+				
+					//* save new counter value
+					$system_config['misc']['customer_no_counter']++;
+					$system_config_str = $app->ini_parser->get_ini_string($system_config);
+					$app->db->datalogUpdate('sys_ini', "config = '".$app->db->quote($system_config_str)."'", 'sysini_id', 1);
+				}
+			} else {
+				//* Logged in user must be a reseller
+				//* get the record of the reseller
+				$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
+				$reseller = $app->db->queryOneRecord("SELECT client.client_id, client.customer_no_template, client.customer_no_counter, client.customer_no_start FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = ".$client_group_id);
+				
+				if($reseller['customer_no_template'] != '') {
+					//* save new counter value
+					$customer_no_counter = $app->functions->intval($reseller['customer_no_counter']+1);
+					$app->db->query("UPDATE client SET customer_no_counter = $customer_no_counter WHERE client_id = ".$app->functions->intval($reseller['client_id']));
+				}
+			}
+		}
 
 		parent::onAfterInsert();
 	}

--
Gitblit v1.9.1