<?php
include(dirname(__FILE__)."/../core/codon.config.php");
include(dirname(__FILE__)."/../core/local.config.php");

	/************************************
	*Parser le fichier NAVROUTE Aivlasoft*
	*************************************/
	
	/*header("Content-type: text/plain; charset=utf-8"); */
	header('Content-Type: text/csv; charset=utf-8');
	header('Content-Disposition: attachment; filename=airway.csv');
	
	$mtime=microtime();
	$mtime=explode(" ", $mtime);
	$mtime=$mtime[1]+$mtime[0];
	$starttime=$mtime;
	/* add */
	$total = 0;
	/* add */
	//echo "Loading airways segments...\n";

	$fichier=fopen("wpnavrte.txt", "r");
	while(!feof($fichier))
	{
		$ligne=trim(fgets($fichier));
		if(!empty($ligne) && substr($ligne, 0, 1)!=";")
		{
			/*array (
			0 => 'R446',
			1 => '002',
			2 => 'DASKO',
			3 => '49.105278',
			4 => '138.142778',
			5 => 'FL100',
			6 => 'FL100',
			7 => 'FL530',
			8 => '120',
			9 => '121',
			10 => 'B',
			11 => '-',
			); */
			
			$pieces = explode(" ", $ligne);
			/* echo $pieces[0].";".$pieces[1].";".$pieces[2].";".$pieces[3].";".$pieces[4].";".$pieces[10]."\n"; */
			/*echo "phpvms_navdata format \n"; */
			echo $total++.";".$pieces[2].";".$pieces[2].";".$pieces[0].";".$pieces[10].";".$pieces[1].";".'loc'.";".$pieces[3].";".$pieces[4].";".'n/a'.";"."5"."\n";

		}
	}

	fclose($fichier);

	$mtime=microtime();
	$mtime=explode(" ", $mtime);
	$mtime=$mtime[1]+$mtime[0];
	$endtime=$mtime;
	$totaltime=($endtime-$starttime);
	/*echo"OK : Done in ".$totaltime." seconds";*/
	?>