Patch pour une plus zoli boite de sélection de répertoires

This commit is contained in:
Alan Garcia 2013-01-24 11:25:15 +00:00
parent a87d30c7a7
commit e83da9c579
6 changed files with 227 additions and 19 deletions

1
.gitattributes vendored
View File

@ -134,6 +134,7 @@ bureau/admin/bro_pref.php -text
bureau/admin/bro_tgzdown.php -text
bureau/admin/bro_view.php -text
bureau/admin/browseforfolder.php -text
bureau/admin/browseforfolder2.php -text
bureau/admin/cron.php -text
bureau/admin/dom_add.php -text
bureau/admin/dom_defdel.php -text

View File

@ -0,0 +1,174 @@
<?php
/*
Navigateur de dossiers en php. (BrowseForFolder in win32 api :)
Version 1.0
Notes :
Benjamin Sonntag 23/12/2001 Version initiale: n'utilise qu'un seul uid : 1...
Fichier :
browseforfolder.php3 : Dialogue de navigation BrowseForFolder
$caller = composant form appelant (de la forme forms['main'].component )
function browseforfolder(caller) {
eval("file=document."+caller+".value");
w=window.open("browseforfolder.php?caller="+caller+"&file="+file,"browseforfolder","width=300,height=400,scrollbars,left=100,top=100");
}
requires : ife($test,$iftrue,$iffalse) function :
function ife($test,$true,$false="") {
if ($test)
return $true;
else
return $false;
}
BrowseForFolder($curdir); Retourne le tableau avec la liste des dossiers à afficher dans
la fonction browseforfolder sachant que le dossier actuel et curdir
retourne un tableau de tableau de la forme :
dir => "directory" Nom du dossier
level => 0-n Niveau du dossier (0=racine 1,2 ...)
put => "/sub/sub/directory" Contenu de la variable post à ajouter pour la balise A si ="" c'est le dossier courant.
Si probleme, positionne $errbrowsefold
Sinon, retourne le tableau et $maxlevel contient le nombre maximum de sous-dossiers.
*/
include("../class/config.php");
// FIXME Refaire ce truc hein...
$fields = array (
"caller" => array ("request", "string", ""),
"select" => array ("request", "string", ""),
"curdir" => array ("request", "string", ""),
"lastcurdir" => array ("request", "string", ""),
"file" => array ("request", "string", ""),
"bid" => array ("request", "string", ""),
);
getFields($fields);
function _subbrowse($curdir,$pos,$level) {
global $maxlevel,$root,$brlist;
if ($level>$maxlevel)
$maxlevel=$level;
$rot=substr($curdir,0,$pos);
$next=@strpos($curdir,"/",$pos+1);
$nextstr=substr($curdir,$pos+1,$next-$pos-1);
$c=opendir($root.$rot);
$i=0; $tmp = array();
while ($r=readdir($c)) {
if (is_dir($root.$rot."/".$r) && $r!="." && $r!="..") { $tmp[$i++]=$r; }
}
sort($tmp);
foreach ($tmp as $r) {
/* Ajout */
$brlist[]=array("dir"=>$r,"level"=>$level,"put"=> ife($curdir==$rot."/".$r."/","",$rot."/".$r));
if ($r==$nextstr) {
_subbrowse($curdir,$next,$level+1);
}
}
}
function browseforfolder($curdir) {
global $maxlevel,$root,$brlist;
$maxlevel=0;
$pat=explode("/",$curdir);
$brlist=array(array("dir"=>"/","level"=>0,"put"=> ife($curdir=="/","","/") ));
_subbrowse($curdir,0,1);
return $brlist;
}
$root=getuserpath();
// pour utiliser 'la ou est browseforfolder', mettre dirname($HTTP_SERVER_VARS["PATH_TRANSLATED"]);
if (substr($file,0,1)!="/") $file="/".$file;
if (substr($file,-1)!="/") $file.="/";
if (!$file) $file="/";
$errbrowsefold=0; /* Erreur lors de la création d'un dossier */
$brlist=array(); /* Liste des dossiers ... */
$maxlevel=0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Recherche d'un dossier</title>
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
/* Fonction appellée lors du lancement d'un popup Fichier : */
function popupfile() {
window.focus();
if (document.forms["main"].file)
document.forms["main"].file.focus();
}
function addslashes(ch) {
ch = ch.replace(/\\/g,"\\\\")
ch = ch.replace(/\'/g,"\\'")
ch = ch.replace(/\"/g,"\\\"")
return ch
}
/* Fontion de retour de la valeur selectionnee */
function retour() {
window.parent.document.<?php echo $caller; ?>.value = addslashes( $("#file").val() );
window.parent.jQuery('#<?php echo $bid; ?>').dialog('close');
return false;
}
</script>
</head>
<body onload="popupfile();">
<h3><?php __("Searching for a folder ($bid)"); ?></h3>
<?php
$ar=browseforfolder($file);
if ($errbrowsefold) {
/* Si le dossier spécifié n'existe pas ou est un fichier : */
echo _("Error, cannot find this folder")."<br />";
/* Retour : */
echo "<a href=\"browseforfolder2.php?caller=".urlencode($caller)."&amp;curdir=".$root."&amp;bid=".$bid."\">"._("Back to the root folder")."</a><br />";
} else {
/* Sinon, tout va bien, on affiche le tableau */
reset($ar);
?>
<form method="post" id="main" name="main" action="browseforfolder2.php">
<p>
<input type="hidden" name="caller" value="<?php echo $caller; ?>" />
<input type="hidden" name="lastcurdir" value="<?php echo $curdir; ?>" />
<input type="hidden" name="bid" value="<?php echo $bid; ?>" />
<input type="text" class="int" id="file" name="file" size="20" value="<?php ehe($file); ?>" /><br />
<input type="button" name="select" value="<?php __("Select"); ?>" class="inb" onclick="retour();" />&nbsp;
<input type="button" name="cancel" value="<?php __("Cancel"); ?>" class="inb" onclick="window.parent.jQuery('#<?php echo $bid; ?>').dialog('close');" />&nbsp;
</p>
</form>
<table style="border: 0" cellspacing="2" cellpadding="0">
<?php
while (list($key,$val)=each($ar)) {
echo "<tr>\n";
for ($i=0;$i<$val["level"];$i++)
echo "<td width=\"16\"></td>";
if ($val["put"]!="") {
?>
<td width="16"><img src="icon/folder.png" width="16" height="16" alt="" /></td>
<?php
} else {
?>
<td width="16"><img src="icon/openfold.png" width="16" height="16" alt="" /></td>
<?php
}
echo "<td colspan=\"".($maxlevel-$val["level"]+1)."\">";
if ($val["put"]!="") {
echo "<a href=\"browseforfolder2.php?caller=".urlencode($caller)."&amp;bid=".$bid."&amp;file=".urlencode($val["put"])."\">".$val["dir"]."</a>";
} else {
echo "<b>".$val["dir"]."</b>";
}
echo "</td>\n</tr>\n";
}
} // OK ?
?>
</table>
</body>
</html>

View File

@ -80,11 +80,8 @@ $dom->unlock();
break;
case "DIRECTORY": ?>
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="28" />
<script type="text/javascript">
<!--
document.write("&nbsp;<input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.t_<?php echo $dt['name'];?>');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
// -->
</script><?php
<?php display_browser( $targval , "main.t_".$dt['name'] ); ?>
<?php
break;
case "URL": ?>
<input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe( (empty($targval)?'http://':$targval) ); ?>" size="50" />

View File

@ -73,11 +73,9 @@ if (isset($error) && $error) {
<th><label for="dir"><?php __("Folder"); ?></label></th>
<td>
<input type="text" class="int" name="dir" id="dir" value="<?php empty($dir)?@ehe("/".$r[0]["dir"]):@ehe($dir); ?>" size="20" maxlength="64" />
<script type="text/javascript">
<!--
document.write("&nbsp;<input type=\"button\" name=\"bff\" onclick=\"browseforfolder('main.dir');\" value=\" <?php __("Choose a folder..."); ?> \" class=\"bff\">");
// -->
</script>
<?php display_browser( empty($dir)?("/".$r[0]["dir"]):$dir , "main.dir" ); ?>
<p><?php __("This is the root folder for this FTP user. i.e. this FTP user can access to this forlder and all its sub-folders."); ?></p>
</td>
</tr>
<tr>

View File

@ -91,12 +91,8 @@ if (is_array($r)) {
</tr>
<tr>
<th><label for="bck_dir"><?php __("In which folder do you want to store the backups?"); ?></label></th>
<td><input type="text" class="int" name="bck_dir" id="bck_dir" size="30" maxlength="255" value="<?php ehe($r["dir"]); ?>" />
<script type="text/javascript">
<!--
document.write("&nbsp;<input type=\"button\" name=\"bff\" class=\"bff\" onclick=\"browseforfolder('main.bck_dir');\" value=\" <?php __("Choose a folder..."); ?> \" />");
// -->
</script>
<td><input type="text" class="int" name="bck_dir" id="bck_dir" size="30" maxlength="255" value="<?php @ehe($r["dir"]); ?>" />
<?php display_browser( $r["dir"] , "main.bck_dir" ); ?>
</td>
</tr>

View File

@ -433,11 +433,15 @@ function eoption($values,$cur,$info="") {
* <input type="text" name="toto" value="<?php ehe($toto); ?>" />
* Use the charset of the current language for transcription
*/
function ehe($str) {
function ehe($str,$affiche=1) {
global $charset;
echo htmlspecialchars($str,ENT_QUOTES,$charset);
$retour = htmlspecialchars($str,ENT_QUOTES,$charset);
if ($affiche) {
echo $retour;
} else {
return $retour;
}
}
/* Get the Fields of the posted form from $_REQUEST or POST or GET
* and check their type
@ -602,6 +606,7 @@ function create_pass($length = 8){
define("DEFAULT_PASS_SIZE", 8);
/* Affiche un bouton qui permet de generer automatiquement des mots de passes */
function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_fill1="", $fields_to_fill2="") {
$id=rand(1,1000);
echo "<div id='$id' style='display:none;'><a href=\"javascript:generate_password_html('$id',$pass_size,'$fields_to_fill1','$fields_to_fill2');\">";
@ -611,5 +616,42 @@ function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_
return 0;
}
/* Affiche un bouton pour selectionner un dossier sur le serveur */
function display_browser($dir="", $caller="main.dir", $width=350, $height=450) {
// Browser id
$bid="b".rand(1,1000);
echo "<script type=\"text/javascript\">
<!--
$(function() {
$( \"#".$bid."\" ).dialog({
autoOpen: false,
width: ".$width.",
height: ".$height.",
modal: true,
open: function()
{
$('.ui-widget-overlay').css('opacity', .70);
},
});
$( \"#bt".$bid."\" )
.button()
.click(function() {
$( \"#".$bid."\" ).dialog( \"open\" );
return false;
});
});
document.write('&nbsp;<input type=\"button\" id=\"bt".$bid."\" value=\""._("Choose a folder...")."\" class=\"bff\">');
document.write('<div id=\"".$bid."\" title=\""._("Choose a folder...")."\">');
document.write(' <iframe src=\"/browseforfolder2.php?caller=".$caller."&file=".ehe($dir, 0)."&bid=".$bid."\" width=\"".($width-25)."\" height=\"".($height-50)."\" frameborder=\"no\" id=\"browseiframe\"></iframe>');
document.write('</div>');
// -->
</script>
";
}
?>