<?php
	session_start();   
	
	//include ("entete.php");

?>

<!--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Gestionnaire de fichiers: Patrice Delpy 2013</title>
<!--
<LINK rel="stylesheet" type="text/css" media="screen" href="autre.css" />
-->

<!--
<style  TYPE="text/css">

		

#message  		{

					position: absolute;
					right: 100px;
					top : 100px;
					background:green;
					overflow: visible;
					visibility: visible;
					
					z-index: 1;
				}
			
			
</style>




</head>
-->

<?php



$basedir = $_SESSION['repertoire'];

### definition des variables 

//$basedir = "../repertoire";

/*if (isset($_GET["path"]))
	{
		$basedir = $_GET["path"];
		
		//chdir('../');
		
		chdir($basedir);
		$stocke_rep = getcwd();

		$_SESSION['repertoire']= $basedir;
	
		//$_SESSION['repertoire']= "/Users/lucien";
		
		echo "> " .$_SESSION['repertoire'];
		echo '</br>';
		echo '</br>';
}
*/
/*else {
		echo "En mémoire " .$stocke_rep;
	}*/

	
	
$updatecheck = "yes";

### 
$enable_css = "no";
$enable_logout = "no";

### autorisation
$allow_move = "yes";
$allow_download = "yes";
$allow_copy = "yes";
$allow_touch = "yes";
$allow_rename = "yes";
$allow_edit = "yes";
$allow_chmod = "yes";
$allow_delete = "yes";
$allow_upload = "yes";
$allow_create_dir = "yes";
$allow_create_file = "yes";
$allow_display_env = "no";

$not_allowed = "Cette fonction n'est pas disponible. Consulter l'administrateur.";

$html_ender = "</td></tr><tr><td colspan=\"2\"><hr></td></tr><tr><th colspan=\"2\" bgcolor=\"#4C4C99\"><font size=\"-1\" color=\"white\" face=\"arial, helvetica\">Patrice Delpy 2013</font></th></tr></table></body></html>";


############### Size for textarea
if($enable_css == "yes")
	{
	$textrows = "27";
	$textcols = "160";
	}
else
	{
	$textrows = "20";
	$textcols = "100";
	}

############### If $wdir (working directory) isn't specified, set it as a slash (/)
if(!$wdir) $wdir="/";

//echo $wdir;

### calcule la taille d'une image
function image_size()
	{
	$size = GetImageSize("$image");
	}

### HTML header
function html_header(){
	global $basedir;
	global $wdir;
	global $lastaction;
	global $version;
	global $HTTP_REFERER;
	global $action;
	global $webname;
	global $display;
	global $file;
	global $browse;
	global $raw;
	global $image;
	global $fileurl;
	global $enable_css;
	global $allow_display_env;
	global $enable_logout;
	
	echo " <BR> ";
	echo " <BR> ";

	############ We want a BACK link when viewing pictures and raw text.
	if($action == "show")
		{
		echo " <td width=\"50%\" nobreak><b><font size=\"3\" color=\"#4C4C99\" face=\"arial, helvetica\">$lastaction</font></b></td>";
		echo "<div id=\"message\">";

		echo " <td width=\"50%\" nobreak align=\"right\"><b><font size=\"3\" color=\"#4C4C99\" face=\"arial, helvetica\"><a href=\"$HTTP_REFERER\" title=\"Retour\">Back</a></font></b></td>";
		echo "</div>";
		}

	############ We dont want a BACK link
	else
		{
		echo " <td colspan=\"2\"><b><font size=\"3\" color=\"#4C4C99\" face=\"arial, helvetica\">$lastaction</font></b></td>";
		}

	
	echo "<BR>";
	echo "<BR>";
	
	echo "<tr>";
	echo "<td colspan=\"2\"><hr><td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td colspan=\"2\">";
}

### taille des fichiers
function display_size($file)
        { 
		
			 //preg_match("/([^A-Za-z0-9])/",$file,$result);
			//On cherche tt les caractères autre que [A-Za-z] ou [0-9]
			//if(empty($result))
			
			if(is_file($file))
			{
					$file_size = filesize($file);

					if($file_size >= 1073741824)
					{
					### en giga 
					$file_size = round($file_size / 1073741824 * 100) / 100 . " Go";
					}
					elseif($file_size >= 1048576)
					{ ### en mega
					$file_size = round($file_size / 1048576 * 100) / 100 . " Mo";
					}
					elseif($file_size >= 1024)
					{ ### en kilo
					$file_size = round($file_size / 1024 * 100) / 100 . " Ko";
					}
					else{   ### en octet (byte)
					$file_size = $file_size . " Octets";
					}
					return $file_size;
			}		
}

############ List the files function
function list_files()
	{
	global $basedir;
	global $wdir;	
	global $single;
	global $key;

	global $allow_move;
	global $allow_chmod;
	global $allow_create_file;
	global $allow_create_dir;	
	global $allow_upload;

	global $allow_touch;
	global $allow_delete;

	################## Load directory into array
	$handle=opendir(".");
	while ($file = readdir($handle))
		{
		if(is_file($file)) $filelist[] = $file;
		}
	closedir($handle);

	############### List files
	if($filelist)
		{
		############### Sort the filelist alphabetically
		asort($filelist);
		while (list ($key, $file) = each ($filelist))
			{

			############### Registered filetypes. You can add more filetypes here at wish..
			############### Check what fileformat it is and give it the correct icon and attributes
			$ext = strrchr ( $file , "." );

			############### Image
			if((!strcasecmp ($ext, ".gif")) || (!strcasecmp ($ext, ".jpg")) || (!strcasecmp ($ext, ".png")) || (!strcasecmp ($ext, ".bmp")) || (!strcasecmp ($ext, ".jpeg")))
				{
				$icon = "<IMG SRC=\"image.gif\" alt=\"fichier Image\" border=\"0\" width=\"16\" height=\"16\">";
				$browse = "1";
				$raw = "0";
				$image = "1";
				}
	
			############### Textfile
			elseif(!strcasecmp ($ext, ".txt"))
				{
				$icon = "<IMG SRC=\"text.gif\" alt=\"fichier Texte\" border=\"0\" width=\"13\" height=\"16\">";
				$browse = "1";
				$raw = "1";
				$image = "0";
				}
		
			############### Audiofile
			elseif((!strcasecmp ($ext, ".wav")) || (!strcasecmp ($ext, ".mp2")) || (!strcasecmp ($ext, ".mp3")) || (!strcasecmp ($ext, ".mp4")) || (!strcasecmp ($ext, ".vqf")) || (!strcasecmp ($ext, ".midi")) || (!strcasecmp ($ext, ".mid")))
				{
				$icon = "<IMG SRC=\"audio.gif\" alt=\"Format audio - fichier son\" border=\"0\" width=\"16\" height=\"16\">";
				$browse = "1";
				$raw = "0";
				$image = "0";
				}

			############### Webscript
			elseif((!strcasecmp ($ext, ".phps")) || (!strcasecmp ($ext, ".php")) || (!strcasecmp ($ext, ".php2")) || (!strcasecmp ($ext, ".php3")) || (!strcasecmp ($ext, ".php4")) || (!strcasecmp ($ext, ".phtml")) || (!strcasecmp ($ext, ".asp")) || (!strcasecmp ($ext, ".asa")) || (!strcasecmp ($ext, ".cgi")) || (!strcasecmp ($ext, ".shtml")) || (!strcasecmp ($ext, ".pl")))
				{
				$icon = "<IMG SRC=\"webscript.gif\" alt=\"Script ex'cut' par le serveur\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "1";
				$raw = "1";
				$image = "0";
				}

			############### Apache Webserver security settings
			elseif(!strcasecmp ($ext, ".htaccess"))
				{
				$icon = "<IMG SRC=\"security.gif\" alt=\"Fichier de s'curit' du serveur Apache (configuration)\" border=\"0\" width=\"15\" height=\"16\">" ;
				$browse = "0";
				$raw = "1";
				$image = "0";
				}

			############### Web page
			elseif ((!strcasecmp ($ext, ".html")) || (!strcasecmp ($ext, ".htm")))
				{
				$icon = "<IMG SRC=\"webpage.gif\" alt=\"Page web HTML\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "1";
				$raw = "1";
				$image = "0";
				}

			############### WAP page
			elseif(!strcasecmp ($ext, ".wml"))
				{
				$icon = "<IMG SRC=\"webscript.gif\" alt=\"WAP page\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "1";
				$image = "0";
				}

			############### Compressed file
			elseif((!strcasecmp ($ext, ".zip")) || (!strcasecmp ($ext, ".tar")) || (!strcasecmp ($ext, ".rar")) || (!strcasecmp ($ext, ".gz")))
				{
				$icon = "<IMG SRC=\"text.gif\" alt=\"Fichier compress'\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "0";
				$raw = "0";
				$image = "0";
				}
			
			############### Unknown
			else
				{ 
				$icon = "<IMG SRC=\"text.gif\" alt=\"Extension non répertorié par l'application\" border=\"0\" width=\"15\" height=\"15\">";
				$browse = "1";
				$raw = "1";
				$image = "0";
				}
			
			############### List the file(s)
			$filename=$basedir.$wdir.$file;
			$fileurl=rawurlencode($wdir.$file);
			if(is_file($file))
			  { 
			    $nom = basename ($file); 
				//echo ">>>>> " .$nom;
			    $lastchanged = filectime($nom);
				$changeddate = date("d-m-Y H:i:s", $lastchanged);
			}
			echo "<TR>";
			echo "<TD align=\"center\" nobreak>";
			
			############### Make the fileicon clickable for quickviewing
			if($raw == "1")
				{
				echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&object=file&browse=$browse&raw=$raw\">";
				}
			
			if($image == "1")
				{
				echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image&object=file&browse=$browse&raw=$raw\">";
				}
			
			echo "$icon</TD>\n";
			echo "<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" . htmlspecialchars($file) . "</font></TD>\n";
			echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
			echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
		
			############### CHMOD file?
			if($allow_chmod == "yes")
				{
				echo "<A HREF=\"$PHP_SELF?action=chmod&wdir=$wdir&file=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\" title=\"Change le niveau des permissions du fichier : $file\">";
				}
			
			echo "<font size =\"-1\" face=\"arial, helvetica\">";
			if(is_file($filename))
			{printf("%o", (fileperms($filename)) & 0777);
			}
			echo "</font>";
	
			if($allow_chmod == "yes")
				{
				echo "</A>";
				}
	
			echo "</TD><TD nobreak>";
				
			############### Move file?
			if($allow_move == "yes")
				{
				echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl&object=file&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"move.gif\" alt=\"Déplace, renomme ou copie le fichier : $file\" border=\"0\" width=\"15\" height=\"15\"></A> ";
				}
		
			############### Touch file?
			if($allow_touch == "yes")
				{
				echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\" width=\"12\" height=\"16\"></A> ";
				}

			############### Delete file?
			if($allow_delete == "yes")
				{
				echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"delete.gif\" alt=\"Effacer le fichier : $file\" border=\"0\" width=\"20\" height=\"16\"></A> ";
				}
	
			############### If the file can be browsed, give it the browse icon
			if($browse == "1")
				{
				echo " <A HREF=\"$wdir$file\"><img src=\"browse.gif\" alt=\"Affiche dans le navigateur : $file\" border=\"0\" width=\"16\" height=\"16\"></A> ";
				}

			############### If the file can be edited, give it the edit icon
			if($raw =="1")
				{
				echo " <A HREF=\"$PHP_SELF?wdir=$wdir&action=edit&display=1&file=$fileurl&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\"><img src=\"edit.gif\" alt=\"Edition du fichier : $file\" border=\"0\" width=\"16\" height=\"16\"></A> ";
				}
			}
		}
	}

### liste des objets (tableau contenant les repertoires ou les fichiers)
function displaydir()
	{
	global $file;
	global $basedir;
	global $wdir;	
	global $allow_create_file;
	global $allow_create_dir;	
	global $allow_upload;
	global $allow_touch;
	global $allow_delete;
	global $allow_move;
	
	global $single;

	html_header();
	
	### haut du listing  
	if(isset($single))
		{
		echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" align=\"center\">";
		}
	else
		{
		echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">";	
		}
	
	echo "<tr>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, helvetica\">Type</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, helvetica\">Nom</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, helvetica\">Taille</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, helvetica\">Modifications</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, helvetica\">Droits</font></th>";
	echo "<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, helvetica\">Action</font></th>";
	echo "</tr>";
	
	################## Load directory into array
	
	if(!isset($single))
		{
		//echo ">>>> " .$single;
		chdir($basedir . $wdir);
		
		//echo "++++++  " .$basedir . $wdir ." ++++ " .getcwd();
		
		$handle=opendir(".");
		while ($file = readdir($handle))
			{
			if(is_dir($file)) $dirlist[] = $file;
			}
		closedir($handle);

		############### List directories first		
		if($dirlist)
			{
			############### Sort alphabetically
			asort($dirlist);
			############### Walk through array
			while (list ($key, $file) = each ($dirlist))
				{
				################## Skip the tiresome "."
				if (!($file == "."))
					{
					$filename=$basedir.$wdir.$file;
					$fileurl=rawurlencode($wdir.$file);
					//$lastchanged = filectime($filename);
					//$changeddate = date("d-m-Y H:i:s", $lastchanged);
					echo "<TR>";

					############### Print PARENT arrow
					if($file == "..")
						{
						$downdir = dirname("$wdir");
						echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"parent.gif\" alt=\"Répertoire parent\" border=\"0\" width=\"20\" height=\"16\"></a></TD>\n";
						echo "<TD></TD>\n";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
						//printf("%o", (fileperms($filename)) & 0777);
						if(is_file($filename))
						{printf("%o", (fileperms($filename)) & 0777);
						}
						echo "</TD><TD nobreak>";
						echo "<A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"parent.gif\" alt=\"Répertoire parent\" border=\"0\" width=\"20\" height=\"16\"></A> ";
						}

					############### List the directory
					else
						{
						
						//$lastchanged = filectime($filename);
						echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$fileurl\"><img src=\"folder.gif\" alt=\"Changement de destination : répertoire vers $file\" border=\"0\" width=\"15\" height=\"13\"></a></TD>\n";
						echo "<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" . htmlspecialchars($file) . "</font></TD>\n";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
						echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
						echo "<A HREF=\"$PHP_SELF?action=chmod&file=$filename\" title=\"Change le niveau des permissions du fichier : $file\"><font size =\"-1\" face=\"arial, helvetica\">";
						//printf("%o", (fileperms($filename)) & 0777);
						if(is_file($filename))
						{printf("%o", (fileperms($filename)) & 0777);
						}
						echo "</A>";
						echo "</font></TD><TD nobreak>";

						############### Move directory?
						if($allow_move == "yes")
							{
							echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><img src=\"move.gif\" alt=\"Renomme le fichier : $file\" border=\"0\" width=\"15\" height=\"15\"></A> ";
							}
						
						############### Touch directory?
						if($allow_touch == "yes")
							{
							echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\" width=\"12\" height=\"16\"></A> ";
							}

						############### Delete directory?
						if($allow_delete == "yes")
							{
							echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><img src=\"delete.gif\" alt=\"Supprime le fichier : $file\" border=\"0\" width=\"20\" height=\"16\"></A> ";
							}
						}
					}	
				}
			}
		list_files();
		echo "</TD></TR>\n";
		echo "</TABLE>";

		############### Display forms for different actions
		echo "<table border=\"0\" width=\"100%\">";
		echo "<TR><TD colspan=\"2\"><hr></td>";

		############### Upload file
		if($allow_upload  == "yes")
			{
			echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Upload file</font></td><td>";
			echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT NAME=\"userfile\" TYPE=\"file\" size=\"40\">";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"upload\" VALUE=\"Go!\"></TD></TR>";
			echo "</FORM>";
			}

		############### création d'un répertoire
		if($allow_create_dir == "yes")
			{
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";	
			echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Créer un répertoire</font></td><td>";
			echo "<INPUT TYPE=\"TEXT\" NAME=\"mkdirfile\" size=\"40\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"mkdir\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"mkdir\"  VALUE=\"VALIDER\"></TD></TR>";
			echo "</FORM>";
			}

		############### création d'un fichier
		if($allow_create_file == "yes")
			{
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
			echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Créer un fichier</font></td><td>";
			echo "<INPUT TYPE=\"TEXT\" NAME=\"file\" size=\"40\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\"> ";
			//echo "<input type=\"checkbox\" name=\"html\" value=\"yes\"><font size =\"-2\" face=\"arial, helvetica\">(html template)</font> ";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"createfile\" VALUE=\"VALIDER\">";
			echo "</TD></TR>";
			echo "</FORM>";
			}
		echo "</TABLE>";
		}

	else
		{
		list_files();
		}
	}



#########################################################################################################
############### The user pressed CANCEL, set the $action to nothing
if($cancel) $action="";

############### User has entered .. as directory. Potential security breach. Deny access.
$regexp="\\.\\.";
if (ereg( $regexp, $file, $regs )| ereg( $regexp, $wdir,$regs ))
{
    $lastaction = "ERROR: Directories may not contain the character \"..\"";
    html_header();
    exit;
}

############### Upload file
if($upload) 
	{
	copy($userfile,$basedir.$wdir.$userfile_name); 
		$lastaction = "Uploaded $userfile_name to $wdir";
		html_header();
		displaydir();
		exit;
	}

#########################################################################################################
############### Begin actions code
switch ($action)
{

#########################################################################################################
############### 	aucune action - affichage initial	
	case "":
		$lastaction = "Résultat de l'action ->>> Contenu du repertoire";
		echo "TRACE";
		
		html_header();
		displaydir();
		break;


#########################################################################################################
############### aide en ligne
	case "help":
		$lastaction = "Aide contextuelle";
		html_header();
		echo("Voici la page d'aide, le reste viendra plus tard");
            	break;

#########################################################################################################
############### passage en mode root
	/*case "root":
   		$wdir="/";
		$lastaction = "Répertoire réserver exclcusivement à l'administrateur";
		html_header();
		displaydir();
		break;*/

#########################################################################################################
############### affiche le tableau - PHP env
	case "env":
		if($allow_display_env == "no")
			{
			$lastaction = $not_allowed;
			html_header();
			displaydir();
			}
		else
			{
	   		$lastaction = "Affiche le fichier PHP.ini du serveur ( içi free.fr)";
			html_header();
			phpinfo();
			
			}
		break;

#########################################################################################################
############### change de repertoire 
	case "chdr":
	
	//$basedir
		//$wdir=$file."/";
		//echo "dfggg " .$basedir ."/Docs";
		
/*		echo '</br>';
		echo '********************************';
		echo '</br>';
		echo "Variable " .$file;
		echo '</br>';
		echo '********************************';
		echo '</br>';
		
		if($file == ".")
		{ $file = "";
		}
		echo '</br>';
		echo '********************************';
		echo '</br>';
		$changement = $_SESSION['repertoire'] .$file;
		echo "Changement " .$changement;
		echo '</br>';
		echo '********************************';
		echo '</br>';
		
		
		
		$wdir = chdir($changement);
		$wdir = getcwd();
		
		/*echo '</br>';
		echo '********************************';
		echo '</br>';
		echo "Memoire " .$stocke_rep;
		$wdir = $stocke_rep .'/Docs';*/
		
/*		echo '</br>';
		echo '********************************';
		echo '</br>';
		echo $wdir;
		echo '</br>';
		echo '********************************';
		echo '</br>';
		echo '</br>';
		echo '</br>';
		echo '</br>';
		echo "Downdir " .dirname("$wdir");
		
		$basedir = $_SESSION['repertoire'];
		
		$lastaction = "Résultat de l'action ->>> Change de répertoire -> $wdir";
		//html_header();
		displaydir();
		break;*/
		
		
		$wdir=$file."/";
		
		$lastaction = "Changed directory to $wdir";
		html_header();
		displaydir();
		echo $html_ender;


#########################################################################################################
############### Touch object (create a new timestamp)
	case "touch":
		if($allow_touch == "no")
			{
			$lastaction = $not_allowed;
			html_header();
			displaydir();
			}
		else
			{
			touch($basedir.$touchfile);
			$lastaction = "Touched $touchfile";
			html_header();
			displaydir();
			}
		break;


#########################################################################################################
############### supprime un fichier ou un repertoire

	case "del":
		############### a se stade, l'utilisateur a confirmer la suppression
		if ($confirm)
			{
			
			############### l'objet est un repertoire
			if(is_dir($basedir.$file))
				{
				rmdir($basedir.$file);
				}

			############### Object is a file
			else
				{
				unlink($basedir.$file);
				}
			$lastaction = ">>> Suppression du fichier: $file";
			html_header();
			displaydir();
			}

		############### confirmation
		else
			{
			if($raw == "1")
				{
				$lastaction = "Etes vous sur de vouloir supprimer le fichier :<br><A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\" title=\"Afficher le contenu du fichier\">$file</a>?";
				}
			elseif($image == "1")
				{
				$lastaction = "Etes vous sur de vouloir supprimer le fichier : <br><A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\" title=\"Voir l'image\">$file</a>?";
				}
			else
				{
				$lastaction = "Etes vous sur de vouloir supprimer le fichier :<<br>$file?";
				}

			html_header();
			echo "<center><b><font size =\"5\" face=\"arial, helvetica\"><A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$file&confirm=1\">Ok!</A></font><br>";
			echo "<p><font size =\"5\" face=\"arial, helvetica\"><A HREF=\"$PHP_SELF?wdir=$wdir\">Non!</A></font><br><b></center>";
			}
		
		break;

#########################################################################################################
############### droit des fichiers

	case "chmod":

		############### The user has confirmed
		if ($confirm)
			{
			$level = "0";
			$level .= $owner;
			$level .= $group;
			$level .= $public;
			$showlevel = $level;
			$level=octdec($level);
			chmod($basedir.$file,$level);
			$lastaction = "Fixer des droits liés au fichier: $file -> $showlevel";
			html_header();
			displaydir();
			}

		############### Prompt the user for confirmation
		else
			{
			$lastaction = "Change le niveau des permissions du fichier : $file";
			html_header();			
			echo "<font face=\"arial, helvetica\"><center><h4>Droits actuel::: ";
			printf("%o", (fileperms($basedir.$file)) & 0777);
			echo "</h4><FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
			
			function selections($type)  //  type: 0 Owner, 1 Group, 2 Public
				{
				echo "<option value=\"0\""; if (substr($GLOBALS["perm"], $type, 1)=="0") echo "Choix:"; echo ">0 - Aucune permissions";
				echo "<option value=\"1\""; if (substr($GLOBALS["perm"], $type, 1)=="1") echo "Choix:"; echo ">1 - Execute";
				echo "<option value=\"2\""; if (substr($GLOBALS["perm"], $type, 1)=="2") echo "Choix:"; echo ">2 - Write ";
				echo "<option value=\"3\""; if (substr($GLOBALS["perm"], $type, 1)=="3") echo "Choix:"; echo ">3 - Execute & Write";
				echo "<option value=\"4\""; if (substr($GLOBALS["perm"], $type, 1)=="4") echo "Choix:"; echo ">4 - Read";
				echo "<option value=\"5\""; if (substr($GLOBALS["perm"], $type, 1)=="5") echo "Choix:"; echo ">5 - Execute & Read";
				echo "<option value=\"6\""; if (substr($GLOBALS["perm"], $type, 1)=="6") echo "Choix:"; echo ">6 - Write & Read";
				echo "<option value=\"7\""; if (substr($GLOBALS["perm"], $type, 1)=="7") echo "Choix:"; echo ">7 - Write, Execute & Read";
				echo "</select>";
				}
			
			$perm = sprintf ("%o", (fileperms($basedir.$file)) & 0777);  // Definition of a variable containing the file permissions
			echo "<p><h4>Propriétaire (Owner)<br>";
			echo "<select name=\"owner\">";
			selections(0);

			echo "<p>Groupe<br>";
			echo "<select name=\"group\">";
			selections(1);

			echo "<p>Public<br>";
			echo "<select name=\"public\">";
			selections(2);

			echo "</h4>";
			echo "<p>";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Change\">\n";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Annuler\">\n";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"chmod\">\n";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "</FORM>";
			echo "</center>";
			}
		
		break;

#########################################################################################################
############### deplacer un fichier dans l'arborescence

	case "move":
		############### 
		if($confirm && $newfile)
 			{
			############### The destination object exists
    			if(file_exists($basedir.$newfile))
				{
				$lastaction = "Résultat de l'action ->>> Le fichier existe déjà, choisir une autre destination ou alors renomer le fichier.";
				}
			else
				{
				if($do == copy)
					{
					copy($basedir.$file,$basedir.$newfile);
					$lastaction = "Résultat de l'action ->>> Copie\n$file -> $newfile";
					}
				else
					{
					rename($basedir.$file,$basedir.$newfile);
					$lastaction = "Résultat de l'action ->>> Déplace/renomme\n$file -> $newfile";
					}
				}
			html_header();
			displaydir();
    			
			}

		############### Prompt the user for destination name and action
		else
			{
			if($object == "file")
				{
				if($raw == "1")
					{
					$lastaction = "Résultat de l'action ->>> Déplacer/renomer ou copier <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\" title=\"Voir le contenu du fichier\">$file</a>";
					}
				elseif($image == "1")
					{
					$lastaction = "Résultat de l'action ->>> Déplacer/renomer ou copier : <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\" title=\"Voir l'image\">$file</a>";
					}
				else
					{
					$lastaction = "Résultat de l'action ->>> Déplacer/renomer ou copier le fichier : $file";
					}

				html_header();
				echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
				echo "<select name=\"do\">";
				echo "<option value=\"copy\">Copie";
				echo "<option value=\"move\">Déplace/renomme";
				echo "</select> ";
				echo "Le fichier : ($file)";
				echo "<h4>Vers</h4>";
				echo "<INPUT TYPE=\"TEXT\" NAME=\"newfile\" value=\"$file\" size=\"40\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";			
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
				echo "<p>";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Appliquer\">\n";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Annuler\">\n";
				echo "</FORM>";
				
				}
			else
				{
				$lastaction = ">>> Nouveau nom pour le fichier : $file";

				html_header();
				echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
				echo "<h4>Renomme</h4>";
				echo "$file";
				echo "<h4>En</h4>";
				echo "<INPUT TYPE=\"TEXT\" NAME=\"newfile\" value=\"$file\" size=\"40\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
				echo "<p>";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Appliquer\">\n";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Annuler\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"do\" VALUE=\"move\">\n";
				echo "</FORM>";
				
				}
			}
		break;

#########################################################################################################
############### Edit file
	case "edit":

		############### Function for saving the file.
		function savefile()
			{
			global $basedir;
			global $file;
			global $code;
			html_header();
			$fp=fopen($basedir.$file,"w");
			fputs($fp,stripslashes($code));
			fclose($fp);
			}

		function buttons()
			{
			global $file;
			global $wdir;
			
			echo "<center>";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"edit\">";
			echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
			echo "<INPUT TYPE=\"RESET\" VALUE=\"Restore l'original\"> ";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"save\" VALUE=\"Sauve\"> ";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"saveexit\" VALUE=\"Sauve & Retour\"> ";
			echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Annuler / Retour\"> ";
			echo "</center><BR>\n";
			}
					 
		############### The user is done editing. Return to main screen
		if($saveexit)
   			{
    			$lastaction = "Résultat de l'action ->>> Edite le fichier : <a href=\"$file\" title=\"Voir le fichier\">$file</a>";
			savefile();
			displaydir();
			}

		############### Save the file, but continue editing.
		if($save)
   			{
    			$lastaction = "Résultat de l'action ->>> Sauve le fichier : <a href=\"$file\" title=\"Voir le fichier\">$file</a>, ( en cours d'édition).";
			savefile();
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
			$fp=fopen($basedir.$file,"r");
			$contents=fread($fp,filesize($basedir.$file));
			echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
			echo htmlspecialchars($contents);
			echo "</TEXTAREA><BR>\n";
			echo "<center>";
			buttons();
			echo "</FORM>";
			}

		############### Display file in textarea
		if($display)
			{
			if($raw == "1")
				{
				$lastaction = "Edition du fichier : <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$file&browse=$browse&raw=$raw&image=$image&fileurl=$fileurl\" title=\"Voir le contenu du fichier (impossible de modifier)\">$file</a>";
				}
			elseif($image == "1")
				{
				$lastaction = "Edition du fichier : <A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\" title=\"View the image\">$file</a>";
				}
			else
				{
				$lastaction = "Edition du fichier : $file";
				}
	
			html_header();
			echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
			$fp=fopen($basedir.$file,"r");
			$contents=fread($fp,filesize($basedir.$file));
			echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
			echo htmlspecialchars($contents);
			echo "</TEXTAREA><BR>\n";
			buttons();
			echo "</FORM>";
			}
		
		break;

		
#########################################################################################################
############### Display file
	case "show":

		############### Display file in textformat
		$filelocation = $wdir.$file;	
		//$str = stripslashes($file);  
		//echo $str;
		$str = basename($file);
		$lastaction = ">>> Visualisation du fichier : $str";
		html_header();

		############### It is a picture, display it. The filename needs to be either relative to the current document, or an absolute filesystem path. 
		if($image == "1")
			{
			//echo $DOCUMENT_ROOT ." + " .$file;
			//$size = GetImageSize($DOCUMENT_ROOT.$file);
			$source = basename($file);
			$source = getcwd();
			//$source = $basedir ."/" .$source;
			//echo "Source  " . $wdir;
			
			$source = "/homez.65/analogde/www/WORKAREA/WEBSITE/Users/lucien/rep1/Desert.jpg"; // .$file;
			
			echo $source;
			
			$size = GetImageSize($source);
			echo "<center><img src=\"$source\" $size[3]></center>";
			}

		############### It is text, display it.
		else
			{
			$single = "yes";
#			displaydir();
			echo"<hr><br>";
			show_source($basedir.$file);
			}
		
		break;

#########################################################################################################
############### Create directory
	case "mkdir":
		
		############### Is the action allowed?
		if($allow_create_dir == "no")
			{
			$lastaction = $not_allowed;
			html_header();
			}
		else
			{
			############### The directory already exists. 
			if(file_exists($basedir.$wdir.$mkdirfile))
				{
				$lastaction = "Résultat de l'action ->>> Le répertoire $wdir$mkdirfile existe déjà.";
				html_header();
				}

			############### Create directory
			else
				{
				$lastaction = "Résultat de l'action ->>> Création du répertoire $wdir$mkdirfile";
				html_header();
				mkdir($basedir.$wdir.$mkdirfile,0750);
				}
			displaydir();
			
			}
		break;

#########################################################################################################
############### Create file
	case "createfile":
		$filelocation = $wdir.$file;

		############### The user is done editing. Return to main screen
		if($done == "1")
   			{
			$lastaction = "Résultat de l'action ->>> Le fichier : $file vient d'être créer.";
			html_header();

#			if($convert == "yes")
#   				{
#				$code = str_replace ("\n", "<BR>");
#				}
		
			$fp=fopen($basedir.$filelocation,"w");
			fputs($fp,stripslashes($code));
      			fclose($fp);
			displaydir();
			}

		############### Display a textarea that will be the file
		else
			{

   			############### The file allready exists
   			if(file_exists($basedir.$filelocation))
   				{
   				$lastaction = "Résultat de l'action ->>> Le fichier $file exite déjà. !!!";
				html_header();
				displaydir();
				}

			############### Give the user a textarea to write the contents of file
			else
				{
				$lastaction = "Résultat de l'action ->>> Création du fichier : $file";
				html_header();
				echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
				echo "<INPUT TYPE=\"HIDDEN\" NAME=\"done\" VALUE=\"1\">\n";
				echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";

				############### The user selected to use a html template. Put it inside the textarea
				if(isset($html))
					{
					
					echo "<html>\n";
					echo "<head>\n\n";
					echo "<title>Sans nom</title>\n";
					echo "</head>\n";
					echo "<body>\n\n";
					echo "</body>\n";
					echo "</html>";
					}
				echo "</TEXTAREA><BR>\n";
				echo "<center><INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Créer\">\n";
				echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Annuler\"><br>";
				$ext = strrchr ( $file , "." );
				if(!strcasecmp ($ext, ".txt"))
					{
					echo "<input type=\"checkbox\" name=\"convert\" value=\"yes\"><font size =\"-2\" face=\"arial, helvetica\">(convert line returns to BR)</font> ";					
					}
				echo "</center><BR>\n</FORM>";
				}
			}
		
		break;
}
?>