Skip to content

Commit 340d5c1

Browse files
committed
Small improvements
1 parent 8e9dbb4 commit 340d5c1

File tree

4 files changed

+38
-52
lines changed

4 files changed

+38
-52
lines changed

app/Controllers/HomeController.php

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,31 @@ public function index(Request $request, Response $response)
2727
public function dashboard(Request $request, Response $response)
2828
{
2929
$db = $this->container->get('db');
30-
31-
if ($_SESSION['auth_roles'] === 0) {
32-
$clid = null;
30+
$isAdmin = $_SESSION["auth_roles"] == 0;
31+
$userId = $_SESSION["auth_user_id"];
32+
33+
if ($isAdmin) {
34+
// Admin: total counts
35+
$userCount = $db->selectValue('SELECT COUNT(*) FROM users');
36+
$zoneCount = $db->selectValue('SELECT COUNT(*) FROM zones');
37+
$ticketCount = $db->selectValue('SELECT COUNT(*) FROM support_tickets');
38+
39+
$openTickets = $db->selectValue('SELECT COUNT(*) FROM support_tickets WHERE status = ?', ['Open']);
3340
} else {
34-
$result = $db->selectRow('SELECT zone_id FROM zone_users WHERE user_id = ?', [$_SESSION['auth_user_id']]);
35-
if (is_array($result)) {
36-
$clid = $result['zone_id'];
37-
} else if (is_object($result) && method_exists($result, 'fetch')) {
38-
$clid = $result->fetch();
39-
} else {
40-
$clid = null;
41-
}
42-
}
41+
// Regular user: filtered by user_id
42+
$userCount = null; // Don't send this to view for users
43+
$zoneCount = $db->selectValue('SELECT COUNT(*) FROM zones WHERE client_id = ?', [$userId]);
44+
$ticketCount = $db->selectValue('SELECT COUNT(*) FROM support_tickets WHERE user_id = ?', [$userId]);
4345

44-
if ($clid !== null) {
45-
$zones = $db->selectValue('SELECT count(id) as zones FROM zones WHERE client_id = ?', [$clid]);
46-
$latest_zones = $db->select('SELECT domain_name, created_at FROM zones WHERE client_id = ? ORDER BY created_at DESC LIMIT 10', [$clid]);
47-
48-
return view($response, 'admin/dashboard/index.twig', [
49-
'zones' => $zones,
50-
'latest_zones' => $latest_zones,
51-
]);
52-
} else {
53-
$zones = $db->selectValue('SELECT count(id) as zones FROM zones');
54-
$latest_zones = $db->select('SELECT domain_name, created_at FROM zones ORDER BY created_at DESC LIMIT 10');
55-
56-
return view($response, 'admin/dashboard/index.twig', [
57-
'zones' => $zones,
58-
'latest_zones' => $latest_zones,
59-
]);
46+
$openTickets = $db->selectValue('SELECT COUNT(*) FROM support_tickets WHERE user_id = ? AND status = ?', [$userId, 'Open']);
6047
}
48+
49+
return view($response, 'admin/dashboard/index.twig', [
50+
'userCount' => $userCount,
51+
'zoneCount' => $zoneCount,
52+
'ticketCount' => $ticketCount,
53+
'openTickets' => $openTickets
54+
]);
6155
}
6256

6357
public function mode(Request $request, Response $response)

resources/views/admin/dashboard/index.twig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
</div>
5555
<div class="col">
5656
<div class="font-weight-medium">
57-
<span class="h1 mt-3">{{ orderCount }} {{ __('Zones') }}</span>
58-
<span class="float-end font-weight-medium text-orange">{{ pendingOrders }} {{ __('pending') }}</span>
57+
<span class="h1 mt-3">{{ zoneCount }} {{ __('Zones') }}</span>
5958
</div>
6059
</div>
6160
</div>

resources/views/admin/zones/listZones.twig

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
<div class="container-xl">
1010
<div class="row g-2 align-items-center">
1111
<div class="col">
12-
<!-- Page pre-title -->
13-
<div class="page-pretitle">
14-
{{ __('Overview') }}
12+
<div class="mb-1">
13+
<ol class="breadcrumb">
14+
<li class="breadcrumb-item">
15+
<a href="{{route('home')}}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none" /><polyline points="5 12 3 12 12 3 21 12 19 12" /><path d="M5 12v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-8" /><rect x="10" y="12" width="4" height="4" /></svg></a>
16+
</li>
17+
<li class="breadcrumb-item active">
18+
{{ __('Zones') }}
19+
</li>
20+
</ol>
1521
</div>
1622
<h2 class="page-title">
1723
{{ __('Zones') }}
@@ -44,18 +50,13 @@
4450
{% include 'partials/flash.twig' %}
4551
<div class="card">
4652
<div class="card-body py-3">
47-
<div class="d-flex">
48-
<div class="text-secondary">
49-
<button class="btn btn-info btn-icon" onclick="downloadCSV()" title="Export page"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 15a1 1 0 0 0 1 1h2a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-2a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1"></path><path d="M17 8l2 8l2 -8"></path><path d="M7 10a2 2 0 1 0 -4 0v4a2 2 0 1 0 4 0"></path></svg></button>
50-
<button class="btn btn-info btn-icon" onclick="downloadJSON()" title="Export page"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M20 16v-8l3 8v-8"></path><path d="M15 8a2 2 0 0 1 2 2v4a2 2 0 1 1 -4 0v-4a2 2 0 0 1 2 -2z"></path><path d="M1 8h3v6.5a1.5 1.5 0 0 1 -3 0v-.5"></path><path d="M7 15a1 1 0 0 0 1 1h1a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h1a1 1 0 0 1 1 1"></path></svg></button>
51-
<button class="btn btn-green btn-icon" onclick="downloadXLSX()" title="Export page"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M14 3v4a1 1 0 0 0 1 1h4"></path><path d="M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"></path><path d="M4 15l4 6"></path><path d="M4 21l4 -6"></path><path d="M17 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"></path><path d="M11 15v6h3"></path></svg></button>
52-
<button class="btn btn-red btn-icon" onclick="downloadPDF()" title="Export page"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 8v8h2a2 2 0 0 0 2 -2v-4a2 2 0 0 0 -2 -2h-2z"></path><path d="M3 12h2a2 2 0 1 0 0 -4h-2v8"></path><path d="M17 12h3"></path><path d="M21 8h-4v8"></path></svg></button>
53+
<div class="d-flex align-items-center justify-content-between flex-nowrap gap-2 flex-wrap-sm">
54+
<div class="d-flex align-items-center gap-2">
55+
<button class="btn btn-ghost-info btn-icon" onclick="downloadCSV()" title="{{ __('Export page') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 15a1 1 0 0 0 1 1h2a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-2a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1"></path><path d="M17 8l2 8l2 -8"></path><path d="M7 10a2 2 0 1 0 -4 0v4a2 2 0 1 0 4 0"></path></svg></button>
56+
<button class="btn btn-ghost-red btn-icon" onclick="downloadPDF()" title="{{ __('Export page') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 8v8h2a2 2 0 0 0 2 -2v-4a2 2 0 0 0 -2 -2h-2z"></path><path d="M3 12h2a2 2 0 1 0 0 -4h-2v8"></path><path d="M17 12h3"></path><path d="M21 8h-4v8"></path></svg></button>
5357
</div>
54-
<div class="ms-auto text-secondary">
55-
{{ __('Search') }}:
56-
<div class="ms-2 d-inline-block">
57-
<input id="search-input" type="text" class="form-control" aria-label="{{ __('Search zones') }}" autocapitalize="none">
58-
</div>
58+
<div class="d-flex align-items-center gap-2">
59+
<input id="search-input" type="text" class="form-control" placeholder="{{ __('Search zones') }}" aria-label="{{ __('Search zones') }}" autocapitalize="none">
5960
</div>
6061
</div>
6162
</div>

resources/views/partials/js-zones.twig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@
130130
table.download("csv", "zones.csv");
131131
}
132132
133-
function downloadJSON() {
134-
table.download("json", "zones.json");
135-
}
136-
137-
function downloadXLSX() {
138-
table.download("xlsx", "zones.xlsx", {sheetName:"My Zones"});
139-
}
140-
141133
function downloadPDF() {
142134
table.download("pdf", "zones.pdf", {
143135
orientation:"portrait",

0 commit comments

Comments
 (0)