diff --git a/app/controllers/User.php b/app/controllers/User.php index e72a8f9e5a9e27d82051348044b4fdbce63a5a8b..554e85a66d24ec1e30fbb944dffbcadfc7d67f2a 100644 --- a/app/controllers/User.php +++ b/app/controllers/User.php @@ -2,21 +2,26 @@ session_start(); class User extends Controller { - public function index() + public function index($page = 1) { // Check if the user is logged in as 'user' - if(isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user'){ - $this->view('library/booklist'); - } - else{ + if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user') { + $limit = 10; + $offset = ($page - 1) * $limit; + $data['book'] = $this->model('BookModel')->getAllBookList($limit, $offset); + + $this->view('library/booklist', $data); + } else { $this->view('login/login'); } } - public function bookmark() + public function bookmark($page = 1) { if(isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user'){ - $data['book'] = $this->model('BookModel')->getAllBookmark(); + $limit = 10; + $offset = ($page - 1) * $limit; + $data['book'] = $this->model('BookModel')->getAllBookmark($limit, $offset); $this->view('bookmark/bookmark', $data); } else{ @@ -28,6 +33,7 @@ class User extends Controller { public function bookdetail() { if(isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user'){ + // $data['book'] = $this->model('BookModel')->getAllBookmark(); $this->view('library/detailbook'); } else{ @@ -35,24 +41,30 @@ class User extends Controller { } } - public function bookmarkSearch() + + + public function bookmarkSearch($page = 1) { if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'user') { - var_dump($_SERVER['REQUEST_METHOD']); if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $search = $_POST['search']; - var_dump($search); + $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'] : ''; - // Perform a search using the $search variable - $searchResults = $this->model('BookModel')->searchBookmark($search); - + $limit = 10; + $offset = ($page - 1) * $limit; + // Perform a search using the parameters and the model method + $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; } else { // Handle non-POST requests (e.g., redirect to a different page) - + $this->view('bookmark/bookmark'); } } else { $this->view('login/login'); diff --git a/app/core/connection.php b/app/core/connection.php index 550fb5e9158d3ffc606fef217171d72d7cdb9eda..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/app/core/connection.php +++ b/app/core/connection.php @@ -1,11 +0,0 @@ -<?php -$host = "localhost"; -$user = "root"; -$pass = "vongola1"; -$db = "audiolib"; - -$conn = mysqli_connect($host, $user, $pass, $db); -if (!$conn) { - die("Connection failed: " . mysqli_connect_error()); -} - diff --git a/app/models/BookModel.php b/app/models/BookModel.php index 8db8081edab74b7fbe4341c254f55b0561277bb9..625d4de411f8b655261a15328a14149dd10eb2ad 100644 --- a/app/models/BookModel.php +++ b/app/models/BookModel.php @@ -46,20 +46,53 @@ class BookModel $this->database->execute(); return 1; } - public function getAllBookmark(){ - $this->database->query('SELECT * FROM book JOIN inventory ON book.id = inventory.book_id JOIN user ON user.id = inventory.user_id '); + 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']); return $this->database->resultSet(); } - public function getAllBookList(){ - $this->database->query('SELECT * FROM book'); + public function getAllBookList($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"); return $this->database->resultSet(); } - public function searchBookmark($search){ - $this->database->query('SELECT * FROM book JOIN inventory ON book.id = inventory.book_id JOIN user ON user.id = inventory.user_id '); + + public function searchBookmark($searchInput, $sortSelect, $sortOrder, $filterSelect, $filterQuery, $limit, $offset){ + // Construct the SQL query based on the provided parameters + $sql = "SELECT title, author_id, category FROM book WHERE 1=1"; // Initial WHERE condition + + if ($filterSelect && $filterQuery) { + $sql .= " AND $filterSelect = '$filterQuery'"; + } + + if ($searchInput) { + // Sanitize the search input to prevent SQL injection + // $searchInput = mysqli_real_escape_string($this->database->getConnection(), $searchInput); + + // Create a search query using LIKE clause for substring search + $sql .= " AND (title LIKE '%$searchInput%' OR author_id LIKE '%$searchInput%')"; + } + + if ($sortSelect && $sortOrder) { + $sql .= " ORDER BY $sortSelect $sortOrder"; + } + $sql .= " LIMIT $limit OFFSET $offset"; + // Execute the query and return the results + $this->database->query($sql); return $this->database->resultSet(); } public function searchBookList(){ $this->database->query('SELECT * FROM book'); return $this->database->resultSet(); } + public function pageCount() + { + $this->database->query('SELECT COUNT(*) FROM book JOIN inventory ON book.id = inventory.book_id JOIN user ON user.id = inventory.user_id'); + $count = $this->database->single(); // Assuming you have a method like singleColumn() + + // Convert the count value to an integer + $count = intval($count); + + return $count; + } + } \ No newline at end of file diff --git a/app/views/bookmark/bookmark.php b/app/views/bookmark/bookmark.php index 1edcf264e9a4f932bffbb6e94dfb84a8ab65c5e4..a4bff42a3a1828febf3cb319cd7ae26710c74da3 100644 --- a/app/views/bookmark/bookmark.php +++ b/app/views/bookmark/bookmark.php @@ -1,7 +1,5 @@ <!DOCTYPE html> -<?php -include('C:\xampp\htdocs\tugas-besar-1\app\views' . '/popup/popupEditDelete.php'); -?> + <html lang="en"> @@ -11,7 +9,7 @@ include('C:\xampp\htdocs\tugas-besar-1\app\views' . '/popup/popupEditDelete.php' <title>My Web Page</title> <link rel ="stylesheet" href="http://localhost/tugas-besar-1/public/style/bookmark.css"> <link rel ="stylesheet" href="http://localhost/tugas-besar-1/public/style/pagination.css"> - <?php include('C:\xampp\htdocs\tugas-besar-1\app\views' . '/navbar/navbar.php'); ?> + <?php include(PAGEURL . '/navbar/navbar.php'); ?> <!-- <link rel="stylesheet" type="text/css" href="../style/navBar.css"> --> </head> @@ -21,103 +19,35 @@ include('C:\xampp\htdocs\tugas-besar-1\app\views' . '/popup/popupEditDelete.php' <h1>Bookmarks</h1> </div> - <?php - $boxCount = 0; // Initialize a variable to count the bookmark boxes - - if ($result->num_rows > 0) { - while ($row = $result->fetch_assoc()) { - $title = $row["title"]; - $author_id = $row["author_id"]; - $category = $row["category"]; - - if ($boxCount % 2 == 0) { - if ($boxCount > 0) { - echo '</div>'; - } - - echo '<div class="container">'; - } - - $boxCount++; - - $paragraphId = 'paragraph' . $boxCount; - $editPopupId = 'editPopup' . $boxCount; - $editTextboxId = 'editTextbox' . $boxCount; - $continueButtonId = 'continueButtonEdit' . $boxCount; - $deletePopupId = 'deletePopup' . $boxCount; - $deleteButtonId = 'deleteButton' . $boxCount; - $continueDeleteButtonId = 'continueButtonDelete' . $boxCount; - - ?> - <div class="bookmark-box" data-box-index="<?php echo $boxCount; ?>"> - <div class="image-rectangle"> - <img src="<?php echo BASEURL?>/img/image 3.png" alt="Image Alt Text"> - </div> - <div class="content-rectangle"> - <div class="content-header"> - <h1><?php echo $title; ?></h1> - - <ul class="star-list"> - <li><i class="fa fa-star checked"></i></li> - <li><i class="fa fa-star checked"></i></li> - <li><i class="fa fa-star checked"></i></li> - <li><i class="fa fa-star checked"></i></li> - <li><i class="fa fa-star"></i></li> - </ul> - </div> - <br> - <h2><?php echo $author_id ?></h2> - <p id="<?php echo $paragraphId; ?>"><br><?php echo $category; ?></p> - <hr class="bookmark-line"> - <button class="edit-button" data-box-index="<?php echo $boxCount; ?>">Edit</button> - <!-- Add data-employee-number attribute to store the employee number --> - <button class="delete-button" id="<?php echo $deleteButtonId; ?>" data-employee-number="<?php echo $title; ?>">Delete</button> - - </div> +<div class="container"> + <?php foreach ($data['book'] as $row) : ?> + <div class="bookmark-box"> + <div class="image-rectangle"> + <img src="<?php echo BASEURL?>/img/image 3.png" alt="Image Alt Text"> </div> - - - <div id="<?php echo $editPopupId; ?>" class="popup"> - <div class="popup-content"> - <h1><?php echo $editPopupContentTitle; ?></h1> - <input class="textbox" id="<?php echo $editTextboxId; ?>" type="text"> - <div class="button-container"> - <button class="continue-button" id="<?php echo $continueButtonId; ?>"><?php echo $continueButtonText; ?></button> - <button class="cancel-button" id="cancelButtonEdit<?php echo $boxCount; ?>"><?php echo $cancelButtonText; ?></button> - </div> - </div> - </div> - - - <div id="<?php echo $deletePopupId; ?>" class="popup"> - <div class="popup-content"> - <h1><?php echo $deletePopupContentTitle; ?></h1> - <div class="button-container"> - <button class="continue-button" id="<?php echo $continueDeleteButtonId; ?>"><?php echo $continueButtonText; ?></button> - <button class="cancel-button" id="cancelButtonDelete<?php echo $boxCount; ?>"><?php echo $cancelButtonText; ?></button> - </div> + <div class="content-rectangle"> + <div class="content-header"> + <h1><?php echo $row['title']; ?></h1> + + <ul class="star-list"> + <li><i class="fa fa-star checked"></i></li> + <li><i class="fa fa-star checked"></i></li> + <li><i class="fa fa-star checked"></i></li> + <li><i class="fa fa-star checked"></i></li> + <li><i class="fa fa-star"></i></li> + </ul> </div> + <br> + <h2><?php echo $row['name']; ?></h2> + <p><br><?php echo $row['category']; ?></p> + <hr class="bookmark-line"> + <button class="edit-button" data-box-index="<?php echo $boxCount; ?>">Edit</button> + <button class="delete-button" id="<?php echo $deleteButtonId; ?>" data-employee-number="<?php echo $row['title']; ?>">Delete</button> </div> + </div> + <?php endforeach; ?> +</div> - <script src="<?php echo BASEURL; ?>/js/bookmark.js"></script> - - <?php - - if ($boxCount % 2 == 0) { - echo '</div>'; - } - } - - if ($boxCount % 2 != 0) { - echo '</div>'; - } -} else { - echo "No records found"; -} +<?php include(PAGEURL . '/navbar/pagination.php'); ?> -$conn->close(); -?> -<?php -include(PAGEURL . '/navbar/pagination.php'); -?> diff --git a/app/views/bookmark/search.php b/app/views/bookmark/search.php index 069a842b23b8370cd9d107f492b130d210aae6cf..a508602f06202e17dcefb818f3c8edfad6871541 100644 --- a/app/views/bookmark/search.php +++ b/app/views/bookmark/search.php @@ -1,4 +1,6 @@ + <?php +/* include(APPURL .'/core/connection.php'); // Read URL parameters @@ -78,4 +80,5 @@ $sql .= " LIMIT $itemsPerPage OFFSET $offset"; $result = $conn->query($sql); ?> -<script src="http://localhost:8080/public/js/search.js"></script> \ No newline at end of file +<script src="http://localhost:8080/public/js/search.js"></script> +*/ \ No newline at end of file diff --git a/app/views/library/booklist.php b/app/views/library/booklist.php index 61f9e6ae49287f01e23a976761c977961d9dc6ab..3cea58af56df19ac2305298db6d16cfb928e1b8f 100644 --- a/app/views/library/booklist.php +++ b/app/views/library/booklist.php @@ -1,7 +1,4 @@ <!DOCTYPE html> -<?php -include('/var/www/html/app/views/popup/popupEditDelete.php'); -?> <html lang="en"> @@ -22,13 +19,13 @@ include('/var/www/html/app/views/popup/popupEditDelete.php'); </div> <?php - $boxCount = 0; // Initialize a variable to count the bookmark boxes + $boxCount = 0; - if ($result->num_rows > 0) { - while ($row = $result->fetch_assoc()) { - $title = $row["title"]; - $authorId = $row["author_id"]; - $category = $row["category"]; + if (!empty($book)) { + foreach ($book as $row) { + $title = $row['title']; + $author = $row['name']; + $category = $row['category']; if ($boxCount % 2 == 0) { if ($boxCount > 0) { @@ -104,7 +101,6 @@ include('/var/www/html/app/views/popup/popupEditDelete.php'); echo "No records found"; } -$conn->close(); ?> <?php include(PAGEURL . '/navbar/pagination.php'); diff --git a/app/views/navbar/pagination.php b/app/views/navbar/pagination.php index b9bd7550007cc7dbbaed2ab19e85d408dd9ce587..fb912ece3dd2094c2ee91092e7c203d62e7eeed7 100644 --- a/app/views/navbar/pagination.php +++ b/app/views/navbar/pagination.php @@ -2,8 +2,8 @@ <div class="pagination"> <!-- Previous Page Button --> <?php - $prevPage = $activePage - 1; - + $prevPage = $pagination['activePage'] - 1; + // Validation check for previous page if ($prevPage >= 1) { echo '<a href="?page=' . $prevPage . '">«</a>'; @@ -14,29 +14,28 @@ <!-- Change links based on offset and limit--> <?php - for ($i = 1; $i <= $totalPages; $i++) { - $activeClass = ($activePage == $i) ? 'class="active"' : ''; + for ($i = 1; $i <= $pagination['totalPages']; $i++) { + $activeClass = ($pagination['activePage'] == $i) ? 'class="active"' : ''; echo '<a href="?page=' . $i . '" ' . $activeClass . '>' . $i . '</a>'; } ?> <!-- Next Page Button --> <?php - $nextPage = $activePage + 1; - + $nextPage = $pagination['activePage'] + 1; + // Validation check for next page - if ($nextPage <= $totalPages) { + if ($nextPage <= $pagination['totalPages']) { echo '<a href="?page=' . $nextPage . '">»</a>'; } else { echo '<a class="disabled">»</a>'; } ?> + </div> </div> </body> -</html> - - +</html> \ No newline at end of file diff --git a/mysql/#innodb_temp/temp_1.ibt b/mysql/#innodb_temp/temp_1.ibt new file mode 100644 index 0000000000000000000000000000000000000000..2d169ff20a583b09c6129bed90c0707ea9117d55 Binary files /dev/null and b/mysql/#innodb_temp/temp_1.ibt differ diff --git a/mysql/#innodb_temp/temp_10.ibt b/mysql/#innodb_temp/temp_10.ibt new file mode 100644 index 0000000000000000000000000000000000000000..0d0182d3b2355e3dcd19e19a8f4766a5b164a0c9 Binary files /dev/null and b/mysql/#innodb_temp/temp_10.ibt differ diff --git a/mysql/#innodb_temp/temp_2.ibt b/mysql/#innodb_temp/temp_2.ibt new file mode 100644 index 0000000000000000000000000000000000000000..4f88a88ee0ad0d5876f26909bd40df5fee5eb559 Binary files /dev/null and b/mysql/#innodb_temp/temp_2.ibt differ diff --git a/mysql/#innodb_temp/temp_3.ibt b/mysql/#innodb_temp/temp_3.ibt new file mode 100644 index 0000000000000000000000000000000000000000..a4da66454135a7614ec905aa137fd956d33bb624 Binary files /dev/null and b/mysql/#innodb_temp/temp_3.ibt differ diff --git a/mysql/#innodb_temp/temp_4.ibt b/mysql/#innodb_temp/temp_4.ibt new file mode 100644 index 0000000000000000000000000000000000000000..ff791b32fa6275cf1ad3cb8010d4c1a303998d8d Binary files /dev/null and b/mysql/#innodb_temp/temp_4.ibt differ diff --git a/mysql/#innodb_temp/temp_5.ibt b/mysql/#innodb_temp/temp_5.ibt new file mode 100644 index 0000000000000000000000000000000000000000..6a19e81dd65422ba57fe7e2a5dfd1a664ad99d70 Binary files /dev/null and b/mysql/#innodb_temp/temp_5.ibt differ diff --git a/mysql/#innodb_temp/temp_6.ibt b/mysql/#innodb_temp/temp_6.ibt new file mode 100644 index 0000000000000000000000000000000000000000..6b970b59a0053fc0d09f2d072c4c8ad6d8c6a077 Binary files /dev/null and b/mysql/#innodb_temp/temp_6.ibt differ diff --git a/mysql/#innodb_temp/temp_7.ibt b/mysql/#innodb_temp/temp_7.ibt new file mode 100644 index 0000000000000000000000000000000000000000..8fc2d42d8145919a095940602463390681d85fd2 Binary files /dev/null and b/mysql/#innodb_temp/temp_7.ibt differ diff --git a/mysql/#innodb_temp/temp_8.ibt b/mysql/#innodb_temp/temp_8.ibt new file mode 100644 index 0000000000000000000000000000000000000000..105307e99c7eea7e88ed3d241548611d54a4709f Binary files /dev/null and b/mysql/#innodb_temp/temp_8.ibt differ diff --git a/mysql/#innodb_temp/temp_9.ibt b/mysql/#innodb_temp/temp_9.ibt new file mode 100644 index 0000000000000000000000000000000000000000..a8375f292e4d73286ad32c3bd28b81e23ccdce6a Binary files /dev/null and b/mysql/#innodb_temp/temp_9.ibt differ diff --git a/mysql/auto.cnf b/mysql/auto.cnf index 51b38e107bb3779f05d18c58ef138ab91dd772c3..2a311dbee790a450b02ec19d8da9d7ac89d8b8cb 100644 --- a/mysql/auto.cnf +++ b/mysql/auto.cnf @@ -1,2 +1,6 @@ [auto] +<<<<<<< HEAD server-uuid=4076b398-6506-11ee-9ef4-0242ac1d0003 +======= +server-uuid=fe2245a8-64f8-11ee-9db3-0242ac150003 +>>>>>>> 8a35fb95f84f7bfc965b2c16bf99a2ec24387ab0 diff --git a/mysql/binlog.000004 b/mysql/binlog.000004 new file mode 100644 index 0000000000000000000000000000000000000000..5ee77c5fa067e612daa18d9b464b85b4e617901e Binary files /dev/null and b/mysql/binlog.000004 differ diff --git a/mysql/binlog.index b/mysql/binlog.index index d1626c4f10d2b5fc8db162e02173ad12d5fe634e..c8452a5a4aa81807a4f7dcb97ad1df784629027d 100644 --- a/mysql/binlog.index +++ b/mysql/binlog.index @@ -1,3 +1,4 @@ ./binlog.000001 ./binlog.000002 ./binlog.000003 +./binlog.000004 diff --git a/mysql/ibtmp1 b/mysql/ibtmp1 new file mode 100644 index 0000000000000000000000000000000000000000..b1749292b1cd6ba9a4c334e55a2b39b4e3ca42f5 Binary files /dev/null and b/mysql/ibtmp1 differ diff --git a/public/js/navbar.js b/public/js/navbar.js index c5e8b98214dee7b3cb745456a779f01671e332f3..816f0e952b872accbc50402717539e4e9e98d6ca 100644 --- a/public/js/navbar.js +++ b/public/js/navbar.js @@ -14,7 +14,7 @@ document.getElementById('sortButton').addEventListener('click', function() { // Create an XMLHttpRequest var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://localhost/tugas-besar-1/app/controllers/User.php', true); + xhr.open('POST', 'http://localhost:8080/tugas-besar-1/user/bookmarkSearch', true); xhr.setRequestHeader('Content-Type', 'application/json'); // Send the serialized JSON data as the request body