From 3a5e3388e38e27ea3dfffb627b69c16ef58e6a6d Mon Sep 17 00:00:00 2001
From: Pinga <121483313+getpinga@users.noreply.github.com>
Date: Thu, 3 Apr 2025 09:27:58 +0300
Subject: [PATCH] More UI improvements
---
cp/app/Controllers/SystemController.php | 61 ++++++++-
.../views/admin/system/manageTld.twig | 96 +-------------
.../views/admin/system/viewPromo.twig | 125 ++++++++++++++++++
cp/resources/views/layouts/app.twig | 2 +-
cp/resources/views/partials/js-tlds.twig | 2 +-
cp/routes/web.php | 1 +
6 files changed, 186 insertions(+), 101 deletions(-)
create mode 100644 cp/resources/views/admin/system/viewPromo.twig
diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php
index 74649c7..d9feda1 100644
--- a/cp/app/Controllers/SystemController.php
+++ b/cp/app/Controllers/SystemController.php
@@ -976,8 +976,6 @@ class SystemController extends Controller
$premium_pricing = $db->selectRow('SELECT * FROM premium_domain_pricing WHERE tld_id = ?',
[ $tld['id'] ]);
$premium_categories = $db->select('SELECT * FROM premium_domain_categories');
- $promotions = $db->select('SELECT * FROM promotion_pricing WHERE tld_id = ?',
- [ $tld['id'] ]);
$launch_phases = $db->select('SELECT * FROM launch_phases WHERE tld_id = ?',
[ $tld['id'] ]);
@@ -1169,7 +1167,6 @@ class SystemController extends Controller
'tld_restore' => $tld_restore,
'premium_pricing' => $premium_pricing,
'premium_categories' => $premium_categories,
- 'promotions' => $promotions,
'launch_phases' => $launch_phases,
'secureTld' => $secureTld,
'dnssecData' => $dnssecData,
@@ -1487,6 +1484,60 @@ class SystemController extends Controller
//}
}
+ public function viewPromo(Request $request, Response $response, $args)
+ {
+ if ($_SESSION["auth_roles"] != 0) {
+ return $response->withHeader('Location', '/dashboard')->withStatus(302);
+ }
+
+ $db = $this->container->get('db');
+ // Get the current URI
+ $uri = $request->getUri()->getPath();
+
+ if ($args) {
+ $args = trim($args);
+
+ if (!preg_match('/^\.(xn--[a-zA-Z0-9-]+|[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)?)$/', $args)) {
+ $this->container->get('flash')->addMessage('error', 'Invalid TLD format');
+ return $response->withHeader('Location', '/registry/tlds')->withStatus(302);
+ }
+
+ $tld = $db->selectRow('SELECT id, tld, idn_table, secure FROM domain_tld WHERE tld = ?',
+ [ $args ]);
+
+ if ($tld) {
+ $promotions = $db->select('SELECT * FROM promotion_pricing WHERE tld_id = ?',
+ [ $tld['id'] ]);
+
+ if (strpos(strtolower($tld['tld']), '.xn--') === 0) {
+ $tld['tld'] = ltrim($tld['tld'], '.');
+ $tld_u = '.'.idn_to_utf8($tld['tld'], 0, INTL_IDNA_VARIANT_UTS46);
+ $tld['tld'] = '.'.$tld['tld'];
+ } else {
+ $tld_u = $tld['tld'];
+ }
+
+ $_SESSION['u_tld_id'] = [$tld['id']];
+ $_SESSION['u_tld_extension'] = [$tld['tld']];
+
+ return view($response,'admin/system/viewPromo.twig', [
+ 'tld' => $tld,
+ 'tld_u' => $tld_u,
+ 'promotions' => $promotions,
+ 'currentUri' => $uri
+ ]);
+ } else {
+ // TLD does not exist, redirect to the tlds view
+ return $response->withHeader('Location', '/registry/tlds')->withStatus(302);
+ }
+
+ } else {
+ // Redirect to the tlds view
+ return $response->withHeader('Location', '/registry/tlds')->withStatus(302);
+ }
+
+ }
+
public function managePromo(Request $request, Response $response)
{
if ($_SESSION["auth_roles"] != 0) {
@@ -1568,11 +1619,11 @@ class SystemController extends Controller
unset($_SESSION['u_tld_extension']);
$this->container->get('flash')->addMessage('success', 'Promotion updates for the ' . $sData['extension'] . ' TLD have been successfully applied');
- return $response->withHeader('Location', '/registry/tlds')->withStatus(302);
+ return $response->withHeader('Location', '/registry/promotion/'.$sData['extension'])->withStatus(302);
} catch (Exception $e) {
$db->rollBack();
$this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage());
- return $response->withHeader('Location', '/registry/tld/'.$sData['extension'])->withStatus(302);
+ return $response->withHeader('Location', '/registry/promotion/'.$sData['extension'])->withStatus(302);
}
} else {
diff --git a/cp/resources/views/admin/system/manageTld.twig b/cp/resources/views/admin/system/manageTld.twig
index e61175f..495e902 100644
--- a/cp/resources/views/admin/system/manageTld.twig
+++ b/cp/resources/views/admin/system/manageTld.twig
@@ -20,11 +20,11 @@
-
-
-
-
-
-
-
- {{ __('Promotion Name') }} |
- {{ __('Start Date') }} |
- {{ __('End Date') }} |
- {{ __('Discount') }} (%) |
- {{ __('Discount Amount') }} |
- {{ __('Description') }} |
-
-
-
- {% for promo in promotions %}
-
- {{ promo.promo_name }} |
- {{ promo.start_date }} |
- {{ promo.end_date }} |
- {{ promo.discount_percentage ? promo.discount_percentage ~ '%' : 'N/A' }} |
- {{ promo.discount_amount ? promo.discount_amount : 'N/A' }} |
- {{ promo.description ? promo.description : 'N/A' }} |
-
- {% else %}
-
- {{ __('No promotions found.') }} |
-
- {% endfor %}
-
-
-
-
{{ __('Create New Promotion') }}
-
-
-
-