From d7512206b4a5d575030cbeab9b6258bb55e896ce Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:36:12 +0300 Subject: [PATCH] Added option to manage custom registrar pricing #129 --- cp/app/Controllers/RegistrarsController.php | 55 ++++++++ .../views/admin/registrars/customPricing.twig | 131 ++++++++++++++++++ .../views/partials/js-registrars.twig | 2 +- cp/routes/web.php | 1 + 4 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 cp/resources/views/admin/registrars/customPricing.twig diff --git a/cp/app/Controllers/RegistrarsController.php b/cp/app/Controllers/RegistrarsController.php index d0c61f3..30243a7 100644 --- a/cp/app/Controllers/RegistrarsController.php +++ b/cp/app/Controllers/RegistrarsController.php @@ -1167,5 +1167,60 @@ class RegistrarsController extends Controller return $response->withHeader('Location', '/dashboard')->withStatus(302); } } + + public function updateCustomPricing(Request $request, Response $response, $args) + { + if ($_SESSION["auth_roles"] != 0) { + return $response->withHeader('Location', '/dashboard')->withStatus(302); + } + //TODO + if ($request->getMethod() === 'POST') { + // Retrieve POST data + $data = $request->getParsedBody(); + $db = $this->container->get('db'); + + var_dump ($data);die(); + } + + $db = $this->container->get('db'); + // Get the current URI + $uri = $request->getUri()->getPath(); + + if ($args) { + $args = trim($args); + + $registrar = $db->selectRow('SELECT id,clid,name FROM registrar WHERE clid = ?', + [ $args ]); + $tlds = $db->select('SELECT id, tld FROM domain_tld'); + + $result = []; + + foreach ($tlds as $tld) { + $createPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) AND command = ? ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id'], 'create']); + $renewPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) AND command = ? ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id'], 'renew']); + $transferPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) AND command = ? ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id'], 'transfer']); + $tld_restore = $db->selectRow('SELECT * FROM domain_restore_price WHERE tldid = ? AND (registrar_id = ? OR registrar_id IS NULL) ORDER BY registrar_id DESC LIMIT 1', [$tld['id'], $registrar['id']]); + + $result[] = [ + 'tld' => $tld['tld'], + 'createPrices' => ($createPrices && $createPrices['registrar_id'] === $registrar['id']) ? $createPrices : null, + 'renewPrices' => ($renewPrices && $renewPrices['registrar_id'] === $registrar['id']) ? $renewPrices : null, + 'transferPrices' => ($transferPrices && $transferPrices['registrar_id'] === $registrar['id']) ? $transferPrices : null, + 'tld_restore' => ($tld_restore && $tld_restore['registrar_id'] === $registrar['id']) ? $tld_restore : null, + ]; + } + + return view($response, 'admin/registrars/customPricing.twig', [ + 'tlds' => $result, + 'name' => $registrar['name'], + 'clid' => $registrar['clid'], + 'currentUri' => $uri, + ]); + + } else { + // Redirect to the registrars view + return $response->withHeader('Location', '/registrars')->withStatus(302); + } + } } \ No newline at end of file diff --git a/cp/resources/views/admin/registrars/customPricing.twig b/cp/resources/views/admin/registrars/customPricing.twig new file mode 100644 index 0000000..ece320f --- /dev/null +++ b/cp/resources/views/admin/registrars/customPricing.twig @@ -0,0 +1,131 @@ +{% extends "layouts/app.twig" %} + +{% block title %}{{ __('Manage Custom Pricing') }}{% endblock %} + +{% block content %} +
+ + + +
+
+
+ {% include 'partials/flash.twig' %} +
+ {{ csrf.field | raw }} +
+
+

{{ __('Registrar') }} {{ name }}

+
+ +
+
+
+ +
+ + + + + + + + + + + + {% for tld in tlds %} + + + {% if tld.createPrices or tld.renewPrices or tld.transferPrices or tld.tld_restore %} + + + + + {% else %} + + {% endif %} + + {% endfor %} + +
{{ __('TLD') }} / {{ __('Command') }}{{ __('Create') }}{{ __('Renew') }}{{ __('Transfer') }}{{ __('Restore Price') }}
{{ tld.tld }} + {% if tld.createPrices %} + {% for year in [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] %} +
+
+ +
+
+ +
+
+ {% endfor %} + {% else %} + N/A + {% endif %} +
+ {% if tld.renewPrices %} + {% for year in [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] %} +
+
+ +
+
+ +
+
+ {% endfor %} + {% else %} + N/A + {% endif %} +
+ {% if tld.transferPrices %} + {% for year in [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] %} +
+
+ +
+
+ +
+
+ {% endfor %} + {% else %} + N/A + {% endif %} +
+ {% if tld.tld_restore %} + + {% else %} + N/A + {% endif %} + {{ __('Registrar does not have custom prices for') }} {{ tld.tld }}
+
+
+
+
+
+
+
+ {% include 'partials/footer.twig' %} +
+{% endblock %} \ No newline at end of file diff --git a/cp/resources/views/partials/js-registrars.twig b/cp/resources/views/partials/js-registrars.twig index 1ce6188..8ecedf2 100644 --- a/cp/resources/views/partials/js-registrars.twig +++ b/cp/resources/views/partials/js-registrars.twig @@ -13,7 +13,7 @@ function actionsFormatter(cell, formatterParams, onRendered) { return ` - + `; } diff --git a/cp/routes/web.php b/cp/routes/web.php index 6a9e151..df568ce 100644 --- a/cp/routes/web.php +++ b/cp/routes/web.php @@ -90,6 +90,7 @@ $app->group('', function ($route) { $route->map(['GET', 'POST'], '/registrar/create', RegistrarsController::class . ':create')->setName('registrarcreate'); $route->get('/registrar/view/{registrar}', RegistrarsController::class . ':viewRegistrar')->setName('viewRegistrar'); $route->get('/registrar/update/{registrar}', RegistrarsController::class . ':updateRegistrar')->setName('updateRegistrar'); + $route->map(['GET', 'POST'], '/registrar/pricing/{registrar}', RegistrarsController::class . ':updateCustomPricing')->setName('updateCustomPricing'); $route->post('/registrar/update', RegistrarsController::class . ':updateRegistrarProcess')->setName('updateRegistrarProcess'); $route->get('/registrar', RegistrarsController::class .':registrar')->setName('registrar'); $route->map(['GET', 'POST'], '/registrar/edit', RegistrarsController::class .':editRegistrar')->setName('editRegistrar');