<?
	# ouvre un fichier, et retourne le contenu
	function zzzOpenFile($fn) {
		if (file_exists($fn)) {
			$fp = fopen ($fn, "r"); # "r" is used to open a file in read mode
			$content = fread($fp, filesize($fn));
			fclose($fp);
		}
		return $content;
	}

	# fonction recoit le contenu d'un fichier csv, et ressort le tableau correspondant
	function zzzDecrunch($content) {
		global $cell, $lin, $col;
		
		for ($j=1; $j<=100; $j++) {
				for ($i=1; $i<=100; $i++) {
					$cell[$j][$i]="";
				}
			}
		
		$l = strlen($content);
		$lin=1; $col=0; $maxcol=0; $maxlin=0; $cel="";
		for ($i=0; $i<=$l-1; $i++) {
			$c = $content[$i];
			switch (ord($c)) {
				case "10" :
					$col++;
					if ($col>$maxcol) { $maxcol=$col; }
					if ($lin>$maxlin) { $maxlin=$lin; }
					$cell[$lin][$col]=$cel;
#					echo $cel."<br>";
					$cel="";
					
					$col=0;
					$lin++;
				break;
				case "13" :
					$col++;
					if ($col>$maxcol) { $maxcol=$col; }
					if ($lin>$maxlin) { $maxlin=$lin; }
					$cell[$lin][$col]=$cel;
#					echo $cel."<br>";
					$cel="";
				break;
				case "59" :
					$col++;
					if ($col>$maxcol) { $maxcol=$col; }
					if ($lin>$maxlin) { $maxlin=$lin; }
					$cell[$lin][$col]=$cel;
#					echo $cel."<br>";
					$cel="";
				break;
				default :
					$cel.=$c;
				break;
			}
		}
		$lin=$maxlin;
		$col=$maxcol;
	}

	$fn = $DOCUMENT_ROOT."/zzzfilelist.csv";
#	echo "***".$fn."***<br>";
 	if (file_exists ($fn)) {
		$content = zzzOpenFile($fn);
		zzzDecrunch($content);
		$filelist=$cell;
		$filelistnb=$lin;
		$filelistcol=$col;
	}

	# returns absolute path to file with filename
	function Inc($file) {
		global $filelist, $filelistnb, $DOCUMENT_ROOT;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($file == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return $DOCUMENT_ROOT.$isindir.'/'.$file;
	}
	
	# returns relative path to file with filename	
	function IncL($file) {
		global $filelist, $filelistnb;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($file == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return $isindir.'/'.$file;
	}

	# returns absolute path to third file with filename	
	function Incref($file, $ref) {
		global $filelist, $filelistnb, $DOCUMENT_ROOT;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($ref == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return $DOCUMENT_ROOT.$isindir.'/'.$file;
	}
	
	# returns absolute path to third file without filename	
	function Incref2($ref) {
		global $filelist, $filelistnb, $DOCUMENT_ROOT;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($ref == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return $DOCUMENT_ROOT.$isindir.'/';
	}

	# returns relative path to third file with filename	
	function IncLref($file, $ref) {
		global $filelist, $filelistnb;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($ref == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return $isindir.'/'.$file;
	}

	# returns url path to file with filename
	function IncCL($file) {
		global $HTTP_HOST, $filelist, $filelistnb;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($file == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return "http://".$HTTP_HOST.$isindir.'/'.$file;
	}
	
	# returns url path to third file with filename
	function IncCLref($file, $ref) {
		global $HTTP_HOST, $filelist, $filelistnb;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($ref == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return "http://".$HTTP_HOST.$isindir.'/'.$file;
	}

	# returns the dir of file
	function DirL($file) {
		global $filelist, $filelistnb, $DOCUMENT_ROOT;
		
		for ($i=1; $i<=$filelistnb; $i++) {
			if ($file == $filelist[$i][1]) {
				$isindir = $filelist[$i][2];
			}
		}
		return $isindir.'/';
	}

	# returns file on another server
	function IncStock1($file, $rep) {
		return "http://fcambounet.free.fr".$rep.$file;
	}

?>