<?PHP
//        require_once("db.php");

	define("BASE_DIR", "projects/");
	define("THUMB_DIR", "thumbnails/");
	define("THUMB_Y_SIZE", 120);
	define("IMG_Y_SIZE", 500);

	// A simple function that scans the contents of a directory given the path and returns an array with the result
	function myscandir($path)
	{
		if(is_dir($path))
			if($dh = opendir($path))
			{
				$result = array();
				$n = 0;
				while(($file = readdir($dh)) !== false)
					// skip parent/this dir and any hidden files/dirs
					if(substr($file, 0, 1) != ".")
						$result[$n++] = $file;
				closedir($dh);
			}
		return $result;
	}

	// This function creates HTML for all projects currently located in the "BASE_DIR" directory
	function list_projects()
	{
		$projects = myscandir(BASE_DIR);
		foreach($projects as $project)
		{
			$path = BASE_DIR . $project;
			$contents = myscandir($path);
			$images = array();
			foreach($contents as $file)
			{
				if($file == "info.txt")
				{
					$info_file = fopen(BASE_DIR . $project . "/" . $file, 'r');
					while(!feof($info_file))
						echo fgets($info_file) . "<br>\n";
					fclose($info_file);
				}
				else
					$images[$n++] = $file;
			}
			foreach($images as $image)
			{
				echo "<a href=\"" . BASE_DIR . $project . "/" . $file . "\" border=1><font color=\"#000000\"><img src=\"" . THUMB_DIR . $project . "/" . $file . "\"></font></a>";
			}
		}
	}
PHP?>

<html>
<head>
<title></title>
</head>

<body bgproperties=fixed background="img/main.jpg" style="background-attachment: fixed;">

<br><font size="3" color="#ffffff" face="Verdana"><b>Portfolio</b></font>

<p style="width:390px;">
<font size="-1" face="Verdana">Här kan du se några av de tidigare projekt vi jobbat med.</font>
</p>

<?PHP
	list_projects();
PHP?>

</body>
</html>
