diff --git a/Layout/default/Building/Form.php b/Layout/default/Building/Form.php index 2ea2af35f..08f52858e 100644 --- a/Layout/default/Building/Form.php +++ b/Layout/default/Building/Form.php @@ -83,12 +83,14 @@ + id): ?> +
@@ -205,15 +207,6 @@
- -
@@ -234,9 +227,9 @@
- +
- is(["Admin", "netowner", "pipeplanner"])) ? "disabled='disabled'" : ""?>> @@ -246,9 +239,9 @@
- +
- is(["Admin", "netowner", "pipeplanner"])) ? "disabled='disabled'" : ""?>> diff --git a/Layout/default/User/Form.php b/Layout/default/User/Form.php index cf9f1b980..5cf86bcd2 100644 --- a/Layout/default/User/Form.php +++ b/Layout/default/User/Form.php @@ -46,7 +46,7 @@
diff --git a/Layout/default/User/Index.php b/Layout/default/User/Index.php index 81676e373..0d03ff8e5 100644 --- a/Layout/default/User/Index.php +++ b/Layout/default/User/Index.php @@ -38,7 +38,11 @@

diff --git a/Layout/default/menu.php b/Layout/default/menu.php index 9ecd54144..2fbebd98f 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -7,6 +7,8 @@
  • ">Dashboard
  • + + is("Admin")): ?>
  • Stammdaten
    @@ -16,38 +18,39 @@
    ">Personen & Firmen
  • -
  • - ">Produkte - -
  • +
  • ">Produkte
  • +
  • ">Technologien
  • ">Benutzer
  • ">Netzgebiete
  • + + + is(["Admin","netowner","lineplanner","pipeplanner"])): ?>
  • Netzbau
  • + + is(["Admin","salespartner"])): ?>
  • - Verkauf
    + Verkauf
  • + diff --git a/Layout/default/topbar.php b/Layout/default/topbar.php index 275865e3c..098c11b7c 100644 --- a/Layout/default/topbar.php +++ b/Layout/default/topbar.php @@ -94,58 +94,22 @@ -
  • - username?> + username?> -
  • - +
  • + " class="nav-link nav-user"> + + Omöldn + +
  • diff --git a/application/Address/Address.php b/application/Address/Address.php index f8c91def7..0b738f244 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -2,8 +2,11 @@ class Address extends mfBaseModel { protected $forcestr = ['street','company','zip','phone','fax','mobile','note']; + private $parent; private $types; private $attributes; + private $permissions; + public function getFullName() { // Assumes "Firma1 Firma2" or "firstname lastname" as readable form @@ -28,17 +31,33 @@ class Address extends mfBaseModel { return $this->getFullName(); } - private function loadAddresstypes() { + + public function loadAddresstypes() { if(!$this->id) { return false; } - $this->types = AddresstypeModel::search(['address_id' => $this->id], true); + if(!$this->parent_id) { + $this->types = AddresstypeModel::search(['address_id' => $this->id], true); + } else { + // get types from parent + + $parent = $this->getProperty("parent"); + $types = $parent->getProperty("types"); + $this->types = $types; + } + + return true; + } public function getProperty($name) { if($this->$name == null) { + if(!$this->id) { + return null; + } + if($name == "types") { $this->loadAddresstypes(); return $this->types; @@ -55,6 +74,16 @@ class Address extends mfBaseModel { return $this->attributes; } + if($name == "permissions") { + $this->permissions = NetworkAddressModel::search(['address_id' => $this->id]); + return $permissions; + } + + if($name == "parent") { + $this->parent = new Address($this->parent_id); + return $this->parent; + } + $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 84bbce2b1..ac81a0b4d 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -95,10 +95,12 @@ class AddressModel { } } - $res = $db->select("Address", "*", "$where AND id NOT IN (".implode(",", $have).")"); - if($db->num_rows()) { - while($data = $db->fetch_object($res)) { - $items[] = new Address($data); + if(!array_key_exists("addresstype", $filter)) { + $res = $db->select("Address", "*", "$where AND id NOT IN (".implode(",", $have).")"); + if($db->num_rows()) { + while($data = $db->fetch_object($res)) { + $items[] = new Address($data); + } } } diff --git a/application/Building/BuildingController.php b/application/Building/BuildingController.php index 027d34f08..06bf633a7 100644 --- a/application/Building/BuildingController.php +++ b/application/Building/BuildingController.php @@ -9,7 +9,7 @@ class BuildingController extends mfBaseController { $this->me = $me; $this->layout()->set("me",$me); - if(!$me->isAdmin()) { + if(!$me->is(["Admin", "netowner", "pipeplanner"])) { $this->redirect("Dashboard"); } } @@ -21,12 +21,43 @@ class BuildingController extends mfBaseController { protected function addAction() { $this->layout()->setTemplate("Building/Form"); - $this->layout()->set("networks", NetworkModel::getAll()); + + if($this->me->isAdmin()) { + $this->layout()->set("networks", NetworkModel::getAll()); + $this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]])); // change to NetworkaddressModel + $this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]])); // change to NetworkaddressModel + } else { + $this->layout()->set("networks", $this->me->my_networks); + $pipeworkers = []; + $lineworkers = []; + foreach($this->me->my_networks as $network) { + //var_dump($network->addresstypes);exit; + if(is_array($network->addresstypes)) { + foreach($network->getTypeAddresses("pipeworker") as $address) { + if(!array_key_exists($address->id, $pipeworkers)) { + $pipeworkers[$address->id] = $address; + } + } + foreach($network->getTypeAddresses("lineworker") as $address) { + if(!array_key_exists($address->id, $lineworkers)) { + $lineworkers[$address->id] = $address; + } + } + } + } + + $this->layout()->set("pipeworkers", $pipeworkers); // change to NetworkaddressModel + $this->layout()->set("lineworkers", $lineworkers); // change to NetworkaddressModel + + + } + $this->layout()->set("types", BuildingtypeModel::getAll()); $this->layout()->set("statuses", BuildingstatusModel::getAll()); - $this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]])); - $this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]])); + $this->layout()->set("networksections", NetworksectionModel::getAll()); + + } protected function editAction() { @@ -71,7 +102,7 @@ class BuildingController extends mfBaseController { $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['status_id'] = ($r->status_id) ? $r->status_id : 1; $data['pipeworker_id'] = ($r->pipeworker_id) ? $r->pipeworker_id : null; $data['lineworker_id'] = ($r->lineworker_id) ? $r->lineworker_id : null; $data['networksection_id'] = ($r->networksection_id) ? $r->networksection_id : null; @@ -98,7 +129,6 @@ class BuildingController extends mfBaseController { } if($mode == "add") { - $data['status_id'] = 1; $data['create_by'] = 1; $building = BuildingModel::create($data); } else { @@ -141,7 +171,8 @@ class BuildingController extends mfBaseController { } // Anschlüsse anlegen - if($building->units > 0) { + + if(!$building->terminations && $building->units > 0) { for($i = 1; $i <= $building->units; $i++) { $data = []; $data['building_id'] = $building->id; diff --git a/application/Dashboard/DashboardController.php b/application/Dashboard/DashboardController.php index 72d65511e..e373f3c62 100644 --- a/application/Dashboard/DashboardController.php +++ b/application/Dashboard/DashboardController.php @@ -17,8 +17,11 @@ class DashboardController extends mfBaseController { protected function testAction() { - $b = new Building(7); + /*$b = new Building(7); var_dump($b->getNewObjectCode());exit; + */ + $address = AddressModel::getOne(5); + var_dump($address->types);exit; } } \ No newline at end of file diff --git a/application/Network/Network.php b/application/Network/Network.php index 286eb9130..1020975ab 100644 --- a/application/Network/Network.php +++ b/application/Network/Network.php @@ -7,6 +7,28 @@ class Network extends mfBaseModel { private $roles; private $sections; + + public function getTypeAddresses($search_type) { + if(!$this->id) { + return false; + } + $addresses = []; + + $addresstypes = $this->getProperty("addresstypes"); + //var_dump($addresstypes);exit; + foreach($addresstypes as $address_id => $atypes) { + //var_dump($atypes); + foreach($atypes as $atype) { + //var_dump($atype); + if($atype->type == $search_type && !array_key_exists($address_id, $addresses)) { + $addresses[$address_id] = new Address($address_id); + } + } + } + + return $addresses; + } + public function loadAddresstypes() { if(!$this->id) { return false; diff --git a/application/Network/NetworkController.php b/application/Network/NetworkController.php index abb1351f2..dee0b6e9a 100644 --- a/application/Network/NetworkController.php +++ b/application/Network/NetworkController.php @@ -9,7 +9,7 @@ class NetworkController extends mfBaseController { $this->me = $me; $this->layout()->set("me",$me); - if(!$me->isAdmin()) { + if(!$me->is(["Admin", "netowner", "pipeplanner"])) { $this->redirect("Dashboard"); } } diff --git a/application/Networksection/NetworksectionController.php b/application/Networksection/NetworksectionController.php index f9b01d812..4c450cd62 100644 --- a/application/Networksection/NetworksectionController.php +++ b/application/Networksection/NetworksectionController.php @@ -9,7 +9,7 @@ class NetworksectionController extends mfBaseController { $this->me = $me; $this->layout()->set("me",$me); - if(!$me->isAdmin()) { + if(!$me->is(["Admin", "netowner", "pipeplanner"])) { $this->redirect("Dashboard"); } } diff --git a/application/OrderProduct/OrderProductModel.php b/application/OrderProduct/OrderProductModel.php index b77ba55f6..76a0751d0 100644 --- a/application/OrderProduct/OrderProductModel.php +++ b/application/OrderProduct/OrderProductModel.php @@ -124,6 +124,13 @@ class OrderProductModel { } } + if(array_key_exists("termination_id", $filter)) { + $termination_id = $filter['termination_id']; + if(is_numeric($termination_id)) { + $where .= " AND termination_id=$termination_id"; + } + } + //var_dump($filter, $where);exit; return $where; } diff --git a/application/Pop/PopController.php b/application/Pop/PopController.php index 00e4e3c38..fa014c605 100644 --- a/application/Pop/PopController.php +++ b/application/Pop/PopController.php @@ -9,7 +9,7 @@ class PopController extends mfBaseController { $this->me = $me; $this->layout()->set("me",$me); - if(!$me->isAdmin()) { + if(!$me->is(["Admin", "netowner", "pipeplanner"])) { $this->redirect("Dashboard"); } } diff --git a/application/Product/ProductModel.php b/application/Product/ProductModel.php index e1dc9aee8..cc1f2a6f7 100644 --- a/application/Product/ProductModel.php +++ b/application/Product/ProductModel.php @@ -8,6 +8,7 @@ class ProductModel { public $productgroup_id = null; public $producttech_id = null; public $price = null; + public $price_setup = null; public $price_nne = null; public $price_nbe = null; public $billing_period = null; diff --git a/application/Termination/TerminationController.php b/application/Termination/TerminationController.php index e02b5294e..1a22d4e67 100644 --- a/application/Termination/TerminationController.php +++ b/application/Termination/TerminationController.php @@ -71,7 +71,7 @@ class TerminationController extends mfBaseController { protected function delete() { - if(!$this->me->is("Admin")) { + if(!$this->me->is(["Admin", "netowner", "pipeplanner"])) { $this->layout()->setFlash("Keine Berechtigung", "error"); $this->redirect("Building"); } @@ -91,6 +91,36 @@ class TerminationController extends mfBaseController { $building_id = $term->building_id; + // if user is not admin, check if they have permission for this network + if(!$this->me->is("Admin")) { + $allowed = false; + + $building = $term->building; + $network = $building->network; + foreach(["netowner", "pipeplanner"] as $type) { + $perms = $network->getTypeAddresses($type); + foreach($perms as $address_id => $perm) { + if($this->me->address_id != $address_id) { + continue; + } + $allowed = true; + } + } + + if(!$allowed) { + $this->layout()->setFlash("Keine Berechtigung", "error"); + $this->redirect("Building", "Index", [], "building=".$building_id); + } + } + + + // check for dependencies + if(OrderProductModel::search(["termination_id" => $id])) { + $this->layout()->setFlash("Anschluss kann nicht gelöscht werden, da abhängige Objekte gefunden wurden.", "error"); + $this->redirect("Building", "Index", [], "building=".$building_id); + } + + $term->delete(); $this->layout()->setFlash("Anschluss gelöscht", "success"); @@ -148,4 +178,4 @@ class TerminationController extends mfBaseController { return ["msg" => "Saved successfully"]; } -} \ No newline at end of file +} diff --git a/application/User/User.php b/application/User/User.php index 9510ecf4b..5f68ec505 100644 --- a/application/User/User.php +++ b/application/User/User.php @@ -9,6 +9,8 @@ class User extends mfBaseModel { public $permissions; public $flags; public $address; + + private $my_networks; public function init() { $this->table = "Worker"; @@ -77,12 +79,27 @@ class User extends mfBaseModel { if(!$this->id) { return false; } - if(is_object($this->permissions) && property_exists($this->permissions, "is$what")) { - return $this->permissions->{"is$what"}; + + if(!is_array($what)) { + $what = [$what]; } - if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) { - return ($this->address->types[$what]->id) ? true : false; + + foreach($what as $w) { + if(is_object($this->permissions) && property_exists($this->permissions, "is$w")) { + if($this->permissions->{"is$w"} === true) { + return true; + } + } + //var_dump($this->address->types);exit; + if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) { + if($this->address->types[$w]->id) { + return true; + } + } + } + + return false; } public function isAdmin() { @@ -96,4 +113,49 @@ class User extends mfBaseModel { public function __toString() { return $this->username; } + + + public function getProperty($name) { + if($this->$name == null) { + + if(!$this->id) { + return null; + } + + if($name == "my_networks") { + $this->my_networks = $this->getMyNetworks(); + return $this->my_networks; + } + + $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; + } + + + private function getMyNetworks() { + if(!$this->id) { + return false; + } + + $my_networks = []; + + $network_list = NetworkAddressModel::search(['address_id' => $this->address_id]); + foreach($network_list as $n) { + if(!array_key_exists($n->network_id, $my_networks)) { + $my_networks[$n->network_id] = new Network($n->network_id); + } + } + + return $my_networks; + } } diff --git a/application/User/UserController.php b/application/User/UserController.php index 9536d99da..acffbc5c9 100644 --- a/application/User/UserController.php +++ b/application/User/UserController.php @@ -49,6 +49,10 @@ class UserController extends mfBaseController { $addresses = AddressModel::getAll(); $this->layout()->set("addresses", $addresses); + + if($this->request->address_id) { + $this->layout()->set("address_id", $this->request->address_id); + } } protected function editAction($request) {