diff --git a/webseite/classes/TopicData.php b/webseite/classes/TopicData.php index 0247342..fde0cc2 100644 --- a/webseite/classes/TopicData.php +++ b/webseite/classes/TopicData.php @@ -475,6 +475,11 @@ class TopicData return true; } + public function removeAllTasks() + { + $this->tasks = array(); + } + public function getId(): string { return $this->id; diff --git a/webseite/topicEditor.php b/webseite/topicEditor.php index fa5dff5..208aa43 100644 --- a/webseite/topicEditor.php +++ b/webseite/topicEditor.php @@ -3,6 +3,7 @@ require_once("classes/User.php"); require_once("classes/SubjectData.php"); require_once("classes/TopicData.php"); +require_once("classes/Task.php"); session_start(); @@ -22,6 +23,7 @@ $defaultValues['description'] = ""; $defaultValues['icon'] = ""; $defaultValues['relatedTopics'] = ""; $defaultValues['existing_files'] = ""; +$defaultValues['formulas'] = ""; $defaultValues['article'] = ""; $errors = array(); @@ -37,6 +39,17 @@ if (isset($_GET['subject']) && isset($_GET['topic'])) { $defaultValues['icon'] = $editingTopic->getIcon(); $defaultValues['relatedTopics'] = implode(", ", $editingTopic->getRelatedTopics()); $defaultValues['existing_files'] = implode(", ", $editingTopic->getFiles()); + + $tasks = array(); + foreach($editingTopic->getTasks() as $task) { + $variables = array(); + foreach($task->getVariables() as $name => $variable) { + $variables[] = $name . "::" . $variable; + } + + $tasks[] = $task->getText() . ";;" . implode(";;", $variables); + } + $defaultValues['formulas'] = implode(";;;;", $tasks); $defaultValues['article'] = $editingTopic->getFinishedArticle(); } } else if(isset($_GET['subject'])) { @@ -68,6 +81,18 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $errors["icon"] = "Bitte geben Sie ein Icon an."; } + if(!isset($_POST['relatedTopics'])) { + $errors["relatedTopics"] = "Feld relatedTopics nicht mitgesendet!"; + } + + if(!isset($_POST['existing_files'])) { + $errors["existing_files"] = "Feld existing_files nicht mitgesendet!"; + } + + if(!isset($_POST['formulas'])) { + $errors["formulas"] = "Feld formulas nicht mitgesendet!"; + } + if(!isset($_POST['article']) || trim($_POST['article']) == "") { $errors["article"] = "Bitte geben Sie einen Erklärtext an."; } @@ -97,6 +122,38 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $existingFiles[] = trim($existingTopic); } + $formulas = array(); + foreach (explode(";;;;", $_POST['formulas']) as $formulaString) { + $text = false; + $answers = array(); + foreach (explode(";;", $formulaString) as $formulaEntry) { + if(!$text) { + $text = trim($formulaEntry); + continue; + } + + $answer = explode("::", $formulaEntry); + if(count($answer) != 2) { + $errors['formulas'] = "Jede Formel muss einen Text und mindestens eine Antwortmöglichkeit haben!"; + break; + } + + $answers[trim($answer[0])] = trim($answer[1]); + } + + if(!$text) { + $errors['formulas'] = "Jede Formel muss einen Text haben!"; + break; + } + + if(count($answers) == 0) { + $errors['formulas'] = "Jede Formel muss mindestens eine Antwortmöglichkeit haben!"; + break; + } + + $formulas[] = new Task($text, $answers); + } + $article = htmlentities($_POST['article'], ENT_HTML401, 'UTF-8'); $dom = new DOMDocument(); $dom->encoding = 'UTF-8'; @@ -147,6 +204,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { } } $newTopic->setArticle($article); + $newTopic->removeAllTasks(); } else { $newTopic = TopicData::createNew($_POST['id'], $_POST['subjectId'], $_POST['displayName'], $_POST['icon'], $_POST['description'], $relatedTopics, $article); } @@ -162,6 +220,10 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $newTopic->uploadImage($name, $image); } + foreach ($formulas as $formula) { + $newTopic->addTask($formula); + } + if($_POST['submit'] == "Thema löschen") { $newTopic->delete(); header("Location: " . "subject.php?subject=" . $_POST['subjectId']); @@ -275,6 +337,12 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { Übungsblätter hinzufügen + +
+ + +