diff --git a/README.md b/README.md deleted file mode 100644 index fa5ead2ca2f511b04c6a96f3a63c9f4bcead0bd9..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,86 +0,0 @@ -php -S localhost:8080 -c "C:\Users\ASUS\Downloads\php-8.2.10-Win32-vs16-x64\php.INI-DEVELOPMENT" - -Users Endpoints: - -Create a User (POST): -Endpoint: /register -Method: POST -Description: Create a new user. -Request Body: JSON containing user data (username, password, email, role). -Response: Returns the newly created user's ID or an error message. - -User Login (POST): -Endpoint: /login -Method: POST -Description: Authenticate and log in a user. -Request Body: JSON containing username and password. -Response: Returns logged in user's information. Stores session. - - -Create a Cat (POST): - -Endpoint: /cats -Method: POST -Description: Add a new wild cat to the directory. -Request Body: JSON containing cat data (name, description, color, size, sound_url, image_url). -Response: Returns the newly created cat's ID or an error message. -Get All Cats (GET): - -Endpoint: /cats -Method: GET -Description: Retrieve a list of all wild cats. -Response: Returns an array of cat objects. -Get Cat Details (GET): - -TODOO -Endpoint: /cats/{cat_id} -Method: GET -Description: Retrieve details of a specific wild cat by ID. -Response: Returns cat details. -Update Cat Details (PUT): - -Endpoint: /cats/{cat_id} -Method: POST -Description: Update the details of a specific wild cat by ID. -Request Body: JSON containing cat data to be updated. -Response: Returns a success message or an error message. - -Delete Cat (DELETE): -Endpoint: /cats/{cat_id} -Method: DELETE -Description: Delete a wild cat from the directory by ID. -Response: Returns a success message or an error message. -Sightings Endpoints: - -Record Sighting (POST): - -Endpoint: /sightings -Method: POST -Description: Record a new sighting of a wild cat. -Request Body: JSON containing sighting data (cat_id, location, date, time, description, image_url). -Response: Returns the newly created sighting's ID or an error message. -Get All Sightings (GET): - -Endpoint: /sightings -Method: GET -Description: Retrieve a list of all wild cat sightings. -Response: Returns an array of sighting objects. -Get Sighting Details (GET): - -Endpoint: /sightings/{sighting_id} -Method: GET -Description: Retrieve details of a specific wild cat sighting by ID. -Response: Returns sighting details. -Update Sighting Details (PUT): - -Endpoint: /sightings/{sighting_id} -Method: PUT -Description: Update the details of a specific wild cat sighting by ID. -Request Body: JSON containing sighting data to be updated. -Response: Returns a success message or an error message. -Delete Sighting (DELETE): - -Endpoint: /sightings/{sighting_id} -Method: DELETE -Description: Delete a wild cat sighting by ID. -Response: Returns a success message or an error message. \ No newline at end of file diff --git a/public/css/styles.css b/public/css/styles.css index f090cf50d1e1c303b987f319dc752407e8e6fc71..ef1c8b26740ec47c4f8000c6c2a1213e44902a6a 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -623,8 +623,8 @@ button[type="submit"] { /* Edit button styles */ .edit-button { - background-color: #007BFF; - color: #fff; + background-color: #1100ff; + color: #ffffff; padding: 10px 20px; border: none; border-radius: 5px; diff --git a/public/images/image.png b/public/images/image.png new file mode 100644 index 0000000000000000000000000000000000000000..0232ae8a1c43878108d6e288fac0d9198c036eb0 Binary files /dev/null and b/public/images/image.png differ diff --git a/public/images/image2.png b/public/images/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..deee9105069b51279d55e958b88dd9b98ed7b60e Binary files /dev/null and b/public/images/image2.png differ diff --git a/public/images/image3.png b/public/images/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..5fcaeab196236b241a6d998b9de68120842c308a Binary files /dev/null and b/public/images/image3.png differ diff --git a/public/images/image4.png b/public/images/image4.png new file mode 100644 index 0000000000000000000000000000000000000000..de38384b75204cba2fc21de0810de3ddcb174d34 Binary files /dev/null and b/public/images/image4.png differ diff --git a/public/images/image5.png b/public/images/image5.png new file mode 100644 index 0000000000000000000000000000000000000000..0c5c252400dc5e73db236d48974991fe9de888c0 Binary files /dev/null and b/public/images/image5.png differ diff --git a/public/view/cats.php b/public/view/cats.php index fc7b3ab87a2a92a1b96fc436269fa3e23b613fdb..1f4623ce0fb96f8f7b3b8bfae60c4ebea20ac948 100644 --- a/public/view/cats.php +++ b/public/view/cats.php @@ -4,6 +4,8 @@ <head> <meta charset="UTF-8"> <title>List of Cats</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="public/css/styles.css"> </head> @@ -17,44 +19,53 @@ <div class="search-options"> <div class="filter-bar"> - <select name="gender" class="filter-select"> + <label for="gender-select" class="filter-label">Select gender filter: </label> + <select name="gender" id="gender-select" class="filter-select"> <option value="">Filter by Gender</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> - <select name="spayed" class="filter-select"> + <label for="spayed-select" class="filter-label">Select spay filter: </label> + <select name="spayed" id="spayed-select" class="filter-select"> <option value="">Filter by Spayed</option> <option value="Yes">Yes</option> <option value="No">No</option> </select> </div> + <div class="sort-bar"> <label for="order" class="sort-label">Sort by:</label> <div class="sort-options"> <div class="sort-option"> - <input type="checkbox" name="order[]" value="name" id="name-checkbox" class="sort-checkbox"> - <label for="name-checkbox" class="sort-option-label">Name</label> + <label for="name-checkbox" class="sort-option-label"> + <input type="checkbox" name="order[]" value="name" id="name-checkbox" + class="sort-checkbox" aria-label="Name"> + Name</label> </div> <div class="sort-option"> - <input type="checkbox" name="order[]" value="location" id="location-checkbox" - class="sort-checkbox"> - <label for="location-checkbox" class="sort-option-label">Location</label> + <label for="location-checkbox" class="sort-option-label"> + <input type="checkbox" name="order[]" value="location" id="location-checkbox" + class="sort-checkbox" aria-label="location"> + Location</label> </div> <div class="sort-option"> - <input type="checkbox" name="order[]" value="color" id="color-checkbox" - class="sort-checkbox"> - <label for="color-checkbox" class="sort-option-label">Color</label> + <label for="color-checkbox" class="sort-option-label"> + <input type="checkbox" name="order[]" value="color" id="color-checkbox" + class="sort-checkbox" aria-label="color"> + Color</label> </div> <div class="sort-option"> - <input type="checkbox" name="order[]" value="cat_added" id="cat-added-checkbox" - class="sort-checkbox"> - <label for="cat-added-checkbox" class="sort-option-label">Cat Added</label> + <label for="cat-added-checkbox" class="sort-option-label"> + <input type="checkbox" name="order[]" value="cat_added" id="cat-added-checkbox" + class="sort-checkbox" aria-label="cat added"> + Cat Added</label> </div> </div> - <label for="isDesc" class="sort-label">Descending:</label> - <input type="checkbox" name="isDesc" value="true" class="sort-checkbox"> + + <label for="isDesc" class="sort-label" aria-label="descending">Descending:</label> + <input type="checkbox" name="isDesc" value="true" aria-label="descending" class="sort-checkbox"> </div> </div> <input type="hidden" name="pageNo" value="<?= isset($_GET['pageNo']) ? intval($_GET['pageNo']) : 1 ?>"> diff --git a/public/view/register.php b/public/view/register.php index d0e4eb77f0265530e739a1c5e527093ba75f6eb0..77364e9ee074f5f6a86dae5789aea20ffc504b10 100644 --- a/public/view/register.php +++ b/public/view/register.php @@ -1,12 +1,16 @@ <!DOCTYPE html> <html lang="en"> + <head> <meta charset="UTF-8"> <title>Register</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="public/css/styles.css"> </head> + <body> - <?php require_once(PROJECT_ROOT_PATH.'/public/components/Navbar.php'); ?> + <?php require_once(PROJECT_ROOT_PATH . '/public/components/Navbar.php'); ?> <h1 id="registerTitle">Register</h1> <form id="registerForm" enctype="multipart/form-data" method="POST" action="register.php"> <label for="username" id="usernameLabel">Username:</label> @@ -24,4 +28,5 @@ <button type="submit" id="registerButton">Register</button> </form> </body> -</html> + +</html> \ No newline at end of file diff --git a/public/view/sighting.php b/public/view/sighting.php index 1a0517d922aafdf29520d556b1ae72450441cd46..bfa9bf4c8d722edee52889ea2b85ad66e03cbfa3 100644 --- a/public/view/sighting.php +++ b/public/view/sighting.php @@ -4,6 +4,8 @@ <head> <meta charset="UTF-8"> <title>List of Sightings</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="public/css/styles.css"> </head> @@ -12,21 +14,24 @@ <div class="search-container"> <form method="get" id="search-form" class="search-form"> <div class="search-bar"> - <input type="text" name="search" class="search-input" placeholder="Search..."> + <input type="text" name="search" class="search-input" placeholder="Search..." aria-label="search"> </div> <div class="search-options"> <div class="sort-bar"> <label for="order" class="sort-label">Sort by:</label> <div class="sort-option"> - <input type="checkbox" name="order[]" value="name" id="name-checkbox" class="sort-checkbox"> + <input type="checkbox" name="order[]" value="name" id="name-checkbox" class="sort-checkbox" + aria-label="name"> <label for="name-checkbox" class="sort-option-label">Name</label> </div> <div class="sort-option"> - <input type="checkbox" name="order[]" value="date" id="date-checkbox" class="sort-checkbox"> + <input type="checkbox" name="order[]" value="date" id="date-checkbox" class="sort-checkbox" + aria-label="date"> <label for="date-checkbox" class="sort-option-label">Date</label> </div> <label for="isDesc" class="sort-label">Descending:</label> - <input type="checkbox" id="isDesc" name="isDesc" value="true" class="sort-checkbox"> + <input type="checkbox" id="isDesc" name="isDesc" value="true" class="sort-checkbox" + aria-label="Descending"> </div> </div> <input type="hidden" name="pageNo" value="<?= isset($_GET['pageNo']) ? intval($_GET['pageNo']) : 1 ?>"> @@ -78,6 +83,10 @@ <?= htmlspecialchars($sighting['time']) ?> </span> </div> + <div class="sighting-cat-id" style="display: none;"> + <?= htmlspecialchars($cat['cat_id']) ?> + </div> + </div> </div> <?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] === $sighting['user_id']): ?> @@ -110,21 +119,22 @@ </div> <div class="form-group"> <label for="edit-date">Date:</label> - <input type="date" id="edit-date" name="date" class="form-control"> + <input type="date" id="edit-date" name="date" class="form-control" aria-label="date"> </div> <div class="form-group"> <label for="edit-time">Time:</label> - <input type="time" value="00:00:00" id="edit-time" name="time" class="form-control"> + <input type="time" value="00:00:00" id="edit-time" name="time" class="form-control" + aria-label="time"> </div> <div class="form-group"> <label for="edit-sighting-description">Description:</label> - <textarea id="edit-sighting-description" name="sighting_description" - class="form-control"></textarea> + <textarea id="edit-sighting-description" name="sighting_description" class="form-control" + aria-label="description"></textarea> </div> <div class="form-group"> <label for="edit-image_url">Image File (JPG, JPEG, PNG):</label> <input type="file" id="edit-image_url" name="image_url" class="file-input" - accept=".jpg, .jpeg, .png"> + accept=".jpg, .jpeg, .png" aria-label="image_url"> </div> <button type="submit" class="submit-button">Edit Sighting</button> </form> diff --git a/public/view/users.php b/public/view/users.php index 05fb10a051bcbe41cf65a3b80868bffa86280a2b..19c14f93093fdcab8c53dbb678e448bb88880edb 100644 --- a/public/view/users.php +++ b/public/view/users.php @@ -4,6 +4,8 @@ <head> <meta charset="UTF-8"> <title>List of Users</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="public/css/styles.css"> </head> @@ -28,7 +30,7 @@ <p class="user-isadmin"> <?= htmlspecialchars($user['isAdmin']) ?> </p> - <button class="edit-button" onclick="editUser(<?= $user['user_id'] ?>)">Edit</button> + <b><button class="edit-button" onclick="editUser(<?= $user['user_id'] ?>)">Edit</button></b> </div> <?php endforeach; ?> </div> diff --git a/src/services/UserSrv.php b/src/services/UserSrv.php index 6d50c4c59439432b664f969869d2617058fd56c4..8df1f819f2db90fe4717265f082c8819053239e7 100644 --- a/src/services/UserSrv.php +++ b/src/services/UserSrv.php @@ -37,6 +37,10 @@ class UserSrv extends BaseSrv public function register($nama, $username, $email, $password, $confirm_password) { + $existingUser = $this->getByEmail($email); + if (!is_null($existingUser->get('email'))) { + throw new Exception("Email already taken!"); + } if ($password !== $confirm_password) { throw new Exception("Password and confirm password do not match"); } @@ -61,9 +65,6 @@ class UserSrv extends BaseSrv public function getAll($config) { $order = ["registration_date"]; - // if ($config["order"]) { - // $order = explode(",", $config["order"]); - // } $usersResult = $this->repository->select('*', [], $order, $config["pageNo"], $config['pageSize'], null); $users = []; @@ -77,20 +78,7 @@ class UserSrv extends BaseSrv public function login($email_uname, $password) { - $user = null; - - $userByEmail = $this->getByEmail($email_uname); - if ($userByEmail && !is_null($userByEmail->get('user_id'))) { - $user = $userByEmail; - } - - if (is_null($user)) { - $userByUsername = $this->getByUsername($email_uname); - if ($userByUsername && !is_null($userByUsername->get('user_id'))) { - $user = $userByUsername; - } - } - + $user = $this->getByEmail($email_uname); if (is_null($user)) { throw new Exception("User not found"); } @@ -101,6 +89,7 @@ class UserSrv extends BaseSrv $_SESSION["user_id"] = $user->get('user_id'); $_SESSION["isAdmin"] = $user->get('isAdmin'); + $_SESSION['username'] = $user->get('username'); return $user; @@ -134,17 +123,6 @@ class UserSrv extends BaseSrv return $user; } - public function getByUsername($username) - { - $user = new UserModel(); - $sqlRes = $this->repository->getByUsername($username); - if ($sqlRes) { - $user->constructFromArray($sqlRes); - } - - return $user; - } - public function updateUser($userId, $userData) { $existingUser = $this->getUserById($userId); @@ -161,29 +139,4 @@ class UserSrv extends BaseSrv return $existingUser; } - - public function isUsernameExist($username) - { - $user = $this->getByUsername($username); - return !is_null($user->get('user_id')); - } - - public function isEmailExist($email) - { - $user = $this->getByEmail($email); - return !is_null($user->get('user_id')); - } - - public function getById($id) - { - $user = $this->repository->getById($id); - if (!$user) { - return null; - } - - $userModel = new UserModel(); - $userModel->constructFromArray($user); - - return $userModel; - } } \ No newline at end of file