Files
thetool/application/ConstructionConsentJournal/ConstructionConsentJournalController.php
2025-02-05 09:35:34 +01:00

56 lines
1.7 KiB
PHP

<?php
class ConstructionConsentJournalController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if (!($me->is(["Admin","netowner","salespartner"]) && in_array($me->address_id, [1,209,5908]))) $this->redirect("Dashboard");
}
protected function saveAction() {
$r = $this->request;
//var_dump($r);exit;
$consent_id = $r->consent_id;
if(!is_numeric($consent_id) || $consent_id < 1) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden!", "error");
$this->redirect("ConstructionConsent");
}
$consent = new ConstructionConsent($consent_id);
if(!$consent->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden!", "error");
$this->redirect("ConstructionConsent");
}
$text = trim(htmlentities($r->text));
if(!$text) {
$this->layout()->setFlash("Bitte Text eingeben", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
}
$journal = ConstructionConsentJournal::create([
"constructionconsent_id" => $consent->id,
"text" => $text
]);
if(!$journal->save()) {
$this->layout()->setFlash("Fehler beim speichern!", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
}
$this->layout()->setFlash("Journaleintrag gespeichert", "success");
$this->redirect("ConstructionConsent", "View", ["id" => $consent->id]);
}
}