diff --git a/app/controllers/User.php b/app/controllers/User.php index 554e85a66d24ec1e30fbb944dffbcadfc7d67f2a..bc4a4238bcb3b2e54a3b9b17a56e282029c85b23 100644 --- a/app/controllers/User.php +++ b/app/controllers/User.php @@ -7,7 +7,9 @@ class User extends Controller { // Check if the user is logged in as 'user' if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user') { $limit = 10; + $page = intval($page); $offset = ($page - 1) * $limit; + $offset = intval($offset); $data['book'] = $this->model('BookModel')->getAllBookList($limit, $offset); $this->view('library/booklist', $data); @@ -59,9 +61,7 @@ class User extends Controller { $searchResults = $this->model('BookModel')->searchBookmark($searchInput, $sortSelect, $sortOrder, $filterSelect, $filterQuery, $limit, $offset); // You can return the search results as JSON, for example - header('Content-Type: application/json'); - echo json_encode($searchResults); - exit; + $this->view('bookmark/bookmark', $searchResults); } else { // Handle non-POST requests (e.g., redirect to a different page) $this->view('bookmark/bookmark'); @@ -70,6 +70,30 @@ class User extends Controller { $this->view('login/login'); } } + public function booklistSearch($page = 1){ + if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user') { + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $searchInput = isset($_POST['search']) ? $_POST['search'] : ''; + $sortSelect = isset($_POST['sortSelect']) ? $_POST['sortSelect'] : 'title'; + $sortOrder = isset($_POST['sortOrder']) ? $_POST['sortOrder'] : 'ASC'; + $filterSelect = isset($_POST['filterSelect']) ? $_POST['filterSelect'] : 'none'; + $filterQuery = isset($_POST['filterQuery']) ? $_POST['filterQuery'] : ''; + + $limit = 10; + $offset = ($page - 1) * $limit; + // Perform a search using the parameters and the model method + $searchResults = $this->model('BookModel')->searchBookList($searchInput, $sortSelect, $sortOrder, $filterSelect, $filterQuery, $limit, $offset); + + // You can return the search results as JSON, for example + $this->view('library/booklist', $searchResults); + } else { + // Handle non-POST requests (e.g., redirect to a different page) + $this->view('library/booklist'); + } + } else { + $this->view('login/login'); + } + } } \ No newline at end of file diff --git a/app/core/Database.php b/app/core/Database.php index a7de4781f069744dfbf0968c321a6a28eb11eeb6..8e34d33d2c86e037bf0e96a0b3acd1549e0b95dc 100644 --- a/app/core/Database.php +++ b/app/core/Database.php @@ -39,8 +39,8 @@ class Database $this->query($query); // Bind parameters - $username = "johny"; // Replace with the actual username - $password = password_hash("12345", PASSWORD_DEFAULT); // Replace with the actual password + $username = "johnys"; // Replace with the actual username + $password = "12345"; // Replace with the actual password $admin = 0; // Set to 0 for a non-admin user $this->statement->bindParam(":username", $username, PDO::PARAM_STR); diff --git a/app/models/BookModel.php b/app/models/BookModel.php index 625d4de411f8b655261a15328a14149dd10eb2ad..298c5fc1711e9efb34289852203cbdf0baacbef3 100644 --- a/app/models/BookModel.php +++ b/app/models/BookModel.php @@ -48,7 +48,8 @@ class BookModel } public function getAllBookmark($limit, $offset){ $this->database->query("SELECT title, author_id, category FROM book JOIN inventory ON book.id = inventory.book_id JOIN user ON user.id = inventory.user_id LIMIT $limit OFFSET $offset"); - $this->database->bind('id',$_SESSION['id']); + // $this->database->bind('id',$_SESSION['user_id']); + return $this->database->resultSet(); } public function getAllBookList($limit, $offset){ diff --git a/app/views/navbar/pagination.php b/app/views/navbar/pagination.php index fb912ece3dd2094c2ee91092e7c203d62e7eeed7..a4cefe74658f3c22b77b5f2733fdd9c83456a1a3 100644 --- a/app/views/navbar/pagination.php +++ b/app/views/navbar/pagination.php @@ -1,8 +1,37 @@ <div class="center"> <div class="pagination"> <!-- Previous Page Button --> + <?php - $prevPage = $pagination['activePage'] - 1; + // Get the current URL + $currentUrl = $_SERVER['REQUEST_URI']; + + // Parse the URL and get the path + $urlParts = parse_url($currentUrl); + + if (isset($urlParts['path'])) { + // Split the path into segments + $pathSegments = explode('/', trim($urlParts['path'], '/')); + + // Get the last segment (rightmost element) + $lastSegment = end($pathSegments); + + // Convert it to an integer + $pageNumber = (int)$lastSegment; + + // Check if it's a valid integer + if (is_numeric($pageNumber)) { + $activePage = $pageNumber; + } else { + $activePage = 1; + } + } else { + echo "URL path not found."; + } + + $prevPage = $activePage - 1; + $totalPages = count($data['book']); + // Validation check for previous page if ($prevPage >= 1) { @@ -14,18 +43,18 @@ <!-- Change links based on offset and limit--> <?php - for ($i = 1; $i <= $pagination['totalPages']; $i++) { - $activeClass = ($pagination['activePage'] == $i) ? 'class="active"' : ''; + for ($i = 1; $i <= $totalPages; $i++) { + $activeClass = ($activePage == $i) ? 'class="active"' : ''; echo '<a href="?page=' . $i . '" ' . $activeClass . '>' . $i . '</a>'; } ?> <!-- Next Page Button --> <?php - $nextPage = $pagination['activePage'] + 1; + $nextPage = $activePage + 1; // Validation check for next page - if ($nextPage <= $pagination['totalPages']) { + if ($nextPage <= $totalPages) { echo '<a href="?page=' . $nextPage . '">»</a>'; } else { echo '<a class="disabled">»</a>'; diff --git a/mysql/#innodb_redo/#ib_redo9 b/mysql/#innodb_redo/#ib_redo9 index 835c031f61ed409d9cbbd5e2021d36f5430a4aee..b71badd475ecc473ed7de6e266740ceba3bc03bc 100644 Binary files a/mysql/#innodb_redo/#ib_redo9 and b/mysql/#innodb_redo/#ib_redo9 differ