<?
	/*
		Script that handle the download of a file -- Modelib website
		Romain Gaucher

		use: dl.php?file=URI
		use: dl.php
			> download page
			> links etc.
			> auto-package building ?
	*/

	function file_size($file)
	{
		$prelim_size=filesize($file);
		$b=$prelim_size;
		$kb=round($b/1024,4);
		$mb=round($kb/1024,4);

		$size_out = "$mb Mo";
		return $size_out;
	}

	  function ListFolders($path)
	  {
	    if (empty($path))
	       return false;
	    if (!is_dir($path))
	       return false;
	    $O = dir($path);

	    while($local_file = $O -> read()) 
	    {
	        if($local_file != '.' && $local_file != '..')
	        {
	            $p = $path.'/'.$local_file;
	            if(is_file($p))
	            {
	            	$size = file_size($p);
					$date_fic=date("d-m-Y", filemtime($p));

					if (strstr($local_file,".tar.gz") || strstr($local_file,".tar.bz2"))
					{
					echo "<div class=\"dl\"><img src=\"images/tgz.png\" alt=\"ico\" /><a href=\"dl.php?file=$p\">$local_file</a> :: Archive, $size, $date_fic</div>\n";
	    			}
	    			else if (strstr($local_file,".lib") || strstr($local_file,".exe") /*)*/ || strstr($local_file,".png"))
	    			{
					echo "<div class=\"dl\"><img src=\"images/exe.png\" alt=\"ico\" /><a href=\"dl.php?file=$p\">$local_file</a> :: Librairie, Exectuable, $size, $date_fic</div>\n";
	    			}
	    			else if (strstr($local_file,".pdf"))
	    			{
					echo "<div class=\"dl\"><img src=\"images/pdf.png\" alt=\"ico\" /><a href=\"dl.php?file=$p\">$local_file</a> :: Documentation PDF, $size, $date_fic</div>\n";
	    			}
	    			else if (strstr($local_file,".zip"))
	    			{
					echo "<div class=\"dl\"><img src=\"images/zip.png\" alt=\"ico\" /><a href=\"dl.php?file=$p\">$local_file</a> :: Archive, $size, $date_fic</div>\n";
	    			}
	    			else if (strstr($local_file,".txt"))
	    			{
					echo "<div class=\"dl\"><img src=\"images/txt.png\" alt=\"ico\" /><a href=\"dl.php?file=$p\">$local_file</a> :: Texte, $size, $date_fic</div>\n";
					}
	        	}
	            else if (is_dir($p))
	            {
					echo "<div class=\"title\"><b>Dossier: $local_file </b><br />\n";
					$description = $path.'/'.$local_file.'/'.$local_file.'.phtml';
					if (is_file($description))
					{
						include ($description);
						echo "<br />";
					}
					echo "</div>\n";
					ListFolders($p);
				}
	         }
	    }
	    $O -> close();
	    return true;
	  }

?>

			<div id="text">
			    <h3>Distribution</h3>
					Nous avons eu l'accord de notre chef de projet pour distribuer <b>librement</b> tout le contenu de notre projet.<br />
					Le voici:
					<?
						ListFolders("./distrib");
					?>
					<br />
					Le projet est disponible sous licence BSD.
			</div>


			<div id="licence">
 					<h3>Licence</h3>
					<pre>
Copyright (c) 2005, Quentin Lequy and Romain Gaucher
All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following 
conditions are met:

	* Redistributions of source code must retain the above copyright
	  notice, this list of conditions and the following disclaimer.

	* Redistributions in binary form must reproduce the above copyright 
	  notice, this list of conditions and the following disclaimer in the 
	  documentation and/or other materials provided with the distribution.

	* Neither the name of Quentin Lequy or Romain Gaucher nor the names 
	  of its contributors may be used to endorse or promote products
	  derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
					</pre>
			</div>
