Skip to content

Commit 3d96c53

Browse files
author
Till Brehm
committed
- 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
1 parent 3dbe806 commit 3d96c53

File tree

15 files changed

+217
-1
lines changed

15 files changed

+217
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE `client` ADD `customer_no_template` VARCHAR( 255 ) NULL DEFAULT 'C[CUSTOMER_NO]' AFTER `ssh_rsa` ,
2+
ADD `customer_no_start` INT NOT NULL DEFAULT '1' AFTER `customer_no_template` ,
3+
ADD `customer_no_counter` INT NOT NULL DEFAULT '0' AFTER `customer_no_start` ,
4+
ADD `added_date` DATE NOT NULL default '0000-00-00' AFTER `customer_no_counter` ,
5+
ADD `added_by` VARCHAR( 255 ) NULL AFTER `added_date` ;
6+
ALTER TABLE `web_domain` ADD `added_date` DATE NOT NULL default '0000-00-00' AFTER `rewrite_rules` ,
7+
ADD `added_by` VARCHAR( 255 ) NULL AFTER `added_date` ;
8+
ALTER TABLE `sys_session` ADD `permanent` ENUM('n','y') NOT NULL DEFAULT 'n' AFTER `last_updated`;

install/sql/ispconfig3.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ CREATE TABLE `client` (
232232
`tmp_data` mediumblob,
233233
`id_rsa` varchar(2000) NOT NULL DEFAULT '',
234234
`ssh_rsa` varchar(600) NOT NULL DEFAULT '',
235+
`customer_no_template` varchar(255) DEFAULT 'C[CUSTOMER_NO]',
236+
`customer_no_start` int(11) NOT NULL DEFAULT '1',
237+
`customer_no_counter` int(11) NOT NULL DEFAULT '0',
238+
`added_date` date NOT NULL DEFAULT '0000-00-00',
239+
`added_by` varchar(255) DEFAULT NULL,
235240
PRIMARY KEY (`client_id`)
236241
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
237242

@@ -1796,6 +1801,8 @@ CREATE TABLE `web_domain` (
17961801
`proxy_directives` mediumtext,
17971802
`last_quota_notification` date NULL default NULL,
17981803
`rewrite_rules` mediumtext,
1804+
`added_date` date NOT NULL DEFAULT '0000-00-00',
1805+
`added_by` varchar(255) DEFAULT NULL,
17991806
PRIMARY KEY (`domain_id`)
18001807
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
18011808

interface/web/client/client_edit.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,46 @@ function onShowEnd() {
171171

172172
$app->tpl->setVar('template_additional_list', $text);
173173
$app->tpl->setVar('app_module', 'client');
174+
175+
//* Set the 'customer no' default value
176+
if($this->id == 0) {
177+
178+
if($app->auth->is_admin()) {
179+
//* Logged in User is admin
180+
//* get the system config
181+
$app->uses('getconf');
182+
$system_config = $app->getconf->get_global_config();
183+
if($system_config['misc']['customer_no_template'] != '') {
184+
185+
//* Set customer no default
186+
$customer_no = $app->functions->intval($system_config['misc']['customer_no_start']+$system_config['misc']['customer_no_counter']);
187+
$customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$system_config['misc']['customer_no_template']);
188+
$app->tpl->setVar('customer_no',$customer_no_string);
189+
190+
//* save new counter value
191+
$system_config['misc']['customer_no_counter']++;
192+
$system_config_str = $app->ini_parser->get_ini_string($system_config);
193+
$app->db->datalogUpdate('sys_ini', "config = '".$app->db->quote($system_config_str)."'", 'sysini_id', 1);
194+
}
195+
} else {
196+
//* Logged in user must be a reseller
197+
//* get the record of the reseller
198+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
199+
$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);
200+
201+
if($reseller['customer_no_template'] != '') {
202+
//* Set customer no default
203+
$customer_no = $app->functions->intval($reseller['customer_no_start']+$reseller['customer_no_counter']);
204+
$customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$reseller['customer_no_template']);
205+
$app->tpl->setVar('customer_no',$customer_no_string);
206+
207+
//* save new counter value
208+
$customer_no_counter = $app->functions->intval($reseller['customer_no_counter']+1);
209+
$app->db->query("UPDATE client SET customer_no_counter = $customer_no_counter WHERE client_id = ".$app->functions->intval($reseller['client_id']));
210+
echo "UPDATE client SET customer_no_counter = $customer_no_counter WHERE client_id = ".$app->functions->intval($reseller['client_id']);
211+
}
212+
}
213+
}
174214

175215
parent::onShowEnd();
176216

interface/web/client/form/client.tform.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,28 @@
472472
'default' => 'n',
473473
'value' => array(0 => 'n', 1 => 'y')
474474
),
475+
'added_date' => array (
476+
'datatype' => 'DATE',
477+
'formtype' => 'TEXT',
478+
'default' => date($app->lng('conf_format_dateshort')),
479+
'value' => '',
480+
'separator' => '',
481+
'width' => '15',
482+
'maxlength' => '15',
483+
'rows' => '',
484+
'cols' => ''
485+
),
486+
'added_by' => array (
487+
'datatype' => 'VARCHAR',
488+
'formtype' => 'TEXT',
489+
'default' => $_SESSION['s']['user']['username'],
490+
'value' => '',
491+
'separator' => '',
492+
'width' => '30',
493+
'maxlength' => '255',
494+
'rows' => '',
495+
'cols' => ''
496+
),
475497
//#################################
476498
// END Datatable fields
477499
//#################################

interface/web/client/form/reseller.tform.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,28 @@
469469
'default' => 'n',
470470
'value' => array(0 => 'n', 1 => 'y')
471471
),
472+
'added_date' => array (
473+
'datatype' => 'DATE',
474+
'formtype' => 'TEXT',
475+
'default' => date($app->lng('conf_format_dateshort')),
476+
'value' => '',
477+
'separator' => '',
478+
'width' => '15',
479+
'maxlength' => '15',
480+
'rows' => '',
481+
'cols' => ''
482+
),
483+
'added_by' => array (
484+
'datatype' => 'VARCHAR',
485+
'formtype' => 'TEXT',
486+
'default' => $_SESSION['s']['user']['username'],
487+
'value' => '',
488+
'separator' => '',
489+
'width' => '30',
490+
'maxlength' => '255',
491+
'rows' => '',
492+
'cols' => ''
493+
),
472494
//#################################
473495
// END Datatable fields
474496
//#################################
@@ -1080,6 +1102,34 @@
10801102
'rows' => '',
10811103
'cols' => ''
10821104
),
1105+
'customer_no_template' => array (
1106+
'datatype' => 'VARCHAR',
1107+
'formtype' => 'TEXT',
1108+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
1109+
'regex' => '/^[a-zA-Z0-0\-\_\[\]]{0,50}$/',
1110+
'errmsg'=> 'customer_no_template_error_regex'),
1111+
),
1112+
'default' => '',
1113+
'value' => '',
1114+
'width' => '30',
1115+
'maxlength' => '255'
1116+
),
1117+
'customer_no_start' => array (
1118+
'datatype' => 'INTEGER',
1119+
'formtype' => 'TEXT',
1120+
'default' => '',
1121+
'value' => '',
1122+
'width' => '30',
1123+
'maxlength' => '255'
1124+
),
1125+
'customer_no_counter' => array (
1126+
'datatype' => 'INTEGER',
1127+
'formtype' => 'TEXT',
1128+
'default' => '',
1129+
'value' => '',
1130+
'width' => '30',
1131+
'maxlength' => '255'
1132+
),
10831133
//#################################
10841134
// END Datatable fields
10851135
//#################################

interface/web/client/lib/lang/en_client.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ $wb['canceled_txt'] = 'Canceled (disables client login)';
152152
$wb['gender_txt'] = 'Title';
153153
$wb['gender_m_txt'] = 'Mr.';
154154
$wb['gender_f_txt'] = 'Ms.';
155+
$wb['added_by_txt'] = 'Added by';
156+
$wb['added_date_txt'] = 'Added date';
155157
?>

interface/web/client/lib/lang/en_reseller.lng

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,10 @@ $wb['canceled_txt'] = 'Canceled';
150150
$wb['gender_m_txt'] = 'Mr.';
151151
$wb['gender_f_txt'] = 'Ms.';
152152
$wb['gender_txt'] = 'Title';
153+
$wb['customer_no_template_txt'] = 'Customer No. template';
154+
$wb['customer_no_template_error_regex_txt'] = 'The customer No. template contains invalid characters';
155+
$wb['customer_no_start_txt'] = 'Customer No. start value';
156+
$wb['customer_no_counter_txt'] = 'Customer No. counter';
157+
$wb['added_by_txt'] = 'Added by';
158+
$wb['added_date_txt'] = 'Added date';
153159
?>

interface/web/client/reseller_edit.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ function onShowEnd() {
139139
}
140140

141141
$app->tpl->setVar('template_additional_list', $text);
142+
143+
//* Set the 'customer no' default value
144+
if($this->id == 0) {
145+
//* get the system config
146+
$app->uses('getconf');
147+
$system_config = $app->getconf->get_global_config();
148+
if($system_config['misc']['customer_no_template'] != '') {
149+
150+
//* Set customer no default
151+
$customer_no = $app->functions->intval($system_config['misc']['customer_no_start']+$system_config['misc']['customer_no_counter']);
152+
$customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$system_config['misc']['customer_no_template']);
153+
$app->tpl->setVar('customer_no',$customer_no_string);
154+
155+
//* save new counter value
156+
$system_config['misc']['customer_no_counter']++;
157+
$system_config_str = $app->ini_parser->get_ini_string($system_config);
158+
$app->db->datalogUpdate('sys_ini', "config = '".$app->db->quote($system_config_str)."'", 'sysini_id', 1);
159+
}
160+
}
142161

143162
parent::onShowEnd();
144163

interface/web/client/templates/client_edit_address.htm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
135135
<div class="ctrlHolder">
136136
<label for="paypal_email">{tmpl_var name='paypal_email_txt'}</label>
137137
<input name="paypal_email" id="paypal_email" value="{tmpl_var name='paypal_email'}" size="30" maxlength="255" type="text" class="textInput" />
138+
</div>
139+
<div class="ctrlHolder">
140+
<label for="added_date">{tmpl_var name='added_date_txt'}</label>
141+
<input name="added_date" id="added_date" value="{tmpl_var name='added_date'}" size="10" maxlength="255" type="text" class="textInput" />
142+
</div>
143+
<div class="ctrlHolder">
144+
<label for="added_by">{tmpl_var name='added_by_txt'}</label>
145+
<input name="added_by" id="added_by" value="{tmpl_var name='added_by'}" size="10" maxlength="255" type="text" class="textInput" />
138146
</div>
139147
<div class="ctrlHolder">
140148
<label for="notes">{tmpl_var name='notes_txt'}</label>

interface/web/client/templates/reseller_edit_address.htm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
135135
<div class="ctrlHolder">
136136
<label for="paypal_email">{tmpl_var name='paypal_email_txt'}</label>
137137
<input name="paypal_email" id="paypal_email" value="{tmpl_var name='paypal_email'}" size="30" maxlength="255" type="text" class="textInput" />
138+
</div>
139+
<div class="ctrlHolder">
140+
<label for="added_date">{tmpl_var name='added_date_txt'}</label>
141+
<input name="added_date" id="added_date" value="{tmpl_var name='added_date'}" size="10" maxlength="255" type="text" class="textInput" />
142+
</div>
143+
<div class="ctrlHolder">
144+
<label for="added_by">{tmpl_var name='added_by_txt'}</label>
145+
<input name="added_by" id="added_by" value="{tmpl_var name='added_by'}" size="10" maxlength="255" type="text" class="textInput" />
138146
</div>
139147
<div class="ctrlHolder">
140148
<label for="notes">{tmpl_var name='notes_txt'}</label>

0 commit comments

Comments
 (0)