Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6b72ee5
css changes in dashboard icons
Rathinarasa7Nimal Nov 30, 2024
1e68fd1
service centre tab is added to side bar
Rathinarasa7Nimal Dec 1, 2024
952b407
additonal file of admin-dashboard.php is deleted
Rathinarasa7Nimal Dec 2, 2024
14fb3e1
comment part of code is deleted in admin/dashboard
Rathinarasa7Nimal Jan 5, 2025
6e79270
admin dashboard retrieve counts of customers, technicians and service…
Rathinarasa7Nimal Jan 29, 2025
f40863d
the file is changed to dashboard to admin-dashboard
Rathinarasa7Nimal Jan 29, 2025
fb17bc5
Service centre fetching details from database added
Rathinarasa7Nimal Mar 3, 2025
435c127
added
Rathinarasa7Nimal Apr 13, 2025
070c413
Merge branch 'develop' into admin-dashboard
Rathinarasa7Nimal Apr 14, 2025
ac64c10
added css
Rathinarasa7Nimal Apr 14, 2025
42b3d3b
the change of technician name to service centre
Rathinarasa7Nimal Apr 14, 2025
6d9c113
service center id delete
Rathinarasa7Nimal Apr 14, 2025
55c8d86
change regards to service centre delete
Rathinarasa7Nimal Apr 15, 2025
8f77db9
files regard to service center
Rathinarasa7Nimal Apr 15, 2025
a618e31
search bar is added
Rathinarasa7Nimal Apr 15, 2025
91acd61
adding recent activities
Rathinarasa7Nimal Apr 16, 2025
c9677d8
Merge branch 'develop' into admin-dashboard
Rathinarasa7Nimal Apr 16, 2025
f28e778
changed layout in admin dashboard
Rathinarasa7Nimal Apr 19, 2025
9dddbf4
Merge branch 'develop' into admin-dashboard
Rathinarasa7Nimal Apr 19, 2025
94b9aeb
admin css
Rathinarasa7Nimal Apr 19, 2025
7556e04
css regards to nav bar
Rathinarasa7Nimal Apr 20, 2025
c674d4a
regarding the access of customers access
Rathinarasa7Nimal Apr 22, 2025
d221cd7
access property added for technician
Rathinarasa7Nimal Apr 22, 2025
ab560e0
the access of service-center added
Rathinarasa7Nimal Apr 22, 2025
b1c7127
user login name is added to side bar of admindashboard
Rathinarasa7Nimal Apr 22, 2025
f523780
service center access added
Rathinarasa7Nimal Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 60 additions & 42 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
use app\models\Customer;
use app\models\Promotion;
use app\models\Technician;
use app\models\ServiceCenter;

class AdminController extends Controller
{
public function adminDashboard()
{
$this->setLayout('auth');
// Fetch counts for technicians, customers, and service centers
$counts = Admin::countEntities();

$requestfromUsers = Admin::requestsFromUser();

// Set the layout and render the dashboard with counts
$this->setLayout('header');
return $this->render('/admin/admin-dashboard');
}


public function manageUsers()
{
$this->setLayout('auth');
Expand All @@ -27,7 +33,7 @@ public function manageUsers()

public function adminSettings()
{
$this->setLayout('auth');
$this->setLayout('header');
return $this->render('/admin/admin-settings');
}

Expand Down Expand Up @@ -55,7 +61,7 @@ public function updateAdminProfile(Request $request)

public function viewReports()
{
$this->setLayout('auth');
$this->setLayout('header');
return $this->render('/admin/reports');
}

Expand All @@ -74,7 +80,7 @@ public function adminLogin()

public function promotions()
{
$this->setLayout('auth');
$this->setLayout('header');
$promotions = Promotion::getAllPromotions();
return $this->render('/admin/admin-promotions', [
'promotions' => $promotions
Expand Down Expand Up @@ -139,7 +145,7 @@ public function customers()
// Fetch all customers records
$customers = Admin::findAllCustomers();
// Render the all the customer in the database
$this->setLayout('auth');
$this->setLayout('header');
return $this->render('/admin/customers', ['customers' => $customers]);

}
Expand All @@ -149,62 +155,74 @@ public function technicians()
// Fetch all technicians records
$technicians = Admin::findAllTechnicians();
// Render the all the customer in the database
$this->setLayout('auth');
$this->setLayout('header');
return $this->render('/admin/technicians', ['technicians' => $technicians]);

}
public function serviceCenters()
{
// Fetch all service centers records
$serviceCenters = Admin::findAllServiceCenters();
// Render the all the customer in the database
$this->setLayout('header');
return $this->render('/admin/admin-service-center', ['serviceCenters' => $serviceCenters]);

public function deleteCustomer(Request $request)
}

public function changeCustomerStatus(Request $request)
{
// Decode JSON payload manually since getBody() does not handle JSON
$data = json_decode(file_get_contents('php://input'), true);
$cus_id = $data['cus_id'] ?? null;
$status = $data['status'] ?? null;

// Debug: Log incoming data
error_log('Request payload: ' . print_r($data, true));
if ($cus_id && $status) {
$result = Admin::updateCustomerStatus($cus_id, $status); // Call the method to update the status
if ($result) {
echo json_encode(['status' => 'success', 'message' => 'Customer status updated successfully.']);
return;
}
}

if (isset($data['cus_id'])) {
$cus_id = $data['cus_id'];
echo json_encode(['status' => 'error', 'message' => 'Failed to update customer status.']);
}

// Call the model function to delete the customer
$result = Admin::deleteCustomerById($cus_id);
public function changeTechnicianStatus(Request $request)
{
$data = json_decode(file_get_contents('php://input'), true);
$tech_id = $data['tech_id'] ?? null;
$status = $data['status'] ?? null;

if ($tech_id && $status) {
$result = Admin::updateTechnicianStatus($tech_id, $status); // Call the method to update the status
if ($result) {
// Debug: Log successful deletion
error_log("Customer with ID $cus_id deleted successfully.");
echo json_encode(['status' => 'success']);
} else {
// Debug: Log failure
error_log("Failed to delete customer with ID $cus_id.");
echo json_encode(['status' => 'error', 'message' => 'Failed to delete customer']);
echo json_encode(['status' => 'success', 'message' => 'Technician status updated successfully.']);
return;
}
} else {
// Debug: Log invalid request
error_log("Invalid customer ID in request payload.");
echo json_encode(['status' => 'error', 'message' => 'Invalid customer ID']);
}
}

echo json_encode(['status' => 'error', 'message' => 'Failed to update technician status.']);
}

public function deleteTechnician(Request $request)
public function changeServiceCenterStatus(Request $request)
{
$data = json_decode(file_get_contents("php://input"), true);

if (isset($data['tech_id'])) {
$tech_id = $data['tech_id'];

// Call model to delete technician
$result = Admin::deleteTechnicianById($tech_id);
$data = json_decode(file_get_contents('php://input'), true);
$ser_cen_id = $data['ser_cen_id'] ?? null;
error_log("service cneter id: ", print_r($ser_cen_id, true));
$status = $data['status'] ?? null;

if ($ser_cen_id && $status) {
$result = Admin::updateServiceCenterStatus($ser_cen_id, $status); // Call the method to update the status
if ($result) {
return $response->json(['status' => 'success']);
} else {
return $response->json(['status' => 'error', 'message' => 'Failed to delete technician']);
echo json_encode(['status' => 'success', 'message' => 'Service center status updated successfully.']);
return;
}
} else {
return $response->json(['status' => 'error', 'message' => 'Invalid technician ID']);
}
}

echo json_encode(['status' => 'error', 'message' => 'Failed to update service center status.']);

}


}

}
1 change: 1 addition & 0 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Application
public Controller $controller;
public ?DbModel $customer;
public ?DbModel $serviceCenter;
public ?DbModel $admin;

public function __construct($rootPath, array $config)
{
Expand Down
81 changes: 72 additions & 9 deletions models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,105 @@ public function attributes(): array
'password',
];
}
public static function requestsfromUser()
{
$sql = "SELECT * FROM cus_tech_req ORDER BY date DESC LIMIT 3";
$statement = (new Admin)->prepare($sql);
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}

public static function findAllCustomers()
{
$sql = "SELECT cus_id, fname, lname, email, phone_no, address, reg_date FROM customer";
$sql = "SELECT cus_id, fname, lname, email, phone_no, address, reg_date,status FROM customer";
$statement = (new Admin)->prepare($sql);
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}

public static function findAllTechnicians()
{
$sql = "SELECT tech_id, fname, lname, email, phone_no, address, reg_date FROM technician";
$sql = "SELECT tech_id, fname, lname, email, phone_no, address, reg_date,status FROM technician";
$statement = (new Admin)->prepare($sql);
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
public static function findAllServiceCenters()
{
$sql = "SELECT ser_cen_id, name, email, phone_no, address, reg_date, status FROM service_center";
$statement = (new Admin)->prepare($sql);
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
public static function countTechnicians()
{
// Query to count total technicians
$sql = "SELECT COUNT(*) AS technicianCount FROM technician";
$statement = (new Admin)->prepare($sql);
$statement->execute();
$result = $statement->fetch(\PDO::FETCH_ASSOC);

public static function deleteCustomerById($cus_id)
// Return the count
return (int)($result['technicianCount'] ?? 0);
}
public static function updateCustomerStatus($cus_id, $status)
{
$db = Application::$app->db; // Ensure this points to the correct Database instance
$sql = "DELETE FROM customer WHERE cus_id = :cus_id";
$db = Application::$app->db;
$sql = "UPDATE customer SET status = :status WHERE cus_id = :cus_id";
$stmt = $db->prepare($sql);
$stmt->bindValue(':status', $status, \PDO::PARAM_STR);
$stmt->bindValue(':cus_id', (int)$cus_id, \PDO::PARAM_INT);
return $stmt->execute();

}

public static function deleteTechnicianById($tech_id)
public static function updateTechnicianStatus($tech_id, $status)
{
$db = Application::$app->db; // Database instance
$sql = "DELETE FROM technician WHERE tech_id = :tech_id";
$db = Application::$app->db;
$sql = "UPDATE technician SET status = :status WHERE tech_id = :tech_id";
$stmt = $db->prepare($sql);
$stmt->bindValue(':status', $status, \PDO::PARAM_STR);
$stmt->bindValue(':tech_id', (int)$tech_id, \PDO::PARAM_INT);
return $stmt->execute();
}

public static function updateServiceCenterStatus($ser_cen_id, $status)
{
$db = Application::$app->db;
$sql = "UPDATE service_center SET status = :status WHERE ser_cen_id = :ser_cen_id";
$stmt = $db->prepare($sql);
$stmt->bindValue(':status', $status, \PDO::PARAM_STR);
$stmt->bindValue(':ser_cen_id', (int)$ser_cen_id, \PDO::PARAM_INT);
return $stmt->execute();
}
public static function countEntities()
{
$db = new Admin();

// Query to count total technicians
$sqlTech = "SELECT COUNT(*) AS technicianCount FROM technician";
$stmtTech = $db->prepare($sqlTech);
$stmtTech->execute();
$technicianCount = (int)($stmtTech->fetch(\PDO::FETCH_ASSOC)['technicianCount'] ?? 0);

// Query to count total customers
$sqlCust = "SELECT COUNT(*) AS customerCount FROM customer";
$stmtCust = $db->prepare($sqlCust);
$stmtCust->execute();
$customerCount = (int)($stmtCust->fetch(\PDO::FETCH_ASSOC)['customerCount'] ?? 0);

// Query to count total service centers
$sqlSC = "SELECT COUNT(*) AS serviceCentreCount FROM service_center";
$stmtSC = $db->prepare($sqlSC);
$stmtSC->execute();
$serviceCentreCount = (int)($stmtSC->fetch(\PDO::FETCH_ASSOC)['serviceCentreCount'] ?? 0);

return [
'technicianCount' => $technicianCount,
'customerCount' => $customerCount,
'serviceCentreCount' => $serviceCentreCount
];
}

public function countTotalTechnicians()
{
$sql = "SELECT COUNT(*) as total FROM technician";
Expand Down
4 changes: 4 additions & 0 deletions models/CustomerLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function login()
return false;
}

if ($customer->status === 'Access Denied') {
$this->addErrorMessage('email', 'Your account access has been denied. Please contact support.');
return false;
}
show($customer);

return Application::$app->loginCustomer($customer);
Expand Down
5 changes: 5 additions & 0 deletions models/ServiceCenterLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function loginServiceCenter()
return false;
}

if ($service_center->status == 'Access Denied') {
$this->addErrorMessage('email', 'Your account access has been denied. Please contact support.');
return false;
}

return Application::$app->loginServiceCenter($service_center);
}
}
5 changes: 5 additions & 0 deletions models/TechnicianLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function loginTechnician()
return false;
}

if ($technician->status === 'Access Denied') {
$this->addError('email', 'Your account access has been denied. Please contact support.');
return false;
}

return Application::$app->loginTechnician($technician);
}
}
Loading