Skip to content

Commit

Permalink
Fixed #63
Browse files Browse the repository at this point in the history
  • Loading branch information
getpinga committed Jan 23, 2024
1 parent c8c8cc3 commit aaa2971
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
32 changes: 20 additions & 12 deletions cp/app/Controllers/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -971,26 +971,34 @@ public function manageReserved(Request $request, Response $response)
}

$db = $this->container->get('db');
$types = $db->select("SELECT DISTINCT type FROM reserved_domain_names");
// Get the current URI
$uri = $request->getUri()->getPath();

// Set default types if $types is empty
if (empty($types)) {
$types = [
['type' => 'reserved'],
['type' => 'restricted']
];
$typesResult = $db->select("SELECT DISTINCT type FROM reserved_domain_names");

// Initialize $types as an empty array if the query result is null
$types = $typesResult ?: [];

// Ensure all default types are represented
$defaultTypes = ['reserved', 'restricted'];
foreach ($defaultTypes as $defaultType) {
$found = false;
foreach ($types as $type) {
if ($type['type'] === $defaultType) {
$found = true;
break;
}
}

if (!$found) {
$types[] = ['type' => $defaultType];
}
}

$categories = [];
foreach ($types as $type) {
$typeNames = $db->select(
'SELECT name FROM reserved_domain_names WHERE type = ?',
[ $type['type'] ]
);

// Initialize the type with an empty array if no names are found
$categories[$type['type']] = $typeNames ? array_column($typeNames, 'name') : [];
}

Expand Down
8 changes: 6 additions & 2 deletions cp/resources/views/admin/system/manageReserved.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@
<div class="card mb-3">
<div class="card-header">{{ type|capitalize }} Names</div>
<div class="card-body">
<textarea class="form-control" name="domains_{{ type }}" rows="4" placeholder="Enter domain names, one per line" required>{{ names|join('\n') }}</textarea>
{% if names is not empty %}
<textarea class="form-control" name="domains_{{ type }}" rows="4" placeholder="Enter domain names, one per line" required>{{ names|join('\n') }}</textarea>
{% else %}
<textarea class="form-control" name="domains_{{ type }}" rows="4" placeholder="No {{ type|lower }} names. Enter new names, one per line" required></textarea>
{% endif %}
<small class="form-hint">
<strong>{{ type|capitalize }} Names:</strong> 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.
<br><em>Enter each {{ type }} name on a new line, without the extension. For instance, use "example" in place of "example.com".</em>
</small>
</small>
</div>
</div>
{% endfor %}
Expand Down

0 comments on commit aaa2971

Please sign in to comment.