diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php index e0a0da7..3b4cd4e 100644 --- a/cp/app/Controllers/SystemController.php +++ b/cp/app/Controllers/SystemController.php @@ -6,6 +6,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Container\ContainerInterface; use Respect\Validation\Validator as v; +use League\ISO3166\ISO3166; class SystemController extends Controller { @@ -142,8 +143,19 @@ class SystemController extends Controller 'name' => "rdap_server" ] ); + + $db->update( + 'settings', + [ + 'value' => $data['currency'] + ], + [ + 'name' => "currency" + ] + ); $db->commit(); + $_SESSION['_currency'] = $data['currency']; } catch (Exception $e) { $db->rollBack(); $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); @@ -154,7 +166,9 @@ class SystemController extends Controller return $response->withHeader('Location', '/registry')->withStatus(302); } - + + $iso3166 = new ISO3166(); + $countries = $iso3166->all(); $db = $this->container->get('db'); $company_name = $db->selectValue("SELECT value FROM settings WHERE name = 'company_name'"); $vat_number = $db->selectValue("SELECT value FROM settings WHERE name = 'vat_number'"); @@ -166,6 +180,17 @@ class SystemController extends Controller $launch_phases = $db->selectValue("SELECT value FROM settings WHERE name = 'launch_phases'"); $whois_server = $db->selectValue("SELECT value FROM settings WHERE name = 'whois_server'"); $rdap_server = $db->selectValue("SELECT value FROM settings WHERE name = 'rdap_server'"); + $currency = $db->selectValue("SELECT value FROM settings WHERE name = 'currency'"); + + $uniqueCurrencies = []; + foreach ($countries as $country) { + // Assuming each country has a 'currency' field with an array of currencies + foreach ($country['currency'] as $currencyCode) { + if (!array_key_exists($currencyCode, $uniqueCurrencies)) { + $uniqueCurrencies[$currencyCode] = $currencyCode; // Or any other currency detail you have + } + } + } return view($response,'admin/system/registry.twig', [ 'company_name' => $company_name, @@ -177,7 +202,9 @@ class SystemController extends Controller 'handle' => $handle, 'launch_phases' => $launch_phases, 'whois_server' => $whois_server, - 'rdap_server' => $rdap_server + 'rdap_server' => $rdap_server, + 'uniqueCurrencies' => $uniqueCurrencies, + 'currency' => $currency ]); } diff --git a/cp/bootstrap/app.php b/cp/bootstrap/app.php index b0196d8..a3bd605 100644 --- a/cp/bootstrap/app.php +++ b/cp/bootstrap/app.php @@ -131,22 +131,20 @@ $container->set('view', function ($container) { } $db = $container->get('db'); - $query = 'SELECT r.currency, ru.registrar_id + $user_data = 'SELECT ru.registrar_id FROM registrar_users ru JOIN registrar r ON ru.registrar_id = r.id WHERE ru.user_id = ?'; + $currency_data = "SELECT value FROM settings WHERE name = 'currency'"; if (isset($_SESSION['auth_user_id'])) { - $result = $db->select($query, [$_SESSION['auth_user_id']]); + $result = $db->select($user_data, [$_SESSION['auth_user_id']]); + $db_currency = $db->select($currency_data); - // Default values - $_SESSION['_currency'] = 'USD'; + $_SESSION['_currency'] = $db_currency[0]['value']; $_SESSION['auth_registrar_id'] = null; // Default registrar_id if ($result !== null && count($result) > 0) { - if (isset($result[0]['currency'])) { - $_SESSION['_currency'] = $result[0]['currency']; - } if (isset($result[0]['registrar_id'])) { $_SESSION['auth_registrar_id'] = $result[0]['registrar_id']; } diff --git a/cp/lang/en_US/messages.po b/cp/lang/en_US/messages.po index cc8aad1..044b58a 100644 --- a/cp/lang/en_US/messages.po +++ b/cp/lang/en_US/messages.po @@ -1339,3 +1339,8 @@ msgstr "TLDs" msgid "Support" msgstr "Support" +msgid "Registry Currency" +msgstr "Registry Currency" + +msgid "Choose the currency for all transactions. This impacts billing and financial reports. Inform stakeholders of changes." +msgstr "Choose the currency for all transactions. This impacts billing and financial reports. Inform stakeholders of changes." diff --git a/cp/lang/messages_template.po b/cp/lang/messages_template.po index 3edd579..8dd6a95 100644 --- a/cp/lang/messages_template.po +++ b/cp/lang/messages_template.po @@ -1339,3 +1339,8 @@ msgstr "" msgid "Support" msgstr "" +msgid "Registry Currency" +msgstr "" + +msgid "Choose the currency for all transactions. This impacts billing and financial reports. Inform stakeholders of changes." +msgstr "" diff --git a/cp/lang/uk_UA/messages.po b/cp/lang/uk_UA/messages.po index fe35b9f..4450f25 100644 --- a/cp/lang/uk_UA/messages.po +++ b/cp/lang/uk_UA/messages.po @@ -1339,3 +1339,8 @@ msgstr "TLDs" msgid "Support" msgstr "Підтримка" +msgid "Registry Currency" +msgstr "Валюта реєстру" + +msgid "Choose the currency for all transactions. This impacts billing and financial reports. Inform stakeholders of changes." +msgstr "Виберіть валюту для всіх операцій. Це впливає на рахунки та фінансові звіти. Інформувати зацікавлених сторін про зміни." diff --git a/cp/resources/views/admin/system/registry.twig b/cp/resources/views/admin/system/registry.twig index 0b2c67f..e224a57 100644 --- a/cp/resources/views/admin/system/registry.twig +++ b/cp/resources/views/admin/system/registry.twig @@ -38,7 +38,19 @@ {{ __('The official name of the organization operating the registry.') }} + +