<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
.ver013 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
text-decoration: none;
color: #000000;
}
</style>
<title>EPTV File Browser</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" language="javascript">
<!-- Debut
function lien(url) {
    opener.location.href = url;
  // Ferme le pop-up automatiquement
  window.close()
}
// Fin -->
</script>
<script language="JavaScript" type="text/javascript"> 
function Go(chemin) 
	{ 
    // Donne la valeur de la variable 'url' au champ 'page' 
    document.forms.menu.elements.chemin.value=chemin; 
    // Permet l'envoi du formulaire lors de l'exécution de la fonction 
    document.forms.menu.submit(); 
	}   
	</script>
</head>

<body>
<?

$rep_def = "../photos/";

function ListDir()
{	
	global $rep_def;
   if (isset($_REQUEST['chemin']))
   {
   		$chemin = $_REQUEST['chemin'];
		$tab_chemin = split ("/", $chemin);
				
		if (strcmp($chemin, $rep_def))
		{
			if (!strlen(array_pop($tab_chemin)))
				array_pop($tab_chemin);
			$precedent = implode("/",$tab_chemin);
			$precedent .= "/";
		}
		else
		{
			unset ($precedent);
		}
   }
   else
	{
		$chemin = $rep_def;
	}
	$rep=opendir($chemin);
    chdir($chemin);
	$i = 0;
	$c = 0;
	?>
	<table BORDER=1 CELLSPACING=0 CELLPADING=0>
	<tr BGCOLOR=#000000><td WIDTH=150><font color="#FFFFFF">Nom</font></td><td ALIGN=CENTER><font color="#FFFFFF">Type</font></td><td WIDTH=100 ALIGN=RIGHT><font color="#FFFFFF">Taille</font></td><td WIDTH=200 ALIGN=RIGHT><font color="#FFFFFF">Dernière modification</font></td></tr>
	<FORM METHOD="POST" name="menu">
   	<input type="hidden" name="chemin" value="">
	<?
	
	if (isset($precedent))
	{
		echo "<tr bordercolor=\"#FFFFFF\" ><td><a href=\"#\" onClick=\"Go('$precedent')\"><p class=\"ver013\"><img SRC=\"../images/dir.gif\" BORDER=0> ..</p></a></td><td><p class=\"ver013\">Dossier</p></td><td></td><td WIDTH=200 ALIGN=RIGHT></td></tr>";
	}
	
	while ($file = readdir($rep))
   	{
    	if($file !='..' && $file !='.' && $file !='')
       	{
           	if (is_dir($file))
        	{
            	if ($chemin == ".")
                {
                	$chemin = "";
             	}
				/////////////////////////////
				//Navigation ds les dossier//
				/////////////////////////////
				//if (!bcmod($c, 2))
				//{
					//$color = "#6699CC";
				//}
				//else
				//{
					//$color = "#99CCFF";
				//}
				$dossier[$c++] = "<tr bgcolor=\"#EEEEEE\" bordercolor=\"#FFFFFF\"><td><a href=\"#\" onClick=\"Go('$chemin$file/')\"><p class=\"ver013\"><img SRC=\"../images/dir.gif\" BORDER=0> $file</p></a></td><td><p class=\"ver013\">Dossier</p></td><td></td><td WIDTH=200 ALIGN=RIGHT><p class=\"ver013\">".date("d/m/Y H:i:s.", filectime($file))."</p></td></tr>";
				//echo "<a href=\"#\" onClick=\"Go('$chemin$file/')\">Dossier : $file</a></td></tr>";
			}
			if (is_file($file))
			{
				//$lien[$i++] = "<a href=\"#\"  onClick=\"lien('cg_test.php?file=$file')\">$file</a>";
				$lien[$i++] = $file;
			}
		}
	}
	closedir($rep);
	if (isset($dossier))
	{
		sort ($dossier);
		foreach($dossier as $value)
        {
			echo $value;
		}
	}
?>
	</form>
<?
    if (isset($lien))
    {
		sort ($lien);
		$i = 0;
        foreach($lien as $value)
        {
			$tab_ext = split("\.", $value);
			$len_tab = count($tab_ext);
			$ext = $tab_ext[$len_tab-1];
			if (!is_file("../images/ico_browser/avi.gif"))
			{
				//Normale c "file" ms is_file ou file_exist marche pas
				$ico = $ext;
			}
			else
			{
				$ico = $ext;
			}
			if ($i)
			{
				$i = 0;
				$color = "#6699CC";
			}
			else
			{
				$i = 1;
				$color = "#99CCFF";
			}
			$link_tab = split("/", $chemin);
			for ($x = 1; $link_tab[$x]; $x++)
			{
				$link .= $link_tab[$x];
				$link .= "/";
			}
        	echo "<tr bgcolor=\"$color\" bordercolor=\"#FFFFFF\" ><td nowrap><a href=\"#\"  
			onClick=\"lien('../index.php?section=AdminHome&section_admin=AdminAddPhotos&file=$link$value')\"><p class=\"ver013\"><img SRC=\"../images/ico_browser/$ico.gif\" BORDER=0> $value</p></a></td>";
			echo "<td WIDTH=75 ALIGN=CENTER><p class=\"ver013\">Fichier ".strtoupper($ext)."</p></td>";
			//print "Fichier de type ".strtoupper($ext);
			$size = filesize($value) / 1000;
			echo "<td ALIGN=RIGHT><p class=\"ver013\">".$size." Ko</p></td>";
			//print " de taille ".filesize($value);
			echo "<td WIDTH=200 ALIGN=RIGHT><p class=\"ver013\">".date("d/m/Y H:i:s.", filectime($value))."</p></td></tr>";
			//print " Date de derniere modif ".date("d/m/Y H:i:s.", filectime($value));
			unset ($link);
			unset ($link_tab);
        }
   }
 echo "</table>";
}

ListDir();

?>
</body>
</html>
