From 742c2b01602319efa7c888a4579eefccb9a3a85a Mon Sep 17 00:00:00 2001 From: pbbfa23abi Date: Thu, 3 Jul 2025 11:49:18 +0200 Subject: [PATCH] WIP --- CSS/Element/form.css | 20 +++++++++----- CSS/variables.css | 1 + Controller/AdminController.php | 16 +++++------ Controller/ContactController.php | 6 +---- Controller/UserController.php | 2 +- Model/AdminModel.php | 35 +++++++++++++++++++++--- Views/Admin/showAdminForm.phtml | 43 ++++++++++++++++++++++++++++++ Views/Admin/showConfirmation.phtml | 12 +++++++++ Views/Admin/showForm.phtml | 34 ----------------------- Views/header.phtml | 2 +- 10 files changed, 112 insertions(+), 59 deletions(-) create mode 100644 Views/Admin/showAdminForm.phtml create mode 100644 Views/Admin/showConfirmation.phtml delete mode 100644 Views/Admin/showForm.phtml diff --git a/CSS/Element/form.css b/CSS/Element/form.css index 3036e98..87bdb51 100644 --- a/CSS/Element/form.css +++ b/CSS/Element/form.css @@ -15,12 +15,19 @@ form label { } form input { - border: var(--border-primary); height: var(--h-md); padding-left: 8px; padding-right: 8px; } +form input, textarea { + border: var(--border-primary); + padding: 8px; + font-size: 1rem; + margin-top: 5px; + width: 100%; +} + .input { display: flex; flex-direction: column; @@ -58,9 +65,10 @@ form input { column-span: 2; } -input, textarea { - padding: 8px; - font-size: 1rem; - margin-top: 5px; +form .error { + color: var(--error); + border-color: var(--error); + margin-block-start: 4px; + margin-block-end: 0; + outline-color: var(--error); } - diff --git a/CSS/variables.css b/CSS/variables.css index e573f4a..080a92e 100644 --- a/CSS/variables.css +++ b/CSS/variables.css @@ -6,6 +6,7 @@ --brand-white: #ffffff; --fullblock: darkblue; --input-placeholder: #998E82; + --error: #FF0000; /*Fonts*/ diff --git a/Controller/AdminController.php b/Controller/AdminController.php index a8e81ae..9a85c10 100644 --- a/Controller/AdminController.php +++ b/Controller/AdminController.php @@ -10,7 +10,7 @@ class AdminController private $db; private $validData = array(); private $errors = array(); - private $labels = array("name" => "Name*", "preis" => "€ Preis*", "dauer" => "Dauer* (Stunden)", "rabatt" => "Rabatt", "kategorie" => "Kategorie", "beschreibung" => "Beschreibung"); + private $labels = array("name" => "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) @@ -19,7 +19,7 @@ class AdminController $this->view = $view; } - public function showForm() + public function showAdminForm() { $this->view->setVars([ 'labels' => $this->labels, @@ -30,22 +30,22 @@ class AdminController public function showConfirmation() { - echo "

Erfolgreich erstellt!

"; + } public function validateForm(){ foreach ($this->labels as $index => $value) { - if (!isset($_POST[$index]) || empty($_POST[$index])) { - $this->errors[$index] = "Bitte " . $value . " angeben"; + if (strpos($value, "*") !== false && (!isset($_POST[$index]) || empty($_POST[$index]))) { + $this->errors[$index] = "Bitte " . $value . " eingeben"; } else { $this->validData[$index] = $_POST[$index]; } } if (count($this->errors) > 0) { - $this->view->setDoMethodName("showForm"); - $this->showForm(); + $this->view->setDoMethodName("showAdminForm"); + $this->showAdminForm(); } else { - if ($this->db->writeContactData($this->validData)) { + if ($this->db->writeNewCourse($this->validData, $_SESSION["user_id"])) { $this->view->setDoMethodName("showConfirmation"); $this->showConfirmation(); } diff --git a/Controller/ContactController.php b/Controller/ContactController.php index 7a24662..1ba145c 100644 --- a/Controller/ContactController.php +++ b/Controller/ContactController.php @@ -28,10 +28,7 @@ class ContactController ]); } - public function showConfirmation() - { - - } + public function showConfirmation() {} public function validateForm(){ foreach ($this->labels as $index => $value) { @@ -41,7 +38,6 @@ class ContactController $this->validData[$index] = $_POST[$index]; } } - if (count($this->errors) > 0) { $this->view->setDoMethodName("showContactForm"); $this->showContactForm(); diff --git a/Controller/UserController.php b/Controller/UserController.php index 46512de..53b5982 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -77,7 +77,7 @@ class UserController{ } public function isUserLoggenIn(){ - return isset($_SESSION["user_id"]); + return isset($_SESSION["user_id"]) && $_SESSION["user_id"] != null; } public function getCurrentUserId(){ diff --git a/Model/AdminModel.php b/Model/AdminModel.php index 6177b99..63dc2da 100644 --- a/Model/AdminModel.php +++ b/Model/AdminModel.php @@ -6,12 +6,37 @@ use PDOException; class AdminModel extends Database { - public function writeNewCourse($values) - { + private function writeNewAddress($values) { $guid = $this->createUUID(); - $sql = "INSERT INTO kurs (`id`, `name`, `preis`, `dauer`, `rabatt`, `kategorie`, `beschreibung`) VALUES ( - :guid, :name, :preis, :dauer, :rabatt, :kategorie, :beschreibung);"; + $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(); @@ -24,6 +49,8 @@ class AdminModel extends Database ":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); diff --git a/Views/Admin/showAdminForm.phtml b/Views/Admin/showAdminForm.phtml new file mode 100644 index 0000000..9cf5c33 --- /dev/null +++ b/Views/Admin/showAdminForm.phtml @@ -0,0 +1,43 @@ + + + + +

Neuer Kurs

+
+ + $value) { + $hasError = isset($errors[$key]); + $errorClass = $hasError ? ' error' : ''; + + echo '
'; + echo ''; + + if ($key == "beschreibung") { + echo ''; + } else { + echo ''; + } + + if ($hasError) { + echo '

' . $errors[$key] . '

'; + } + + echo '
'; + $index++; +} +?> + + + +
+ + \ No newline at end of file diff --git a/Views/Admin/showConfirmation.phtml b/Views/Admin/showConfirmation.phtml new file mode 100644 index 0000000..35de568 --- /dev/null +++ b/Views/Admin/showConfirmation.phtml @@ -0,0 +1,12 @@ + + +
+

Kurs erfolgreich erstellt.

+Weiter +
+ + + + \ No newline at end of file diff --git a/Views/Admin/showForm.phtml b/Views/Admin/showForm.phtml deleted file mode 100644 index 2b7b1db..0000000 --- a/Views/Admin/showForm.phtml +++ /dev/null @@ -1,34 +0,0 @@ - - - - -

Neuer Kurs

-
- - $value) { - echo '
'; - if ($key == "beschreibung") { - echo "
"; - } else { - echo '
'; - } - if (isset($errors[$key])) { - echo '
'; - } - echo '
'; - $index++; -} -?> - - - -
- - \ No newline at end of file diff --git a/Views/header.phtml b/Views/header.phtml index 022093e..b8124d2 100644 --- a/Views/header.phtml +++ b/Views/header.phtml @@ -20,7 +20,7 @@