diff --git a/CSS/Element/button.css b/CSS/Element/button.css index 9f9edea..eed5813 100644 --- a/CSS/Element/button.css +++ b/CSS/Element/button.css @@ -56,3 +56,29 @@ .btn-logout{ background-color: red; } + +.btn-userchange{ + background-color: var(--brand-white); + color: var(--brand-background); +} + +/* Hovers */ +.btn-primary:hover { + background-color: var(--brand-primary-hover); +} + +.btn-secondary:hover { + background-color: var(--bg-muted-hover); +} + +.btn-accent:hover { + background-color: var(--fullblock-hover); +} + +.btn-danger:hover { + background-color: var(--error-hover); +} + +.btn-userchange:hover, .btn-logout:hover{ + opacity: 0.95; +} diff --git a/CSS/Element/form.css b/CSS/Element/form.css index 2ab719d..2064c7c 100644 --- a/CSS/Element/form.css +++ b/CSS/Element/form.css @@ -95,21 +95,16 @@ form .error { grid-template-columns: auto !important; } -/* fix radio buttons registration */ .radio { flex-direction: row; - justify-content: space-between; max-width: 290px; align-items: center; -} - -.radio { - display: flex; - flex-direction: row; - align-items: center; - gap: 10px; + gap: 24px; + } .radio input { margin-top: 0; + height: var(--h-sm); + width: var(--h-sm); } diff --git a/CSS/Element/sidebar.css b/CSS/Element/sidebar.css new file mode 100644 index 0000000..e20a2dc --- /dev/null +++ b/CSS/Element/sidebar.css @@ -0,0 +1,32 @@ +.sidebar { + width: 200px; + background-color: transparent; + height: 100%; +} + +.sidebar nav ul { + margin: 0; + padding: 0; +} + +.sidebar nav ul li { + margin-bottom: 0.5rem; + list-style: none; +} + +.sidebar nav ul li a { + text-decoration: none; + color: #333; + display: block; + padding: 0.5rem; + border-radius: 4px; +} + +.sidebar nav ul li a:hover { + background-color: #e2e6ea; +} + +.sidebar button{ + width: 100%; + padding: 10px 10px; +} diff --git a/CSS/style.css b/CSS/style.css index f630618..4a0d848 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -6,6 +6,7 @@ @import url(Element/form.css); @import url(Element/button.css); @import url(Element/card.css); +@import url(Element/sidebar.css); @import url(Element/filter_box.css); *, @@ -38,6 +39,10 @@ h2 { color: orange; } +*, button, a { + transition: background-color 0.2s, color 0.2s; +} + main { margin-top: 190px; } diff --git a/CSS/variables.css b/CSS/variables.css index 080a92e..0db4045 100644 --- a/CSS/variables.css +++ b/CSS/variables.css @@ -8,7 +8,6 @@ --input-placeholder: #998E82; --error: #FF0000; - /*Fonts*/ --font-family-main: "Inter", sans-serif; --font-family-headline: "Source Serif 4", serif; @@ -22,6 +21,14 @@ /*Font-Weight*/ --font-weight-semibold: 600; + --h-sm: 24px; --h-md: 48px; --border-primary: 1px solid #998E82; + + /* Hover Variants */ + --brand-primary-hover: #FF9E33; + --brand-background-hover: #2A231F; + --bg-muted-hover: #6A6A6A; + --fullblock-hover: #00008B; + --error-hover: #CC0000; } \ No newline at end of file diff --git a/Controller/AdminController.php b/Controller/AdminController.php deleted file mode 100644 index aeb17f4..0000000 --- a/Controller/AdminController.php +++ /dev/null @@ -1,66 +0,0 @@ - "Name*", - "preis" => "€ Preis*", - "dauer" => "Dauer* (Stunden)", - "rabatt" => "Rabatt", - "kategorie" => "Kategorie", - "|" => "", - "stadt" => "Stadt*", - "strasse" => "Straße und Nummer*", - "plz" => "PLZ*", - "|" => "", - "beschreibung" => "Beschreibung"); - - - public function __construct($view) - { - $this->db = new AdminModel(); - $this->view = $view; - } - - public function showAdminForm() - { - $this->view->setVars([ - 'labels' => $this->labels, - 'validData' => $this->validData, - 'errors' => $this->errors - ]); - } - - public function showConfirmation() - { - - } - - public function validateForm(){ - foreach ($this->labels as $index => $value) { - if (strpos($value, "*") !== false && (!isset($_POST[$index]) || empty($_POST[$index]))) { - $this->errors[$index] = "Bitte " . $value . " eingeben"; - } else { - $this->validData[$index] = $_POST[$index] === '' ? null : $_POST[$index]; - } - } - if (count($this->errors) > 0) { - $this->view->setDoMethodName("showAdminForm"); - $this->showAdminForm(); - } else { - if ($this->db->writeNewCourse($this->validData, $_SESSION["user_id"])) { - $this->view->setDoMethodName("showConfirmation"); - $this->showConfirmation(); - } - } - } -} -?> \ No newline at end of file diff --git a/Controller/UserController.php b/Controller/UserController.php index 92aaadd..aff9823 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -26,12 +26,27 @@ class UserController{ ]; private $changeUserLabels = [ - 'name' => 'Vorname*', - 'lastname' => 'Nachname*', + 'vorname' => 'Vorname*', + 'name' => 'Nachname*', 'email' => 'E-Mail*', 'password' => 'Passwort*', ]; + private $kursValidData = array(); + private $kursErrors = array(); + private $kursLabels = array( + "name" => "Name*", + "preis" => "€ Preis*", + "dauer" => "Dauer* (Stunden)", + "rabatt" => "Rabatt", + "kategorie" => "Kategorie", + "1" => "|", + "stadt" => "Stadt*", + "strasse" => "Straße und Nummer*", + "plz" => "PLZ*", + "2" => "|", + "beschreibung" => "Beschreibung"); + public function __construct($view){ $this->db = new UserModel(); $this->view = $view; @@ -99,6 +114,48 @@ class UserController{ } } + public function validateKursForm(){ + foreach ($this->kursLabels as $index => $value) { + if($value === "|") continue; + if (strpos($value, "*") !== false && (!isset($_POST[$index]) || empty($_POST[$index]))) { + $this->kursErrors[$index] = "Bitte " . $value . " eingeben"; + } else { + $this->kursValidData[$index] = $_POST[$index] === '' ? null : $_POST[$index]; + } + } + if (count($this->errors) > 0) { + $this->view->setDoMethodName("showUserAccountPage"); + $this->showUserAccountPage(); + } else { + if ($this->db->writeNewCourse($this->kursValidData, $_SESSION["user_id"])) { + $this->view->setDoMethodName("showNewKursConfirmation"); + $this->showConfirmation(); + } + } + } + + public function validateEditKursForm(){ + foreach ($this->kursLabels as $index => $value) { + if($value === "|") continue; + if (strpos($value, "*") !== false && (!isset($_POST[$index]) || empty($_POST[$index]))) { + $this->kursErrors[$index] = "Bitte " . $value . " eingeben"; + } else { + $this->kursValidData[$index] = $_POST[$index] === '' ? null : $_POST[$index]; + } + } + if (count($this->errors) > 0) { + $this->view->setDoMethodName("showUserAccountPage"); + $this->showUserAccountPage(); + } else { + if ($this->db->writeNewCourse($this->kursValidData, $_SESSION["user_id"])) { + $this->view->setDoMethodName("showKursEditedConfirmation"); + $this->showConfirmation(); + } + } + } + + public function showConfirmation(){} + public function showUserLoginConfirmation(){ $userId = $this->getCurrentUserId(); $user = null; @@ -172,7 +229,11 @@ class UserController{ } public function showUserAccountPage (){ - + $this->view->setVars([ + 'labels' => $this->kursLabels, + 'errors' => $this->kursErrors, + 'validData' => $this->kursValidData + ]); } public function showUserDeleteConfirmation(){ @@ -210,19 +271,19 @@ class UserController{ } $validData = [ + 'vorname' => $currentUser["vorname"], 'name' => $currentUser["name"], - 'vorname' => $currentUser["vorname"], 'email' => $currentUser["email"], ]; $this->view->setVars([ - 'labels' => $this->changeUserLabels, - 'validData' => $validData, - 'errors' => $this->errors, - 'message' => $this->message ?? null, + 'changeUserLabels' => $this->changeUserLabels, + 'validData' => $validData, + 'errors' => $this->errors, ]); - $this->view->render('User/showUserChangeAccountSettings'); + //$this->view->render('User/showUserChangeAccountSettings'); + return; } public function updateAccountData() @@ -239,18 +300,18 @@ class UserController{ } $submitted = [ + 'vorname' => trim($_POST['vorname'] ?? ''), 'name' => trim($_POST['name'] ?? ''), - 'lastname' => trim($_POST['lastname'] ?? ''), 'email' => trim($_POST['email'] ?? ''), 'password' => trim($_POST['password'] ?? ''), ]; $this->errors = []; - if (strlen($submitted['name']) < 2) { - $this->errors['name'] = 'Vorname muss mindestens 2 Zeichen haben.'; + if (strlen($submitted['vorname']) < 2) { + $this->errors['vorname'] = 'Vorname muss mindestens 2 Zeichen haben.'; } - if (strlen($submitted['lastname']) < 2) { - $this->errors['lastname'] = 'Nachname muss mindestens 2 Zeichen haben.'; + if (strlen($submitted['name']) < 2) { + $this->errors['name'] = 'Nachname muss mindestens 2 Zeichen haben.'; } if (!filter_var($submitted['email'], FILTER_VALIDATE_EMAIL)) { $this->errors['email'] = 'Ungültige E-Mail-Adresse.'; @@ -259,46 +320,72 @@ class UserController{ $this->errors['password'] = 'Passwort muss mindestens 6 Zeichen haben.'; } + if (count($this->errors) > 0) { $this->view->setVars([ - 'labels' => $this->changeUserLabels, - 'validData' => $submitted, - 'errors' => $this->errors, + 'changeUserLabels' => $this->changeUserLabels, + 'validData' => $submitted, + 'errors' => $this->errors, ]); - return $this->showUserChangeAccountSettings(); + $this->view->render('User/showUserChangeAccountSettings'); + return; } $updateData = []; - foreach (['name','lastname','email'] as $field) { - if ($submitted[$field] !== $currentUser[$field]) { - $updateData[$field] = $submitted[$field]; - } + if ($submitted['vorname'] !== $currentUser['vorname']) { + $updateData['vorname'] = $submitted['vorname']; + } + if ($submitted['name'] !== $currentUser['name']) { + $updateData['name'] = $submitted['name']; + } + if ($submitted['email'] !== $currentUser['email']) { + $updateData['email'] = $submitted['email']; } if ($submitted['password'] !== '') { - $salt = bin2hex(random_bytes(16)); - $hash = hash('sha256', $submitted['password'] . $salt); + // Passwort und Salt auf neu setzen + $salt = bin2hex(random_bytes(16)); + $hash = hash('sha256', $submitted['password'] . $salt); $updateData['passwort'] = $hash; $updateData['salt'] = $salt; } + + if ($submitted['password'] !== '') { + $salt = bin2hex(random_bytes(16)); + $hash = hash('sha256', $submitted['password'] . $salt); + $updateData['passwort'] = $hash; + $updateData['salt'] = $salt; + } + if (empty($updateData)) { $this->message = 'Keine Änderungen festgestellt.'; - return $this->showUserChangeAccountSettings(); + $this->view->render('User/showUserChangeAccountSettings'); + return; } $ok = $this->db->updateUserData($userId, $updateData); if ($ok) { - // Session‑Werte aktualisieren $_SESSION['vorname'] = $updateData['name'] ?? $_SESSION['vorname']; $_SESSION['name'] = $updateData['lastname'] ?? $_SESSION['name']; $_SESSION['email'] = $updateData['email'] ?? $_SESSION['email']; $this->message = 'Änderungen erfolgreich gespeichert.'; + + echo "ok"; + + header("Location: index.php?controller=user&do=showUserAccountPage"); + exit(); } else { $this->errors['general'] = 'Beim Speichern ist ein Fehler aufgetreten.'; + $this->view->setVars([ + 'changeUserLabels' => $this->changeUserLabels, + 'validData' => $submitted, + 'errors' => $this->errors, + ]); + $this->view->setDoMethodName('showUserChangeAccountSettings'); + return; } - return $this->showUserChangeAccountSettings(); } diff --git a/Model/AdminModel.php b/Model/AdminModel.php deleted file mode 100644 index 98b771d..0000000 --- a/Model/AdminModel.php +++ /dev/null @@ -1,81 +0,0 @@ -createUUID(); - - $sql = "INSERT INTO ort (`id`, `stadt`, `strasse`, `plz`) VALUES ( - :guid, :stadt, :strasse, :plz);"; - - $pdo = $this->linkDB(); - - try { - $sth = $pdo->prepare($sql); - $sth->execute(array(":guid" => $guid, - ":stadt" => $values["stadt"], - ":strasse" => $values["strasse"], - ":plz" => $values["plz"], - )); - return $guid; - } catch (PDOException $e) { - new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); - die; - } - } - - public function writeNewCourse($values, $kursleiterId) - { - // Bleibt übrig wenn Adresse erstellt wird aber Kurs nicht weil Error - $addressId = $this->writeNewAddress($values); - - $guid = $this->createUUID(); - - $sql = "INSERT INTO kurs (`id`, `name`, `preis`, `dauer`, `rabatt`, `kategorie`, `beschreibung`, `kurseleiter`, `ort_id`) VALUES ( - :guid, :name, :preis, :dauer, :rabatt, :kategorie, :beschreibung, :kurseleiter, :ort_id);"; - - $pdo = $this->linkDB(); - - try { - $sth = $pdo->prepare($sql); - $sth->execute(array(":guid" => $guid, - ":name" => $values["name"], - ":preis" => $values["preis"], - ":dauer" => $values["dauer"], - ":rabatt" => $values["rabatt"], - ":kategorie" => $values["kategorie"], - ":beschreibung" => $values["beschreibung"], - ":kurseleiter" => $kursleiterId, - "ort_id" => $addressId - )); - } catch (PDOException $e) { - new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); - die; - } - - return true; - } - - public function getMyCourses() { - $sql = "SELECT k.id, k.name, k.preis, k.dauer, k.rabatt, k.kategorie, k.beschreibung, o.stadt, o.strasse, o.plz, b.note, b.kommentar - FROM kurs AS k - JOIN ort AS o ON o.id = k.ort_id - LEFT JOIN bewertungen AS b ON b.kurs_id = k.id - ORDER BY k.name;"; - - $pdo = $this->linkDB(); - - try { - $sth = $pdo->prepare($sql); - $sth->execute(); - return $sth->fetchAll(\PDO::FETCH_ASSOC); - } catch (PDOException $e) { - new \Blog\Library\ErrorMsg("Fehler beim Lesen der Daten.", $e); - die; - } - } -} \ No newline at end of file diff --git a/Model/UserModel.php b/Model/UserModel.php index 8e940ad..a5ac67e 100644 --- a/Model/UserModel.php +++ b/Model/UserModel.php @@ -102,4 +102,163 @@ class UserModel extends Database } + private function writeNewAddress($values) { + $guid = $this->createUUID(); + + $sql = "INSERT INTO ort (`id`, `stadt`, `strasse`, `plz`) VALUES ( + :guid, :stadt, :strasse, :plz);"; + + $pdo = $this->linkDB(); + + try { + $sth = $pdo->prepare($sql); + $sth->execute(array(":guid" => $guid, + ":stadt" => $values["stadt"], + ":strasse" => $values["strasse"], + ":plz" => $values["plz"], + )); + return $guid; + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); + die; + } + } + + public function writeNewCourse($values, $kursleiterId) + { + // Bleibt übrig wenn Adresse erstellt wird aber Kurs nicht weil Error + $addressId = $this->writeNewAddress($values); + + $guid = $this->createUUID(); + + $sql = "INSERT INTO kurs (`id`, `name`, `preis`, `dauer`, `rabatt`, `kategorie`, `beschreibung`, `kurseleiter`, `ort_id`) VALUES ( + :guid, :name, :preis, :dauer, :rabatt, :kategorie, :beschreibung, :kurseleiter, :ort_id);"; + + $pdo = $this->linkDB(); + + try { + $sth = $pdo->prepare($sql); + $sth->execute(array(":guid" => $guid, + ":name" => $values["name"], + ":preis" => $values["preis"], + ":dauer" => $values["dauer"], + ":rabatt" => $values["rabatt"], + ":kategorie" => $values["kategorie"], + ":beschreibung" => $values["beschreibung"], + ":kurseleiter" => $kursleiterId, + "ort_id" => $addressId + )); + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); + die; + } + + return true; + } + + public function getMyCourses() { + $personId = $_SESSION["user_id"]; + $isKursleiter = $_SESSION["user_role"] === "leiter"; + + $pdo = $this->linkDB(); + + if ($isKursleiter) { + $sql = "SELECT k.id, k.name, k.preis, k.dauer, k.rabatt, k.kategorie, k.beschreibung, k.ort_id, + o.stadt, o.strasse, o.plz, b.note, b.kommentar + FROM kurs AS k + JOIN ort AS o ON o.id = k.ort_id + LEFT JOIN bewertungen AS b ON b.kurs_id = k.id + WHERE k.kursleiter = :personId + ORDER BY k.name"; + } else { + $sql = "SELECT k.id, k.name, k.preis, k.dauer, k.rabatt, k.kategorie, k.beschreibung, k.ort_id, + o.stadt, o.strasse, o.plz, b.note, b.kommentar + FROM kurs_user AS ku + JOIN kurs AS k ON k.id = ku.kurs_id + JOIN ort AS o ON o.id = k.ort_id + LEFT JOIN bewertungen AS b ON b.kurs_id = k.id + WHERE ku.user_id = :personId + ORDER BY k.name"; + } + + try { + $sth = $pdo->prepare($sql); + $sth->execute([':personId' => $personId]); + return $sth->fetchAll(\PDO::FETCH_ASSOC); + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Lesen der Daten.", $e); + die; + } + } + + + public function updateCourse($course) { + $pdo = $this->linkDB(); + + try { + if (isset($course['ort_id'])) { + $this->updateAddress($course); + $addressId = $course['ort_id']; + } else { + $addressId = $this->writeNewAddress($course); + } + + $sql = "UPDATE kurs SET + `name` = :name, + `preis` = :preis, + `dauer` = :dauer, + `rabatt` = :rabatt, + `kategorie` = :kategorie, + `beschreibung` = :beschreibung, + `ort_id` = :ort_id + WHERE `id` = :id"; + + $sth = $pdo->prepare($sql); + $sth->execute([ + ':id' => $course['id'], + ':name' => $course['name'], + ':preis' => $course['preis'], + ':dauer' => $course['dauer'], + ':rabatt' => $course['rabatt'], + ':kategorie' => $course['kategorie'], + ':beschreibung' => $course['beschreibung'], + ':ort_id' => $addressId + ]); + + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Aktualisieren des Kurses.", $e); + die; + } + + return true; + } + + public function updateAddress($data) { + $pdo = $this->linkDB(); + + if (!isset($data['ort_id'])) { + throw new \Exception("Keine Adress-ID vorhanden zum Aktualisieren."); + } + + $sql = "UPDATE ort SET + `strasse` = :strasse, + `stadt` = :stadt, + `plz` = :plz + WHERE `id` = :id"; + + try { + $sth = $pdo->prepare($sql); + $sth->execute([ + ':id' => $data['ort_id'], + ':strasse' => $data['strasse'], + ':stadt' => $data['stadt'], + ':plz' => $data['plz'] + ]); + } catch (PDOException $e) { + new \Blog\Library\ErrorMsg("Fehler beim Aktualisieren der Adresse.", $e); + die; + } + + return true; + } } \ No newline at end of file diff --git a/Views/Admin/showAdminForm.phtml b/Views/User/showAdminForm.phtml similarity index 73% rename from Views/Admin/showAdminForm.phtml rename to Views/User/showAdminForm.phtml index 138f254..0e5cff4 100644 --- a/Views/Admin/showAdminForm.phtml +++ b/Views/User/showAdminForm.phtml @@ -1,10 +1,21 @@ - -
Keine Kurse gefunden.
'; } ?> - - \ No newline at end of file diff --git a/Views/User/showKursEditedConfirmation.phtml b/Views/User/showKursEditedConfirmation.phtml new file mode 100644 index 0000000..effcbd2 --- /dev/null +++ b/Views/User/showKursEditedConfirmation.phtml @@ -0,0 +1,12 @@ + + +Kurs erfolgreich bearbeitet.
+Weiter +