diff --git a/application/Address/Address.php b/application/Address/Address.php
index 806fa6983..1db2506d3 100644
--- a/application/Address/Address.php
+++ b/application/Address/Address.php
@@ -4,6 +4,7 @@ class Address extends mfBaseModel {
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
private $parent;
private $childaddresses;
+ private $links;
private $types;
private $attributes;
private $permissions;
@@ -128,6 +129,19 @@ class Address extends mfBaseModel {
return $spin;
}
+ public function deleteLinks() {
+ $links = $this->getProperty("links");
+ //var_dump($links);exit;
+ if(is_array($links) && count($links)) {
+ foreach($links as $type => $linktypes) {
+ //var_dump($type, $linktypes);exit;
+ foreach($linktypes as $link) {
+ //var_dump($link);exit;
+ $link->delete();
+ }
+ }
+ }
+ }
public function getProperty($name) {
if($this->$name == null) {
@@ -166,6 +180,30 @@ class Address extends mfBaseModel {
$this->childaddresses = AddressModel::search(['parent' => $this->id]);
return $this->childaddresses;
}
+ /*
+ if($name == "links_to") {
+ $links = AddressLinkModel::search(['address_id' => $this->id]);
+ foreach($links as $link) {
+ if(!array_key_exists($link->type, $this->links_to)) {
+ $this->links_to[$link->type] = [];
+ }
+ $this->links_to[$link->type][] = $link->linked_to;
+ }
+ return $this->links_to;
+ }*/
+
+ if($name == "links") {
+ $links = AddressLinkModel::search(['origin_address_id' => $this->id]);
+ //var_dump($links);exit;
+ foreach($links as $link) {
+ if(!array_key_exists($link->type, $this->links)) {
+ $this->links[$link->type] = [];
+ }
+ $this->links[$link->type][] = $link;
+ //var_dump($this->links);exit;
+ }
+ return $this->links;
+ }
$classname = ucfirst($name);
$idfield = $name."_id";
diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php
index 951afb2ec..affa50a93 100644
--- a/application/Address/AddressController.php
+++ b/application/Address/AddressController.php
@@ -104,7 +104,7 @@ class AddressController extends mfBaseController {
protected function saveAction() {
$r = $this->request;
$id = $r->id;
- //var_dump($r);exit;
+ //var_dump($r->get());exit;
if(is_numeric($id) && $id > 0) {
$mode = "edit";
$address = new Address($id);
@@ -228,6 +228,24 @@ class AddressController extends mfBaseController {
}
}
+
+ $address->deleteLinks();
+ //var_dump($r->links);exit;
+ if(is_array($r->links) && count($r->links)) {
+ //var_dump($r->links);exit;
+ foreach($r->links as $linknum => $link) {
+ if(!$link['type'] || !$link['address_id']) {
+ continue;
+ }
+ $l = AddressLinkModel::create([
+ 'origin_address_id' => $new_id,
+ 'type' => $link['type'],
+ 'address_id' => $link['address_id']
+ ]);
+ $l->save();
+ }
+ }
+
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
$this->redirect("Address", "Edit", ['id' => $new_id]);
}
@@ -287,6 +305,12 @@ class AddressController extends mfBaseController {
$role = "billing";
$po = 0;
}
+ if($this->request->role == "techcontact") {
+ $role = "techcontact";
+ $po = 0;
+ }
+
+ $this->log->debug(print_r($this->request->get(),true));
$addresses = [];
diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php
index 60fd32f74..079ab5609 100644
--- a/application/Address/AddressModel.php
+++ b/application/Address/AddressModel.php
@@ -66,7 +66,7 @@ class AddressModel {
$res = $db->select("Address", "*", "$where ORDER BY company, lastname, firstname, zip, city LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
- $item = new Voicenumber($data);
+ $item = new Address($data);
if($item->id) {
return $item;
} else {
diff --git a/application/AddressLink/AddressLink.php b/application/AddressLink/AddressLink.php
new file mode 100644
index 000000000..97c29b8bb
--- /dev/null
+++ b/application/AddressLink/AddressLink.php
@@ -0,0 +1,32 @@
+$name == null) {
+
+ if(!$this->id) {
+ return null;
+ }
+
+ if($name == "origin") {
+ $this->origin = new Address($this->origin_address_id);
+ return $this->origin;
+ }
+
+ $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/AddressLink/AddressLinkModel.php b/application/AddressLink/AddressLinkModel.php
new file mode 100644
index 000000000..a91f55612
--- /dev/null
+++ b/application/AddressLink/AddressLinkModel.php
@@ -0,0 +1,131 @@
+ $value) {
+ if(property_exists(get_called_class(), $field)) {
+ $model->$field = $value;
+ }
+ }
+
+ $me = new User();
+ $me->loadMe();
+
+ if(!is_numeric($model->create_by) && !$model->create_by) {
+ $model->create_by = $me->id;
+ }
+ if(!is_numeric($model->edit_by) && !$model->edit_by) {
+ $model->edit_by = $me->id;
+ }
+
+ return $model;
+ }
+
+ public static function getFirst($filter = null) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("AddressLink", "*", "$where ORDER BY address_id,`create`,origin_address_idLIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new AddressLink($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function getAll() {
+ $items = [];
+
+ $db = FronkDB::singleton();
+
+ $res = $db->select("AddressLink", "*", "1=1 ORDER BY address_id,`create`,origin_address_id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new AddressLink($data);
+ }
+ }
+ return $items;
+
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("AddressLink", "COUNT(*) as cnt", "$where");
+
+ //$res = $db->query($sql);
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ return $data->cnt;
+ }
+ return 0;
+ }
+
+
+ public static function search($filter, $limit = false) {
+ $items = [];
+ $db = FronkDB::singleton();
+
+ $where = self::getSqlFilter($filter);
+
+ $sql = "SELECT * FROM AddressLink WHERE $where ORDER BY address_id,`create`,origin_address_id";
+
+ if(is_array($limit) && count($limit)) {
+ if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
+ $sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
+ } elseif(is_numeric($count)) {
+ $sql .= " LIMIT ".$limit['count'];
+ }
+ }
+
+ mfLoghandler::singleton()->debug($sql);
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new AddressLink($data);
+ }
+ }
+
+ return $items;
+ }
+
+ private function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ //var_dump($filter);exit;
+ if(array_key_exists("address_id", $filter)) {
+ $address_id = $filter["address_id"];
+ if(is_numeric($address_id)) {
+ $where .= " AND address_id=$address_id";
+ }
+ }
+
+ if(array_key_exists("origin_address_id", $filter)) {
+ $origin_address_id = $filter["origin_address_id"];
+ if(is_numeric($origin_address_id)) {
+ $where .= " AND origin_address_id=$origin_address_id";
+ }
+ }
+
+ return $where;
+ }
+
+}
\ No newline at end of file