<?php
srand((float)microtime()*1000000); // windows bug
function affiche_site($id, $secours = array()) {
  $query = "select id, nom, code, frequence, position, (photo is not null) as aphoto from aerodromes where id = $id";
  $result = pg_query_ok($query);
  if ($line = @pg_fetch_array($result,0 )) {
    list($x,$y) = explode("," , str_replace( array("(",")"), "", $line[position])); 
	print "<aerodrome code=\"$line[code]\" nom=\"$line[nom]\" photo=\"".($line[aphoto]=="t"?"photo.php?site=$id":"")."\" x=\"".decversdeg($x)."\" y=\"".decversdeg($y)."\">";
	print "<meteo>";
	$metar = get_metar($line[code]);
	$decoded_metar = process_metar($metar);
	print "<table bgcolor=\"white\" style=\"float: left; \"><tr><td nowrap=\"true\"><img style=\"display: inline;\" src=\"phpweather/"; 
	get_temp_image($decoded_metar); print "\" />";
	print "<img style=\"display: inline;\" src=\"phpweather/"; 
	get_winddir_image($decoded_metar); print "\" />";
	print "<img style=\"display: inline;\" src=\"phpweather/"; 
	get_sky_image($decoded_metar); print "\" />";
	print "</td></tr></table>";
    pretty_print_metar($metar,$line[nom]);
	print "</meteo>";
	$j = 0;
	$partenaires = array("partenaire_club", "partenaire_loueur", "partenaire_resto");
	shuffle($partenaires);
	do {
	  list ($useless, $partenaire) = each($partenaires); 
	} while($partenaire && (! $partenaire($id)));
	if ($_POST[pilote] ) {
	  $query = "select pilotes.id, pilotes.nom, pilotes.email, (pilotes.photo is not null) as aphoto from pilotes, aerodromes where aerodromes.id = $id and pilotes.publie = true and (pilotes.position <-> aerodromes.position) < 0.2";
	  $result = pg_query_ok($query);
	  if (pg_num_rows($result)) {
	    print "<pilotes>";
	    $i = 0;
	    while($line = @pg_fetch_array($result,$i++ )) {
	      print "<pilote nom=\"$line[nom]\" email=\"$line[email]\" photo=\"".($line[aphoto]=="t"?"photo.php?site=$line[id]":"")."\" />";
	    }
	    print "</pilotes>";  
	  }
	}
	if (sizeof($secours)) {
	  foreach($secours as $s){
	    list($x,$y) = explode("," , str_replace( array("(",")"), "", $s[position]));
	    print "<aerodrome nom=\"$s[nom]\" id=\"$s[id]\" x=\"".decversdeg($x)."\" y=\"".decversdeg($y)."\" />\n";	
	  } 
	}
	print"</aerodrome>";
  }
}
?>