Location: PHPKode > projects > chillyCMS > chillyCMS/modules/menu/menu.php
<?php
defined('DOIT') or die('Restricted access');

require_once(PATH."/modules/menu/menu.include.php");

//get settings
$modsettings = explode(",",$modsettings);
if (isset($modsettings[0])) { $whichmenu = $modsettings[0]; } else { $whichmenu = false; }
if (isset($modsettings[1])) { $displayname = $modsettings[1]; } else { $displayname = false; }
if (isset($modsettings[2])) { $showsubitems = $modsettings[2]; } else { $showsubitems = false; }
if (isset($modsettings[3])) { $extensible = $modsettings[3]; } else { $extensible = false; }

//Variable zum Prüfen, ob ein Menü ausgeklappt ist oder nicht beim wiederholten Laden der Seite:
//(mit Cookies realisiert)
if (isset($_COOKIE['menu'.$modinstanceid])) {
	$showmyitems=$_COOKIE['menu'.$modinstanceid];
} else {
	$showmyitems = false;
}

$menu = get_tree($whichmenu);
$menu = make_ul($menu);

if (!empty($mysession)) {
	$gids = $mysession->user->gids;
} else {
	$gids = false;
}

$printmenu = "\t<ul>\n";
$heading = "";

if($extensible==1) {
	//Javascript extensible menu
	echo "<script type='text/javascript' language='javascript'>
	function accordion(which) {
		menu = document.getElementById('menu' + which);
		ab = document.getElementById('accordionbutton' + which);
		ab.style.background = 'url(".URL."/modules/menu/images/minus.png) 0 0 no-repeat';
		if (menu.style.display=='none') {
			menu.style.display = 'block';
			ab.style.background = 'url(".URL."/modules/menu/images/minus.png) 0 0 no-repeat';
			document.cookie = 'menu' + which + '= open';
		} else {
			menu.style.display = 'none';
			ab.style.background = 'url(".URL."/modules/menu/images/plus.png) 0 0 no-repeat';
			document.cookie = 'menu' + which + '= closed';
		}
	}
	function fold(which, status) {
		menu = document.getElementById('menu' + which);
		menu.style.display = status;
		if (status=='none') {
			document.cookie = 'menu' + which + '= closed';
		} else {
			document.cookie = 'menu' + which + '= open';
		}
	}
	</script>\n";
	// wenn die Menüs überhaupt ausklappar sind ($extensible==1) und...
	// sind die Untermenüs sichtbar oder nicht? (gegebenenfalls Grafik anpassen(+ oder -))
	// beim ersten Laden der Seite sind die Menüs per default zugeklappt, noch keine Cookies gesetzt( $showitems=="" ):
		if($showmyitems=='closed' || $showmyitems=='') {
			$accordion = 'foldedup';
		} else {
			$accordion = 'foldedout';
		}
}

foreach ($menu as $item) {

	//has the user access to each of the menu items?
	$hasspecialaccess = false;	
	if (isset($item->specialaccess) && !is_null($item->specialaccess)) {
		$itemspecialaccess = explode(',',$item->specialaccess);
	} else {
		$itemspecialaccess = array();
	}
	if ($mysession && is_array($mysession->user->gids) && !empty($mysession->user->gids)) {
		foreach ($mysession->user->gids as $ug) {
			if (in_array($ug,$itemspecialaccess)) {
				$hasspecialaccess = true;
				break;
			}
		}
	}

	$displayme = false;
	
	//display single item?
	if (!is_array($item) && get_class($item)=='Menuitem') {
		if ($item->active==1 && 
		($item->access==0 or 
		($item->access==1 && $is_user) or
		($item->access==2 && ($is_admin or (isset($hasspecialaccess) && $hasspecialaccess))))) {
			$displayme=true;
		}
	}

	$current="";
	$tabs="";
	$marksubul = false;
	if (isset($item->depth)) {
		for ($i=0;$i<=$item->depth;$i++) { $tabs.="\t"; }
	}
	
	//display item(s) with subitem(s)
	if (is_array($item) && !empty($item)) {
	
		//mark the parent item if it is the current item
		if (isset($this->id) && $this->id==$item["parent"]->id) {
			$current = ' class="current menu_item'.$item["parent"]->id.'"';
			$marksubul = true;
		} else {
			$current = ' class="menu_item'.$item["parent"]->id.'"';
		}
		//display the parent item?
		if ($item['parent']->active==1 &&						//it must be active AND
		($item['parent']->access==0 or							//be open for everybody
		($item['parent']->access==1 && $is_user) or					//or for users and this is a user requesting it
		($item['parent']->access==2 && ($is_admin or $hasspecialaccess)))) {		//or for admins and this is an admin requesting it
			$displayme=true;
		} else {
			$displayme=false;
		}
		//it will be displayed
		if ($displayme) {
			$printmenu .= "$tabs<li$current>";
			$printmenu .= print_item($item["parent"]);

			//display children?
			if ($showsubitems==1) {
				//is one of the children the current item?
				if (is_array($item['children']) && !empty($item['children'])) {
					foreach ($item["children"] as $subitem) {
						//if yes mark it
						if ($this->id==$subitem->id or $marksubul) {
							$current = ' class="current menu_item'.$item["parent"]->id.'"';
							break;
						} else {
							$current = ' class="menu_item'.$item["parent"]->id.'"';
						}
					}
				}
				$printmenu.="\n$tabs\t<ul$current>\n";
				$current="";
				foreach ($item["children"] as $subitem) {
					//display subitem?
					if ($subitem->active==1 &&					//it must be active AND
					($subitem->access==0 or						//be open for everybody
					($subitem->access==1 && $is_user) or				//or for users and this is a user requesting it
					($subitem->access==2 && ($is_admin or $hasspecialaccess)))) {	//or for admins and this is an admin requesting it
						$displayme=true;
					} else {
						$displayme=false;
					}
					//it will be displayed
					if ($displayme) {
						if ($this->id==$subitem->id) {
							$current = ' class="current menu_item'.$subitem->id.'"';
						} else {
							$current = ' class="menu_item'.$subitem->id.'"';
						}
						$printmenu.="$tabs\t\t<li$current>".print_item($subitem)."</li>\n";
					}
				}
				$printmenu.="$tabs\t</ul>\n";
			}
			$printmenu.="$tabs</li>\n";
		}
	} else {
		//heading
		if ($item->depth==0) {
			if ($displayname==1) {
				if ($extensible==1) {
					$heading="\t<h3 class='heading'>\n".
					"\t\t".$item->name."\n".
					"\t\t<a class='accordionbutton $accordion' id='accordionbutton$modinstanceid'".
					" href='javascript:accordion($modinstanceid)'></a>\n".
					"\t</h3>\n";
				} else {
					$heading="\t<h3 class='heading'>".$item->name."</h3>\n";
				}
			}
		} else {
			if ($this->id==$item->id) {
				$current = ' class="current menu_item'.$item->id.'"';
			} else {
				$current = ' class="menu_item'.$item->id.'"';
			}
			if ($displayme===true) {
				$printmenu .= "$tabs<li$current>".print_item($item)."</li>\n";
			}
		}
	}
}
$printmenu .= "</ul>\n";

echo "<div class='menu' id='menu$modinstanceid'>\n".$heading.$printmenu."</div>\n";

//closed per default
if (!isset($_COOKIE["menu".$modinstanceid]) && $extensible) {
	echo "<script type='text/javascript'>fold($modinstanceid, 'none');</script>";
} elseif (isset($_COOKIE["menu".$modinstanceid]) && $_COOKIE["menu".$modinstanceid]=="open" && $extensible) {
	echo "<script type='text/javascript'>fold($modinstanceid, 'block');</script>";
} elseif (isset($_COOKIE["menu".$modinstanceid]) && $_COOKIE["menu".$modinstanceid]=="closed" && $extensible) {
	echo "<script type='text/javascript'>fold($modinstanceid, 'none');</script>";
}
?>
Return current item: chillyCMS