Skip to content

Commit b6d9115

Browse files
committedNov 23, 2024
added admin update functionality
1 parent ea06e40 commit b6d9115

File tree

5 files changed

+110
-109
lines changed

5 files changed

+110
-109
lines changed
 

‎controllers/AdminController.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,31 @@ public function manageUsers()
2323
return $this->render('/admin/users');
2424
}
2525

26-
public function settings()
26+
public function adminSettings()
2727
{
2828
$this->setLayout('auth');
29-
return $this->render('/admin/settings');
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+
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+
}
3051
}
3152

3253
public function viewReports()

‎controllers/AdminController.php~

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+

‎public/index.php

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
$app->router->get('/admin-reports', [AdminController::class, 'viewReports']);
132132
$app->router->post('/admin-reports-generate', [AdminController::class, 'generateReport']);
133133

134-
$app->router->get('/admin-settings', [AdminController::class, 'settings']);
135134
$app->router->post('/admin-settings-update', [AdminController::class, 'updateSettings']);
136135

137136
/* Admin Auth routes */

‎views/admin/settings.php

-24
This file was deleted.

‎views/admin/users.php

-82
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.