WIP
This commit is contained in:
parent
4e88e4c571
commit
742c2b0160
@ -15,12 +15,19 @@ form label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
form input {
|
form input {
|
||||||
border: var(--border-primary);
|
|
||||||
height: var(--h-md);
|
height: var(--h-md);
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
padding-right: 8px;
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form input, textarea {
|
||||||
|
border: var(--border-primary);
|
||||||
|
padding: 8px;
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-top: 5px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@ -58,9 +65,10 @@ form input {
|
|||||||
column-span: 2;
|
column-span: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
input, textarea {
|
form .error {
|
||||||
padding: 8px;
|
color: var(--error);
|
||||||
font-size: 1rem;
|
border-color: var(--error);
|
||||||
margin-top: 5px;
|
margin-block-start: 4px;
|
||||||
|
margin-block-end: 0;
|
||||||
|
outline-color: var(--error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
--brand-white: #ffffff;
|
--brand-white: #ffffff;
|
||||||
--fullblock: darkblue;
|
--fullblock: darkblue;
|
||||||
--input-placeholder: #998E82;
|
--input-placeholder: #998E82;
|
||||||
|
--error: #FF0000;
|
||||||
|
|
||||||
|
|
||||||
/*Fonts*/
|
/*Fonts*/
|
||||||
|
@ -10,7 +10,7 @@ class AdminController
|
|||||||
private $db;
|
private $db;
|
||||||
private $validData = array();
|
private $validData = array();
|
||||||
private $errors = 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)
|
public function __construct($view)
|
||||||
@ -19,7 +19,7 @@ class AdminController
|
|||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showForm()
|
public function showAdminForm()
|
||||||
{
|
{
|
||||||
$this->view->setVars([
|
$this->view->setVars([
|
||||||
'labels' => $this->labels,
|
'labels' => $this->labels,
|
||||||
@ -30,22 +30,22 @@ class AdminController
|
|||||||
|
|
||||||
public function showConfirmation()
|
public function showConfirmation()
|
||||||
{
|
{
|
||||||
echo "<p>Erfolgreich erstellt!</p>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateForm(){
|
public function validateForm(){
|
||||||
foreach ($this->labels as $index => $value) {
|
foreach ($this->labels as $index => $value) {
|
||||||
if (!isset($_POST[$index]) || empty($_POST[$index])) {
|
if (strpos($value, "*") !== false && (!isset($_POST[$index]) || empty($_POST[$index]))) {
|
||||||
$this->errors[$index] = "Bitte " . $value . " angeben";
|
$this->errors[$index] = "Bitte " . $value . " eingeben";
|
||||||
} else {
|
} else {
|
||||||
$this->validData[$index] = $_POST[$index];
|
$this->validData[$index] = $_POST[$index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count($this->errors) > 0) {
|
if (count($this->errors) > 0) {
|
||||||
$this->view->setDoMethodName("showForm");
|
$this->view->setDoMethodName("showAdminForm");
|
||||||
$this->showForm();
|
$this->showAdminForm();
|
||||||
} else {
|
} else {
|
||||||
if ($this->db->writeContactData($this->validData)) {
|
if ($this->db->writeNewCourse($this->validData, $_SESSION["user_id"])) {
|
||||||
$this->view->setDoMethodName("showConfirmation");
|
$this->view->setDoMethodName("showConfirmation");
|
||||||
$this->showConfirmation();
|
$this->showConfirmation();
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,7 @@ class ContactController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showConfirmation()
|
public function showConfirmation() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validateForm(){
|
public function validateForm(){
|
||||||
foreach ($this->labels as $index => $value) {
|
foreach ($this->labels as $index => $value) {
|
||||||
@ -41,7 +38,6 @@ class ContactController
|
|||||||
$this->validData[$index] = $_POST[$index];
|
$this->validData[$index] = $_POST[$index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->errors) > 0) {
|
if (count($this->errors) > 0) {
|
||||||
$this->view->setDoMethodName("showContactForm");
|
$this->view->setDoMethodName("showContactForm");
|
||||||
$this->showContactForm();
|
$this->showContactForm();
|
||||||
|
@ -77,7 +77,7 @@ class UserController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isUserLoggenIn(){
|
public function isUserLoggenIn(){
|
||||||
return isset($_SESSION["user_id"]);
|
return isset($_SESSION["user_id"]) && $_SESSION["user_id"] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCurrentUserId(){
|
public function getCurrentUserId(){
|
||||||
|
@ -6,12 +6,37 @@ use PDOException;
|
|||||||
|
|
||||||
class AdminModel extends Database
|
class AdminModel extends Database
|
||||||
{
|
{
|
||||||
public function writeNewCourse($values)
|
private function writeNewAddress($values) {
|
||||||
{
|
|
||||||
$guid = $this->createUUID();
|
$guid = $this->createUUID();
|
||||||
|
|
||||||
$sql = "INSERT INTO kurs (`id`, `name`, `preis`, `dauer`, `rabatt`, `kategorie`, `beschreibung`) VALUES (
|
$sql = "INSERT INTO ort (`id`, `stadt`, `strasse`, `plz`) VALUES (
|
||||||
:guid, :name, :preis, :dauer, :rabatt, :kategorie, :beschreibung);";
|
: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();
|
$pdo = $this->linkDB();
|
||||||
|
|
||||||
@ -24,6 +49,8 @@ class AdminModel extends Database
|
|||||||
":rabatt" => $values["rabatt"],
|
":rabatt" => $values["rabatt"],
|
||||||
":kategorie" => $values["kategorie"],
|
":kategorie" => $values["kategorie"],
|
||||||
":beschreibung" => $values["beschreibung"],
|
":beschreibung" => $values["beschreibung"],
|
||||||
|
":kurseleiter" => $kursleiterId,
|
||||||
|
"ort_id" => $addressId
|
||||||
));
|
));
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e);
|
new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e);
|
||||||
|
43
Views/Admin/showAdminForm.phtml
Normal file
43
Views/Admin/showAdminForm.phtml
Normal 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'; ?>
|
12
Views/Admin/showConfirmation.phtml
Normal file
12
Views/Admin/showConfirmation.phtml
Normal 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'; ?>
|
@ -1,34 +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">
|
|
||||||
<input type="submit" name="submit" value="Absenden"></form>
|
|
||||||
|
|
||||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
|
@ -20,7 +20,7 @@
|
|||||||
<div style="column-gap: 8px;" class="d-flex-between">
|
<div style="column-gap: 8px;" class="d-flex-between">
|
||||||
<div style="column-gap: 8px;" class="d-flex-between">
|
<div style="column-gap: 8px;" class="d-flex-between">
|
||||||
<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] !== null): ?>
|
<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] !== null): ?>
|
||||||
<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'] ?? "") ?>
|
<?php echo ($_SESSION['vorname'] ?? "") . " " . ($_SESSION['name'] ?? "") ?>
|
||||||
<span class="btn btn-user">
|
<span class="btn btn-user">
|
||||||
<span class="material-icons">person</span>
|
<span class="material-icons">person</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user