From 3d96c53b303cfd720a44ad6f825eb94f7c4a3ca3 Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Wed, 20 Nov 2013 13:07:50 -0500
Subject: [PATCH] - Function to increment the customer number automatically - Added fields to client, reseller and website to show when a record was added and by which user
---
interface/web/sites/templates/web_domain_advanced.htm | 8 ++
interface/web/client/reseller_edit.php | 19 ++++
install/sql/incremental/upd_0060.sql | 8 ++
interface/web/client/form/client.tform.php | 22 +++++
interface/web/sites/lib/lang/en_web_domain.lng | 2
interface/web/sites/web_domain_edit.php | 4
interface/web/client/lib/lang/en_reseller.lng | 6 +
interface/web/client/templates/client_edit_address.htm | 8 ++
interface/web/client/lib/lang/en_client.lng | 2
interface/web/client/client_edit.php | 40 ++++++++++
install/sql/ispconfig3.sql | 7 +
interface/web/client/templates/reseller_edit_limits.htm | 12 +++
interface/web/client/form/reseller.tform.php | 50 ++++++++++++
interface/web/client/templates/reseller_edit_address.htm | 8 ++
interface/web/sites/form/web_domain.tform.php | 22 +++++
15 files changed, 217 insertions(+), 1 deletions(-)
diff --git a/install/sql/incremental/upd_0060.sql b/install/sql/incremental/upd_0060.sql
new file mode 100644
index 0000000..64c9a0d
--- /dev/null
+++ b/install/sql/incremental/upd_0060.sql
@@ -0,0 +1,8 @@
+ALTER TABLE `client` ADD `customer_no_template` VARCHAR( 255 ) NULL DEFAULT 'C[CUSTOMER_NO]' AFTER `ssh_rsa` ,
+ADD `customer_no_start` INT NOT NULL DEFAULT '1' AFTER `customer_no_template` ,
+ADD `customer_no_counter` INT NOT NULL DEFAULT '0' AFTER `customer_no_start` ,
+ADD `added_date` DATE NOT NULL default '0000-00-00' AFTER `customer_no_counter` ,
+ADD `added_by` VARCHAR( 255 ) NULL AFTER `added_date` ;
+ALTER TABLE `web_domain` ADD `added_date` DATE NOT NULL default '0000-00-00' AFTER `rewrite_rules` ,
+ADD `added_by` VARCHAR( 255 ) NULL AFTER `added_date` ;
+ALTER TABLE `sys_session` ADD `permanent` ENUM('n','y') NOT NULL DEFAULT 'n' AFTER `last_updated`;
\ No newline at end of file
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 565db7e..77425fe 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -232,6 +232,11 @@
`tmp_data` mediumblob,
`id_rsa` varchar(2000) NOT NULL DEFAULT '',
`ssh_rsa` varchar(600) NOT NULL DEFAULT '',
+ `customer_no_template` varchar(255) DEFAULT 'C[CUSTOMER_NO]',
+ `customer_no_start` int(11) NOT NULL DEFAULT '1',
+ `customer_no_counter` int(11) NOT NULL DEFAULT '0',
+ `added_date` date NOT NULL DEFAULT '0000-00-00',
+ `added_by` varchar(255) DEFAULT NULL,
PRIMARY KEY (`client_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
@@ -1796,6 +1801,8 @@
`proxy_directives` mediumtext,
`last_quota_notification` date NULL default NULL,
`rewrite_rules` mediumtext,
+ `added_date` date NOT NULL DEFAULT '0000-00-00',
+ `added_by` varchar(255) DEFAULT NULL,
PRIMARY KEY (`domain_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php
index efbf8ab..b98a368 100644
--- a/interface/web/client/client_edit.php
+++ b/interface/web/client/client_edit.php
@@ -171,6 +171,46 @@
$app->tpl->setVar('template_additional_list', $text);
$app->tpl->setVar('app_module', 'client');
+
+ //* Set the 'customer no' default value
+ if($this->id == 0) {
+
+ 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'] != '') {
+
+ //* Set customer no default
+ $customer_no = $app->functions->intval($system_config['misc']['customer_no_start']+$system_config['misc']['customer_no_counter']);
+ $customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$system_config['misc']['customer_no_template']);
+ $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
+ //* 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'] != '') {
+ //* Set customer no default
+ $customer_no = $app->functions->intval($reseller['customer_no_start']+$reseller['customer_no_counter']);
+ $customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$reseller['customer_no_template']);
+ $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']));
+ echo "UPDATE client SET customer_no_counter = $customer_no_counter WHERE client_id = ".$app->functions->intval($reseller['client_id']);
+ }
+ }
+ }
parent::onShowEnd();
diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php
index 16e68c0..5869776 100644
--- a/interface/web/client/form/client.tform.php
+++ b/interface/web/client/form/client.tform.php
@@ -472,6 +472,28 @@
'default' => 'n',
'value' => array(0 => 'n', 1 => 'y')
),
+ 'added_date' => array (
+ 'datatype' => 'DATE',
+ 'formtype' => 'TEXT',
+ 'default' => date($app->lng('conf_format_dateshort')),
+ 'value' => '',
+ 'separator' => '',
+ 'width' => '15',
+ 'maxlength' => '15',
+ 'rows' => '',
+ 'cols' => ''
+ ),
+ 'added_by' => array (
+ 'datatype' => 'VARCHAR',
+ 'formtype' => 'TEXT',
+ 'default' => $_SESSION['s']['user']['username'],
+ 'value' => '',
+ 'separator' => '',
+ 'width' => '30',
+ 'maxlength' => '255',
+ 'rows' => '',
+ 'cols' => ''
+ ),
//#################################
// END Datatable fields
//#################################
diff --git a/interface/web/client/form/reseller.tform.php b/interface/web/client/form/reseller.tform.php
index fad0cd7..77e1f63 100644
--- a/interface/web/client/form/reseller.tform.php
+++ b/interface/web/client/form/reseller.tform.php
@@ -469,6 +469,28 @@
'default' => 'n',
'value' => array(0 => 'n', 1 => 'y')
),
+ 'added_date' => array (
+ 'datatype' => 'DATE',
+ 'formtype' => 'TEXT',
+ 'default' => date($app->lng('conf_format_dateshort')),
+ 'value' => '',
+ 'separator' => '',
+ 'width' => '15',
+ 'maxlength' => '15',
+ 'rows' => '',
+ 'cols' => ''
+ ),
+ 'added_by' => array (
+ 'datatype' => 'VARCHAR',
+ 'formtype' => 'TEXT',
+ 'default' => $_SESSION['s']['user']['username'],
+ 'value' => '',
+ 'separator' => '',
+ 'width' => '30',
+ 'maxlength' => '255',
+ 'rows' => '',
+ 'cols' => ''
+ ),
//#################################
// END Datatable fields
//#################################
@@ -1080,6 +1102,34 @@
'rows' => '',
'cols' => ''
),
+ 'customer_no_template' => array (
+ 'datatype' => 'VARCHAR',
+ 'formtype' => 'TEXT',
+ 'validators' => array ( 0 => array ( 'type' => 'REGEX',
+ 'regex' => '/^[a-zA-Z0-0\-\_\[\]]{0,50}$/',
+ 'errmsg'=> 'customer_no_template_error_regex'),
+ ),
+ 'default' => '',
+ 'value' => '',
+ 'width' => '30',
+ 'maxlength' => '255'
+ ),
+ 'customer_no_start' => array (
+ 'datatype' => 'INTEGER',
+ 'formtype' => 'TEXT',
+ 'default' => '',
+ 'value' => '',
+ 'width' => '30',
+ 'maxlength' => '255'
+ ),
+ 'customer_no_counter' => array (
+ 'datatype' => 'INTEGER',
+ 'formtype' => 'TEXT',
+ 'default' => '',
+ 'value' => '',
+ 'width' => '30',
+ 'maxlength' => '255'
+ ),
//#################################
// END Datatable fields
//#################################
diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng
index 7c4ee26..ad268a7 100644
--- a/interface/web/client/lib/lang/en_client.lng
+++ b/interface/web/client/lib/lang/en_client.lng
@@ -152,4 +152,6 @@
$wb['gender_txt'] = 'Title';
$wb['gender_m_txt'] = 'Mr.';
$wb['gender_f_txt'] = 'Ms.';
+$wb['added_by_txt'] = 'Added by';
+$wb['added_date_txt'] = 'Added date';
?>
diff --git a/interface/web/client/lib/lang/en_reseller.lng b/interface/web/client/lib/lang/en_reseller.lng
index 4076dd5..e58d4e3 100644
--- a/interface/web/client/lib/lang/en_reseller.lng
+++ b/interface/web/client/lib/lang/en_reseller.lng
@@ -150,4 +150,10 @@
$wb['gender_m_txt'] = 'Mr.';
$wb['gender_f_txt'] = 'Ms.';
$wb['gender_txt'] = 'Title';
+$wb['customer_no_template_txt'] = 'Customer No. template';
+$wb['customer_no_template_error_regex_txt'] = 'The customer No. template contains invalid characters';
+$wb['customer_no_start_txt'] = 'Customer No. start value';
+$wb['customer_no_counter_txt'] = 'Customer No. counter';
+$wb['added_by_txt'] = 'Added by';
+$wb['added_date_txt'] = 'Added date';
?>
diff --git a/interface/web/client/reseller_edit.php b/interface/web/client/reseller_edit.php
index 6c67aee..20273b7 100644
--- a/interface/web/client/reseller_edit.php
+++ b/interface/web/client/reseller_edit.php
@@ -139,6 +139,25 @@
}
$app->tpl->setVar('template_additional_list', $text);
+
+ //* Set the 'customer no' default value
+ if($this->id == 0) {
+ //* get the system config
+ $app->uses('getconf');
+ $system_config = $app->getconf->get_global_config();
+ if($system_config['misc']['customer_no_template'] != '') {
+
+ //* Set customer no default
+ $customer_no = $app->functions->intval($system_config['misc']['customer_no_start']+$system_config['misc']['customer_no_counter']);
+ $customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$system_config['misc']['customer_no_template']);
+ $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);
+ }
+ }
parent::onShowEnd();
diff --git a/interface/web/client/templates/client_edit_address.htm b/interface/web/client/templates/client_edit_address.htm
index 018d1d5..8392820 100644
--- a/interface/web/client/templates/client_edit_address.htm
+++ b/interface/web/client/templates/client_edit_address.htm
@@ -136,6 +136,14 @@
<label for="paypal_email">{tmpl_var name='paypal_email_txt'}</label>
<input name="paypal_email" id="paypal_email" value="{tmpl_var name='paypal_email'}" size="30" maxlength="255" type="text" class="textInput" />
</div>
+ <div class="ctrlHolder">
+ <label for="added_date">{tmpl_var name='added_date_txt'}</label>
+ <input name="added_date" id="added_date" value="{tmpl_var name='added_date'}" size="10" maxlength="255" type="text" class="textInput" />
+ </div>
+ <div class="ctrlHolder">
+ <label for="added_by">{tmpl_var name='added_by_txt'}</label>
+ <input name="added_by" id="added_by" value="{tmpl_var name='added_by'}" size="10" maxlength="255" type="text" class="textInput" />
+ </div>
<div class="ctrlHolder">
<label for="notes">{tmpl_var name='notes_txt'}</label>
<textarea name="notes" id="notes" rows='10' cols='30'>{tmpl_var name='notes'}</textarea>
diff --git a/interface/web/client/templates/reseller_edit_address.htm b/interface/web/client/templates/reseller_edit_address.htm
index 4ffd78a..86acccd 100644
--- a/interface/web/client/templates/reseller_edit_address.htm
+++ b/interface/web/client/templates/reseller_edit_address.htm
@@ -136,6 +136,14 @@
<label for="paypal_email">{tmpl_var name='paypal_email_txt'}</label>
<input name="paypal_email" id="paypal_email" value="{tmpl_var name='paypal_email'}" size="30" maxlength="255" type="text" class="textInput" />
</div>
+ <div class="ctrlHolder">
+ <label for="added_date">{tmpl_var name='added_date_txt'}</label>
+ <input name="added_date" id="added_date" value="{tmpl_var name='added_date'}" size="10" maxlength="255" type="text" class="textInput" />
+ </div>
+ <div class="ctrlHolder">
+ <label for="added_by">{tmpl_var name='added_by_txt'}</label>
+ <input name="added_by" id="added_by" value="{tmpl_var name='added_by'}" size="10" maxlength="255" type="text" class="textInput" />
+ </div>
<div class="ctrlHolder">
<label for="notes">{tmpl_var name='notes_txt'}</label>
<textarea name="notes" id="notes" rows='10' cols='30'>{tmpl_var name='notes'}</textarea>
diff --git a/interface/web/client/templates/reseller_edit_limits.htm b/interface/web/client/templates/reseller_edit_limits.htm
index 6a93369..a115dc8 100644
--- a/interface/web/client/templates/reseller_edit_limits.htm
+++ b/interface/web/client/templates/reseller_edit_limits.htm
@@ -30,6 +30,18 @@
<label for="limit_client">{tmpl_var name='limit_client_txt'}</label>
<input name="limit_client" id="limit_client" value="{tmpl_var name='limit_client'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" />
</div>
+ <div class="ctrlHolder">
+ <label for="customer_no_template">{tmpl_var name='customer_no_template_txt'}</label>
+ <input name="customer_no_template" id="customer_no_template" value="{tmpl_var name='customer_no_template'}" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
+ </div>
+ <div class="ctrlHolder">
+ <label for="customer_no_start">{tmpl_var name='customer_no_start_txt'}</label>
+ <input name="customer_no_start" id="customer_no_start" value="{tmpl_var name='customer_no_start'}" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
+ </div>
+ <div class="ctrlHolder">
+ <label for="customer_no_counter">{tmpl_var name='customer_no_counter_txt'}</label>
+ <input name="customer_no_counter" id="customer_no_counter" value="{tmpl_var name='customer_no_counter'}" size="30" maxlength="255" type="text" class="textInput formLengthHalf" />
+ </div>
<div class="subsectiontoggle"><span class="showing"></span>{tmpl_var name='web_limits_txt'}<em class="showing"></em></div>
<div>
<div class="ctrlHolder">
diff --git a/interface/web/sites/form/web_domain.tform.php b/interface/web/sites/form/web_domain.tform.php
index 9907956..59ecba4 100644
--- a/interface/web/sites/form/web_domain.tform.php
+++ b/interface/web/sites/form/web_domain.tform.php
@@ -717,6 +717,28 @@
'width' => '30',
'maxlength' => '255'
),
+ 'added_date' => array (
+ 'datatype' => 'DATE',
+ 'formtype' => 'TEXT',
+ 'default' => date($app->lng('conf_format_dateshort')),
+ 'value' => '',
+ 'separator' => '',
+ 'width' => '15',
+ 'maxlength' => '15',
+ 'rows' => '',
+ 'cols' => ''
+ ),
+ 'added_by' => array (
+ 'datatype' => 'VARCHAR',
+ 'formtype' => 'TEXT',
+ 'default' => $_SESSION['s']['user']['username'],
+ 'value' => '',
+ 'separator' => '',
+ 'width' => '30',
+ 'maxlength' => '255',
+ 'rows' => '',
+ 'cols' => ''
+ ),
//#################################
// ENDE Datatable fields
//#################################
diff --git a/interface/web/sites/lib/lang/en_web_domain.lng b/interface/web/sites/lib/lang/en_web_domain.lng
index ad32a90..b35236c 100644
--- a/interface/web/sites/lib/lang/en_web_domain.lng
+++ b/interface/web/sites/lib/lang/en_web_domain.lng
@@ -121,4 +121,6 @@
$wb['allowed_rewrite_rule_directives_txt'] = 'Allowed Directives:';
$wb['configuration_error_txt'] = "CONFIGURATION ERROR";
$wb['variables_txt'] = 'Variables';
+$wb['added_by_txt'] = 'Added by';
+$wb['added_date_txt'] = 'Added date';
?>
\ No newline at end of file
diff --git a/interface/web/sites/templates/web_domain_advanced.htm b/interface/web/sites/templates/web_domain_advanced.htm
index 3cc7d2e..0afe57a 100644
--- a/interface/web/sites/templates/web_domain_advanced.htm
+++ b/interface/web/sites/templates/web_domain_advanced.htm
@@ -16,6 +16,14 @@
<fieldset class="inlineLabels">
<input name="document_root" id="document_root" value="{tmpl_var name='document_root'}" size="30" maxlength="255" type="hidden" class="textInput" />
<div class="ctrlHolder">
+ <label for="added_date">{tmpl_var name='added_date_txt'}</label>
+ <input name="added_date" id="added_date" value="{tmpl_var name='added_date'}" size="10" maxlength="255" type="text" class="textInput" />
+ </div>
+ <div class="ctrlHolder">
+ <label for="added_by">{tmpl_var name='added_by_txt'}</label>
+ <input name="added_by" id="added_by" value="{tmpl_var name='added_by'}" size="10" maxlength="255" type="text" class="textInput" />
+ </div>
+ <div class="ctrlHolder">
<label for="system_user">{tmpl_var name='system_user_txt'}</label>
<label for="system_user">{tmpl_var name='system_user'}</label>
<input name="system_user" id="system_user" value="{tmpl_var name='system_user'}" type="hidden" />
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index e1a8611..ccb356c 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -775,8 +775,10 @@
$php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir));
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
+ $added_date = date($app->lng('conf_format_dateshort'));
+ $added_by = $app->db->quote($_SESSION['s']['user']['username']);
- $sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id;
+ $sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir', added_date = '$added_date', added_by = '$added_by' WHERE domain_id = ".$this->id;
$app->db->query($sql);
}
--
Gitblit v1.9.1