Location: PHPKode > scripts > NavTree > navtree/class_navtree.php
<?php

//######################################################################
//##### TITLE       :: CLASS NAVTREE
//##### FILE        :: class_navtree.php
//##### PROJECT	    :: WebVision
//##### RELATED DOCUMENT :: None
//##### DESCRIPTION   ::
//#####     To provide an explorer-like tree-driven manuals
//##### AUTHOR      :: Mark Quah
//##### REVISION 	:: 0001 - 30 Nov 2002
//######################################################################
define("NAV_HIDEROOT", 1);         // HIDE Root Node
define("NAV_NOICON", 2);           // HIDE ICON
define("NAV_NODESC", 4);           // HIDE DESCRIPTION
define("NAV_STATIC", 8);           // STATIC TREE
define("NAV_SETALL", 16);           // SHOW EXPAND ALL/COLLAPSE ALL ICON
define("NAV_NOINDENT", 32);           // SHOW EXPAND ALL/COLLAPSE ALL ICON
define("NAV_NOLEADLINE", 64);           // HIDE LEADLINE

class NAVTREE
{
    // tree info
    var $tree;
    var $type;
    var $tree;
    var $node;
    var $tree_style;

    function NAVTREE($img_dir="/IMAGES/NAVTREE")
    {   //----- Indentation
        $this->indent_width=22;
        $this->indent_height=10;
        //----- image set up
        $this->img_hsize=$this->indent_width * 2;
        $this->img_vsize=$this->indent_width;
        $this->img_dir = $img_dir;
        $this->img_spacer=$img_dir.'/nav_spacer.gif';
        $this->img_plus=$img_dir.'/nav_plus.gif';
        $this->img_minus=$img_dir.'/nav_minus.gif';
        //----- display style
        $this->Style['#navs_action'] =
            'font-size: 8pt; font-family: Arial, Helvetica; font-weight: bold;'.
            'line-height:100%; font-weight: bold;';
        $this->Style['#navs_tree']  =
            'font-size: 8pt; font-family: Arial, Helvetica; font-weight: bold;';
        $this->Style['#navs_content']=
            'border: 2 groove; padding: 5; font-size: 8pt; '.
            'font-family: Arial, Helvetica';
    }

    function SetStyle($style_name, $style)
    {
        $this->Style["#$style_name"]= $style;
    }

    function SetTreeStyle($tree_id, $style_name, $style)
    {
        $this->Style["#$style_name.$tree_id"]= $style;
    }

    function LoadData()
    {   //----- Display Style
        echo "<style>\n";
        foreach ($this->Style as $key => $value)
            echo "$key {{$value}}\n";
        //---- leadline style
        echo ".leadline0 { background-image: url('".$this->img_dir."/leadlineL.gif');";
        echo "             margin:0; padding:0; ";
        echo "             width:20; height: 100%; background-repeat: repeat-y; }\n";
        echo ".leadline1 { background-image: url('".$this->img_dir."/leadlineO.gif');";
        echo "             margin:0; padding:0;";
        echo "             width:20; height: 100%; background-repeat: repeat-y;}\n";
        echo ".leadline2 { background-image: url('".$this->img_dir."/leadlineT.gif');";
        echo "             margin:0; padding:0; ";
        echo "             width:20; height: 100%; background-repeat: repeat-y;}\n";
        echo ".leadline3 { background-image: url('".$this->img_dir."/leadlineI.gif');";
        echo "             margin:0; padding:0;";
        echo "             width:20; height: 100%; background-repeat: repeat-y}\n";
        echo "</style>\n";
        //----- Load in Javascript
        include_once "class_navtree_inc.php";
        //----- global settings
        echo "<script>\n";
        echo "img_dir = '".$this->img_dir."';\n";
        echo "img_hsize = ".$this->img_hsize.";\n";
        echo "img_vsize = ".$this->img_vsize.";\n";
        echo "img_spacer  = '".$this->img_spacer."';\n";
        echo "img_plus  = '".$this->img_plus."';\n";
        echo "img_minus  = '".$this->img_minus."';\n";
        //----- Build up tree data
        foreach ($this->type as $value)
            echo "$value\n";
        foreach ($this->tree as $value)
            echo "$value\n";
        foreach ($this->node as $value)
            echo "$value\n";
        //----- Get cookie
        echo "GetCookie();";
        echo "</script>\n";
    }

    function CreateType($name)
    {   $pos = count($this->type);
        $img_prefix = $this->img_dir."/".$name;
        $this->type[] = "nav_type$pos=CreateType('$name', '$img_prefix');";
        return $pos;
    }

    function CreateNode($parent, $type, $state, $header, $content)
    {   $pos = count($this->node);
        $content = addcslashes($content, "'/");
        $header = addcslashes($header, "'/");
        $this->node[] ="nav_node$pos=CreateNode($parent, $type, '$state', '$header', '$content');";
        return $pos;
    }

    function CreateLinkNode($parent, $href, $desc, $text, $type=0)
    {   global $navtree;
        $action="<A HREF='$href'>$desc</A>";
        $link = $this->CreateNode($parent, $type, "close" , $action, $text);
        return $link;
    }

    function CreateTree($root_node, $div_id,
                        $option=0, $indent_width=20, $indent_height=10)
    {   $pos = count($this->tree);
        $this->tree[] = "nav_tree$pos=CreateTree($root_node, '$div_id', ".
                       "$option, $indent_width, $indent_height);";
        return $pos;
    }


    // Display Tree
    function DisplayTree($tree_id)
    {
        // Display subtree
        $this->JSRun("WriteMenu($tree_id);\n");
    }

    function PrintTree($tree_id)
    {
        // Display subtree
        $this->JSRun("PrintMenu($tree_id);\n");
    }
    //---- Supporting funtcions
    function JSRun($jscode)
    {
        echo '<script language="JavaScript" type="text/javascript">';
        echo $jscode;
        echo '</script>';
    }

} // End NAVTREE


?>

Return current item: NavTree