287 lines
9.8 KiB
PHP
287 lines
9.8 KiB
PHP
<?php
|
|
|
|
class FiberPlanPipeController 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"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction()
|
|
{
|
|
$this->layout()->setTemplate("FiberPlanPipe/Index");
|
|
$fiberplanpipes = FiberPlanPipeModel::getAll();
|
|
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
|
|
$fiberplanpipeEndpoints = FiberPlanPipeEndpointModel::getAll();
|
|
|
|
$this->layout()->set("fiberplanpipeEndpoints", $fiberplanpipeEndpoints);
|
|
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
|
|
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
|
|
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
$networks = NetworkModel::getAll();
|
|
$fiberplanpipetemplates = FiberPlanPipeModel::getTemplates();
|
|
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
|
|
$this->layout()->set("networks", $networks);
|
|
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
|
|
$this->layout()->set("fiberplanpipetemplates", $fiberplanpipetemplates);
|
|
|
|
$this->layout()->setTemplate("FiberPlanPipe/Form");
|
|
|
|
}
|
|
|
|
protected function apiAction()
|
|
{
|
|
$do = $this->request->do;
|
|
$network = $this->request->network_id;
|
|
$bdtype = $this->request->bdtype;
|
|
|
|
|
|
switch ($do) {
|
|
case "getBuildingInfo":
|
|
$return = $this->getBuildingInfo($network, $bdtype);
|
|
break;
|
|
case "getPops":
|
|
$return = $this->getPops($network);
|
|
break;
|
|
default:
|
|
$return = false;
|
|
}
|
|
|
|
}
|
|
|
|
protected function detailAction()
|
|
{
|
|
$id = $this->request->id;
|
|
$this->layout()->setTemplate("FiberPlanPipe/Detail");
|
|
if (!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
$fiberplanpipes = new FiberPlanPipe($id);
|
|
if ($fiberplanpipes->id != $id) {
|
|
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
$pipworkeraddresses = FiberPlanPipeModel::getPipeworkerAddresses();
|
|
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
|
|
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
|
|
$this->layout()->set("pipworkeraddresses", $pipworkeraddresses);
|
|
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
$id = $this->request->id;
|
|
|
|
if (!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
|
|
$fiberplanpipes = new FiberPlanPipe($id);
|
|
if ($fiberplanpipes->id != $id) {
|
|
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
|
|
$this->layout()->set("fiberplanpipeendpoints", $fiberplanpipeendpoints);
|
|
$this->layout()->set("fiberplanpipes", $fiberplanpipes);
|
|
return $this->addAction();
|
|
}
|
|
|
|
protected function saveAction()
|
|
{
|
|
$r = $this->request;
|
|
$id = $r->id;
|
|
if (is_numeric($id) && $id > 0) {
|
|
$mode = "edit";
|
|
$fiberplanpipes = new FiberPlanPipe($id);
|
|
if (!$fiberplanpipes->id) {
|
|
$this->layout()->setFlash("Rohrverzeichnisse nicht gefunden", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
$data = [];
|
|
$data['description'] = trim($r->description);
|
|
$data['gisid'] = trim($r->gisid);
|
|
$data['type'] = trim($r->type);
|
|
$data['type_description'] = trim($r->type_description);
|
|
$data['fiberplanpipetemplate_id'] = trim($r->fiberplanpipetemplate_id);
|
|
$data['length'] = trim($r->length);
|
|
$data['status'] = trim($r->status);
|
|
$data['responsible'] = trim($r->responsible);
|
|
$data['responsible_text'] = trim($r->responsible_text);
|
|
$data['address_id'] = trim($r->address_id);
|
|
$data['comment'] = trim($r->comment);
|
|
|
|
$returnUrl = "FiberPlanPipe";
|
|
$returnAction = "Index";
|
|
$returnVariables = array();
|
|
$returnAnker = "";
|
|
if ($this->request->returnto) {
|
|
|
|
if (strpos($this->request->returnto, "-") !== false) {
|
|
$urls = explode('-', $this->request->returnto);
|
|
$urlCounter = 0;
|
|
$returnUrlGen = "";
|
|
foreach ($urls as $url) {
|
|
if ($urlCounter > 0) {
|
|
$returnUrlGen .= "/";
|
|
$returnUrlGen .= ucfirst($url);
|
|
} else {
|
|
$returnUrlGen .= 'FiberPlanPipe';
|
|
}
|
|
$urlCounter++;
|
|
}
|
|
$returnAction = "";
|
|
$returnVariables['id'] = $id;
|
|
$returnUrl = $returnUrlGen;
|
|
} else {
|
|
$returnUrl = ucfirst($this->request->returnto);
|
|
|
|
}
|
|
}
|
|
if (!$data['description']) {
|
|
$this->layout()->setFlash("Bezeichnung darf nicht leer sein", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
if (!$data['type']) {
|
|
$data['type'] = NULL;
|
|
}
|
|
if (!$data['gisid']) {
|
|
$data['gisid'] = NULL;
|
|
}
|
|
if (!$data['responsible_text']) {
|
|
$data['responsible_text'] = NULL;
|
|
}
|
|
if (!$data['address_id']) {
|
|
$data['address_id'] = NULL;
|
|
}
|
|
if (!$data['type_description']) {
|
|
$data['type_description'] = NULL;
|
|
}
|
|
if (!$data['fiberplanpipetemplate_id']) {
|
|
$data['fiberplanpipetemplate_id'] = NULL;
|
|
}
|
|
if (!$data['length']) {
|
|
$data['length'] = NULL;
|
|
}
|
|
if (!$data['status']) {
|
|
$data['status'] = NULL;
|
|
}
|
|
if (!$data['responsible']) {
|
|
$data['responsible'] = NULL;
|
|
}
|
|
if (!$data['comment']) {
|
|
$data['comment'] = NULL;
|
|
}
|
|
|
|
|
|
// var_dump($_FILES);
|
|
// var_dump($upload);
|
|
// exit;
|
|
|
|
|
|
if ($mode == "edit") {
|
|
$fiberplanpipes->update($data);
|
|
|
|
} else {
|
|
$fiberplanpipes = FiberPlanPipeModel::create($data);
|
|
}
|
|
// var_dump($filestore);
|
|
// exit;
|
|
$id = $fiberplanpipes->save();
|
|
|
|
$endpoint_id = $r->endpointid;
|
|
$endpoint_type = $r->endpoint_type;
|
|
$endpoint = $r->endpoint;
|
|
|
|
if (!empty($endpoint)) {
|
|
$fiberplanpipeendpoints = FiberPlanPipeEndpointModel::search(['fiberPlanPipe_id' => $id]);
|
|
foreach ($fiberplanpipeendpoints as $fiberplanpipeendpoint) {
|
|
if (!in_array($fiberplanpipeendpoint->id, $endpoint_id)) {
|
|
$fiberplanpipeendpoint->delete();
|
|
}
|
|
}
|
|
$counter = 1;
|
|
foreach ($endpoint as $key => $Endpoint) {
|
|
unset($endpointarray);
|
|
$endpointarray = [];
|
|
$endpointarray['fiberPlanDispatcher_id'] = null;
|
|
$endpointarray['pop_id'] = null;
|
|
$endpointarray['building_id'] = null;
|
|
if ($endpoint_type[$key] == 4 || $endpoint_type[$key] == 1) {
|
|
$endpointarray['fiberPlanDispatcher_id'] = $Endpoint;
|
|
} else if ($endpoint_type[$key] == 2) {
|
|
$endpointarray['pop_id'] = $Endpoint;
|
|
} else if ($endpoint_type[$key] == 3) {
|
|
$endpointarray['building_id'] = $Endpoint;
|
|
}
|
|
$endpointarray['fiberPlanPipe_id'] = $id;
|
|
$endpointarray['sort'] = $counter;
|
|
// print_r($endpointarray);
|
|
// var_dump($endpoint_id[$key]);
|
|
// die();
|
|
if ($endpoint_id[$key]) {
|
|
$fiberplanpipeendpoint = new FiberPlanPipeEndpoint($endpoint_id[$key]);
|
|
$fiberplanpipeendpoint->update($endpointarray);
|
|
unset($endpoint_id[$key]);
|
|
} else {
|
|
$fiberplanpipeendpoint = FiberPlanPipeEndpointModel::create($endpointarray);
|
|
}
|
|
$fiberplanpipeendpoint->save();
|
|
$counter++;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (!$id) {
|
|
$this->layout()->setFlash("Rohrverzeichnis konnte nicht angelegt werden", "error");
|
|
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
|
}
|
|
|
|
if ($mode == "edit") {
|
|
$this->layout()->setFlash("Rohrverzeichnis erfolgreich geändert", "success");
|
|
} else if ($mode = "add") {
|
|
$this->layout()->setFlash("Rohrverzeichnis erfolgreich angelegt", "success");
|
|
}
|
|
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
|
}
|
|
|
|
|
|
protected function deleteAction()
|
|
{
|
|
$id = $this->request->id;
|
|
$fiberplanpipes = new FiberPlanPipe($id);
|
|
if (!$fiberplanpipes->id || $fiberplanpipes->id != $id) {
|
|
$this->layout()->setFlash("Rohrverzeichnis nicht gefunden.", "error");
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
|
|
$fiberplanpipes->delete();
|
|
$this->redirect("FiberPlanPipe");
|
|
}
|
|
|
|
protected function getBuildingInfo($network, $bdtype)
|
|
{
|
|
FiberPlanPipeModel::getBuildingInfo($network, $bdtype);
|
|
}
|
|
}
|