This commit is contained in:
2025-07-09 11:12:35 +02:00
8 changed files with 129 additions and 170 deletions

View File

@@ -32,6 +32,21 @@ class UserController{
'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,28 @@ 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 showConfirmation(){}
public function showUserLoginConfirmation(){
$userId = $this->getCurrentUserId();
$user = null;
@@ -172,7 +209,11 @@ class UserController{
}
public function showUserAccountPage (){
$this->view->setVars([
'labels' => $this->kursLabels,
'errors' => $this->kursErrors,
'validData' => $this->kursValidData
]);
}
public function showUserDeleteConfirmation(){