-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin-Dashboard.html
More file actions
1326 lines (1118 loc) · 55.6 KB
/
Admin-Dashboard.html
File metadata and controls
1326 lines (1118 loc) · 55.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixsoft Graphics Hub - Admin Dashboard</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.min.js"></script>
<link rel="stylesheet" href="Admin-Dashboard.css">
<link rel="stylesheet" href="Admin-Dashboard-responsive.css">
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<!-- navbar -->
<!-- Navbar (loaded via fetch) -->
<div id="navbar-container"></div>
<script>
function initNavbar() {
console.log("Navbar Loaded!");
// Elements
const navbar = document.getElementById('navbar');
const hamburgerBtn = document.getElementById('hamburgerBtn');
const closeBtn = document.getElementById('closeBtn');
const mobileSidebar = document.getElementById('mobileSidebar');
const sidebarOverlay = document.getElementById('sidebarOverlay');
let lastScrollTop = 0;
// Smart Sticky Navbar (Hides on Scroll Down, Shows on Scroll Up)
// window.addEventListener('scroll', function () {
// let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// if (scrollTop > 10) {
// navbar.classList.add('scrolled');
// } else {
// navbar.classList.remove('scrolled');
//}
//if (scrollTop > lastScrollTop && scrollTop > 100) {
// navbar.style.transform = 'translateY(-100%)';
// } else {
// navbar.style.transform = 'translateY(0)';
// }
// lastScrollTop = scrollTop;
// });
// Toggle Sidebar Function
function toggleSidebar() {
console.log("Toggling Sidebar!");
mobileSidebar.classList.toggle('active');
sidebarOverlay.classList.toggle('active');
if (mobileSidebar.classList.contains('active')) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
}
// Attach Event Listeners
if (hamburgerBtn) {
hamburgerBtn.addEventListener('click', function () {
console.log("Hamburger Clicked!");
toggleSidebar();
});
}
if (closeBtn) {
closeBtn.addEventListener('click', function () {
console.log("Close Button Clicked!");
toggleSidebar();
});
}
if (sidebarOverlay) {
sidebarOverlay.addEventListener('click', function () {
console.log("Overlay Clicked!");
toggleSidebar();
});
}
// Close sidebar when clicking a menu item
document.querySelectorAll('.mobile-nav a').forEach(link => {
link.addEventListener('click', function () {
console.log("Sidebar Link Clicked!");
toggleSidebar();
});
});
// Close sidebar on window resize (if resized to desktop)
window.addEventListener('resize', function () {
if (window.innerWidth > 768 && mobileSidebar.classList.contains('active')) {
toggleSidebar();
}
});
}
// Load Navbar and then Initialize it
fetch('navbar.php')
.then(response => response.text())
.then(data => {
document.getElementById("navbar-container").innerHTML = data;
setTimeout(() => {
initNavbar(); // Call the function after navbar is loaded
}, 500);
})
.catch(error => console.error("Error loading navbar:", error));
</script>
<!-- Navbar (loaded via fetch) -->
<!-- navbar -->
<!-- <div id="head-content"></div> -->
<div class="dashboard-container">
<!-- Sidebar -->
<div class="sidebar">
<div class="sidebar-header">
<h1>PIX<span class="pix">S</span>OFT</h1> <h3>GRAPHICS HUB</h3>
</div>
<div class="nav-menu">
<div class="nav-item active" data-section="dashboard">Dashboard</div>
<div class="nav-item" data-section="users">Booking Management</div>
<div class="nav-item" data-section="services">Service Management</div>
<div class="nav-item" data-section="orders">Order Management</div>
<div class="nav-item" data-section="content">Content Management</div>
<div class="nav-item" data-section="reports">Reports & Analytics</div>
<div class="nav-item" data-section="settings">Contact Form Response</div>
<div class="nav-item" data-section="feedback">Feedback</div>
<div class="nav-item" data-section="newsletter">Subscribers List</div>
<div class="nav-item" data-section="profile">Update Profile</div>
<div class="nav-item" id="logout1">Logout</div>
<script>
document.getElementById("logout1").addEventListener("click", function(event) {
event.preventDefault(); // Prevent immediate redirect
// Show confirmation dialog
let confirmLogout = confirm("Are you sure you want to log out?");
if (confirmLogout) {
window.location.href = "logout.php"; // Redirect if user confirms
}
});
</script>
</div>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Dashboard Overview -->
<div class="header">
<h1>Dashboard Overview</h1>
<div class="profile-section">
<div class="profile-img">
<img class="profile-img" src="admin.jpg" alt="">
</div>
<span id="adminNameDisplay">Loading...</span>
</div>
</div>
<!-- Dashboard Overview -->
<!-- Dashboard Section -->
<div id="dashboard" class="section active">
<div class="stats-container">
<!-- Total Users (Reports & Analytics) -->
<div class="stat-card">
<h3>Total Users</h3>
<p id="totalUsersReport">Loading...</p>
</div>
<script>
// Fetch total users and update Reports & Analytics
function loadTotalUsersReport() {
fetch('get_total_users.php')
.then(response => response.json())
.then(data => {
document.getElementById("totalUsersReport").innerText = data.total_users;
})
.catch(error => console.error("Error loading total users (Reports):", error));
}
// Load on page load
document.addEventListener("DOMContentLoaded", loadTotalUsersReport);
</script>
<!-- Totsal users -->
<!-- Total Active Projects -->
<div class="stat-card">
<h3>Active Projects</h3>
<p>45</p>
</div>
<!-- ajax for total active projects -->
<script>
function loadAdminActiveProjects() {
$.ajax({
url: "get_admin_active_projects.php",
method: "GET",
dataType: "json",
success: function (response) {
if (response.status === "success") {
$(".stat-card h3:contains('Active Projects')").next("p").text(response.total);
} else {
console.error("Error fetching data:", response.message);
}
},
error: function () {
console.error("Error loading active projects.");
}
});
}
$(document).ready(function () {
loadAdminActiveProjects();
setInterval(loadAdminActiveProjects, 10000); // Auto-refresh every 10 seconds
});
</script>
<!-- ajax for total active projects -->
<!-- Total Active Projects -->
<!-- Total Completed Projects -->
<div class="stat-card">
<h3>Completed Orders</h3>
<p>892</p>
</div>
<!-- ajax for total completed projects -->
<script>
function loadAdminCompletedOrders() {
$.ajax({
url: "get_admin_completed_orders.php",
method: "GET",
dataType: "json",
success: function (response) {
if (response.status === "success") {
$(".stat-card h3:contains('Completed Orders')").next("p").text(response.total);
} else {
console.error("Error fetching data:", response.message);
}
},
error: function () {
console.error("Error loading completed orders.");
}
});
}
$(document).ready(function () {
loadAdminCompletedOrders();
setInterval(loadAdminCompletedOrders, 10000); // Auto-refresh every 10 seconds
});
</script>
<!-- ajax for total completed projects -->
<!-- Total Completed Projects -->
<!-- <div class="stat-card">
<h3>Revenue</h3>
<p>₹45,678</p>
</div> -->
</div>
<div class="charts-grid">
<div class="chart-container">
<canvas id="trafficChart"></canvas>
</div>
<div class="chart-container">
<canvas id="ordersChart"></canvas>
</div>
</div>
<!-- Admins Recent Activities -->
<div class="table-container" id="recent-orders-section">
<h2>Recent Orders</h2>
<table>
<thead>
<tr>
<th>Order ID</th>
<th>Client</th>
<th>Service</th>
<th>Status</th>
<th>Date</th>
</tr>
</thead>
<tbody id="recentOrdersTable">
<!-- Data will be loaded dynamically here -->
</tbody>
</table>
</div>
<!-- script -->
<script>
function loadAdminRecentActivities() {
$.ajax({
url: "get_admin_recent_activities.php",
method: "GET",
dataType: "json",
success: function (response) {
if (response.status === "success") {
let activitiesHtml = "";
response.activities.forEach(activity => {
let statusClass = "";
if (activity.status === "Pendings") statusClass = "status-pending";
else if (activity.status === "In Progress") statusClass = "status-progress";
else if (activity.status === "Completed") statusClass = "status-completed";
else if (activity.status === "Rejected") statusClass = "status-rejected";
activitiesHtml += `
<tr>
<td>#${activity.booking_id}</td>
<td>${activity.full_name}</td>
<td>${activity.service_name}</td>
<td><span class="status-badge ${statusClass}">${activity.status}</span></td>
<td>${activity.created_at}</td>
</tr>
`;
});
$("#recentOrdersTable").html(activitiesHtml);
} else {
console.error("Error fetching data:", response.message);
$("#recentOrdersTable").html("<tr><td colspan='5'>No recent activities found.</td></tr>");
}
},
error: function () {
console.error("Error loading recent activities.");
$("#recentOrdersTable").html("<tr><td colspan='5'>Error loading data.</td></tr>");
}
});
}
$(document).ready(function () {
loadAdminRecentActivities();
setInterval(loadAdminRecentActivities, 10000); // Auto-refresh every 10 seconds
});
</script>
<!-- script -->
<!-- Admins Recent Activities -->
</div>
<!-- Booking Management Section -->
<div id="users" class="section">
<div class="table-container">
<h2>Booking Management</h2>
<table>
<thead>
<tr>
<th>Booking ID</th>
<th>Name</th>
<th>Email</th>
<th>Services Booked</th>
<th>Preferred Date</th>
<th>Project Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody id="bookingTableBody">
<!-- Dynamic Data Will Be Loaded Here -->
</tbody>
</table>
</div>
</div>
<!-- jQuery Script to Load Bookings via AJAX -->
<script>
$(document).ready(function () {
loadBookings(); // Load booking data on page load
// Function to Load Booking Requests Dynamically
function loadBookings() {
$.ajax({
url: "fetch_bookings.php",
method: "GET",
success: function (data) {
$("#bookingTableBody").html(data);
},
error: function () {
alert("Error loading booking data.");
}
});
}
// Event Delegation for Accept/Reject Buttons (Fix for Dynamic Elements)
$(document).on("click", ".action-btn", function () {
let bookingId = $(this).data("id");
let action = $(this).data("action").toLowerCase(); // Normalize to lowercase
if (!confirm(`Are you sure you want to ${action} this booking?`)) {
return;
}
let newStatus = (action === "accept") ? "Pendings" : "Rejected"; // Fix Status
$.ajax({
url: "update_booking_status.php",
type: "POST",
data: { booking_id: bookingId, new_status: newStatus },
dataType: "json",
success: function (response) {
console.log("Response:", response);
if (response.status === "success") {
alert(response.message);
loadBookings(); // Reload bookings without refreshing page
} else {
alert("Error: " + response.message);
}
},
error: function () {
alert("Something went wrong! Please try again.");
}
});
});
});
</script>
<!-- Service Management Section -->
<div id="services" class="section">
<div class="table-container">
<h2>Service Management</h2>
<table>
<thead>
<tr>
<th>Category</th>
<th>Service Name</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody id="servicesTable">
<!-- Services will be loaded here via AJAX -->
</tbody>
</table>
</div>
</div>
<script>
// Fetch and display services
function loadServices() {
fetch('get-services.php')
.then(response => response.json())
.then(data => {
if (data.length === 0) {
document.getElementById("servicesTable").innerHTML = "<tr><td colspan='4' style='text-align:center; color:red;'>No services found.</td></tr>";
return;
}
let tableContent = '';
data.forEach(service => {
tableContent += `
<tr>
<td>${service.category}</td>
<td><input type="text" value="${service.title}" id="title_${service.id}"></td>
<td><input type="text" value="${service.description}" id="desc_${service.id}"></td>
<td><button onclick="updateService(${service.id})">Update</button></td>
</tr>
`;
});
document.getElementById("servicesTable").innerHTML = tableContent;
})
.catch(error => console.error("Error loading services:", error));
}
// Update service function
function updateService(serviceId) {
const title = document.getElementById(`title_${serviceId}`).value;
const description = document.getElementById(`desc_${serviceId}`).value;
fetch('update-service.php', {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: `id=${serviceId}&title=${encodeURIComponent(title)}&description=${encodeURIComponent(description)}`
})
.then(response => response.json())
.then(data => {
alert(data.message);
loadServices();
})
.catch(error => console.error("Error updating service:", error));
}
// Load services on page load
document.addEventListener("DOMContentLoaded", loadServices);
</script>
<!-- Script for ajax of service Managment -->
<!-- Order Management Section -->
<!-- Order Management Section -->
<div id="orders" class="section">
<div class="table-container">
<h2>Order Management</h2>
<table>
<thead>
<tr>
<th>Order ID</th>
<th>Client Name</th>
<th>Email</th>
<th>Service</th>
<th>Preferred Date</th>
<th>Project Details</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody id="orderTableBody">
<!-- Dynamic Data Will Be Loaded Here -->
</tbody>
</table>
</div>
</div>
<!-- jQuery Script to Load Orders via AJAX -->
<script>
function loadOrders() {
$.ajax({
url: "fetch_orders.php",
method: "GET",
success: function (data) {
$("#orderTableBody").html(data);
}
});
}
// Load orders when the page loads
$(document).ready(function () {
loadOrders();
});
</script>
<!-- update status dynamically -->
<script>
$(document).ready(function () {
$(document).on("click", ".update-status", function () {
let bookingId = $(this).data("id");
let newStatus = $(this).data("status");
let row = $(this).closest("tr");
// Confirmation popup
if (!confirm(`Are you sure you want to change status to ${newStatus}?`)) {
return;
}
$.ajax({
url: "update_order_status.php",
type: "POST",
data: { booking_id: bookingId, status: newStatus },
dataType: "json",
success: function (response) {
if (response.status === "success") {
alert("Order status updated successfully!");
// Update the status text in the table
row.find(".status-badge").text(newStatus);
row.find(".status-badge").removeClass("status-pending status-progress").addClass(newStatus === "In Progress" ? "status-progress" : "status-completed");
// Enable/disable buttons based on status
if (newStatus === "In Progress") {
row.find("[data-status='In Progress']").prop("disabled", true);
row.find("[data-status='Completed']").prop("disabled", false);
} else if (newStatus === "Completed") {
row.find("[data-status='Completed']").prop("disabled", true);
}
} else {
alert("Error: " + response.message);
}
},
error: function () {
alert("Something went wrong! Please try again.");
}
});
});
});
</script>
<!-- update status dynamically -->
<!-- Content Management Section -->
<!-- Content Management Section -->
<div id="content" class="section">
<div class="table-container">
<h2>Content Management</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Image</th>
<th>Title</th>
<th>Description</th>
<th>Last Updated</th>
<th>Action</th>
</tr>
</thead>
<tbody id="contentTable">
<!-- Blog data will be loaded here -->
</tbody>
</table>
</div>
</div>
<script>
function loadAdminContent() {
fetch("fetch_blogs.php")
.then(response => response.json())
.then(data => {
if (data.status === "success") {
let contentHtml = "";
data.blogs.forEach(blog => {
contentHtml += `
<tr>
<td>#${blog.blog_id}</td>
<td><img src="${blog.image}" width="100"></td>
<td>${blog.title}</td>
<td>${blog.description}</td>
<td>${new Date(blog.updated_at).toLocaleDateString()}</td>
<td>
<button onclick="editBlog(${blog.blog_id})">Edit</button>
</td>
</tr>
`;
});
document.getElementById("contentTable").innerHTML = contentHtml;
} else {
console.error("Failed to fetch blogs.");
}
})
.catch(error => console.error("Error loading blogs:", error));
}
// Load blogs on page load
document.addEventListener("DOMContentLoaded", loadAdminContent);
function editBlog(blog_id) {
const newTitle = prompt("Enter new title:");
const newDesc = prompt("Enter new description:");
const newLink = prompt("Enter new blog link:");
if (newTitle && newDesc && newLink) {
const formData = new FormData();
formData.append("blog_id", blog_id);
formData.append("title", newTitle);
formData.append("description", newDesc);
formData.append("blog_link", newLink);
fetch("update_blog.php", {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
if (data.status === "success") {
alert("Blog updated successfully!");
loadAdminContent();
} else {
alert("Update failed: " + data.message);
}
})
.catch(error => console.error("Error updating blog:", error));
}
}
</script>
<!-- Content Management Section -->
<!-- Reports & Analytics Section -->
<div id="reports" class="section">
<div class="stats-container">
<!-- <div class="stat-card">
<h3>Monthly Revenue</h3>
<p>₹12,450</p>
</div> -->
<!-- Total Users (Reports & Analytics) -->
<!-- <div class="stat-card">
<h3>Total Users</h3>
<p id="totalUsersReport">Loading...</p>
</div>
<script>
function loadTotalUsersReport() {
fetch('get_total_users.php?t=' + new Date().getTime()) // Prevent caching
.then(response => response.json())
.then(data => {
document.getElementById("totalUsersReport").innerText = data.total_users;
})
.catch(error => console.error("Error loading total users (Reports):", error));
}
// Run when page loads
document.addEventListener("DOMContentLoaded", loadTotalUsersReport);
</script> -->
<!-- Totsal users -->
<!-- Service Conversion -->
<div class="stat-card">
<h3>Service Conversion</h3>
<p id="serviceConversionRate">Loading...</p>
</div>
<script>
function loadServiceConversionRate() {
fetch('get_service_conversion.php')
.then(response => response.json())
.then(data => {
document.getElementById("serviceConversionRate").innerText = data.conversion_rate + "%";
})
.catch(error => console.error("Error loading service conversion rate:", error));
}
// Load on page load
document.addEventListener("DOMContentLoaded", loadServiceConversionRate);
</script>
<!-- Service Conversion -->
<!-- Customer Satisfaction -->
<div class="stat-card">
<h3>Customer Satisfaction</h3>
<p id="avg-satisfaction">0/5</p>
</div>
<!-- script for customer satisfaction -->
<script>
function fetchAverageSatisfaction() {
fetch('get_average_rating.php')
.then(response => response.json())
.then(data => {
const rating = data.avg_rating || 0;
document.getElementById("avg-satisfaction").textContent = `${rating}/5`;
})
.catch(err => console.error("Error fetching average satisfaction:", err));
}
// Call on page load
fetchAverageSatisfaction();
</script>
<!-- script for customer satisfaction -->
<!-- Customer Satisfaction -->
<!-- Stats Conatiner end div -->
</div>
<!-- Stats Conatiner end div -->
<div class="charts-grid">
<!-- <div class="chart-container">
<canvas id="revenueChart"></canvas>
</div> -->
<div class="chart-container" style="width: 40%;">
<canvas id="serviceChart"></canvas>
</div>
</div>
</div>
<!-- Contact Form response Section -->
<!-- Contact Form Responses Section -->
<div id="settings" class="section">
<div class="table-container">
<h2>Contact Form Submissions</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Subject</th>
<th>Message</th>
<th>Date</th>
</tr>
</thead>
<tbody id="contactMessagesTable">
<!-- Data will be loaded here -->
</tbody>
</table>
</div>
</div>
<!-- AjAx for Admin contact form -->
<script>
function loadContactMessages() {
$.ajax({
url: 'get_contact_messages.php',
method: 'GET',
dataType: 'json',
success: function (response) {
if (response.status === 'success') {
let rows = '';
response.messages.forEach(msg => {
rows += `
<tr>
<td>#${msg.id}</td>
<td>${msg.name}</td>
<td>${msg.email}</td>
<td>${msg.subject}</td>
<td>${msg.message}</td>
<td>${msg.submitted_at}</td>
</tr>
`;
});
$('#contactMessagesTable').html(rows);
}
}
});
}
$(document).ready(function () {
loadContactMessages();
setInterval(loadContactMessages, 10000); // refresh every 10s
});
</script>
<!-- AjAx for Admin contact form -->
<!-- Contact Form response Section -->
<!-- Feedback Management Section -->
<div id="feedback" class="section">
<div class="table-container">
<h2>User Feedback</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>User</th>
<th>Service</th>
<th>Rating</th>
<th>Comment</th>
<th>Date</th>
</tr>
</thead>
<tbody id="feedbackTableBody">
<!-- Loaded dynamically -->
</tbody>
</table>
<div id="pagination-controls" style="margin-top: 15px;"></div>
</div>
</div>
<script>
let currentPage = 1;
function loadFeedback(page = 1) {
$.ajax({
url: "get_feedback.php?page=" + page,
method: "GET",
dataType: "json",
success: function (response) {
if (response.status === "success") {
renderTable(response.feedback);
renderPagination(response.total_feedback, response.current_page);
} else {
$("#feedbackTableBody").html("<tr><td colspan='6'>No feedback found.</td></tr>");
}
},
error: function () {
$("#feedbackTableBody").html("<tr><td colspan='6'>Error loading feedback.</td></tr>");
}
});
}
function renderTable(feedbackList) {
let html = "";
feedbackList.forEach(item => {
let badgeColor = "badge-grey";
if (item.rating >= 4) badgeColor = "badge-green";
else if (item.rating == 3) badgeColor = "badge-yellow";
else badgeColor = "badge-red";
html += `
<tr>
<td>#${item.booking_id}</td>
<td>${item.full_name}</td>
<td>${item.service_name}</td>
<td><span class="status-badge ${badgeColor}">${item.rating}/5</span></td>
<td>${item.comment}</td>
<td>${item.submitted_at}</td>
</tr>
`;
});
$("#feedbackTableBody").html(html);
}
function renderPagination(total, current) {
let totalPages = Math.ceil(total / 5);
let paginationHtml = "";
for (let i = 1; i <= totalPages; i++) {
paginationHtml += `<button class="pagination-btn ${i === current ? 'active-page' : ''}" data-page="${i}">${i}</button>`;
}
$("#pagination-controls").html(paginationHtml);
}
$(document).ready(function () {
loadFeedback();
// Handle pagination click
$(document).on("click", ".pagination-btn", function () {
let page = $(this).data("page");
currentPage = page;
loadFeedback(page);
});
});
</script>
<style>
.status-badge.badge-green {
background: #16a34a;
color: white;
padding: 4px 8px;
border-radius: 4px;
}
.status-badge.badge-yellow {
background: #facc15;
color: black;
padding: 4px 8px;
border-radius: 4px;
}
.status-badge.badge-red {
background: #dc2626;
color: white;
padding: 4px 8px;
border-radius: 4px;
}
.status-badge.badge-grey {
background: #6b7280;
color: white;
padding: 4px 8px;
border-radius: 4px;