Location: PHPKode > scripts > PHP Drop Down Menu > php-drop-down-menu/phpddm.php
<?
###############################################################################
#  - SteO Menu - Ver. 0.6php (18-OCT-03) [http://www.steo.it/php]
#
#  Please give me any comment !
#
#  Copyright (c) 2001, Stefano SteO Arcidiacono - hide@address.com
#
#  This file is distributed with General Public License.
#  Any derivatives of this software must remain OpenSource and
#  must be distributed at no charge.
#  (See license.txt for additional information)
#
###############################################################################


//
// >>> You don't need to edit this file <<<
//

print "<!-- PHP Drop Down Menu 0.4 by Stefano SteO Arcidiacono (ww.steo.it/php) -->\n";

class phpddm_menu {
     function phpddm_menu($title, $vtitle, $width, $url, $target) {
        $this->TITLE = $title;
		$this->VTITLE = $vtitle;
		$this->WIDTH = $width;
		$this->URL = $url;
		$this->TARGET = $target;
    }
}

class phpddm_submenu {
     function phpddm_submenu($title, $url, $target) {
        $this->TITLE = $title;
		$this->URL = $url;
		$this->TARGET = $target;
    }
}

require('phpddm.inc.php');

// Browser check 3.0
  unset($browser);
  $browser = 'ns'; // Default browser
  if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'opera')) $browser = 'op';   
  elseif (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 6')) $browser = 'ie6'; 
  elseif (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie')) $browser = 'ie'; 
  elseif (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mozilla')) $browser = 'ns'; 
  if (stristr($_SERVER['HTTP_USER_AGENT'], 'Gecko/200') && (!(stristr($HTTP_USER_AGENT, 'compatible')))) $browser = 'ns6';

$Maxmenu = count($PHPDDM_menu) - 1;
$sum = 0;

for ($i=0; $i <= $Maxmenu; $i++ ) 
	{
	$PHPDDM_width[$i] = $PHPDDM_menu[$i]->WIDTH;
    $PHPDDM_pos[$i] = $sum; 
	$sum = $sum + $PHPDDM_width[$i];
	}

function vtitle($str) 
	{
	$return = '';
	for ($i=0; $i <= strlen($str); $i++) $return.= substr($str, $i, 1).'<br>'; 
	return $return;
	}

########################## Create main menu

unset($str);
$str = '';

if ($browser == 'op') $visibility = ''; else $visibility = 'visibility:hidden;';

$str.= '<div id="phpddmMenu" style="position:absolute; width:100%; top:'.$PHPDDM['top'].'; left:0;'.$visibility.'"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr bgcolor="'.$PHPDDM['mcolor'].'">'; 

for ($i=0; $i <= $Maxmenu; $i++ ) 
	if ($browser == 'ns')  
		$str.= '<td width="'.$PHPDDM_width[$i].'" align="left"><ILAYER><LAYER width="'.$PHPDDM_width[$i].'" onmouseover="showMenu(\''.$i.'\'); bgColor='.$phpddm_mover.'" onmouseout="bgColor=\''.$PHPDDM['mcolor'].'\'"><a href="'.$PHPDDM_menu[$i]->URL.'" target="'.$PHPDDM_menu[$i]->TARGET.'"><span class="MENU">'.$PHPDDM_menu[$i]->TITLE.'</span></a></LAYER></ILAYER></td>';
	else  
		$str.= '<td bgcolor="'.$PHPDDM['mcolor'].'" width="'.$PHPDDM_width[$i].'" onmouseover="bgColor=\''.$PHPDDM['mover'].'\'; showMenu('.$i.')" onmouseout="bgColor=\''.$PHPDDM['mcolor'].'\'" align="left"><a href="'.$PHPDDM_menu[$i]->URL.'" target="'.$PHPDDM_menu[$i]->TARGET.'"><span class="MENU">'.$PHPDDM_menu[$i]->TITLE.'</span></a></td>'; 
		
if ($browser == 'ns') 
	$str.= "<td width=\"100%\">&nbsp;</td></tr></table></div>\n";  
else 
	$str.= "<td>&nbsp;</td></tr></table></div>\n";
	
print $str; 


######################## Create Submenu
// IE and NS version
$str = '';

for ($i=0; $i <= $Maxmenu; $i++) 
	{
	if (empty($PHPDDM_submenu[$i])) 
		$str.= '<div id="subMenu'.$i.'" style="position:absolute; width:0; height:0; top:0; left:0; visibility:hidden; z-index:99;"></div>';
	else 
		{
		$str.= '<div id="subMenu'.$i.'" style="position:absolute; left:'.$PHPDDM_pos[$i].'; top:'.$PHPDDM['subtop'].'; width:'.$PHPDDM['width'].';  background-color:black;layer-background-color:black; visibility:hidden; z-index:99;"';

		if ($browser == 'ns') 
			{
			$str.= '><table width="'.$PHPDDM['width'].'" border="0" cellspacing="0" cellpadding="0">';
			$str.= '<tr><td valign="top">';
			$str.= '<table bgcolor="'.$PHPDDM['lcolor'].'" border="0" width="100%" cellspacing="1" cellpadding="1">';
			} 
		elseif ($browser == 'ie6')  
			{
			$str.= 'onmouseout="hideMenu()"><table width="'.$PHPDDM['width'].'" border="0" cellspacing="0" cellpadding="0" onmouseover="showMenu('.$i.')">';
			$str.= '<tr><td width="15" bgcolor="#C0C0C0" align="center" valign="top" style="padding:0,0,0,0;border-color:black;border-style:solid; border-right:0;border-width:1"><span class="VMENU">'.vtitle($PHPDDM_menu[$i]->VTITLE).'</span></td><td valign="top">'; 
			$str.= '<table bgcolor="'.$PHPDDM['lcolor'].'" border="0" width="100%" cellspacing="1" cellpadding="1" onmouseover="showMenu('.$i.')">';
			}
		else
			{
			$str.= '><table width="'.$PHPDDM['width'].'" border="0" cellspacing="0" cellpadding="0">';
			$str.= '<tr><td width="15" bgcolor="#C0C0C0" align="center" valign="top" style="padding:0,0,0,0;border-color:black;border-style:solid; border-right:0;border-width:1"><span class="VMENU">'.vtitle($PHPDDM_menu[$i]->VTITLE).'</span></td><td valign="top">'; 
			$str.= '<table bgcolor="'.$PHPDDM['lcolor'].'" border="0" width="100%" cellspacing="1" cellpadding="1">';
			}
	
		for ($k=0; $k < count($PHPDDM_submenu[$i]); $k++) 
		  if ($browser == 'ns')  
			$str.= '<tr><td bgcolor="'.$PHPDDM['scolor'].'"><ILAYER><LAYER width="100%" onmouseover="bgColor=\''.$PHPDDM['sover'].'\'" onmouseout="bgColor=\''.$PHPDDM['scolor'].'\'"><a href="'.$PHPDDM_submenu[$i][$k]->URL.'" target="'.$PHPDDM_submenu[$i][$k]->TARGET.'" class="SUBMENU">'.$PHPDDM_submenu[$i][$k]->TITLE.'</a></LAYER></ILAYER></td></tr>'; 
		  elseif ($browser == 'ie6')   
			$str.= '<tr ><td bgcolor="'.$PHPDDM['scolor'].'" onmouseover="bgColor=\''.$PHPDDM['sover'].'\'" onmouseout="bgColor=\''.$PHPDDM['scolor'].'\'"><a href="'.$PHPDDM_submenu[$i][$k]->URL.'" target="'.$PHPDDM_submenu[$i][$k]->TARGET.'" class="SUBMENU" onmouseover="showMenu('.$i.')">'.$PHPDDM_submenu[$i][$k]->TITLE.'</a></td></tr>';
		  else 
			$str.= '<tr><td bgcolor="'.$PHPDDM['scolor'].'" onmouseover="bgColor=\''.$PHPDDM['sover'].'\'" onmouseout="bgColor=\''.$PHPDDM['scolor'].'\'"><a href="'.$PHPDDM_submenu[$i][$k]->URL.'" target="'.$PHPDDM_submenu[$i][$k]->TARGET.'" class="SUBMENU">'.$PHPDDM_submenu[$i][$k]->TITLE.'</a></td></tr>';
				
		$str.= "</table></td></tr></table></div>\n";
		}
	}

print $str; 

############################ Javascript #############################
?>
<script language="JavaScript">

var sub_top = <?=$PHPDDM['top']?>;
var x = 0; var y = 0; 
var x1 = 0; var y1 = 0; 
var x2 = 0; var y2 = 0; 
var sel = 0; var temp;

<?
//######################## OPERA
if ($browser == 'op') 
	{
	for ($i=0; $i <= $Maxmenu; $i++) 
		{
		 print "document.all['subMenu$i'].onmouseover=handlerMM;";
		 print "document.all['subMenu$i'].onmouseout=handlerMM;";
		}
?>

function handlerMM(e) {
	if(!e)e=window.event;
	if(e.type=="mouseover")mouse=true;
	else{ mouse=false; setTimeout("hideMenu()",100) }
   }

function showMenu(x) {
	eval('document.all["subMenu'+sel+'"].style.visibility="hidden"');
	sel = x;
	eval('document.all["subMenu'+sel+'"].style.visibility="visible"');
   }

function hideMenu() {
	if(!mouse){	eval('document.all["subMenu'+sel+'"].style.visibility="hidden"');}
   }
<? 
//######################## Internet Explorer	
} elseif($browser == 'ie') {?>
	
	   
function handlerMM(e) {
	x = event.clientX;
	y = event.clientY;
	temp = 'subMenu' + sel;	

	x1 = document.all[temp].style.posLeft; 
	x2 = x1 + document.all[temp].offsetWidth;
	y1 = document.all[temp].style.posTop;
	y2 = y1 + document.all[temp].offsetHeight;	

	if ((x <= x1) || (x >= x2) || (y >= y2))  { eval('document.all["subMenu'+sel+'"].style.visibility="hidden"') }
   }

function showMenu(x){
	eval('document.all["subMenu'+sel+'"].style.visibility="hidden"');
	sel = x;
	eval('document.all["subMenu'+sel+'"].style.visibility="visible"');
   }
   
document.onmousemove = handlerMM 
eval('document.all["phpddmMenu"].style.visibility="visible"');
<? 
//######################## Netscape Navigator	
} elseif($browser == 'ns') {?>
			   
function handlerMM(e) {
	x = e.pageX 
	y = e.pageY
	temp = 'subMenu' + sel;	

	x1  = document.layers[temp].left;
	x2 = x1 + document.layers[temp].clip.width;
	y1  = document.layers[temp].top;
	y2 = y1 + document.layers[temp].clip.height;		
	
	if ((x <= x1) || (x >= x2) || (y >= y2))  { eval('document.layers["subMenu'+sel+'"].visibility="hidden"') }
}

function showMenu(x) {
	eval('document.layers["subMenu'+sel+'"].visibility="hidden"');
	sel = x;
	eval('document.layers["subMenu'+sel+'"].visibility="visible"');
   }

document.captureEvents(Event.MOUSEMOVE);   
document.onmousemove = handlerMM 
eval('document.layers["phpddmMenu"].visibility="visible"');
<? 
//######################## Netscape Navigator	
} elseif($browser == 'ns6') {?>
		   
function handlerMM(e) {
	if (e.type=="mouseover") { 	mHide=false; } else { mHide=true; setTimeout("hideMenu()",1000) }
}

function hideMenu() {
	if (mHide == true) {
		menu = "subMenu" + sel;
		document.getElementById(menu).style.visibility = "hidden";	
		}
	}

function showMenu(x) {
	menu = "subMenu" + sel;
	document.getElementById(menu).style.visibility = "hidden";
	sel = x;
	menu = "subMenu" + sel;
	document.getElementById(menu).style.visibility = "visible";
   }
 
<? 
	$str = '';

	for ($i=0; $i <= $Maxmenu; $i++) 
		{
		 $str.= "document.getElementById(\"subMenu$i\").addEventListener(\"mouseout\", handlerMM, false);\n";
		 $str.= "document.getElementById(\"subMenu$i\").addEventListener(\"mouseover\", handlerMM, false);\n";
		}
	$str.= "document.getElementById(\"phpddmMenu\").style.visibility = \"visible\";\n";
	print $str;
	
//######################## INTERNET EXPLORER DOM
} elseif($browser == 'ie6') {?>

sel=1;

function showMenu(x){
	eval('document.all["subMenu'+sel+'"].style.visibility="hidden"');
	sel = x;
	eval('document.all["subMenu'+sel+'"].style.visibility="visible"');
	window.event.cancelBubble=true
   }

function hideMenu(){
		eval('document.all["subMenu'+sel+'"].style.visibility="hidden"');
		window.event.cancelBubble=true
   }

eval('document.all["phpddmMenu"].style.visibility="visible"');

<? } 
?>
</script>	
Return current item: PHP Drop Down Menu