<?php

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

						///////////////////////////////////////
						
						admin_validate_section("customize",12);
						$action = $GLOBALS["Get"]->val("action");
								
							switch($action){								
										
								case '':
									translate_manager();
									break;
									
								case 'start':
									start_translate();
									break;
									
								case 'save_completes':
									save_completes();
									break;
									
								case 'errors':
									errors();
									break;
								
								case 'save_errors':
									save_errors();
									break;
									
								case 'emails':
									emails();
									break;
									
								case 'save_emails':
									save_emails();
									break;
									
								case 'titles':
									titles();
									break;
									
								case 'save_titles':
									save_titles();
									break;
									
								case 'invitation':
									invitation();
									break;
									
								case 'save_invitations':
									save_invitations();
									break;
									
								case 'tips':
									tips();
									break;
									
								case 'save_tips':
									save_tips();
									break;
									
								case 'labels':
									labels();
									break;
									
								case 'save_labels':
									save_labels();
									break;
									
								case 'menus':
									menus();
									break;
									
								case 'save_menus':
									save_menus();
									break;
									
								case 'options':
									options();
									break;
									
								case 'save_options':
									save_options();
									break;
									
								case 'wording':
									wording();
									break;
									
								case 'save_wording':
									save_wording();
									break;
									
								case 'translate_done':
									translate_done();
									break;
																		
							}//switch
							
						///////////////////////////////////////
						
function translate_manager(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$data["themes"] = admin_get_themes();
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_manager";
	
	admin_output($layout,$data);
	
}//translate_manager

function start_translate(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["themes"] = admin_get_themes();
	
	include(DOC_ROOT."/themes/".$theme."/system/completes.inc.php");
	$data["completes"] = $completes;
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_system_completes";
	
	admin_output($layout,$data);
	
}//start_translate

function save_completes(){
	
	admin_validate();
	
	$completes = $GLOBALS["Get"]->val("completes");
	$theme     = $GLOBALS["Get"]->val("theme");
	
	$write_str = "<?php\n\n";
	$write_str.= go_through_array("\$completes",$completes);
	$write_str.= "\n?>";
	
	$file = DOC_ROOT."/themes/".$theme."/system/completes.inc.php";
	$file_handler = fopen($file,"w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	load_page("index.php?section=translate&action=errors&theme=".$theme);
	
}//save_completes

function errors(){
	
	admin_validate();
	
	$data["themes"] = admin_get_themes();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	include(DOC_ROOT."/themes/".$theme."/system/errors.inc.php");
	$data["errors"] = $errors;
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_system_errors";
	
	admin_output($layout,$data);
	
}//errors

function save_errors(){
	
	admin_validate();
	
	$theme  = $GLOBALS["Get"]->val("theme");
	$errors = $GLOBALS["Get"]->val("errors");
	
	$write_str = "<?php\n\n";
	$write_str.= go_through_array("\$errors",$errors);
	$write_str.= "\n?>";
	
	$file = DOC_ROOT."/themes/".$theme."/system/errors.inc.php";
	$file_handler = fopen($file,"w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	load_page("index.php?section=translate&action=emails&theme=".$theme);
	
}//save_errors

function emails(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$data["themes"] = admin_get_themes();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	include(DOC_ROOT."/themes/".$theme."/system/messages.inc.php");
	$data["messages"] = $messages;
	
	$patterns[0] = array (
		"|recipient_name|" => "recipient name",
		"|login|" => "member login (email/username)",
		"|password|" => "member password",
		"|link|" => "email verification link",
		"|code|" => "email verification code"
	);
	
	$patterns[1] = array (
		"|recipient_name|" => "recipient name",
		"|login|" => "member login (email/username)",
		"|password|" => "member password"
	);
	
	$patterns[2] = array (
		"|recipient_name|" => "recipient name",
		"|login|" => "member login (email/username)",
		"|password|" => "member password"
	);
	
	$patterns[3] = array (
		"|recipient_name|" => "recipient name",
		"|login|" => "member login (email/username)",
		"|password|" => "member password"
	);
	
	$patterns[4] = array (
		"|subject|" => "invitation subject",
		"|body|" => "invitation message",
		"|link|" => "invitation link"
	);
	
	$patterns[5] = array (
		"|recipient_name|" => "recipient name"		
	);
	
	$patterns[6] = array (
		"|recipient_name|" => "recipient name",
		"|login|" => "member login (email/username)",
		"|password|" => "member password"
	);
	
	$patterns[7] = array (
		"|subject|" => "invitation subject",
		"|body|" => "invitation message",
		"|link|" => "invitation link"
	);
	
	$patterns[8] = array (
		"|recipient_name|" => "recipient name",
		"|link|" => "eCard URL"
	);
	
	$patterns[9] = array (
		"|recipient_name|" => "recipient name",
		"|invitee_name|" => "invitee member name"
	);
	
	$patterns[10] = array (
		"|recipient_name|" => "recipient name",
		"|person_email|" => "eCard viewer email"
	);
	
	$patterns[11] = array (
		"|recipient_name|" => "recipient name",
		"|member_name|" => "eCard viewer name"
	);
	
	$patterns[12] = array (
		"|member_name|" => "member name",
		"|recipient_name|" => "recipient name",
		"|blog_name|" => "blog name"
	);
	
	$patterns[13] = array (
		"|subject|" => "invitation subject",
		"|body|" => "invitation message",
		"|link|" => "invitation link"
	);
	
	$patterns[14] = array (
		"|member_name|" => "member name",
		"|recipient_name|" => "recipient name",
		"|classified_ad_name|" => "classified ad name"
	);
	
	$patterns[15] = array (
		"|subject|" => "invitation subject",
		"|body|" => "invitation message",
		"|link|" => "invitation link"
	);
	
	$patterns[16] = array (
		"|member_name|" => "member name",
		"|recipient_name|" => "recipient name",
		"|event_name|" => "event name"
	);
	
	$patterns[17] = array (
		"|subject|" => "invitation subject",
		"|body|" => "invitation message",
		"|link|" => "invitation link"
	);
	
	$patterns[18] = array (
		"|member_name|" => "member name",
		"|recipient_name|" => "recipient name",
		"|club_name|" => "club name"
	);
	
	$patterns[19] = array (
		"|subject|" => "invitation subject",
		"|body|" => "invitation message",
		"|link|" => "invitation link"
	);
	
	$patterns[20] = array (
		"|recipient_name|" => "recipient name",
		"|search_name|" => "saved search name",
		"|items|" => "search matches"
	);
	
	$patterns[21] = array (
		"|recipient_name|" => "recipient name",
		"|item_type|" => "item type",
		"|item_name|" => "item name"
	);
	
	$patterns[22] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "blog name",
		"|link|" => "unsubscribe link"
	);
	
	$patterns[23] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "blog name"
	);
	
	$patterns[24] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "classified ad name",
		"|link|" => "unsubscribe link"
	);
	
	$patterns[25] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "classified ad name"
	);
	
	$patterns[26] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "event name",
		"|link|" => "unsubscribe link"
	);
	
	$patterns[27] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "event name"
	);
	
	$patterns[28] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "club name",
		"|link|" => "unsubscribe link"
	);
	
	$patterns[29] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "club name"
	);
	
	$patterns[30] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "classified ad name",
		"|link|" => "unsubscribe link"
	);
	
	$patterns[31] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "classified ad name"
	);
	
	$patterns[32] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "event name",
		"|link|" => "unsubscribe link"
	);
	
	$patterns[33] = array (
		"|recipient_name|" => "recipient name",
		"|name|" => "event name"
	);
	
	$patterns[34] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[35] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[36] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[37] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[38] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[39] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[40] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[41] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[42] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[43] = array (
		"|recipient_name|" => "recipient name"
	);
	
	$patterns[44] = array (
	"|recipient_name|" => "recipient name",
	"|site_name|" => "site name"
	);
	    
	$patterns[45] = array (
	"|recipient_name|" => "recipient name",
	"|site_name|" => "site name"
	);
	
	$patterns[100] = array (
		"|member_name|" => "member name"
	);
	
	$patterns[101] = array (
		"|member_name|" => "member name"
	);
	
	$patterns[102] = array (
		"|club_name|" => "club name",
		"|member_name|" => "member name"
	);
	
	$patterns[103] = array (
		"|member_name|" => "invitee member name",
		"|member_name2|" => "invited member name",
		"|club_name|" => "club name"
	);
	
	$patterns[104] = array (
		"|club_name|" => "club name",
		"|member_name|" => "member name"
	);
	
	$patterns[105] = array (
		"|club_name|" => "club name",
		"|member_name|" => "member name"
	);
	
	$patterns[106] = array (
		"|member_name|" => "member name",
		"|custommessage|" => "custom message"
	);
	
	$patterns[107] = array (
		"|member_name|" => "member name",
		"|blog_name|" => "blog name"
	);
	
	$patterns[108] = array (
		"|member_name|" => "member name",
		"|classified_ad_name|" => "classified ad name"
	);
	
	$patterns[109] = array (
		"|member_name|" => "member name",
		"|event_name|" => "event name"
	);
	
	$patterns[110] = array (
		"|member_name|" => "member name",
		"|club_name|" => "club name"
	);
	
	$data["patterns"] = $patterns;
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_system_emails";
	
	admin_output($layout,$data);
	
}//emails

function save_emails(){
	
	admin_validate();
	
	$subjects = $GLOBALS["Get"]->val("subjects");
	$bodies   = $GLOBALS["Get"]->val("bodies");
	$theme    = $GLOBALS["Get"]->val("theme");
	
	$write_str = "<?php\n\n";
	while(list($key,$val) = each($subjects)){
		$subject = stripslashes(html_entity_decode($val));
		$subject = hs_ereg_replace('"','\"',$subject);
		$subject = hs_ereg_replace(preg_quote("&#124;"),"|",$subject);
		$body    = stripslashes(html_entity_decode($bodies[$key]));
		$body    = hs_ereg_replace('"','\"',$body);
		$body    = hs_ereg_replace(preg_quote("&#124;"),"|",$body);
		$write_str.= "\$messages[\"subject\"][".$key."] = \"".$subject."\";\n";
		$write_str.= "\$messages[\"body\"][".$key."] = \"".$body."\";\n\n";
	}//while
	$write_str.= "\n?>";
	
	$file = DOC_ROOT."/themes/".$theme."/system/messages.inc.php";
	$file_handler = fopen($file,"w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	load_page("index.php?section=translate&action=titles&theme=".$theme);
	
}//save_emails

function titles(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["themes"] = admin_get_themes();
	
	include(DOC_ROOT."/themes/".$theme."/titles.inc.php");	
	$data["titles"] = $titles;
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_pages_titles";
	
	admin_output($layout,$data);
	
}//titles

function save_titles(){
	
	admin_validate();	
	
	$titles = $GLOBALS["Get"]->val("titles");
	$theme = $GLOBALS["Get"]->val("theme");
	
	$write_str = "<?php\n\n";
	$write_str.= go_through_array("\$titles",$titles);
	$write_str.= "\n?>";
	
	$file = DOC_ROOT."/themes/".$theme."/titles.inc.php";
	$file_handler = fopen($file,"w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	load_page("index.php?section=translate&action=invitation&theme=".$theme);
	
}//save_titles

function invitation(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["themes"] = admin_get_themes();
	
	include(DOC_ROOT."/themes/".$theme."/invitations.inc.php");
	
	$data["invitations"] = $invitations;
	$data["titles"][invite]      = "General Invitation";
	$data["titles"][ecards]      = "eCard Invitation";
	$data["titles"][blogs]       = "Blog Invitation";
	$data["titles"][classifieds] = "Classified Ad Invitation";
	$data["titles"][events]      = "Event Invitation";
	$data["titles"][clubs]       = "Clubs Invitation";
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_invitations";
	
	admin_output($layout,$data);
	
}//invitation

function save_invitations(){
	
	admin_validate();
	
	$subjects = $GLOBALS["Get"]->val("subjects");
	$bodies   = $GLOBALS["Get"]->val("bodies");
	$theme    = $GLOBALS["Get"]->val("theme");
	
	$write_str = "<?php\n\n";
	while(list($key,$val) = each($subjects)){
		$subject = stripslashes(html_entity_decode($val));
		$subject = hs_ereg_replace('"','\"',$subject);
		$subject = hs_ereg_replace(preg_quote("&#124;"),"|",$subject);
		$body    = stripslashes(html_entity_decode($bodies[$key]));
		$body    = hs_ereg_replace('"','\"',$body);
		$body    = hs_ereg_replace(preg_quote("&#124;"),"|",$body);
		$write_str.= "\$invitations[".$key."][\"subject\"] = \"".$subject."\";\n";
		$write_str.= "\$invitations[".$key."][\"body\"] = \"".$body."\";\n\n";
	}//while
	$write_str.= "\n?>";
	
	$file_handler = fopen(DOC_ROOT."/themes/".$theme."/invitations.inc.php","w");
	fwrite($file_handler, $write_str);
	fclose($file_handler);
	
	load_page("index.php?section=translate&action=tips&theme=".$theme);
	
}//save_invitation

function tips(){
	
	admin_validate();
	
	$data["themes"] = admin_get_themes();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["pages"] = admin_get_pages($theme);
	
	$sql_query = "SELECT page,message FROM tips WHERE theme='".$theme."'";
	$result = $GLOBALS["DB"]->result($sql_query);
	$tips = array();
	foreach($result as $res){
		$tips[$res["page"]] = $res["message"];
	}//foreach
	
	$data["tips"] = $tips;
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_tips";
	
	admin_output($layout,$data);
	
}//tips

function save_tips(){
	
	admin_validate();
	
	$tips = $GLOBALS["Get"]->val("tips");
	$theme = $GLOBALS["Get"]->val("theme");
	
	$sql_query = "DELETE FROM tips WHERE theme='".$theme."'";
	$GLOBALS["DB"]->execute($sql_query);
	
	while(list($key,$val) = each($tips)){
		$val = stripslashes(html_entity_decode($val));
		$val = hs_ereg_replace(preg_quote("&#124;"),"|",$val);
		$val = ereg_replace("\\\\","\\\\",$val);
		$sql_query = "INSERT INTO tips (page,message,theme)
					  VALUES ('".$key."','".ereg_replace("'","\'",$val)."','".$theme."')";
		$GLOBALS["DB"]->execute($sql_query);
	}//while
	
	load_page("index.php?section=translate&action=labels&theme=".$theme);
	
}//save_tips

function labels(){
	
	admin_validate();
	
	$data["themes"] = admin_get_themes();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["formlabels"] = formlabels($theme);
	$data["outputlabels"] = outputlabels($theme);
	$data["buttonlabels"] = buttonlabels($theme);
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_labels";
	
	admin_output($layout,$data);
	
}//labels

function formlabels($theme){
	
	$labels = array();
	$folder = DOC_ROOT."/themes/".$theme."/forms";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php",$file)){
			$form["labels"] = array();
			include($folder."/".$file);			
			reset($form["labels"]);
			while(list($key,$val) = each($form["labels"])){
				if($val && !in_array($val,$labels)){
					$key = urlencode($val);
					$labels[$key] = $val;
				}//if
			}//while
		}//if
	}//while
	closedir($dir);
	
	return $labels;
	
}//formlabels

function outputlabels($theme){
	
	$labels = array();
	$folder = DOC_ROOT."/themes/".$theme."/profiles";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php",$file)){
			$output["labels"] = array();
			include($folder."/".$file);
			reset($output["labels"]);
			while(list($key,$val) = each($output["labels"])){
				if($val && !in_array($val,$labels)){
					$key = urlencode($val);
					$labels[$key] = $val;
				}//if
			}//while
		}//if
	}//while
	closedir($dir);
	
	return $labels;
	
}//outputlabels

function buttonlabels($theme){
	
	$labels = array();
	$folder = DOC_ROOT."/themes/".$theme."/forms";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php",$file)){
			$form["txt_buttons"] = array();
			include($folder."/".$file);
			reset($form["txt_buttons"]);
			while(list($key,$val) = each($form["txt_buttons"])){
				if($val && !in_array($val,$labels)){
					$key = urlencode($val);
					$labels[$key] = $val;
				}//if
			}//while
		}//if
	}//while
	closedir($dir);
	
	return $labels;
	
}//buttonlabels

function save_labels(){
	
	admin_validate();
	
	$formlabels = $GLOBALS["Get"]->val("formlabels");
	$outputlabels = $GLOBALS["Get"]->val("outputlabels");
	$buttonlabels = $GLOBALS["Get"]->val("buttonlabels");
	$theme = $GLOBALS["Get"]->val("theme");
	
	save_formlabels($theme,$formlabels);
	save_outputlabels($theme,$outputlabels);
	save_buttonlabels($theme,$buttonlabels);
	
	load_page("index.php?section=translate&action=menus&theme=".$theme);
	
}//save_labels

function save_formlabels($theme,$formlabels_new){
	
	$formlabels = formlabels($theme);
	
	$folder = DOC_ROOT."/themes/".$theme."/forms";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php",$file)){			
			$form_name = ereg_replace("\.inc\.php","",$file);
			$form = array();
			$form["labels"] = array();
			$form = form_data($theme,$form_name);
			reset($form["labels"]);
			while(list($key,$val) = each($form["labels"])){
				$k = array_search($val,$formlabels);
				if(!extract_null_value($k))
				$form["labels"][$key] = $formlabels_new[$k];
			}//while
			save_form($folder."/".$file,$form);
		}//if
	}//while
	closedir($dir);
	
}//save_formlabels

function save_outputlabels($theme,$outputlabels_new){
	
	$outputlabels = outputlabels($theme);
	
	$folder = DOC_ROOT."/themes/".$theme."/profiles";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php",$file)){
			$output = array();
			$output["labels"] = array();
			include($folder."/".$file);
			reset($output["labels"]);
			while(list($key,$val) = each($output["labels"])){
				$k = array_search($val,$outputlabels);
				if(!extract_null_value($k))
				$output["labels"][$key] = $outputlabels_new[$k];
			}//while
			save_output($folder."/".$file,$output);
		}//if
	}//while
	closedir($dir);
	
}//save_outputlabels

function save_buttonlabels($theme,$buttonlabels_new){
	
	$buttonlabels = buttonlabels($theme);
	
	$folder = DOC_ROOT."/themes/".$theme."/forms";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php",$file)){			
			$form_name = ereg_replace("\.inc\.php","",$file);
			$form = array();
			$form["txt_buttons"] = array();
			$form = form_data($theme,$form_name);
			reset($form["txt_buttons"]);
			while(list($key,$val) = each($form["txt_buttons"])){
				$k = array_search($val,$buttonlabels);
				if(!extract_null_value($k))
				$form["txt_buttons"][$key] = $buttonlabels_new[$k];
			}//while
			save_form($folder."/".$file,$form);
		}//if
	}//while
	closedir($dir);
	
}//save_buttonlabels

function form_data($theme,$form_name){
	
	include(DOC_ROOT."/themes/".$theme."/forms/".$form_name.".inc.php");
	return $form;
	
}//form_data

function save_form($form_file,$form){
	
	$form_str = "<?php\n\n";
	$form_str.= go_through_array("\$form",$form);
	$form_str.= "\n?>";
	
	$file_handler = fopen($form_file,"w");
	fwrite($file_handler,$form_str);
	fclose($file_handler);
	
}//save_form

function save_output($output_file,$output){
	
	$output_str = "<?php\n\n";
	$output_str.= go_through_array("\$output",$output);
	$output_str.= "\n?>";
	
	$file_handler = fopen($output_file,"w");
	fwrite($file_handler,$output_str);
	fclose($file_handler);
	
}//save_output

function menus(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["themes"] = admin_get_themes();
	
	$data["menus"] = theme_menus($data["theme"]);
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_menus";
	
	admin_output($layout,$data);
	
}//menus

function theme_menus($theme){
	
	$menus = array();
	
	$folder = DOC_ROOT."/themes/".$theme."/menus";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php$",$file)){
			$menu = menu_wording($folder."/".$file,$theme);
			$menus = array_merge($menus,$menu);
		}//if
	}//while
	closedir($dir);
	
	return $menus;
	
}//theme_menus

function menu_wording($mfile,$theme){
	
	$wording = array();
	
	$menu_xml = implode("",file($mfile));
	
	$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=0;
	
	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"){
			$name = $attributes["NAME"];
			$type = $attributes["TYPE"];
			if($type != "text")
				break;
		}//if
		elseif($tag == "on" && $type == "complete"){			
			if($value!="")
			$wording[] = $value;
		}//elseif
		elseif($tag == "off" && $type == "complete"){
			if($value!="")
			$wording[] = $value;
		}//elseif
	}//foreach	
	
	return $wording;
	
}//menu_wording

function save_menus(){
	
	admin_validate();
	
	$menus = $GLOBALS["Get"]->val("menus");
	$theme = $GLOBALS["Get"]->val("theme");
	
	save_theme_menus($theme,$menus);
	
	load_page("index.php?section=translate&action=options&theme=".$theme);
	
}//save_menus

function save_theme_menus($theme,$wording){
	
	$old_wording = theme_menus($theme);
	
	$folder = DOC_ROOT."/themes/".$theme."/menus";
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php$",$file)){
			replace_menu_wording($folder."/".$file,$old_wording,$wording,$theme);
		}//if
	}//while
	closedir($dir);
	
}//save_theme_menus

function replace_menu_wording($mfile,$old_wording,$new_wording,$theme){
	
	$menu_xml = implode("",file($mfile));
	
	$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=0;
	
	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"){
			$word = array_search($value,$old_wording);
			if(!extract_null_value($word))
				$menu["items"][$i]["on"] = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$new_wording[$word])));
			else
				$menu["items"][$i]["on"] = $value;
		}//elseif
		elseif($tag == "off" && $type == "complete"){
			$word = array_search($value,$old_wording);
			if(!extract_null_value($word))
				$menu["items"][$i]["off"] = stripslashes(html_entity_decode(hs_ereg_replace(preg_quote("&#124;"),"|",$new_wording[$word])));
			else
				$menu["items"][$i]["off"] = $value;
		}//elseif
		elseif($tag == "link" && $type == "complete"){
			$menu["items"][$i]["link"] = $value;
		}//elseif
		
	}//foreach	
	
	$xml = "<menu name=\"".$menu["name"]."\" type=\"".$menu["type"]."\">\n";
	for($i=0;$i<count($menu["items"]);$i++){
		$xml.= "\t<item page=\"".htmlspecialchars($menu["items"][$i]["page"])."\" group=\"".htmlspecialchars($menu["items"][$i]["group"])."\">\n";
		$xml.= "\t\t<on>".htmlspecialchars($menu["items"][$i]["on"])."</on>\n";
		$xml.= "\t\t<off>".htmlspecialchars($menu["items"][$i]["off"])."</off>\n";
		$xml.= "\t\t<link>".htmlspecialchars($menu["items"][$i]["link"])."</link>\n";
		$xml.= "\t</item>\n";
	}//for
	$xml.= "</menu>";
	
	$file_handler = fopen($mfile,"w");
	fwrite($file_handler,$xml);
	fclose($file_handler);
	
}//replace_menu_wording

function options(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["themes"] = admin_get_themes();
	
	$data["options"] = theme_options($data["theme"]);
	$data["categories"] = theme_categories($data["theme"]);
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_options";
	
	admin_output($layout,$data);
	
}//options

function theme_options($theme){
	
	$total_options = array();
	
	$folder = DOC_ROOT."/themes/".$theme."/options";
	
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php$",$file)){			
			include($folder."/".$file);
			reset($options);
			while(list($key,$val) = each($options)){
				if(!in_array($val,$total_options))
					$total_options[] = $val;
			}//while			
		}//if
	}//while
	closedir($dir);
	
	return $total_options;
	
}//theme_options

function theme_categories($theme){
	
	$total_categories = array();
	
	$folder = DOC_ROOT."/themes/".$theme."/system";
	
	//clubs categories
	include($folder."/clb_categories.inc.php");
	while(list($key,$val) = each($categories)){
		if(!in_array($val,$total_categories))
		$total_categories[] = $val;
		while(list($k,$v) = each($subcategories[$key])){
			if(!in_array($v,$total_categories))
			$total_categories[] = $v;
		}//while
		reset($subcategories[$key]);
	}//while
	reset($categories);
	
	//classifieds categories
	include($folder."/cls_categories.inc.php");
	while(list($key,$val) = each($categories)){
		if(!in_array($val,$total_categories))
		$total_categories[] = $val;
		while(list($k,$v) = each($subcategories[$key])){
			if(!in_array($v,$total_categories))
			$total_categories[] = $v;
		}//while
		reset($subcategories[$key]);
	}//while
	reset($categories);
	
	//events categories
	include($folder."/evn_categories.inc.php");
	while(list($key,$val) = each($categories)){
		if(!in_array($val,$total_categories))
		$total_categories[] = $val;
		while(list($k,$v) = each($subcategories[$key])){
			if(!in_array($v,$total_categories))
			$total_categories[] = $v;
		}//while
		reset($subcategories[$key]);
	}//while
	reset($categories);
	
	//ecards categories
	include($folder."/ecards_categories.inc.php");
	while(list($key,$val) = each($categories)){
		if(!in_array($val,$total_categories))
		$total_categories[] = $val;
		while(list($k,$v) = each($subcategories[$key])){
			if(!in_array($v,$total_categories))
			$total_categories[] = $v;
		}//while
		reset($subcategories[$key]);
	}//while
	reset($categories);
	
	return $total_categories;
	
}//theme_categories

function save_options(){
	
	admin_validate();
	
	$options = $GLOBALS["Get"]->val("options");
	$categories = $GLOBALS["Get"]->val("categories");
	$theme = $GLOBALS["Get"]->val("theme");
	
	save_theme_options($theme,$options);
	save_theme_categories($theme,$categories);	
	
	load_page("index.php?section=translate&action=wording&theme=".$theme);
	
}//save_options

function save_theme_options($theme,$options_new){
	
	$options_old = theme_options($theme);
	
	$folder = DOC_ROOT."/themes/".$theme."/options";
	
	$dir = opendir($folder);
	while($file = readdir($dir)){
		if($file!="." && $file!=".." && is_file($folder."/".$file) && hs_eregi("\.inc\.php$",$file)){
			$options = array();
			include($folder."/".$file);
			reset($options);
			while(list($key,$val) = each($options)){
				$k = array_search($val,$options_old);
				if(!extract_null_value($k))
				$options[$key] = $options_new[$k];
			}//while
			write_options($folder."/".$file,$options,$options_name);
		}//if
	}//while
	closedir($dir);
	
}//save_theme_options

function write_options($file,$options,$options_name){
	
	$str = "<?php\n\n";
	$str.= "\$options_name = \"".hs_ereg_replace('"','\"',$options_name)."\";\n";
	$str.= go_through_array("\$options",$options);
	$str.= "\n?>";
	
	$file_handler = fopen($file,"w");
	fwrite($file_handler,$str);
	fclose($file_handler);
	
}//write_options

function save_theme_categories($theme,$categories_new){
	
	$categories_old = theme_categories($theme);
	
	$catfiles = array("clb_categories.inc.php","cls_categories.inc.php","evn_categories.inc.php","ecards_categories.inc.php");
	foreach($catfiles as $cfile){
		$categories = array();
		$subcategories = array();
		include(DOC_ROOT."/themes/".$theme."/system/".$cfile);
		reset($categories);
		while(list($key,$val) = each($categories)){
			$nkey = array_search($val,$categories_old);
			if(!extract_null_value($nkey))
				$categories[$key] = stripslashes(html_entity_decode($categories_new[$nkey]));				
			reset($subcategories[$key]);
			while(list($k,$v) = each($subcategories[$key])){
				$nkey = array_search($v,$categories_old);
				if(!extract_null_value($nkey))
					$subcategories[$key][$k] = stripslashes(html_entity_decode($categories_new[$nkey]));
			}//while
			reset($subcategories[$key]);
		}//while
		reset($categories);
		write_categories(DOC_ROOT."/themes/".$theme."/system/".$cfile,$categories,$subcategories);
	}//foreach
	
}//save_theme_categories

function write_categories($cfile,$categories,$subcategories){
	
	$str = "<?php\n\n";
	while(list($key,$val) = each($categories)){
		$str.= "\$categories[".$key."] = \"".hs_eregi_replace('"','\"',$val)."\";\n";
		while(list($k,$v) = each($subcategories[$key])){			
			$str.= "\$subcategories[".$key."][".$k."] = \"".hs_eregi_replace('"','\"',$v)."\";\n";
		}//while
	}//while
	$str.= "\n?>";
	
	$file_handler = fopen($cfile,"w");
	fwrite($file_handler,$str);
	fclose($file_handler);
	
}//write_categories

function wording(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	
	$data["themes"] = admin_get_themes();
	
	include(DOC_ROOT."/themes/".$theme."/language.inc.php");	
	$data["language"] = $language;
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_wording";
	
	admin_output($layout,$data);
	
}//wording

function save_wording(){
	
	admin_validate();	
	
	$language = $GLOBALS["Get"]->val("language");
	$theme = $GLOBALS["Get"]->val("theme");
	
	$write_str = "<?php\n\n";
	while(list($key,$val) = each($language)){
		$key = stripslashes(html_entity_decode($key));
		$key = hs_ereg_replace('"','\"',$key);
		$val = stripslashes(html_entity_decode($val));
		$val = hs_ereg_replace('"','\"',$val);
		$write_str.= "\$language[\"".$key."\"] = \"".$val."\";\n";
	}//while
	$write_str.= "\n?>";
	
	$file = DOC_ROOT."/themes/".$theme."/language.inc.php";
	$file_handler = fopen($file,"w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	unset($language);
	include(DOC_ROOT."/themes/".$theme."/language.inc.php");
	$lang = array();
	
	while(list($key,$val) = each($language)){
		$key = hs_strtolower($key);
		$key = hs_ereg_replace("[^A-Za-z]","_",$key);
		$key = hs_ereg_replace("[_]+","_",$key);
		$key = hs_ereg_replace("^_","",$key);
		$key = hs_ereg_replace("_$","",$key);
		$lang[$key] = $val;
	}//while
	
	$wri = go_through_array("\$language",$lang);
	$f = fopen(DOC_ROOT."/themes/".$theme."/language_cached.inc.php","w");
	fwrite($f,"<?php\n\n".$wri."\n?>");
	fclose($f);
	
	load_page("index.php?section=translate&action=translate_done&theme=".$theme);
	
}//save_wording

function translate_done(){
	
	admin_validate();
	
	$data["section"] = "customize";
	$data["subsection"] = 12;
	$data["title_id"] = "51";	$data["action"] = "translate";
	
	$theme = $GLOBALS["Get"]->val("theme");
	$data["theme"] = $theme;
	$data["themes"] = admin_get_themes();
	
	$layout[0] = "translate_nav";
	$layout[1] = "translate_done";
	
	admin_output($layout,$data);
	
}//translate_done
						
?>
