This commit is contained in:
Illia Hromovoi 2025-07-03 11:52:20 +02:00
commit fdb02b051c
11 changed files with 113 additions and 61 deletions

View File

@ -15,7 +15,7 @@ body {
.welcome-heading {
font-size: 50px;
font-weight: 500;
color: var(--brand-primary); /* Orange-Ton */
color: var(--brand-primary);
margin-bottom: 20px;
}

View File

@ -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,12 +65,13 @@ 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);
}
.form-user{
justify-content: center!important;
grid-template-columns: auto!important;

View File

@ -6,6 +6,7 @@
--brand-white: #ffffff;
--fullblock: darkblue;
--input-placeholder: #998E82;
--error: #FF0000;
/*Fonts*/

View File

@ -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 "<p>Erfolgreich erstellt!</p>";
}
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();
}

View File

@ -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();

View File

@ -152,7 +152,7 @@ class UserController{
}
public function isUserLoggenIn(){
return isset($_SESSION["user_id"]);
return isset($_SESSION["user_id"]) && $_SESSION["user_id"] != null;
}
public function getCurrentUserId(){

View File

@ -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);

View File

@ -0,0 +1,43 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<h2>Neuer Kurs</h2>
<form method="post" class="form-grid">
<?php
$index = 0;
foreach ($labels as $key => $value) {
$hasError = isset($errors[$key]);
$errorClass = $hasError ? ' error' : '';
echo '<div class="input">';
echo '<label for="' . $key . '">' . $value . '</label>';
if ($key == "beschreibung") {
echo '<textarea id="' . $key . '" name="' . $key . '" class="' . $errorClass . '">';
if (isset($validData[$key])) {
echo $validData[$key];
}
echo '</textarea>';
} else {
echo '<input class="' . $errorClass . '" type="text" name="' . $key . '" value="' . (isset($validData[$key]) ? $validData[$key] : '') . '">';
}
if ($hasError) {
echo '<p class="error">' . $errors[$key] . '</p>';
}
echo '</div>';
$index++;
}
?>
<input type="hidden" name="controller" value="admin">
<input type="hidden" name="do" value="validateForm">
<input type="submit" name="submit" value="Absenden"></form>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -0,0 +1,12 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<div class="msg">
<p>Kurs erfolgreich erstellt.</p>
<a href="?controller=Welcome&do=showWelcome">Weiter</a>
</div>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -1,35 +0,0 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<h2>Neuer Kurs</h2>
<form method="post" class="form-grid">
<?php
$index = 0;
foreach ($labels as $key => $value) {
echo '<div class="input"><label for="' . $key . '">' . $value . '</label>';
if ($key == "beschreibung") {
echo "<textarea id=\"$key\" name=\"$key\" >";
if (isset($validData[$key])) { echo $validData[$key]; }
echo "</textarea><br>";
} else {
echo '<input class="input" type="text" name="' . $key . '" value="' . (isset($validData[$key]) ? $validData[$key] : '') . '"><br>';
}
if (isset($errors[$key])) {
echo '<label class="errorMsg">' . $errors[$key] . '</label><br>';
}
echo '</div>';
$index++;
}
?>
<input type="hidden" name="controller" value="admin">
<input type="hidden" name="do" value="showForm">
<button type="submit" class="btn">Absenden</button>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -21,7 +21,7 @@
<div style="column-gap: 8px;" class="d-flex-between">
<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] !== null): ?>
<?php if($_SESSION['user_role'] == 'admin'): ?>
<a style="column-gap: 16px;" class="btn" href="?controller=Admin&do=showForm">
<a style="column-gap: 16px;" class="btn" href="?controller=Admin&do=showAdminForm">
<?php echo ($_SESSION['vorname'] ?? "") . " " . ($_SESSION['name'] ?? "") . ", " . ($_SESSION['user_role']) ?>
<span class="btn btn-user">
<span class="material-icons">person</span>