<?php

						/*************************************\
						
						    Handshakes Professional (3.3)
						            by DZOIC LTD
						       Copyright(c) 2005-2007
						        http://www.dzoic.com
						
						\*************************************/

						///////////////////////////////////////

						admin_validate_section("customize",7);
						$action = $GLOBALS["Get"]->val("action");

							switch($action){

								case '':
									menus();
									break;
									
								case 'edit_group':
									menu_edit_group();
									break;
									
								case 'save_group':
									menu_save_group();
									break;
									
								case 'delete_group':
									menu_delete_group();
									break;
									
								case 'edit_menu':
									edit_menu();
									break;
									
								case 'save_menu':
									save_menu();
									break;
									
								case 'edit_item':
									edit_menu_item();
									break;
									
								case 'repos_item':
									reposition_item();
									break;
									
								case 'save_item':
									save_menu_item();
									break;
									
								case 'save_pages':
									save_menu_pages();
									break;
									
								case 'create_menu':
									create_menu();
									break;
									
								case 'delete_item':
									delete_menu_item();
									break;
									
								case 'delete_menu':
									delete_menu();
									break;
									
								case 'save_menu_pages':
									save_menu_pages();
									break;
																	
							}//switch

						///////////////////////////////////////
						
function menus(){
	
	admin_validate();

	$data["themes"] = admin_get_themes();
	$data["menus"]  = array();
	$data["groups"] = array();

	$theme = $GLOBALS["Get"]->val("theme");
	
	if(!$theme)
		$theme = $GLOBALS["THEME"];
	
	if($theme){
		$menu_names = menus_scan($theme);
		foreach($menu_names as $menu_name){
			$menu_data     = menu_data($theme,$menu_name);
			$menu["name"]    = $menu_data["name"];
			$menu["type"]    = $menu_data["type"];
			$menu["items"]   = count($menu_data["items"]);
			$menu["edit"]    = "index.php?section=menus&action=edit_menu&theme=".$theme."&menu=".$menu_name;
			$menu["delete"]  = "index.php?section=menus&action=delete_menu&theme=".$theme."&menu=".$menu_name;
			$data["menus"][] = $menu;
			$sort_array[] = strtolower($menu["name"]);
		}//foreach
		
		array_multisort($sort_array,$data["menus"]);
		$sort_array = array();
		
		$page_groups = menu_page_groups($theme);
		while(list($key,$val) = each($page_groups)){
			$group["name"]    = $val["name"];
			$group["pages"]   = count(handle_empties(explode(",",$val["pages"])));
			$group["edit"]    = "index.php?section=menus&action=edit_group&theme=".$theme."&group=".$key;
			$group["delete"]  = "index.php?section=menus&action=delete_group&theme=".$theme."&group=".$key;
			$data["groups"][] = $group;
			$sort_array[] = strtolower($group["name"]);
		}//while
		
		array_multisort($sort_array,$data["groups"]);
		
		$layout[0] = "menus";
	}//if
	
	$data["theme"] = $theme;
	
	$data["section"] = "customize";
	$data["subsection"] = 7;
	$data["title_id"] = "36";	
	admin_output($layout,$data);
	
}//menus

function menus_scan($theme){
	
	$menus = array();
	
	$folder = DOC_ROOT."/themes/".$theme."/menus";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if(eregi("\.inc\.php",$file)){
			$menu_name = ereg_replace("\.inc\.php","",$file);
			$menus[] = $menu_name;
		}//if
	}//while
	closedir($dir);
	
	return $menus;
	
}//menus_scan

function create_menu(){
	
	admin_validate();
	$theme = $GLOBALS["Get"]->val("theme");
	$name  = stripslashes(html_entity_decode($GLOBALS["Get"]->val("name")));
	$items = $GLOBALS["Get"]->type_val("items","integer");
	
	$menu_name = ereg_replace("[^A-Za-z|0-9]","_",strtolower($name));
	$menu_name = ereg_replace("[_]+","_",$menu_name);
	
	if(empty($menu_name) || empty($items))
		load_page("index.php?section=menus&theme=".$theme."&err_id=15");
		
	if(file_exists(DOC_ROOT."/themes/".$theme."/menus/".$menu_name.".inc.php"))
		load_page("index.php?section=menus&theme=".$theme."&err_id=13");
	
	$menu["name"] = $name;
	for($i=1;$i<=$items;$i++){
		$menu["items"][$i] = array (
			"on"    => "",
			"off"   => "",
			"link"  => "",
			"page"  => "",
			"group" => ""
		);
	}//for
	$menu["type"] = "text";
	
	$new_menu = fopen(DOC_ROOT."/themes/".$theme."/menus/".$menu_name.".inc.php","w");
	fclose($new_menu);
	chmod(DOC_ROOT."/themes/".$theme."/menus/".$menu_name.".inc.php",0777);
	
	save_menu_data($theme,$menu_name,$menu);
	
	load_page("index.php?section=menus&action=edit_menu&theme=".$theme."&menu=".$menu_name);
	
}//create_menu

function menu_edit_group(){
	
	admin_validate();
	$theme = $GLOBALS["Get"]->val("theme");
	$group = $GLOBALS["Get"]->val("group");
	
	$groups = menu_page_groups($theme);
	$group_data = $groups[$group];
	
	$data["name"] = $group_data["name"];
	$group_pages = handle_empties(explode(",",$group_data["pages"]));
	
	$site_pages  = admin_get_pages($theme);
	
	$data["pages"] = array();
	$data["npages"] = array();
	
	foreach($group_pages as $group_page){
		$data["pages"][$group_page] = $site_pages[$group_page];
	}//foreach
	
	$nonform_pages = array_diff(array_keys($site_pages),array_keys($data["pages"]));
	foreach($nonform_pages as $nonform_page){
		$data["npages"][$nonform_page] = $site_pages[$nonform_page];
	}//foreach
	
	$layout[0] = "edit_page_group";
	
	$data["javascript"] = <<<JAVASCRIPTCODE
<script language="JavaScript">
<!--
	function HS_LoadOptions(FieldHandler, OptionsLine){
		if(OptionsLine != ''){
			ListItems = OptionsLine.split("|");
			OptionsHandler = FieldHandler.options;
			for(i=0;i<(ListItems.length/2);i++){
				j = i*2;
				OptionsHandler[i] = new Option(ListItems[j+1],ListItems[j]);
			}//for
		}//if
	}//HS_LoadOptions
	function HS_MoveOptions(FieldHandlerFrom, FieldHandlerTo){
		var TransferOptions = new Array();
		var j=0;
		var k=0;		
		OptionsHandlerFrom = FieldHandlerFrom.options;
		OptionsHandlerTo = FieldHandlerTo.options;		
		for(i=0;i<OptionsHandlerFrom.length;i++){
			if(OptionsHandlerFrom[i].selected == true){
				OptionsHandlerTo[OptionsHandlerTo.length] = 
				new Option(OptionsHandlerFrom[i].text,OptionsHandlerFrom[i].value);
				OptionsHandlerFrom[i] = null;
				TransferOptions[j] = i;
				j++;
				i--;				
			}//if
		}//for
	}//HS_MoveOptions
	function HS_PrepareData(FieldHandlerSrc, FieldHandlerResult){
		var ResultLine = "";
		OptionsHandlerSrc = FieldHandlerSrc.options;
		for(i=0;i<OptionsHandlerSrc.length;i++){
			ResultLine+= OptionsHandlerSrc[i].value + ",";
		}//for
		FieldHandlerResult.value = ResultLine;		
	}//HS_PrepareData	
//-->
</script>
JAVASCRIPTCODE;

	$group_pages  = "";
	$group_npages = "";
	while(list($key,$val) = each($data["pages"])){
		$group_pages.= $key."|".$val."|";
	}//while
	$group_pages = rtrim($group_pages,"|");
	while(list($key,$val) = each($data["npages"])){
		$group_npages.= $key."|".$val."|";
	}//while
	$group_npages = rtrim($group_npages,"|");	
	
	$data["onload"].= "HS_LoadOptions(document.group_edit.g_pages,'".htmlspecialchars(ereg_replace("'","\'",$group_pages))."');";
	$data["onload"].= "HS_LoadOptions(document.group_edit.g_npages,'".htmlspecialchars(ereg_replace("'","\'",$group_npages))."');";
	
	$data["theme"] = $theme;
	
	$data["section"] = "customize";
	$data["subsection"] = 7;
	$data["title_id"] = "36";	$data["group"] = $group;
	
	$data["link"] = "index.php?section=menus&theme=".$theme;
	
	admin_output($layout,$data);
	
}//menu_edit_group

function menu_save_group(){
	
	admin_validate();
	$theme = $GLOBALS["Get"]->val("theme");
	$group = $GLOBALS["Get"]->val("group");
	$name  = $GLOBALS["Get"]->val("name");
	$group_pages = $GLOBALS["Get"]->val("group_pages");
	
	$groups = menu_page_groups($theme);
	
	if(empty($group))
		$group = @max(array_keys($groups))+1;
		
	$groups[$group]["name"]  = $name;
	$groups[$group]["pages"] = $group_pages;
	
	$settings = "<?php\n\n";
	$settings.= go_through_array("\$page_groups",$groups);
	$settings.= "\n?>";
	
	$file_handler = fopen(DOC_ROOT."/themes/".$theme."/page_groups.inc.php","w");
	fwrite($file_handler,$settings);
	fclose($file_handler);
	
	load_page("index.php?section=menus&action=edit_group&theme=".$theme."&group=".$group);
	
}//menu_save_group

function menu_delete_group(){
	
	admin_validate();
	$theme = $GLOBALS["Get"]->val("theme");
	$group = $GLOBALS["Get"]->val("group");
	
	$groups = menu_page_groups($theme);
	unset($groups[$group]);
	
	$settings = "<?php\n\n";
	$settings.= go_through_array("\$page_groups",$groups);
	$settings.= "\n?>";
	
	$file_handler = fopen(DOC_ROOT."/themes/".$theme."/page_groups.inc.php","w");
	fwrite($file_handler,$settings);
	fclose($file_handler);
	
	load_page($GLOBALS["Get"]->referer());
	
}//menu_delete_group

function edit_menu(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$menu_name = $GLOBALS["Get"]->val("menu");
	$data["items"] = array();
	$site_pages  = admin_get_pages($theme);
	$groups = menu_page_groups($theme);
	
	$menu_data = menu_data($theme,$menu_name);
	
	$sql_query = "SELECT page FROM associations WHERE assoc_type='menu'
				  AND theme='".$theme."' AND association='".$menu_name."'";
	
	$result = $GLOBALS["DB"]->result($sql_query);
	$menu_pages = array();
	foreach($result as $res){
		$menu_pages[] = $res["page"];
	}//foreach
	
	$min = @min(array_keys($menu_data["items"]));
	$max = @max(array_keys($menu_data["items"]));
	while(list($key,$val) = each($menu_data["items"])){
		$switch = array();
		$item = array();
		$val["on"] = handle_menu_patterns(handle_special_menu_item($val["on"]));
		$val["off"] = handle_menu_patterns(handle_special_menu_item($val["off"]));
		if($menu_data["type"] == "text"){
			$item["on"]  = $val["on"];
			$item["off"] = $val["off"];
		}//if
		else{
			if($val["on"])
				$item["on"]  = admin_output_image($val["on"],0,"themes/".$theme."/gfx","",0,0);
			if($val["off"])
				$item["off"] = admin_output_image($val["off"],0,"themes/".$theme."/gfx","",0,0);
		}//else
		
		if($val["group"])
			$switch[] = "Group: ".$groups[$val["group"]]["name"];
		if($val["page"])
			$switch[] = "Page: ".$site_pages[$val["page"]];
			
		$item["switch"] = implode("<br />",$switch);
		
		if($key != $min)
			$item["move_up"] = "index.php?section=menus&action=repos_item&theme=".$theme."&menu=".$menu_name."&item=".$key."&direction=up";
		else
			$item["move_up"] = "";
			
		if($key != $max)
			$item["move_down"] = "index.php?section=menus&action=repos_item&theme=".$theme."&menu=".$menu_name."&item=".$key."&direction=down";
		else
			$item["move_down"] = "";
			
		$item["edit"]   = "index.php?section=menus&action=edit_item&theme=".$theme."&menu=".$menu_name."&item=".$key;
		$item["delete"] = "index.php?section=menus&action=delete_item&theme=".$theme."&menu=".$menu_name."&item=".$key;
			
		$data["items"][] = $item;
	}//while
	
	$data["menu"]       = $menu_name;
	$data["theme"]      = $theme;
	$data["menu_name"]  = $menu_data["name"];
	$data["link"]       = "index.php?section=menus&theme=".$theme;
	$data["section"]    = "customize";
	$data["subsection"] = 7;
	$data["title"]      = "Handshakes::Admin Console - Menus";
	
	$data["pages"] = array();
	$data["npages"] = array();
	
	foreach($menu_pages as $menu_page){
		$data["pages"][$menu_page] = $site_pages[$menu_page];
	}//foreach
	
	$nonform_pages = array_diff(array_keys($site_pages),array_keys($data["pages"]));
	foreach($nonform_pages as $nonform_page){
		$data["npages"][$nonform_page] = $site_pages[$nonform_page];
	}//foreach

	$data["javascript"] = <<<JAVASCRIPTCODE
<script language="JavaScript">
<!--
	function HS_LoadOptions(FieldHandler, OptionsLine){
		if(OptionsLine != ''){
			ListItems = OptionsLine.split("|");
			OptionsHandler = FieldHandler.options;
			for(i=0;i<(ListItems.length/2);i++){
				j = i*2;
				OptionsHandler[i] = new Option(ListItems[j+1],ListItems[j]);
			}//for
		}//if
	}//HS_LoadOptions
	function HS_MoveOptions(FieldHandlerFrom, FieldHandlerTo){
		var TransferOptions = new Array();
		var j=0;
		var k=0;		
		OptionsHandlerFrom = FieldHandlerFrom.options;
		OptionsHandlerTo = FieldHandlerTo.options;		
		for(i=0;i<OptionsHandlerFrom.length;i++){
			if(OptionsHandlerFrom[i].selected == true){
				OptionsHandlerTo[OptionsHandlerTo.length] = 
				new Option(OptionsHandlerFrom[i].text,OptionsHandlerFrom[i].value);
				OptionsHandlerFrom[i] = null;
				TransferOptions[j] = i;
				j++;
				i--;				
			}//if
		}//for
	}//HS_MoveOptions
	function HS_PrepareData(FieldHandlerSrc, FieldHandlerResult){
		var ResultLine = "";
		OptionsHandlerSrc = FieldHandlerSrc.options;
		for(i=0;i<OptionsHandlerSrc.length;i++){
			ResultLine+= OptionsHandlerSrc[i].value + ",";
		}//for
		FieldHandlerResult.value = ResultLine;		
	}//HS_PrepareData	
//-->
</script>
JAVASCRIPTCODE;

	$menu_pages = "";
	while(list($key,$val) = each($data["pages"])){
		$menu_pages.= $key."|".$val."|";
	}//while
	$menu_pages = rtrim($menu_pages,"|");
	while(list($key,$val) = each($data["npages"])){
		$menu_npages.= $key."|".$val."|";
	}//while
	$menu_npages = rtrim($menu_npages,"|");	
	
	$data["onload"].= "HS_LoadOptions(document.menu_edit.m_pages,'".htmlspecialchars(ereg_replace("'","\'",$menu_pages))."');";
	$data["onload"].= "HS_LoadOptions(document.menu_edit.m_npages,'".htmlspecialchars(ereg_replace("'","\'",$menu_npages))."');";
	
	$layout[0] = "edit_menu";
	
	admin_output($layout,$data);
	
}//edit_menu

function edit_menu_item(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$menu_name = $GLOBALS["Get"]->val("menu");
	$item = $GLOBALS["Get"]->val("item");
	
	$menu_data = menu_data($theme,$menu_name);
	$data["values"] = $menu_data["items"][$item];
	
	$data["pages"]  = admin_get_pages($theme);
	$data["groups"] = array();
	
	$groups = menu_page_groups($theme);
	while(list($key,$group) = each($groups)){
		$data["groups"][$key] = $group["name"];
	}//while
	
	$layout[0] = "edit_menu_item";
	
	$data["menu"]       = $menu_name;
	$data["theme"]      = $theme;
	$data["item"]       = $item;
	$data["menu_name"]  = $menu_data["name"];
	$data["link"]       = "index.php?section=menus&theme=".$theme."&action=edit_menu&menu=".$menu_name;
	$data["section"]    = "customize";
	$data["subsection"] = 7;
	$data["title"]      = "Handshakes::Admin Console - Menus";
	
	$data["patterns"] = array(
		"" => "Please, select...",
		"name" => "Member name",
		"new_messages_inbox" => "New inbox messages",
		"total_messages_inbox" => "Total inbox messages",
		"total_messages_sent" => "Total sent messages",
		"total_messages_archive" => "Total archived messages",
		"new_invitations" => "New invitations",
		"total_invitations" => "Total invitations",
		"new_testimonials" => "New testimonials",
		"total_testimonials" => "Total testimonials",
		"new_announcements" => "New announcements",
		"total_announcements" => "Total announcements",
		"new_actions" => "New actions",
		"total_actions" => "Total actions"
	);
	
	$data["conditions"] = array (
		"" => "Please, select...",
		"SPECIAL;;BOOKMARK;;PROFILE" => "Member is not bookmarked",
		"SPECIAL;;FRIENDSHIP" => "Member is not a friend",
		"SPECIAL;;IGNORE" => "Member is not ignored",
		"SPECIAL;;MAILBOX" => "There are new messages in the mailbox",
		"SPECIAL;;AD_OWNER" => "Member is author of currently viewed classified ad",
		"SPECIAL;;EVENT_OWNER" => "Member is author of currently viewed event",
		"SPECIAL;;CLUB_OWNER" => "Member is moderator of currently viewed club",
		"SPECIAL;;PRIVATE_CLUB_OWNER" => "Member is moderator of currently viewed private club",
		"SPECIAL;;BLOG_OWNER" => "Member is author of currently viewed blog",
		"SPECIAL;;BOOKMARK;;AD" => "Classified Ad is not bookmarked",
		"SPECIAL;;BOOKMARK;;EVENT" => "Event is not bookmarked",
		"SPECIAL;;BOOKMARK;;CLUB" => "Club is not bookmarked",
		"SPECIAL;;BOOKMARK;;BLOG" => "Blog is not bookmarked",
		"SPECIAL;;JOIN" => "User is  not a member of currently viewed club",
		"SPECIAL;;IMCONTACT" => "Member is not IM contact",
		"SPECIAL;;ATTEND_EVENT" => "Member already attends currently viewed event",
		"SPECIAL;;IS_PAID" => "User is a paid member"
	);
	
	$data["javascript"] = <<<JAVASCRIPTCODE
<script language="JavaScript">
<!--
	function HS_InsertPattern(FormHandler){
		var Pattern = FormHandler.patterns.options[FormHandler.patterns.selectedIndex].value;
		if(Pattern != ""){
			FormHandler.pattern.value = "|"+Pattern+"|";
		}//if
	}//HS_InsertPattern
	function HS_InsertLogic(FormHandler){
		var Condition = FormHandler.condition.options[FormHandler.condition.selectedIndex].value;
		var Option1 = FormHandler.option1.value;
		var Option2 = FormHandler.option2.value;
		var Logic = Condition+";;"+Option1+";;"+Option2;
		FormHandler.logic.value = Logic;
	}//HS_InsertLogic
//-->
</script>
JAVASCRIPTCODE;
	
	admin_output($layout,$data);
	
}//edit_menu_item

function save_menu_item(){
	
	admin_validate();
	
	$vals = array("theme","menu","item","on","off","link","page","group");
	$values = $GLOBALS["Get"]->arr($vals,1);
	
	$menu_data = menu_data($values["theme"],$values["menu"]);
	
	if(empty($values["item"]))
		$values["item"] = @max(array_keys($menu_data["items"]))+1;
	
	$menu_data["items"][$values["item"]]["on"]    = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$values["on"])));
	$menu_data["items"][$values["item"]]["off"]   = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$values["off"])));
	$menu_data["items"][$values["item"]]["link"]  = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$values["link"])));
	$menu_data["items"][$values["item"]]["page"]  = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$values["page"])));
	$menu_data["items"][$values["item"]]["group"] = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$values["group"])));
	
	save_menu_data($values["theme"],$values["menu"],$menu_data);
	
	load_page("index.php?section=menus&action=edit_item&theme=".$values["theme"]."&menu=".$values["menu"]."&item=".$values["item"]);
	
}//save_menu_item

function reposition_item(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$menu_name = $GLOBALS["Get"]->val("menu");
	$item = $GLOBALS["Get"]->val("item");
	$direction = $GLOBALS["Get"]->val("direction");
	
	$menu_data = menu_data($theme,$menu_name);
	
	if($direction == "up")
		$newposition = $item-1;
	elseif($direction == "down")
		$newposition = $item+1;
		
	list($menu_data["items"][$item],$menu_data["items"][$newposition]) = array ($menu_data["items"][$newposition],$menu_data["items"][$item]);
	
	save_menu_data($theme,$menu_name,$menu_data);
	
	load_page($GLOBALS["Get"]->referer());
	
}//reposition_item

function delete_menu_item(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$menu_name = $GLOBALS["Get"]->val("menu");
	$item = $GLOBALS["Get"]->val("item");
	
	$menu_data = menu_data($theme,$menu_name);
	unset($menu_data["items"][$item]);
	
	save_menu_data($theme,$menu_name,$menu_data);
	
	load_page($GLOBALS["Get"]->referer());
	
}//delete_menu_item

function delete_menu(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$menu_name = $GLOBALS["Get"]->val("menu");
	
	@unlink(DOC_ROOT."/themes/".$theme."/menus/".$menu_name.".inc.php");
	
	$sql_query = "DELETE FROM associations WHERE `assoc_type`='menu' AND `association`='".$menu_name."' AND `theme`='".$theme."'";
	$GLOBALS["DB"]->execute($sql_query);
	
	load_page("index.php?section=menus&theme=".$theme);
	
}//delete_menu

function save_menu_pages(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$menu_name = $GLOBALS["Get"]->val("menu");
	
	$menu_pages = $GLOBALS["Get"]->val("menu_pages");
	$menu_pages = handle_empties(explode(",",$menu_pages));
			
	$sql_query = "DELETE FROM associations WHERE `assoc_type`='menu' AND `association`='".$menu_name."' AND `theme`='".$theme."'";
	$GLOBALS["DB"]->execute($sql_query);
	
	foreach($menu_pages as $p){
		$sql_query = "INSERT INTO associations (`assoc_type`,`page`,`association`,`theme`)
					  VALUES ('menu','".$p."','".$menu_name."','".$theme."')";
		$GLOBALS["DB"]->execute($sql_query);
	}//foreach
	
	load_page("index.php?section=menus&action=edit_menu&theme=".$theme."&menu=".$menu_name);
	
}//save_menu_pages

function menu_data($theme,$menu_name){
	
	$menu_xml = implode("",file(DOC_ROOT."/themes/".$theme."/menus/".$menu_name.".inc.php"));
	
	$menu_xml = handle_xml_entities($menu_xml);	
	$parser = xml_parser_create();
	
	if(!IGNORE_XML_ENCODING){
		$encoding = extract_encoding("html",$theme);
		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $encoding);
	}//if
	
	xml_parse_into_struct($parser,$menu_xml,$xml_elements,$xml_index);
	
	$i=1;
	
	foreach($xml_elements as $element){
		$tag        = hs_strtolower($element["tag"]);
		$type       = $element["type"];
		$value      = $element["value"];
		$level      = $element["level"];
		$attributes = $element["attributes"];
		
		if($tag == "menu" && $type == "open"){
			$menu["name"] = $attributes["NAME"];
			$menu["type"] = $attributes["TYPE"];
		}//if
		elseif($tag == "item" && $type == "open"){
			$menu["items"][$i]["group"] = $attributes["GROUP"];
			$menu["items"][$i]["page"]  = $attributes["PAGE"];
		}//elseif
		elseif($tag == "item" && $type == "close"){
			$i++;
		}//elseif
		elseif($tag == "on" && $type == "complete"){			
			$menu["items"][$i]["on"] = $value;
		}//elseif
		elseif($tag == "off" && $type == "complete"){
			$menu["items"][$i]["off"] = $value;
		}//elseif
		elseif($tag == "link" && $type == "complete"){
			$menu["items"][$i]["link"] = $value;
		}//elseif
		
	}//foreach
	
	return $menu;
	
}//menu_data

function save_menu_data($theme,$menu_name,$data){
	
	$settings = "<menu name=\"".htmlspecialchars($data["name"])."\" type=\"".htmlspecialchars($data["type"])."\">\n";
	while(list($key,$item) = each($data["items"])){
		$settings.= "\t<item page=\"".htmlspecialchars($item["page"])."\" group=\"".htmlspecialchars($item["group"])."\">\n";
		$settings.= "\t\t<on>".htmlspecialchars($item["on"])."</on>\n";
		$settings.= "\t\t<off>".htmlspecialchars($item["off"])."</off>\n";
		$settings.= "\t\t<link>".htmlspecialchars($item["link"])."</link>\n";
		$settings.= "\t</item>\n";
	}//while
	$settings.= "</menu>";
	
	$file_handler = fopen(DOC_ROOT."/themes/".$theme."/menus/".$menu_name.".inc.php","w");
	fwrite($file_handler,$settings);
	fclose($file_handler);
	
}//save_menu_data

function menu_page_groups($theme){
	
	include(DOC_ROOT."/themes/".$theme."/page_groups.inc.php");
	return $page_groups;	
	
}//menu_page_groups
						
?>