<html>
<head><title>ZIP Code Radius/Lookup Demo</title></head>

<body>

<?php require_once('zipcode.php'); 
if (isset($_POST['zip'])) $zip=$_POST['zip'];
?>

<center>

<h2>ZIP Code Lookup</h2>
<form method="post">
ZIP <input type="text" name="zip" size=5 value="<?php echo $zip; ?>">
<input type="submit" value="Submit"/>
</form>
<?php
if ($zip && strlen($zip) > 0) {
  $ZIP = new Zipcode();
  $current = $ZIP->query($zip);
  if ($current) {
    printf("%s, %s<br>", $current->name, $current->state);
    printf("Lat/Lon: %.2f, %.2f", $current->lat, $current->lon);
  }
  else printf("Query failed. Check input and try again.");
}
?>
</center>

<h2>

<center>
<h2>Radius Search</h2>
<form method="post">
ZIP <input type="text" name="zipsearch" size=5 value="<?php echo $zipsearch; ?>">
<SELECT name="distance">
     <OPTION selected label="distance" value="5">5</OPTION>
     <OPTION label="distance" value="10">10</OPTION>
     <OPTION label="distance" value="15">15</OPTION>
     <OPTION label="distance" value="20">20</OPTION>
</select>
<SELECT name="units">
     <OPTION selected label="units" value="mi">miles</OPTION>
     <OPTION label="units" value="km">kilometers</OPTION>
     <OPTION label="units" value="nm">nautical miles</OPTION>
 </select>
<input type="hidden" name="page" value"home">
<input type="submit" value="Submit"/>
</form>
<?php
if ($zipsearch && strlen($zipsearch) > 0) {
?>
<?php
  printf("<p>ZIP Codes within %d %s of %s:\r\n\n", $distance, $units, $zipsearch);
  printf("<p><table><tr><th>ZIP<th>Distance");
  $zipcode = new Zipcode();
  $result = $zipcode ->local($zipsearch, $distance, $units);
  foreach ($result as $key => $value) {
    printf("<tr><td align=center>%s<td align=center>%.1f", $key, $value);
  }
  printf("</table>");
?>
</center>
<?php
}
?>

</body>

</html>