Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #38

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DB_DSN = "mysql:host=localhost;dbname=fixmedb"
DB_USER = root
DB_PASSWORD = Nimal@123
DB_PASSWORD =
92 changes: 87 additions & 5 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,126 @@
use app\core\Application;
use app\core\Controller;
use app\core\Request;
use app\models\Admin;
use app\models\Customer;
use app\models\Technician;

class AdminController extends Controller
{
public function dashboard()
public function adminDashboard()
{
$this->setLayout('auth');
return $this->render('/admin/dashboard');
}

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

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

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

public function updateAdminProfile(Request $request)
{
$admin = new Admin();
if ($request->isPost()) {
$admin->loadData($request->getBody());
if ($admin->updateValidate()) {
$admin->updateAdmin();
Application::$app->session->setFlash('update-success', 'You have been Updated your account info successfully!');
Application::$app->response->redirect('/admin-profile');
} else {
Application::$app->response->redirect('/admin-profile');
}
}
}

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

public function manageServices()
{
$this->setLayout('auth');
return $this->render('/admin/services');
}

public function adminLogin()
{
$this->setLayout('auth');
return $this->render('/admin/admin-login.php');
}



public function customers()
{
// Fetch all customers records
$customers = Admin::findAllCustomers();
// Render the all the customer in the database
$this->setLayout('auth');
return $this->render('/admin/customers', ['customers' => $customers]);

}

public function technicians()
{
// Fetch all technicians records
$technicians = Admin::findAllTechnicians();
// Render the all the customer in the database
$this->setLayout('auth');
return $this->render('/admin/technicians', ['technicians' => $technicians]);

}

public function deleteCustomer(Request $request)
{
$data = $request->getBody(); // Assuming this already returns an array
if (isset($data['cus_id'])) {
$cus_id = $data['cus_id'];

// Call the model function to delete the customer
$result = Admin::deleteCustomerById($cus_id);

if ($result) {
echo json_encode(['status' => 'success']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to delete customer']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid customer ID']);
}
}

public function deleteTechnician(Request $request)
{
$data = $request->getBody(); // Assuming this already returns an array
if (isset($data['tech_id'])) {
$tech_id = $data['tech_id'];

// Call the model function to delete the technician
$result = Admin::deleteTechnicianById($tech_id);

if ($result) {
echo json_encode(['status' => 'success']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to delete technician']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid technician ID']);
}
}

}

18 changes: 18 additions & 0 deletions models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public static function findAllCustomers()
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}

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

public static function deleteCustomerById($cus_id)
{
$db = Application::$app->db; // Ensure this points to the correct Database instance
Expand All @@ -99,4 +107,14 @@ public static function deleteCustomerById($cus_id)

}

public static function deleteTechnicianById($cus_id)
{
$db = Application::$app->db; // Ensure this points to the correct Database instance
$sql = "DELETE FROM technician WHERE tech_id = :tech_id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':tech_id', $tech_id, \PDO::PARAM_INT);
return $stmt->execute();

}

}
Binary file added public/assets/uploads/6741a7eb25785_Car1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/uploads/Tools1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 120 additions & 9 deletions public/css/service-center/add-products.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/* General Form Styling */
form {
max-width: 600px;
margin: 2rem auto;
margin: 2rem auto; /* Centers the form horizontally and adds vertical spacing */
padding: 1.5rem;
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
gap: 1rem;
}

/* Label Styling */
form label {
display: block;
margin-bottom: 0.5rem;
font-weight: bold;
color: #333;
font-size: 1rem;
}

/* Input and Textarea Styling */
Expand All @@ -23,12 +25,12 @@ form input[type="file"],
form textarea {
width: 100%;
padding: 0.75rem;
margin-bottom: 1rem;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
font-family: inherit;
box-sizing: border-box;
resize: none; /* Prevents textarea from being resized manually */
}

/* Input and Textarea Focus Effects */
Expand All @@ -39,9 +41,17 @@ form textarea:focus {
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}

/* File Input Styling */
form input[type="file"] {
padding: 0.5rem;
font-size: 1rem;
}

/* Button Styling */
form button {
display: inline-block;
align-self: center;
width: 100%;
max-width: 200px;
padding: 0.75rem 1.5rem;
background-color: #007bff;
color: white;
Expand All @@ -59,18 +69,119 @@ form button:hover {
background-color: #0056b3;
}

/* File Input Styling */
form input[type="file"] {
padding: 0.5rem;
/* Centering the Form Container */
.create-product-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 2rem auto;
padding: 1rem;
text-align: center;
}

/* General Table Styling */
table {
width: 100%;
border-collapse: collapse; /* Remove double borders */
margin: 2rem auto; /* Center the table horizontally */
background-color: #f9f9f9;
font-family: Arial, sans-serif;
font-size: 1rem;
text-align: left;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden; /* Ensures rounded corners for tables with borders */
}

/* Table Headers */
table th {
background-color: #007bff;
color: #ffffff;
padding: 0.75rem;
text-align: left;
font-weight: bold;
}

/* Table Rows */
table td {
padding: 0.75rem;
border-bottom: 1px solid #ddd; /* Light border between rows */
}

/* Image in Table */
table td img {
width: 80px; /* Adjust image size */
height: auto;
border-radius: 4px;
display: block;
margin: 0 auto; /* Center the image */
}

table td form {
display: inline-block; /* Align forms inline */
background: none; /* Remove default form background */
border: none; /* Ensure no border exists */
padding: 0; /* Remove unnecessary padding */
margin: 0 0.25rem; /* Uniform margin */
}

table td button {
all: unset; /* Reset browser styles */
padding: 0.5rem 1rem;
background-color: #007bff;
color: #fff;
border-radius: 4px;
cursor: pointer;
font-size: 0.9rem;
text-align: center;
transition: background-color 0.3s ease;
border: none;
}

table td button:hover {
background-color: #0056b3;
}


table td button:hover {
background-color: #0056b3;
}

/* Alternate Row Colors */
table tr:nth-child(even) {
background-color: #f2f2f2; /* Light gray for alternating rows */
}

/* Highlight Row on Hover */
table tr:hover {
background-color: #e9ecef;
}

/* Responsive Table */
@media (max-width: 768px) {
table {
font-size: 0.9rem;
}

table td, table th {
padding: 0.5rem;
}

table td img {
width: 60px; /* Smaller image for mobile */
}
}


/* Responsive Design */
@media (max-width: 768px) {
form {
padding: 1rem;
}

form button {
width: 100%;
width: 100%; /* Full width for small screens */
}
}

14 changes: 6 additions & 8 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use app\controllers\ProductController;



/* load environment variables */

$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
Expand Down Expand Up @@ -78,6 +77,7 @@
/* Admin Routes */
$app->router->get('/admin-dashboard', [AdminController::class, 'adminDashboard']);
$app->router->get('/customers', [AdminController::class, 'customers']);
$app->router->get('/technicians', [AdminController::class, 'technicians']);
$app->router->post('/admin/delete-customer', [AdminController::class, 'deleteCustomer']);
$app->router->get('/admin-settings', [AdminController::class, 'adminSettings']);
$app->router->get('/admin-profile', [AdminController::class, 'adminProfile']);
Expand Down Expand Up @@ -114,16 +114,15 @@
$app->router->post('/service-center-create-product', [ProductController::class, 'create']);
$app->router->get('/market-place-home', [ProductController::class, 'index']);
$app->router->get('/service-center-create-product', [ProductController::class, 'filterProductsById']);
$app->router->get('/service-center-update-product', [ServiceCentreController::class,'update']);
$app->router->get('/service-center-update-product', [ServiceCentreController::class, 'update']);
$app->router->post('/service-center-update-product', [ProductController::class, 'update']);


/** Admin Routes */
$app->router->get('/admin-dashboard', [AdminController::class, 'dashboard']);
$app->router->get('/admin-users', [AdminController::class, 'manageUsers']);
$app->router->post('/admin-users-add', [AdminController::class, 'addUser']);
$app->router->post('/admin-users-edit', [AdminController::class, 'editUser']);
$app->router->post('/admin-users-delete', [AdminController::class, 'deleteUser']);
$app->router->get('/admin-dashboard', [AdminController::class, 'adminDashboard']);
$app->router->get('/customers', [AdminController::class, 'customers']);
$app->router->post('/admin/delete-customer', [AdminController::class, 'deleteCustomer']);


$app->router->get('/admin-services', [AdminController::class, 'manageServices']);
$app->router->post('/admin-services-add', [AdminController::class, 'addService']);
Expand All @@ -133,7 +132,6 @@
$app->router->get('/admin-reports', [AdminController::class, 'viewReports']);
$app->router->post('/admin-reports-generate', [AdminController::class, 'generateReport']);

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

/* Admin Auth routes */
Expand Down
Loading