<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<?php
require_once('mysql.inc.php');
echo "<head>";
echo "<title>Auswahl einer Sehensw&uuml;rdigkeit und Ausgabe der Adresse und Beschreibung</title>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
echo '
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzosMcEBJXrsEQFGBQAWclRQgU1QyBe_kcGDWdfFXsq08_1MSqxREpHLDVDDm5p9ub3kwCQeYethC1w"
type="text/javascript">
</script>    
';
echo "</head>";
echo '<body onload="load()" onunload="GUnload()">';
echo "<h2>Auswahl einer Sehensw&uuml;rdigkeit und Ausgabe der Adresse und Beschreibung sowie Anzeige des Standortes in Google Maps</h2>
Bitte w&auml;hlen Sie eine Sehensw&uuml;rdigkeit aus";
echo "<form action='' method='post'>";
echo "<select name='umfrage'>";
mysqli_select_db($dz, 'goettingen');
$sql = mysqli_query($dz, "SELECT * FROM sights");
while ($ds = mysqli_fetch_object($sql)){
  $name = $ds -> name;
  $id	  = $ds -> id;
  $sight[]=$name;
  }
$anzahl = count($sight);
for ($i = 0; $i < $anzahl; $i++){
  echo "<option value=\"$i\">$sight[$i]</option>";
  }
echo "</select>";
echo "<input type='submit' value='Auswählen'>";
echo "</form>";
if (array_key_exists('umfrage',$_POST)) {
$sight= $sight[$_POST['umfrage']];
$query="
SELECT name AS 'Sehenswürdigkeit',address AS 'Adresse', discription  AS 'Beschreibung',r, h
FROM sights
WHERE (name LIKE '". mysqli_real_escape_string($dz, $sight) ."');";
$result=mysqli_query($dz, $query);
} else {
	$sight ='';
	$result ='';
}
if ($sight != ""){
  if ($result){
    echo "</span><p>";
	$rows=mysqli_num_rows($result);
    $cols=mysqli_num_fields($result);
    for ($r=0; $r<$rows; $r++){
      for ($c=0; $c<3; $c++){ // statt 3 kann hier auch $cols stehen, dann wuerden noch die GK-Koordinaten ausgegeben werden, da dies jedoch nicht erwuenscht ist werden nur die ersten drei Spalten einer Zeile als echo ausgegeben, die Koordinaten werden dennoch ausgelesen da sie ja spaeter umgerechnet werden muessen
        echo mysqli_result($result, $r, $c);
		echo "<br>";
        }
	  }
      echo "</p>";
    }
}
if ($result){
  $rows = mysqli_num_rows($result);
  $cols = mysqli_num_fields($result);
  for($r=0; $r< $rows; $r++){
	 list($noop, $nobj[$r], $noop1, $xobj[$r], $yobj[$r]) = mysqli_fetch_row($result);
    }
include './gaussk.php';
for($r=0; $r< $rows; $r++){
  $xin=$xobj[$r];
  $yin=$yobj[$r];
  list($xobj[$r], $yobj[$r]) = CalcStart($xin, $yin);
  }
$zoom = "15";
mysqli_free_result($result);
echo '<script type="text/javascript">';
echo '
function load() {
  function createListener (marker, text) {
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(text);
        }
        );
      }
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
        map.addControl(new GOverviewMapControl());
        ';
        echo '
        map.setCenter(new GLatLng('.$xobj[0].', '.$yobj[0].'), '.$zoom.', G_SATELLITE_MAP);
        var point = new Array();
        var text = new Array();
        var marker = new Array();
        ';
        for ($r=0; $r<$rows; $r++) {
          echo '
          point['.$r.'] = new GLatLng('.$xobj[$r].','.$yobj[$r].');
          text['.$r.'] = "'.$nobj[$r].'";
          ';
          }
        echo '
        var marker = new Array();
        for (i=0; i< point.length; i++) {
          marker[i] = new GMarker(point[i]);
          map.addOverlay(marker[i]);
          createListener (marker[i], text[i]);
          }
        ';
        echo '
        }
      }
    </script>
    ';
  }  
	 echo '
    <div id="map" style="width:780px;height:320px"></div>
    ';
    echo "</body>";
?>
