Skip to content

Commit ba14479

Browse files
committed
finishing ui components
2 parents a843be7 + 57b0598 commit ba14479

39 files changed

+2219
-343
lines changed

controllers/AdminController.php

+20-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public function adminDashboard()
1818
}
1919

2020

21-
2221
public function manageUsers()
2322
{
2423
$this->setLayout('auth');
@@ -71,13 +70,12 @@ public function adminLogin()
7170
return $this->render('/admin/admin-login.php');
7271
}
7372

74-
73+
7574
public function promotions()
7675
{
7776
$this->setLayout('auth');
7877
return $this->render('/admin/admin-promotions');
7978
}
80-
8179

8280

8381
public function customers()
@@ -102,39 +100,52 @@ public function technicians()
102100

103101
public function deleteCustomer(Request $request)
104102
{
105-
$data = $request->getBody(); // Assuming this already returns an array
103+
// Decode JSON payload manually since getBody() does not handle JSON
104+
$data = json_decode(file_get_contents('php://input'), true);
105+
106+
// Debug: Log incoming data
107+
error_log('Request payload: ' . print_r($data, true));
108+
106109
if (isset($data['cus_id'])) {
107110
$cus_id = $data['cus_id'];
108111

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

112115
if ($result) {
116+
// Debug: Log successful deletion
117+
error_log("Customer with ID $cus_id deleted successfully.");
113118
echo json_encode(['status' => 'success']);
114119
} else {
120+
// Debug: Log failure
121+
error_log("Failed to delete customer with ID $cus_id.");
115122
echo json_encode(['status' => 'error', 'message' => 'Failed to delete customer']);
116123
}
117124
} else {
125+
// Debug: Log invalid request
126+
error_log("Invalid customer ID in request payload.");
118127
echo json_encode(['status' => 'error', 'message' => 'Invalid customer ID']);
119128
}
120129
}
121130

131+
122132
public function deleteTechnician(Request $request)
123133
{
124-
$data = $request->getBody(); // Assuming this already returns an array
134+
$data = json_decode(file_get_contents("php://input"), true);
135+
125136
if (isset($data['tech_id'])) {
126137
$tech_id = $data['tech_id'];
127138

128-
// Call the model function to delete the technician
139+
// Call model to delete technician
129140
$result = Admin::deleteTechnicianById($tech_id);
130141

131142
if ($result) {
132-
echo json_encode(['status' => 'success']);
143+
return $response->json(['status' => 'success']);
133144
} else {
134-
echo json_encode(['status' => 'error', 'message' => 'Failed to delete technician']);
145+
return $response->json(['status' => 'error', 'message' => 'Failed to delete technician']);
135146
}
136147
} else {
137-
echo json_encode(['status' => 'error', 'message' => 'Invalid technician ID']);
148+
return $response->json(['status' => 'error', 'message' => 'Invalid technician ID']);
138149
}
139150
}
140151

controllers/CustomerController.php

+40
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public function customerTechnicians()
4646
return $this->render('/customer/customer-technicians');
4747
}
4848

49+
public function customerServiceCenter()
50+
{
51+
$this->setLayout('auth');
52+
return $this->render('/customer/customer-serviceCenter');
53+
}
54+
55+
public function serviceCenterProfile()
56+
{
57+
$this->setLayout('auth');
58+
return $this->render('/customer/service-center-profile');
59+
}
60+
4961
public function customerMap()
5062
{
5163
$this->setLayout('auth');
@@ -125,6 +137,34 @@ public function cusTechReq()
125137
}
126138
}
127139

140+
public function deleteCusTechReq()
141+
{
142+
header('Content-type: application/json');
143+
144+
try {
145+
$jsonData = file_get_contents('php://input');
146+
$data = json_decode($jsonData, true);
147+
148+
$customerId = $data['cus_id'];
149+
$technicianId = $data['tech_id'];
150+
151+
if (!$customerId || !$technicianId) {
152+
Application::$app->response->setStatusCode(400);
153+
return json_encode(['success' => false, 'error' => 'Missing the required parameter customerId, technicianId']);
154+
exit;
155+
}
156+
157+
$cusReq = new CusTechReq();
158+
$res = $cusReq->deleteCusTechReq($customerId, $technicianId);
159+
return json_encode($res);
160+
161+
} catch (\Exception $e) {
162+
Application::$app->response->setStatusCode(500);
163+
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
164+
}
165+
166+
}
167+
128168
public function fixmeCommunity()
129169
{
130170

controllers/TechnicianController.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ public function viewTechnicianProfile($id)
116116
return $this->render('_404');
117117
}
118118
// show($technician['fname']);
119-
return $this->render('/customer/technician-profile', ['technician' => $technician]);
119+
$postModel = new Post();
120+
$posts = $postModel->getPostsByTechnicianId(intval($id[0]));
121+
122+
return $this->render('/customer/technician-profile', [
123+
'technician' => $technician,
124+
'posts' => $posts
125+
]);
120126
}
121127

122128
public function viewRequests()
@@ -146,5 +152,7 @@ public function updateRequestStatus($request)
146152
}
147153
Application::$app->response->redirect('/technician-requests');
148154
}
155+
156+
149157
}
150158

models/Admin.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ public static function deleteCustomerById($cus_id)
102102
$db = Application::$app->db; // Ensure this points to the correct Database instance
103103
$sql = "DELETE FROM customer WHERE cus_id = :cus_id";
104104
$stmt = $db->prepare($sql);
105-
$stmt->bindParam(':cus_id', $cus_id, \PDO::PARAM_INT);
105+
$stmt->bindValue(':cus_id', (int)$cus_id, \PDO::PARAM_INT);
106106
return $stmt->execute();
107107

108108
}
109109

110-
public static function deleteTechnicianById($cus_id)
110+
public static function deleteTechnicianById($tech_id)
111111
{
112-
$db = Application::$app->db; // Ensure this points to the correct Database instance
112+
$db = Application::$app->db; // Database instance
113113
$sql = "DELETE FROM technician WHERE tech_id = :tech_id";
114114
$stmt = $db->prepare($sql);
115-
$stmt->bindParam(':tech_id', $tech_id, \PDO::PARAM_INT);
115+
$stmt->bindValue(':tech_id', (int)$tech_id, \PDO::PARAM_INT);
116116
return $stmt->execute();
117-
118117
}
119118

119+
120120
}

models/CusTechReq.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,38 @@ public function createCusTechReq($cusId, $techId)
4242
}
4343
}
4444

45+
public function deleteCusTechReq($cusId, $techId)
46+
{
47+
/* Check if a pending request from customer to technician already exits in the database */
48+
$sql = "SELECT req_id FROM cus_tech_req WHERE cus_id = :cus_id AND tech_id = :tech_id";
49+
$stmt = self::prepare($sql);
50+
$stmt->bindValue(':cus_id', $cusId);
51+
$stmt->bindValue(':tech_id', $techId);
52+
$stmt->execute();
53+
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
54+
55+
if ($row) {
56+
$sql = "DELETE FROM cus_tech_req WHERE cus_id = :cus_id AND tech_id = :tech_id";
57+
$stmt = self::prepare($sql);
58+
$stmt->bindValue(':cus_id', $cusId);
59+
$stmt->bindValue(':tech_id', $techId);
60+
$stmt->execute();
61+
Application::$app->response->setStatusCode(200);
62+
Application::$app->session->setflash('deleteCusTechReq-success', 'You have been successfully deleted the request !');
63+
64+
return ['success' => true, 'message' => 'Customer request deleted succesfully'];
65+
66+
} else {
67+
Application::$app->response->setStatusCode(400);
68+
Application::$app->session->setFlash('deleteCusTechReq-error', 'You have already been deleted the request for this technician !');
69+
70+
return ['success' => false, 'message' => 'Unable to delete technician request !'];
71+
}
72+
}
73+
4574
public function getAllRequests($cusId)
4675
{
47-
$sql = "SELECT tech.fname AS fname, tech.lname AS lname, ctr.status AS status FROM technician AS tech, cus_tech_req AS ctr WHERE ctr.tech_id = tech.tech_id AND ctr.cus_id = :cus_id";
76+
$sql = "SELECT ctr.tech_id AS tech_id, ctr.cus_id AS cus_id, tech.fname AS fname, tech.lname AS lname, ctr.status AS status FROM technician AS tech, cus_tech_req AS ctr WHERE ctr.tech_id = tech.tech_id AND ctr.cus_id = :cus_id";
4877
$stmt = self::prepare($sql);
4978
$stmt->bindValue(':cus_id', $cusId);
5079
$stmt->execute();

models/Post.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace app\models;
44

55
use app\core\DbModel;
6+
use app\core\Application;
67

78
class Post extends DbModel
89
{
@@ -113,5 +114,15 @@ public function updateRules(): array
113114

114115
];
115116
}
116-
}
117117

118+
// In models/Post.php
119+
public function getPostsByTechnicianId($id)
120+
{
121+
$sql = "SELECT * FROM post WHERE tech_id = :tech_id ORDER BY created_at DESC";
122+
$stmt = self::prepare($sql);
123+
$stmt->bindValue(':tech_id', $id);
124+
$stmt->execute();
125+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
126+
}
127+
128+
}

models/ServiceCenter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function serviceCentreAddressGeocoding()
6666

6767
public function serviceCentresGeocoding()
6868
{
69-
$sql = "SELECT ser_cen_id, name, latitude, longitude FROM service_center WHERE latitude IS NOT NULL AND longitude IS NOT NULL";
69+
$sql = "SELECT ser_cen_id, name, latitude, longitude, address FROM service_center WHERE latitude IS NOT NULL AND longitude IS NOT NULL";
7070
$stmt = self::prepare($sql);
7171
$stmt->execute();
7272
$service_centres = $stmt->fetchAll(\PDO::FETCH_ASSOC);

models/Technician.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function TechnicianAddressGeocoding()
6767

6868
public function techniciansGeocoding()
6969
{
70-
$sql = "SELECT tech_id, fname, lname, latitude, longitude, profile_picture FROM technician WHERE latitude IS NOT NULL AND longitude IS NOT NULL";
70+
$sql = "SELECT tech_id, fname, lname, latitude, longitude, profile_picture, address FROM technician WHERE latitude IS NOT NULL AND longitude IS NOT NULL";
7171
$stmt = self::prepare($sql);
7272
$stmt->execute();
7373
$technicians = $stmt->fetchAll(\PDO::FETCH_ASSOC);
Loading
Binary file not shown.

public/css/customer/customer-dashboard.css

+20-5
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ a {
360360
}
361361

362362
.status.completed {
363-
padding: 2px 4px;
363+
padding: .5rem 1rem;
364364
background: #8de02c;
365365
color: var(--white);
366366
border-radius: 4px;
@@ -369,25 +369,26 @@ a {
369369
}
370370

371371
.status.pending {
372-
padding: 2px 4px;
372+
padding: .5rem 1rem;
373373
background: #e9b10a;
374374
color: var(--white);
375375
border-radius: 4px;
376376
font-size: 14px;
377377
font-weight: 500;
378+
border-radius: 1rem;
378379
}
379380

380381
.status.rejected {
381-
padding: 2px 4px;
382+
padding: .5rem 1rem;
382383
background: #f00;
383384
color: var(--white);
384385
border-radius: 4px;
385386
font-size: 14px;
386387
font-weight: 500;
387388
}
388389

389-
.status.inProgress {
390-
padding: 2px 4px;
390+
.status.inprogress {
391+
padding: .5rem 1rem;
391392
background: #1795ce;
392393
color: var(--white);
393394
border-radius: 4px;
@@ -544,4 +545,18 @@ a {
544545
margin-left: 300px;
545546
color: var(--white);
546547
font-size: 0.9rem;
548+
}
549+
550+
.cancel-btn {
551+
background-color: #0d6efd;
552+
border: none;
553+
border-radius: 1rem;
554+
color: #FFFFFF;
555+
padding: .5rem 1rem;
556+
margin: 0;
557+
}
558+
559+
.cancel-btn:hover {
560+
cursor: pointer;
561+
background-color: rgba(13, 110, 253, 0.84);
547562
}

0 commit comments

Comments
 (0)