From 5241cfd17592570b10c0812ceda10b80c60e397d Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 24 Jun 2021 22:34:45 +0200 Subject: [PATCH] Added Network --- Layout/default/Network/Form.php | 97 ++++++++++++++++ Layout/default/Network/Index.php | 78 +++++++++++++ Layout/default/menu.php | 6 +- application/Address/AddressController.php | 12 ++ application/Address/AddressModel.php | 28 ++++- .../AddressattributeModel.php | 12 +- application/Addresstype/AddresstypeModel.php | 4 +- application/Network/Network.php | 31 ++++++ application/Network/NetworkController.php | 95 ++++++++++++++++ application/Network/NetworkModel.php | 105 ++++++++++++++++++ application/Pop/Pop.php | 5 + application/Pop/PopController.php | 17 +++ 12 files changed, 475 insertions(+), 15 deletions(-) create mode 100644 Layout/default/Network/Form.php create mode 100644 Layout/default/Network/Index.php create mode 100644 application/Network/Network.php create mode 100644 application/Network/NetworkController.php create mode 100644 application/Network/NetworkModel.php create mode 100644 application/Pop/Pop.php create mode 100644 application/Pop/PopController.php diff --git a/Layout/default/Network/Form.php b/Layout/default/Network/Form.php new file mode 100644 index 000000000..ae71ad3ab --- /dev/null +++ b/Layout/default/Network/Form.php @@ -0,0 +1,97 @@ + + +
+
+ + +
+
+
+
+ +
+

Netzgebiete

+
+
+
+ + +
+
+ +
+
+

id) ? "Netzbereich bearbeiten" : "Neuer Netzbereich"?>

+ +
"> +
+
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+ + + +
+
+
+ +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/Layout/default/Network/Index.php b/Layout/default/Network/Index.php new file mode 100644 index 000000000..d27dba0b6 --- /dev/null +++ b/Layout/default/Network/Index.php @@ -0,0 +1,78 @@ + + +
+
+ + +
+
+
+
+ +
+

Netzgebiete

+
+
+
+ + +
+
+ +
+
+
+
+
+

Liste aller Netzgebiete

+
+ +
+
+ + + + + + + + + + + + + + + +
NameBesitzer
name?>owner->getFullName())?> + ["network_id" => $network->id]])?>" title="POPs anzeigen"> + $network->id])?>"> + $network->id])?>" class="text-danger" title="Löschen"> +
+ +

Keine Netzgebiete gefunden

+ +
+
+ +
+
+ +
+
+ + + \ No newline at end of file diff --git a/Layout/default/menu.php b/Layout/default/menu.php index e4485affe..20e16213e 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -21,9 +21,9 @@
  • ["addresstype" => ["supplier"]]])?>">Lieferanten
  • -
  • - ">Benutzer -
  • +
  • ">Benutzer
  • +
  • ">Neztgebiete
  • +
  • ">POPs
  • diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index 9d1e4ba07..008555856 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -3,6 +3,18 @@ class AddressController extends mfBaseController { private $filter; + 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() { //var_dump($this->request->filter); $default_filter = ['parents_only' => 1]; diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 6a593a49f..4f3885848 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -94,8 +94,29 @@ class AddressModel { if(is_array($filter['addresstype']) && count($filter['addresstype'])) { $at = $filter['addresstype']; $in = []; - if(in_array("owner", $at)) { - $in[] = "Addresstype.type = 'owner'"; + if(in_array("systemowner", $at)) { + $in[] = "Addresstype.type = 'systemowner'"; + } + if(in_array("netowner", $at)) { + $in[] = "Addresstype.type = 'netowner'"; + } + if(in_array("salespartner", $at)) { + $in[] = "Addresstype.type = 'Addresstype'"; + } + if(in_array("pipeworker", $at)) { + $in[] = "Addresstype.type = 'pipeworker'"; + } + if(in_array("lineworker", $at)) { + $in[] = "Addresstype.type = 'lineworker'"; + } + if(in_array("netoperator", $at)) { + $in[] = "Addresstype.type = 'netoperator'"; + } + if(in_array("support", $at)) { + $in[] = "Addresstype.type = 'support'"; + } + if(in_array("billing", $at)) { + $in[] = "Addresstype.type = 'billing'"; } if(in_array("employee", $at)) { $in[] = "Addresstype.type = 'employee'"; @@ -109,9 +130,6 @@ class AddressModel { if(in_array("contact", $at)) { $in[] = "Addresstype.type = 'contact'"; } - if(in_array("billing", $at)) { - $in[] = "Addresstype.type = 'billing'"; - } $or = ""; if(count($in)) { diff --git a/application/Addressattribute/AddressattributeModel.php b/application/Addressattribute/AddressattributeModel.php index 8cb2779e5..4f00cc6f1 100644 --- a/application/Addressattribute/AddressattributeModel.php +++ b/application/Addressattribute/AddressattributeModel.php @@ -36,15 +36,19 @@ class AddressattributeModel { if(!is_numeric($id) || !$id) { throw new Exception("Invalid number", 400); } - $item = []; $db = FronkDB::singleton(); $res = $db->select("Addressattribute", "*", "id=$id LIMIT 1"); if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Addressattribute($data); + if($item->id) { + return $item; + } else { + return null; + } } - return $item; + return null; } public static function getAll($filter = false) { @@ -76,10 +80,8 @@ class AddressattributeModel { } else { return null; } - } else { - return null; } - return $items; + return null; } public static function search($filter) { diff --git a/application/Addresstype/AddresstypeModel.php b/application/Addresstype/AddresstypeModel.php index c7cdfc141..68c2ae972 100644 --- a/application/Addresstype/AddresstypeModel.php +++ b/application/Addresstype/AddresstypeModel.php @@ -24,14 +24,14 @@ class AddresstypeModel { $me = new User(); $me->loadMe(); - + if($model->create_by === null) { $model->create_by = $me->id; } if($model->edit_by === null) { $model->edit_by = $me->id; } - + return $model; } diff --git a/application/Network/Network.php b/application/Network/Network.php new file mode 100644 index 000000000..29cd95c6c --- /dev/null +++ b/application/Network/Network.php @@ -0,0 +1,31 @@ +$name == null) { + + if($name == "owner") { + if($this->id) { + $this->owner = new Address($this->owner_id); + return $this->owner; + } else { + return null; + } + } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = new $classname($this->$idfield); + + if($this->$name->id) { + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } +} \ No newline at end of file diff --git a/application/Network/NetworkController.php b/application/Network/NetworkController.php new file mode 100644 index 000000000..ceee1621a --- /dev/null +++ b/application/Network/NetworkController.php @@ -0,0 +1,95 @@ +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()->set("owners", AddressModel::search(['addresstype' => ["netowner"]])); + $this->layout()->set("networks", NetworkModel::getAll()); + } + + protected function addAction() { + $this->layout()->setTemplate("Network/Form"); + $this->layout()->set("owners", AddressModel::search(['addresstype' => ["netowner"]])); + + } + + protected function editAction() { + $id = $this->request->id; + if(!is_numeric($id) || !$id) { + $this->layout()->setFlash("Netzgebiet nicht gefunden", "error"); + $this->redirect("Network"); + } + + $network = new Network($id); + if($network->id != $id) { + $this->layout()->setFlash("Netzgebiet nicht gefunden", "error"); + $this->redirect("Network"); + } + + $this->layout()->set("network", $network); + return $this->addAction(); + } + + protected function saveAction() { + $r = $this->request; + $id = $r->id; + //var_dump($r); + if(is_numeric($id) && $id > 0) { + $mode = "edit"; + $network = new Network($id); + if(!$network->id) { + $this->layout()->setFlash("Netzgebie tnicht gefunden", "error"); + $this->redirect("Network"); + } + } else { + $mode = "add"; + } + + //var_dump($r->addresstypes);exit; + + if(!$r->owner_id || !$r->name) { + $this->layout()->setFlash("Bitte Name und Besitzer eintragen", "error"); + $this->layout()->set("network", $network); + return $this->add(); + } + + $data = []; + $data['owner_id'] = $r->owner_id; + $data['name'] = $r->name; + $data['note'] = $r->note; + + $data['edit_by'] = 1; + + if($mode == "add") { + $data['create_by'] = 1; + $network = NetworkModel::create($data); + } else { + $network->update($data); + } + + //var_dump($address);exit; + + $new_id = $network->save(); + if(!$new_id) { + $this->layout()->setFlash("Fehler beim Speichern", "error"); + $this->layout()->set("network", $network); + return $this->add(); + } + + + $this->layout()->setFlash("Netzgebiet erfolgreich gespeichert.", "success"); + $this->redirect("Network", "Edit", ['id' => $new_id]); + } +} \ No newline at end of file diff --git a/application/Network/NetworkModel.php b/application/Network/NetworkModel.php new file mode 100644 index 000000000..9a9652db4 --- /dev/null +++ b/application/Network/NetworkModel.php @@ -0,0 +1,105 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + return $model; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("Network", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Network($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Network", "*"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Network($data); + } + } + return $items; + + } + + public static function getFirst() { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Network", "*". "$where ORDER BY name, owner_id"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Network($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Network", "*". "$where ORDER BY name, owner_id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Network($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + //var_dump($filter);exit; + if(array_key_exists("owner_id", $filter)) { + $ownerid= $filter['owner_id']; + if(is_numeric($ownerid)) { + $where .= " AND owner_id=$ownerid"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Pop/Pop.php b/application/Pop/Pop.php new file mode 100644 index 000000000..638f7e08a --- /dev/null +++ b/application/Pop/Pop.php @@ -0,0 +1,5 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + /* + if(!$me->isAdmin()) { + $this->redirect("Dashboard"); + }*/ + } + +} \ No newline at end of file