diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php index 51f506a..0b2c0e4 100644 --- a/cp/app/Controllers/SystemController.php +++ b/cp/app/Controllers/SystemController.php @@ -15,19 +15,121 @@ class SystemController extends Controller return $response->withHeader('Location', '/dashboard')->withStatus(302); } - $db = $this->container->get('db'); - $tlds = $db->select("SELECT id, tld, idn_table, secure FROM domain_tld"); - - foreach ($tlds as $key => $tld) { - // Count the domains for each TLD - $domainCount = $db->select("SELECT COUNT(name) FROM domain WHERE tldid = ?", [$tld['id']]); + if ($request->getMethod() === 'POST') { + // Retrieve POST data + $data = $request->getParsedBody(); + $db = $this->container->get('db'); - // Add the domain count to the TLD array - $tlds[$key]['domain_count'] = $domainCount[0]['COUNT(name)']; - } + // Error message initialization + $error = ''; + // Check each field + foreach ($data as $key => $value) { + if (empty($value)) { + // Construct error message + $error .= "Error: '$key' cannot be empty.\n"; + } + } + + // Display error messages if any + if (!empty($error)) { + $this->container->get('flash')->addMessage('error', $error); + return $response->withHeader('Location', '/registry')->withStatus(302); + } + + try { + $db->beginTransaction(); + + $currentDateTime = new \DateTime(); + $crdate = $currentDateTime->format('Y-m-d H:i:s.v'); // Current timestamp + + $db->update( + 'settings', + [ + 'value' => $data['registryOperator'] + ], + [ + 'name' => "company_name" + ] + ); + + $db->update( + 'settings', + [ + 'value' => $data['contactAddress'] + ], + [ + 'name' => "address" + ] + ); + + $db->update( + 'settings', + [ + 'value' => $data['contactAddress2'] + ], + [ + 'name' => "address2" + ] + ); + + $db->update( + 'settings', + [ + 'value' => $data['contactEmail'] + ], + [ + 'name' => "email" + ] + ); + + $db->update( + 'settings', + [ + 'value' => $data['contactPhone'] + ], + [ + 'name' => "phone" + ] + ); + + $db->update( + 'settings', + [ + 'value' => $data['registryHandle'] + ], + [ + 'name' => "handle" + ] + ); + + $db->commit(); + } catch (Exception $e) { + $db->rollBack(); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/registry')->withStatus(302); + } + + $this->container->get('flash')->addMessage('success', 'Registry details have been updated successfully'); + return $response->withHeader('Location', '/registry')->withStatus(302); + + } + + $db = $this->container->get('db'); + $company_name = $db->selectValue("SELECT value FROM settings WHERE name = 'company_name'"); + $address = $db->selectValue("SELECT value FROM settings WHERE name = 'address'"); + $address2 = $db->selectValue("SELECT value FROM settings WHERE name = 'address2'"); + $phone = $db->selectValue("SELECT value FROM settings WHERE name = 'phone'"); + $email = $db->selectValue("SELECT value FROM settings WHERE name = 'email'"); + $handle = $db->selectValue("SELECT value FROM settings WHERE name = 'handle'"); + return view($response,'admin/system/registry.twig', [ - 'tlds' => $tlds, + 'company_name' => $company_name, + 'address' => $address, + 'address2' => $address2, + 'phone' => $phone, + 'email' => $email, + 'handle' => $handle ]); } diff --git a/cp/resources/views/admin/system/registry.twig b/cp/resources/views/admin/system/registry.twig index 9a02f3c..58636c6 100644 --- a/cp/resources/views/admin/system/registry.twig +++ b/cp/resources/views/admin/system/registry.twig @@ -17,23 +17,6 @@ {{ __('Registry Configuration') }} - -
-
- - - {{ __('Manage Reserved Names') }} - - - - - {{ __('Create New TLD') }} - - - - -
-
@@ -41,33 +24,63 @@
+ {% include 'partials/flash.twig' %}
+
+ {{ csrf.field | raw }}
- - + +
The official name of the organization operating the registry.
+
- - -
The email address for general inquiries to the registry.
+ + +
The contact address of the registry.
- - + +
+ + +
The contact address of the registry. (Line 2)
+
+
-
- - -
A unique identifier for the registry which will be appended to each object handle.
-
-
+
+ + +
The email address for general inquiries to the registry.
+
+ +
+ + +
The phone number for general inquiries to the registry.
+
+ +
+ + +
A unique identifier for the registry which will be appended to each object handle.
+
+
+
+
diff --git a/cp/routes/web.php b/cp/routes/web.php index 0c92bab..e681277 100644 --- a/cp/routes/web.php +++ b/cp/routes/web.php @@ -88,8 +88,8 @@ $app->group('', function ($route) { $route->map(['GET', 'POST'], '/payment-cancel', FinancialsController::class .':cancel')->setName('cancel'); $route->get('/transactions', FinancialsController::class .':transactions')->setName('transactions'); $route->get('/overview', FinancialsController::class .':overview')->setName('overview'); - - $route->get('/registry', SystemController::class .':registry')->setName('registry'); + + $route->map(['GET', 'POST'], '/registry', SystemController::class .':registry')->setName('registry'); $route->map(['GET', 'POST'], '/registry/tld/create', SystemController::class .':createTld')->setName('createTld'); $route->map(['GET', 'POST'], '/registry/tld/{tld}', SystemController::class . ':manageTld')->setName('manageTld'); $route->get('/registry/tlds', SystemController::class .':listTlds')->setName('listTlds');