96 lines
3.1 KiB
PHP
96 lines
3.1 KiB
PHP
<?php
|
|
|
|
class ConstructionConsentContactController extends mfBaseController
|
|
{
|
|
|
|
protected function init(): void
|
|
{
|
|
$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->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");
|
|
}
|
|
|
|
$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");
|
|
}
|
|
|
|
$contact->delete();
|
|
|
|
$this->layout()->setFlash("Ansprechpartner wurde gelöscht.", "success");
|
|
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
|
|
}
|
|
} |