Add New Prefix Type CUSTOMERNO
[This is a feature request but even with following the link 'http://bugtracker.ispconfig.org/index.php?do=newtask&project=3&task_type=2' I am not able to get a non-issue ticke inserted here - sorry]
I know / assume I could remove the prefixes in whole by modifying the FTP user prefix (eg) in the Main Config. But I am a fan of automatisms, as they reduce faulty input.
For this I would like to suggest - in addition to existing 'CLIENTNAME', 'CLIENTID', 'DOMAINID' - a new prefix key 'CUSTOMERNO', which replaces the keyword [CUSTOMERNO] by the customer number of the current selected (or user assigned) client.
Following changes work for me, but I would really prefer if this could be adjusted to fit into ISPConfig development best practices:
[modifiying /interface/lib/classes/tools_sites.inc.php]
[line 37]
old:
$keywordlist=array('CLIENTNAME', 'CLIENTID', 'DOMAINID');
new:
$keywordlist=array('CLIENTNAME', 'CLIENTID', 'DOMAINID', 'CUSTOMERNO');
[line 40 foreach added case]
case 'CUSTOMERNO':
$name=str_replace('['.$keyword.']', $this->getCustomerNo($dataRecord), $name);
break;
[new]
function getCustomerNo($dataRecord) {
global $app, $conf;
$clientId=$this->getClientID($dataRecord);
if ($clientId == '[CLIENTID]') {
return '[CUSTOMERNO]';
} elseif ($clientId == '') {
return 'default';
}
$tmp = $app->db->queryOneRecord("SELECT customer_no FROM client WHERE client_id = ?", $clientId);
$customerNo = $tmp['customer_no'];
if ($customerNo == '') $customerNo = 'default';
$customerNo = $this->convertCustomerNo($customerNo);
return $customerNo;
}
[new - duplicated from function convertClientName for further flexibility, not necessarily needed to be a separate function]
function convertCustomerNo($customerNo){
$allowed = 'abcdefghijklmnopqrstuvwxyz0123456789_';
$res = '';
$customerNo = strtolower(trim($customerNo));
for ($i=0; $i < strlen($customerNo); $i++){
if ($customerNo[$i] == ' ') continue;
if (strpos($allowed, $customerNo[$i]) !== false){
$res .= $customerNo[$i];
}
else {
$res .= '_';
}
}
return $res;
}