Can now save Network Roles
This commit is contained in:
@@ -65,7 +65,7 @@
|
||||
<ul class="nav nav-pills navtab-bg nav-justified">
|
||||
<li class="nav-item"><a class="nav-link active" href="#net-detail-<?=$network->id?>-detail" data-toggle="tab" aria-expanded="false">Details</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#net-detail-<?=$network->id?>-pops" data-toggle="tab" aria-expanded="false">POPs</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#net-detail-<?=$network->id?>-third" data-toggle="tab" aria-expanded="false">Berechtigungen</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#net-detail-<?=$network->id?>-roles" data-toggle="tab" aria-expanded="false">Berechtigungen</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div id="net-detail-<?=$network->id?>-detail" class="tab-pane show active">
|
||||
@@ -89,6 +89,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="net-detail-<?=$network->id?>-pops" class="tab-pane">
|
||||
<h4>POPs in <strong><?=$network->name?></strong></h4>
|
||||
<div class="card">
|
||||
@@ -121,48 +122,88 @@
|
||||
|
||||
<a class="btn btn-primary" href="<?=self::getUrl("Pop", "add", ['network_id' => $network->id])?>"><i class="fas fa-plus"></i> Neuen POP anlegen</a>
|
||||
</div>
|
||||
<div id="net-detail-<?=$network->id?>-third" class="tab-pane">
|
||||
|
||||
<div id="net-detail-<?=$network->id?>-roles" class="tab-pane">
|
||||
<h4>Berechtigungen</h4>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<?php if(is_array($network->addresstypes) && count($network->addresstypes)): ?>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<?php foreach(['netowner','salespartner','pipeworker','lineworker','pipeplanner','lineplanner','netoperator',] as $role): ?>
|
||||
<th><?=__($role)?></th>
|
||||
<?php endforeach ?>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($network->addresstypes as $address_id => $addresstypes): ?>
|
||||
<tr>
|
||||
<td><?=AddressModel::getOne($address_id)->getCompanyOrName()?></td>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<td>
|
||||
<?php if(AddresstypeModel::getFirst(['address_id' => $address_id, 'addresstype' => [$role]]) !== null): ?>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="role_<?=$role?>[<?=$address_id?>]"
|
||||
value="1"
|
||||
<?php foreach($addresstypes as $type): ?>
|
||||
<?php if($type->type == $role): ?>
|
||||
checked='checked'
|
||||
<?php continue; endif; ?>
|
||||
<?php endforeach; ?>
|
||||
/>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
<td class="controls" style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Pop", "edit", ["id" => $pop->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Pop", "delete", ["id" => $pop->id])?>" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<form class="form" method="post" action="<?=self::getUrl("NetworkAddress", "save")?>">
|
||||
<input type="hidden" name="network_id" value="<?=$network->id?>" />
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<th class="text-center"><?=__($role)?></th>
|
||||
<?php endforeach ?>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($network->addresstypes as $address_id => $addresstypes): ?>
|
||||
<tr>
|
||||
<td><?=AddressModel::getOne($address_id)->getCompanyOrName()?></td>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<td class="text-center">
|
||||
<?php if(AddresstypeModel::getFirst(['address_id' => $address_id, 'addresstype' => [$role]]) !== null): ?>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="roles[<?=$address_id?>][]"
|
||||
value="<?=$role?>"
|
||||
<?php foreach($addresstypes as $type): ?>
|
||||
<?php if($type->type == $role): ?>
|
||||
checked='checked'
|
||||
<?php continue; endif; ?>
|
||||
<?php endforeach; ?>
|
||||
/>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
<td class="controls" style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("NetworkAddress", "delete", ["id" => $address_id])?>" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<button type="submit" class="btn btn-primary"><i class="fas fa-check"></i> Speichern</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<p><i>Keine berechtigten Firmen/Personen vorhanden.</i></p>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<h4 class="mt-4">Neu</h4>
|
||||
<form class="form" method="post" action="<?=self::getUrl("NetworkAddress", "create")?>">
|
||||
<input type="hidden" name="network_id" value="<?=$network->id?>" />
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Person / Firma</th>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<th class="text-center"><?=__($role)?></th>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<select class="select2 form-control " name="address_id" id="address_id">
|
||||
<option></option>
|
||||
<?php foreach(AddressModel::search(["parents_only" => 1]) as $address): ?>
|
||||
<?php if(is_array($network->addresstypes) && array_key_exists($address->id, $network->addresstypes)) continue; ?>
|
||||
<option value="<?=$address->id?>"><?=($address->getCompanyOrName())?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<?php foreach(TT_NETWORK_ROLES as $role): ?>
|
||||
<td class="text-center">
|
||||
<input type="checkbox" name="roles[]" value="<?=$role?>" />
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<button type="submit" class="btn btn-primary" ><i class="fas fa-plus"></i> Person / Firma hinzufügen</button>
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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'];
|
||||
|
||||
@@ -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 = "";
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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;*/
|
||||
|
||||
103
application/NetworkAddress/NetworkAddressController.php
Normal file
103
application/NetworkAddress/NetworkAddressController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
class NetworkAddressController 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 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");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
11
contrib/migrations/20210701-networkaddress.sql
Normal file
11
contrib/migrations/20210701-networkaddress.sql
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user