Skip to content

Commit 23cef7e

Browse files
committed
Implement locked locale field in domain contact details and locale assignment ordering improvements
1 parent f59a7f7 commit 23cef7e

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

modules/registrars/openprovider/Controllers/Hooks/AdminAreaFooterController.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace OpenProvider\WhmcsRegistrar\Controllers\Hooks;
44

5+
use WHMCS\Database\Capsule;
6+
57
/**
68
* Class AdminAreaFooterController
79
* OpenProvider Registrar module
@@ -20,6 +22,57 @@ public function __construct()
2022
{
2123
}
2224

25+
public function makeLocaleReadonly(array $vars): string
26+
{
27+
if (($vars['filename'] ?? '') !== 'clientsdomaincontacts') {
28+
return '';
29+
}
30+
31+
$domainId = (int) ($_GET['domainid'] ?? $_REQUEST['domainid'] ?? 0);
32+
if (!$domainId) {
33+
return '';
34+
}
35+
36+
$registrar = Capsule::table('tbldomains')
37+
->where('id', $domainId)
38+
->value('registrar');
39+
40+
if ($registrar !== 'openprovider') {
41+
return '';
42+
}
43+
44+
return <<<'HTML'
45+
<script>
46+
(function () {
47+
function lockLocaleFields() {
48+
var inputs = document.querySelectorAll('input[name*="[locale]"]');
49+
if (!inputs.length) return false;
50+
51+
inputs.forEach(function (input) {
52+
input.setAttribute('readonly', 'readonly');
53+
input.style.backgroundColor = '#f5f5f5';
54+
input.style.cursor = 'not-allowed';
55+
input.title = 'Locale is managed automatically and cannot be edited directly.';
56+
});
57+
return true;
58+
}
59+
60+
jQuery(function () {
61+
if (lockLocaleFields()) return;
62+
63+
var attempts = 0;
64+
var timer = setInterval(function () {
65+
attempts++;
66+
if (lockLocaleFields() || attempts > 20) {
67+
clearInterval(timer);
68+
}
69+
}, 150);
70+
});
71+
}());
72+
</script>
73+
HTML;
74+
}
75+
2376
public function output($vars)
2477
{
2578
// Only on the Admin -> Domain Information page

modules/registrars/openprovider/OpenProvider/API/Customer.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function __construct($params, $prefix = '')
101101
$prefix = 'owner';
102102

103103
$getFromContactDetails = false;
104+
$topLevelLanguage = $params['language'] ?? null;
104105
if (isset($params['contactdetails']))
105106
{
106107
$getFromContactDetails = true;
@@ -232,10 +233,16 @@ public function __construct($params, $prefix = '')
232233
$this->companyName = $params[$indexes['companyname']];
233234
$this->tags = $tags->getTags();
234235
$language = $params[$indexes['language']] ?? null;
235-
if ($language) {
236+
$locale = !empty($params[$indexes['locale']] ?? null)
237+
? trim(str_replace('-', '_', (string) $params[$indexes['locale']]))
238+
: null;
239+
240+
if ($locale) {
241+
$this->locale = $locale;
242+
} elseif ($language) {
236243
$this->locale = $this->getLocaleByLanguage($language);
237-
} elseif (isset($indexes['locale']) && !empty($params[$indexes['locale']])) {
238-
$this->locale = $params[$indexes['locale']];
244+
} elseif ($topLevelLanguage) {
245+
$this->locale = $this->getLocaleByLanguage($topLevelLanguage);
239246
} else {
240247
$this->locale = $this->getLocaleByLanguage(null);
241248
}

modules/registrars/openprovider/routes/hooks.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
'priority' => 1,
153153
'controller' => 'AdminAreaFooterController@output',
154154
],
155+
[
156+
'hookPoint' => 'AdminAreaFooterOutput',
157+
'priority' => 2,
158+
'controller' => 'AdminAreaFooterController@makeLocaleReadonly',
159+
],
155160
[
156161
'hookPoint' => 'AdminClientDomainsTabFieldsSave',
157162
'priority' => 1,

0 commit comments

Comments
 (0)