<?php
include_once "navtree2.php";
//#-----------------------------------------------------------------
//#---- FUNCTION :: GetFileList($p_dir, $parent_id)
//#---- DESCRIPTION ::
//#---- Read all the file under $p_dir
//#---- The root node id will be the $parent_id
//#---- INPUT ::
//#---- p_dir : root of directory
//#---- Parent_id : node number that contain the tree
//#---- OUTPUT ::
//#---- none
//#---- OTHERS ::
//#-----------------------------------------------------------------
function GetFileList($p_dir="", $parent_id=0, $parent_path="/")
{
global $navtree;
global $file_path;
$dir = $p_dir;
// Open a known directory, and proceed to read its contents
$dh = ( is_dir($dir) ? opendir($dir): FALSE);
if ($dh)
{ while ( ($file = readdir($dh)) !== false )
{ $ftype = filetype("$dir/$file");
if ( $file != "." && $file != ".." )
{ //----- Add a node
if ( $ftype == "dir" || $ftype == "file" )
{
$node_id = $navtree->AddNode($file, $ftype, $parent_id, 0);
$file_path[$node_id] = "$parent_path/$file";
}
//echo "Adding node $node_id : $file <BR>";
if ($ftype == "dir")
{
GetFileList("$dir/$file", $node_id, "$parent_path/$file" );
}
} // if file = "."
} // end while
closedir($dh);
} // if opendir
} // end GetFileList
//#-----------------------------------------------------------------
//#---- FUNCTION :: Transform()
//#---- Transform the plain content to href
//#-----------------------------------------------------------------
function Transform()
{ global $navtree;
global $file_path;
for ($i = 1; $i <= $navtree->no_node; $i ++)
{ $content = $navtree->node_content[$i];
$ftype = $navtree->node_class[$i];
// stuff an icon in front and a href behind
$content = "<IMG SRC='IMAGE/$ftype.gif'></IMG>".
"<A target=new HREF='".$file_path[$i]."'>$content</A>";
$navtree->node_content[$i] = $content;
}
$navtree->node_content[0] = $navtree->no_node." documents";
}
//======= MAIN CODE ===================================================
//---- Get Data
$navtree = new NAVTREE2("DIVTREE", "ROOT", "ROOT", 0);
$root_path="http://".$_SERVER['SERVER_NAME'];
GetFileList($_SERVER['DOCUMENT_ROOT'], 0, $root_path);
Transform();
//----- Set Style - as in the node_class during AddNode
echo "<HTML>";
echo "<HEAD>";
echo "<TITLE>NAVTREE2 DEMO</TITLE>";
echo "<STYLE>";
echo ".dir { font: bold italic; background: cyan;}";
echo ".file { background: lightblue;}";
echo ".root { font: bold 16pt; border: ridge green }";
echo "</STYLE>";
echo "</HEAD>";
echo "<BODY>";
//----- Print a Static Tree
echo "<HR><H1>Static Menu</H1>";
echo "<CENTER><DIV style='text-align: left; width: 50%; background: green'>";
echo $navtree->PrintTree(0, 0);
echo "</DIV></CENTER>";
//---- Generate a Dynamic Tree
echo "<HR><H1>Dymanic Menu</H1>";
echo "<DIV id='DIVTREE'>GenTree</DIV>";
$navtree->GenJSTree();
echo "</BODY></HTML>";
?>