diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php index 0b2c0e4..450570d 100644 --- a/cp/app/Controllers/SystemController.php +++ b/cp/app/Controllers/SystemController.php @@ -799,5 +799,91 @@ class SystemController extends Controller } } + + public function manageReserved(Request $request, Response $response) + { + if ($_SESSION["auth_roles"] != 0) { + return $response->withHeader('Location', '/dashboard')->withStatus(302); + } + + if ($request->getMethod() === 'POST') { + // Retrieve POST data + $data = $request->getParsedBody(); + $db = $this->container->get('db'); + + $domainCategories = []; + + foreach ($data as $key => $value) { + if (strpos($key, 'domains_') === 0) { // Check if the key starts with 'domains_' + $domains = explode("\n", trim($value)); + $domains = array_filter(array_map('trim', $domains)); + $domainCategories[substr($key, 8)] = $domains; + } + } + + try { + // Fetch existing names + $existingDomains = $db->select('SELECT name, type FROM reserved_domain_names'); + + // Organize existing names by type + $existingByType = []; + foreach ($existingDomains as $domain) { + $existingByType[$domain['type']][] = $domain['name']; + } + + $db->beginTransaction(); + + foreach ($domainCategories as $type => $submittedDomains) { + // Find domains to delete + $domainsToDelete = array_diff($existingByType[$type] ?? [], $submittedDomains); + + // Delete domains not in the submitted list + foreach ($domainsToDelete as $domain) { + $db->exec( + "DELETE FROM reserved_domain_names WHERE name = ? AND type = ?", + [$domain, $type] + ); + } + + // Insert or ignore new domains + foreach ($submittedDomains as $domain) { + $db->exec( + "INSERT IGNORE INTO reserved_domain_names (name, type) VALUES (?, ?)", + [$domain, $type] + ); + } + } + + $db->commit(); + } catch (Exception $e) { + $db->rollBack(); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/registry/reserved')->withStatus(302); + } + + $this->container->get('flash')->addMessage('success', 'Reserved names have been updated successfully'); + return $response->withHeader('Location', '/registry/reserved')->withStatus(302); + + } + + $db = $this->container->get('db'); + $types = $db->select("SELECT DISTINCT type FROM reserved_domain_names"); + // Get the current URI + $uri = $request->getUri()->getPath(); + + $categories = []; + foreach ($types as $type) { + $typeNames = $db->select( + 'SELECT name FROM reserved_domain_names WHERE type = ?', + [ $type['type'] ] + ); + $categories[$type['type']] = array_column($typeNames, 'name'); + } + + return view($response,'admin/system/manageReserved.twig', [ + 'categories' => $categories, + 'currentUri' => $uri + ]); + } } \ No newline at end of file diff --git a/cp/resources/views/admin/system/listTlds.twig b/cp/resources/views/admin/system/listTlds.twig index d1b75b9..54ec72c 100644 --- a/cp/resources/views/admin/system/listTlds.twig +++ b/cp/resources/views/admin/system/listTlds.twig @@ -21,7 +21,7 @@
- + {{ __('Manage Reserved Names') }} diff --git a/cp/resources/views/admin/system/manageReserved.twig b/cp/resources/views/admin/system/manageReserved.twig new file mode 100644 index 0000000..11c0ffb --- /dev/null +++ b/cp/resources/views/admin/system/manageReserved.twig @@ -0,0 +1,74 @@ +{% extends "layouts/app.twig" %} + +{% block title %}{{ __('Managed Reserved Names') }}{% endblock %} + +{% block content %} +
+ + + +
+
+
+ {% include 'partials/flash.twig' %} +
+
+ {{ csrf.field | raw }} +
+

Manage Reserved Names

+
+
+ {% for type, names in categories %} +
+
{{ type|capitalize }} Names
+
+ + + {{ type|capitalize }} Names: These domain names are subject to special regulations or registration requirements. They might be available for registration but under specific conditions, such as proof of eligibility or additional documentation. +
Enter each {{ type }} name on a new line, without the extension. For instance, use "example" in place of "example.com". +
+
+
+ {% endfor %} +
+
+
+
+
+
+
+
+
+
    +
  • + Copyright © 2023 + Namingo. +
  • +
+
+
+
+ +
+{% endblock %} \ No newline at end of file diff --git a/cp/resources/views/admin/system/registry.twig b/cp/resources/views/admin/system/registry.twig index 58636c6..4810f31 100644 --- a/cp/resources/views/admin/system/registry.twig +++ b/cp/resources/views/admin/system/registry.twig @@ -34,19 +34,19 @@
-
The official name of the organization operating the registry.
+ The official name of the organization operating the registry.
-
The contact address of the registry.
+ The contact address of the registry.
-
The contact address of the registry. (Line 2)
+ The contact address of the registry. (Line 2)
@@ -55,19 +55,19 @@
-
The email address for general inquiries to the registry.
+ The email address for general inquiries to the registry.
-
The phone number 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.
+ A unique identifier for the registry which will be appended to each object handle.
diff --git a/cp/resources/views/layouts/app.twig b/cp/resources/views/layouts/app.twig index b5414d2..d96d989 100644 --- a/cp/resources/views/layouts/app.twig +++ b/cp/resources/views/layouts/app.twig @@ -189,7 +189,7 @@ -
  • +