<!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 Haltestelle und Anzeige in GM</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 Haltestelle und Anzeige in GM</h2>
Bitte w&auml;hlen Sie eine Haltestelle aus";
echo "<form action='' method='post'>";
echo "<select name='umfrage'>";
mysqli_select_db($dz, 'goettingen');
$sql = mysqli_query($dz, "SELECT * FROM stations");
while ($ds = mysqli_fetch_object($sql)){
  $name = $ds -> name;
  $id  = $ds -> id;
  $station[]=$name;
  $id1[]=$id;
  }
$anzahl = count($station);
for ($i = 0; $i < $anzahl; $i++){
  echo "<option value=\"$i\">$station[$i]</option>\n";
  }	
echo "</select>";
echo "<input type='submit' value='Auswählen'>";
echo "</form>\n";
if (array_key_exists('umfrage',$_POST)) {
	$halte= $station[$_POST['umfrage']];
	$query="
	SELECT name, r, h FROM stations WHERE (name LIKE '". mysqli_real_escape_string($dz, $halte) ."');";
	$result=mysqli_query($dz, $query);
} else {
	$halte ='';
	$result ='';
}
if ($halte != "") {
  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<1; $c++){ // statt 1 kann hier auch $cols stehen, dann wuerden noch die GK-Koordinaten ausgegeben werden, da dies jedoch nicht erwuenscht ist wird nur die erste Spalte 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($nobj[$r], $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>";
?>
