diff --git a/application/Api/v1/PreorderselfserviceApicontroller.php b/application/Api/v1/PreorderselfserviceApicontroller.php new file mode 100644 index 000000000..681dbae68 --- /dev/null +++ b/application/Api/v1/PreorderselfserviceApicontroller.php @@ -0,0 +1,73 @@ +addRoute("/preorderselfservice/preorder", "getPreorder", "GET"); + } + + protected function authenticated() { + if($this->me->username != "preorder-selfservice-gui-api") { + return \mfResponse::Forbidden(); + } + } + + private function authUser() { + return true; + //return false; + } + protected function getPreorder() { + if(!$this->authUser()) { + return mfResponse::Forbidden(["status" => "403", "message" => "User authentication failed"]); + } + + $auth_email = trim($this->get["auth_email"]); + $auth_phone = trim($this->get["auth_phone"]); + + $search = []; + if($auth_email) { + $search = ["email" => $auth_email]; + } elseif($auth_phone) { + $phone_search = []; + $auth_phone = preg_replace('/[^0-9]+/', '', $auth_phone); + $phone_search[] = $auth_phone; + + if(substr($auth_phone, 0, 2) == "43") { + $phone_search[] = "+$auth_phone"; + $auth_phone = preg_replace('/^43/', '0', $auth_phone); + $phone_search[] = $auth_phone; + } + + if(substr($auth_phone, 0, 1) != "0") { + $phone_search[] = "0$auth_phone"; + } + $search = ["phone" => $phone_search]; + } + + if(!count($search)) { + return mfResponse::BadRequest(["message" => "auth method missing"]); + } + + $preorders = PreorderModel::searchActive($search); + + $result = []; + + foreach($preorders as $preorder) { + if(!$preorder->adb_hausnummer || !$preorder->adb_wohneinheit) continue; + + //$hausnummer = $preorder->adb_hausnummer; + //$wohneinheit = $preorder->adb_wohneinheit; + + $item = []; + + $item["preorder"] = $preorder->getApiArray(["full_home", "full_address"]); + //$item["building"] = $hausnummer->getApiArray(); + //$item["unit"] = $wohneinheit->getApiArray(); + + $result[] = $item; + } + + return mfResponse::Ok($result); + } + +} \ No newline at end of file diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 5819ee9f1..3cd2a2fcc 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -959,11 +959,14 @@ class Preorder extends mfBaseModel { } $include_full_home = false; + $include_full_address = false; if(in_array("full_home", $options)) { $include_full_home = true; } - + if(in_array("full_address", $options)) { + $include_full_address = true; + } $hausnummer = $this->getProperty("adb_hausnummer"); $wohneinheit = $this->getProperty("adb_wohneinheit"); @@ -1020,6 +1023,22 @@ class Preorder extends mfBaseModel { unset($address['municipality']); } + if($include_full_address) { + $address['gps_lat'] = $hausnummer->gps_lat; + $address['gps_long'] = $hausnummer->gps_long; + $address["borderpoint_lat"] = $hausnummer->borderpoint_lat; + $address["borderpoint_long"] = $hausnummer->borderpoint_long; + + $address["trenches"] = []; + $address["home_trench"] = []; + if($hausnummer->trenches) { + $address["trenches"] = json_decode($hausnummer->trenches); + } + if($hausnummer->home_trench) { + $address["home_trench"] = json_decode($hausnummer->home_trench); + } + } + if(!$include_full_home) { $address['block'] = ($wohneinheit->block) ? $wohneinheit->block : null; $address['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null; diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index 26bed9c25..1a97fbe11 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -670,6 +670,25 @@ class PreorderModel { $where .= " AND tt_preorder.extref = '$extref'"; } } + + if(array_key_exists("email", $filter)) { + $email = FronkDB::singleton()->escape($filter['email']); + if($email) { + $where .= " AND tt_preorder.email = '$email'"; + } + } + + if(array_key_exists("phone", $filter)) { + $phone = $filter["phone"]; + if(is_array($phone)) { + $where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') IN ('".implode("','", $phone)."')"; + } else { + $phone = FronkDB::singleton()->escape($filter['phone']); + if($phone) { + $where .= " AND REGEXP_REPLACE(tt_preorder.phone, '[^0-9]+', '') = '$phone'"; + } + } + } if(array_key_exists("workorder_export_date", $filter)) { $workorder_export_date = $filter['workorder_export_date'];