diff --git a/cp/app/Controllers/ContactsController.php b/cp/app/Controllers/ContactsController.php index 20d2344..1e67c05 100644 --- a/cp/app/Controllers/ContactsController.php +++ b/cp/app/Controllers/ContactsController.php @@ -59,7 +59,7 @@ class ContactsController extends Controller $voice = $data['voice'] ?? null; $fax = $data['fax'] ?? null; - $email = $data['email'] ?? null; + $email = strtolower($data['email']) ?? null; $authInfo_pw = $data['authInfo'] ?? null; if (!$contactID) { @@ -207,15 +207,22 @@ class ContactsController extends Controller } } - - if ($voice && (!preg_match('/^\+\d{1,3}\.\d{1,14}$/', $voice) || strlen($voice) > 17)) { - $this->container->get('flash')->addMessage('error', 'Unable to create contact: Voice must be (\+[0-9]{1,3}\.[0-9]{1,14})'); + + $normalizedVoice = normalizePhoneNumber($voice, strtoupper($postalInfoIntCc)); + if (isset($normalizedVoice['error'])) { + $this->container->get('flash')->addMessage('error', 'Unable to create contact: ' . $normalizedVoice['error']); return $response->withHeader('Location', '/contact/create')->withStatus(302); } + $voice = $normalizedVoice['success']; - if ($fax && (!preg_match('/^\+\d{1,3}\.\d{1,14}$/', $fax) || strlen($fax) > 17)) { - $this->container->get('flash')->addMessage('error', 'Unable to create contact: Fax must be (\+[0-9]{1,3}\.[0-9]{1,14})'); - return $response->withHeader('Location', '/contact/create')->withStatus(302); + if (!empty($fax)) { + $normalizedFax = normalizePhoneNumber($fax, strtoupper($postalInfoIntCc)); + if (isset($normalizedFax['error'])) { + $this->container->get('flash')->addMessage('error', 'Unable to create contact: ' . $normalizedFax['error']); + return $response->withHeader('Location', '/contact/create')->withStatus(302); + } + // Update the fax number only if normalization was successful. + $fax = $normalizedFax['success']; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { @@ -395,6 +402,8 @@ class ContactsController extends Controller if ($contact) { $registrars = $db->selectRow('SELECT id, clid, name FROM registrar WHERE id = ?', [$contact['clid']]); + $iso3166 = new ISO3166(); + $countries = $iso3166->all(); // Check if the user is not an admin (assuming role 0 is admin) if ($_SESSION["auth_roles"] != 0) { @@ -426,7 +435,8 @@ class ContactsController extends Controller 'contactAuth' => $contactAuth, 'contactPostal' => $contactPostal, 'registrars' => $registrars, - 'currentUri' => $uri + 'currentUri' => $uri, + 'countries' => $countries ]; $verifyPhone = $db->selectValue("SELECT value FROM settings WHERE name = 'verifyPhone'"); diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index 010f77a..8539031 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -14,6 +14,9 @@ use MatthiasMullie\Scrapbook\Psr6\Pool; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Guid\Guid; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use libphonenumber\PhoneNumberUtil; +use libphonenumber\PhoneNumberFormat; +use libphonenumber\NumberParseException; /** * @return mixed|string|string[] @@ -435,4 +438,43 @@ function get_client_location() { $country = $json['country']; return $country; +} + +function normalizePhoneNumber($number, $defaultRegion = 'US') { + $phoneUtil = PhoneNumberUtil::getInstance(); + + // Strip only empty spaces and dashes from the number. + $number = str_replace([' ', '-'], '', $number); + + // Prepend '00' if the number does not start with '+' or '0'. + if (strpos($number, '+') !== 0 && strpos($number, '0') !== 0) { + $number = '00' . $number; + } + + // Convert a leading '+' to '00' for international format compatibility. + if (strpos($number, '+') === 0) { + $number = '00' . substr($number, 1); + } + + // Now, clean the number to ensure it consists only of digits. + $cleanNumber = preg_replace('/\D/', '', $number); + + try { + // Parse the clean, digit-only string, which may start with '00' for international format. + $numberProto = $phoneUtil->parse($cleanNumber, $defaultRegion); + + // Format the number to E.164 to ensure it includes the correct country code. + $formattedNumberE164 = $phoneUtil->format($numberProto, PhoneNumberFormat::E164); + + // Extract the country code and national number. + $countryCode = $numberProto->getCountryCode(); + $nationalNumber = $numberProto->getNationalNumber(); + + // Reconstruct the number in the desired EPP format: +CountryCode.NationalNumber + $formattedNumber = '+' . $countryCode . '.' . $nationalNumber; + return ['success' => $formattedNumber]; + + } catch (NumberParseException $e) { + return ['error' => 'Failed to parse and normalize phone number: ' . $e->getMessage()]; + } } \ No newline at end of file diff --git a/cp/resources/views/admin/contacts/createContact.twig b/cp/resources/views/admin/contacts/createContact.twig index 1996bd3..2c532d1 100644 --- a/cp/resources/views/admin/contacts/createContact.twig +++ b/cp/resources/views/admin/contacts/createContact.twig @@ -57,8 +57,8 @@
- - + +
diff --git a/cp/resources/views/admin/contacts/viewContact.twig b/cp/resources/views/admin/contacts/viewContact.twig index 74add3b..3d0baf3 100644 --- a/cp/resources/views/admin/contacts/viewContact.twig +++ b/cp/resources/views/admin/contacts/viewContact.twig @@ -53,7 +53,7 @@
{{ __('Fax') }}
-
{{ contact.fax|default('N/A') }}
+
{{ contact.fax|default('N/A') }} {% if contact.disclose_fax == '1' %}{{ __('Visible in Public') }}{% else %}{{ __('Hidden from Public') }}{% endif %}
{{ __('NIN') }}
@@ -160,7 +160,13 @@
{{ __('Country') }}
-
{{ postal.cc }} {% if postal.disclose_addr_int == '1' %} +
+ {% for country in countries %} + {% if postal.cc|lower == country.alpha2|lower %} + {{ country.name }} + {% endif %} + {% endfor %} + {% if postal.disclose_addr_int == '1' %} {{ __('Visible in Public') }} {% else %} {{ __('Hidden from Public') }} @@ -237,7 +243,13 @@
{{ __('Country') }}
-
{{ postal.cc }} {% if postal.disclose_addr_loc == '1' %} +
+ {% for country in countries %} + {% if postal.cc|lower == country.alpha2|lower %} + {{ country.name }} + {% endif %} + {% endfor %} + {% if postal.disclose_addr_loc == '1' %} {{ __('Visible in Public') }} {% else %} {{ __('Hidden from Public') }}