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 %} +