From 81e1f83025cfbdaabdf3a8fbb6126b5a372ac3cc Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Fri, 09 Aug 2013 08:12:05 -0400
Subject: [PATCH] - Implemented:  FS#3077 - Add gender field for client  - Implemented:  FS#1312 - disabling a whole client     -> see bugtracker comments for more details - Fixed:  FS#3060 - Subdomain vhost ip update on web domain update - Implemented:  FS#3078 - Change client template system: delete specific template from limits      -> including link in billing module to link specific assigned templates - Fixed:  FS#3058 - Error in mail quota calculation when changing tab in mailboxe configuration     -> quota limit no longer checked if it was not changed - Fixed: Deleting a client's template could mess up his assigned templates - Added: remoting functions to change client templates the new way

---
 interface/web/client/reseller_edit.php                   |   34 +
 interface/web/client/templates/client_edit_limits.htm    |    6 
 interface/web/client/form/client.tform.php               |   18 +
 interface/web/client/client_template_del.php             |    7 
 interface/web/client/lib/lang/de_reseller.lng            |    5 
 interface/web/mail/mail_user_edit.php                    |    2 
 interface/web/sites/web_domain_edit.php                  |   11 
 interface/web/client/lib/lang/en_reseller.lng            |    5 
 interface/web/client/lib/lang/de_client.lng              |    5 
 interface/web/client/templates/client_edit_address.htm   |   18 +
 interface/web/client/client_template_edit.php            |    2 
 interface/web/client/lib/lang/en_client.lng              |    5 
 interface/lib/classes/client_templates.inc.php           |  206 ++++++++++-----
 interface/web/client/client_edit.php                     |  176 ++++++++++++-
 install/sql/ispconfig3.sql                               |   17 +
 interface/lib/classes/remoting.inc.php                   |   86 ++++++
 interface/web/client/form/reseller.tform.php             |   18 +
 interface/web/client/templates/reseller_edit_address.htm |   18 +
 install/sql/incremental/upd_0056.sql                     |   12 
 interface/web/js/scrigo.js.php                           |   71 +++-
 20 files changed, 597 insertions(+), 125 deletions(-)

diff --git a/install/sql/incremental/upd_0056.sql b/install/sql/incremental/upd_0056.sql
new file mode 100644
index 0000000..c7cb528
--- /dev/null
+++ b/install/sql/incremental/upd_0056.sql
@@ -0,0 +1,12 @@
+CREATE TABLE `client_template_assigned` (
+  `assigned_template_id` bigint(20) NOT NULL auto_increment,
+  `client_id` bigint(11) NOT NULL DEFAULT '0',
+  `client_template_id` int(11) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`assigned_template_id`),
+  KEY `client_id` (`client_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+
+ALTER TABLE `client` ADD `gender` enum('','m','f') NOT NULL DEFAULT '' AFTER `company_id`,
+  ADD `locked` enum('n','y') NOT NULL DEFAULT 'n' AFTER `created_at`,
+  ADD `canceled` enum('n','y') NOT NULL DEFAULT 'n' AFTER `locked`,
+  ADD `tmp_data` mediumblob AFTER `canceled` ;
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 37d0366..8d8b8c0 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -145,6 +145,7 @@
   `sys_perm_other` varchar(5) DEFAULT NULL,
   `company_name` varchar(64) DEFAULT NULL,
   `company_id` varchar(30) DEFAULT NULL,
+  `gender` enum('','m','f') NOT NULL DEFAULT '',
   `contact_name` varchar(64) DEFAULT NULL,
   `customer_no` varchar(64) DEFAULT NULL,
   `vat_id` varchar(64) DEFAULT NULL,
@@ -225,6 +226,9 @@
   `template_master` int(11) unsigned NOT NULL DEFAULT '0',
   `template_additional` text NOT NULL DEFAULT '',
   `created_at` bigint(20) DEFAULT NULL,
+  `locked` enum('n','y') NOT NULL DEFAULT 'n',
+  `canceled` enum('n','y') NOT NULL DEFAULT 'n',
+  `tmp_data` mediumblob,
   `id_rsa` varchar(2000) NOT NULL DEFAULT '',
   `ssh_rsa` varchar(600) NOT NULL DEFAULT '',
   PRIMARY KEY (`client_id`)
@@ -315,6 +319,19 @@
 
 -- --------------------------------------------------------
 
+-- 
+-- Table structure for table  `client_template_assigned`
+-- 
+
+CREATE TABLE `client_template_assigned` (
+  `assigned_template_id` bigint(20) NOT NULL auto_increment,
+  `client_id` bigint(11) NOT NULL DEFAULT '0',
+  `client_template_id` int(11) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`assigned_template_id`),
+  KEY `client_id` (`client_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+-- --------------------------------------------------------
+
 --
 -- Table structure for table `country`
 --
diff --git a/interface/lib/classes/client_templates.inc.php b/interface/lib/classes/client_templates.inc.php
index c2ef0bb..181f741 100644
--- a/interface/lib/classes/client_templates.inc.php
+++ b/interface/lib/classes/client_templates.inc.php
@@ -9,7 +9,62 @@
  
 class client_templates {
 
-	function apply_client_templates($clientId) {
+    /** 
+     *  - check for old-style templates and change to new style
+     *  - update assigned templates
+     */
+	function update_client_templates($clientId, $templates = array()) {
+        global $app, $conf;
+        
+        if(!is_array($templates)) return false;
+        
+        $new_tpl = array();
+        $used_assigned = array();
+        foreach($templates as $item) {
+            $item = trim($item);
+            if($item == '') continue;
+            
+            $tpl_id = 0;
+            $assigned_id = 0;
+            if(strpos($item, ':') === false) {
+                $tpl_id = $item;
+            } else {
+                list($assigned_id, $tpl_id) = explode(':', $item, 2);
+                if(substr($assigned_id, 0, 1) === 'n') $assigned_id = 0; // newly inserted items
+            }
+            
+            if($assigned_id > 0) {
+                $used_assigned[] = $assigned_id; // for comparison with database
+            } else {
+                $new_tpl[] = $tpl_id;
+            }
+        }
+        
+        $in_db = $app->db->queryAllRecords('SELECT `assigned_template_id`, `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ' . $clientId);
+        if(is_array($in_db) && count($in_db) > 0) {
+            // check which templates were removed from this client
+            foreach($in_db as $item) {
+                if(in_array($item['assigned_template_id'], $used_assigned) == false) {
+                    // delete this one
+                    $app->db->query('DELETE FROM `client_template_assigned` WHERE `assigned_template_id` = ' . $item['assigned_template_id']);
+                }
+            }
+        }
+        
+        if(count($new_tpl) > 0) {
+            foreach($new_tpl as $item) {
+                // add new template to client (includes those from old-style without assigned_template_id)
+                $app->db->query('INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (' . $clientId . ', ' . $item . ')');
+            }
+        }
+        unset($new_tpl);
+        unset($in_db);
+        unset($templates);
+        unset($used_assigned);
+        return true;
+    }
+    
+    function apply_client_templates($clientId) {
         global $app;
         
         include('../client/form/client.tform.php');
@@ -20,8 +75,13 @@
         $sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . $app->functions->intval($clientId);
         $record = $app->db->queryOneRecord($sql);
         $masterTemplateId = $record['template_master'];
-        $additionalTemplateStr = $record['template_additional'];
-
+        
+        if($record['template_additional'] != '') {
+            // we have to call the update_client_templates function
+            $templates = explode('/', $record['template_additional']);
+            $this->update_client_templates($clientId, $templates);
+        }
+        
         /*
          * if the master-Template is custom there is NO changing
          */
@@ -40,82 +100,82 @@
          * if != -1)
          */
         $addTpl = explode('/', $additionalTemplateStr);
-        foreach ($addTpl as $item){
-            if (trim($item) != ''){
-                $sql = "SELECT * FROM client_template WHERE template_id = " . $app->functions->intval($item);
-                $addLimits = $app->db->queryOneRecord($sql);
-                $app->log('Template processing subtemplate ' . $item . ' for client ' . $clientId, LOGLEVEL_DEBUG);
-                /* maybe the template is deleted in the meantime */
-                if (is_array($addLimits)){
-                    foreach($addLimits as $k => $v){
-                        /* 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 $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec'){
-                            $app->log('Template processing key ' . $k . ' for client ' . $clientId, LOGLEVEL_DEBUG);
+        $addTpls = $app->db->queryAllRecords('SELECT `client_template_id` FROM `client_template_assigned` WHERE `client_id` = ' . $app->functions->intval($clientId));
+        foreach ($addTpls as $addTpl){
+            $item = $addTpl['client_template_id'];
+            $sql = "SELECT * FROM client_template WHERE template_id = " . $app->functions->intval($item);
+            $addLimits = $app->db->queryOneRecord($sql);
+            $app->log('Template processing subtemplate ' . $item . ' for client ' . $clientId, LOGLEVEL_DEBUG);
+            /* maybe the template is deleted in the meantime */
+            if (is_array($addLimits)){
+                foreach($addLimits as $k => $v){
+                    /* 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 $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec'){
+                        $app->log('Template processing key ' . $k . ' for client ' . $clientId, LOGLEVEL_DEBUG);
 
-                            /* process the numerical limits */
-                            if (is_numeric($v)){
-                                /* switch for special cases */
-                                switch ($k){
-                                case 'limit_cron_frequency':
-                                    if ($v < $limits[$k]) $limits[$k] = $v;
-                                    /* silent adjustment of the minimum cron frequency to 1 minute */
-                                    /* maybe this control test should be done via validator definition in tform.php file, but I don't know how */
-                                    if ($limits[$k] < 1) $limits[$k] = 1;
-                                break;
+                        /* process the numerical limits */
+                        if (is_numeric($v)){
+                            /* switch for special cases */
+                            switch ($k){
+                            case 'limit_cron_frequency':
+                                if ($v < $limits[$k]) $limits[$k] = $v;
+                                /* silent adjustment of the minimum cron frequency to 1 minute */
+                                /* maybe this control test should be done via validator definition in tform.php file, but I don't know how */
+                                if ($limits[$k] < 1) $limits[$k] = 1;
+                            break;
 
-                                default:
-                                    if ($limits[$k] > -1){
-                                        if ($v == -1){
-                                            $limits[$k] = -1;
-                                        }
-                                        else {
-                                            $limits[$k] += $v;
-                                        }
+                            default:
+                                if ($limits[$k] > -1){
+                                    if ($v == -1){
+                                        $limits[$k] = -1;
+                                    }
+                                    else {
+                                        $limits[$k] += $v;
                                     }
                                 }
                             }
-                            /* process the string limits (CHECKBOXARRAY, SELECT etc.) */
-                            elseif (is_string($v)){
-                                switch ($form["tabs"]["limits"]["fields"][$k]['formtype']){
-                                case 'CHECKBOXARRAY':
-                                    if (!isset($limits[$k])){
-                                        $limits[$k] = array();
-                                    }
-
-                                    $limits_values = $limits[$k];
-                                    if (is_string($limits[$k])){
-                                        $limits_values = explode($form["tabs"]["limits"]["fields"][$k]["separator"],$limits[$k]);
-                                    }
-                                    $additional_values = explode($form["tabs"]["limits"]["fields"][$k]["separator"],$v);
-                                    $app->log('Template processing key ' . $k . ' type CHECKBOXARRAY, lim / add: ' . implode(',', $limits_values) . ' / ' . implode(',', $additional_values) . ' for client ' . $clientId, LOGLEVEL_DEBUG);
-                                    /* unification of limits_values (master template) and additional_values (additional template) */
-                                    $limits_unified = array();
-                                    foreach($form["tabs"]["limits"]["fields"][$k]["value"] as $key => $val){
-                                        if (in_array($key,$limits_values) || in_array($key,$additional_values)) $limits_unified[] = $key;
-                                    }
-                                    $limits[$k] = implode($form["tabs"]["limits"]["fields"][$k]["separator"],$limits_unified);
-                                break;
-                                case 'CHECKBOX':
-                                    if($k == 'force_suexec') {
-                                        // 'n' is less limited than y
-                                        if (!isset($limits[$k])){
-                                            $limits[$k] = 'y';
-                                        }
-                                        if($limits[$k] == 'n' || $v == 'n') $limits[$k] = 'n';
-                                    } else {
-                                        // 'y' is less limited than n
-                                        if (!isset($limits[$k])){
-                                            $limits[$k] = 'n';
-                                        }
-                                        if($limits[$k] == 'y' || $v == 'y') $limits[$k] = 'y';
-                                    }
-                                break;
-                                case 'SELECT':
-                                    $limit_values = array_keys($form["tabs"]["limits"]["fields"][$k]["value"]);
-                                    /* choose the lower index of the two SELECT items */
-                                    $limits[$k] = $limit_values[min(array_search($limits[$k], $limit_values), array_search($v, $limit_values))];
-                                break;
+                        }
+                        /* process the string limits (CHECKBOXARRAY, SELECT etc.) */
+                        elseif (is_string($v)){
+                            switch ($form["tabs"]["limits"]["fields"][$k]['formtype']){
+                            case 'CHECKBOXARRAY':
+                                if (!isset($limits[$k])){
+                                    $limits[$k] = array();
                                 }
+
+                                $limits_values = $limits[$k];
+                                if (is_string($limits[$k])){
+                                    $limits_values = explode($form["tabs"]["limits"]["fields"][$k]["separator"],$limits[$k]);
+                                }
+                                $additional_values = explode($form["tabs"]["limits"]["fields"][$k]["separator"],$v);
+                                $app->log('Template processing key ' . $k . ' type CHECKBOXARRAY, lim / add: ' . implode(',', $limits_values) . ' / ' . implode(',', $additional_values) . ' for client ' . $clientId, LOGLEVEL_DEBUG);
+                                /* unification of limits_values (master template) and additional_values (additional template) */
+                                $limits_unified = array();
+                                foreach($form["tabs"]["limits"]["fields"][$k]["value"] as $key => $val){
+                                    if (in_array($key,$limits_values) || in_array($key,$additional_values)) $limits_unified[] = $key;
+                                }
+                                $limits[$k] = implode($form["tabs"]["limits"]["fields"][$k]["separator"],$limits_unified);
+                            break;
+                            case 'CHECKBOX':
+                                if($k == 'force_suexec') {
+                                    // 'n' is less limited than y
+                                    if (!isset($limits[$k])){
+                                        $limits[$k] = 'y';
+                                    }
+                                    if($limits[$k] == 'n' || $v == 'n') $limits[$k] = 'n';
+                                } else {
+                                    // 'y' is less limited than n
+                                    if (!isset($limits[$k])){
+                                        $limits[$k] = 'n';
+                                    }
+                                    if($limits[$k] == 'y' || $v == 'y') $limits[$k] = 'y';
+                                }
+                            break;
+                            case 'SELECT':
+                                $limit_values = array_keys($form["tabs"]["limits"]["fields"][$k]["value"]);
+                                /* choose the lower index of the two SELECT items */
+                                $limits[$k] = $limit_values[min(array_search($limits[$k], $limit_values), array_search($v, $limit_values))];
+                            break;
                             }
                         }
                     }
diff --git a/interface/lib/classes/remoting.inc.php b/interface/lib/classes/remoting.inc.php
index 66ba90d..1668004 100644
--- a/interface/lib/classes/remoting.inc.php
+++ b/interface/lib/classes/remoting.inc.php
@@ -1176,7 +1176,93 @@
 			
 			return $affected_rows;
 	}
+    
+    public function client_template_additional_get($session_id, $client_id) {
+        global $app;
 
+		if(!$this->checkPerm($session_id, 'client_get')) {
+			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+			return false;
+		}
+        
+        if(@is_numeric($client_id)) {
+            $sql = "SELECT * FROM `client_template_assigned` WHERE `client_id` = ".$client_id;
+            return $app->db->queryOneRecord($sql);
+        } else {
+            $this->server->fault('The ID must be an integer.');
+            return array();
+        }
+    }
+    
+    public function client_template_additional_add($session_id, $client_id, $template_id) {
+        global $app;
+        
+		if(!$this->checkPerm($session_id, 'client_update')) {
+			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+			return false;
+		}
+        
+        if(@is_numeric($client_id) && @is_numeric($template_id)) {
+            // check if client exists
+            $check = $app->db->queryOneRecord('SELECT `client_id` FROM `client` WHERE `client_id` = ' . $client_id);
+            if(!$check) {
+                $this->server->fault('Invalid client');
+                return false;
+            }
+            // check if template exists
+            $check = $app->db->queryOneRecord('SELECT `template_id` FROM `client_template` WHERE `template_id` = ' . $template_id);
+            if(!$check) {
+                $this->server->fault('Invalid template');
+                return false;
+            }
+            
+            $sql = "INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (" . $client_id . ", " . $template_id . ")";
+            $app->db->query($sql);
+            $insert_id = $app->db->insertID();
+            
+            $app->plugin->raiseEvent('client:client:on_after_update',$this);
+            
+            return $insert_id;
+        } else {
+            $this->server->fault('The IDs must be of type integer.');
+            return false;
+        }
+    }
+
+    public function client_template_additional_delete($session_id, $client_id, $assigned_template_id) {
+        global $app;
+        
+		if(!$this->checkPerm($session_id, 'client_update')) {
+			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+			return false;
+		}
+        
+        if(@is_numeric($client_id) && @is_numeric($template_id)) {
+            // check if client exists
+            $check = $app->db->queryOneRecord('SELECT `client_id` FROM `client` WHERE `client_id` = ' . $client_id);
+            if(!$check) {
+                $this->server->fault('Invalid client');
+                return false;
+            }
+            // check if template exists
+            $check = $app->db->queryOneRecord('SELECT `assigned_template_id` FROM `client_template_assigned` WHERE `assigned_template_id` = ' . $assigned_template_id);
+            if(!$check) {
+                $this->server->fault('Invalid template');
+                return false;
+            }
+            
+            $sql = "DELETE FROM `client_template_assigned` WHERE `assigned_template_id` = " . $template_id . " AND `client_id` = " . $client_id;
+            $app->db->query($sql);
+            $affected_rows = $app->db->affectedRows();
+            
+            $app->plugin->raiseEvent('client:client:on_after_update',$this);
+            
+            return $affected_rows;
+        } else {
+            $this->server->fault('The IDs must be of type integer.');
+            return false;
+        }
+    }
 
 	public function client_delete($session_id,$client_id)
 	{
diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php
index 2b72d81..2becb95 100644
--- a/interface/web/client/client_edit.php
+++ b/interface/web/client/client_edit.php
@@ -49,8 +49,8 @@
 $app->load('tform_actions');
 
 class page_action extends tform_actions {
-
-
+    var $_template_additional = array();
+    
 	function onShowNew() {
 		global $app, $conf;
 		
@@ -92,8 +92,28 @@
 				}
 			}
 		}
-		
-		parent::onSubmit();
+        
+        if($this->id != 0) {
+            $this->oldTemplatesAssigned = $app->db->queryAllRecords('SELECT * FROM `client_template_assigned` WHERE `client_id` = ' . $this->id);
+            if(!is_array($this->oldTemplatesAssigned) || count($this->oldTemplatesAssigned) < 1) {
+                // check previous type of storing templates
+                $tpls = explode('/', $this->oldDataRecord['template_additional']);
+                $this->oldTemplatesAssigned = array();
+                foreach($tpls as $item) {
+                    $item = trim($item);
+                    if(!$item) continue;
+                    $this->oldTemplatesAssigned[] = array('assigned_templated_id' => 0, 'client_template_id' => $item, 'client_id' => $this->id);
+                }
+                unset($tpls);
+            }
+        } else {
+            $this->oldTemplatesAssigned = array();
+        }
+        
+        $this->_template_additional = explode('/', $this->dataRecord['template_additional']);
+        $this->dataRecord['template_additional'] = '';
+        
+        parent::onSubmit();
 	}
 
 	function onShowEnd() {
@@ -110,16 +130,44 @@
 		}
 		$app->tpl->setVar('tpl_add_select',$option);
 
-		$sql = "SELECT template_additional FROM client WHERE client_id = " . $this->id;
-		$result = $app->db->queryOneRecord($sql);
-		$tplAdd = explode("/", $result['template_additional']);
-		$text = '';
-		foreach($tplAdd as $item){
-			if (trim($item) != ''){
-				if ($text != '') $text .= '';
-				$text .= '<li>' . $tpl[$item]. '</li>';
-			}
-		}
+        // check for new-style records
+        $result = $app->db->queryAllRecords('SELECT assigned_template_id, client_template_id FROM client_template_assigned WHERE client_id = ' . $this->id);
+        if($result && count($result) > 0) {
+            // new style
+            $items = array();
+            $text = '';
+            foreach($result as $item){
+                if (trim($item['client_template_id']) != ''){
+                    if ($text != '') $text .= '';
+                    $text .= '<li rel="' . $item['assigned_template_id'] . '">' . $tpl[$item['client_template_id']];
+                    $text .= '<a href="#" class="button icons16 icoDelete"></a>';
+                                        $tmp = new stdClass();
+                    $tmp->id = $item['assigned_template_id'];
+                    $tmp->data = '';
+                    $app->plugin->raiseEvent('get_client_template_details', $tmp);
+                    if($tmp->data != '') $text .= '<br /><em>' . $tmp->data . '</em>';
+
+                    $text .= '</li>';
+                    $items[] = $item['assigned_template_id'] . ':' . $item['client_template_id'];
+                }
+            }
+
+            $tmprec = $app->tform->getHTML(array('template_additional' => implode('/', $items)), $this->active_tab, 'EDIT');
+            $app->tpl->setVar('template_additional', $tmprec['template_additional']);
+            unset($tmprec);
+        } else {
+            // old style
+            $sql = "SELECT template_additional FROM client WHERE client_id = " . $this->id;
+            $result = $app->db->queryOneRecord($sql);
+            $tplAdd = explode("/", $result['template_additional']);
+            $text = '';
+            foreach($tplAdd as $item){
+                if (trim($item) != ''){
+                    if ($text != '') $text .= '';
+                    $text .= '<li>' . $tpl[$item]. '<a href="#" class="button icons16 icoDelete"></a></li>';
+                }
+            }
+        }
 
 		$app->tpl->setVar('template_additional_list', $text);
 		$app->tpl->setVar('app_module','client');
@@ -127,7 +175,7 @@
 		parent::onShowEnd();
 
 	}
-
+    
 	/*
 	 This function is called automatically right after
 	 the data was successful inserted in the database.
@@ -180,6 +228,8 @@
 		$sql = "UPDATE client SET default_mailserver = $default_mailserver, default_webserver = $default_webserver, default_dnsserver = $default_dnsserver, default_slave_dnsserver = $default_dnsserver, default_dbserver = $default_dbserver WHERE client_id = ".$this->id;
 		$app->db->query($sql);
 		
+        $app->uses('client_templates');
+        $app->client_templates->update_client_templates($this->id, $this->_template_additional);
 
 		parent::onAfterInsert();
 	}
@@ -218,6 +268,99 @@
 			$app->db->query($sql);
 		}
 		
+        if(!isset($this->dataRecord['locked'])) $this->dataRecord['locked'] = 'n';
+        if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && $this->dataRecord["locked"] != $this->oldDataRecord['locked']) {
+            /** lock all the things like web, mail etc. - easy to extend */
+            
+            // get tmp_data of client
+            $client_data = $app->db->queryOneRecord('SELECT `tmp_data` FROM `client` WHERE `client_id` = ' . $this->id);
+            
+            if($client_data['tmp_data'] == '') $tmp_data = array();
+            else $tmp_data = unserialize($client_data['tmp_data']);
+            
+            if(!is_array($tmp_data)) $tmp_data = array();
+            
+            // database tables with their primary key columns
+            $to_disable = array('cron' => 'id',
+                                'ftp_user' => 'ftp_user_id',
+                                'mail_domain' => 'domain_id',
+                                'mail_forwarding' => 'forwarding_id',
+                                'mail_get' => 'mailget_id',
+                                'openvz_vm' => 'vm_id',
+                                'shell_user' => 'shell_user_id',
+                                'webdav_user' => 'webdav_user_id',
+                                'web_database' => 'database_id',
+                                'web_domain' => 'domain_id',
+                                'web_folder' => 'web_folder_id',
+                                'web_folder_user' => 'web_folder_user_id'
+                               );
+            
+            $udata = $app->db->queryOneRecord('SELECT `userid` FROM `sys_user` WHERE `client_id` = ' . $this->id);
+            $gdata = $app->db->queryOneRecord('SELECT `groupid` FROM `sys_group` WHERE `client_id` = ' . $this->id);
+            $sys_groupid = $gdata['groupid'];
+            $sys_userid = $udata['userid'];
+            
+            $entries = array();
+            if($this->dataRecord['locked'] == 'y') {
+                $prev_active = array();
+                $prev_sysuser = array();
+                foreach($to_disable as $current => $keycolumn) {
+                    $prev_active[$current] = array();
+                    $prev_sysuser[$current] = array();
+                    
+                    $entries = $app->db->queryAllRecords('SELECT `' . $keycolumn . '` as `id`, `sys_userid`, `active` FROM `' . $current . '` WHERE `sys_groupid` = ' . $sys_groupid);
+                    foreach($entries as $item) {
+                        
+                        if($item['active'] != 'y') $prev_active[$current][$item['id']]['active'] = 'n';
+                        if($item['sys_userid'] != $sys_userid) $prev_sysuser[$current][$item['id']]['active'] = $item['sys_userid'];
+                        // we don't have to store these if y, as everything without previous state gets enabled later
+                        
+                        $app->db->datalogUpdate($current, array('active' => 'n', 'sys_userid' => $_SESSION["s"]["user"]["userid"]), $keycolumn, $item['id']);
+                    }
+                }
+                
+                $tmp_data['prev_active'] = $prev_active;
+                $tmp_data['prev_sys_userid'] = $prev_sysuser;
+                $app->db->query("UPDATE `client` SET `tmp_data` = '" . $app->db->quote(serialize($tmp_data)) . "' WHERE `client_id` = " . $this->id);
+                unset($prev_active);
+                unset($prev_sysuser);
+            } elseif($this->dataRecord['locked'] == 'n') {
+                foreach($to_disable as $current => $keycolumn) {
+                    $entries = $app->db->queryAllRecords('SELECT `' . $keycolumn . '` as `id` FROM `' . $current . '` WHERE `sys_groupid` = ' . $sys_groupid);
+                    foreach($entries as $item) {
+                        $set_active = 'y';
+                        $set_sysuser = $sys_userid;
+                        if(array_key_exists('prev_active', $tmp_data) == true
+                            && array_key_exists($current, $tmp_data['prev_active']) == true
+                            && array_key_exists($item['id'], $tmp_data['prev_active'][$current]) == true
+                            && $tmp_data['prev_active'][$current][$item['id']] == 'n') $set_active = 'n';
+                        if(array_key_exists('prev_sysuser', $tmp_data) == true
+                            && array_key_exists($current, $tmp_data['prev_sysuser']) == true
+                            && array_key_exists($item['id'], $tmp_data['prev_sysuser'][$current]) == true
+                            && $tmp_data['prev_sysuser'][$current][$item['id']] != $sys_userid) $set_sysuser = $tmp_data['prev_sysuser'][$current][$item['id']];
+                        
+                        $app->db->datalogUpdate($current, array('active' => $set_active, 'sys_userid' => $set_sysuser), $keycolumn, $item['id']);
+                    }
+                }
+                if(array_key_exists('prev_active', $tmp_data)) unset($tmp_data['prev_active']);
+                $app->db->query("UPDATE `client` SET `tmp_data` = '" . $app->db->quote(serialize($tmp_data)) . "' WHERE `client_id` = " . $this->id);
+            }
+            unset($tmp_data);
+            unset($entries);
+            unset($to_disable);
+        }
+        
+        if(!isset($this->dataRecord['canceled'])) $this->dataRecord['canceled'] = 'n';
+        if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord["canceled"]) && $this->dataRecord["canceled"] != $this->oldDataRecord['canceled']) {
+            if($this->dataRecord['canceled'] == 'y') {
+                $sql = "UPDATE sys_user SET active = 'n' WHERE client_id = " . $this->id;
+                $app->db->query($sql);
+            } elseif($this->dataRecord['canceled'] == 'n') {
+                $sql = "UPDATE sys_user SET active = 'y' WHERE client_id = " . $this->id;
+                $app->db->query($sql);
+            }
+        }
+        
 		// language changed
 		if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['language']) && $this->dataRecord['language'] != '' && $this->oldDataRecord['language'] != $this->dataRecord['language']) {
 			$language = $app->db->quote($this->dataRecord["language"]);
@@ -236,6 +379,9 @@
 			$app->db->query($sql);
 		}
 		
+        $app->uses('client_templates');
+        $app->client_templates->update_client_templates($this->id, $this->_template_additional);
+        
 		parent::onAfterUpdate();
 	}
 }
diff --git a/interface/web/client/client_template_del.php b/interface/web/client/client_template_del.php
index dbe8639..647ad7c 100644
--- a/interface/web/client/client_template_del.php
+++ b/interface/web/client/client_template_del.php
@@ -53,6 +53,13 @@
 	function onBeforeDelete() {
 		global $app;
 		
+		// check new style
+        $rec = $app->db->queryOneRecord("SELECT count(client_id) as number FROM client_template_assigned WHERE client_template_id = ".$this->id);
+		if($rec['number'] > 0) {
+			$app->error($app->tform->lng('template_del_aborted_txt'));
+		}
+        
+        // check old style
 		$rec = $app->db->queryOneRecord("SELECT count(client_id) as number FROM client WHERE template_master = ".$this->id." OR template_additional like '%/".$this->id."/%'");
 		if($rec['number'] > 0) {
 			$app->error($app->tform->lng('template_del_aborted_txt'));
diff --git a/interface/web/client/client_template_edit.php b/interface/web/client/client_template_edit.php
index a683800..bb2fd94 100644
--- a/interface/web/client/client_template_edit.php
+++ b/interface/web/client/client_template_edit.php
@@ -81,7 +81,7 @@
 		if ($this->dataRecord["template_type"] == 'm'){
 			$sql = "SELECT client_id FROM client WHERE template_master = " . $this->id;
 		} else {
-			$sql = "SELECT client_id FROM client WHERE template_additional LIKE '%/" . $this->id . "/%' OR template_additional LIKE '" . $this->id . "/%' OR template_additional LIKE '%/" . $this->id . "'";
+			$sql = "SELECT client_id FROM client WHERE template_additional LIKE '%/" . $this->id . "/%' OR template_additional LIKE '" . $this->id . "/%' OR template_additional LIKE '%/" . $this->id . "' UNION SELECT client_id FROM client_template_assigned WHERE client_template_id = " . $this->id;
 		}
 		$clients = $app->db->queryAllRecords($sql);
 		if (is_array($clients)){
diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php
index b29a831..0362480 100644
--- a/interface/web/client/form/client.tform.php
+++ b/interface/web/client/form/client.tform.php
@@ -100,6 +100,12 @@
 			'cols'		=> '',
 			'searchable' => 2
 		),
+		'gender' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'SELECT',
+			'default'	=> '',
+			'value'		=> array('' => '', 'm' => 'gender_m_txt', 'f' => 'gender_f_txt')
+		),
 		'contact_name' => array (
 			'datatype'	=> 'VARCHAR',
 			'formtype'	=> 'TEXT',
@@ -454,6 +460,18 @@
 			'cols'		=> '',
 			'searchable' => 2
 		),
+		'locked' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'CHECKBOX',
+			'default'	=> 'n',
+			'value'		=> array(0 => 'n',1 => 'y')
+		),
+		'canceled' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'CHECKBOX',
+			'default'	=> 'n',
+			'value'		=> array(0 => 'n',1 => 'y')
+		),
 	##################################
 	# END Datatable fields
 	##################################
diff --git a/interface/web/client/form/reseller.tform.php b/interface/web/client/form/reseller.tform.php
index a6c4bd9..c78ed8e 100644
--- a/interface/web/client/form/reseller.tform.php
+++ b/interface/web/client/form/reseller.tform.php
@@ -100,6 +100,12 @@
 			'cols'		=> '',
 			'searchable' => 2
 		),
+		'gender' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'SELECT',
+			'default'	=> '',
+			'value'		=> array('' => '', 'm' => 'gender_m_txt', 'f' => 'gender_f_txt')
+		),
 		'contact_name' => array (
 			'datatype'	=> 'VARCHAR',
 			'formtype'	=> 'TEXT',
@@ -451,6 +457,18 @@
 			'cols'		=> '',
 			'searchable' => 2
 		),
+		'locked' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'CHECKBOX',
+			'default'	=> 'n',
+			'value'		=> array(0 => 'n',1 => 'y')
+		),
+		'canceled' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'CHECKBOX',
+			'default'	=> 'n',
+			'value'		=> array(0 => 'n',1 => 'y')
+		),
 	##################################
 	# END Datatable fields
 	##################################
diff --git a/interface/web/client/lib/lang/de_client.lng b/interface/web/client/lib/lang/de_client.lng
index 57310d8..4aa8abd 100644
--- a/interface/web/client/lib/lang/de_client.lng
+++ b/interface/web/client/lib/lang/de_client.lng
@@ -144,4 +144,9 @@
 $wb['limit_aps_txt'] = 'Max. Anzahl an APS-Instanzen';
 $wb['limit_aps_error_notint'] = 'Das APS Instanzen Limit muss eine Zahl sein.';
 $wb['default_slave_dnsserver_txt'] = 'Standard Secondary DNS Server';
+$wb['locked_txt'] = 'Gesperrt (deaktiviert alle Webs, etc.)';
+$wb['canceled_txt'] = 'Gek&uuml;ndigt (verhindert Kundenlogin)';
+$wb['gender_txt'] = 'Anrede';
+$wb['gender_m_txt'] = 'Herr';
+$wb['gender_f_txt'] = 'Frau';
 ?>
diff --git a/interface/web/client/lib/lang/de_reseller.lng b/interface/web/client/lib/lang/de_reseller.lng
index 072d648..9bc4d53 100644
--- a/interface/web/client/lib/lang/de_reseller.lng
+++ b/interface/web/client/lib/lang/de_reseller.lng
@@ -143,4 +143,9 @@
 $wb['limit_aps_txt'] = 'Max. Anzahl an APS-Instanzen';
 $wb['limit_aps_error_notint'] = 'Das APS Instanzen Limit muss eine Zahl sein.';
 $wb['default_slave_dnsserver_txt'] = 'Standard Secondary DNS Server';
+$wb['locked_txt'] = 'Gesperrt';
+$wb['canceled_txt'] = 'Gek&uuml;ndigt';
+$wb['gender_m_txt'] = 'Herr';
+$wb['gender_f_txt'] = 'Frau';
+$wb['gender_txt'] = 'Anrede';
 ?>
diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng
index 69574d8..7c4ee26 100644
--- a/interface/web/client/lib/lang/en_client.lng
+++ b/interface/web/client/lib/lang/en_client.lng
@@ -147,4 +147,9 @@
 $wb['limit_aps_txt'] = 'Max. number of APS instances';
 $wb['limit_aps_error_notint'] = 'The APS instances limit must be a number.';
 $wb["default_slave_dnsserver_txt"] = 'Default Secondary DNS Server';
+$wb['locked_txt'] = 'Locked (disables all webs etc.)';
+$wb['canceled_txt'] = 'Canceled (disables client login)';
+$wb['gender_txt'] = 'Title';
+$wb['gender_m_txt'] = 'Mr.';
+$wb['gender_f_txt'] = 'Ms.';
 ?>
diff --git a/interface/web/client/lib/lang/en_reseller.lng b/interface/web/client/lib/lang/en_reseller.lng
index d936ddb..4076dd5 100644
--- a/interface/web/client/lib/lang/en_reseller.lng
+++ b/interface/web/client/lib/lang/en_reseller.lng
@@ -145,4 +145,9 @@
 $wb['limit_aps_txt'] = 'Max. number of APS instances';
 $wb['limit_aps_error_notint'] = 'The APS instances limit must be a number.';
 $wb["default_slave_dnsserver_txt"] = 'Default Secondary DNS Server';
+$wb['locked_txt'] = 'Locked';
+$wb['canceled_txt'] = 'Canceled';
+$wb['gender_m_txt'] = 'Mr.';
+$wb['gender_f_txt'] = 'Ms.';
+$wb['gender_txt'] = 'Title';
 ?>
diff --git a/interface/web/client/reseller_edit.php b/interface/web/client/reseller_edit.php
index 1d02237..ca2780c 100644
--- a/interface/web/client/reseller_edit.php
+++ b/interface/web/client/reseller_edit.php
@@ -113,16 +113,30 @@
 		}
 		$app->tpl->setVar('tpl_add_select',$option);
 
-		$sql = "SELECT template_additional FROM client WHERE client_id = " . $this->id;
-		$result = $app->db->queryOneRecord($sql);
-		$tplAdd = explode("/", $result['template_additional']);
-		$text = '';
-		foreach($tplAdd as $item){
-			if (trim($item) != ''){
-				if ($text != '') $text .= '<br />';
-				$text .= $tpl[$item];
-			}
-		}
+        // check for new-style records
+        $result = $app->db->queryAllRecords('SELECT assigned_template_id, client_template_id FROM client_template_assigned WHERE client_id = ' . $this->id);
+        if($result && count($result) > 0) {
+            // new style
+            $text = '';
+            foreach($result as $item){
+                if (trim($item['client_template_id']) != ''){
+                    if ($text != '') $text .= '';
+                    $text .= '<li rel="' . $item['assigned_template_id'] . '">' . $tpl[$item['client_template_id']]. '<a href="#" class="button icons16 icoDelete"></a></li>';
+                }
+            }
+        } else {
+            // old style
+            $sql = "SELECT template_additional FROM client WHERE client_id = " . $this->id;
+            $result = $app->db->queryOneRecord($sql);
+            $tplAdd = explode("/", $result['template_additional']);
+            $text = '';
+            foreach($tplAdd as $item){
+                if (trim($item) != ''){
+                    if ($text != '') $text .= '';
+                    $text .= '<li>' . $tpl[$item]. '<a href="#" class="button icons16 icoDelete"></a></li>';
+                }
+            }
+        }
 
 		$app->tpl->setVar('template_additional_list', $text);
 
diff --git a/interface/web/client/templates/client_edit_address.htm b/interface/web/client/templates/client_edit_address.htm
index f9d96f0..018d1d5 100644
--- a/interface/web/client/templates/client_edit_address.htm
+++ b/interface/web/client/templates/client_edit_address.htm
@@ -10,6 +10,12 @@
                 <input name="company_name" id="company_name" value="{tmpl_var name='company_name'}" size="30" maxlength="255" type="text" class="textInput" />
             </div>
             <div class="ctrlHolder">
+                <label for="gender">{tmpl_var name='gender_txt'}</label>
+                <select name="gender" id="gender" class="selectInput">
+                    {tmpl_var name='gender'}
+                </select>
+            </div>
+            <div class="ctrlHolder">
                 <label for="contact_name">{tmpl_var name='contact_name_txt'}*</label>
                 <input name="contact_name" id="contact_name" value="{tmpl_var name='contact_name'}" size="30" maxlength="255" type="text" class="textInput" />
             </div>
@@ -134,6 +140,18 @@
                 <label for="notes">{tmpl_var name='notes_txt'}</label>
                 <textarea name="notes" id="notes" rows='10' cols='30'>{tmpl_var name='notes'}</textarea>
             </div>
+            <div class="ctrlHolder">
+                <p class="label">{tmpl_var name='locked_txt'}</p>
+                <div class="multiField">
+                    {tmpl_var name='locked'}
+                </div>
+            </div>
+            <div class="ctrlHolder">
+                <p class="label">{tmpl_var name='canceled_txt'}</p>
+                <div class="multiField">
+                    {tmpl_var name='canceled'}
+                </div>
+            </div>
             {tmpl_var name='required_fields_txt'}
         </fieldset>
 
diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm
index 2e81002..ba349b6 100644
--- a/interface/web/client/templates/client_edit_limits.htm
+++ b/interface/web/client/templates/client_edit_limits.htm
@@ -8,7 +8,6 @@
             <fieldset><legend>{tmpl_var name="toolsarea_head_txt"}</legend>
                 <div class="buttons topbuttons">
                     <button class="positive iconstxt icoAdd" type="button" value="{tmpl_var name='add_additional_template_txt'}" onclick="addAdditionalTemplate();"><span>{tmpl_var name='add_additional_template_txt'}</span></button>
-                    <button class="negative iconstxt icoDelete" type="button" value="{tmpl_var name='delete_additional_template_txt'}" onclick="delAdditionalTemplate();"><span>{tmpl_var name='delete_additional_template_txt'}</span></button>
                 </div>
             </fieldset>
         </div>
@@ -309,6 +308,11 @@
     return ($('#template_master').val() == '0' ? true : false);
 }
 
+jQuery('#template_additional_list').find('li > a').click(function(e) {
+    e.preventDefault();
+    delAdditionalTemplate($(this).parent().attr('rel'));
+});
+
 jQuery('div.panel_client')
         .find('div.pnl_formsarea')
         .find('fieldset')
diff --git a/interface/web/client/templates/reseller_edit_address.htm b/interface/web/client/templates/reseller_edit_address.htm
index 67eabbe..4ffd78a 100644
--- a/interface/web/client/templates/reseller_edit_address.htm
+++ b/interface/web/client/templates/reseller_edit_address.htm
@@ -10,6 +10,12 @@
                 <input name="company_name" id="company_name" value="{tmpl_var name='company_name'}" size="30" maxlength="255" type="text" class="textInput" />
             </div>
             <div class="ctrlHolder">
+                <label for="gender">{tmpl_var name='gender_txt'}</label>
+                <select name="gender" id="gender" class="selectInput">
+                    {tmpl_var name='gender'}
+                </select>
+            </div>
+            <div class="ctrlHolder">
                 <label for="contact_name">{tmpl_var name='contact_name_txt'}*</label>
                 <input name="contact_name" id="contact_name" value="{tmpl_var name='contact_name'}" size="30" maxlength="255" type="text" class="textInput" />
             </div>
@@ -134,6 +140,18 @@
                 <label for="notes">{tmpl_var name='notes_txt'}</label>
                 <textarea name="notes" id="notes" rows='10' cols='30'>{tmpl_var name='notes'}</textarea>
             </div>
+            <div class="ctrlHolder">
+                <p class="label">{tmpl_var name='locked_txt'}</p>
+                <div class="multiField">
+                    {tmpl_var name='locked'}
+                </div>
+            </div>
+            <div class="ctrlHolder">
+                <p class="label">{tmpl_var name='canceled_txt'}</p>
+                <div class="multiField">
+                    {tmpl_var name='canceled'}
+                </div>
+            </div>
             {tmpl_var name='required_fields_txt'}
         </fieldset>
 
diff --git a/interface/web/js/scrigo.js.php b/interface/web/js/scrigo.js.php
index c78406a..418b26b 100644
--- a/interface/web/js/scrigo.js.php
+++ b/interface/web/js/scrigo.js.php
@@ -642,40 +642,65 @@
 	return false;
 }
 
+var new_tpl_add_id = 0;
 function addAdditionalTemplate(){
-	var tpl_add = document.getElementById('template_additional').value;
-	
-	  var tpl_list = document.getElementById('template_additional_list').innerHTML;
-	  var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
-	  var addTplId = addTemplate[0];
-	  var addTplText = addTemplate[1];
+    var tpl_add = jQuery('#template_additional').val();
+    var addTemplate = jQuery('#tpl_add_select').val().split('|',2);
+	var addTplId = addTemplate[0];
+	var addTplText = addTemplate[1];
 	if(addTplId > 0) {
-	  var newVal = tpl_add + '/' + addTplId + '/';
-	  newVal = newVal.replace('//', '/');
-	  var newList = tpl_list + '<br>' + addTplText;
-	  newList = newList.replace('<br><br>', '<br>');
-	  document.getElementById('template_additional').value = newVal;
-	  document.getElementById('template_additional_list').innerHTML = newList;
-	  alert('additional template ' + addTplText + ' added to customer');
+        var newVal = tpl_add.split('/');
+        new_tpl_add_id += 1;
+        var delbtn = jQuery('<a href="#"></a>').attr('class', 'button icons16 icoDelete').click(function(e) {
+            e.preventDefault();
+            delAdditionalTemplate($(this).parent().attr('rel'));
+        });
+        newVal[newVal.length] = 'n' + new_tpl_add_id + ':' + addTplId;
+	    jQuery('<li>' + addTplText + '</li>').attr('rel', 'n' + new_tpl_add_id).append(delbtn).appendTo('#template_additional_list ul');
+	    jQuery('#template_additional').val(newVal.join('/'));
+	    alert('additional template ' + addTplText + ' added to customer');
 	} else {
-	  alert('no additional template selcted');
+	    alert('no additional template selcted');
 	}
 }
 
-function delAdditionalTemplate(){
-	var tpl_add = document.getElementById('template_additional').value;
-	if(tpl_add != '') {
-		var tpl_list = document.getElementById('template_additional_list').innerHTML;
+function delAdditionalTemplate(tpl_id){
+    var tpl_add = jQuery('#template_additional').val();
+	if(tpl_id) {
+        // new style
+		var $el = jQuery('#template_additional_list ul').find('li[rel="' + tpl_id + '"]').eq(0); // only the first
+        var addTplText = $el.text();
+        $el.remove();
+        
+		var oldVal = tpl_add.split('/');
+		var newVal = new Array();
+        for(var i = 0; i < oldVal.length; i++) {
+            var tmp = oldVal[i].split(':', 2);
+            if(tmp.length == 2 && tmp[0] == tpl_id) continue;
+            newVal[newVal.length] = oldVal[i];
+        }
+        jQuery('#template_additional').val(newVal.join('/'));
+		alert('additional template ' + addTplText + ' deleted from customer');
+    } else if(tpl_add != '') {
+        // old style
 		var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
 		var addTplId = addTemplate[0];
 		var addTplText = addTemplate[1];
+
+		jQuery('#template_additional_list ul').find('li:not([rel])').each(function() {
+            var text = jQuery(this).text();
+            if(text == addTplText) {
+                jQuery(this).remove();
+                return false;
+            }
+            return this;
+        });
+        
 		var newVal = tpl_add;
-		newVal = newVal.replace(addTplId, '');
+        var repl = new RegExp('(^|\/)' + addTplId + '(\/|$)');
+		newVal = newVal.replace(repl, '');
 		newVal = newVal.replace('//', '/');
-		var newList = tpl_list.replace(addTplText, '');
-		newList = newList.replace('<br><br>', '<br>');
-		document.getElementById('template_additional').value = newVal;
-		document.getElementById('template_additional_list').innerHTML = newList;
+		jQuery('#template_additional').val(newVal);
 		alert('additional template ' + addTplText + ' deleted from customer');
   } else {
   	alert('no additional template selcted');
diff --git a/interface/web/mail/mail_user_edit.php b/interface/web/mail/mail_user_edit.php
index ca973c5..da3f99cb 100644
--- a/interface/web/mail/mail_user_edit.php
+++ b/interface/web/mail/mail_user_edit.php
@@ -166,7 +166,7 @@
 			}
 			
 			// Check the quota and adjust
-			if(isset($_POST["quota"]) && $client["limit_mailquota"] >= 0) {
+			if(isset($_POST["quota"]) && $client["limit_mailquota"] >= 0 && $app->functions->intval($this->dataRecord["quota"]) * 1024 * 1024 != $this->oldDataRecord['quota']) {
 				$tmp = $app->db->queryOneRecord("SELECT sum(quota) as mailquota FROM mail_user WHERE mailuser_id != ".$app->functions->intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
 				$mailquota = $tmp["mailquota"] / 1024 / 1024;
 				$new_mailbox_quota = $app->functions->intval($this->dataRecord["quota"]);
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index 4554bc2..faf9435 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -968,7 +968,16 @@
 			unset($backup_copies);
 			unset($backup_interval);
 		}
-
+        
+        //* Change vhost subdomain ip/ipv6 if domain ip/ipv6 has changed
+        if(isset($this->dataRecord['ip_address']) && ($this->dataRecord['ip_address'] != $this->oldDataRecord['ip_address'] || $this->dataRecord['ipv6_address'] != $this->oldDataRecord['ipv6_address'])) {
+			$records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE type = 'vhostsubdomain' AND parent_domain_id = ".$this->id);
+			foreach($records as $rec) {
+				$app->db->datalogUpdate('web_domain', "ip_address = '".$web_rec['ip_address']."', ipv6_address = '".$web_rec['ipv6_address']."'", 'domain_id', $rec['domain_id']);
+			}
+			unset($records);
+			unset($rec);
+        }
 	}
 
 	function onAfterDelete() {

--
Gitblit v1.9.1