|
5 | 5 | use app\core\Application;
|
6 | 6 | use app\core\Controller;
|
7 | 7 | use app\core\Request;
|
| 8 | +use app\models\Admin; |
8 | 9 | use app\models\Customer;
|
9 | 10 | use app\models\Technician;
|
10 | 11 |
|
11 | 12 | class AdminController extends Controller
|
12 | 13 | {
|
13 |
| - public function dashboard() |
| 14 | + public function adminDashboard() |
14 | 15 | {
|
15 | 16 | $this->setLayout('auth');
|
16 | 17 | return $this->render('/admin/dashboard');
|
17 | 18 | }
|
| 19 | + |
| 20 | + |
| 21 | + |
18 | 22 | public function manageUsers()
|
19 | 23 | {
|
20 | 24 | $this->setLayout('auth');
|
21 | 25 | return $this->render('/admin/users');
|
22 | 26 | }
|
23 |
| - public function settings() |
| 27 | + |
| 28 | + public function adminSettings() |
24 | 29 | {
|
25 | 30 | $this->setLayout('auth');
|
26 |
| - return $this->render('/admin/settings'); |
| 31 | + return $this->render('/admin/admin-settings'); |
27 | 32 | }
|
| 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 | + |
28 | 56 | public function viewReports()
|
29 | 57 | {
|
30 | 58 | $this->setLayout('auth');
|
31 | 59 | return $this->render('/admin/reports');
|
32 | 60 | }
|
| 61 | + |
33 | 62 | public function manageServices()
|
34 | 63 | {
|
35 | 64 | $this->setLayout('auth');
|
36 | 65 | return $this->render('/admin/services');
|
37 | 66 | }
|
| 67 | + |
38 | 68 | public function adminLogin()
|
39 | 69 | {
|
40 | 70 | $this->setLayout('auth');
|
41 | 71 | return $this->render('/admin/admin-login.php');
|
42 | 72 | }
|
43 |
| - |
44 | 73 |
|
45 | 74 |
|
| 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 | + |
46 | 141 |
|
47 | 142 | }
|
48 | 143 |
|
0 commit comments