diff --git a/app/public/actions/addAnime.php b/app/api/anime/add.php similarity index 100% rename from app/public/actions/addAnime.php rename to app/api/anime/add.php diff --git a/app/public/actions/deleteAnime.php b/app/api/anime/delete.php similarity index 100% rename from app/public/actions/deleteAnime.php rename to app/api/anime/delete.php diff --git a/app/public/actions/editAnime.php b/app/api/anime/edit.php similarity index 100% rename from app/public/actions/editAnime.php rename to app/api/anime/edit.php diff --git a/app/public/actions/addClient.php b/app/api/client/add.php similarity index 100% rename from app/public/actions/addClient.php rename to app/api/client/add.php diff --git a/app/public/actions/deleteClient.php b/app/api/client/delete.php similarity index 100% rename from app/public/actions/deleteClient.php rename to app/api/client/delete.php diff --git a/app/public/actions/editClient.php b/app/api/client/edit.php similarity index 100% rename from app/public/actions/editClient.php rename to app/api/client/edit.php diff --git a/app/public/actions/addStudio.php b/app/api/studio/add.php similarity index 100% rename from app/public/actions/addStudio.php rename to app/api/studio/add.php diff --git a/app/public/actions/deleteStudio.php b/app/api/studio/delete.php similarity index 100% rename from app/public/actions/deleteStudio.php rename to app/api/studio/delete.php diff --git a/app/public/actions/editStudio.php b/app/api/studio/edit.php similarity index 100% rename from app/public/actions/editStudio.php rename to app/api/studio/edit.php diff --git a/app/public/handler/admin.js b/app/public/handler/admin.js index 78c6edb798fc52c62c4c96686135e6cb7ea7533d..cf3089ce85dbc3277cfbf7ca058700fc36ae5541 100644 --- a/app/public/handler/admin.js +++ b/app/public/handler/admin.js @@ -27,7 +27,7 @@ document.addEventListener('DOMContentLoaded', function() { let clientId = e.target.getAttribute('client-id'); if (confirm('Are you sure you want to delete this client?')) { - window.location.href = `/public/actions/deleteClient.php?id=${clientId}`; + window.location.href = `/api/client/delete.php?id=${clientId}`; } }); }); @@ -41,7 +41,7 @@ document.addEventListener('DOMContentLoaded', function() { let animeId = e.target.getAttribute('anime-id'); if (confirm('Are you sure you want to delete this anime?')) { - window.location.href = `/public/actions/deleteAnime.php?id=${animeId}`; + window.location.href = `/api/anime/delete.php?id=${animeId}`; } }); }); @@ -55,7 +55,7 @@ document.addEventListener('DOMContentLoaded', function() { let studioId = e.target.getAttribute('studio-id'); if (confirm('Are you sure you want to delete this studio?')) { - window.location.href = `/public/actions/deleteStudio.php?id=${studioId}`; + window.location.href = `/api/studio/delete.php?id=${studioId}`; } }); }); diff --git a/app/public/handler/client.js b/app/public/handler/client.js new file mode 100644 index 0000000000000000000000000000000000000000..3f20c8875703c24fbb603740b43c9e4003ea869e --- /dev/null +++ b/app/public/handler/client.js @@ -0,0 +1,39 @@ +function openModal(button){ + const clientId = button.getAttribute('data-client-id'); + const username = button.getAttribute('data-username'); + const email = button.getAttribute('data-email'); + const password = button.getAttribute('data-password'); + const birthdate = button.getAttribute('data-birthdate'); + const bio = button.getAttribute('data-bio'); + const imagePath = button.getAttribute('data-image'); + + // Populate the modal's fields with the extracted data + document.getElementById('editClientId').value = clientId; + document.getElementById('editUsername').value = username; + document.getElementById('editEmail').value = email; + document.getElementById('editPassword').value = password; + document.getElementById('editBio').value = bio; + + const imageElement = document.getElementById('currentImage'); + if(imagePath) { + imageElement.src = imagePath; + imageElement.alt = "Current Image"; + imageElement.style.display = ""; // show image + } else { + imageElement.style.display = "none"; // hide image + } + + + if (birthdate) { + document.getElementById('editBirthdate').value = birthdate; + } else { + document.getElementById('editBirthdate').value = null; + } + + // Display the modal + document.getElementById('edit-modal').style.display = 'block'; +} + +function closeModal(){ + document.getElementById('edit-modal').style.display = 'none'; +} \ No newline at end of file diff --git a/app/public/style/admin.css b/app/public/style/admin.css index 5a0c1c0a003de026e13f90c1e72828dc83cb85fd..fc571cda5b8c7afebb2123f6c2571abe5d2072d7 100644 --- a/app/public/style/admin.css +++ b/app/public/style/admin.css @@ -138,18 +138,16 @@ th { top: 0; width: 100%; height: 100%; - background-color: rgba(0,0,0,0.4); + overflow: auto; + background-color: rgba(0,0,0,0.85); } .modal-content { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%,-50%); + margin: 30px auto; background-color: #fefefe; padding: 20px; border: 1px solid #888; - width: 50%; + width: 60%; } .close-btn { diff --git a/app/public/style/client.css b/app/public/style/client.css index 994513986b7609f86cf635ab0bcbbba6502f40a3..3c89410e012299f370811b45d430d41336946bd4 100644 --- a/app/public/style/client.css +++ b/app/public/style/client.css @@ -87,6 +87,7 @@ cursor: pointer; transition: ease-in-out; transition-duration: 0.2s; + border: none; } .client-edit-button:hover { @@ -184,3 +185,45 @@ object-fit: contain; object-position: center; } + +.modal { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.85); + overflow: auto; +} + +.modal-content { + margin: 30px auto; + background-color: #fefefe; + padding: 20px; + border: 1px solid #888; + width: 50%; +} + +.close-btn { + color: black; + float: right; + font-size: 28px; + font-weight: bold; + cursor: pointer; +} + +.close-btn:hover, +.close-btn:focus { + color: #656565; + text-decoration: none; + cursor: pointer; +} + +.form-vertical { + display: flex; + flex-direction: column; + gap: 10px; /* Provides space between each item */ + width: 45%px; /* Adjust based on your preference */ +} diff --git a/app/views/Admin/index.php b/app/views/Admin/index.php index 214a85c439522680d833cf04155329562edd4243..a49ac5b53f4dc5772062132f4ba0f100b4b81d53 100644 --- a/app/views/Admin/index.php +++ b/app/views/Admin/index.php @@ -43,7 +43,7 @@ $s = new Studio(); <span class="close-btn" onclick="closeAddModal()">×</span> <h2>Add New Client</h2> - <form class="form-vertical" action="/public/actions/addClient.php" method="post" enctype="multipart/form-data"> + <form class="form-vertical" action="/api/client/add.php" method="post" enctype="multipart/form-data"> <label for="username">Username:</label> <input type="text" id="username" name="username" placeholder="Username" required> @@ -79,7 +79,7 @@ $s = new Studio(); <span class="close-btn" onclick="closeAddModal()">×</span> <h2>Add New Anime</h2> - <form class="form-vertical" action="/public/actions/addAnime.php" method="post" enctype="multipart/form-data"> + <form class="form-vertical" action="/api/anime/add.php" method="post" enctype="multipart/form-data"> <label for="title">Title:</label> <input type="text" id="title" name="title" placeholder="Title" required> @@ -141,7 +141,7 @@ $s = new Studio(); <span class="close-btn" onclick="closeAddModal()">×</span> <h2>Add New Studio</h2> - <form class="form-vertical" action="/public/actions/addStudio.php" method="post" enctype="multipart/form-data"> + <form class="form-vertical" action="/api/studio/add.php" method="post" enctype="multipart/form-data"> <label for="name">Name:</label> <input type="text" id="name" name="name" placeholder="Name" required> @@ -230,7 +230,7 @@ $s = new Studio(); <span class="close-btn" onclick="closeEditClientModal()">×</span> <h2>Edit Client</h2> - <form class="form-vertical" action="/public/actions/editClient.php" method="post" enctype="multipart/form-data"> + <form class="form-vertical" action="/api/client/edit.php" method="post" enctype="multipart/form-data"> <!-- Hidden input for client_id --> <input type="hidden" id="editClientId" name="client_id"> @@ -345,7 +345,7 @@ $s = new Studio(); <span class="close-btn" onclick="closeEditAnimeModal()">×</span> <h2>Edit Anime</h2> - <form class="form-vertical" action="/public/actions/editAnime.php" method="post" enctype="multipart/form-data"> + <form class="form-vertical" action="/api/anime/edit.php" method="post" enctype="multipart/form-data"> <!-- Hidden input for anime_id --> <input type="hidden" id="editAnimeId" name="anime_id"> @@ -467,7 +467,7 @@ $s = new Studio(); <span class="close-btn" onclick="closeEditStudioModal()">×</span> <h2>Edit Studio</h2> - <form class="form-vertical" action="/public/actions/editStudio.php" method="post" enctype="multipart/form-data"> + <form class="form-vertical" action="/api/studio/edit.php" method="post" enctype="multipart/form-data"> <input type="hidden" id="editStudioId" name="studio_id"> <label for="editName">Name:</label> diff --git a/app/views/Client/detail.php b/app/views/Client/detail.php index eac1a015138698c216c98f318c9ce3b1e6d758fb..6a819509728f6d362b5e10c13386e1da8e41b370 100644 --- a/app/views/Client/detail.php +++ b/app/views/Client/detail.php @@ -24,9 +24,57 @@ $isUser = $c->getClientByUsername($_SESSION['username'])['client_id'] == $id; <link rel="stylesheet" href="../../public/style/global.css"> <link rel="stylesheet" href="../../public/style/client.css"> <script src='/public/handler/navbar.js'></script> + <script src='/public/handler/client.js'></script> </head> <body> + <div id ='edit-modal' class='modal' > + <div class="modal-content"> + <span class="close-btn" onclick="closeModal()">×</span> + <h2>Edit Profile</h2> + + <form class="form-vertical" action="/api/client/edit.php" method="post" enctype="multipart/form-data"> + <!-- Hidden input for client_id --> + <input type="hidden" id="editClientId" name="client_id"> + + <label for="editUsername">Username:</label> + <input type="text" id="editUsername" name="username" required> + + <label for="editEmail">Email:</label> + <input type="email" id="editEmail" name="email" required> + + <label for="editBirthdate">Established Date:</label> + <input type="date" id="editBirthdate" name="birthdate"> + + <!-- Note: Consider if you really want to show and edit passwords this way --> + <label for="editPassword">Password:</label> + <input type="text" id="editPassword" name="password" required> + + <label for="editAdminStatus">Status:</label> + <select id="editAdminStatus" name="admin_status"> + <?php + $option = $client['admin_status'] ? 'Admin' : 'Client'; + echo + " + <option value='$client[admin_status]'>$option</option> + "; + ?> + </select> + + <label for="editBio">Bio:</label> + <textarea id="editBio" name="bio"></textarea> + + <label for="currentImage">Current Image:</label> + <img src="" alt="No image available." id="currentImage" style="display: none;"> + + <label for="newImage">Update Image:</label> + <input type="file" id="newImage" name="newImage"> + + <input type="submit" value="Update Client"> + </form> + </div> +`</div> + <div class='client-big-container'> <div class='client-left-container'> <div class='client-main-container'> @@ -47,7 +95,15 @@ $isUser = $c->getClientByUsername($_SESSION['username'])['client_id'] == $id; "; if ($isUser){ echo " - <div class='client-edit-button'> Edit profile </div> + <button class='client-edit-button' onclick='openModal(this)' + data-client-id=$client[client_id] + data-username='$client[username]' + data-email='$client[email]' + data-password='$client[password]' + data-birthdate='$client[birthdate]' ?? '' + data-bio='$client[bio]' + data-image='$client[image]' + > Edit profile </button> "; } ?>