From b64172c2e9fd55914b22897b91bc848ac036c071 Mon Sep 17 00:00:00 2001 From: hexstudy Date: Mon, 11 Jan 2016 17:05:15 +0000 Subject: [PATCH] git-svn-id: https://msi/svn/firstRepo/Service/branches/Manut_2.2.3@44 0f545695-f87b-41b6-9a03-7f16563b5454 --- profile.php | 14 ++++++-- serviceapp.php | 1 + spacciatoripm.php | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 spacciatoripm.php diff --git a/profile.php b/profile.php index c910413..eb8d543 100644 --- a/profile.php +++ b/profile.php @@ -143,8 +143,18 @@ $app->put('/profile', function () use ($app) { $callbackFn = $app->request()->get('callback'); $json_data_body = json_decode($app->request()->post('dataPair')); $mysqlconnetion = new MysqlClass; - $query = "update profilo set RisultatiRicerca = '" . $json_data_body->risRic . "', TemaUI = '" . $json_data_body->tema . "' where ProfiloID = '" . $json_data_body->keyStore . "'"; - + $query = "update profilo set RisultatiRicerca = '" . $json_data_body->risRic . + "', TemaUI = '" . $json_data_body->tema . + "', Email = '" . $json_data_body->email . + "', bSpacciatore = " . $json_data_body->isSpacc . + ", bPrivacy = " . $json_data_body->privacy . + ", Cap = '" . $json_data_body->cap . + "', Comune = '" . $json_data_body->comune . + "', Provincia = '" . $json_data_body->prov . + "', TipoPM = " . $json_data_body->tipopm . + ", Latitudine = " . $json_data_body->lat . + ", Longitudine = " . $json_data_body->lng . + " where ProfiloID = '" . $json_data_body->keyStore . "'"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti(); diff --git a/serviceapp.php b/serviceapp.php index 0857f4b..cd1db2e 100644 --- a/serviceapp.php +++ b/serviceapp.php @@ -6,6 +6,7 @@ $app->group('/api', function () use ($app) { include "./ricette.php"; include "./profile.php"; include "./image.php"; + include "./spacciatoripm.php"; }); $app->group('/backend', function () use ($app) { diff --git a/spacciatoripm.php b/spacciatoripm.php new file mode 100644 index 0000000..f0267ef --- /dev/null +++ b/spacciatoripm.php @@ -0,0 +1,88 @@ +get('/spacciatori/kml', function () use ($app) { + $callbackFn = $app->request()->get('callback'); + $mysqlconnetion = new MysqlClass; + $query = "SELECT ProfiloID, Name, Email, CONCAT(Comune, ', ', Cap, ' - ', Provincia) as Indirizzo, Latitudine, Longitudine, TipoPM FROM `profilo` where bSpacciatore = 1"; + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + + // Creates the Document. + $dom = new DOMDocument('1.0', 'UTF-8'); + + // Creates the root KML element and appends it to the root document. + $node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); + $parNode = $dom->appendChild($node); + + // Creates a KML Document element and append it to the KML element. + $dnode = $dom->createElement('Document'); + $docNode = $parNode->appendChild($dnode); + + // Creates the two Style elements, one for restaurant and one for bar, and append the elements to the Document element. + $restStyleNode = $dom->createElement('Style'); + $restStyleNode->setAttribute('id', '1'); + $restIconstyleNode = $dom->createElement('IconStyle'); + $restIconstyleNode->setAttribute('id', 'restaurantIcon'); + $restIconNode = $dom->createElement('Icon'); + $restHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon63.png'); + $restIconNode->appendChild($restHref); + $restIconstyleNode->appendChild($restIconNode); + $restStyleNode->appendChild($restIconstyleNode); + $docNode->appendChild($restStyleNode); + + $barStyleNode = $dom->createElement('Style'); + $barStyleNode->setAttribute('id', '2'); + $barIconstyleNode = $dom->createElement('IconStyle'); + $barIconstyleNode->setAttribute('id', 'barIcon'); + $barIconNode = $dom->createElement('Icon'); + $barHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon27.png'); + $barIconNode->appendChild($barHref); + $barIconstyleNode->appendChild($barIconNode); + $barStyleNode->appendChild($barIconstyleNode); + $docNode->appendChild($barStyleNode); + + // Iterates through the MySQL results, creating one Placemark for each row. + foreach ($retObj as $row) + { + // Creates a Placemark and append it to the Document. + + $node = $dom->createElement('Placemark'); + $placeNode = $docNode->appendChild($node); + + // Creates an id attribute and assign it the value of id column. + $placeNode->setAttribute('id', 'placemark_' . $row['ProfiloID']); + + // Create name, and description elements and assigns them the values of the name and address columns from the results. + $nameNode = $dom->createElement('name',htmlentities($row['Name'])); + $placeNode->appendChild($nameNode); + $descNode = $dom->createElement('description', $row['Indirizzo'] . '
Contatta: ' . $row['Email']); + $placeNode->appendChild($descNode); + $styleUrl = $dom->createElement('styleUrl', '#' . $row['TipoPM']); + $placeNode->appendChild($styleUrl); + + // Creates a Point element. + $pointNode = $dom->createElement('Point'); + $placeNode->appendChild($pointNode); + + // Creates a coordinates element and gives it the value of the lng and lat columns from the results. + $coorStr = $row['Longitudine'] . ',' . $row['Latitudine']; + $coorNode = $dom->createElement('coordinates', $coorStr); + $pointNode->appendChild($coorNode); + } + + $kmlOutput = $dom->saveXML(); + header('Content-type: application/vnd.google-earth.kml+xml'); + echo $kmlOutput; +}); + +$app->get('/spacciatori/bound/:FromLat/:FromLng/:ToLat/:ToLng', function ($FromLat, $FromLng, $ToLat, $ToLng) use ($app) { + $callbackFn = $app->request()->get('callback'); + $mysqlconnetion = new MysqlClass; + $query = "SELECT Name, Email, CONCAT(Comune, ', ', Cap, ' - ', Provincia) as Indirizzo, Latitudine, Longitudine, TipoPM FROM `profilo` " . + "where bSpacciatore = 1 AND " . + "Latitudine BETWEEN " . $ToLat . " AND " . $FromLat . " AND ". + "Longitudine BETWEEN " . $ToLng . " AND " . $FromLng; + $retObj = $mysqlconnetion->queryToObject($query); + $mysqlconnetion->disconnetti(); + returnJson($app, $callbackFn, $retObj); +}); \ No newline at end of file