<?
session_start();
include("includes/connection.php");
//Cette classe genrere les droits pour l'administrateur (login_id 1);
$rep = "apps";
$dir = opendir($rep);
show_apps($dir,$rep);
function lire_dir($dir,$rep){
	while ($f = readdir($dir)) {
		echo $rep.$f."<br>";
   		if(is_file($rep."/".$f)) {
			echo "<li>Nom : ".$f;
			echo "<li>Taille : ".filesize($rep."/".$f)." octets";
			echo "<li>Création : ".dd(filectime($rep."/".$f));
			echo "<li>Modification : ".dd(filemtime($rep."/".$f));
			echo "<li>Dernier accès : ".dd(fileatime($rep."/".$f));
			echo "<br><br>";
		}else{
			
			if(is_dir($rep."/".$f) && $f !="." && $f!=".."){
				$dir2 = opendir($rep."/".$f);
				lire_dir($dir2,$rep."/".$f);
			}
		}
	}
}

function dd($date) {
	return date("d/m/Y H:i:s",$date);
}

function show_apps($dir,$rep){
	while ($f = readdir($dir)) {
		if(is_dir($rep."/".$f) && $f != "." && $f != ".." && $f !="CVS") {
			echo "Application:$f<br />";
			$dir2 = opendir($rep."/".$f."/modules");
			show_modules($f,$dir2,$rep."/".$f."/modules");
		}
	}
}

function show_modules($app,$dir,$rep){
	while ($f = readdir($dir)) {
		if(is_dir($rep."/".$f) && $f != "." && $f != ".." && $f !="CVS") {
			echo "$app Modules:$f<br />";
			ajouter_droit($app,$f,"".$f."/list_".$f.".php");
		}
	}
}

function ajouter_droit($app,$mod ,$rep){
	$access = mysql_query("SELECT * FROM ACCESS WHERE App_Id='$app' AND Module='$mod' AND User_Id='1'");
	if(!mysql_fetch_object($access)){
		mysql_query("INSERT INTO ACCESS VALUES('','$app','$mod','$rep','','1')");
		echo "Nouvelle application $app et module $mod";
	}
}
?>