Merge branch 'main' of https://git.bib.de/PBBFA23AHR/kurs-app
This commit is contained in:
commit
cee9220f6a
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
32
CSS/Element/sidebar.css
Normal file
32
CSS/Element/sidebar.css
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Blog\Controller;
|
||||
|
||||
use Blog\Model\AdminModel;
|
||||
|
||||
class AdminController
|
||||
{
|
||||
protected $view;
|
||||
private $db;
|
||||
private $validData = array();
|
||||
private $errors = array();
|
||||
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)
|
||||
{
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Blog\Model;
|
||||
|
||||
use PDOException;
|
||||
|
||||
class AdminModel 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() {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,10 +1,21 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<h2>Neuer Kurs</h2>
|
||||
<form method="post">
|
||||
<?php
|
||||
$userModel = new \Blog\Model\UserModel();
|
||||
$courses = $userModel->getMyCourses();
|
||||
$id = $_GET["id"] ?? null;
|
||||
|
||||
$selectedCourse = null;
|
||||
foreach ($courses as $course) {
|
||||
if ($course['id'] === $id) {
|
||||
$selectedCourse = $course;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$validData = $selectedCourse ?? null;
|
||||
$isEditing = $validData != null;
|
||||
$saveLabel = $isEditing ? "Speichern" : "Erstellen";
|
||||
|
||||
function createInputField($label, $name, $errors, $validData, $type = 'input') {
|
||||
$errorClass = isset($errors[$name]) ? 'error' : '';
|
||||
$value = htmlspecialchars($validData[$name] ?? '');
|
||||
@ -30,25 +41,28 @@ function createInputField($label, $name, $errors, $validData, $type = 'input') {
|
||||
}
|
||||
echo '<div style="margin-top: 32px;" class="form-grid-3">';
|
||||
foreach ($labels as $name => $label) {
|
||||
if($name === "|") {
|
||||
if($label === "|") {
|
||||
echo '</div>';
|
||||
echo '<div style="margin-top: 32px;" class="form-grid-3">';
|
||||
} else {
|
||||
echo createInputField($label, $name, $errors, $validData, $type = $name === 'beschreibung' ? 'textarea' : 'input');
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
?>
|
||||
<input type="hidden" name="controller" value="admin">
|
||||
<input type="hidden" name="do" value="validateForm">
|
||||
<div class="form-grid-3" style="margin-top: 16px;">
|
||||
<input style="grid-column: 3;" type="submit" name="submit" value="Absenden">
|
||||
</div>
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<?php
|
||||
$action = $isEditing ? 'validateEditKursForm' : 'validateKursForm';
|
||||
echo <<<HTML
|
||||
<input type="hidden" name="do" value="{$action}">
|
||||
<div class="form-grid-3" style="margin-top: 16px;">
|
||||
<input style="grid-column: 3;" type="submit" name="submit" value="{$saveLabel}">
|
||||
</div>
|
||||
HTML;
|
||||
?>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
$adminModel = new \Blog\Model\AdminModel();
|
||||
$courses = $adminModel->getMyCourses();
|
||||
$doc = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
if (!empty($courses)) {
|
||||
@ -56,7 +70,7 @@ if (!empty($courses)) {
|
||||
foreach ($courses as $kurs) {
|
||||
$courseCard = $doc->createElement('div');
|
||||
$courseCard->setAttribute('class', 'course-card');
|
||||
|
||||
|
||||
$courseImage = $doc->createElement('div');
|
||||
$courseImage->setAttribute('class', 'course-image');
|
||||
$courseCard->appendChild($courseImage);
|
||||
@ -88,6 +102,11 @@ if (!empty($courses)) {
|
||||
$category = $doc->createElement('div', htmlspecialchars($kurs['kategorie'] ?? 'Keine Kategorie'));
|
||||
$courseRight->appendChild($category);
|
||||
|
||||
$editLink = $doc->createElement('a', "Bearbeiten");
|
||||
$editLink->setAttribute('href', '?controller=User&do=showUserAccountPage&id=' . $kurs['id']);
|
||||
$editLink->setAttribute('class', 'course-card-link');
|
||||
$courseRight->appendChild($editLink);
|
||||
|
||||
echo $doc->saveHTML($courseCard);
|
||||
}
|
||||
echo '</div>';
|
||||
@ -95,5 +114,3 @@ if (!empty($courses)) {
|
||||
echo '<p>Keine Kurse gefunden.</p>';
|
||||
}
|
||||
?>
|
||||
|
||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
12
Views/User/showKursEditedConfirmation.phtml
Normal file
12
Views/User/showKursEditedConfirmation.phtml
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<div class="msg">
|
||||
<p>Kurs erfolgreich bearbeitet.</p>
|
||||
<a href="?controller=User&do=showUserAccountPage">Weiter</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
@ -4,7 +4,7 @@ include dirname(__DIR__).'/header.phtml';
|
||||
|
||||
<div class="msg">
|
||||
<p>Kurs erfolgreich erstellt.</p>
|
||||
<a href="?controller=Welcome&do=showWelcome">Weiter</a>
|
||||
<a href="?controller=User&do=showUserAccountPage">Weiter</a>
|
||||
</div>
|
||||
|
||||
|
@ -6,29 +6,51 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1>Hallo,
|
||||
<?php echo ($_SESSION['vorname'] ?? "") . " " . ($_SESSION['name'] ?? "") ?>
|
||||
</br>
|
||||
Hier können Sie ihren Account verwalten.
|
||||
</h1>
|
||||
<div class="row">
|
||||
<form method="post">
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="logout">
|
||||
<button type="submit" class="btn btn-logout">Ausloggen</button>
|
||||
</form>
|
||||
<form method="post">
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="deleteAccount">
|
||||
<button type="submit" class="btn btn-logout">Meinen Account löschen</button>
|
||||
</form>
|
||||
<form method="post">
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="changeAccountDataRedirect">
|
||||
<button type="submit" class="btn btn-logout">Meine Kontodaten ändern</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<h1>Hallo,
|
||||
<?php echo ($_SESSION['vorname'] ?? "") . " " . ($_SESSION['name'] ?? "") ?>
|
||||
</br>
|
||||
Hier können Sie ihren Account verwalten.
|
||||
</h1>
|
||||
</div>
|
||||
<div class="col-4 sidebar">
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<form method="post">
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="logout">
|
||||
<button type="submit" class="btn btn-primary">Ausloggen</button>
|
||||
</form>
|
||||
</li>
|
||||
<li>
|
||||
<form method="post">
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="changeAccountDataRedirect">
|
||||
<button type="submit" class="btn btn-userchange">Meine Kontodaten ändern</button>
|
||||
</form>
|
||||
</li>
|
||||
<li>
|
||||
<form method="post">
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="deleteAccount">
|
||||
<button type="submit" class="btn btn-logout">Meinen Account löschen</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if(isset($_SESSION["user_id"]) && $_SESSION["user_id"] != null && $_SESSION["user_role"] == "leiter") {
|
||||
include dirname(__DIR__).'/User/showAdminForm.phtml';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</article>
|
||||
</article>
|
||||
|
||||
|
||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
@ -14,9 +14,9 @@ include dirname(__DIR__).'/header.phtml';
|
||||
<?php if ($key === 'password'): ?>
|
||||
<input type="password" name="<?= $key ?>" id="reg_<?= $key ?>">
|
||||
<?php elseif($key === 'email'): ?>
|
||||
<input type="email" name="<?= $key ?>" id="reg_<?= $key ?>">
|
||||
<input type="email" name="<?= $key ?>" id="reg_<?= $key ?>" value="<?= htmlspecialchars($validData[$key] ?? '') ?>">
|
||||
<?php else: ?>
|
||||
<input type="text" name="<?= $key ?>" id="reg_<?= $key ?>" value="<?= htmlspecialchars($validData[$key] ?? '') ?>">
|
||||
<input type="text" name="<?= $key ?>" id="reg_<?= $key ?>" value="<?= htmlspecialchars($validData[$key] ?? $_SESSION['vorname']) ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($errors[$key])): ?>
|
||||
|
@ -6,11 +6,9 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1>Registration</h1>
|
||||
|
||||
<form method="post" class="form-grid">
|
||||
|
||||
<?php foreach ($labels as $key => $label): ?>
|
||||
<div class="input">
|
||||
<div class="input <?= $key === 'role' ? "radio" : "" ?>">
|
||||
<label for="reg_<?= $key ?>"><?= $label ?></label>
|
||||
<?php if ($key === 'password'): ?>
|
||||
<input type="password" name="<?= $key ?>" id="reg_<?= $key ?>" required>
|
||||
|
@ -20,21 +20,12 @@
|
||||
<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($_SESSION['user_role'] == 'leiter'): ?>
|
||||
<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>
|
||||
</span>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a style="column-gap: 16px;" class="btn" href="?controller=User&do=showUserAccountPage">
|
||||
<?php echo ($_SESSION['vorname'] ?? "") . " " . ($_SESSION['name'] ?? "") . ", " . ($_SESSION['user_role']) ?>
|
||||
<span class="btn btn-user">
|
||||
<span class="material-icons">person</span>
|
||||
</span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<a class="btn" href="?controller=User&do=showUserLoginForm">Anmeldung</a>
|
||||
<a class="btn btn-primary" href="?controller=User&do=showUserRegisterForm">Registration</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user