diff --git a/app/controllers/admin.php b/app/controllers/admin.php index 60bfca62c0f96dee3f412d04230907b5461b10b5..e7e1085fe5f5b04ac556afd3ad4ce282d93ef6d7 100644 --- a/app/controllers/admin.php +++ b/app/controllers/admin.php @@ -111,22 +111,21 @@ class Admin extends Controller { if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') { if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Get values from the input form - $newAuthorName = $_POST['newAuthorName']; // Assuming you have an input field for author name - // Additional author-related fields can be added here - $oldAuthorName = $_POST['authorName']; // Assuming you have a hidden input for the old author name - - // Check if the new author name doesn't already exist in the database - $data['authors'] = $this->model('AuthorModel')->getAllAuthors(); + $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)){ - // Update the author's information in the database using your AuthorModel - $this->model('AuthorModel')->updateAuthor($oldAuthorName, $newAuthorName); // Adjust this according to your model's method + + $this->model('AuthorModel')->updateAuthor($oldAuthorName, $newAuthorName); } } - // Fetch the list of authors (optional) - $data['authors'] = $this->model('AuthorModel')->getAllAuthors(); - $this->view('admin/authoradmin', $data); // Adjust the view file and path accordingly + + $data['authors'] = $this->model('AuthorModel')->getAllAuthor(); + $this->view('admin/authoradmin', $data); } else { $this->view('login/login'); } diff --git a/app/models/AuthorModel.php b/app/models/AuthorModel.php index 8684fd6bd2d516e0db6949de29d5e6428d472631..e2bff15e4825aa281456018a60c3980c00946547 100644 --- a/app/models/AuthorModel.php +++ b/app/models/AuthorModel.php @@ -21,4 +21,10 @@ class AuthorModel $this->database->query('SELECT name FROM author'); return $this->database->resultSet(); } + 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(); + } } \ No newline at end of file diff --git a/app/views/admin/authoradmin.php b/app/views/admin/authoradmin.php index 280a628ec77fa276c706420f6907edb4b8395480..2283b6cca8e4371393c7389ee3d5f446dc8641a0 100644 --- a/app/views/admin/authoradmin.php +++ b/app/views/admin/authoradmin.php @@ -32,7 +32,7 @@ </tr> </thead> <tbody> - <?php foreach ($data['user'] as $row): ?> + <?php foreach ($data['authors'] as $row): ?> <?php $id = $row['id']; $name = $row['name']; @@ -51,7 +51,7 @@ </td> <div class="edit-popup" id="editpopup"> <form id="editForm" method="post" action='<?php echo BASEURL; ?>/admin/editAuthor'> - <input type="hidden" name="username" value="<?php echo $name; ?>"> + <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> diff --git a/mysql/#innodb_redo/#ib_redo9 b/mysql/#innodb_redo/#ib_redo9 index 6669a0938a75cba049a46e91ee04e95773f80369..00b0647c4097e84234df80c55cf00055d2bd4aaa 100644 Binary files a/mysql/#innodb_redo/#ib_redo9 and b/mysql/#innodb_redo/#ib_redo9 differ diff --git a/public/js/authoradmin.js b/public/js/authoradmin.js index d6c04121e6a02683365ee1f86f18da7e99b32b19..8dcf57ee4f61ad5c58de530befaff0821cb28665 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");