<?php

// Directory lister
// Maakt een tabelletje met daarin allerlei bestanden en directories 
// van een directory. Geeft de UBB-code voor gebruik op fora's en dergelijke.

$domein = "www.darklands-sewer-system.eu"; 
$dir = ".";
$pad = $_SERVER['REQUEST_URI'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Directory listing of <?php echo $domein ?><?php echo $pad ?></title>
<style type="text/css">
	<!--

	body{
	background-color: #ffdd00;
	font-family: Verdana, sans-serif;
	text-align: center;
	}
	#content{
	width: 1000px;
	text-align: left;
	margin-left: auto;
	margin-right: auto;
	}
	h1{
 color: blue;
	font-size: 18px;
	}
	table{
	border: 1px solid Silver;
	border-collapse: collapse;
	}
	td, th{
	border: 1px solid silver;
	padding: 5px;
 color: blue;
	font-size: 11px;
	text-align: left;	}
	
	td.file{
 color: blue;
	font-size: 13px;
}
	td.dir{
 color: blue;
	font-size: 14px;
	font-weight: bold;
}
 td a{
 color: blue;
 }
 td a:hover{
 color: green;
 }
 td a:visited{
 color: magenta;
 }
 .ubb{
	color: red;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<div id="content">
<?php
function getFileSize($fsize) {
                $toa = $fsize/(1024*50);
                $seconds = $toa % 60;
                $mins = floor($toa/60);
                $hours = floor($mins/60);
                $minutes = $mins % 60;

                $minutes = sprintf("%02d", $minutes);
                $seconds = sprintf("%02d", $seconds);
                if ( $fsize > 1024 ) {
                   $fsize = $fsize/1024;
                   $sizeunit = " kb";
                }
                if ( $fsize > 1024 ) {
                   $fsize = $fsize/1024;
                   $sizeunit = " Mb";
                }
                return number_format($fsize,1).$sizeunit;
}

function getDownloadEst($fsize,$scale) {
                $toa = $fsize/(1024*50);
                $seconds = $toa % 60;
                $mins = floor($toa/60);
                $hours = floor($mins/60);
                $minutes = $mins % 60;

                $hours   = sprintf("%02d", $hours);
                $minutes = sprintf("%02d", $minutes);
                $seconds = sprintf("%02d", $seconds);
                switch ($scale) {
                    case 'mins': 
                           return $minutes."' ".$seconds."''";
                           break;
                    default: 
                           return $hours."h ".$minutes."' ".$seconds."''";
                           break;
                    }
}

if ($handle = opendir($dir)) {
echo "<table>\n<tr><th>Contents</th><th>Size</th><th>ETA@50 kb/s</th></tr>\n";
$i = 0;

// Bestanden in een array zetten

while (false !== ($file = readdir($handle))) {
$bestanden[$i]= $file;
		$i++;
 }
 
// Array sorteren, dan bestanden op het scherm pleuren. 

	 natcasesort($bestanden);

 	foreach($bestanden as $file){
	if (strlen($file)>1 && substr($file, -3, 3)!= 'php'){
		if (strtolower(substr($file, -3, 3)) == 'mp3' 
		){ 
			  echo '<tr><td><a href=download.php?file='.$file.'><b>'.$file.'</b></a></td><td><b>'.getFileSize(filesize($file)).'</b></td><td>'.getDownloadEst(filesize($file),'mins').'</td></tr>';
		}
		elseif (filetype($file) == 'dir'){
                if (strtolower(substr($file, 0, 2)) != '..')
                     {
				echo "<tr>\n
				<td class=\"dir\"><a href=\"$file\">$file</a></td>\n
				<td class=\"ubb\">directory</td>\n
				</tr>\n";
                    } 
		}
	 	else {    
		}
	 }
}
echo "</table>";

   closedir($handle);
	 
}
?> </div>
</body>
</html>
