<?php

	// get the current section from the page, which comes from the wrapper script
	$current_page = $page;
	list($current_section) = explode("_", $current_page);
	
	// define the contents of the menus and submenus
	$menu_items = Array();
	$menu_items[] = Array(
		"name" => "Content", "section" => "content", "pages" => Array(
			Array("name" => "Edit", "page" => "content_edit"),
			Array("name" => "Review", "page" => "content_review"),
			Array("name" => "History", "page" => "content_history")
		)
	);
	if (CONTENT_TYPE == "contemplate") {
		// this feature only works with Contemplate sites
		$menu_items[0]["pages"][] = Array("name" => "Browse site", "page" => "content_browse");
	}
	if ($role > 1) {
		if ((CONTENT_TYPE == "contemplate")||(CONTENT_TYPE == "dreamweaver")) {
			$menu_items[] = Array("name" => "Pages", "section" => "pages", "pages" => Array());
			$menu_items[1]["pages"][] = Array("name" => "Manage", "page" => "pages_manage");
		}
	}
	$menu_items[] = Array(
		"name" => "Files", "section" => "files", "pages" => Array(
			Array("name" => "Manage", "page" => "files_manage")
		)
	);
	$menu_items[] = Array(
		"name" => "Users", "section" => "users", "pages" => Array(
			Array("name" => "Manage", "page" => "users_manage")
		)
	);
	
	// build the menu and identify the submenu
	$menu = Array();
	foreach($menu_items as $menu_item) {
		if ($current_section == $menu_item["section"]) {
			$menu[] = $menu_item["name"];
			$submenu_items = $menu_item["pages"];
			$submenu_section = $menu_item["section"];
		} else {
			$start_name = $menu_item["name"];
			$start_page = $menu_item["pages"][0]["page"];
			$menu[] = "<a href=\"$wrapper_page?page=$start_page\">$start_name</a>";
		}
	}
	$menu = implode("\n\n|\n\n", $menu);
	
	// build the submenu
	if (isset($submenu_items)) {
		$submenu = Array();
		foreach($submenu_items as $submenu_item) {
			if ($current_page == $submenu_item["page"]) {
				$submenu[] = $submenu_item["name"];
			} else {
				$name = $submenu_item["name"];
				$page = $submenu_item["page"];
				$submenu[] = "<a href=\"$wrapper_page?page=$page\">$name</a>";
			}
		}
		$submenu = implode("\n\n|\n\n", $submenu);
	} else {
		$submenu = "&nbsp;";
	}

	// if we're logged in, display the menu, submenu and status with a logout link
	if ($user) {
		print "<div class=\"toolbar\">\n";
		print "<p class=\"toolbar_menu\">".$menu."</p>\n";
		print "<p class=\"toolbar_submenu\">".$submenu."</p>\n";
		print "<div class=\"toolbar_status\">\n";
		print "<p class=\"toolbar_menu\">\n";
		print "Logged&nbsp;in&nbsp;as&nbsp;<a href=\"$wrapper_page?page=users_edit&ID=$user\">$username</a>\n";
		print "|\n";
		print "<a href=\"$wrapper_page?page=logout_submit\">Log out</a>\n";
		print "</p>\n";
		print "</div>\n";
		print "</div>\n";
	}
	
?>

<div class="page_margin">
