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 @@ + - @@ -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%;