Skip to content

Commit e10d6e9

Browse files
authored
Merge pull request #38 from kasunmendis7/develop
Develop
2 parents b155b54 + 3e8380f commit e10d6e9

File tree

13 files changed

+326
-147
lines changed

13 files changed

+326
-147
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
DB_DSN = "mysql:host=localhost;dbname=fixmedb"
22
DB_USER = root
3-
DB_PASSWORD = Nimal@123
3+
DB_PASSWORD =

controllers/AdminController.php

+87-5
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,126 @@
55
use app\core\Application;
66
use app\core\Controller;
77
use app\core\Request;
8+
use app\models\Admin;
89
use app\models\Customer;
910
use app\models\Technician;
1011

1112
class AdminController extends Controller
1213
{
13-
public function dashboard()
14+
public function adminDashboard()
1415
{
1516
$this->setLayout('auth');
1617
return $this->render('/admin/dashboard');
1718
}
19+
1820
public function manageUsers()
1921
{
2022
$this->setLayout('auth');
2123
return $this->render('/admin/users');
2224
}
23-
public function settings()
25+
26+
public function adminSettings()
27+
{
28+
$this->setLayout('auth');
29+
return $this->render('/admin/admin-settings');
30+
}
31+
32+
public function adminProfile()
2433
{
2534
$this->setLayout('auth');
26-
return $this->render('/admin/settings');
35+
return $this->render('/admin/admin-profile');
36+
}
37+
38+
public function updateAdminProfile(Request $request)
39+
{
40+
$admin = new Admin();
41+
if ($request->isPost()) {
42+
$admin->loadData($request->getBody());
43+
if ($admin->updateValidate()) {
44+
$admin->updateAdmin();
45+
Application::$app->session->setFlash('update-success', 'You have been Updated your account info successfully!');
46+
Application::$app->response->redirect('/admin-profile');
47+
} else {
48+
Application::$app->response->redirect('/admin-profile');
49+
}
50+
}
2751
}
52+
2853
public function viewReports()
2954
{
3055
$this->setLayout('auth');
3156
return $this->render('/admin/reports');
3257
}
58+
3359
public function manageServices()
3460
{
3561
$this->setLayout('auth');
3662
return $this->render('/admin/services');
3763
}
64+
3865
public function adminLogin()
3966
{
4067
$this->setLayout('auth');
4168
return $this->render('/admin/admin-login.php');
4269
}
43-
4470

45-
71+
public function customers()
72+
{
73+
// Fetch all customers records
74+
$customers = Admin::findAllCustomers();
75+
// Render the all the customer in the database
76+
$this->setLayout('auth');
77+
return $this->render('/admin/customers', ['customers' => $customers]);
78+
79+
}
80+
81+
public function technicians()
82+
{
83+
// Fetch all technicians records
84+
$technicians = Admin::findAllTechnicians();
85+
// Render the all the customer in the database
86+
$this->setLayout('auth');
87+
return $this->render('/admin/technicians', ['technicians' => $technicians]);
88+
89+
}
90+
91+
public function deleteCustomer(Request $request)
92+
{
93+
$data = $request->getBody(); // Assuming this already returns an array
94+
if (isset($data['cus_id'])) {
95+
$cus_id = $data['cus_id'];
96+
97+
// Call the model function to delete the customer
98+
$result = Admin::deleteCustomerById($cus_id);
99+
100+
if ($result) {
101+
echo json_encode(['status' => 'success']);
102+
} else {
103+
echo json_encode(['status' => 'error', 'message' => 'Failed to delete customer']);
104+
}
105+
} else {
106+
echo json_encode(['status' => 'error', 'message' => 'Invalid customer ID']);
107+
}
108+
}
109+
110+
public function deleteTechnician(Request $request)
111+
{
112+
$data = $request->getBody(); // Assuming this already returns an array
113+
if (isset($data['tech_id'])) {
114+
$tech_id = $data['tech_id'];
115+
116+
// Call the model function to delete the technician
117+
$result = Admin::deleteTechnicianById($tech_id);
118+
119+
if ($result) {
120+
echo json_encode(['status' => 'success']);
121+
} else {
122+
echo json_encode(['status' => 'error', 'message' => 'Failed to delete technician']);
123+
}
124+
} else {
125+
echo json_encode(['status' => 'error', 'message' => 'Invalid technician ID']);
126+
}
127+
}
46128

47129
}
48130

models/Admin.php

+18
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ public static function findAllCustomers()
8989
return $statement->fetchAll(\PDO::FETCH_ASSOC);
9090
}
9191

92+
public static function findAllTechnicians()
93+
{
94+
$sql = "SELECT tech_id, fname, lname, email, phone_no, address, reg_date FROM technician";
95+
$statement = (new Admin)->prepare($sql);
96+
$statement->execute();
97+
return $statement->fetchAll(\PDO::FETCH_ASSOC);
98+
}
99+
92100
public static function deleteCustomerById($cus_id)
93101
{
94102
$db = Application::$app->db; // Ensure this points to the correct Database instance
@@ -99,4 +107,14 @@ public static function deleteCustomerById($cus_id)
99107

100108
}
101109

110+
public static function deleteTechnicianById($cus_id)
111+
{
112+
$db = Application::$app->db; // Ensure this points to the correct Database instance
113+
$sql = "DELETE FROM technician WHERE tech_id = :tech_id";
114+
$stmt = $db->prepare($sql);
115+
$stmt->bindParam(':tech_id', $tech_id, \PDO::PARAM_INT);
116+
return $stmt->execute();
117+
118+
}
119+
102120
}
493 KB
Loading

public/assets/uploads/Tools1.jpg

69.6 KB
Loading

public/css/service-center/add-products.css

+120-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
/* General Form Styling */
22
form {
33
max-width: 600px;
4-
margin: 2rem auto;
4+
margin: 2rem auto; /* Centers the form horizontally and adds vertical spacing */
55
padding: 1.5rem;
66
background-color: #f9f9f9;
77
border-radius: 8px;
88
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
99
font-family: Arial, sans-serif;
10+
display: flex;
11+
flex-direction: column;
12+
gap: 1rem;
1013
}
1114

1215
/* Label Styling */
1316
form label {
14-
display: block;
15-
margin-bottom: 0.5rem;
1617
font-weight: bold;
1718
color: #333;
19+
font-size: 1rem;
1820
}
1921

2022
/* Input and Textarea Styling */
@@ -23,12 +25,12 @@ form input[type="file"],
2325
form textarea {
2426
width: 100%;
2527
padding: 0.75rem;
26-
margin-bottom: 1rem;
2728
border: 1px solid #ccc;
2829
border-radius: 4px;
2930
font-size: 1rem;
3031
font-family: inherit;
3132
box-sizing: border-box;
33+
resize: none; /* Prevents textarea from being resized manually */
3234
}
3335

3436
/* Input and Textarea Focus Effects */
@@ -39,9 +41,17 @@ form textarea:focus {
3941
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
4042
}
4143

44+
/* File Input Styling */
45+
form input[type="file"] {
46+
padding: 0.5rem;
47+
font-size: 1rem;
48+
}
49+
4250
/* Button Styling */
4351
form button {
44-
display: inline-block;
52+
align-self: center;
53+
width: 100%;
54+
max-width: 200px;
4555
padding: 0.75rem 1.5rem;
4656
background-color: #007bff;
4757
color: white;
@@ -59,18 +69,119 @@ form button:hover {
5969
background-color: #0056b3;
6070
}
6171

62-
/* File Input Styling */
63-
form input[type="file"] {
64-
padding: 0.5rem;
72+
/* Centering the Form Container */
73+
.create-product-container {
74+
display: flex;
75+
flex-direction: column;
76+
align-items: center;
77+
justify-content: center;
78+
margin: 2rem auto;
79+
padding: 1rem;
80+
text-align: center;
81+
}
82+
83+
/* General Table Styling */
84+
table {
85+
width: 100%;
86+
border-collapse: collapse; /* Remove double borders */
87+
margin: 2rem auto; /* Center the table horizontally */
88+
background-color: #f9f9f9;
89+
font-family: Arial, sans-serif;
90+
font-size: 1rem;
91+
text-align: left;
92+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
93+
border-radius: 8px;
94+
overflow: hidden; /* Ensures rounded corners for tables with borders */
95+
}
96+
97+
/* Table Headers */
98+
table th {
99+
background-color: #007bff;
100+
color: #ffffff;
101+
padding: 0.75rem;
102+
text-align: left;
103+
font-weight: bold;
104+
}
105+
106+
/* Table Rows */
107+
table td {
108+
padding: 0.75rem;
109+
border-bottom: 1px solid #ddd; /* Light border between rows */
110+
}
111+
112+
/* Image in Table */
113+
table td img {
114+
width: 80px; /* Adjust image size */
115+
height: auto;
116+
border-radius: 4px;
117+
display: block;
118+
margin: 0 auto; /* Center the image */
65119
}
66120

121+
table td form {
122+
display: inline-block; /* Align forms inline */
123+
background: none; /* Remove default form background */
124+
border: none; /* Ensure no border exists */
125+
padding: 0; /* Remove unnecessary padding */
126+
margin: 0 0.25rem; /* Uniform margin */
127+
}
128+
129+
table td button {
130+
all: unset; /* Reset browser styles */
131+
padding: 0.5rem 1rem;
132+
background-color: #007bff;
133+
color: #fff;
134+
border-radius: 4px;
135+
cursor: pointer;
136+
font-size: 0.9rem;
137+
text-align: center;
138+
transition: background-color 0.3s ease;
139+
border: none;
140+
}
141+
142+
table td button:hover {
143+
background-color: #0056b3;
144+
}
145+
146+
147+
table td button:hover {
148+
background-color: #0056b3;
149+
}
150+
151+
/* Alternate Row Colors */
152+
table tr:nth-child(even) {
153+
background-color: #f2f2f2; /* Light gray for alternating rows */
154+
}
155+
156+
/* Highlight Row on Hover */
157+
table tr:hover {
158+
background-color: #e9ecef;
159+
}
160+
161+
/* Responsive Table */
162+
@media (max-width: 768px) {
163+
table {
164+
font-size: 0.9rem;
165+
}
166+
167+
table td, table th {
168+
padding: 0.5rem;
169+
}
170+
171+
table td img {
172+
width: 60px; /* Smaller image for mobile */
173+
}
174+
}
175+
176+
67177
/* Responsive Design */
68178
@media (max-width: 768px) {
69179
form {
70180
padding: 1rem;
71181
}
72182

73183
form button {
74-
width: 100%;
184+
width: 100%; /* Full width for small screens */
75185
}
76186
}
187+

public/index.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use app\controllers\ProductController;
1515

1616

17-
1817
/* load environment variables */
1918

2019
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
@@ -78,6 +77,7 @@
7877
/* Admin Routes */
7978
$app->router->get('/admin-dashboard', [AdminController::class, 'adminDashboard']);
8079
$app->router->get('/customers', [AdminController::class, 'customers']);
80+
$app->router->get('/technicians', [AdminController::class, 'technicians']);
8181
$app->router->post('/admin/delete-customer', [AdminController::class, 'deleteCustomer']);
8282
$app->router->get('/admin-settings', [AdminController::class, 'adminSettings']);
8383
$app->router->get('/admin-profile', [AdminController::class, 'adminProfile']);
@@ -114,16 +114,15 @@
114114
$app->router->post('/service-center-create-product', [ProductController::class, 'create']);
115115
$app->router->get('/market-place-home', [ProductController::class, 'index']);
116116
$app->router->get('/service-center-create-product', [ProductController::class, 'filterProductsById']);
117-
$app->router->get('/service-center-update-product', [ServiceCentreController::class,'update']);
117+
$app->router->get('/service-center-update-product', [ServiceCentreController::class, 'update']);
118118
$app->router->post('/service-center-update-product', [ProductController::class, 'update']);
119119

120120

121121
/** Admin Routes */
122-
$app->router->get('/admin-dashboard', [AdminController::class, 'dashboard']);
123-
$app->router->get('/admin-users', [AdminController::class, 'manageUsers']);
124-
$app->router->post('/admin-users-add', [AdminController::class, 'addUser']);
125-
$app->router->post('/admin-users-edit', [AdminController::class, 'editUser']);
126-
$app->router->post('/admin-users-delete', [AdminController::class, 'deleteUser']);
122+
$app->router->get('/admin-dashboard', [AdminController::class, 'adminDashboard']);
123+
$app->router->get('/customers', [AdminController::class, 'customers']);
124+
$app->router->post('/admin/delete-customer', [AdminController::class, 'deleteCustomer']);
125+
127126

128127
$app->router->get('/admin-services', [AdminController::class, 'manageServices']);
129128
$app->router->post('/admin-services-add', [AdminController::class, 'addService']);
@@ -133,7 +132,6 @@
133132
$app->router->get('/admin-reports', [AdminController::class, 'viewReports']);
134133
$app->router->post('/admin-reports-generate', [AdminController::class, 'generateReport']);
135134

136-
$app->router->get('/admin-settings', [AdminController::class, 'settings']);
137135
$app->router->post('/admin-settings-update', [AdminController::class, 'updateSettings']);
138136

139137
/* Admin Auth routes */

0 commit comments

Comments
 (0)