105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
class ADBWohneinheitController 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"]) && !$me->can("Preorder")) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function addAction() {
|
|
$this->layout()->setTemplate("ADBWohneinheit/Form");
|
|
|
|
if($this->me->is("Admin")) {
|
|
$my_networks = NetworkModel::getAll();
|
|
} else {
|
|
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
|
}
|
|
|
|
$netzgebiet_ids = [];
|
|
$my_adb_networks = [];
|
|
foreach($my_networks as $network) {
|
|
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
|
|
$netzgebiet_ids[] = $network->adb_netzgebiet_id;
|
|
$my_adb_networks[$network->adb_netzgebiet_id] = new ADBNetzgebiet($network->adb_netzgebiet_id);
|
|
}
|
|
}
|
|
$this->layout()->set("my_adb_networks", $my_adb_networks);
|
|
|
|
}
|
|
|
|
protected function editAction() {
|
|
$id = $this->request->id;
|
|
if(!is_numeric($id) || $id < 1) {
|
|
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
|
$this->redirect("AddressDB");
|
|
}
|
|
|
|
$unit = new ADBWohneinheit($id);
|
|
if(!$unit->id) {
|
|
$this->layout()->setFlash("Wohneinheit nicht gefunden", "error");
|
|
$this->redirect("AddressDB");
|
|
}
|
|
|
|
/*if(!in_array($hausnummer->netzgebiet_id, $my_adb_networks)) {
|
|
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
|
$this->redirect("AddressDB");
|
|
}*/
|
|
|
|
$this->layout()->set("unit", $unit);
|
|
|
|
return $this->addAction();
|
|
}
|
|
|
|
protected function saveAction() {
|
|
$r = $this->request;
|
|
$id = $r->id;
|
|
//var_dump($r->get());exit;
|
|
|
|
$unit_data = [];
|
|
|
|
if(is_numeric($id) && $id > 0) {
|
|
$mode = "edit";
|
|
$unit = new ADBWohneinheit($id);
|
|
if(!$unit->id) {
|
|
$this->layout()->setFlash("Wohneinheit nicht gefunden", "error");
|
|
$this->redirect("AddressDB");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
|
|
$unit_data["oaid"] = ($r->oaid) ? trim($r->oaid) : null;
|
|
$unit_data["extref"] = ($r->extref) ? trim($r->extref) : null;
|
|
$unit_data["block"] = ($r->block) ? trim($r->block) : null;
|
|
$unit_data["stiege"] = ($r->stiege) ? trim($r->stiege) : null;
|
|
$unit_data["stock"] = ($r->stock) ? trim($r->stock) : null;
|
|
$unit_data["tuer"] = ($r->tuer) ? trim($r->tuer) : null;
|
|
$unit_data["zusatz"] = ($r->zusatz) ? trim($r->zusatz) : null;
|
|
$unit_data["bezeichner"] = ($r->bezeichner) ? trim($r->bezeichner) : null;
|
|
|
|
if($mode == "add") {
|
|
$unit = ADBWohneinheitModel::create($unit_data);
|
|
} else {
|
|
$unit->update($unit_data);
|
|
}
|
|
|
|
if(!$unit->save()) {
|
|
$this->layout()->setFlash("Beim Speichern der Wohneinheit ist ein Fehler aufgetreten.", "error");
|
|
$this->layout()->set("unit", $unit);
|
|
return $this->addAction();
|
|
}
|
|
|
|
$this->layout()->setFlash("Wohneinheit erfolgreich gespeichert.", "success");
|
|
$this->redirect("AddressDB", "view", ["id" => $unit->hausnummer_id]);
|
|
}
|
|
|
|
} |