diff --git a/api/material/delete.php b/api/material/delete.php index c856ba07670f468d3660cc4bd379086ab5735814..8b86478eb95b5dbccfe92fe80247942ab768c14d 100644 --- a/api/material/delete.php +++ b/api/material/delete.php @@ -10,7 +10,12 @@ if(isset($_POST["material_id"])){ $material = new Material(); - $rows = $material->delete_material($_POST["material_id"]); + + $deleted_material = $material->single_material($_POST["material_id"]); + $rm_file = 'rm ../..' . $deleted_material["material_path"]; + exec($rm_file); + + $rows = $material->delete_material($_POST["material_id"]); if($rows){ http_response_code(200); $_SESSION["success"] = "Material has been deleted!"; diff --git a/api/material/edit.php b/api/material/edit.php index 76cc8a6d0298bbd98abf1e6e1dc9f00f0c7ef94a..2172dd4139e820b90fb39de741a1dc8e02fd3ce4 100644 --- a/api/material/edit.php +++ b/api/material/edit.php @@ -32,6 +32,11 @@ $response = move_uploaded_file($_FILES["material_path"]["tmp_name"],$targeted_file); $saved_file = $material_file; } + + $deleted_material = $material->single_material($_POST["material_id"]); + $rm_file = 'rm ../..' . $deleted_material["material_path"]; + exec($rm_file); + $rows = $material->update_material($material_id,$title,$description,$material_type,$saved_file); if($rows){ http_response_code(200); diff --git a/app/models/Material.php b/app/models/Material.php index b78deb613cc3b5ef9e60462037ff2ba191a835d1..ecc7a09c9a4b355bcf2f9b54e4309a5f84a69fb9 100644 --- a/app/models/Material.php +++ b/app/models/Material.php @@ -34,5 +34,14 @@ class Material extends Model{ $this->database->execute(); return $this->database->rowCount(); } + + public function single_material($id){ + $query = "SELECT * FROM materials WHERE material_id = :material_id"; + $this->database->query($query); + $this->database->bind("material_id",$id); + $result = $this->database->single_fetch(); + return $result; + } + } ?> \ No newline at end of file diff --git a/app/views/courses/detailModule.php b/app/views/courses/detailModule.php index c6e43c8b9b4a0fc9d2149ef1500131273d55810b..733db74f05d04e4d1f560ea5f6c145ccf464378a 100644 --- a/app/views/courses/detailModule.php +++ b/app/views/courses/detailModule.php @@ -257,7 +257,7 @@ <path fill='#564C95' d='M19 19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .896-2 2v14c0 1.104.897 2 2 2h14a2 2 0 0 0 2-2v-8.668l-2 2V19z'></path> </svg> </i> - <i onclick='openFormDeleteMaterial(\"$module[module_id]\", \"$material[material_id]\", \"$material[title]\")'> + <i onclick='openFormDeleteMaterial(\"$module[module_id]\", \"$material[material_id]\", \"$material[title]\", \"$material[material_path]\")'> <svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' style='fill: #564C95 ;'> <path d='M6 7H5v13a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7H6zm10.618-3L15 2H9L7.382 4H3v2h18V4z'></path> </svg> diff --git a/app/views/navbar/navbar.php b/app/views/navbar/navbar.php index b9697927bcebd41459af9d28c387f0d1c53cd601..6f215fe532a640963f346937404b737a65cc8bd5 100644 --- a/app/views/navbar/navbar.php +++ b/app/views/navbar/navbar.php @@ -98,7 +98,7 @@ <li> <a href="/search"> <i> - <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" style="fill: rgba(0, 0, 0, 1);transform: ;msFilter:;"> + <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" style="fill: rgba(0, 0, 0, 1);"> <path fill="white" d="M19.023 16.977a35.13 35.13 0 0 1-1.367-1.384c-.372-.378-.596-.653-.596-.653l-2.8-1.337A6.962 6.962 0 0 0 16 9c0-3.859-3.14-7-7-7S2 5.141 2 9s3.14 7 7 7c1.763 0 3.37-.66 4.603-1.739l1.337 2.8s.275.224.653.596c.387.363.896.854 1.384 1.367l1.358 1.392.604.646 2.121-2.121-.646-.604c-.379-.372-.885-.866-1.391-1.36zM9 14c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z"></path> </svg> </i> diff --git a/public/file/.gitkeep b/public/file/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/public/image/course/.gitkeep b/public/image/course/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/public/image/course/defaultprofilepicture.jpg b/public/image/course/defaultprofilepicture.jpg deleted file mode 100644 index aa55b282dffd60b7a561fa52b4a5c9ecf8a97068..0000000000000000000000000000000000000000 Binary files a/public/image/course/defaultprofilepicture.jpg and /dev/null differ diff --git a/public/js/detailsModule.js b/public/js/detailsModule.js index 88bbe92aada7b94066ada25218776fbf35447d33..a0562f7cc376e35a8618f21a0761e67a8da33847 100644 --- a/public/js/detailsModule.js +++ b/public/js/detailsModule.js @@ -69,13 +69,13 @@ function openFormAddMaterial(module_id) { }; } -function openFormDeleteMaterial(module_id, material_id, title) { +function openFormDeleteMaterial(module_id, material_id, title, material_path) { 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 () { - handleDeleteMaterial(module_id, material_id); + handleDeleteMaterial(module_id, material_id, material_path); }; } @@ -190,9 +190,10 @@ const handleAddMaterial = (module_id) => { xhr.send(data); }; -const handleDeleteMaterial = (module_id, material_id) => { +const handleDeleteMaterial = (module_id, material_id, material_path) => { const data = new FormData(); data.append("material_id", parseInt(material_id)); + data.append("old_file", material_path); const xhr = new XMLHttpRequest(); xhr.open("POST", "/api/material/delete.php", true); xhr.onload = function () {