diff --git a/app/controllers/admin.php b/app/controllers/admin.php index 6f45ea5767dd120db6383047cb1c5f09fa38194d..f5759b1363af217a5e51956ebc777cd5044c3cc2 100644 --- a/app/controllers/admin.php +++ b/app/controllers/admin.php @@ -38,7 +38,7 @@ class Admin extends Controller { } public function authoradmin(){ if(isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin'){ - $data['user'] = $this->model('UserModel')->getAllAuthor(); + $data['user'] = $this->model('AuthorModel')->getAllAuthor(); $this->view('admin/authoradmin',$data); } else{ @@ -141,4 +141,63 @@ class Admin extends Controller { $this->view('login/login'); } } + public function addAuthor(){ + if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin' ){ + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $newAuthorName = $_POST['newAuthorName']; // Assuming you have an input field for author name + // Additional author-related fields can be added here + + // Check if the author already exists in the database + $data['authors'] = $this->model('AuthorModel')->getAllAuthor(); + $authorNames = array_column($data['authors'], "author_name"); + + if (!in_array($newAuthorName, $authorNames, true)){ + // Insert the new author into the database using your AuthorModel + $this->model('AuthorModel')->insertAuthor($newAuthorName); // Adjust this according to your model's method + } + } + // Fetch the list of authors (optional) + $data['authors'] = $this->model('AuthorModel')->getAllAuthor(); + $this->view('admin/authoradmin', $data); // Adjust the view file and path accordingly + } else { + $this->view('login/login'); + } + } + + public function editAuthor(){ + if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') { + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Get values from the input form + $newAuthorName = $_POST['newAuthorName']; + + $oldAuthorName = $_POST['authorName']; + + $data['authors'] = $this->model('AuthorModel')->getAllAuthor(); + $authorNames = array_column($data['authors'], "author_name"); + + if (!in_array($newAuthorName, $authorNames, true)){ + + $this->model('AuthorModel')->updateAuthor($oldAuthorName, $newAuthorName); + } + } + + $data['authors'] = $this->model('AuthorModel')->getAllAuthor(); + $this->view('admin/authoradmin', $data); + } else { + $this->view('login/login'); + } + } + public function deleteAuthor(){ + if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') { + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $authorName = $_POST['authorName']; + $this->model('AuthorModel')->deleteAuthor($authorName); + } + $data['authors'] = $this->model('AuthorModel')->getAllAuthor(); + $this->view('admin/authoradmin', $data); + } else { + $this->view('login/login'); + } + } + } \ No newline at end of file diff --git a/app/models/AuthorModel.php b/app/models/AuthorModel.php new file mode 100644 index 0000000000000000000000000000000000000000..44774dd0618b8759eb00c0fc6078c355e3d02e05 --- /dev/null +++ b/app/models/AuthorModel.php @@ -0,0 +1,35 @@ +<?php +class AuthorModel +{ + private $table = 'author'; + private $database; + + public function __construct() + { + $this->database = new Database; + } + public function getAllAuthor(){ + $this->database->query('SELECT * FROM author'); + return $this->database->resultSet(); + } + public function getAuthor(){ + $this->database->query('SELECT name FROM author'); + return $this->database->resultSet(); + } + public function insertAuthor($newAuthorName){ + $this->database->query('INSERT IGNORE INTO author (id, name) VALUES (NULL, :newAuthorName)'); + $this->database->bind('newAuthorName', $newAuthorName); + $this->database->execute(); + } + public function updateAuthor($currentUsername, $newUsername){ + $this->database->query('UPDATE ' . $this->table . ' SET name = :newName WHERE name = :oldName'); + $this->database->bind('newName', $newUsername); + $this->database->bind('oldName', $currentUsername); + $this->database->execute(); + } + public function deleteAuthor($authorName){ + $this->database->query('DELETE FROM ' . $this->table . ' WHERE name = :name'); + $this->database->bind('name', $authorName); + $this->database->execute(); + } +} \ No newline at end of file diff --git a/app/models/BookModel.php b/app/models/BookModel.php index 6637e198555c5a8e93c31977e39535069b3d686c..24d85a657e11a16e5978c3b6d75b3c2d31fb8ff0 100644 --- a/app/models/BookModel.php +++ b/app/models/BookModel.php @@ -38,11 +38,6 @@ class BookModel $this->database->query('SELECT DISTINCT category FROM book'); return $this->database->resultSet(); } - - public function getAuthor(){ - $this->database->query('SELECT name FROM author'); - return $this->database->resultSet(); - } public function updateBook($currentTitle, $newTitle, $selectedAuthor, $newContent, $selectedCategory){ $this->database->query('UPDATE book SET title = :newTitle, content = :newContent, author_id = (SELECT id FROM author WHERE author.name = :selectedAuthor), category = :newCategory WHERE title = :currentTitle'); $this->database->bind('currentTitle', $currentTitle); @@ -84,7 +79,7 @@ class BookModel if (!$existingTuple) { // The tuple doesn't exist, so insert it - $this->database->query("INSERT INTO inventory (id, bookid) VALUES (:id, :bookid)"); + $this->database->query("INSERT INTO inventory (user_id, book_id) VALUES (:id, :bookid)"); $this->database->bind('id', $id); $this->database->bind('bookid', $bookid); $this->database->execute(); diff --git a/app/models/UserModel.php b/app/models/UserModel.php index 2d081787dc24c3c9619e25ad44a73a70b1fb9739..65deccf3a473aba25b67345f23f1e402650a3b9f 100644 --- a/app/models/UserModel.php +++ b/app/models/UserModel.php @@ -13,7 +13,8 @@ class UserModel public function getAllUser(){ $this->database->query('SELECT * FROM user WHERE admin = 0'); return $this->database->resultSet(); - } + } + public function getAllUsername(){ $this->database->query('SELECT username FROM user WHERE admin = 0'); return $this->database->resultSet(); diff --git a/app/views/admin/authoradmin.php b/app/views/admin/authoradmin.php index 526912f2b65d40ae51675f7fded36c6e3e11557d..ee2d10b6e1629eb71519c91ac47d9388fee158e3 100644 --- a/app/views/admin/authoradmin.php +++ b/app/views/admin/authoradmin.php @@ -1,101 +1,102 @@ <!DOCTYPE html> - <head> - <meta charset="UTF-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name = "viewport" content="width=device-width, initial-scale=1.0"> - <title> Admin Page </title> - <link rel ="stylesheet" href="<?php echo BASEURL; ?>/style/sidebar.css"> - <link rel ="stylesheet" href="<?php echo BASEURL; ?>/style/authoradmin.css"> - <link href='https://fonts.googleapis.com/css?family=Italianno' rel='stylesheet'> - <link href='https://fonts.googleapis.com/css?family=Hanuman' rel='stylesheet'> - <link href='https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css' rel='stylesheet'> - </head> - <body> - <?php - include(__DIR__ . '/sidebar.php'); - ?> - - <div class="top-section"> - <h1 class="title">Authors</h1> - <button class="add-btn" onclick="openAddPopup()">Add User</button> - </div> - - <div class="overlay" id="overlay"></div> - <div style="overflow-x: auto;"> - <table id="users"> - <!-- Judul-judul kolom --> - <thead> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title> Admin Page </title> + <link rel="stylesheet" href="<?php echo BASEURL; ?>/style/sidebar.css"> + <link rel="stylesheet" href="<?php echo BASEURL; ?>/style/authoradmin.css"> + <link href='https://fonts.googleapis.com/css?family=Italianno' rel='stylesheet'> + <link href='https://fonts.googleapis.com/css?family=Hanuman' rel='stylesheet'> + <link href='https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css' rel='stylesheet'> +</head> + +<body> + <?php + include(__DIR__ . '/sidebar.php'); + ?> + + <div class="top-section"> + <h1 class="title">Authors</h1> + <button class="add-btn" onclick="openAddPopup()">Add User</button> + </div> + + <div class="overlay" id="overlay"></div> + <div style="overflow-x: auto;"> + <table id="users"> + <!-- Judul-judul kolom --> + <thead> + <tr> + <th>ID</th> + <th>Name</th> + <th>Action</th> + </tr> + </thead> + <tbody> + <?php foreach ($data['authors'] as $row) : ?> + <?php + $id = $row['id']; + $name = $row['name']; + + ?> <tr> - <th>ID</th> - <th>Name</th> - <th>Action</th> - </tr> - </thead> - <tbody> - <?php foreach ($data['user'] as $row): ?> - <?php - $id = $row['id']; - $name = $row['name']; - - ?> - <tr> - <td><?php echo $id; ?></td> - <td><?php echo $name; ?></td> - <td> + <td><?php echo $id; ?></td> + <td><?php echo $name; ?></td> + <td> <button class="edituser" onclick="editUser('<?php echo $name; ?>')"> Edit </button> <button class="deleteuser" onclick="deleteUser()"> Delete </button> - </td> - <div class="edit-popup" id="editpopup"> - <form id="editForm" method="post" action='<?php echo BASEURL; ?>/admin/editUser'> - <input type="hidden" name="username" value="<?php echo $name; ?>"> - <div class="add-input"> - <input type="text" id="username" name="newUsername" placeholder="Enter new username.." required> - </div> - <div class="add-input"> - <input type="password" id="password" name="newPassword" placeholder="Enter new password.." required> - </div> - </form> - <div class="add-submission"> - <button type="submit" class="submit-button" onclick="submitForm()">Submit</button> - <button class="cancel-button" onclick="closeEditPopup()">Cancel</button> - </div> + </td> + <div class="edit-popup" id="editpopup"> + <form id="editForm" method="post" action='<?php echo BASEURL; ?>/admin/editAuthor'> + <input type="hidden" name="authorName" value="<?php echo $name; ?>"> + <div class="add-input"> + <input type="text" id="username" name="newAuthorName" placeholder="Enter new username.." required> + </div> + </form> + <div class="add-submission"> + <button type="submit" class="submit-button" onclick="submitForm()">Submit</button> + <button class="cancel-button" onclick="closeEditPopup()">Cancel</button> </div> - + </div> - <div class="delete-popup" id="deletepopup"> - <p> - Are you sure want to delete this user? - </p> - <div class="add-submission"> - <button class="submit-button">Delete</button> - <button class="cancel-button" onclick=closeDeletePopup()>Cancel</button> - </div> + + <div class="delete-popup" id="deletepopup"> + <p> + Are you sure want to delete this author? + </p> + <form id="deleteForm" method="post" action='<?php echo BASEURL; ?>/admin/deleteAuthor'> + <input type="hidden" name="authorName" value="<?php echo $name; ?>"> + </form> + <div class="add-submission"> + <button class="submit-button" onclick="deleteForm()">Delete</button> + <button class="cancel-button" onclick=closeDeletePopup()>Cancel</button> </div> - </tr> - <?php endforeach ?> - </tbody> - </table> - </div> - - <div class="add-popup" id="addpopup"> - <form id="addForm" method="post" action='<?php echo BASEURL; ?>/admin/addUser'> - <div class="add-input"> - <input type="text" id="username" name="newUsername" placeholder="Enter new username.." required> - </div> - <div class="add-input"> - <input type="password" id="password" name="newPassword" placeholder="Enter new password.." required> - </div> - </form> - <div class="add-submission"> - <button type="submit" class="submit-button" onclick="addForm()">Submit</button> - <button class="cancel-button" onclick="closeAddPopup()">Cancel</button> - </div> + </div> + + </tr> + <?php endforeach ?> + </tbody> + </table> + </div> + + <div class="add-popup" id="addpopup"> + <form id="addForm" method="post" action='<?php echo BASEURL; ?>/admin/addAuthor'> + <div class="add-input"> + <input type="text" id="username" name="newAuthorName" placeholder="Enter new username.." required> </div> + </form> + <div class="add-submission"> + <button type="submit" class="submit-button" onclick="addForm()">Submit</button> + <button class="cancel-button" onclick="closeAddPopup()">Cancel</button> + </div> + </div> + + <script src="<?php echo BASEURL; ?>/js/authoradmin.js"></script> +</body> - <script src="<?php echo BASEURL; ?>/js/authoradmin.js"></script> - </body> </html> \ No newline at end of file diff --git a/app/views/library/detailbook.php b/app/views/library/detailbook.php index 4d3229b5aac38be119e4ba85d0ab7eea33ac9187..5ddfc57e493c86aa8198d8c6c16b98743033ae39 100644 --- a/app/views/library/detailbook.php +++ b/app/views/library/detailbook.php @@ -26,6 +26,10 @@ // Echo the values from $data into the HTML template ?> + + <a class="back-button" href="<?php echo BASEURL; ?>/user/index"><i class="fas fa-arrow-left"></i> Back</a> + + <h1 class="book-title"><?php echo $title; ?></h1> <div class="line"></div> <div class="container"> diff --git a/public/js/authoradmin.js b/public/js/authoradmin.js index d6c04121e6a02683365ee1f86f18da7e99b32b19..861ef8ced57cc1c03a73f7b5c1c16592cd8b873b 100644 --- a/public/js/authoradmin.js +++ b/public/js/authoradmin.js @@ -19,9 +19,8 @@ function closeAddPopup(){ pw.value =''; } -function editUser(username, password){ +function editUser(username){ user.value = username; - pw.value = password; editpopup.classList.add("open-edit-popup"); ol.classList.add("open-overlay"); @@ -38,6 +37,10 @@ function addForm(){ const form = document.getElementById("addForm"); form.submit(); } +function deleteForm(){ + const form = document.getElementById("deleteForm"); + form.submit(); +} function deleteUser(){ deletepopup.classList.add("open-delete-popup"); diff --git a/public/style/detailbook.css b/public/style/detailbook.css index b23ab0feb9a1535d52c79660afc093aaee6d78c7..4882d197e95badd8e89cce713aa6f101fb7ef9be 100644 --- a/public/style/detailbook.css +++ b/public/style/detailbook.css @@ -73,4 +73,32 @@ body { padding-left: 15px; padding-right: 15px; font-size: 15px; - } \ No newline at end of file + } + .bookmark:hover { + background-color: #f89a67; + color:#fff5e1; + border: 15px; + outline:invert; + border-radius: 5px; + width:100px; + padding-top:8px; + padding-bottom: 8px; + padding-left: 15px; + padding-right: 15px; + font-size: 15px; + } + .back-button { + display: inline-block; + padding: 10px 20px; + background-color: #f89a67; /* Adjust the background color */ + color: #fff; /* Text color */ + border: none; + border-radius: 5px; + cursor: pointer; + font-size: 16px; + margin-left: 1%; +} +.back-button:hover{ + background-color: #fff5e1; + color: #f89a67; +} \ No newline at end of file