From 254630ab67b4d51547b3ab29cd4b5af9da12918e Mon Sep 17 00:00:00 2001 From: Matthias Grief Date: Thu, 2 Jan 2025 18:28:04 +0100 Subject: [PATCH] =?UTF-8?q?Bearbeitung=20von=20=C3=9Cbungsbl=C3=A4ttern=20?= =?UTF-8?q?eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webseite/classes/TopicData.php | 8 +++-- webseite/topicEditor.php | 54 +++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/webseite/classes/TopicData.php b/webseite/classes/TopicData.php index 67f6a31..0247342 100644 --- a/webseite/classes/TopicData.php +++ b/webseite/classes/TopicData.php @@ -226,7 +226,7 @@ class TopicData } $result->cleanupRelatedTopics(); - $result->cleanupFiles(); + //$result->cleanupFiles(); return $result; } @@ -238,7 +238,7 @@ class TopicData public function save(): bool { $this->cleanupRelatedTopics(); - $this->cleanupFiles(); + //$this->cleanupFiles(); $data = array(); $data["displayName"] = $this->displayName; @@ -316,11 +316,13 @@ class TopicData */ public function deleteDownload(string $name): bool { - if (!isset($this->files[$name])) { + if (!in_array($name, $this->files)) { + echo "a"; return false; } if (!unlink(Config::getTopicDirectory($this->getSubjectId(), $this->getId()) . "downloads/$name")) { + echo "b"; return false; } diff --git a/webseite/topicEditor.php b/webseite/topicEditor.php index fb0a55c..86d4634 100644 --- a/webseite/topicEditor.php +++ b/webseite/topicEditor.php @@ -15,6 +15,7 @@ $defaultValues['subjectId'] = ""; $defaultValues['description'] = ""; $defaultValues['icon'] = ""; $defaultValues['relatedTopics'] = ""; +$defaultValues['existing_files'] = ""; $defaultValues['article'] = ""; $errors = array(); @@ -29,6 +30,7 @@ if (isset($_GET['subject']) && isset($_GET['topic'])) { $defaultValues['description'] = $editingTopic->getDescription(); $defaultValues['icon'] = $editingTopic->getIcon(); $defaultValues['relatedTopics'] = implode(", ", $editingTopic->getRelatedTopics()); + $defaultValues['existing_files'] = implode(", ", $editingTopic->getFiles()); $defaultValues['article'] = $editingTopic->getFinishedArticle(); } } else if(isset($_GET['subject'])) { @@ -80,8 +82,16 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $relatedTopics[] = $relatedTopic; } - $article = htmlentities($_POST['article'], ENT_HTML401, 'UTF-8'); + $existingFiles = array(); + foreach (explode(",", $_POST['existing_files']) as $existingTopic) { + $existingTopic = trim($existingTopic); + if($existingTopic == "") { + continue; + } + $existingFiles[] = trim($existingTopic); + } + $article = htmlentities($_POST['article'], ENT_HTML401, 'UTF-8'); $dom = new DOMDocument(); $dom->encoding = 'UTF-8'; $dom->loadHTML($article, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); @@ -114,6 +124,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $htmlImage->setAttribute("src", '__TOPICPATH__/' . $imagename); } + // extension=mbstring in php.ini muss aktiviert sein! $article = mb_convert_encoding($dom->saveHTML(), 'UTF-8', 'HTML-ENTITIES'); if(isset($allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']])) { @@ -123,8 +134,12 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $newTopic->setSubjectId($_POST['subjectId']); $newTopic->setDescription($_POST['description']); $newTopic->setIcon($_POST['icon']); - $newTopic->setRelatedTopics($relatedTopics); + foreach ($newTopic->getFiles() as $file) { + if(!in_array($file, $existingFiles)) { + $newTopic->deleteDownload($file); + } + } $newTopic->setArticle($article); } else { $newTopic = TopicData::createNew($_POST['id'], $_POST['subjectId'], $_POST['displayName'], $_POST['icon'], $_POST['description'], $relatedTopics, $article); @@ -133,6 +148,10 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { if(!$newTopic) { $errors["error"] = "Fehler beim Speichern des Themas."; } else { + for($i = 0; $i < count($_FILES['new_files']['name']); $i++) { + !$newTopic->addDownload($_FILES['new_files']['name'][$i], $_FILES['new_files']['tmp_name'][$i]); + } + foreach ($newImages as $name => $image) { $newTopic->uploadImage($name, $image); } @@ -174,7 +193,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { -
+
@@ -227,6 +246,29 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
+ +
+ + +
+ +
+ + +
+ +
+ + +
@@ -246,14 +288,12 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { -
- -
+ ?>