<?php
require_once "../../config/config.php";
function getFilePermission($filename)
{
//$filename="\"".PHYSICAL_DIR.$filename."\"";
$perms = fileperms($filename);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
return $info;
}
function getDirectory( $path = '.', $level = 0 , &$parentnode='', &$result)
{
$ignore = array( 'cgi-bin', '.', '..' );
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.
$dh = @opendir( $path );
// Open the directory to the handle $dh
$style='';
while( false !== ( $file = readdir( $dh ) ) ){
// Loop through the directory
if( !in_array( $file, $ignore ) ){
// Check that this file is not to be ignored
$spaces = str_repeat( ' ', ( $level * 4 ) );
// Just to add spacing to the list, to better
// show the directory tree.
if( is_dir( "$path/$file" ) ){
// Its a directory, so we need to keep reading down...
if($level==0)
{
$style="font-family:Verdana,Arial,Helvetica,Sans-serif;font-size:10px;";
//$parentnode=='';
$parentnode=$file.'$';
}
else
{
$style="font-family:Verdana,Arial,Helvetica,Sans-serif;font-size:10px;display:none;";
if(strpos($parentnode,'$')>0)
{
$parentnodearr = explode('$',$parentnode);
$parentnode='';
$iparentnodearrloop=0;
foreach($parentnodearr as $key=>$value)
{
if($iparentnodearrloop<$level)
$parentnode .= $value.'$';
$iparentnodearrloop+=1;
}
$parentnode = substr($parentnode,0,strlen($parentnode)-1);
}
$parentnode= $parentnode.'$'.$file.'$';
}
//($parentnode=='')?($parentnode=$file.$level):($parentnode='childof'.$parentnode);
$pathoffile=$path."/".$file;
$permission=getFilePermission($pathoffile);
$result .= "<tr id=\"$parentnode\" name=\"$parentnode\" style=\"$style\"><td>$spaces<img id=\"img{$parentnode}\" onclick=\"opennodes('$parentnode');\" src=\"images/add.gif\" alt=\"$spaces $file\">
<span id=\"spn{$parentnode}\" onclick=\"return CustomFunction('$parentnode')\">
$file
</span>
</td>
<td>$permission</td>
</tr>\r\n";
//$parentnode= str_replace('$'.$file,'',$parentnode);
getDirectory( "$path/$file", ($level+1),$parentnode,$result );
// Re-call this same function but on a new directory.
// this is what makes function recursive.
}
/*
else
{
echo "$spaces $file<br />";
// Just print out the filename
}
*/
}
}
closedir( $dh );
// Close the directory handle
return $result;
}
$parentnode='';
$result = '';
echo "<div style=\"height:500;width:400px;border:solid 1px \#000000;overflow:auto\"><table id=\"treeviewtable\">".getDirectory(PHYSICAL_DIR,0,$parentnode,$result)."</table></div>";
?>
<script language="javascript" type="text/javascript">
function opennodes(parentNodeId)
{
var parentNode= document.getElementById(parentNodeId);
var parentNodeImg = document.getElementById('img'+parentNodeId);
var treeviewtable_tbody_childnodes = parentNode.parentNode.childNodes;
//alert(treeviewtable_tbody_childnodes.length);
var childnodeid='';
if(treeviewtable_tbody_childnodes.length>0)
{
for(i=0;i<treeviewtable_tbody_childnodes.length;i++)
{
childnodeid = treeviewtable_tbody_childnodes[i].id;
if(childnodeid)
{
if(childnodeid.indexOf(parentNodeId)>=0)
{
childnodeid = childnodeid.replace(parentNodeId,'');
if(parentNodeImg.src.indexOf('add.gif')>=0)
{
if(childnodeid.split('$').length==2)
{
treeviewtable_tbody_childnodes[i].style.display='';
}
}
// if "-" node clicked then close all child nodes of child as well
if(parentNodeImg.src.indexOf('subtract.gif')>=0)
{
if(childnodeid.split('$').length>=2)
{
treeviewtable_tbody_childnodes[i].style.display='none';
document.getElementById('img'+treeviewtable_tbody_childnodes[i].id).src='images/add.gif';
}
}
}
}
}
}
//replace image of opened node
if(parentNodeImg.src.indexOf('add.gif')>=0)
parentNodeImg.src='images/subtract.gif';
else
parentNodeImg.src='images/add.gif';
}
function CustomFunction(nodetext)
{
//alert('here');
//parentNode = document.getElementById('parentNodeId').parentNode;
//childNodeText = parentNode.childNodes[0].innerHTML;
//alert(nodetext);
//alert(nodetext.length);
arrnodetext = nodetext.split('$');
nodetext = '';
for(i=0;i<arrnodetext.length;i++)
{
nodetext += arrnodetext[i]+'/';
}
nodetext = '/'+nodetext.substring(0,nodetext.length-2);
if(window.opener)
{
window.opener.document.addform.folder.value=nodetext;
window.close();
}
return false;
}
</script>