<?php
function route($post, $avec_reperes) {
  $aerodromes = array();
  if ($avec_reperes) {
	$b = pg_result(pg_query_ok("select position from aerodromes where id = ".current($post)),0,"position");
    for($i = 0; $i < (sizeof($post)-1); $i++) {
      $aerodromes[] = array( id => $post[$i], 
  		                     style => "aero",
			 			     position => $b);
	  $a = $b;
      $b = pg_result(pg_query_ok("select position from aerodromes where id = ".next($post)),0,"position");
	  $result = pg_query_ok("select reperes_proches(1.05, '$a', '$b') as id");
	  while($line = @pg_fetch_array($result,$j++ )) {
	    $aerodromes[] = array (id => $line[id],
	   						   style => "repere",
							   position => pg_result($r = pg_query_ok("select nom, position from reperes where id = $line[id]"),0,"position"),
							   nom => pg_result($r, 0, "nom"));
	  }
	}
	$aerodromes[] = array( id => end($post),style => "aero", position => $b); 
  } else {
	foreach($post as $a) {
	  $p = pg_result(pg_query_ok("select position from aerodromes where id = $a"),0,"position");
	  $aerodromes[] = array (id => $a,
		  					 style => "aero",
							 position => $p);
    }
  }
  return $aerodromes;
}
?>