Alternc  latest
Alternc logiel libre pour l'hébergement
browseforfolder2.php
Go to the documentation of this file.
1 <?php
2 /*
3  ----------------------------------------------------------------------
4  LICENSE
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License (GPL)
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  To read the license please visit http://www.gnu.org/copyleft/gpl.html
17  ----------------------------------------------------------------------
18 */
19 
20 /**
21  * An HTML page to browse for a folder on a remote server and choose it using
22  * Javascript. Chroot the user to its root,
23  *
24  * @copyright AlternC-Team 2000-2017 https://alternc.com/
25  */
26 
27 include("../class/config.php");
28 
29 $fields = array (
30  "caller" => array ("request", "string", ""),
31  "select" => array ("request", "string", ""),
32  "curdir" => array ("request", "string", ""),
33  "lastcurdir" => array ("request", "string", ""),
34  "file" => array ("request", "string", ""),
35  "bid" => array ("request", "string", ""),
36  );
38 
39 /**
40  * @param integer $pos
41  * @param integer $level
42  * @param string $curdir
43  */
44 function _subbrowse($curdir,$pos,$level) {
45  global $maxlevel,$root,$brlist;
46  if ($level>$maxlevel)
47  $maxlevel=$level;
48  $rot=substr($curdir,0,$pos);
49  $next=@strpos($curdir,"/",$pos+1);
50  $nextstr=substr($curdir,$pos+1,$next-$pos-1);
51  $c=opendir($root.$rot);
52  $i=0; $tmp = array();
53  while ($r=readdir($c)) {
54  if (is_dir($root.$rot."/".$r) && $r!="." && $r!="..") { $tmp[$i++]=$r; }
55  }
56  sort($tmp);
57  foreach ($tmp as $r) {
58  /* Ajout */
59  $brlist[]=array("dir"=>$r,"level"=>$level,"put"=> ife($curdir==$rot."/".$r."/","",$rot."/".$r));
60  if ($r==$nextstr) {
61  _subbrowse($curdir,$next,$level+1);
62  }
63  }
64 }
65 
66 /**
67  * @param string $curdir
68  */
69 function browseforfolder($curdir) {
70  global $maxlevel,$root,$brlist;
71  $maxlevel=0;
72  $brlist=array(array("dir"=>"/","level"=>0,"put"=> ife($curdir=="/","","/") ));
73  _subbrowse($curdir,0,1);
74  return $brlist;
75 }
76 
78 // pour utiliser 'la ou est browseforfolder', mettre dirname($HTTP_SERVER_VARS["PATH_TRANSLATED"]);
79 
80 if (substr($file,0,1)!="/") $file="/".$file;
81 if (substr($file,-1)!="/") $file.="/";
82 if (!$file) $file="/";
83 
84 $errbrowsefold=0; /* Erreur lors de la création d'un dossier */
85 $brlist=array(); /* Liste des dossiers ... */
87 ?>
88 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
89 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
90 <head>
91 <title>Recherche d'un dossier</title>
92 <link rel="stylesheet" href="styles/style.css" type="text/css" />
93 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
94 <script src="/javascript/jquery/jquery.min.js" type="text/javascript"></script>
95 <script type="text/javascript">
96 /* Fonction appellée lors du lancement d'un popup Fichier : */
97 function popupfile() {
98  window.focus();
99  if (document.forms["main"].file)
100  document.forms["main"].file.focus();
101 }
102 
103 function addslashes(ch) {
104  ch = ch.replace(/\\/g,"\\\\")
105  ch = ch.replace(/\'/g,"\\'")
106  ch = ch.replace(/\"/g,"\\\"")
107  return ch
108 }
109 
110 /* Fontion de retour de la valeur selectionnee */
111 function retour() {
112  window.parent.jQuery('#<?php echo $caller; ?>').val( $("#file").val() );
113  window.parent.jQuery('#<?php echo $bid; ?>').dialog('close');
114  return false;
115 }
116 
117 </script>
118 </head>
119 <body class="light" onload="popupfile();">
120 <h3><?php __("Searching for a folder"); ?></h3>
121 <?php
122 
124 if ($errbrowsefold) {
125  /* Si le dossier spécifié n'existe pas ou est un fichier : */
126  echo _("Error, cannot find this folder")."<br />";
127  /* Retour : */
128  echo "<a href=\"browseforfolder2.php?caller=".urlencode($caller)."&amp;curdir=".$root."&amp;bid=".$bid."\">"._("Back to the root folder")."</a><br />";
129 } else {
130  /* Sinon, tout va bien, on affiche le tableau */
131  reset($ar);
132  ?>
133  <form method="post" id="main" name="main" action="browseforfolder2.php">
134  <?php csrf_get(); ?>
135  <p>
136  <input type="hidden" name="caller" value="<?php ehe($caller); ?>" />
137  <input type="hidden" name="lastcurdir" value="<?php ehe($curdir); ?>" />
138  <input type="hidden" name="bid" value="<?php ehe($bid); ?>" />
139 
140  <input type="text" class="int" id="file" name="file" size="20" value="<?php ehe($file); ?>" /><br />
141 
142  <input type="button" name="select" value="<?php __("Select"); ?>" class="inb" onclick="retour();" />&nbsp;
143  <input type="button" name="cancel" value="<?php __("Cancel"); ?>" class="inb" onclick="window.parent.jQuery('#<?php ehe($bid); ?>').dialog('close');" />&nbsp;
144  </p>
145  </form>
146 
147  <table style="border: 0" cellspacing="2" cellpadding="0">
148 
149  <?php
150  while (list($key,$val)=each($ar)) {
151  echo "<tr>\n";
152  for ($i=0;$i<$val["level"];$i++)
153  echo "<td width=\"16\"></td>";
154  if ($val["put"]!="") {
155  ?>
156  <td width="16"><img src="icon/folder.png" width="16" height="16" alt="" /></td>
157  <?php
158  } else {
159  ?>
160  <td width="16"><img src="icon/openfold.png" width="16" height="16" alt="" /></td>
161  <?php
162  }
163  echo "<td colspan=\"".($maxlevel-$val["level"]+1)."\">";
164  if ($val["put"]!="") {
165  echo "<a href=\"browseforfolder2.php?caller=".eue($caller,false)."&amp;bid=".eue($bid,false)."&amp;file=".eue($val["put"],false)."\">".ehe($val["dir"],false)."</a>";
166  } else {
167  echo "<b>".ehe($val["dir"],false)."</b>";
168  }
169  echo "</td>\n</tr>\n";
170  }
171 } // OK ?
172 ?>
173 </table>
174 </body>
175 </html>
$c
Definition: bootstrap.php:47
$r
Definition: aws_add.php:75
$errbrowsefold
_subbrowse($curdir, $pos, $level)
browseforfolder($curdir)
$fields
An HTML page to browse for a folder on a remote server and choose it using Javascript.
d($mess)
Debug function that print infos.
Definition: do_actions.php:75
ife($test, $tr, $fa="")
Definition: functions.php:416
ehe($str, $display=TRUE)
Echo the HTMLSpecialChars version of a value.
Definition: functions.php:647
__($str)
Definition: functions.php:404
eue($str, $display=TRUE)
Echo the URLENCODED version of a value.
Definition: functions.php:670
getFields($fields, $requestOnly=false)
Get the Fields of the posted form from $_REQUEST or POST or GET and check their type.
Definition: functions.php:688
getuserpath($user=null)
get the home of the user
Definition: functions.php:329
csrf_get($return=false)
Give a new CSRF uniq token for a form the session must be up since the CSRF is linked to the session ...
Definition: functions.php:1159
$i
$val
Definition: tempovars.php:15
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14