<?php
ob_start();/* header buffer */
session_start();
?>
<html>
<head>
<?php
################## legend #############################
### different sections
// things to do
/*  information  */
#######################################################
/* php 5 */
/* Mutliple tiers */
/* Menu data is stored in a class array and selected through post with a menuId variable*/
/* Link adresses:
/* Can be an include (inc) or a copy of file(copy),also an anchor can be inseted in the menubar(url)*/
/* The menu information is stored in a class array */
/* The menu id number is returned by post*/
/* Useing the id number the the data is extacted from the class array*/
/* The link file is put in an table cell*/
/* Change css for different styles */
### new instance of menu bar class ###################
// set menu bar name
$menuBar= new menuBar("menu bar name");
### new menu settings  ###############################
// set menu bar width 
$menuWidth= "130px";
// set sub menus  width 
$subMenuWidth= "100px";
// delete lines or add lines  as required.
// group: collection of menus.
// menu: handle for link address. 
// change class function settings to form menu groups, menus and set link addresses.
// link addresses can be an included file ('inc') or copy of a web site ('copy').
// class function,type,  group,  group or menu,----------- link file --------------------------------------- 
$menuBar->menuSet('copy','Main'             ,'Home'                ,'http://snippets.bluejon.co.uk/index.php');
$menuBar->menuSet(''    ,'Main'             ,'Scrolling Tables '   ,'');
$menuBar->menuSet('copy','Scrolling Tables ','Version 2'           ,'http://snippets.bluejon.co.uk/scrolltable/scrollTableV2.php');
$menuBar->menuSet('copy','Scrolling Tables ','Version 3'           ,'http://snippets.bluejon.co.uk/scrolltable/scrollTableV3.php');
$menuBar->menuSet('copy','Scrolling Tables ','Version 4'           ,'http://snippets.bluejon.co.uk/scrolltable/scrollTableV4.php');
$menuBar->menuSet(''    ,'Main'             ,'Script Enabled'      ,'');
$menuBar->menuSet('inc' ,'Script Enabled'   ,'Version 1'           ,'/includes/check4-js-endabled-v1.php');
$menuBar->menuSet('inc' ,'Script Enabled'   ,'Version 2'           ,'/includes/check4-js-enabled-v2.php');
$menuBar->menuSet('inc' ,'Script Enabled'   ,'Version 3-1'         ,'/includes/check4-js-and-cookie-enabled-v3-1.php');
$menuBar->menuSet(''    ,'Main'             ,'Menus'               ,'');
$menuBar->menuSet('url' ,'Menus'            ,'Version1'            ,'http://snippets.bluejon.co.uk/menu/menubar-vert-v1.php');
$menuBar->menuSet('url' ,'Menus'            ,'Version2'            ,'http://snippets.bluejon.co.uk/menu/menubar-vert-v2.php');
$menuBar->menuSet('copy','Main'             ,'Database'            ,'http://snippets.bluejon.co.uk/db-editor/db-viewer-v1.php');
$menuBar->menuSet('copy','Main'             ,'Maps'                ,'http://snippets.bluejon.co.uk/streetmap/streetmap-v1.php');
$menuBar->menuSet('copy','Main'             ,'Miscellaneous'       ,'');
$menuBar->menuSet('copy','Miscellaneous'    ,'Variables'           ,'http://snippets.bluejon.co.uk/misc/varNameIncremented.php');
$menuBar->menuSet('url' ,'Miscellaneous'    ,'Time Zones'          ,'http://snippets.bluejon.co.uk/localtimezone/local-timezone-v1.php');
###  settings end  #####################################

### php menubar class ##################################
class menuBar{
    protected $menuBarName;
  protected $groupList= array();
  protected $menuList= array();
    protected $menuGroupNum;
  protected $menuGroupId;
  protected $menuId;
        
    function __construct($menuBarNameInput){
        $this->menuBarName= $menuBarNameInput;
  }
  
  function menuSet($linkType,$menuGroupInput,$menuNameInput,$menuLinkInput){/* inputs for menu  */  
  $this->menuId++;
    $this->menuList[$this->menuId]= array(/* make menu array */
    id=>$this->menuId,
    linkType=> $linkType,
    name=>$menuNameInput,
    link=>$menuLinkInput
    ); 
   
  $this->groupList[$menuGroupInput][$menuNameInput]= $this->menuId;/*add menuId number group array */
  }
  function historyDisplay(){ /* display history  */
        print "<div class= 'history'>";
         if($_SESSION['navCurrent']>1){
            print "<input class= 'nav' style= 'left:0;' type= 'submit' name= 'navBackward' value= '&larr;' >";   
        }
         print "<div>". "Navigation". "</div>";
      if($_SESSION['navCurrent']<$_SESSION['navCount']){
            print "<input class= 'nav' style= 'right:0;' type= 'submit' name= 'navForward' value= '&rarr;' >"; 
        }
        print "</div>";
    }
    
    function menuBarDisplay(){ /* display menu bar  */
    $this->menuGroupNum= 0; 
    print "<div class= 'menuBar'id= 'mbar'>";/* css for menubar */ 
    print "<div class= 'menuBarName'>";/* css for menubar name */
    print $this->menuBarName;/* display menu bar name */
    print "</div>";
    $this->historyDisplay();/* display navigation */ 
        foreach($this->groupList  as $menuBarKey=> $menuBarValue){  
      if(!$this->menuSearch($menuBarKey)){/* search menu array to detect if it is a parent menu */  
           print"<div  class= 'menuGroup'>"; 
        print $menuBarKey;
        print"</div>"; 
        $this->menuDisplay($menuBarKey);
      }
    }
  print "</div>";
  } 
    
    function menuDisplay($groupKeyVar){ /* display menus  */
    foreach($this->groupList[$groupKeyVar] as $menuKey=> $menuValue){ 
      if(array_key_exists($menuKey,$this->groupList)){  
        $this->menuGroupNum++;
        $this->menuGroupId= "groupId".$this->menuGroupNum;     
        print"<div class= 'menuGroup'
                onMouseOver= showHide('$this->menuGroupId');
                onMouseOut= showHide('$this->menuGroupId'); >"; 
        print $menuKey."<input class= 'nav' style= 'right:0;' type= 'button' value= '>>' >";/* arrows for sub menus */
              print"<div class= 'hide' id= '$this->menuGroupId'>";
        $this->menuDisplay($menuKey);   
        print"</div>"; 
        print"</div>";
      }else{/* menuId number for $P0ST */
        if($this->menuList[$menuValue]['linkType']== 'url'){/* inserts url or munuId for for $P0ST */
                        $linkInput= "onClick= \"location.href='". $this->menuList[$menuValue]['link']. "';\" ";
                    
                    }else{
                      $linkInput= "onClick= \"menuInput('$menuValue'); \" ";
                }
                    print "<div class= 'menu' 
                    onMouseOver= \"this.className= 'mouseHov'\" 
                    onMouseOut= \"this.className= 'menu'\" 
                    $linkInput;>";
                  print $this->menuList[$menuValue]['name'];
            print "</div>";
      
            }
    }
  }
  
    function menuSearch($menu){ /* search for parent in menu array */
        foreach($this->menuList as $menuKey=> $menuValue){ 
            if($menuValue['name']== $menu){
              return true;
            }
        }
        return false;
    }
    
    function menuSelect($menuId){/*select to include or copy link */
        if(count($this->menuList > 0)){
            if($_SESSION['navCurrent']){
                switch ($this->menuList[$menuId]['linkType']){/* select to copy or include file. Urls are insered as anchores.*/
                case inc:
                include($_SERVER['DOCUMENT_ROOT'].$this->menuList[$menuId]['link']);
                    break;
            case copy:
                print file_get_contents($this->menuList[$menuId]['link']);
               break;  
                }
            }else{
                $_SESSION['navCurrent']=1;
                $_SESSION['navCount']=1;
                $_SESSION['nav'][$_SESSION['navCurrent']]= 1;
                print file_get_contents($this->menuList[1]['link']);    
            } 
        }
    }    
}
?>
<!### CSS  ############################################>
<style type="text/css">
<!--
/* css for page layout */
table.layout{
    color:#404040;
    background-color:LightSteelBlue;
    margin:0;
    padding:0;
    border:1px blue solid;
    border-collapse:collapse;
    border-spacing:0;
    border-spacing:0;
}

td.content{/* display content area */
    width:600px;
    vertical-align:top;
    padding:0;
    border:1px blue solid;
}

input.nav{/* history navigation pointer */
    width:15%;  
    height:100%;
    line-height:100%;
    position:absolute;
    top:0px;
    padding:0;
    border:0;
    color:yellow;
    background-color:cornFlowerBlue;
}

div.menu, .mouseOut, .mouseHov, .show{/* common css */
   height:20px;
     line-height:20px;
     z-index:1000; 
     overflow:visible;
     text-decoration:none;
   text-align:left;
   text-indent:10px;
   font-weight:200; 
   font-style:normal;
   font-family:sans-serif;
   font-size:12px;
   color:white;
   background-color:royalBlue;

div.history{/* css history navigation  */
    height:20px;
    line-height:20px;
    position:relative;
  text-align:center;
    font-size:12px;
  color:white;
  background-color:royalBlue;  
  border-top:1px solid black;
  border-left:1px solid black;
  border-right:1px solid black;
}

div.menuBar{/* css for menu bar  */
  width:<?php print $menuWidth;?>
  border-top:1px solid black;
  border-bottom:1px solid black;
}  

div.menuBarName{/* css for menu bar name */
  height:20px;
    line-height:20px;
  text-align:center;
  font-size:16px;
  font-weight:400; 
  font-style:normal;
  font-family:helvetica;
  color:white;
  background-color:royalBlue; 
  border-left:1px solid black;
  border-right:1px solid black;
}

div.menuGroup{/* css for menu groups */
  height:20px;
    line-height:20px;
    position:relative;
    z-index:1000; 
    overflow:visible;
    border-top:1px solid black;
  border-left:1px solid black;
  border-right:1px solid black;
  cursor:default;
  color:white;
  background-color:cornFlowerBlue;
  text-align:center;
  font-size:12px;
  font-weight:200; 
  font-style:normal;
  font-family:arial;
  color:white;
}

div.menu{/* css for menus */
  border-top:1px solid black;
  border-left:1px solid black;
  border-right:1px solid black;
}
/* css for mouse linked to javascript */
.mouseHov{
   background-color:#0000CD;
   color:yellow;
   cursor:pointer;
   cursor:hand;
   border-top:1px solid black;
   border-left:1px solid black;
   border-right:1px solid black;

.hide{
    display:none;
}
.show{
     top:0;
    position:absolute;
    width:<?php print $subMenuWidth?>;  
    z-order:200;
  right:-<?php print $subMenuWidth;?>
  border-bottom:1px solid black;
}
--> 
</style>
<!### javascript   ###################################>
<script type = "text/javascript">/* javascript */
function showHide(Id){
  var group = document.getElementById(Id);
  menu_status = group.className
  if(menu_status != 'show'){
    group.className = 'show';
  }else{
    group.className = 'hide';
  }
}

function menuInput(id){/* submit menuId number by post */
    document.getElementById('menuId').value =id;
    menuForm.submit();
}
</script>
<?php
### collect $_POST for history navigation ###############
if($_POST['menuId']){/* check for $_POST from form with menuId number and store in a session*/
    if($_SESSION['menuId']!=$_POST['menuId']){
        $_SESSION['menuId']=$_POST['menuId'];
      $_SESSION['navCount']++;  
      $_SESSION['navCurrent']= $_SESSION['navCount'];
        $_SESSION['nav'][$_SESSION['navCurrent']]= $_SESSION['menuId'];
    };
};
if($_POST['navBackward']){
  if($_SESSION['navCurrent']>1){
      $_SESSION['navCurrent']--;
    }
}  
if($_POST['navForward']){
    if($_SESSION['navCurrent']< $_SESSION['navCount']){
      $_SESSION['navCurrent']++;
    }

### display ######################################################
?>
</head>
<body>
<! ### form to to post  menuId ###################################>
<form name= "menuForm" method= "post" action= "<?php print $PHP_SELF;?>" >
<input type= "hidden"  name= "menuId" id= "menuId">
<!### table for display layout ###################################>
<table class= 'layout'>
<tr>
    <td>    </td>
  <td><center><h1>Display Link Content</h1></center></td>
</tr>
<tr>    
    <!### menu display ##############################################>
    <td style='vertical-align:top;'><?php $menuBar->menuBarDisplay();?></td>
    <!### content  display ###########################################>
    <td class= 'content'><?php $menuBar->menuSelect($_SESSION['nav'][$_SESSION['navCurrent']]);/*function to load link*/?></td>
</tr>
</table><br>
</form>
<a  href="http://snippets.bluejon.co.uk/menu/menubar-vert-v3-phpcode.php">Display php source code </a>
</body>
</html>
<?php
ob_end_flush();
?>