+
+
Berechtigungen
addresstypes) && count($network->addresstypes)): ?>
-
+
Keine berechtigten Firmen/Personen vorhanden.
+
+
+
Neu
+
diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php
index 7ac2e2fba..f73341827 100644
--- a/application/Address/AddressModel.php
+++ b/application/Address/AddressModel.php
@@ -29,6 +29,16 @@ class AddressModel {
}
}
+ $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;
}
@@ -90,47 +100,10 @@ class AddressModel {
if(is_array($filter['addresstype']) && count($filter['addresstype'])) {
$at = $filter['addresstype'];
$in = [];
- 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("pipeplanner", $at)) {
- $in[] = "Addresstype.type = 'pipeplanner'";
- }
- if(in_array("lineplanner", $at)) {
- $in[] = "Addresstype.type = 'lineplanner'";
- }
- 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'";
- }
- if(in_array("customer", $at)) {
- $in[] = "Addresstype.type = 'customer'";
- }
- if(in_array("supplier", $at)) {
- $in[] = "Addresstype.type = 'supplier'";
- }
- if(in_array("contact", $at)) {
- $in[] = "Addresstype.type = 'contact'";
+ foreach(TT_ROLES as $role) {
+ if(in_array($role, $at)) {
+ $in[] = "Addresstype.type = '$role'";
+ }
}
$or = "";
@@ -139,6 +112,7 @@ class AddressModel {
$where .= " AND ( $or )";
}
}
+
//var_dump($filter);exit;
if(array_key_exists("parent_id", $filter)) {
$parentid = $filter['parent_id'];
diff --git a/application/Addresstype/AddresstypeModel.php b/application/Addresstype/AddresstypeModel.php
index 1bcb1bdf0..311bbbc19 100644
--- a/application/Addresstype/AddresstypeModel.php
+++ b/application/Addresstype/AddresstypeModel.php
@@ -67,13 +67,12 @@ class AddresstypeModel {
public static function getFirst($filter) {
$db = FronkDB::singleton();
- $log = mfLoghandler::singleton();
- $log->debug(print_r($filter,true));
+
$where = self::getSqlFilter($filter);
$sql = "SELECT Addresstype.* FROM Addresstype
WHERE $where
ORDER BY address_id ASC, `primary` DESC, type ASC";
- $log->debug($sql);
+
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
@@ -118,47 +117,10 @@ class AddresstypeModel {
if(is_array($filter['addresstype']) && count($filter['addresstype'])) {
$at = $filter['addresstype'];
$in = [];
- 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 = 'salespartner'";
- }
- if(in_array("pipeworker", $at)) {
- $in[] = "Addresstype.type = 'pipeworker'";
- }
- if(in_array("lineworker", $at)) {
- $in[] = "Addresstype.type = 'lineworker'";
- }
- if(in_array("pipeplanner", $at)) {
- $in[] = "Addresstype.type = 'pipeplanner'";
- }
- if(in_array("lineplanner", $at)) {
- $in[] = "Addresstype.type = 'lineplanner'";
- }
- 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'";
- }
- if(in_array("customer", $at)) {
- $in[] = "Addresstype.type = 'customer'";
- }
- if(in_array("supplier", $at)) {
- $in[] = "Addresstype.type = 'supplier'";
- }
- if(in_array("contact", $at)) {
- $in[] = "Addresstype.type = 'contact'";
+ foreach(TT_ROLES as $role) {
+ if(in_array($role, $at)) {
+ $in[] = "Addresstype.type = '$role'";
+ }
}
$or = "";
diff --git a/application/Network/Network.php b/application/Network/Network.php
index 18b93f423..b39160015 100644
--- a/application/Network/Network.php
+++ b/application/Network/Network.php
@@ -22,18 +22,6 @@ class Network extends mfBaseModel {
//var_dump($this->addresstypes);exit;
}
- public function loadRoles() {
- if(!$this->id) {
- return false;
- }
-
- $types = AddresstypeModel::search(['addresstype' => TT_NETWORK_ROLES]);
- var_dump($types);exit;
- foreach($types as $type) {
-
- }
- }
-
public function getProperty($name) {
if($this->$name == null) {
diff --git a/application/Network/NetworkController.php b/application/Network/NetworkController.php
index c924590b8..2a1705e03 100644
--- a/application/Network/NetworkController.php
+++ b/application/Network/NetworkController.php
@@ -18,6 +18,8 @@ class NetworkController extends mfBaseController {
$this->layout()->set("owners", AddressModel::search(['addresstype' => ["netowner"]]));
$this->layout()->set("networks", NetworkModel::getAll());
+
+
/*$net = new Network(1);
$at = $net->addresstypes; //[1]->addresstype->address;
var_dump($at);exit;*/
diff --git a/application/NetworkAddress/NetworkAddressController.php b/application/NetworkAddress/NetworkAddressController.php
new file mode 100644
index 000000000..1a795b616
--- /dev/null
+++ b/application/NetworkAddress/NetworkAddressController.php
@@ -0,0 +1,103 @@
+needlogin=true;
+ $me = new User();
+ $me->loadMe();
+ $this->me = $me;
+ $this->layout()->set("me",$me);
+ /*
+ if(!$me->isAdmin()) {
+ $this->redirect("Dashboard");
+ }*/
+ }
+
+ protected function saveAction() {
+ $r = $this->request;
+
+ if(!is_array($r->roles)) {
+ $this->redirect("Network");
+ }
+ if(!$r->network_id) {
+ $this->redirect("Network");
+ }
+ $network_id = $r->network_id;
+
+ $network = new Network($network_id);
+ if(!$network->id) {
+ $this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
+ $this->redirect("Network");
+ }
+
+ foreach($r->roles as $address_id => $new_roles) {
+
+ $address = new Address($address_id);
+ if(!$address->id) {
+ $this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
+ $this->redirect("Network");
+ }
+
+ foreach(TT_NETWORK_ROLES as $rolestring) {
+ if(in_array($rolestring, $new_roles)) {
+ // check if role exists
+ if(NetworkAddressModel::search(['network_id' => $network, 'address_id' => $address_id, 'addresstype' => [$rolestring]])) {
+ continue; // role exists
+ } else {
+ $na = NetworkAddressModel::create(['network_id' => $network_id, 'address_id' => $address_id, 'type' => $rolestring]);
+ $na->save();
+ }
+ // role does not exist, create it
+ } else {
+ // not in new_roles, delete (if exists)
+ $na = NetworkAddressModel::getFirst(['network_id' => $network, 'address_id' => $address_id, 'addresstype' => [$rolestring]]);
+ if($na) {
+ $na->delete();
+ }
+ }
+
+ }
+ }
+ $this->redirect("Network");
+ }
+
+ protected function createAction() {
+ //var_dump($this->request);
+ //var_dump($r->roles);exit;
+
+ $r = $this->request;
+ //var_dump($r->roles);exit;
+ if(!is_array($r->roles)) {
+ $this->redirect("Network");
+ }
+ if(!$r->network_id) {
+ $this->redirect("Network");
+ }
+ $network_id = $r->network_id;
+ $network = new Network($network_id);
+ if(!$network->id) {
+ $this->log->info("Netzgebiet nicht gefunden (".$network_id.")");
+ $this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
+ $this->redirect("Network");
+ }
+
+ if(!$r->address_id) {
+ $this->redirect("Network");
+ }
+ $address_id = $r->address_id;
+ $address = new Address($address_id);
+ if(!$address->id) {
+ $this->log->info("Person/Firma nicht gefunden (".$address_id.")");
+ $this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
+ $this->redirect("Network");
+ }
+
+ foreach($r->roles as $type) {
+ $na = NetworkAddressModel::create(['network_id' => $network_id, 'address_id' => $address_id, 'type' => $type]);
+ $na->save();
+ }
+
+ $this->redirect("Network");
+ }
+}
\ No newline at end of file
diff --git a/application/NetworkAddress/NetworkAddressModel.php b/application/NetworkAddress/NetworkAddressModel.php
index 262b05228..b39c5b049 100644
--- a/application/NetworkAddress/NetworkAddressModel.php
+++ b/application/NetworkAddress/NetworkAddressModel.php
@@ -19,6 +19,16 @@ class NetworkAddressModel {
}
}
+ $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;
}
@@ -85,7 +95,8 @@ class NetworkAddressModel {
private function getSqlFilter($filter) {
$where = "1=1 ";
-
+ $db = FronkDB::singleton();
+
//var_dump($filter);exit;
if(array_key_exists("network_id", $filter)) {
$network_id = $filter['network_id'];
@@ -101,6 +112,22 @@ class NetworkAddressModel {
}
}
+ if(is_array($filter['addresstype']) && count($filter['addresstype'])) {
+ $at = $filter['addresstype'];
+ $in = [];
+ foreach(TT_ROLES as $role) {
+ if(in_array($role, $at)) {
+ $in[] = "NetworkAddress.type = '$role'";
+ }
+ }
+
+ $or = "";
+ if(count($in)) {
+ $or = implode(" OR ", $in);
+ $where .= " AND ( $or )";
+ }
+ }
+
//var_dump($filter, $where);exit;
return $where;
}
diff --git a/contrib/migrations/20210701-networkaddress.sql b/contrib/migrations/20210701-networkaddress.sql
new file mode 100644
index 000000000..fc5f8b060
--- /dev/null
+++ b/contrib/migrations/20210701-networkaddress.sql
@@ -0,0 +1,11 @@
+CREATE TABLE `NetworkAddress` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `network_id` int(11) NOT NULL,
+ `address_id` int(11) NOT NULL,
+ `type` varchar(64) COLLATE utf8mb4_unicode_520_ci NOT NULL,
+ `create_by` int(11) NOT NULL,
+ `edit_by` int(11) NOT NULL,
+ `create` int(10) NOT NULL,
+ `edit` int(10) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci