Login   Register  
PHP Classes
elePHPant
Icontem

File: exanple1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of ROZEBAB  >  TreeMenu  >  exanple1.php  >  Download  
File: exanple1.php
Role: Example script
Content type: text/plain
Description: Example of TreeMenu.
Class: TreeMenu
Output an HTML hierarchical menu
Author: By
Last change: Add script.
Date: 10 years ago
Size: 9,872 bytes
 

Contents

Class file image Download
Test Setmenu<BR>
<?
INCLUDE_ONCE( "Set_Menu.php" );

/*
    menu_id is ID of menu.
    parent_id is ID of menu's parent.
    order is order in that menu group.
*/

                     //    v-----------  Array Index is menu_id,  
                     //                   Array Index must start at 1 and $data_menu_array[ 1 ][ "parent_id" ] must is 0.
$data_menu_array][ "menu_id" ]            = 1;
$data_menu_array][ "parent_id" ]            = 0;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 1";

$data_menu_array][ "menu_id" ]            = 2;
$data_menu_array][ "parent_id" ]            = 1;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 2";

$data_menu_array][ "menu_id" ]            = 3;
$data_menu_array][ "parent_id" ]            = 2;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 3";

$data_menu_array][ "menu_id" ]            = 4;
$data_menu_array][ "parent_id" ]            = 2;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 4";

$data_menu_array][ "menu_id" ]            = 5;
$data_menu_array][ "parent_id" ]            = 2;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 5";

$data_menu_array][ "menu_id" ]            = 6;
$data_menu_array][ "parent_id" ]            = 2;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 6";

$data_menu_array][ "menu_id" ]            = 7;
$data_menu_array][ "parent_id" ]            = 1;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 7";

$data_menu_array][ "menu_id" ]            = 8;
$data_menu_array][ "parent_id" ]            = 7;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 8";

$data_menu_array][ "menu_id" ]            = 9;
$data_menu_array][ "parent_id" ]            = 8;
$data_menu_array][ "order" ]                = 1;
$data_menu_array][ "name" ]                = "Menu 9";

$data_menu_array10 ][ "menu_id" ]        = 10;
$data_menu_array10 ][ "parent_id" ]        = 9;
$data_menu_array10 ][ "order" ]                = 1;
$data_menu_array10 ][ "name" ]            = "Menu 10";

$data_menu_array11 ][ "menu_id" ]        = 11;
$data_menu_array11 ][ "parent_id" ]        = 10;
$data_menu_array11 ][ "order" ]                = 1;
$data_menu_array11 ][ "name" ]            = "Menu 11";

$data_menu_array12 ][ "menu_id" ]        = 12;
$data_menu_array12 ][ "parent_id" ]        = 10;
$data_menu_array12 ][ "order" ]                = 1;
$data_menu_array12 ][ "name" ]            = "Menu 12";

$data_menu_array13 ][ "menu_id" ]        = 13;
$data_menu_array13 ][ "parent_id" ]        = 10;
$data_menu_array13 ][ "order" ]                = 1;
$data_menu_array13 ][ "name" ]            = "Menu 13";

$data_menu_array14 ][ "menu_id" ]        = 14;
$data_menu_array14 ][ "parent_id" ]        = 10;
$data_menu_array14 ][ "order" ]                = 1;
$data_menu_array14 ][ "name" ]            = "Menu 14";

$data_menu_array15 ][ "menu_id" ]        = 15;
$data_menu_array15 ][ "parent_id" ]        = 3;
$data_menu_array15 ][ "order" ]                = 1;
$data_menu_array15 ][ "name" ]            = "Menu 15";

$data_menu_array16 ][ "menu_id" ]        = 16;
$data_menu_array16 ][ "parent_id" ]        = 3;
$data_menu_array16 ][ "order" ]                = 1;
$data_menu_array16 ][ "name" ]            = "Menu 16";

$data_menu_array17 ][ "menu_id" ]        = 17;
$data_menu_array17 ][ "parent_id" ]        = 3;
$data_menu_array17 ][ "order" ]                = 1;
$data_menu_array17 ][ "name" ]            = "Menu 17";

$data_menu_array18 ][ "menu_id" ]        = 18;
$data_menu_array18 ][ "parent_id" ]        = 9;
$data_menu_array18 ][ "order" ]                = 1;
$data_menu_array18 ][ "name" ]            = "Menu 18";

$data_menu_array19 ][ "menu_id" ]        = 19;
$data_menu_array19 ][ "parent_id" ]        = 9;
$data_menu_array19 ][ "order" ]                = 1;
$data_menu_array19 ][ "name" ]            = "Menu 19";

$data_menu_array20 ][ "menu_id" ]        = 20;
$data_menu_array20 ][ "parent_id" ]        = 9;
$data_menu_array20 ][ "order" ]                = 1;
$data_menu_array20 ][ "name" ]            = "Menu 20";

$data_menu_array21 ][ "menu_id" ]        = 21;
$data_menu_array21 ][ "parent_id" ]        = 1;
$data_menu_array21 ][ "order" ]                = 13;
$data_menu_array21 ][ "name" ]            = "Menu 21";

$data_menu_array22 ][ "menu_id" ]        = 22;
$data_menu_array22 ][ "parent_id" ]        = 1;
$data_menu_array22 ][ "order" ]                = 10;
$data_menu_array22 ][ "name" ]            = "Menu 22";

$data_menu_array23 ][ "menu_id" ]        = 23;
$data_menu_array23 ][ "parent_id" ]        = 1;
$data_menu_array23 ][ "order" ]                = 18;
$data_menu_array23 ][ "name" ]            = "Menu 23";

$data_menu_array24 ][ "menu_id" ]        = 24;
$data_menu_array24 ][ "parent_id" ]        = 1;
$data_menu_array24 ][ "order" ]                = 16;
$data_menu_array24 ][ "name" ]            = "Menu 24";

$data_menu_array25 ][ "menu_id" ]        = 25;
$data_menu_array25 ][ "parent_id" ]        = 1;
$data_menu_array25 ][ "order" ]                = 3;
$data_menu_array25 ][ "name" ]            = "Menu 25";

$data_menu_array26 ][ "menu_id" ]        = 26;
$data_menu_array26 ][ "parent_id" ]        = 1;
$data_menu_array26 ][ "order" ]                = 2;
$data_menu_array26 ][ "name" ]            = "Menu 26";

$data_menu_array27 ][ "menu_id" ]        = 27;
$data_menu_array27 ][ "parent_id" ]        = 1;
$data_menu_array27 ][ "order" ]                = 9;
$data_menu_array27 ][ "name" ]            = "Menu 27 <FONT Color=\"red\">Reorder by order number.</FONT>";

$data_menu_array28 ][ "menu_id" ]        = 28;
$data_menu_array28 ][ "parent_id" ]        = 1;
$data_menu_array28 ][ "order" ]                = 5;
$data_menu_array28 ][ "name" ]            = "Menu 28";

$data_menu_array29 ][ "menu_id" ]        = 29;
$data_menu_array29 ][ "parent_id" ]        = 1;
$data_menu_array29 ][ "order" ]                = 4;
$data_menu_array29 ][ "name" ]            = "Menu 29";

$data_menu_array30 ][ "menu_id" ]        = 30;
$data_menu_array30 ][ "parent_id" ]        = 1;
$data_menu_array30 ][ "order" ]                = 20;
$data_menu_array30 ][ "name" ]            = "Menu 30";

$data_menu_array31 ][ "menu_id" ]        = 31;
$data_menu_array31 ][ "parent_id" ]        = 1;
$data_menu_array31 ][ "order" ]                = 15;
$data_menu_array31 ][ "name" ]            = "Menu 31";

$data_menu_array32 ][ "menu_id" ]        = 32;
$data_menu_array32 ][ "parent_id" ]        = 1;
$data_menu_array32 ][ "order" ]                = 19;
$data_menu_array32 ][ "name" ]            = "Menu 32";

$data_menu_array33 ][ "menu_id" ]        = 33;
$data_menu_array33 ][ "parent_id" ]        = 1;
$data_menu_array33 ][ "order" ]                = 30;
$data_menu_array33 ][ "name" ]            = "Menu 33";

//$param1 = "Link";
$treemenu_obj = NEW tree_menu;
$tree_menu $treemenu_obj->set_menu $data_menu_array$param1 $param2  );
//---------------------------------------------------------------------------------------------------------------------
// Sturcture of $tree_menu.
/*
        $tree_menu[ "row" ][ "column" ][ "menu_id" ]        = ID of Menu.
                                                  [ "sign_no" ]        = Number of join sign.
                                                                            0 or empty        is  no sign.
                                                                            1                    is line sign.                ( | )
                                                                            2                    is join sign.                ( + )
                                                                            3                    is joinbottom sign.    ( L )

*/
//---------------------------------------------------------------------------------------------------------------------
/*
WHILE ( LIST( $key, $val ) = EACH( $tree_menu ) ) {
        // -v- WHILE ( LIST( $key, $val ) = EACH( $tree_menu ) )
        ECHO $key." => ".$val."<BR>";
        WHILE ( LIST( $key1, $val1 ) = EACH( $val ) ) {
            // -v- WHILE ( LIST( $key1, $val1 ) = EACH( $val ) )
            ECHO "=================".$key1." => ".$val1."<BR>";
            WHILE ( LIST( $key2, $val2 ) = EACH( $val1 ) ) {
                // -v- WHILE ( LIST( $key2, $val2 ) = EACH( $val1 ) )
                ECHO "------------------------------------------------------------------".$key2." => ".$val2."<BR>";
            }        // -^- WHILE ( LIST( $key2, $val2 ) = EACH( $val1 ) )
        }        // -^- WHILE ( LIST( $key1, $val1 ) = EACH( $val ) )
}        // -^- WHILE ( LIST( $key, $val ) = EACH( $tree_menu ) )
*/


        
$table_menu_data $tree_menu;
        ECHO 
"<TABLE Border=0 cellpadding=\"0\" cellspacing=\"0\">\n";
        WHILE ( LIST( 
$key$val ) = EACH$table_menu_data ) ) {    // -v- WHILE ( LIST( $key, $val ) = EACH( $table_menu_data ) )
            
ECHO "<TR><TD><TABLE Border=0 cellpadding=\"0\" cellspacing=\"0\"><TR><TD>\n";
            WHILE ( LIST( 
$key1$val1 ) = EACH$val ) ) {    // -v- WHILE ( LIST( $key, $val ) = EACH( $val ) )
                
IF ( $key == ) {
                                    
// -v- IF ( $key == 1 )
                    
$path_gif "empty.gif";
                }ELSE {            
// --- IF ( $key == 1 )
                    
SWITCH ( $val1["sign_no"] ) {        // -v- SWITCH ( $val1["sign_no"] )
                        
CASE "0" $path_gif "empty.gif";                BREAK;
                        CASE 
"1" $path_gif "line.gif";                    BREAK;
                        CASE 
"2" $path_gif "join.gif";                    BREAK;
                        CASE 
"3" $path_gif "joinbottom.gif";        BREAK;
                        DEFAULT : 
$path_gif "empty.gif";                BREAK;
                    }                                            
// -^- SWITCH ( $val1["sign_no"] )
                
}                    // -^- IF ( $key == 1 )
                
                
IF ( $val1"menu_id" ] > ) {        // -v- IF ( $val1[ "menu_id" ] > 0 )
                    //ECHO "<TD><IMG SRC=\"../images/line/".$path_gif."\"></TD>\n";
                    
ECHO "<TD><IMG SRC=\"".$path_gif."\"></TD>\n";
                    ECHO 
"<TD><FONT Size=\"2\">&nbsp;".$data_menu_array$val1["menu_id"] ][ "name" ]."</FONT>&nbsp;&nbsp;<FONT Color=\"green\" Size=\"1\">Parent is ".$data_menu_array[$data_menu_array$val1["menu_id"] ][ "parent_id" ]][ "name" ]."</FONT>&nbsp;&nbsp;<FONT Color=\"blue\" Size=\"1\">Order No. ".$data_menu_array$val1["menu_id"] ][ "order" ]."</FONT></TD>\n";
                }ELSE {                                    
// --- IF ( $val1[ "menu_id" ] > 0 )
                    
ECHO "<TD><IMG SRC=\"".$path_gif."\"></TD>\n";
                }                                            
// -^- IF ( $val1[ "menu_id" ] > 0 )
            
}                                                                // -^- WHILE ( LIST( $key, $val ) = EACH( $val ) )
            
ECHO "</TD></TR></TABLE></TD></TR>\n";
        }                                                                                
// -^- WHILE ( LIST( $key, $val ) = EACH( $table_menu_data ) )
        
UNSET( $key$val );
        UNSET( 
$key1$val1 );
        ECHO 
"</TABLE>\n";
?>