236 lines
8.4 KiB
PHP
236 lines
8.4 KiB
PHP
<?php
|
|
require_once("classes/User.php");
|
|
require_once("classes/SubjectData.php");
|
|
require_once("classes/TopicData.php");
|
|
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user']) || !$_SESSION['user']->isLoggedIn()) {
|
|
header("Location: index.php");
|
|
die();
|
|
}
|
|
|
|
$allSubjects = SubjectData::getAll();
|
|
$editingSubject = null;
|
|
|
|
$defaultValues = array();
|
|
$defaultValues['displayName'] = "";
|
|
$defaultValues['id'] = "";
|
|
$defaultValues['description'] = "";
|
|
$defaultValues['color'] = "#3b82f6";
|
|
$defaultValues['icon'] = "";
|
|
|
|
$errors = array();
|
|
|
|
if (isset($_GET['subject'])) {
|
|
$editingSubject = $allSubjects[$_GET['subject']];
|
|
|
|
$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(!isset($_POST['submit']) || !($_POST['submit'] == "Speichern" || $_POST['submit'] == "Fach löschen")) {
|
|
$errors["submit"] = "Ungültig abgeschickt!";
|
|
}
|
|
|
|
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 {
|
|
if($_POST['submit'] == "Fach löschen") {
|
|
$newSubject->delete();
|
|
header("Location: " . "index.php");
|
|
} else {
|
|
$newSubject->save();
|
|
header("Location: " . "subject.php?subject=" . $newSubject->getId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Lehrer Dashboard</title>
|
|
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
|
<link href="assets/css/styles.css" rel="stylesheet">
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
</head>
|
|
|
|
<body class="min-h-screen bg-gray-50">
|
|
|
|
<form id="subjectForm" method="post" onsubmit="handleSubjectSubmit(event)">
|
|
<div class="space-y-6">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Name des Fachs</label>
|
|
<input type="text"
|
|
name="displayName"
|
|
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. Mathematik"
|
|
value="<?php echo $defaultValues['displayName']?>">
|
|
</div>
|
|
|
|
<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>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Beschreibung</label>
|
|
<textarea name="description"
|
|
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"
|
|
rows="4"
|
|
placeholder="Kurze Beschreibung des Fachs"><?php echo $defaultValues['description']?></textarea>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Farbe</label>
|
|
<input type="color" name="color" required
|
|
class="w-full h-14 px-1 py-1 rounded-lg"
|
|
value="<?php echo $defaultValues['color']?>">
|
|
</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>
|
|
<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">
|
|
<?php
|
|
$icons = [
|
|
'fa-book',
|
|
'fa-square-root-alt',
|
|
'fa-flask',
|
|
'fa-language',
|
|
'fa-music',
|
|
'fa-palette',
|
|
'fa-dumbbell',
|
|
'fa-globe',
|
|
'fa-clock',
|
|
'fa-microscope',
|
|
'fa-atom',
|
|
'fa-vial',
|
|
'fa-calculator',
|
|
'fa-pen',
|
|
'fa-theater-masks',
|
|
'fa-draw-polygon',
|
|
'fa-tablets',
|
|
];
|
|
|
|
if(isset($editingSubject)) {
|
|
$icons[] = $editingSubject->getIcon();
|
|
}
|
|
|
|
foreach ($icons as $icon) {
|
|
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'>
|
|
<i class='fas $icon text-2xl mb-2'></i>
|
|
</div>";
|
|
}
|
|
?>
|
|
</div>
|
|
<input type="hidden" name="icon" id="selectedIcon">
|
|
</div>
|
|
-->
|
|
|
|
<?php
|
|
foreach ($errors as $error) {
|
|
echo "<p class='text-red-800'>$error</p>";
|
|
}
|
|
?>
|
|
|
|
</div>
|
|
|
|
<div class="flow-root mt-8 gap-4">
|
|
<input type="submit" value="Fach löschen" name="submit"
|
|
class="float-left px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-gray-200">
|
|
<input type="submit" value="Speichern" name="submit"
|
|
class="float-right px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
|
|
<input type="button" value="Abbrechen" onclick="history.back()"
|
|
class="float-right mx-2 px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200">
|
|
</div>
|
|
</form>
|
|
|
|
<script>
|
|
function selectIcon(element, iconName) {
|
|
// Remove active class from all icons
|
|
document.querySelectorAll('.icon-option').forEach(el => {
|
|
el.classList.remove('bg-blue-50', 'ring-2', 'ring-blue-500');
|
|
});
|
|
|
|
// Add active class to selected icon
|
|
element.classList.add('bg-blue-50', 'ring-2', 'ring-blue-500');
|
|
|
|
// Set the hidden input value and log it
|
|
const iconInput = document.getElementById('selectedIcon');
|
|
iconInput.value = iconName;
|
|
|
|
// Visual feedback
|
|
element.classList.add('scale-105');
|
|
setTimeout(() => {
|
|
element.classList.remove('scale-105');
|
|
}, 200);
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|