Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lang/overrides/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@

$_LANG['itIdentificationCompany'] = 'Company Registration Number';
$_LANG['itIdentificationSocialSecurityNumber'] = 'Individual Codice Fiscale';
$_LANG['itIdentificationCORI'] = 'Company or Individual Codice Fiscale';

$_LANG['seIdentificationCompany'] = 'Legal Entity';
$_LANG['seIdentificationSocialSecurityNumber'] = 'Private individual';
$_LANG['seIdentificationCORI'] = 'Company or Individual ID';

$_LANG['fiIdentificationCompany'] = 'Company Registration Number';
$_LANG['fiIdentificationPassport'] = 'Passport/ID number for Individuals';
$_LANG['fiIdentificationSocialSecurityNumber'] = 'Social Security Number for Individuals';
$_LANG['fiIdentificationBirthDate'] = 'Birthday for Foreign Private Individuals (YYYY-MM-DD)';
$_LANG['fiIdentificationCORI'] = 'Company or Individual ID';
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
use OpenProvider\WhmcsRegistrar\enums\DatabaseTable;
use OpenProvider\WhmcsRegistrar\src\Configuration;
use OpenProvider\WhmcsRegistrar\helpers\DB;
use OpenProvider\WhmcsRegistrar\helpers\DomainFullNameToDomainObject;
use WHMCS\Database\Capsule;

class ClientAreaFooterController
{
private const ID_NUMBER_REQUIRED_TLDS = [
'es',
'pt',
'se',
'com.es',
'nom.es',
'edu.es',
'org.es',
'it',
'fi',
];

private const ES_SECOND_LEVEL_TLDS = [
'com.es',
'nom.es',
'edu.es',
'org.es',
];

public function output($vars)
{
GLOBAL $_LANG;
Expand All @@ -18,10 +36,11 @@ public function output($vars)

if ($idnumbermod) {

$template = $vars['templatefile'];
$template = $vars['templatefile'] ?? '';
$js = '';
$check_tempaltes = array('account-contacts-manage', 'account-contacts-new');
unset($_SESSION['msg']);
if (in_array($template, $check_tempaltes)) {
if (in_array($template, $check_tempaltes, true)) {
$contactid = $vars['contactid'];

if ($_SESSION['Contact_Pending_Update']) {
Expand All @@ -43,6 +62,12 @@ public function output($vars)
$number = $idn->identification_number;
}

$escapedNumber = htmlspecialchars(
(string) ($number ?? ''),
ENT_QUOTES,
'UTF-8'
);

$typePassport = $type == 'passportNumber';
$typeCompanyRegistrationNumber = $type == 'companyRegistrationNumber';
$typeVat = $type == 'vat';
Expand All @@ -55,17 +80,37 @@ public function output($vars)


if ($passport || $typeCompanyRegistrationNumber) {
$js = "$('.main-content form .row .col-xs-12').each(function(index , element){ $(this).attr('data-number' , 'contactsRightDiv_'+index); }); $('.main-content form .row .col-sm-6:not(.pull-right)').each(function(index , element){ $(this).attr('data-number' , 'contactsDiv_'+index); }); $('*[data-number=\'contactsRightDiv_0\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['esIdentificationNumber'] . "</label><input required type=\'text\' name=\'cord\' id=\'cord\' class=\'form-control\' value=\'" . $number . "\'></div>'); $('*[data-number=\'contactsDiv_1\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['esIdentificationType'] . "</label><select id=\'id_type\' required name=\'id_type\' class=\'form-control\'><option value=\'\'>Select ID Type</option>" . $passport . $company . "</select></div>');";
$js = "$('.main-content form .row .col-xs-12').each(function(index , element){ $(this).attr('data-number' , 'contactsRightDiv_'+index); }); $('.main-content form .row .col-sm-6:not(.pull-right)').each(function(index , element){ $(this).attr('data-number' , 'contactsDiv_'+index); }); $('*[data-number=\'contactsRightDiv_0\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['esIdentificationNumber'] . "</label><input type=\'text\' name=\'cord\' id=\'cord\' class=\'form-control\' value=\'" . $escapedNumber . "\'></div>'); $('*[data-number=\'contactsDiv_1\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['esIdentificationType'] . "</label><select id=\'id_type\' name=\'id_type\' class=\'form-control\'><option value=\'\'>Select ID Type</option>" . $passport . $company . "</select></div>');";
} else if ($vat || $socialSecurityNumber) {
$js = "$('.main-content form .row .col-xs-12').each(function(index , element){ $(this).attr('data-number' , 'contactsRightDiv_'+index); }); $('.main-content form .row .col-sm-6:not(.pull-right)').each(function(index , element){ $(this).attr('data-number' , 'contactsDiv_'+index); }); $('*[data-number=\'contactsRightDiv_0\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['ptIdentificationNumber'] . "</label><input required type=\'text\' name=\'cord\' id=\'cord\' class=\'form-control\' value=\'" . $number . "\'></div>'); $('*[data-number=\'contactsDiv_1\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['ptIdentificationType'] . "</label><select id=\'id_type\' required name=\'id_type\' class=\'form-control\'><option value=\'\'>Select ID Type</option>" . $passport . $company . "</select></div>');";
$js = "$('.main-content form .row .col-xs-12').each(function(index , element){ $(this).attr('data-number' , 'contactsRightDiv_'+index); }); $('.main-content form .row .col-sm-6:not(.pull-right)').each(function(index , element){ $(this).attr('data-number' , 'contactsDiv_'+index); }); $('*[data-number=\'contactsRightDiv_0\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['ptIdentificationNumber'] . "</label><input type=\'text\' name=\'cord\' id=\'cord\' class=\'form-control\' value=\'" . $escapedNumber . "\'></div>'); $('*[data-number=\'contactsDiv_1\']').append('<div class=\'form-group\'><label for=\'inputTaxId\' class=\'control-label\'>" . $_LANG['ptIdentificationType'] . "</label><select id=\'id_type\' name=\'id_type\' class=\'form-control\'><option value=\'\'>Select ID Type</option>" . $vat . $socialSecurityNumber . "</select></div>');";
}
}

if ($template == 'clientareadomaincontactinfo') {
$domain = DomainFullNameToDomainObject::convert($vars['domain']);
$idNumberName = $_LANG[sprintf('%s%s', $domain->extension ?? 'es', 'IdentificationCORI')];
$js = '$("#frmDomainContactModification").submit(function(e){ e.preventDefault(); setSessionContact(); $(this).unbind("submit").submit(); }); $("input[name=\"contactdetails[Owner][Company or Individual Id]\"]").attr("required" , true); $("input[name=\"contactdetails[Admin][Company or Individual Id]\"]").attr("required" , true); $("input[name=\"contactdetails[Tech][Company or Individual Id]\"]").attr("required" , true); $("input[name=\"contactdetails[Billing][Company or Individual Id]\"]").attr("required" , true); $("label:contains(\"Company or Individual Id\")").html("' . $idNumberName . '");';
$js .= '$("#frmDomainContactModification").submit(function(e){ e.preventDefault(); setSessionContact(); $(this).unbind("submit").submit(); }); $("input[name=\"contactdetails[Owner][Vat or Tax ID]\"]").attr("required" , true); $("input[name=\"contactdetails[Admin][Vat or Tax ID]\"]").attr("required" , true); $("input[name=\"contactdetails[Tech][Vat or Tax ID]\"]").attr("required" , true); $("input[name=\"contactdetails[Billing][Vat or Tax ID]\"]").attr("required" , true); $("label:contains(\"Vat or Tax ID\")").html("' . $idNumberName . '");';
if ($template === 'clientareadomaincontactinfo') {
$domainName = $vars['domain'] ?? '';
$tld = $this->getFullTld($domainName);

if (!$this->isIdNumberRequiredTld($tld)) {
$js = '$("input[name^=\"contactdetails\"][name$=\"[Company or Individual Id]\"]").closest(".form-group").remove();';
$js .= '$("input[name^=\"contactdetails\"][name$=\"[Vat or Tax ID]\"]").closest(".form-group").remove();';
} else {
$langKey = $this->getIdNumberLangKey($tld);

$idNumberName = $_LANG[$langKey] ?? 'Company or Individual ID';
$idNumberNameJs = json_encode($idNumberName, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);

$js = '$("#frmDomainContactModification").submit(function(e){
e.preventDefault();
setSessionContact();
$(this).unbind("submit").submit();
});';
Comment thread
YumeChaan marked this conversation as resolved.

$js .= '$("input[name^=\"contactdetails\"][name$=\"[Company or Individual Id]\"]").attr("required", true);';
$js .= '$("input[name^=\"contactdetails\"][name$=\"[Vat or Tax ID]\"]").attr("required", true);';

$js .= '$("label:contains(\"Company or Individual Id\")").text(' . $idNumberNameJs . ');';
$js .= '$("label:contains(\"Vat or Tax ID\")").text(' . $idNumberNameJs . ');';
}
}

$systemurl = $vars['systemurl'];
Expand Down Expand Up @@ -122,5 +167,47 @@ function setSessionContact(){
</script>
HTML;
}
return '';
}


private function isIdNumberRequiredTld(string $tld): bool
{
return in_array(strtolower($tld), self::ID_NUMBER_REQUIRED_TLDS, true);
}

private function getFullTld(string $domainName): string
{
$domainName = strtolower($domainName);

foreach (self::ES_SECOND_LEVEL_TLDS as $multiTld) {
if (str_ends_with($domainName, '.' . $multiTld)) {
return $multiTld;
}
}
Comment thread
YumeChaan marked this conversation as resolved.

$labels = array_values(
array_filter(
explode('.', $domainName),
static function ($label) {
return $label !== '';
}
)
);

if (empty($labels)) {
return '';
}

return (string) end($labels);
}

private function getIdNumberLangKey(string $tld): string
{
if (in_array($tld, self::ES_SECOND_LEVEL_TLDS, true)) {
return 'esIdentificationCORI';
}

return $tld . 'IdentificationCORI';
}
}