<?php

// Expects:
//  $directory - the directory to list.

/* Lists all readable files in a public directory and its readable subdirectories as links 
(i.e. it generates site map).
*/

$tab = "";
$directory = "/home/abu-jeib/www/teaching/Spring_07/207/";
list_dir($directory,$tab);
function list_dir($directory,$tab)
{
	if ($dirHandle = opendir ($directory))
	{
		echo "$tab<ul>\n";
		while (($file = readdir ($dirHandle)) !== false)
		{
			if (substr ($file, 0, 1) != ".")
			{
				if (is_dir ($directory . "/" .$file) && is_readable ($directory . "/" .$file))
				{
					echo "$tab   ";
					echo "<li class='directory'><img src=\"/cswebpage/images/dir.gif\" alt='dir 
icon' /> $file</li>\n";
					list_dir($directory."/".$file,$tab."\t");
				
				}
				else if (is_readable ($directory . "/" .$file))
				{
					echo "$tab   <li>|<a href=\"" . $directory . "/" . $file . "\">" . $file . 
"</a></li>\n";
				}
			}
		}
		echo "$tab</ul>\n";
		closedir ($dirHandle);
	}
	else
	{
		echo "<p class=\"error\">Error: Couldn't read directory!</p>\n";
	}
}

?>

