<?php // The current level of the navigation structure $NavNode_Depth= 0; // Elements of the HtmlFormats array are function names to be called to output the correct html for a particular navigation level // Overwrite the HtmlFormats property with function names for each navigation level // If the navigation level goes beyond the length of the HtmlFormats array, NavNode::BuildHtml will use the last element of the array $NavNode_HtmlFormats= array(); class NavNode { // Other properties public $Url= '/index.php'; public $Kids= array(); public $Label= ""; public $HtmlFormats; function NavNode($Url="", $Kids="") { if ($Url!="") $this->Url= $Url; if (is_array($Kids) && count($Kids)>0) { foreach (array_keys($Kids) as $i) { $this->Kids[$i]= $Kids[$i]; $this->Kids[$i]->Label= $i; } } $this->HtmlFormats= &$GLOBALS['NavNode_HtmlFormats']; } // Returns a string containing an HTML representation for this link // Calls the BuildHtml function of all it's children, and appends to the HTML string function BuildHtml() { global $NavNode_HtmlFormats; global $NavNode_Depth; $s= ""; if (count($this->HtmlFormats)<1) die("NavNode::HtmlFormats is empty!"); if ($NavNode_Depth>(count($this->HtmlFormats)-1)) $NavNode_Depth= count($this->HtmlFormats)-1; if ($this->Url && $this->Label) { $funcname= $this->HtmlFormats[$NavNode_Depth].""; $s.= $funcname($this); } // Build children HTML if (count($this->Kids)>0) { $NavNode_Depth++; $k= 0; foreach (array_keys($this->Kids) as $i) { $k++; if ($k==count($this->Kids)) $this->Kids[$i]->isLastChild= true; $s.= $this->Kids[$i]->BuildHtml(); } $NavNode_Depth--; } return $s; } } /* Customization */ $Navigation= new NavNode('', array( 'Home'=> new NavNode(), 'Services'=> new NavNode('/services.php', array( 'Residential'=> new NavNode('/services/residential.php'), 'Commercial'=> new NavNode('/services/commercial.php'), 'Government'=> new NavNode('/services/government.php') )), 'IT Consulting'=> new NavNode('/consulting.php', array( 'Security Consulting'=> new NavNode('/consulting/security.php'), 'Network Deployment'=> new NavNode('/consulting/networkdeployment.php') )), 'Equipment Sales'=> new NavNode('/store/'), 'Support'=> new NavNode('/support.php'), 'Contact Us'=> new NavNode('/contactus.php') )); $Navigation->HtmlFormats= array( 'HtmlFormat0', 'HtmlFormat1', 'HtmlFormat2' ); function HtmlFormat0(&$o) { return ''; } function HtmlFormat1(&$o) { $s= '<tr><td><img src="/design/spacer.gif" width="100" height="10" alt="" /></td></tr>'."\n"; if ($o->Url==$_SERVER['PHP_SELF']) { // make sure pages do not link to themselves! $s.= '<tr><td class="nav_button_active">'.$o->Label.'</td></tr>'."\n"; } else { // create a link to the page $s.= '<tr><td class="nav_button" onClick="document.location.href=\''.$o->Url.'\'" onMouseOver="this.className= \'nav_button_over\'" onMouseOut="this.className= \'nav_button\'"><a href="'.$o->Url.'">'.$o->Label.'</a></td></tr>'; } return $s; } function HtmlFormat2(&$o) { $lastChild= $o->isLastChild ? 'true' : 'false'; $s= '<tr valign="top"><td colspan="3" class="nav_button_sub_'.$lastChild.'">'."\n"; $s.= '<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="top"><img src="/design/subnav_'.$lastChild.'.gif" alt="" width="38" height="15" /></td><td class="nav_button_sub_true">'; if ($o->Url==$_SERVER['PHP_SELF']) { // make sure pages do not link to themselves! $s.= $o->Label; } else { // create a link to the page $s.= '<a href="'.$o->Url.'">'.$o->Label.'</a>'; } return "$s</td></tr></table></td></tr>\n"; }?>