CODE <html> <head> <title>PHP Treeview test</title> <script type="text/javascript"> function toggle(id,imgid) { var td = document.getElementById(id); var imid = document.getElementById(imgid); if (td.style.display == '' || td.style.display == 'none') { td.style.display = "block"; document.getElementById(imgid).src = "images/imgFolder1.gif"; } else { td.style.display = "none"; document.getElementById(imgid).src = "images/imgFolder0.gif"; } } </script> </head> <body> <?php class treeview { var $htmlstr; function treeview($id,$imgid,$childid,$txt,$def) { $this->htmlstr= "<div id='$id'>"; if ($def == 1) { $this->htmlstr.= " <a href="javascript:void(0)" onclick="toggle('$childid','$imgid')"> <img id="$imgid" align="absmiddle" border="0" src="images/imgFolder1.gif">$txt </a>n"; } else { $this->htmlstr.= " <a href="javascript:void(0)" onclick="toggle('$childid','$imgid')"><img id="$imgid" align="absmiddle" border="0" src="images/imgFolder0.gif">$txt</a>"; } } function addNode($id,$level,$def) { if ($level == 1) { if ($def == 1) { $this->htmlstr.= " <ul id='$id' style='padding:0px;margin:0px 0px 0px 20px;list-style-type:none;display:block'> "; } else { $this->htmlstr.= " <ul id='$id' style='padding:0px;margin:0px 0px 0px 20px;list-style-type:none;display:none'> "; } } else { if ($def == 1) { $this->htmlstr.= " <ul id='$id' style='padding:0px;margin:0px 0px 0px 0px;list-style-type:none;display:block'> "; } else { $this->htmlstr.= " <ul id='$id' style='padding:0px;margin:0px 0px 0px 0px;list-style-type:none;display:none'> "; } } } function addItem($menutxt) { $this->htmlstr.= " <li style="padding: 0px; margin:0px; background:url('images/line_vertical.gif');background-repeat:repeat-y" >"; $this->htmlstr.= " <img src="images/line_branch.gif" align="absmiddle" ><img src="images/html.gif" align="absmiddle">$menutxt"; $this->htmlstr.= "</li>"; } function addItemLast($parentflag) { $this->htmlstr.= "</ul>"; if ($parentflag == 1) { $this->htmlstr.= "</li>"; } } function addTree($imgid,$childid,$txt,$def) { $this->htmlstr.= " <li style="padding: 0px; margin:0px; background:url('images/line_vertical.gif');background-repeat:repeat-y">"; if ($def == 1) { $this->htmlstr.= " <a href="javascript:void(0)" onclick="toggle('$childid','$imgid')"><img src="images/line_branch.gif" align="absmiddle" border="0"><img id="$imgid" align="absmiddle" border="0" src="images/imgFolder1.gif">$txt</a>"; } else { $this->htmlstr.= " <a href="javascript:void(0)" onclick="toggle('$childid','$imgid')"><img src="images/line_branch.gif" align="absmiddle" border="0"><img id="$imgid" align="absmiddle" border="0" src="images/imgFolder0.gif">$txt</a>"; } } function addTreeLast($imgid,$childid,$txt,$def) { $this->htmlstr.= "<li style="padding: 0px; margin:0px;">"; if ($def == 1) { $this->htmlstr.= " <a href="javascript:void(0)" onclick="toggle('$childid','$imgid')"><img src="images/line_corner.gif" align="absmiddle" border="0"><img id="$imgid" align="absmiddle" border="0" src="images/imgFolder1.gif">$txt</a>"; } else { $this->htmlstr.= " <a href="javascript:void(0)" onclick="toggle('$childid','$imgid')"><img src="images/line_corner.gif" align="absmiddle" border="0"><img id="$imgid" align="absmiddle" border="0" src="images/imgFolder0.gif">$txt</a>"; } } function endtree() { $this->htmlstr.= "</ul>"; } function showTree() { $this->htmlstr.= "</div>"; return $this->htmlstr; } } $mytree = new treeview("mytree","easyimage","easyweb","Easy Web Page Design",1); $mytree->addNode("easyweb",0,1); $mytree->addItem("<a href='http://www.easywebpagedesign.com'>Home</a>"); $mytree->addItem("<a href='http://www.easywebpagedesign.com/forum/'>Forum</a>"); $mytree->addTree("toolsimage","toolsweb","Tools",1); $mytree->addNode("toolsweb",1,0); $mytree->addItem("<a href='http://www.easywebpagedesign.com/template_creator.html'>Template Creator</a>"); $mytree->addItemLast(1); $mytree->addTree("scriptimage","scriptweb","Scripts",1); $mytree->addNode("scriptweb",1,1); $mytree->addItem("<a href='http://www.easywebpagedesign.com/ezpzmenu.html'>EZPZ Menu</a>"); $mytree->addItem("<a href='http://www.easywebpagedesign.com/ezpzedit.html'>EZPZ DHTML Editor</a>"); $mytree->addItemLast("<a href='http://www.easywebpagedesign.com/ezpzcolor.html'>EZPZ Color Picker</a>",1); $mytree->addTree("tutimage","tutweb","Tutorials",1); $mytree->addNode("tutweb",1,1); $mytree->addItem("<a href='http://www.easywebpagedesign.com/creating_websites.html'>Creating Websites</a>"); $mytree->addItem("<a href='http://www.easywebpagedesign.com/how_the_web_works.html'>How The Web Works</a>"); $mytree->addItem("<a href='http://www.easywebpagedesign.com/html_editor_guide.html'>HTML Editor Guide</a>"); $mytree->addTreeLast("jsimage","jsweb","javascript",1); $mytree->addNode("jsweb",1,1); $mytree->addItem("<a href='http://www.easywebpagedesign.com/javascript_definition.html'>Definition</a>"); $mytree->addItemLast(1); $mytree->endtree(); ?> <table> <tr><td> <div style="width:200px;height:300px;overflow:auto"> <?php echo $mytree->showTree();?> </div> </td><td> </td></tr></table> </body></html>
|