Skip to content

Commit b155b54

Browse files
authored
Merge pull request #36 from kasunmendis7/develop
Develop
2 parents ff4793d + b8834e8 commit b155b54

20 files changed

+1532
-340
lines changed

controllers/AuthController.php

-22
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,6 @@ public function serviceCenterLogout(Request $request, Response $response)
165165
$response->redirect('/service-centre-landing');
166166
}
167167

168-
/* admin sign up method */
169-
public function adminSignUp(Request $request)
170-
{
171-
$admin = new Admin();
172-
if ($request->isPost()) {
173-
174-
$admin->loadData($request->getBody());
175-
if ($admin->validate() && $admin->save()) {
176-
Application::$app->session->setFlash('success', 'You have been registered successfully!');
177-
Application::$app->response->redirect('/admin-login');
178-
}
179-
$this->setLayout('auth');
180-
return $this->render('/admin/admin-sign-up', [
181-
'model' => $admin
182-
]);
183-
}
184-
$this->setLayout('auth');
185-
return $this->render('/admin/admin-sign-up', [
186-
'model' => $admin
187-
]);
188-
}
189-
190168
/* admin login method */
191169
public function adminLogin(Request $request, Response $response)
192170
{

controllers/AuthController.php~

-189
This file was deleted.

core/Request.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class Request
66
{
7-
87
public function getPath()
98
{
109
$path = $_SERVER['REQUEST_URI'] ?? '/';
@@ -34,7 +33,6 @@ public function getBody()
3433
{
3534
// Empty associative array
3635
$body = [];
37-
// Checks if the request method is GET
3836
if ($this->method() === 'get') {
3937
// $_GET: A PHP superglobal that holds query parameters from the URL (e.g., ?key=value).
4038
// Iterates through each key-value pair in the $_GET array
@@ -43,13 +41,25 @@ public function getBody()
4341
$body[$key] = filter_input(INPUT_GET, $key, FILTER_SANITIZE_SPECIAL_CHARS);
4442
}
4543
}
46-
// Checks if the request method is POST
44+
4745
if ($this->method() === 'post') {
48-
// $_POST: A PHP superglobal that holds form data submitted via HTTP POST.
49-
// Iterates through each key-value pair in the $_POST array
50-
foreach ($_POST as $key => $value) {
51-
// Sanitizes the values and adds to the $body array
52-
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS);
46+
// Check Content-Type header to determine how to process the body
47+
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
48+
49+
if (strpos($contentType, 'application/json') !== false) {
50+
// Handle JSON input
51+
$rawInput = file_get_contents('php://input');
52+
$decodedInput = json_decode($rawInput, true);
53+
if (json_last_error() === JSON_ERROR_NONE && is_array($decodedInput)) {
54+
$body = $decodedInput;
55+
}
56+
} else {
57+
// $_POST: A PHP superglobal that holds form data submitted via HTTP POST.
58+
// Iterates through each key-value pair in the $_POST array
59+
// Handle form-encoded input
60+
foreach ($_POST as $key => $value) {
61+
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS);
62+
}
5363
}
5464
}
5565
// Returns the sanitized data

models/Admin.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class Admin extends DbModel
99
{
10-
1110
public string $fname = '';
1211
public string $lname = '';
1312
public string $email = '';
@@ -81,4 +80,23 @@ public function attributes(): array
8180
'password',
8281
];
8382
}
83+
84+
public static function findAllCustomers()
85+
{
86+
$sql = "SELECT cus_id, fname, lname, email, phone_no, address, reg_date FROM customer";
87+
$statement = (new Admin)->prepare($sql);
88+
$statement->execute();
89+
return $statement->fetchAll(\PDO::FETCH_ASSOC);
90+
}
91+
92+
public static function deleteCustomerById($cus_id)
93+
{
94+
$db = Application::$app->db; // Ensure this points to the correct Database instance
95+
$sql = "DELETE FROM customer WHERE cus_id = :cus_id";
96+
$stmt = $db->prepare($sql);
97+
$stmt->bindParam(':cus_id', $cus_id, \PDO::PARAM_INT);
98+
return $stmt->execute();
99+
100+
}
101+
84102
}

public/assets/uploads/HomeImage2.webp

60 KB
Binary file not shown.

public/assets/uploads/OIP.jpeg

24.8 KB
Loading

0 commit comments

Comments
 (0)