From ec443db99907d1492411b68a3003846484ba910d Mon Sep 17 00:00:00 2001 From: Rick Hays Date: Wed, 25 Sep 2019 21:07:14 -0500 Subject: [PATCH] Finish project. Please read the readme. Signed-off-by: Rick Hays --- RX.php | 103 ++++++++++++++++++++++++++++++++++++++++ classes/geocode.php | 35 ++++++++++++++ css/system-min.css | 2 +- css/system.css | 7 ++- db/RX.db | Bin 0 -> 8192 bytes index.php => index.html | 12 ++--- js/system.js | 27 +++++++++-- scss/system.scss | 12 ++++- 8 files changed, 183 insertions(+), 15 deletions(-) create mode 100644 RX.php create mode 100644 classes/geocode.php create mode 100644 db/RX.db rename index.php => index.html (90%) diff --git a/RX.php b/RX.php new file mode 100644 index 0000000..077697b --- /dev/null +++ b/RX.php @@ -0,0 +1,103 @@ +query('SELECT rowid,* FROM pharmacies'); + foreach ($result as $row) { + $distance = $geo->straight_line_distance($Lat, $Lon, $row['Latitude'], $row['Longitude'], 'N'); + if ($distance < $shortest) + { + $pharmacy = $row['Pharmacy']; + $address = $row['Address']; + $city = $row['City']; + $state = $row['State']; + $zip = $row['Zip']; + $latitude = $row['Latitude']; + $longitude = $row['Longitude']; + $shortest = $distance; + } + } + $db = NULL; + } + catch(PDOException $e) + { + echo 'PDO Exception: ' . $e-> getMessage(); + exit; + } + break; +// case 'POST': +// break; +// case 'PUT': +// break; +// case 'DELETE': +// break; + default: + // Invalid Request Method + header("HTTP/1.0 405 Method Not Allowed"); + exit; + } + + // Output JSON back to HTML file. + echo 'Closest Pharmacy To you is:

'; + echo $pharmacy . '
'; + echo $address . '
'; + echo $city . '
'; + echo $state . '
'; + echo $zip . '
'; + echo '
'; +// echo $latitude . '
'; +// echo $longitude . '
'; + echo 'Distance of - ' . round($shortest, 1) . ' mile(s) away.
'; + exit; + +// ##### END OF PROGRAM ################################################################################################ + + /** + * GetParam - Returns the GET or POST values, and allows for defaults if not present. + * @param $param_name + * @param null $default + * + * @return string|null + */ + function GetParam($param_name, $default=NULL) + { + global $_POST; + global $_GET; + $param_value = ""; + + if(isset($_POST[$param_name])) + $param_value = $_POST[$param_name]; + else if(isset($_GET[$param_name])) + $param_value = $_GET[$param_name]; + else if($param_value === '') + $param_value = $default; + + return $param_value; + } diff --git a/classes/geocode.php b/classes/geocode.php new file mode 100644 index 0000000..d864fbb --- /dev/null +++ b/classes/geocode.php @@ -0,0 +1,35 @@ +Rf-^A!fq|$YV8FybK>b4~nh;48O~^uwaWNt>n+$~zk;sd`yKY^(P5jrGyKKAO zUGKZk@B4gz&vPf#GVw$Udak`=eNzHiHB&V?IT|-Y8jU7*_!oA{mIHtDhCj`6hTLS_P+|jaWlX7kNlsBG8eRud+NHoEFx_tBSiTe14%tNLr5l?hBw;e1tHy#?wGDY zr^`Q|pU5x8zQf+Y{MtXYA8FUa&FZE)pgN#BpgN#B@c(tdy$~y@nm4UTtCdK`&r=jD z5QK|B5(<&5KnjSAQVi{(crg~{95&oh?e-pZmi8_0PfCaVJ8sqf;#q)|ShE#eRvbqZ z0y#g&$B>7K`gk%XauO?R5LT<(yJKC$4;2GR=?GJ`Yg>?-4-{qD6i%E#tb_uzKOm7Y z7D`(#E|J4mJK9Ou*AqvtkX0-v6kx%gp6O)*ww8u7X^ zO!8tzi7C?oN!A;yv;9Wy?R(uxskg=b)t159BCN_e;&--=1CUq>c{!eANgtQ;X~H6R z6<^qYy*VlM@bTE1oAhj~yi$<_EM7=+S#UezeJD)VQ;6qC-^5arw6~W-l|84E2MQL^ zv#_#dN|oN|s1V_TKuDAzjwDkMA+F-Ma5}acd-lT+UW`xPUR*m9bET*tI9@0#z(pby zpQa-SC|BU>AQ{eyM-xJ}E7>;ZQzMLKbN&2Nm}kbgyxZig%JD{CiWNcL$1@ZuahxwC zI2;y&aCof>6g(z6>Clh!g?{3Kihl+k)d`wKgC6 z@zB{1lG4fc6XxzKtEXWuZjRhLfjar03y7zE{?Y7PZ7>3IBV}EcDTn1nE<%M!nbbi* zclR9m{Blh&DGePi*>ja*recIsQ5Q)DCJ5k7vpS$^L6V~q;duEyAxcwHrW$zHU7Oce zdo?NDn&mut^5uXLGuczD*$rxO*%d8`WXUiY0yy56sU-K*zSZoR4N2+upPLU(`I;)k z%2G<18L?Db?K0BiWbSL;es~6C25;A1cq?GQmberkfeepUM%YrNW#~Y3Gk|aa+9N#e zu~&i8Z^y0;-u39QvdVFxwc{h9C1f%&b0{sKvC;71%2o!3GI*>ox0EWtOeqbr&Qr&; zX{TYz1b@P`AkZ8O)?~`yE|B5xFOHsqbPyC(bGG;O4h*+Xf5x-aGX41Ft5fU%!bCe%VOpV&$nm3T3ZK zPFN)Y>9LKp`z8F!l=r}~eXnioe}T+_`BmXcKap4+E{Cj=sz-UA$S6&oUSBc4^I%y8 L(ERbB^pW{*#C+sT literal 0 HcmV?d00001 diff --git a/index.php b/index.html similarity index 90% rename from index.php rename to index.html index f862f84..6c90cbb 100644 --- a/index.php +++ b/index.html @@ -1,8 +1,3 @@ - - @@ -17,10 +12,13 @@
-

Please enter a Latitude and Longitude

+

Find the closest Pharmacy to you

+
+

Please enter a Latitude and Longitude

+
@@ -41,7 +39,7 @@
- +
diff --git a/js/system.js b/js/system.js index f4ef07f..afbc026 100644 --- a/js/system.js +++ b/js/system.js @@ -1,7 +1,7 @@ let value_error = false; // Flag if Lat/Lon values are out of range. let latitude_low = 38.0; let latitude_high = 40.0; -let longitude_low = -96.0; +let longitude_low = -97.0; let longitude_high = -94.0; function submitForm() @@ -29,9 +29,26 @@ function submitForm() // if Lat or Lon values are out of range return to form. if (value_error) { return; } + // Call to API + $.ajax( + { + url : 'https://rhays.us/Examples/RX_API_Call/RX.php', + type : 'GET', + dataType: 'html', + data : + { + 'K' : 'RLH1234', + 'Latitude' : nLatitude, + 'Longitude' : nLongitude + }, + success : function(data) + { + $("#results").html(data); + }, + error : function(request,error) + { + alert("Request: "+JSON.stringify(request)); + } + }); - - - - alert('Submit Form'); } diff --git a/scss/system.scss b/scss/system.scss index c9fd1a5..1bd5320 100644 --- a/scss/system.scss +++ b/scss/system.scss @@ -25,6 +25,16 @@ body section { + div#request + { + margin: 0 auto; + width: 80%; + + p + { + text-align: left; + } + } form { div#latitude_error @@ -99,7 +109,7 @@ body div#results { - background-color: aqua; + background-color: white; margin: 0 auto; text-align: left; width: 80%;