diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php
index 426240230..e9ec5e2d1 100644
--- a/Layout/default/Address/Index.php
+++ b/Layout/default/Address/Index.php
@@ -75,7 +75,7 @@
diff --git a/Layout/default/Producttech/Form.php b/Layout/default/Producttech/Form.php
new file mode 100644
index 000000000..7d507d2b5
--- /dev/null
+++ b/Layout/default/Producttech/Form.php
@@ -0,0 +1,235 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Layout/default/Producttech/Index.php b/Layout/default/Producttech/Index.php
new file mode 100644
index 000000000..084878958
--- /dev/null
+++ b/Layout/default/Producttech/Index.php
@@ -0,0 +1,62 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Layout/default/menu.php b/Layout/default/menu.php
index 6a3a6f52d..9711f6385 100644
--- a/Layout/default/menu.php
+++ b/Layout/default/menu.php
@@ -20,9 +20,14 @@
["addresstype" => ["supplier"]]])?>">Lieferanten
+
">Benutzer
">Netzgebiete
-
">Produkte
diff --git a/application/Product/Product.php b/application/Product/Product.php
index 300e9d1f6..13259d899 100644
--- a/application/Product/Product.php
+++ b/application/Product/Product.php
@@ -5,6 +5,36 @@ class Product extends mfBaseModel {
private $producttech;
private $sla;
private $networks;
+ private $attributes;
+
+ public function loadAttributes() {
+ if(!$this->producttech_id) {
+ return false;
+ }
+
+ $this->attributes = [];
+
+ // get tech attribs
+ $ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]);
+ // fill atrribs with existing values of product attribs
+ foreach($ptattribs as $pta) {
+ $attrib = ProductAttributeModel::getFirst(['product_id' => $this->id, 'producttechattribute_id' => $pta->id]);
+ if(!$attrib) {
+ $attrib = new ProductAttribute();
+ $attrib->product_id = $this->id;
+ $attrib->producttechattribute_id = $pta->id;
+ $attrib->value = $pta->value;
+ $attrib->note = $pta->note;
+ }
+ $attrib->name = $pta->name;
+ $attrib->displayname = $pta->displayname;
+ $attrib->description = $pta->description;
+ $this->attributes[$attrib->name] = $attrib;
+ }
+
+ return true;
+
+ }
public function getProperty($name) {
if($this->$name == null) {
@@ -18,7 +48,10 @@ class Product extends mfBaseModel {
return $this->networks;
}
-
+ if($name == "attributes") {
+ $this->loadAttributes();
+ return $this->attributes;
+ }
$classname = ucfirst($name);
$idfield = $name."_id";
diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php
index d54186f6d..ad037b85d 100644
--- a/application/Product/ProductController.php
+++ b/application/Product/ProductController.php
@@ -35,6 +35,8 @@ class ProductController extends mfBaseController {
$this->redirect("Product");
}
+ //var_dump($product->attributes);exit;
+
$this->layout()->set("product", $product);
return $this->addAction();
@@ -49,7 +51,7 @@ class ProductController extends mfBaseController {
$product = new Product($id);
if(!$product->id) {
$this->layout()->setFlash("Produkt nicht gefunden", "error");
- $this->redirect("Produkt");
+ $this->redirect("Product");
}
} else {
$id = false;
@@ -79,10 +81,10 @@ class ProductController extends mfBaseController {
$data['productgroup_id'] = null;
}
- $data['edit_by'] = 1;
+ $data['edit_by'] = $this->me->id;
if($mode == "add") {
- $data['create_by'] = 1;
+ $data['create_by'] = $this->me->id;
$product = ProductModel::create($data);
} else {
$product->update($data);
@@ -141,6 +143,22 @@ class ProductController extends mfBaseController {
$product->save();
}
+ if(is_array($r->attributes) && count($r->attributes)) {
+ foreach($r->attributes as $pta_id => $attribute_value) {
+ $attrib = ProductAttributeModel::getFirst(['product_id' => $new_id, 'producttechattribute_id' => $pta_id]);
+ if(!$attrib) {
+ $attrib = ProductAttributeModel::create([
+ 'product_id' => $new_id,
+ 'producttechattribute_id' => $pta_id,
+ ]);
+ //var_dump($attrib);exit;
+ }
+ $attrib->value = $attribute_value;
+ $attrib->edit_by = $this->me->id;
+ $attrib->save();
+ }
+ }
+
$this->layout()->setFlash("Produkt erfolgreich gespeichert.", "success");
$this->redirect("Product", "Edit", ['id' => $new_id]);
}
diff --git a/application/Product/ProductModel.php b/application/Product/ProductModel.php
index 9bcb88580..e1dc9aee8 100644
--- a/application/Product/ProductModel.php
+++ b/application/Product/ProductModel.php
@@ -94,7 +94,7 @@ class ProductModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
- $res = $db->select("Product", "*", "$where ORDER BY name, owner_id");
+ $res = $db->select("Product", "*", "$where ORDER BY producttech_id, name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Product($data);
diff --git a/application/ProductAttribute/ProductAttribute.php b/application/ProductAttribute/ProductAttribute.php
new file mode 100644
index 000000000..f9ce6a4a0
--- /dev/null
+++ b/application/ProductAttribute/ProductAttribute.php
@@ -0,0 +1,33 @@
+$name == null) {
+
+ if($name == "networks") {
+ $this->networks = [];
+ $productNetworks = ProductNetworkModel::search(['product_id' => $this->id]);
+ foreach($productNetworks as $pnet) {
+ $this->networks[$pnet->network_id] = new Network($pnet->network_id);
+ }
+ return $this->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;
+ }
+}
\ No newline at end of file
diff --git a/application/ProductAttribute/ProductAttributeController.php b/application/ProductAttribute/ProductAttributeController.php
new file mode 100644
index 000000000..cbcc0ddd1
--- /dev/null
+++ b/application/ProductAttribute/ProductAttributeController.php
@@ -0,0 +1,18 @@
+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
diff --git a/application/ProductAttribute/ProductAttributeModel.php b/application/ProductAttribute/ProductAttributeModel.php
new file mode 100644
index 000000000..959483f61
--- /dev/null
+++ b/application/ProductAttribute/ProductAttributeModel.php
@@ -0,0 +1,121 @@
+ $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("ProductAttribute", "*", "id=$id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ProductAttribute($data);
+ }
+ return $item;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("ProductAttribute", "*", "1 = 1 ORDER BY product_id, producttechattribute_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new ProductAttribute($data);
+ }
+ }
+ return $items;
+
+ }
+
+ public static function getFirst($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("ProductAttribute", "*", "$where ORDER BY product_id, producttechattribute_id");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ProductAttribute($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("ProductAttribute", "*", "$where ORDER BY name");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new ProductAttribute($data);
+ }
+ }
+ return $items;
+ }
+
+ private function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ $db = FronkDB::singleton();
+
+ if(array_key_exists("product_id", $filter)) {
+ $product_id = $filter['product_id'];
+ if(is_numeric($product_id)) {
+ $where .= " AND `product_id` = $product_id";
+ }
+ }
+
+ if(array_key_exists("producttechattribute_id", $filter)) {
+ $producttechattribute_id = $filter['producttechattribute_id'];
+ if(is_numeric($producttechattribute_id)) {
+ $where .= " AND `producttechattribute_id` = $producttechattribute_id";
+ }
+ }
+
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
\ No newline at end of file
diff --git a/application/Producttech/Producttech.php b/application/Producttech/Producttech.php
index 3ba28e7e0..11d0ca7f5 100644
--- a/application/Producttech/Producttech.php
+++ b/application/Producttech/Producttech.php
@@ -1,5 +1,32 @@
$name == null) {
+
+ if($name == "attributes") {
+ $this->attributes = [];
+ $producttechAttributes = ProducttechAttributeModel::search(['producttech_id' => $this->id]);
+ foreach($producttechAttributes as $pta) {
+ $this->attributes[$pta->id] = $pta;
+ }
+ return $this->attributes;
+ }
+
+
+ $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/Producttech/ProducttechController.php b/application/Producttech/ProducttechController.php
new file mode 100644
index 000000000..48b27ade9
--- /dev/null
+++ b/application/Producttech/ProducttechController.php
@@ -0,0 +1,133 @@
+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("Producttech/Index");
+ $this->layout()->set("producttechs", ProducttechModel::getAll());
+ }
+
+ protected function addAction() {
+ $this->layout()->setTemplate("Producttech/Form");
+
+ }
+
+ protected function editAction() {
+ $tech_id = $this->request->id;
+ $tech = new Producttech($tech_id);
+ if(!$tech->id) {
+ $this->layout()->setFlash("Technologie nicht gefunden.", "error");
+ $this->redirect("Producttech");
+ }
+
+ $this->layout()->set("producttech", $tech);
+ return $this->addAction();
+ }
+
+ protected function saveAction() {
+ $r = $this->request;
+ //var_dump($r);
+ //var_dump($r->attributes);
+ //exit;
+ $id = $r->id;
+ if(is_numeric($id) && $id > 0) {
+ $mode = "edit";
+ $producttech = new Producttech($id);
+ if(!$producttech->id) {
+ $this->layout()->setFlash("Technologie nicht gefunden", "error");
+ $this->redirect("Producttech");
+ }
+ } else {
+ $id = false;
+ $mode = "add";
+ }
+
+ $data = [];
+ $data['name'] = $r->name;
+ $data['customer_type'] = $r->customer_type;
+ $data['description'] = $r->description;
+ $data['note'] = $r->note;
+
+ $data['edit_by'] = $this->me->id;
+
+ if($mode == "add") {
+ $data['create_by'] = $this->me->id;
+ $producttech = ProducttechModel::create($data);
+ } else {
+ $producttech->update($data);
+ }
+
+ //var_dump($address);exit;
+
+ $new_id = $producttech->save();
+ if(!$new_id) {
+ $this->layout()->setFlash("Fehler beim Speichern", "error");
+ $this->layout()->set("producttech", $producttech);
+ return $this->add();
+ }
+
+ // handle ProductAttributes
+ if(is_array($r->attributes) && count($r->attributes)) {
+ foreach($r->attributes as $aid => $attribute) {
+ if(!trim($attribute['name']) || !trim($attribute['displayname'])) {
+ continue;
+ }
+
+ $a = [];
+ $a['name'] = $attribute['name'];
+ $a['producttech_id'] = $new_id;
+ $a['displayname'] = $attribute['displayname'];
+ $a['value'] = $attribute['value'];
+ $a['description'] = $attribute['description'];
+ $a['note'] = $attribute['note'];
+ $a['edit_by'] = $this->me->id;
+
+ if($aid == "new") {
+ $attrib = ProducttechAttributeModel::create($a);
+ } elseif(is_numeric($aid) && $aid > 0) {
+ $attrib = new ProducttechAttribute($aid);
+ $attrib->update($a);
+ } else {
+ continue;
+ }
+
+ $attrib->save();
+ }
+ }
+
+ $this->layout()->setFlash("Technologie erfolgreich gespeichert.", "success");
+ $this->redirect("Producttech", "edit", ['id' => $new_id]);
+
+ }
+
+ protected function delete() {
+ $id = $this->request->id;
+
+ $tech = new Producttech($id);
+ if(!$tech->id || $tech->id != $id) {
+ $this->layout()->setFlash("Technologie nicht gefunden.", "error");
+ $this->redirect("Producttech");
+ }
+
+ if(ProductModel::search(["producttech_id" => $tech->id])) {
+ $this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error");
+ $this->redirect("Producttech");
+ }
+
+ // check if Product is unused
+ $tech->delete();
+ $this->redirect("Producttech");
+ }
+}
\ No newline at end of file
diff --git a/application/ProducttechAttribute/ProducttechAttribute.php b/application/ProducttechAttribute/ProducttechAttribute.php
new file mode 100644
index 000000000..a5dafef73
--- /dev/null
+++ b/application/ProducttechAttribute/ProducttechAttribute.php
@@ -0,0 +1,23 @@
+$name == 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/ProducttechAttribute/ProducttechAttributeController.php b/application/ProducttechAttribute/ProducttechAttributeController.php
new file mode 100644
index 000000000..664540506
--- /dev/null
+++ b/application/ProducttechAttribute/ProducttechAttributeController.php
@@ -0,0 +1,37 @@
+needlogin=true;
+ $me = new User();
+ $me->loadMe();
+ $this->me = $me;
+ $this->layout()->set("me",$me);
+ /*
+ if(!$me->isAdmin()) {
+ $this->redirect("Dashboard");
+ }*/
+ }
+
+ protected function deleteAction() {
+ $id = $this->request->id;
+
+ $ta = new ProducttechAttribute($id);
+ if(!$ta->id || $ta->id != $id) {
+ $this->layout()->setFlash("Attribut nicht gefunden.", "error");
+ $this->redirect("Producttech");
+ }
+
+ /*if(ProductModel::search(["producttech_id" => $tech->id])) {
+ $this->layout()->setFlash("Technologie kann nicht gelöscht werden, da sie in Verwendung ist.", "error");
+ $this->redirect("Producttech");
+ }*/
+
+ $producttech_id = $ta->producttech_id;
+
+ // check if Product is unused
+ $ta->delete();
+ $this->redirect("Producttech", "edit", ['id' => $producttech_id]);
+ }
+}
\ No newline at end of file
diff --git a/application/ProducttechAttribute/ProducttechAttributeModel.php b/application/ProducttechAttribute/ProducttechAttributeModel.php
new file mode 100644
index 000000000..cf98a9c10
--- /dev/null
+++ b/application/ProducttechAttribute/ProducttechAttributeModel.php
@@ -0,0 +1,132 @@
+ $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("ProducttechAttribute", "*", "id=$id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ProducttechAttribute($data);
+ }
+ return $item;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("ProducttechAttribute", "*", "1 = 1 ORDER BY name");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new ProducttechAttribute($data);
+ }
+ }
+ return $items;
+
+ }
+
+ public static function getFirst() {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("ProducttechAttribute", "*", "$where ORDER BY name");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new ProducttechAttribute($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("ProducttechAttribute", "*", "$where ORDER BY name");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[$data->id] = new ProducttechAttribute($data);
+ }
+ }
+ return $items;
+ }
+
+ private function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ $db = FronkDB::singleton();
+
+ //var_dump($filter);exit;
+ if(array_key_exists("name", $filter)) {
+ $name = $db->escape($filter['name']);
+ if($name) {
+ $where .= " AND `name` like '$name'";
+ }
+ }
+
+ if(array_key_exists("nameLike", $filter)) {
+ $name = $db->escape($filter['nameLike']);
+ if($name) {
+ $where .= " AND `name` like '%$name%'";
+ }
+ }
+
+ if(array_key_exists("producttech_id", $filter)) {
+ $producttech_id = $db->escape($filter['producttech_id']);
+ if(is_numeric($producttech_id)) {
+ $where .= " AND `producttech_id` = $producttech_id";
+ }
+ }
+
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
\ No newline at end of file