Funktionalität Facheditor
This commit is contained in:
@@ -127,7 +127,14 @@ class TopicData
|
|||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
|
if(!is_dir(Config::getTopicsDirectory($subjectId))) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
$topicNames = scandir(Config::getTopicsDirectory($subjectId));
|
$topicNames = scandir(Config::getTopicsDirectory($subjectId));
|
||||||
|
if(!$topicNames) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
usort($topicNames, function ($a, $b) {
|
usort($topicNames, function ($a, $b) {
|
||||||
return strcmp($a, $b);
|
return strcmp($a, $b);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"displayName": "Mathe",
|
"displayName": "Mathe",
|
||||||
"description": "Mathe ist blau",
|
"description": "Mathe ist rot",
|
||||||
"color": "#3b82f6",
|
"color": "#626cd0",
|
||||||
"icon": "fa-square-root-alt"
|
"icon": "fa-square-root-alt"
|
||||||
}
|
}
|
||||||
6
webseite/config/subjects/physik/properties.json
Normal file
6
webseite/config/subjects/physik/properties.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"displayName": "Physik",
|
||||||
|
"description": "Noch ein Fach",
|
||||||
|
"color": "#363cfc",
|
||||||
|
"icon": "fa-square-root-alt"
|
||||||
|
}
|
||||||
@@ -6,8 +6,70 @@ require_once("classes/TopicData.php");
|
|||||||
$allSubjects = SubjectData::getAll();
|
$allSubjects = SubjectData::getAll();
|
||||||
$editingSubject = null;
|
$editingSubject = null;
|
||||||
|
|
||||||
|
$defaultValues = array();
|
||||||
|
$defaultValues['displayName'] = "";
|
||||||
|
$defaultValues['id'] = "";
|
||||||
|
$defaultValues['description'] = "";
|
||||||
|
$defaultValues['color'] = "#3b82f6";
|
||||||
|
$defaultValues['icon'] = "";
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
if (isset($_GET['subjectId'])) {
|
if (isset($_GET['subjectId'])) {
|
||||||
$editingSubject = $allSubjects[$_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'])) {
|
|||||||
|
|
||||||
<body class="min-h-screen bg-gray-50">
|
<body class="min-h-screen bg-gray-50">
|
||||||
|
|
||||||
<form id="subjectForm" onsubmit="handleSubjectSubmit(event)">
|
<form id="subjectForm" method="post" onsubmit="handleSubjectSubmit(event)">
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">Name des Fachs</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">Name des Fachs</label>
|
||||||
@@ -38,11 +100,17 @@ if (isset($_GET['subjectId'])) {
|
|||||||
required
|
required
|
||||||
class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400"
|
class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400"
|
||||||
placeholder="z.B. Mathematik"
|
placeholder="z.B. Mathematik"
|
||||||
value="<?php
|
value="<?php echo $defaultValues['displayName']?>">
|
||||||
if (isset($editingSubject)) {
|
</div>
|
||||||
echo $editingSubject->getDisplayName();
|
|
||||||
}
|
<div>
|
||||||
?>">
|
<label class="block text-sm font-medium text-gray-700 mb-2">ID des Fachs</label>
|
||||||
|
<input type="text"
|
||||||
|
name="id"
|
||||||
|
required
|
||||||
|
class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400"
|
||||||
|
placeholder="z.B. mathe"
|
||||||
|
value="<?php echo $defaultValues['id']?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -51,26 +119,23 @@ if (isset($_GET['subjectId'])) {
|
|||||||
required
|
required
|
||||||
class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400"
|
class="w-full px-4 py-3 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-lg enabled:hover:border-gray-400"
|
||||||
rows="4"
|
rows="4"
|
||||||
placeholder="Kurze Beschreibung des Fachs"><?php
|
placeholder="Kurze Beschreibung des Fachs"><?php echo $defaultValues['description']?></textarea>
|
||||||
if (isset($editingSubject)) {
|
|
||||||
echo $editingSubject->getDescription();
|
|
||||||
}
|
|
||||||
?></textarea>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">Farbe</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">Farbe</label>
|
||||||
<input type="color" name="color" required
|
<input type="color" name="color" required
|
||||||
class="w-full h-14 px-1 py-1 rounded-lg"
|
class="w-full h-14 px-1 py-1 rounded-lg"
|
||||||
value="<?php
|
value="<?php echo $defaultValues['color']?>">
|
||||||
if (isset($editingSubject)) {
|
|
||||||
echo $editingSubject->getColor();
|
|
||||||
} else {
|
|
||||||
echo "#3b82f6";
|
|
||||||
}
|
|
||||||
?>">
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="iconSelect" class="block text-sm font-medium text-gray-700">Icon</label>
|
||||||
|
<input class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm" type="text" name="icon"
|
||||||
|
id="iconSelect" value="<?php echo $defaultValues['icon']?>">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">Icon auswählen</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">Icon auswählen</label>
|
||||||
<div class="grid grid-cols-6 gap-4 p-4 border rounded-lg bg-gray-50">
|
<div class="grid grid-cols-6 gap-4 p-4 border rounded-lg bg-gray-50">
|
||||||
@@ -95,6 +160,10 @@ if (isset($_GET['subjectId'])) {
|
|||||||
'fa-tablets',
|
'fa-tablets',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if(isset($editingSubject)) {
|
||||||
|
$icons[] = $editingSubject->getIcon();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($icons as $icon) {
|
foreach ($icons as $icon) {
|
||||||
echo "<div class='icon-option cursor-pointer p-4 rounded-lg hover:bg-white hover:shadow transition-all text-center'
|
echo "<div class='icon-option cursor-pointer p-4 rounded-lg hover:bg-white hover:shadow transition-all text-center'
|
||||||
onclick='selectIcon(this, \"$icon\")' data-icon='$icon'>
|
onclick='selectIcon(this, \"$icon\")' data-icon='$icon'>
|
||||||
@@ -105,8 +174,17 @@ if (isset($_GET['subjectId'])) {
|
|||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="icon" id="selectedIcon">
|
<input type="hidden" name="icon" id="selectedIcon">
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
echo "<p class='text-red-800'>$error</p>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="mt-8 flex justify-end gap-3">
|
<div class="mt-8 flex justify-end gap-3">
|
||||||
<button type="button" onclick="closeModal()"
|
<button type="button" onclick="closeModal()"
|
||||||
class="px-6 py-3 text-gray-600 hover:text-gray-800 text-lg">
|
class="px-6 py-3 text-gray-600 hover:text-gray-800 text-lg">
|
||||||
@@ -114,7 +192,7 @@ if (isset($_GET['subjectId'])) {
|
|||||||
</button>
|
</button>
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
class="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-lg">
|
class="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-lg">
|
||||||
Fach erstellen
|
Speichern
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user