122 lines
3.4 KiB
PHP
122 lines
3.4 KiB
PHP
<?php
|
|
|
|
class BuildingController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->isAdmin()) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction() {
|
|
$this->layout()->setTemplate("Building/Index");
|
|
$this->layout()->set("buildings", BuildingModel::getAll());
|
|
}
|
|
|
|
protected function addAction() {
|
|
$this->layout()->setTemplate("Building/Form");
|
|
$this->layout()->set("networks", NetworkModel::getAll());
|
|
$this->layout()->set("types", BuildingtypeModel::getAll());
|
|
$this->layout()->set("statuses", BuildingstatusModel::getAll());
|
|
}
|
|
|
|
protected function editAction() {
|
|
$id = $this->request->id;
|
|
if(!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
|
$this->redirect("Building");
|
|
}
|
|
|
|
$building = new Building($id);
|
|
if($building->id != $id) {
|
|
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
|
$this->redirect("Building");
|
|
}
|
|
|
|
$this->layout()->set("building", $building);
|
|
return $this->addAction();
|
|
}
|
|
|
|
protected function saveAction() {
|
|
$r = $this->request;
|
|
$id = $r->id;
|
|
//var_dump($r);exit;
|
|
if(is_numeric($id) && $id > 0) {
|
|
$mode = "edit";
|
|
$building = new Building($id);
|
|
if(!$building->id) {
|
|
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
|
$this->redirect("Objekt");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
if(!$r->network_id || !$r->type_id) {
|
|
$this->layout()->setFlash("Bitte Netzgebiet und Typ auswählen", "error");
|
|
$this->layout()->set("building", $building);
|
|
return $this->add();
|
|
}
|
|
|
|
$data = [];
|
|
$data['network_id'] = $r->network_id;
|
|
$data['pop_id'] = ($r->pop_id) ? $r->pop_id : null;
|
|
$data['type_id'] = $r->type_id;
|
|
$data['status_id'] = ($r->status_id) ? $r->status_id : null;
|
|
$data['pipeworker_id'] = ($r->pipeworker_id) ? $r->pipeworker_id : null;
|
|
$data['code'] = $r->code;
|
|
$data['oan_id'] = $r->oan_id;
|
|
$data['street'] = $r->street;
|
|
$data['zip'] = $r->zip;
|
|
$data['city'] = $r->city;
|
|
$data['gps_lat'] = $r->gps_lat;
|
|
$data['gps_long'] = $r->gps_long;
|
|
$data['contact'] = $r->contact;
|
|
$data['phone'] = $r->phone;
|
|
$data['email'] = $r->email;
|
|
$data['units'] = $r->units;
|
|
$data['description'] = $r->description;
|
|
$data['note'] = $r->note;
|
|
|
|
$data['edit_by'] = 1;
|
|
|
|
if($mode == "add") {
|
|
$data['status_id'] = 1;
|
|
$data['create_by'] = 1;
|
|
$building = BuildingModel::create($data);
|
|
} else {
|
|
$building->update($data);
|
|
}
|
|
|
|
//var_dump($address);exit;
|
|
|
|
$new_id = $building->save();
|
|
if(!$new_id) {
|
|
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
|
$this->layout()->set("building", $building);
|
|
return $this->add();
|
|
}
|
|
|
|
// generate object code and LAEA coords
|
|
if(!$building->code) {
|
|
$building->code = $building->getNewObjectCode();
|
|
$building->save();
|
|
}
|
|
if(!$building->laea) {
|
|
$building->laea = $building->getLaeaCoordinates();
|
|
$building->save();
|
|
}
|
|
|
|
|
|
$this->layout()->setFlash("Objekt erfolgreich gespeichert.", "success");
|
|
$this->redirect("Building", "Edit", ['id' => $new_id]);
|
|
}
|
|
|
|
|
|
} |