From 8966edf04688da8742fe083d41afdca70272e428 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:54:28 +0200 Subject: [PATCH] Panel dashboard is now live --- cp/app/Controllers/HomeController.php | 45 ++- cp/resources/views/admin/dashboard/index.twig | 346 ++++-------------- 2 files changed, 117 insertions(+), 274 deletions(-) diff --git a/cp/app/Controllers/HomeController.php b/cp/app/Controllers/HomeController.php index dbbd9a1..91d0987 100644 --- a/cp/app/Controllers/HomeController.php +++ b/cp/app/Controllers/HomeController.php @@ -16,9 +16,44 @@ class HomeController extends Controller public function dashboard(Request $request, Response $response) { - $userModel = new User($this->container->get('db')); - $users = $userModel->getAllUsers(); - return view($response,'admin/dashboard/index.twig', compact('users')); + $db = $this->container->get('db'); + + if ($_SESSION['auth_roles'] === 0) { + $clid = null; + } else { + $result = $db->selectRow('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]); + if (is_array($result)) { + $clid = $result['registrar_id']; + } else if (is_object($result) && method_exists($result, 'fetch')) { + $clid = $result->fetch(); + } else { + $clid = null; + } + } + + if ($clid !== null) { + $domains = $db->selectRow('SELECT count(id) as domains FROM domain WHERE clid = ?', [$clid]); + $hosts = $db->selectRow('SELECT count(id) as hosts FROM host WHERE clid = ?', [$clid]); + $contacts = $db->selectRow('SELECT count(id) as contacts FROM contact WHERE clid = ?', [$clid]); + + return view($response, 'admin/dashboard/index.twig', [ + 'domains' => $domains['domains'], + 'hosts' => $hosts['hosts'], + 'contacts' => $contacts['contacts'], + ]); + } else { + $domains = $db->selectRow('SELECT count(id) as domains FROM domain'); + $hosts = $db->selectRow('SELECT count(id) as hosts FROM host'); + $contacts = $db->selectRow('SELECT count(id) as contacts FROM contact'); + $registrars = $db->selectRow('SELECT count(id) as registrars FROM registrar'); + + return view($response, 'admin/dashboard/index.twig', [ + 'domains' => $domains['domains'], + 'hosts' => $hosts['hosts'], + 'contacts' => $contacts['contacts'], + 'registrars' => $registrars['registrars'], + ]); + } } public function mode(Request $request, Response $response) @@ -44,7 +79,7 @@ class HomeController extends Controller return $psrResponse; } - + public function lang(Request $request, Response $response) { $data = $request->getQueryParams(); @@ -59,4 +94,4 @@ class HomeController extends Controller } return $response->withHeader('Location', '/dashboard')->withStatus(302); } -} +} \ No newline at end of file diff --git a/cp/resources/views/admin/dashboard/index.twig b/cp/resources/views/admin/dashboard/index.twig index 5bc59c5..9dc4235 100644 --- a/cp/resources/views/admin/dashboard/index.twig +++ b/cp/resources/views/admin/dashboard/index.twig @@ -21,17 +21,15 @@
- | ID - - | -Username | -Status | -- | |
---|---|---|---|---|---|
- | {{ user.id }} | -{{ user.username }} | -{{ user.email }} | -{{ user.status }} | -- - - + {% else %} + | -