Skip to content
Snippets Groups Projects
Commit 6be44eaf authored by Naufal-Nalendra's avatar Naufal-Nalendra
Browse files

feat: edit author for author admin

parent 490cdc78
No related merge requests found
......@@ -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');
}
......
......@@ -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
......@@ -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>
......
No preview for this file type
......@@ -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");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment