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("FiberPlanFiber/Index"); $fiberplanfibers = FiberPlanFiberModel::getAll(); $this->layout()->set("fiberplanfibers", $fiberplanfibers); } protected function addAction() { $cables=CableModel::getAll(); $this->layout()->set("cables", $cables); $this->layout()->setTemplate("FiberPlanFiber/Form"); } protected function editAction() { $id = $this->request->id; if (!is_numeric($id) || !$id) { $this->layout()->setFlash("Faser nicht gefunden", "error"); $this->redirect("FiberPlanFiber"); } $fiberplanfibers = new FiberPlanFiber($id); if ($fiberplanfibers->id != $id) { $this->layout()->setFlash("Faser nicht gefunden", "error"); $this->redirect("FiberPlanFiber"); } $this->layout()->set("fiberplanfibers", $fiberplanfibers); return $this->addAction(); } protected function getCustomerLocationAction() { header('Content-Type: application/json'); $address = $this->request->address; $network_id = intval($this->request->network_id); if (!$address) { echo json_encode(['success' => false, 'error' => 'Keine Adresse angegeben']); return; } $db = FronkDB::singleton(); $address_escaped = $db->escape($address); $sql = "SELECT gps_lat, gps_long FROM FiberPlanAddress WHERE address LIKE '%$address_escaped%' AND network_id = $network_id AND gps_lat IS NOT NULL AND gps_long IS NOT NULL LIMIT 1"; $res = $db->query($sql); if ($db->num_rows($res)) { $data = $db->fetch_object($res); echo json_encode([ 'success' => true, 'gps_lat' => $data->gps_lat, 'gps_long' => $data->gps_long ]); } else { echo json_encode([ 'success' => false, 'error' => 'Keine GPS-Koordinaten gefunden' ]); } exit; } protected function saveAction() { $r = $this->request; $id = $r->id; if (is_numeric($id) && $id > 0) { $mode = "edit"; $fiberplanfibers = new FiberPlanFiber($id); if (!$fiberplanfibers->id) { $this->layout()->setFlash("Fasern nicht gefunden", "error"); $this->redirect("FiberPlanFiber"); } } else { $mode = "add"; } $data = []; $data['cable_id'] = trim($r->cable_id); $data['sheet_range'] = trim($r->sheet_range); $data['connector_nr'] = trim($r->connector_nr); $data['fiber_nr_cable'] = trim($r->fiber_nr_cable); $data['bundle_nr'] = trim($r->bundle_nr); $data['fiber_nr_bundle'] = trim($r->fiber_nr_bundle); $data['fiber_color'] = trim($r->fiber_color); $data['branch_type'] = trim($r->branch_type); $data['branch_cable_nr'] = trim($r->branch_cable_nr); $data['branch_fiber_count'] = trim($r->branch_fiber_count); $data['branch_fiber_nr'] = trim($r->branch_fiber_nr); $data['branch_bundle_nr'] = trim($r->branch_bundle_nr); $data['branch_fiber_in_bundle'] = trim($r->branch_fiber_in_bundle); $data['branch_from_location'] = trim($r->branch_from_location); $data['branch_to_location'] = trim($r->branch_to_location); $data['branch_gis_id'] = trim($r->branch_gis_id); $data['address'] = trim($r->address); $data['name'] = trim($r->name); $data['home_id'] = trim($r->home_id); $data['location'] = trim($r->location); $data['rack_unit'] = trim($r->rack_unit); $data['termination_type'] = trim($r->termination_type); $data['customer_cable_type'] = trim($r->customer_cable_type); $data['customer_cable_fiber_nr'] = trim($r->customer_cable_fiber_nr); $data['customer_connector_type'] = trim($r->customer_connector_type); $data['customer_cable_spec'] = trim($r->customer_cable_spec); $data['customer_fiber_range'] = trim($r->customer_fiber_range); $data['splitter_location'] = trim($r->splitter_location); $data['splitter_factor'] = trim($r->splitter_factor); $data['uuid_qgis_kabel'] = trim($r->uuid_qgis_kabel); $data['status'] = trim($r->status); $data['comment'] = trim($r->comment); foreach ($data as $key => $value) { if ($value === '') { $data[$key] = NULL; } } if ($mode == "edit") { $fiberplanfibers->update($data); } else { $fiberplanfibers = FiberPlanFiberModel::create($data); } $id = $fiberplanfibers->save(); if (!$id) { $this->layout()->setFlash("Faser konnte nicht angelegt werden", "error"); $this->redirect("FiberPlanFiber"); } if ($mode == "edit") { $this->layout()->setFlash("Faser erfolgreich geƤndert", "success"); } else if ($mode = "add") { $this->layout()->setFlash("Faser erfolgreich angelegt", "success"); } $this->redirect("FiberPlanFiber"); } protected function deleteAction() { $id = $this->request->id; $fiberplanfibers = new FiberPlanFiber($id); if (!$fiberplanfibers->id || $fiberplanfibers->id != $id) { $this->layout()->setFlash("Faser nicht gefunden.", "error"); $this->redirect("FiberPlanFiber"); } $fiberplanfibers->delete(); $this->redirect("FiberPlanFiber"); } }