Skip to content

Commit

Permalink
Fixed #64
Browse files Browse the repository at this point in the history
  • Loading branch information
getpinga committed Jan 12, 2024
1 parent 66ae0e2 commit fd0909f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 19 deletions.
31 changes: 29 additions & 2 deletions cp/app/Controllers/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
{
Expand Down Expand Up @@ -142,8 +143,19 @@ public function registry(Request $request, Response $response)
'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());
Expand All @@ -154,7 +166,9 @@ public function registry(Request $request, Response $response)
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'");
Expand All @@ -166,6 +180,17 @@ public function registry(Request $request, Response $response)
$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,
Expand All @@ -177,7 +202,9 @@ public function registry(Request $request, Response $response)
'handle' => $handle,
'launch_phases' => $launch_phases,
'whois_server' => $whois_server,
'rdap_server' => $rdap_server
'rdap_server' => $rdap_server,
'uniqueCurrencies' => $uniqueCurrencies,
'currency' => $currency
]);
}

Expand Down
12 changes: 5 additions & 7 deletions cp/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,20 @@
}

$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'];
}
Expand Down
5 changes: 5 additions & 0 deletions cp/lang/en_US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
5 changes: 5 additions & 0 deletions cp/lang/messages_template.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
5 changes: 5 additions & 0 deletions cp/lang/uk_UA/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Виберіть валюту для всіх операцій. Це впливає на рахунки та фінансові звіти. Інформувати зацікавлених сторін про зміни."
26 changes: 18 additions & 8 deletions cp/resources/views/admin/system/registry.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,33 @@
<input type="text" class="form-control" id="registryOperator" name="registryOperator" placeholder="{{ __('Enter registry operator\'s name') }}" value="{{ company_name }}" required>
<small class="form-hint">{{ __('The official name of the organization operating the registry.') }}</small>
</div>

<div class="mb-3">
<label for="registryHandle" class="form-label required">{{ __('Registry Handle') }}</label>
<input type="text" class="form-control" id="registryHandle" name="registryHandle" placeholder="{{ __('Enter registry handle') }}" value="{{ handle }}" required>
<small class="form-hint">{{ __('A unique identifier for the registry which will be appended to each object handle.') }}</small>
<label for="rdapServer" class="form-label required">{{ __('RDAP Server') }}</label>
<input type="text" class="form-control" id="rdapServer" name="rdapServer" placeholder="{{ __('Enter registry RDAP server') }}" value="{{ rdap_server }}" required>
<small class="form-hint">{{ __('Enter the URL of the registry\'s RDAP server. Example:') }} https://rdap.example.com</small>
</div>

<div class="mb-3">
<label for="whoisServer" class="form-label required">{{ __('WHOIS Server') }}</label>
<input type="text" class="form-control" id="whoisServer" name="whoisServer" placeholder="{{ __('Enter registry whois server') }}" value="{{ whois_server }}" required>
<small class="form-hint">{{ __('Enter the URL of the registry\'s WHOIS server. Example:') }} whois.example.com</small>
</div>

<div class="mb-3">
<label for="registryHandle" class="form-label required">{{ __('Registry Handle') }}</label>
<input type="text" class="form-control" id="registryHandle" name="registryHandle" placeholder="{{ __('Enter registry handle') }}" value="{{ handle }}" required>
<small class="form-hint">{{ __('A unique identifier for the registry which will be appended to each object handle.') }}</small>
</div>

<div class="mb-3">
<label for="rdapServer" class="form-label required">{{ __('RDAP Server') }}</label>
<input type="text" class="form-control" id="rdapServer" name="rdapServer" placeholder="{{ __('Enter registry RDAP server') }}" value="{{ rdap_server }}" required>
<small class="form-hint">{{ __('Enter the URL of the registry\'s RDAP server. Example:') }} https://rdap.example.com</small>
<label for="registryCurrency" class="form-label required">{{ __('Registry Currency') }}</label>
<select class="form-select" id="registryCurrency" name="currency" required="required">
{% for currencyCode, currencyName in uniqueCurrencies %}
<option value="{{ currencyCode }}" {% if currency == currencyCode %}selected{% endif %}>{{ currencyName }}</option>
{% endfor %}
</select>
<small class="form-hint">{{ __('Choose the currency for all transactions. This impacts billing and financial reports. Inform stakeholders of changes.') }}</small>
</div>

<div class="mb-3">
Expand Down
3 changes: 2 additions & 1 deletion database/registry.mariadb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ INSERT INTO `registry`.`settings` (`name`, `value`) VALUES
('email', '[email protected]'),
('launch_phases', 'on'),
('whois_server', 'whois.example.com'),
('rdap_server', 'https://rdap.example.com');
('rdap_server', 'https://rdap.example.com'),
('currency', 'USD');

CREATE DATABASE IF NOT EXISTS `registryTransaction`;

Expand Down
3 changes: 2 additions & 1 deletion database/registry.postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,8 @@ INSERT INTO settings (name, value) VALUES
('email', '[email protected]'),
('launch_phases', 'on'),
('whois_server', 'whois.example.com'),
('rdap_server', 'https://rdap.example.com');
('rdap_server', 'https://rdap.example.com'),
('currency', 'USD');

ALTER TABLE domain_tld ADD FOREIGN KEY (launch_phase_id) REFERENCES launch_phases(id);
ALTER TABLE launch_phases ADD FOREIGN KEY (tld_id) REFERENCES domain_tld(id);
Expand Down

0 comments on commit fd0909f

Please sign in to comment.