diff --git a/Layout/default/Building/Form.php b/Layout/default/Building/Form.php
index e571530f2..71d60af36 100644
--- a/Layout/default/Building/Form.php
+++ b/Layout/default/Building/Form.php
@@ -120,21 +120,21 @@
diff --git a/application/Building/Building.php b/application/Building/Building.php
index 957341547..5f81dfcba 100644
--- a/application/Building/Building.php
+++ b/application/Building/Building.php
@@ -1,7 +1,7 @@
type_id;
$data['status_id'] = ($r->status_id) ? $r->status_id : null;
$data['pipeworker_id'] = ($r->pipeworker_id) ? $r->pipeworker_id : null;
- $data['code'] = $r->code;
+
$data['oan_id'] = $r->oan_id;
$data['street'] = $r->street;
$data['zip'] = $r->zip;
$data['city'] = $r->city;
- $data['gps_lat'] = $r->gps_lat;
- $data['gps_long'] = $r->gps_long;
+
+
$data['contact'] = $r->contact;
$data['phone'] = $r->phone;
$data['email'] = $r->email;
@@ -86,6 +86,13 @@ class BuildingController extends mfBaseController {
$data['edit_by'] = 1;
+ if($this->me->is("Admin")) {
+ if($r->gps_lat) $data['gps_lat'] = $r->gps_lat;
+ if($r->gps_long) $data['gps_long'] = $r->gps_long;
+ if($r->code) $data['code'] = $r->code;
+ if($r->laea) $data['laea'] = $r->laea;
+ }
+
if($mode == "add") {
$data['status_id'] = 1;
$data['create_by'] = 1;
@@ -103,6 +110,22 @@ class BuildingController extends mfBaseController {
return $this->add();
}
+ // get GPS location
+ if(!$building->gps_lat && !$building->gps_long) {
+ $search = [
+ 'country' => "AT",
+ 'city' => $building->city,
+ 'zip' => $building->zip,
+ 'street' => $building->street
+ ];
+ $coords = Gmaps_Geocoding::getCoords($search);
+ if(is_array($coords) && count($coords) == 2) {
+ $building->gps_lat = str_replace(",",".",$coords[0]);
+ $building->gps_long = str_replace(",",".",$coords[1]);
+ $building->save();
+ }
+ }
+
// generate object code and LAEA coords
if(!$building->code) {
$building->code = $building->getNewObjectCode();
diff --git a/application/Dashboard/DashboardController.php b/application/Dashboard/DashboardController.php
index 00df0b36a..70c8b866d 100644
--- a/application/Dashboard/DashboardController.php
+++ b/application/Dashboard/DashboardController.php
@@ -13,4 +13,17 @@ class DashboardController extends mfBaseController {
protected function indexAction() {
}
+
+ protected function testAction() {
+ $search = [
+ 'street' => "Kastellfeldgasse 20",
+ 'zip' => "8010",
+ 'city' => "Graz",
+ 'country' => "AT"
+ ];
+
+ $coords = Gmaps_Geocoding::getCoords($search);
+ var_dump($coords);
+ exit;
+ }
}
\ No newline at end of file
diff --git a/lib/Gmaps/Geocoding.php b/lib/Gmaps/Geocoding.php
new file mode 100644
index 000000000..f9f47b005
--- /dev/null
+++ b/lib/Gmaps/Geocoding.php
@@ -0,0 +1,53 @@
+debug(__FILE__.": $url");
+
+ $resp = file_get_contents($url);
+ //print_r($resp);
+ if($resp) {
+ $json = json_decode($resp);
+ $results = $json->results;
+ if(count($results) > 1) {
+ $log->warn(__FILE__."> Got more then 1 result. Aborting.");
+ return false;
+ }
+ $lat = $results[0]->geometry->location->lat;
+ $long = $results[0]->geometry->location->lng;
+
+ return [$lat,$long];
+ } else {
+ return false;
+ }
+ }
+
+}