diff --git a/api/admin/course/delete.php b/api/admin/course/delete.php index 25f02b4464c280315ae078a817f86195c8be9e8c..35b7dfd3b3f737530f370913fe1e07479907b141 100644 --- a/api/admin/course/delete.php +++ b/api/admin/course/delete.php @@ -2,6 +2,8 @@ require_once("../../../app/models/Admin.php"); require_once("../../../app/core/App.php"); require_once("../../../app/core/Database.php"); + + require_once("../../../app/models/Course.php"); require_once("../../../app/models/User.php"); require_once("../../../app/core/Table.php"); require_once("../../../config/config.php"); @@ -11,8 +13,13 @@ } if(isset($_POST["id"])){ $admin = new Admin; + $course = new Course; + $deleted_course = $course->single_course($_POST["id"]); + $rows = $admin->delete_course($_POST["id"]); if($rows){ + $rm_image = 'rm ../../..' . $deleted_course["image_path"]; + exec($rm_image); http_response_code(200); $_SESSION["success"] = "Course has been deleted!"; }else{ diff --git a/api/admin/course/edit.php b/api/admin/course/edit.php index d832b8b8f3b482d1ea52625acff52bcb5edfcc73..92666456d28fe4d47794508d80ad9514a41cdc6d 100644 --- a/api/admin/course/edit.php +++ b/api/admin/course/edit.php @@ -33,6 +33,8 @@ $uploaded = false; } if($uploaded){ + $rm = "rm ../../..".$_POST["old_image"]; + exec($rm); $response = move_uploaded_file($_FILES["image"]["tmp_name"],$targeted_file); }else{ header("Location: /admin/courses"); diff --git a/app/views/admin/addCourse.php b/app/views/admin/addCourse.php index a46b2c648182426873d48e3353a81649885133ea..45087a04768dccb8cafd7c0bf19fe8466a7aa076 100644 --- a/app/views/admin/addCourse.php +++ b/app/views/admin/addCourse.php @@ -75,7 +75,7 @@ </label> </div> <div class="button-container"> - <button id = "back-button" class="back-btn">Back</button> + <button id = "back-button" class="back-btn" ><a href="/admin/courses" style="text-decoration:none">Back</a></button> <button type="submit" class="add-btn" id="action-button">Add</button> </div> </form> diff --git a/app/views/admin/editCourse.php b/app/views/admin/editCourse.php index af33a7f0a383b2c5329240ddc337f6ee78e84282..47aab165c0c354ca1bc3e7994996bb7f958bcc74 100644 --- a/app/views/admin/editCourse.php +++ b/app/views/admin/editCourse.php @@ -84,7 +84,7 @@ </label> </div> <div class="button-container"> - <button id = "back-button" class="back-btn">Back</button> + <button id = "back-button" class="back-btn"><a href="/admin/courses">Back</a></button> <button type="submit" class="update-btn" id="action-button">Update</button> </div> </form> diff --git a/app/views/admin/editUser.php b/app/views/admin/editUser.php index 7d7393569989f4372d82939a87e9e4ffd1cb3776..d076130557acd1892431baae2633e16da7af5d95 100644 --- a/app/views/admin/editUser.php +++ b/app/views/admin/editUser.php @@ -65,7 +65,7 @@ </div> <p id="username-alert"></p> <div class="button-container"> - <button id = "back-button" class="back-btn">Back</button> + <button id = "back-button" class="back-btn"><a href="/admin/users" style="text-decoration:none">Back</a></button> <button type="submit" class="update-btn" id="update-button">Update</button> </div> </form> diff --git a/public/js/admin.js b/public/js/admin.js index 9f2fc3c7770e0e36c92e52c56eb20a1ceba184ac..78da71b983b36957f3d350d8d9a7f3b6f3adfa44 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -23,6 +23,7 @@ const handleDelete = (type) => { } else { window.location.href = "/admin/courses"; } + } else { console.log("gagal"); } @@ -35,7 +36,6 @@ let cancelButton = document.getElementById("cancel-btn"); let confirmButton = document.getElementById("confirm-btn"); let popup = document.getElementById("popup-container"); let form = document.getElementById("form"); -let backButton = document.getElementById("back-button"); let oldUsername = document.getElementById("old-username"); let oldFullname = document.getElementById("old-fullname"); updateButton && @@ -126,10 +126,7 @@ const check_username = () => { } check_button(); }; -backButton.addEventListener("click", (e) => { - e.preventDefault(); - window.location.href = "/admin/users"; -}); + const handleUpload = () => { var image = document.getElementById("course-image"); diff --git a/public/js/course.js b/public/js/course.js index 238fb90084033f51c18d5ceb23ff1766ba47c13f..c8872137b47aad0422d7083ab16b2a8a7144988c 100644 --- a/public/js/course.js +++ b/public/js/course.js @@ -26,7 +26,6 @@ const handleSubmit = () => { const xhr = new XMLHttpRequest(); xhr.open("POST", "/api/course/add.php", true); xhr.onload = function () { - console.log(this) let response = JSON.parse(this.responseText); if (this.status == 200) { if(response.status == "success"){ @@ -59,7 +58,6 @@ const handleUpdate = () => { if(this.status === 200){ window.location.href = "/course"; }else{ - console.log(this); alert("Something went wrong!"); } } diff --git a/public/js/detailsCourse.js b/public/js/detailsCourse.js index eba561da6bee5874fface96748785acf8b464204..7975849103bace1f79e04a50ccaf01ff0db60cbf 100644 --- a/public/js/detailsCourse.js +++ b/public/js/detailsCourse.js @@ -78,7 +78,6 @@ const handleAddModule = (id) => { if (this.status === 200) { window.location.href = "/course/preview/" + id; } else { - console.log(this); alert("Something went wrong!"); } } @@ -98,7 +97,6 @@ const handleEditModule = (course_id, module_id) => { if (this.status === 200) { window.location.href = "/course/preview/" + course_id; } else { - console.log(this); alert("Something went wrong!"); } } @@ -114,7 +112,6 @@ const handleDeleteModule = (course_id, module_id) => { if (this.status === 200) { window.location.href = "/course/preview/" + course_id; } else { - console.log(this); alert("Something went wrong!"); } } diff --git a/public/js/detailsModule.js b/public/js/detailsModule.js index dc4641a8848a22b7cf1e5bd7e66a2884280b1559..88bbe92aada7b94066ada25218776fbf35447d33 100644 --- a/public/js/detailsModule.js +++ b/public/js/detailsModule.js @@ -1,62 +1,62 @@ -function reset(){ - var nameArea = document.getElementById('moduleName'); - var descArea = document.getElementById('moduleDescription'); - nameArea.value = ''; - descArea.value = ''; +function reset() { + var nameArea = document.getElementById("moduleName"); + var descArea = document.getElementById("moduleDescription"); + nameArea.value = ""; + descArea.value = ""; var submit_button = document.getElementById("confirm-save"); submit_button.disabled = true; - var test = document.querySelector('.addForm-header'); - test.textContent = 'Add Module'; - document.querySelector('#confirm-save').textContent = 'Add'; -}; + var test = document.querySelector(".addForm-header"); + test.textContent = "Add Module"; + document.querySelector("#confirm-save").textContent = "Add"; +} function openForm(section, cancel, popup) { var popupOverlay = document.querySelector(popup); var popupSection = document.querySelector(section); var closePopup = document.querySelector(cancel); popupSection.classList.add("active"); - popupOverlay.style.display = 'block'; - popupSection.style.display = 'block'; + popupOverlay.style.display = "block"; + popupSection.style.display = "block"; // Add a click event listener to the overlay popupOverlay.addEventListener("click", function () { popupSection.classList.remove("active"); - popupOverlay.style.display = 'none'; - popupSection.style.display = 'none'; + popupOverlay.style.display = "none"; + popupSection.style.display = "none"; reset(); }); // Add a click event listener to the close button closePopup.addEventListener("click", function () { popupSection.classList.remove("active"); - popupOverlay.style.display = 'none'; - popupSection.style.display = 'none'; + popupOverlay.style.display = "none"; + popupSection.style.display = "none"; reset(); }); -}; +} function openFormDeleteModule(course_id, module_id, title) { openForm(".popup-section2", ".cancel-save2", ".popup-overlay2"); var message = document.querySelector(".delete-warning"); message.innerText = "Delete module " + title + "?"; - var button = document.querySelector('.confirm-save2'); - button.onclick = function() { + var button = document.querySelector(".confirm-save2"); + button.onclick = function () { handleDeleteModule(course_id, module_id); }; -}; +} function openFormAddModule() { openForm(".popup-section", ".cancel-save", ".popup-overlay"); -}; +} const openFormEditModule = (module_id, title, description) => { - var test = document.querySelector('.addForm-header'); - test.textContent = 'Edit Module'; - document.querySelector('#confirm-save').textContent = 'Edit'; - document.querySelector('#moduleName').value = title; - document.querySelector('#moduleDescription').value = description; - var button = document.getElementById('confirm-save'); - button.onclick = function() { + var test = document.querySelector(".addForm-header"); + test.textContent = "Edit Module"; + document.querySelector("#confirm-save").textContent = "Edit"; + document.querySelector("#moduleName").value = title; + document.querySelector("#moduleDescription").value = description; + var button = document.getElementById("confirm-save"); + button.onclick = function () { handleEditModule(module_id); }; openForm(".popup-section", ".cancel-save", ".popup-overlay"); @@ -64,37 +64,37 @@ const openFormEditModule = (module_id, title, description) => { function openFormAddMaterial(module_id) { openForm(".popup-section3", ".cancel-save3", ".popup-overlay3"); - button.onclick = function() { + button.onclick = function () { handleAddMaterial(module_id); }; -}; +} function openFormDeleteMaterial(module_id, material_id, title) { openForm(".popup-section2", ".cancel-save2", ".popup-overlay2"); var message = document.querySelector(".delete-warning"); message.innerText = "Delete material " + title + "?"; - var button = document.querySelector('.confirm-save2'); - button.onclick = function() { + var button = document.querySelector(".confirm-save2"); + button.onclick = function () { handleDeleteMaterial(module_id, material_id); }; -}; +} const openFormEditMaterial = (module_id, material_id, title, description) => { - var test = document.querySelector('.addForm-header3'); - test.textContent = 'Edit Material'; - document.querySelector('#confirm-save3').textContent = 'Edit'; - document.querySelector('#materialName').value = title; - document.querySelector('#materialDescription').value = description; - var button = document.getElementById('confirm-save3'); - button.onclick = function() { + var test = document.querySelector(".addForm-header3"); + test.textContent = "Edit Material"; + document.querySelector("#confirm-save3").textContent = "Edit"; + document.querySelector("#materialName").value = title; + document.querySelector("#materialDescription").value = description; + var button = document.getElementById("confirm-save3"); + button.onclick = function () { handleEditMaterial(module_id, material_id); }; openForm(".popup-section3", ".cancel-save3", ".popup-overlay3"); }; const handleEditMaterial = (module_id, material_id) => { - let title = document.getElementById('materialName').value; - let description = document.getElementById('materialDescription').value; + let title = document.getElementById("materialName").value; + let description = document.getElementById("materialDescription").value; let material = document.getElementById("materialFile"); const data = new FormData(); data.append("material_id", parseInt(material_id)); @@ -107,10 +107,9 @@ const handleEditMaterial = (module_id, material_id) => { if (this.status === 200) { window.location.href = "/course/module/" + module_id; } else { - console.log(this); alert("Something went wrong!"); } - } + }; xhr.send(data); }; @@ -122,7 +121,7 @@ const handleAddModule = (course_id, module_id) => { data.append("title", title); data.append("description", description); const xhr = new XMLHttpRequest(); - xhr.open("POST", "/api/module/add.php", true) + xhr.open("POST", "/api/module/add.php", true); xhr.onload = function () { if (this.status === 200) { window.location.href = "/course/module/" + module_id; @@ -130,13 +129,13 @@ const handleAddModule = (course_id, module_id) => { console.log(this); alert("Something went wrong!"); } - } + }; xhr.send(data); }; const handleEditModule = (module_id) => { - var title = document.getElementById('moduleName').value; - var description = document.getElementById('moduleDescription').value; + var title = document.getElementById("moduleName").value; + var description = document.getElementById("moduleDescription").value; const data = new FormData(); data.append("module_id", parseInt(module_id)); data.append("title", title); @@ -147,10 +146,9 @@ const handleEditModule = (module_id) => { if (this.status === 200) { window.location.href = "/course/module/" + module_id; } else { - console.log(this); alert("Something went wrong!"); } - } + }; xhr.send(data); }; @@ -166,13 +164,13 @@ const handleDeleteModule = (course_id, module_id) => { console.log(this); alert("Something went wrong!"); } - } + }; xhr.send(data); }; const handleAddMaterial = (module_id) => { - let title = document.getElementById('materialName').value; - let description = document.getElementById('materialDescription').value; + let title = document.getElementById("materialName").value; + let description = document.getElementById("materialDescription").value; let material = document.getElementById("materialFile"); const data = new FormData(); data.append("module_id", parseInt(module_id)); @@ -186,10 +184,9 @@ const handleAddMaterial = (module_id) => { console.log(this); window.location.href = "/course/module/" + module_id; } else { - console.log(this); alert("Something went wrong!"); } - } + }; xhr.send(data); }; @@ -197,14 +194,13 @@ const handleDeleteMaterial = (module_id, material_id) => { const data = new FormData(); data.append("material_id", parseInt(material_id)); const xhr = new XMLHttpRequest(); - xhr.open("POST", "/api/material/delete.php", true) + xhr.open("POST", "/api/material/delete.php", true); xhr.onload = function () { if (this.status === 200) { window.location.href = "/course/module/" + module_id; } else { - console.log(this); alert("Something went wrong!"); } - } + }; xhr.send(data); };