<?php
require_once PHYSICAL_DIR."/config/config.php";
//echo $_SESSION['path'];die;
global $customehtm;
$customehtm="<select name='dirlist' class='selectcss' id='dirlist' style='width: 588px ! important;'>";
$customehtm.="<option value=''>select..</option>";
function getDirectory( $path = '.', $level = 0 , &$parentnode='', &$result)
{
global $customehtm;
$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;
//$parentnode= str_replace('$'.$file,'',$parentnode);
if($level>0)
{
$customehtm.="</optgroup>";
}
$customehtm.="<optgroup label=\"$spaces$file\">";
$optgroup=$file;
getDirectory( "$path/$file", ($level+1),$parentnode,$result );
// Re-call this same function but on a new directory.
// this is what makes function recursive.
}
else
{
if($path.'/'.$file == $_SESSION['path'])
$customehtm.="<option OptionGroup=\"$optgroup\" value=\"$path/$file\" selected>$spaces$file</option>";
else
$customehtm.="<option OptionGroup=\"$optgroup\" value=\"$path/$file\">$spaces$file</option>";
//echo "$spaces $file<br />";
// Just print out the filename
}
}
}
closedir( $dh );
// Close the directory handle
}
$parentnode='';
$result = '';
$dirname=PHYSICAL_DIR."/"."email_attachements";
getDirectory($dirname,0,$parentnode,$result);
$customehtm.="</optgroup></select>";
$cus.=$customehtm;
echo $customehtm;
unset($_SESSION['path']);
?>