55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?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];
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|