|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace app\controllers; |
| 4 | + |
| 5 | +use app\core\Application; |
| 6 | +use app\core\Controller; |
| 7 | +use app\core\Request; |
| 8 | +use app\models\Admin; |
| 9 | +use app\models\Customer; |
| 10 | +use app\models\Technician; |
| 11 | + |
| 12 | +class AdminController extends Controller |
| 13 | +{ |
| 14 | + public function adminDashboard() |
| 15 | + { |
| 16 | + $this->setLayout('auth'); |
| 17 | + return $this->render('/admin/dashboard'); |
| 18 | + } |
| 19 | + |
| 20 | + public function manageUsers() |
| 21 | + { |
| 22 | + $this->setLayout('auth'); |
| 23 | + return $this->render('/admin/users'); |
| 24 | + } |
| 25 | + |
| 26 | + public function adminSettings() |
| 27 | + { |
| 28 | + $this->setLayout('auth'); |
| 29 | + return $this->render('/admin/admin-settings'); |
| 30 | + } |
| 31 | + |
| 32 | + public function adminProfile() |
| 33 | + { |
| 34 | + $this->setLayout('auth'); |
| 35 | + return $this->render('/admin/admin-profile'); |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + public function viewReports() |
| 40 | + { |
| 41 | + $this->setLayout('auth'); |
| 42 | + return $this->render('/admin/reports'); |
| 43 | + } |
| 44 | + |
| 45 | + public function manageServices() |
| 46 | + { |
| 47 | + $this->setLayout('auth'); |
| 48 | + return $this->render('/admin/services'); |
| 49 | + } |
| 50 | + |
| 51 | + public function adminLogin() |
| 52 | + { |
| 53 | + $this->setLayout('auth'); |
| 54 | + return $this->render('/admin/admin-login.php'); |
| 55 | + } |
| 56 | + |
| 57 | + public function customers() |
| 58 | + { |
| 59 | + // Fetch all customers records |
| 60 | + $customers = Admin::findAllCustomers(); |
| 61 | + // Render the all the customer in the database |
| 62 | + $this->setLayout('auth'); |
| 63 | + return $this->render('/admin/customers', ['customers' => $customers]); |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + public function deleteCustomer(Request $request) |
| 68 | + { |
| 69 | + $data = $request->getBody(); // Assuming this already returns an array |
| 70 | + if (isset($data['cus_id'])) { |
| 71 | + $cus_id = $data['cus_id']; |
| 72 | + |
| 73 | + // Call the model function to delete the customer |
| 74 | + $result = Admin::deleteCustomerById($cus_id); |
| 75 | + |
| 76 | + if ($result) { |
| 77 | + echo json_encode(['status' => 'success']); |
| 78 | + } else { |
| 79 | + echo json_encode(['status' => 'error', 'message' => 'Failed to delete customer']); |
| 80 | + } |
| 81 | + } else { |
| 82 | + echo json_encode(['status' => 'error', 'message' => 'Invalid customer ID']); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | +} |
| 87 | + |
0 commit comments