Teil 2 #94

Merged
mg8220s merged 121 commits from dev into main 2025-01-08 10:16:03 +01:00
4 changed files with 50 additions and 40 deletions
Showing only changes of commit 9f58a55bc0 - Show all commits

View File

@@ -1,6 +1,6 @@
{ {
"displayName": "Englisch", "displayName": "Englisch",
"description": "He she it das s muss mit!", "description": "He she it das s muss mit!",
"color": "#17B750", "color": "#17b750",
"icon": "fa-language" "icon": "fa-language"
} }

View File

@@ -1,6 +0,0 @@
{
"displayName": "Physik",
"description": "Noch ein Fach",
"color": "#363cfc",
"icon": "fa-square-root-alt"
}

View File

@@ -50,6 +50,10 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors["icon"] = "Bitte geben Sie ein Icon an."; $errors["icon"] = "Bitte geben Sie ein Icon an.";
} }
if(!isset($_POST['submit']) || !($_POST['submit'] == "Speichern" || $_POST['submit'] == "Fach löschen")) {
$errors["submit"] = "Ungültig abgeschickt!";
}
if(empty($errors)) { if(empty($errors)) {
$newSubject = false; $newSubject = false;
if(isset($allSubjects[$_POST['id']])) { if(isset($allSubjects[$_POST['id']])) {
@@ -65,11 +69,15 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!$newSubject) { if(!$newSubject) {
$errors["error"] = "Fehler beim Speichern des Faches."; $errors["error"] = "Fehler beim Speichern des Faches.";
} else { } else {
$newSubject->save(); if($_POST['submit'] == "Fach löschen") {
header("Location: " . "subject.php?subject=" . $newSubject->getId()); $newSubject->delete();
header("Location: " . "index.php");
} else {
$newSubject->save();
header("Location: " . "subject.php?subject=" . $newSubject->getId());
}
} }
} }
} }
?> ?>
@@ -184,16 +192,13 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
</div> </div>
<div class="flow-root mt-8 gap-4">
<div class="mt-8 flex justify-end gap-3"> <input type="submit" value="Fach löschen" name="submit"
<button type="button" onclick="closeModal()" class="float-left px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-gray-200">
class="px-6 py-3 text-gray-600 hover:text-gray-800 text-lg"> <input type="submit" value="Speichern" name="submit"
Abbrechen class="float-right px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
</button> <input type="button" value="Abbrechen" onclick="history.back()"
<button type="submit" class="float-right mx-2 px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200">
class="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-lg">
Speichern
</button>
</div> </div>
</form> </form>

View File

@@ -64,34 +64,47 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors["article"] = "Bitte geben Sie einen Erklärtext an."; $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)) { if(empty($errors)) {
$newTopic = false; $newTopic = false;
$relatedTopics = array();
foreach (explode(",", $_POST['relatedTopics']) as $relatedTopic) {
$relatedTopic = trim($relatedTopic);
if($relatedTopic == "") {
continue;
}
$relatedTopics[] = $relatedTopic;
}
if(isset($allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']])) { if(isset($allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']])) {
$newTopic = $allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']]; $newTopic = $allSubjects[$_POST['subjectId']]->getTopics()[$_POST['id']];
$newTopic->setDisplayName($_POST['displayName']); $newTopic->setDisplayName($_POST['displayName']);
$newTopic->setSubjectId($_POST['subjectId']); $newTopic->setSubjectId($_POST['subjectId']);
$newTopic->setDescription($_POST['description']); $newTopic->setDescription($_POST['description']);
$newTopic->setIcon($_POST['icon']); $newTopic->setIcon($_POST['icon']);
$relatedTopics = array();
foreach (explode(",", $_POST['relatedTopics']) as $relatedTopic) {
$relatedTopic = trim($relatedTopic);
if($relatedTopic == "") {
continue;
}
$relatedTopics[] = $relatedTopic;
}
$newTopic->setRelatedTopics($relatedTopics); $newTopic->setRelatedTopics($relatedTopics);
$newTopic->setArticle($_POST['article']); $newTopic->setArticle($_POST['article']);
} else { } else {
$newTopic = TopicData::createNew($_POST['id'], $_POST['subjectId'], $_POST['displayName'], $_POST['icon'], $_POST['description'], $_POST['relatedTopics'], $_POST['article']); $newTopic = TopicData::createNew($_POST['id'], $_POST['subjectId'], $_POST['displayName'], $_POST['icon'], $_POST['description'], $relatedTopics, $_POST['article']);
} }
if(!$newTopic) { if(!$newTopic) {
$errors["error"] = "Fehler beim Speichern des Themas."; $errors["error"] = "Fehler beim Speichern des Themas.";
} else { } else {
$newTopic->save(); if($_POST['submit'] == "Thema löschen") {
header("Location: " . "topic.php?subject=" . $newTopic->getSubjectId() . "&topic=" . $newTopic->getId()); $newTopic->delete();
header("Location: " . "subject.php?subject=" . $_POST['subjectId']);
} else {
$newTopic->save();
header("Location: " . "topic.php?subject=" . $newTopic->getSubjectId() . "&topic=" . $newTopic->getId());
}
} }
} }
@@ -210,15 +223,13 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
<div id="contentPreview" class="content-text prose prose-lg max-w-none bg-white p-6 rounded-lg shadow-sm"></div> <div id="contentPreview" class="content-text prose prose-lg max-w-none bg-white p-6 rounded-lg shadow-sm"></div>
</div> </div>
<div class="flex justify-end gap-4"> <div class="flow-root gap-4">
<button type="button" onclick="closeModal()" <input type="submit" value="Thema löschen" name="submit"
class="px-4 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200"> class="float-left px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-gray-200">
Abbrechen <input type="submit" value="Speichern" name="submit"
</button> class="float-right px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
<button type="submit" <input type="button" value="Abbrechen" onclick="history.back()"
class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700"> class="float-right mx-2 px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200">
Speichern
</button>
</div> </div>
<input type="hidden" name="article" id="article-upload-field"> <input type="hidden" name="article" id="article-upload-field">