getTopics()[$_GET['topic']])) { $editingTopic = $allSubjects[$_GET['subject']]->getTopics()[$_GET['topic']]; $defaultValues['displayName'] = $editingTopic->getDisplayName(); $defaultValues['id'] = $editingTopic->getId(); $defaultValues['subjectId'] = $editingTopic->getSubjectId(); $defaultValues['description'] = $editingTopic->getDescription(); $defaultValues['icon'] = $editingTopic->getIcon(); $defaultValues['relatedTopics'] = implode(", ", $editingTopic->getRelatedTopics()); $defaultValues['article'] = $editingTopic->getFinishedArticle(); } } else if(isset($_GET['subject'])) { $defaultValues['subjectId'] = $_GET['subject']; } if($_SERVER['REQUEST_METHOD'] == 'POST') { foreach ($defaultValues as $key => $value) { $defaultValues[$key] = $_POST[$key]; } if(!isset($_POST['displayName']) || trim($_POST['displayName']) == "") { $errors["displayName"] = "Bitte geben Sie einen Namen an."; } if(!isset($_POST['id']) || trim($_POST['id']) == "") { $errors["id"] = "Bitte geben Sie eine ID an."; } if(!isset($_POST['subjectId']) || trim($_POST['subjectId']) == "") { $errors["subjectId"] = "Bitte geben Sie ein Fach an."; } if(!isset($_POST['description']) || trim($_POST['description']) == "") { $errors["description"] = "Bitte geben Sie eine Beschreibung an."; } if(!isset($_POST['icon']) || trim($_POST['icon']) == "") { $errors["icon"] = "Bitte geben Sie ein Icon an."; } if(!isset($_POST['article']) || trim($_POST['article']) == "") { $errors["article"] = "Bitte geben Sie einen Erklärtext an."; } if(!isset($_POST['submit']) || !($_POST['submit'] == "Speichern" || $_POST['submit'] == "Thema löschen")) { $errors["submit"] = "Ungültig abgeschickt!"; } if(empty($errors)) { $newTopic = false; $relatedTopics = array(); foreach (explode(",", $_POST['relatedTopics']) as $relatedTopic) { $relatedTopic = trim($relatedTopic); if($relatedTopic == "") { continue; } $relatedTopics[] = $relatedTopic; } $dom = new DOMDocument(); $dom->loadHTML($_POST['article']); $article = $dom->textContent; if(isset($allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']])) { $newTopic = $allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']]; $newTopic->setDisplayName($_POST['displayName']); $newTopic->setSubjectId($_POST['subjectId']); $newTopic->setDescription($_POST['description']); $newTopic->setIcon($_POST['icon']); $newTopic->setRelatedTopics($relatedTopics); $newTopic->setArticle($article); } else { $newTopic = TopicData::createNew($_POST['id'], $_POST['subjectId'], $_POST['displayName'], $_POST['icon'], $_POST['description'], $relatedTopics, $article); } if(!$newTopic) { $errors["error"] = "Fehler beim Speichern des Themas."; } else { if($_POST['submit'] == "Thema löschen") { $newTopic->delete(); header("Location: " . "subject.php?subject=" . $_POST['subjectId']); } else { $newTopic->save(); header("Location: " . "topic.php?subject=" . $newTopic->getSubjectId() . "&topic=" . $newTopic->getId()); } } } } ?> Lehrer Dashboard

Vorschau