104 lines
2.7 KiB
PHP
104 lines
2.7 KiB
PHP
<?php
|
|
|
|
class PopController 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() {
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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;
|
|
$data['gps_long'] = $r->gps_long;
|
|
$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);
|
|
}
|
|
|
|
//var_dump($address);exit;
|
|
|
|
$new_id = $pop->save();
|
|
if(!$new_id) {
|
|
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
|
$this->layout()->set("network", $network);
|
|
return $this->addAction();
|
|
}
|
|
|
|
$this->layout()->setFlash("Netzgebiet erfolgreich gespeichert.", "success");
|
|
$this->redirect("Pop", "Edit", ['id' => $new_id]);
|
|
}
|
|
} |