From da952bfe3aafdc47e3af200bc146daad10595c4d Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 13 Jul 2021 23:00:16 +0200 Subject: [PATCH] Added Buildings --- Layout/default/Building/Form.php | 208 ++++++++++++++++++ Layout/default/Building/Index.php | 74 +++++++ Layout/default/menu.php | 11 + application/Address/AddressController.php | 4 +- application/Building/Building.php | 42 ++++ application/Building/BuildingController.php | 112 ++++++++++ application/Building/BuildingModel.php | 150 +++++++++++++ application/Buildingstatus/Buildingstatus.php | 5 + .../Buildingstatus/BuildingstatusModel.php | 95 ++++++++ application/Buildingtype/Buildingtype.php | 5 + .../Buildingtype/BuildingtypeModel.php | 90 ++++++++ application/Network/NetworkController.php | 4 +- .../NetworkAddressController.php | 4 +- application/Pop/PopController.php | 4 +- application/Product/ProductController.php | 4 +- .../ProductAttributeController.php | 4 +- .../Productgroup/ProductgroupController.php | 4 +- .../Producttech/ProducttechController.php | 4 +- .../ProducttechAttributeController.php | 4 +- application/User/User.php | 6 + 20 files changed, 816 insertions(+), 18 deletions(-) create mode 100644 Layout/default/Building/Form.php create mode 100644 Layout/default/Building/Index.php create mode 100644 application/Building/Building.php create mode 100644 application/Building/BuildingController.php create mode 100644 application/Building/BuildingModel.php create mode 100644 application/Buildingstatus/Buildingstatus.php create mode 100644 application/Buildingstatus/BuildingstatusModel.php create mode 100644 application/Buildingtype/Buildingtype.php create mode 100644 application/Buildingtype/BuildingtypeModel.php diff --git a/Layout/default/Building/Form.php b/Layout/default/Building/Form.php new file mode 100644 index 000000000..9522c81af --- /dev/null +++ b/Layout/default/Building/Form.php @@ -0,0 +1,208 @@ + + +
+
+ + +
+
+
+
+ +
+

Objekte

+
+
+
+ + +
+
+ +
+
+

id) ? "Objekt bearbeiten" : "Neues Objekt"?>

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

Objekte

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

Liste aller Objekte

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
NetzgebietPOPTypObjektcodeOAN IDAdresseEinheiten
network->name?>pop->name?>type->name?>code?>oan_id?> + street?>
+ zip?> city?> +
units?> + $building->id])?>"> + $building->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen"> +
+
+
+ +
+
+ +
+
+ + + \ No newline at end of file diff --git a/Layout/default/menu.php b/Layout/default/menu.php index 9711f6385..4e5088755 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -30,6 +30,17 @@
  • ">Netzgebiete
  • + +
  • + + Netzbau
    +
    + +
  • + diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index 7801b5748..90ccdf67e 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -9,10 +9,10 @@ class AddressController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function indexAction() { diff --git a/application/Building/Building.php b/application/Building/Building.php new file mode 100644 index 000000000..c0ea2070b --- /dev/null +++ b/application/Building/Building.php @@ -0,0 +1,42 @@ +$name == null) { + + if($name == "type") { + $this->type = new Buildingtype($this->type_id); + return $this->type; + } + + if($name == "status") { + $this->status = new Buildingstatus($this->status_id); + return $this->status; + } + + if($name == "pipeworker") { + $this->pipeworker = new Address($this->pipeworker_id); + return $this->pipeworker; + } + + $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/Building/BuildingController.php b/application/Building/BuildingController.php new file mode 100644 index 000000000..ad6e409be --- /dev/null +++ b/application/Building/BuildingController.php @@ -0,0 +1,112 @@ +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()->setTemplate("Building/Index"); + $this->layout()->set("buildings", BuildingModel::getAll()); + } + + protected function addAction() { + $this->layout()->setTemplate("Building/Form"); + $this->layout()->set("networks", NetworkModel::getAll()); + $this->layout()->set("types", BuildingtypeModel::getAll()); + } + + protected function editAction() { + $id = $this->request->id; + if(!is_numeric($id) || !$id) { + $this->layout()->setFlash("Objekt nicht gefunden", "error"); + $this->redirect("Building"); + } + + $building = new Building($id); + if($building->id != $id) { + $this->layout()->setFlash("Objekt nicht gefunden", "error"); + $this->redirect("Building"); + } + + $this->layout()->set("building", $building); + return $this->addAction(); + } + + protected function saveAction() { + $r = $this->request; + $id = $r->id; + //var_dump($r);exit; + if(is_numeric($id) && $id > 0) { + $mode = "edit"; + $building = new Building($id); + if(!$building->id) { + $this->layout()->setFlash("Objekt nicht gefunden", "error"); + $this->redirect("Objekt"); + } + } else { + $mode = "add"; + } + + if(!$r->network_id || !$r->type_id) { + $this->layout()->setFlash("Bitte Netzgebiet und Typ auswählen", "error"); + $this->layout()->set("building", $building); + return $this->add(); + } + + $data = []; + $data['network_id'] = $r->network_id; + $data['pop_id'] = ($r->pop_id) ? $r->pop_id : null; + $data['type_id'] = $r->type_id; + $data['status_id'] = ($r->status_id) ? $r->status_id : null; + $data['pipeworker_id'] = ($r->pipeworker_id) ? $r->pipeworker_id : null; + $data['code'] = $r->code; + $data['oan_id'] = $r->oan_id; + $data['street'] = $r->street; + $data['zip'] = $r->zip; + $data['city'] = $r->city; + $data['gps_lat'] = $r->gps_lat; + $data['gps_long'] = $r->gps_long; + $data['contact'] = $r->contact; + $data['phone'] = $r->phone; + $data['email'] = $r->email; + $data['units'] = $r->units; + $data['description'] = $r->description; + $data['note'] = $r->note; + + + $data['edit_by'] = 1; + + if($mode == "add") { + $data['status_id'] = 1; + $data['create_by'] = 1; + $building = BuildingModel::create($data); + } else { + $building->update($data); + } + + //var_dump($address);exit; + + $new_id = $building->save(); + if(!$new_id) { + $this->layout()->setFlash("Fehler beim Speichern", "error"); + $this->layout()->set("building", $building); + return $this->add(); + } + + + $this->layout()->setFlash("Objekt erfolgreich gespeichert.", "success"); + $this->redirect("Building", "Edit", ['id' => $new_id]); + } + + +} \ No newline at end of file diff --git a/application/Building/BuildingModel.php b/application/Building/BuildingModel.php new file mode 100644 index 000000000..eda2894d8 --- /dev/null +++ b/application/Building/BuildingModel.php @@ -0,0 +1,150 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $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; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("Building", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Building($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Building", "*", "1=1 ORDER BY network_id,pop_id,street,zip,city"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Building($data); + } + } + return $items; + + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT Building.* FROM Building + LEFT JOIN Buildingtype ON (Buildingtype.id = Building.type_id) + LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id) + WHERE $where + ORDER BY network_id,pop_id,street,zip,city"; + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Address($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + /* + * Address Type + */ + if(is_array($filter['type']) && count($filter['type'])) { + $ot = $filter['type']; + $in = []; + foreach($ot as $type) { + $type = FronkDB::singleton()->escape($type); + $in[] = "Buildingtype.name = '$type'"; + } + + $or = ""; + if(count($in)) { + $or = implode(" OR ", $in); + $where .= " AND ( $or )"; + } + } + + if(array_key_exists("status", $filter)) { + if(in_array(substr($filter['status'], 1, 2), ["<=", ">="])) { + $op = substr($filter['status'], 1, 2); + $status = substr($filter['status'], 3); + } elseif(in_array(substr($filter['status'], 1, 1), ["<", ">"])) { + $op = substr($filter['status'], 1, 1); + $status = substr($filter['status'], 2); + } else { + $op = "="; + $status = $filter['status']; + } + + if(is_numeric($status)) { + $where .= " AND Buildingstatus.code $op $status"; + } else { + // get code of statusname + $code = Buildingstatus::getOne(["name" => $status]); + if($code) { + $status = FronkDB::singleton()->escape($status); + $where .= " AND Buildingstatus.code $op '$status'"; + } + + } + + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Buildingstatus/Buildingstatus.php b/application/Buildingstatus/Buildingstatus.php new file mode 100644 index 000000000..45ca71db4 --- /dev/null +++ b/application/Buildingstatus/Buildingstatus.php @@ -0,0 +1,5 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $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; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("Buildingstatus", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Buildingstatus($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Buildingstatus", "*", "1=1 ORDER BY code,name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Buildingstatus($data); + } + } + return $items; + + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Buildingstatus", "*", $where); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Buildingstatus($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("code", $filter)) { + $code = FronkDB::singleton()->escape($filter['code']); + $where .= " AND code='$code'"; + } + + if(array_key_exists("name", $filter)) { + $name = FronkDB::singleton()->escape($filter['name']); + $where .= " AND name='$name'"; + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Buildingtype/Buildingtype.php b/application/Buildingtype/Buildingtype.php new file mode 100644 index 000000000..996c7eb4a --- /dev/null +++ b/application/Buildingtype/Buildingtype.php @@ -0,0 +1,5 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $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; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("Buildingtype", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Buildingtype($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Buildingtype", "*", "1=1 ORDER BY name"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Buildingtype($data); + } + } + return $items; + + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Buildingtype", "*", $where); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Buildingtype($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("name", $filter)) { + $name = FronkDB::singleton()->escape($filter['name']); + $where .= " AND name='$name'"; + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Network/NetworkController.php b/application/Network/NetworkController.php index c38c152b1..ccc664512 100644 --- a/application/Network/NetworkController.php +++ b/application/Network/NetworkController.php @@ -8,10 +8,10 @@ class NetworkController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function indexAction() { diff --git a/application/NetworkAddress/NetworkAddressController.php b/application/NetworkAddress/NetworkAddressController.php index 14a25147d..1164f1cfa 100644 --- a/application/NetworkAddress/NetworkAddressController.php +++ b/application/NetworkAddress/NetworkAddressController.php @@ -8,10 +8,10 @@ class NetworkAddressController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function saveAction() { diff --git a/application/Pop/PopController.php b/application/Pop/PopController.php index ebd649dbe..80b9ee326 100644 --- a/application/Pop/PopController.php +++ b/application/Pop/PopController.php @@ -8,10 +8,10 @@ class PopController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function indexAction() { diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php index da3fa2626..e1f561543 100644 --- a/application/Product/ProductController.php +++ b/application/Product/ProductController.php @@ -8,10 +8,10 @@ class ProductController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function indexAction() { diff --git a/application/ProductAttribute/ProductAttributeController.php b/application/ProductAttribute/ProductAttributeController.php index cbcc0ddd1..c6f03d83e 100644 --- a/application/ProductAttribute/ProductAttributeController.php +++ b/application/ProductAttribute/ProductAttributeController.php @@ -8,10 +8,10 @@ class ProductAttributeController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } diff --git a/application/Productgroup/ProductgroupController.php b/application/Productgroup/ProductgroupController.php index 79802ce51..3d777b748 100644 --- a/application/Productgroup/ProductgroupController.php +++ b/application/Productgroup/ProductgroupController.php @@ -8,10 +8,10 @@ class ProductgroupController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function indexAction() { diff --git a/application/Producttech/ProducttechController.php b/application/Producttech/ProducttechController.php index 48b27ade9..56f9bb200 100644 --- a/application/Producttech/ProducttechController.php +++ b/application/Producttech/ProducttechController.php @@ -8,10 +8,10 @@ class ProducttechController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function indexAction() { diff --git a/application/ProducttechAttribute/ProducttechAttributeController.php b/application/ProducttechAttribute/ProducttechAttributeController.php index 664540506..5ac9a52e4 100644 --- a/application/ProducttechAttribute/ProducttechAttributeController.php +++ b/application/ProducttechAttribute/ProducttechAttributeController.php @@ -8,10 +8,10 @@ class ProducttechAttributeController extends mfBaseController { $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); - /* + if(!$me->isAdmin()) { $this->redirect("Dashboard"); - }*/ + } } protected function deleteAction() { diff --git a/application/User/User.php b/application/User/User.php index dbac68580..9510ecf4b 100644 --- a/application/User/User.php +++ b/application/User/User.php @@ -74,9 +74,15 @@ class User extends mfBaseModel { } public function is($what) { + if(!$this->id) { + return false; + } if(is_object($this->permissions) && property_exists($this->permissions, "is$what")) { return $this->permissions->{"is$what"}; } + if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) { + return ($this->address->types[$what]->id) ? true : false; + } } public function isAdmin() {