diff --git a/webseite/classes/TopicData.php b/webseite/classes/TopicData.php index c157c0d..6c315ff 100644 --- a/webseite/classes/TopicData.php +++ b/webseite/classes/TopicData.php @@ -127,7 +127,14 @@ class TopicData { $result = array(); + if(!is_dir(Config::getTopicsDirectory($subjectId))) { + return array(); + } + $topicNames = scandir(Config::getTopicsDirectory($subjectId)); + if(!$topicNames) { + return array(); + } usort($topicNames, function ($a, $b) { return strcmp($a, $b); diff --git a/webseite/config/subjects/mathe/properties.json b/webseite/config/subjects/mathe/properties.json index 5b6cb74..f49e3fe 100644 --- a/webseite/config/subjects/mathe/properties.json +++ b/webseite/config/subjects/mathe/properties.json @@ -1,6 +1,6 @@ { "displayName": "Mathe", - "description": "Mathe ist blau", - "color": "#3b82f6", + "description": "Mathe ist rot", + "color": "#626cd0", "icon": "fa-square-root-alt" } \ No newline at end of file diff --git a/webseite/config/subjects/physik/properties.json b/webseite/config/subjects/physik/properties.json new file mode 100644 index 0000000..8f3b5c2 --- /dev/null +++ b/webseite/config/subjects/physik/properties.json @@ -0,0 +1,6 @@ +{ + "displayName": "Physik", + "description": "Noch ein Fach", + "color": "#363cfc", + "icon": "fa-square-root-alt" +} \ No newline at end of file diff --git a/webseite/subjectEditor.php b/webseite/subjectEditor.php index 45d6296..448da70 100644 --- a/webseite/subjectEditor.php +++ b/webseite/subjectEditor.php @@ -6,8 +6,70 @@ require_once("classes/TopicData.php"); $allSubjects = SubjectData::getAll(); $editingSubject = null; +$defaultValues = array(); +$defaultValues['displayName'] = ""; +$defaultValues['id'] = ""; +$defaultValues['description'] = ""; +$defaultValues['color'] = "#3b82f6"; +$defaultValues['icon'] = ""; + +$errors = array(); + if (isset($_GET['subjectId'])) { $editingSubject = $allSubjects[$_GET['subjectId']]; + + $defaultValues['displayName'] = $editingSubject->getDisplayName(); + $defaultValues['id'] = $editingSubject->getId(); + $defaultValues['description'] = $editingSubject->getDescription(); + $defaultValues['color'] = $editingSubject->getColor(); + $defaultValues['icon'] = $editingSubject->getIcon(); +} + +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['description']) || trim($_POST['description']) == "") { + $errors["description"] = "Bitte geben Sie eine Beschreibung an."; + } + + if(!isset($_POST['color']) || trim($_POST['color']) == "") { + $errors["color"] = "Bitte geben Sie eine Farbe an."; + } + + if(!isset($_POST['icon']) || trim($_POST['icon']) == "") { + $errors["icon"] = "Bitte geben Sie ein Icon an."; + } + + if(empty($errors)) { + $newSubject = false; + if(isset($allSubjects[$_POST['id']])) { + $newSubject = $allSubjects[$_POST['id']]; + $newSubject->setDisplayName($_POST['displayName']); + $newSubject->setDescription($_POST['description']); + $newSubject->setColor($_POST['color']); + $newSubject->setIcon($_POST['icon']); + } else { + $newSubject = SubjectData::createNew($_POST['id'], $_POST['displayName'], $_POST['description'], $_POST['color'], $_POST['icon'], array()); + } + + if(!$newSubject) { + $errors["error"] = "Fehler beim Speichern des Faches."; + } else { + $newSubject->save(); + header("Location: " . "subject.php?subject=" . $newSubject->getId()); + } + } + } ?> @@ -29,7 +91,7 @@ if (isset($_GET['subjectId'])) {
-