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->get());exit; $id = $r->contact_id; if (is_numeric($id) && $id > 0) { $mode = "edit"; $item = new ConstructionConsentContact($id); if (!$item->id) { $this->layout()->setFlash("Ansprechpartner nicht gefunden", "error"); $this->redirect("ConstructionConsent"); } } else { $id = false; $mode = "add"; } $cc_id = $r->constructionconsent_id; $cc = new ConstructionConsent($cc_id); if(!$cc_id || !$cc->id) { $this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error"); $this->redirect("ConstructionConsent"); } if (!in_array($cc->constructionconsentproject_id, $this->constructionConsentProjects)) { $this->layout()->setFlash("Sie sind nicht berechtigt, diese Zustimmungserklärung zu bearbeiten", "error"); $this->redirect("ConstructionConsent"); } $data = []; $data["constructionconsent_id"] = $cc_id; $data["type"] = $r->type; $data["name"] = $r->name; $data["street"] = $r->street; $data["zip"] = $r->zip; $data["city"] = $r->city; $data["country"] = $r->country; $data["phone"] = $r->phone; $data["fax"] = $r->fax; $data["email"] = $r->email; if($mode == "add") { $item = ConstructionConsentContact::create($data); } else { $item->update($data); } if(!$item->save()) { $this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error"); } else { $this->layout()->setFlash("Ansprechpartner wurde erfolgreich gespeichert.", "success"); } $this->redirect("ConstructionConsent", "View", ["id" => $cc_id]); } protected function deleteAction() { $r = $this->request; //var_dump($r->get());exit; $id = $r->contact_id; if(!is_numeric($id) || $id < 1) { $this->layout()->setFlash("Ansprechpartner nicht gefunden", "error"); $this->redirect("ConstructionConsent"); } $contact = new ConstructionConsentContact($id); if(!$contact->id) { $this->layout()->setFlash("Ansprechpartner nicht gefunden", "error"); $this->redirect("ConstructionConsent"); } $cc_id = $contact->constructionconsent_id; $cc = new ConstructionConsent($cc_id); if(!$cc_id || !$cc->id) { $this->layout()->setFlash("Beim Löschen ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error"); $this->redirect("ConstructionConsent"); } if (!in_array($cc->constructionconsentproject_id, $this->constructionConsentProjects)) { $this->layout()->setFlash("Sie sind nicht berechtigt, diese Zustimmungserklärung zu bearbeiten", "error"); $this->redirect("ConstructionConsent"); } $contact->delete(); $this->layout()->setFlash("Ansprechpartner wurde gelöscht.", "success"); $this->redirect("ConstructionConsent", "View", ["id" => $cc_id]); } }