Skip to content

Commit 8cc823a

Browse files
authoredNov 23, 2024
Merge branch 'develop' into feature/service-centre
2 parents 86b1d34 + 9593c06 commit 8cc823a

31 files changed

+1884
-464
lines changed
 

‎.env

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

‎controllers/AdminController.php

+99-4
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,139 @@
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+
20+
21+
1822
public function manageUsers()
1923
{
2024
$this->setLayout('auth');
2125
return $this->render('/admin/users');
2226
}
23-
public function settings()
27+
28+
public function adminSettings()
2429
{
2530
$this->setLayout('auth');
26-
return $this->render('/admin/settings');
31+
return $this->render('/admin/admin-settings');
2732
}
33+
34+
public function adminProfile()
35+
36+
{
37+
$this->setLayout('auth');
38+
return $this->render('/admin/admin-profile');
39+
}
40+
41+
public function updateAdminProfile(Request $request)
42+
{
43+
$admin = new Admin();
44+
if ($request->isPost()) {
45+
$admin->loadData($request->getBody());
46+
if ($admin->updateValidate()) {
47+
$admin->updateAdmin();
48+
Application::$app->session->setFlash('update-success', 'You have been Updated your account info successfully!');
49+
Application::$app->response->redirect('/admin-profile');
50+
} else {
51+
Application::$app->response->redirect('/admin-profile');
52+
}
53+
}
54+
}
55+
2856
public function viewReports()
2957
{
3058
$this->setLayout('auth');
3159
return $this->render('/admin/reports');
3260
}
61+
3362
public function manageServices()
3463
{
3564
$this->setLayout('auth');
3665
return $this->render('/admin/services');
3766
}
67+
3868
public function adminLogin()
3969
{
4070
$this->setLayout('auth');
4171
return $this->render('/admin/admin-login.php');
4272
}
43-
4473

4574

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

47142
}
48143

‎controllers/AuthController.php

-22
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,6 @@ public function serviceCenterLogout(Request $request, Response $response)
165165
$response->redirect('/service-centre-landing');
166166
}
167167

168-
/* admin sign up method */
169-
public function adminSignUp(Request $request)
170-
{
171-
$admin = new Admin();
172-
if ($request->isPost()) {
173-
174-
$admin->loadData($request->getBody());
175-
if ($admin->validate() && $admin->save()) {
176-
Application::$app->session->setFlash('success', 'You have been registered successfully!');
177-
Application::$app->response->redirect('/admin-login');
178-
}
179-
$this->setLayout('auth');
180-
return $this->render('/admin/admin-sign-up', [
181-
'model' => $admin
182-
]);
183-
}
184-
$this->setLayout('auth');
185-
return $this->render('/admin/admin-sign-up', [
186-
'model' => $admin
187-
]);
188-
}
189-
190168
/* admin login method */
191169
public function adminLogin(Request $request, Response $response)
192170
{

‎controllers/AuthController.php~

-189
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.