needlogin = true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me", $me); if (!$me->is(["Admin", "netowner", "pipeplanner"])) { $this->redirect("Dashboard"); } } protected function indexAction() { $this->layout()->setTemplate("Pop/Index"); $pops = PopModel::getAll(); $this->layout()->set("pops", $pops); } protected function detailAction() { $id = $this->request->id; if (!is_numeric($id) || !$id) { $this->layout()->setFlash("pop nicht gefunden", "error"); $this->redirect("Pop"); } $device = new Device($id); if ($device->id != $id) { $this->layout()->setFlash("Pop nicht gefunden", "error"); $this->redirect("Pop"); } $this->layout()->setTemplate("Pop/Detail"); $pops = PopModel::getOne($id); $this->layout()->set("pops", $pops); } protected function addAction() { $this->layout()->setTemplate("Pop/Form"); $this->layout()->set("networks", NetworkModel::getAll()); if ($this->request->network_id) { $pop = new Pop(); $pop->network_id = $this->request->network_id; $this->layout()->set("pop", $pop); } } protected function editAction() { $id = $this->request->id; if (!is_numeric($id) || !$id) { $this->layout()->setFlash("POP nicht gefunden", "error"); $this->redirect("Network"); } $pop = new Pop($id); if ($pop->id != $id) { $this->layout()->setFlash("POP nicht gefunden", "error"); $this->redirect("Network"); } $this->layout()->set("pop", $pop); return $this->addAction(); } protected function saveAction() { $r = $this->request; $id = $r->id; //var_dump($r);exit; if (is_numeric($id) && $id > 0) { $mode = "edit"; $pop = new Pop($id); if (!$pop->id) { $this->layout()->setFlash("POP nicht gefunden", "error"); $this->redirect("Network"); } } else { $mode = "add"; } //var_dump($r->addresstypes);exit; $this->log->debug(print_r($r, true)); if (!$r->network_id || !$r->name) { $this->layout()->setFlash("Bitte Name und Netzgebiet eintragen", "error"); $this->layout()->set("pop", $pop); unset($r->network_id); return $this->add(); } $data = []; $data['network_id'] = $r->network_id; $data['name'] = $r->name; $data['gps_lat'] = ($r->gps_lat) ? $r->gps_lat : null; $data['gps_long'] = ($r->gps_long) ? $r->gps_long : null; $data['location'] = $r->location; $data['vlan_public'] = ($r->vlan_public) ? $r->vlan_public : null; $data['vlan_nat'] = ($r->vlan_nat) ? $r->vlan_nat : null; $data['vlan_ipv6'] = ($r->vlan_ipv6) ? $r->vlan_ipv6 : null; $data['note'] = $r->note; $data['edit_by'] = 1; if ($mode == "add") { $data['create_by'] = 1; $pop = PopModel::create($data); } else { $pop->update($data); } $new_id = $pop->save(); if (!$new_id) { $this->layout()->setFlash("Fehler beim Speichern", "error"); $this->layout()->set("network", $network); return $this->addAction(); } if ($this->request->returnto) { $this->returUrl = ucfirst($this->request->returnto); } $this->layout()->setFlash("Netzgebiet erfolgreich gespeichert.", "success"); $this->redirect($this->returUrl, "Index", [], "view=pops&net=" . $pop->network_id); } protected function apiAction() { $do = $this->request->do; $data = []; switch ($do) { case "getPops": $return = $this->getPopsApi(); break; default: $return = false; } if (!is_array($return) || !count($return)) { $data = ["status" => "error"]; $this->returnJson($data); } $data['status'] = "OK"; $data['result'] = $return; $this->returnJson($data); } private function getPopsApi() { $network_id = $this->request->network_id; if (!is_numeric($network_id) || $network_id < 1) { return false; } $network = new Network($network_id); if (!$network->id) { return false; } $pops = []; foreach ($network->pops as $pop) { $pops[$pop->id] = $pop->name; } return ["pops" => $pops]; } protected function deleteAction() { $id = $this->request->id; $pop = new Pop($id); if (!$pop->id || $pop->id != $id) { $this->layout()->setFlash("Datei nicht gefunden.", "error"); $this->redirect("Pop"); } $pop->delete(); $this->redirect("Pop"); } }