<?php
	/************************************
	*Parser le fichier NAVFIX Aivlasoft*
	*************************************/
	
include(dirname(__FILE__)."/../core/codon.config.php");
include(dirname(__FILE__)."/../core/local.config.php");

define('NAV_DME', 1);	
define('NAV_NDB', 2);
define('NAV_VOR', 3);
define('NAV_VORD', 4);
define('NAV_FIX', 5);
define('NAV_TRACK', 6);
define('NAV_ILS', 7);
define('NAV_ILSD', 8);
	
	/*header("Content-type: text/plain; charset=utf-8"); */
	header('Content-Type: text/csv; charset=utf-8');
	header('Content-Disposition: attachment; filename=navfix.csv');
	
	$mtime=microtime();
	$mtime=explode(" ", $mtime);
	$mtime=$mtime[1]+$mtime[0];
	$starttime=$mtime;
	/* add */
	$total = 0;
	/* add */
	$fichier=fopen("wpnavfix.txt", "r");
	while(!feof($fichier))
	{
		$ligne=trim(fgets($fichier));
		if(!empty($ligne) && substr($ligne, 0, 1)!=";")
		{
			$ai_nom=trim(substr($ligne, 0, 24));
			$ai_code=trim(substr($ligne, 24, 5));
			$ai_lat=trim(substr($ligne, 29, 10));
			$ai_lon=trim(substr($ligne, 40, 10));
			$ai_type="5";
			
			/*echo $ai_nom.";".$ai_code.";".$ai_lat.";".$ai_lon."\n";*/
			//echo $ai_code.";".$ai_nom.";".''.";".''.";".$ai_lat.";".$ai_lon.";".$ai_freq.";".$ai_type."\n";
			echo $total++.";".$ai_code.";".$ai_nom.";".'n/a'.";".'n/a'.";".'n/a'.";".'loc'.";".$ai_lat.";".$ai_lon.";".$ai_freq.";".$ai_type."\n";


		}
	}
	fclose($fichier);

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