72 lines
2.5 KiB
PHP
72 lines
2.5 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 ($this->me->is("Admin")) $this->constructionConsentProjects = array_column(ConstructionConsentProject::getAll(), 'id');
|
|
else {
|
|
$constructionConsentProjects = json_decode((new WorkerFlag($this->me->id, "constructionConsent_projects"))->value() ?? '[]');
|
|
empty($constructionConsentProjects) ? $this->redirect("Dashboard") : $this->constructionConsentProjects = $constructionConsentProjects;
|
|
}
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
if (!in_array($consent->constructionconsentproject_id, $this->constructionConsentProjects)) {
|
|
$this->layout()->setFlash("Sie sind nicht berechtigt, diese Zustimmungserklärung zu bearbeiten", "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]);
|
|
}
|
|
|
|
|
|
try {
|
|
$uploaded = mfUpload::handleFormUpload("file", false, "/ConstructionConsentJournal");
|
|
} catch (Exception $e) {
|
|
}
|
|
|
|
|
|
$journal = ConstructionConsentJournal::create([
|
|
"constructionconsent_id" => $consent->id,
|
|
"file_id" => $uploaded->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]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |