<?php

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

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

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

							switch($action){

								case '':
									composer_console();
									break;
									
								case 'page':
									composer_page();
									break;
									
								case 'structure':
									composer_structure();
									break;

								case 'edit_template':
									composer_edit_template();
									break;
									
								case 'save_template':
									composer_save_template();
									break;
								
								case 'newpage':
									composer_new_page();
									break;
									
								case 'do_newpage':
									composer_create_new_page();
									break;

							}//switch

						///////////////////////////////////////
						
function composer_new_page(){
	
	admin_validate();
	
	$data["title_id"] = "5";	
	$data["themes"] = admin_get_themes();
		
	while(list($key,$val) = each($data["themes"])){
		$jscode.= "HS_Pages[\"".$key."\"] = new Array;\n";
		$jscode.= "HS_Pages[\"".$key."\"][\"names\"] = new Array;\n";
		$jscode.= "HS_Pages[\"".$key."\"][\"keys\"] = new Array;\n";
		$pages[$key] = admin_get_pages($key);		
		$c = 0;
		while(list($k,$v) = each($pages[$key])){
			if(!eregi("^profile_",$k) && 
				$k!="blogs_view" && 
				$k!="classifieds_view" && 
				$k!="events_view" && 
				$k!="clubs_main" && 
				$k!="ecards_view")
			$jscode.= "HS_Pages[\"".$key."\"][\"names\"][".$c."] = \"".ereg_replace('"','\"',$v)."\";\n";
			$jscode.= "HS_Pages[\"".$key."\"][\"keys\"][".$c."] = \"".$k."\";\n";
			$c++;
		}//while
	}//while
	reset($data["themes"]);
	
	$data["javascript"] = '
<script language="JavaScript">
<!--
	var HS_Pages = new Array;
	function HS_InitPages(){
		'.$jscode.'
	}//HS_InitPages
	function HS_PopulatePages(TrackField,DistField){
		var SelTheme = TrackField.options[TrackField.selectedIndex].value;
		for(var i=DistField.options.length-1;i>=0;i--){
			DistField.options[i] = null;
		}//for
		k=0;
		for(var Item in HS_Pages[SelTheme]["names"]){
			DistField.options[k] = new Option(HS_Pages[SelTheme]["names"][Item],HS_Pages[SelTheme]["keys"][Item]);
			k++;
		}//for
	}//HS_PopulatePages
	function HS_SelectPage(PageName){
		var FieldHandler = document.composer_console.page;
		for(k=0;k<FieldHandler.options.length;k++){
			if(FieldHandler.options[k].value == PageName){
				FieldHandler.selectedIndex = k;
				break;
			}//if
		}//for
	}//HS_SelectPage
	function HS_ResizeFrame(FrameHeight,FrameID){
		var FrameHandler = document.getElementById(FrameID);
		if(FrameID == "composer_preview")
			FrameHeight+= 100;
		FrameHandler.style.height = FrameHeight;
	}//HS_ResizeFrame
//-->
</script>
';
	
	$theme = $GLOBALS["Get"]->val("theme");
	$page  = $GLOBALS["Get"]->val("page");
	$name  = $GLOBALS["Get"]->val("name");
	
	$data["onload"] = "HS_InitPages();HS_PopulatePages(document.composer_console.theme,document.composer_console.page);HS_SelectPage('".$page."')";	
	
	$data["theme"] = $theme;
	$data["page"]  = $page;
	$data["theme_name"] = $data["themes"][$theme];
	$data["page_name"]  = $pages[$theme][$page];
	$data["name"] = $name;
	
	$title = admin_title($title_id);
	
	if($GLOBALS["moderator"]){
		$logo = "moderator_console_small.gif";
		$path = "../administrator/";
	}//if
	else{
		$logo = "admin_console_small.gif";
		$path = "./";
	}//else
	
	$encoding = extract_encoding("html",$theme);
	
	?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $encoding; ?>">
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $path; ?>gfx/style.css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<?php echo $data["javascript"]; ?>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" onLoad="<?php echo $data["onload"]; ?>">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr><td class="composer_header"><table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr><td><?php
		admin_output_image($logo);
		?></td>
		<td align="right"><?php
		admin_output_image("page_composer.gif");
		?></td></tr>
	</table></td></tr>
	<tr><td class="composer_subheader"><table cellpadding="2" cellspacing="0" border="0" width="100%">
		<form action='index.php' method='post' name='composer_console'>
		<input type='hidden' name='section' value='composer'>
		<tr><td><table cellpadding="0" cellspacing="2" border="0">
			<tr>				
				<td><?php
				$options = $data["themes"];
				admin_form_element( array ("type" => "select", "name" => "theme", "options" => $options, "value" => $data["theme"], "javascript" => "onChange='HS_PopulatePages(document.composer_console.theme,document.composer_console.page)'") );
				?></td>
				<td><?php				
				admin_form_element( array ("type" => "select", "name" => "page", "options" => array (), "value" => $data["page"]) );
				?></td>
				<td><?php
				admin_form_element( array ("type" => "button", "value" => "Load Page") );
				?></td>
			</tr>
		</form>
		</table></td>
		<td align="right"><table cellpadding="0" cellspacing="2" border="0">
		<form action='index.php' method='post'>
		<input type='hidden' name='section' value='composer'>
		<input type='hidden' name='action' value='newpage'>
			<tr><td class="white_body">Page Name:</td><td><?php
			admin_form_element( array ("type" => "input", "size" => 30, "name" => "name") );
			?></td>
			<td align="center"><?php
			admin_form_element( array ("type" => "button", "value" => "Create New Page") );
			?></td></tr>
		</form>
		</table></td></tr>
	</table></td></tr> 
</table>
<table cellpadding="5" cellspacing="10" border="0" align="center" width="400">
	<form action="index.php" method="post">
	<input type="hidden" name="section" value="composer">
	<input type="hidden" name="action" value="do_newpage">
	<tr><td class="form_cell"><table cellpadding="0" cellspacing="3" border="0">
		<tr><td class="body" align="right" width="200">Theme:</td><td><?php
			$options = $data["themes"];
				admin_form_element( array ("type" => "select", "name" => "theme", "options" => $options, "value" => $data["theme"]) );
		?></td></tr>
		<tr><td class="body" align="right">Page Name:</td><td><?php
		admin_form_element( array ("type" => "input", "name" => "name", "value" => $data["name"], "size" => 30) );
		?></td></tr>
		<tr><td class="body" colspan="2" align="center">Page URL:</td></tr>
		<tr><td colspan="2"><table cellpadding="0" cellspacing="2" border="0" align="center">
		<tr><td class="highlight" align="right"><?php echo URL."/index.php?page="; ?></td><td><?php
		admin_form_element( array ("type" => "input", "name" => "page", "value" => $data["page"], "size" => 10) );
		?></td></tr></table></td></tr>
		<tr><td colspan="2" align="center"><?php
		admin_form_element( array ("type" => "button","value" => "Create New Page") );
		?></td></tr>	
	</table></td></tr>
	</form>
</table>
</body></html><?php
	
}//compsoer_new_page

function composer_create_new_page(){
	
	admin_validate();
	
	$vals = array("theme","page","name");
	
	$values = $GLOBALS["Get"]->arr($vals,1);
	
	$values["page"] = ereg_replace("[^A-Za-z|0-9|_]","_",strtolower($values["page"]));
	$values["page"] = ereg_replace("[_]+","_",$values["page"]);
	
	if(!eregi("^[a-z]",$values["page"])){
		$GLOBALS["aerr_id"] = 32;
		composer_new_page();
	}//if
	if(empty($values["theme"]) || empty($values["page"]) || empty($values["name"])){
		$GLOBALS["aerr_id"] = 10;
		composer_new_page();
	}//if
	
	if(file_exists(DOC_ROOT."/themes/".$values["theme"]."/layout/".$values["page"].".inc.php")){
		$GLOBALS["aerr_id"] = 31;
		composer_new_page();
	}//if
	
	$page["title"] = $values["name"];
	$page["items_file"] = $values["page"];
	
	add_new_page($values["theme"],$page);

	load_page("index.php?section=composer&theme=".$values["theme"]."&page=".$values["page"]);
	
}//composer_create_new_page
						
function composer_console(){
	
	admin_validate();
	
	$data["title_id"] = "5";
	$data["themes"] = admin_get_themes();
		
	while(list($key,$val) = each($data["themes"])){
		$jscode.= "HS_Pages[\"".$key."\"] = new Array;\n";
		$jscode.= "HS_Pages[\"".$key."\"][\"names\"] = new Array;\n";
		$jscode.= "HS_Pages[\"".$key."\"][\"keys\"] = new Array;\n";
		$pages[$key] = admin_get_pages($key);		
		$c = 0;
		while(list($k,$v) = each($pages[$key])){
			if(!eregi("^profile_",$k) && 
				$k!="blogs_view" && 
				$k!="classifieds_view" && 
				$k!="events_view" && 
				$k!="clubs_main" && 
				$k!="ecards_view")
			$jscode.= "HS_Pages[\"".$key."\"][\"names\"][".$c."] = \"".ereg_replace('"','\"',$v)."\";\n";
			$jscode.= "HS_Pages[\"".$key."\"][\"keys\"][".$c."] = \"".$k."\";\n";
			$c++;
		}//while
	}//while
	reset($data["themes"]);
	
	$data["javascript"] = '
<script language="JavaScript">
<!--
	var HS_Pages = new Array;
	function HS_InitPages(){
		'.$jscode.'
	}//HS_InitPages
	function HS_PopulatePages(TrackField,DistField){
		var SelTheme = TrackField.options[TrackField.selectedIndex].value;
		for(var i=DistField.options.length-1;i>=0;i--){
			DistField.options[i] = null;
		}//for
		k=0;
		for(var Item in HS_Pages[SelTheme]["names"]){
			DistField.options[k] = new Option(HS_Pages[SelTheme]["names"][Item],HS_Pages[SelTheme]["keys"][Item]);
			k++;
		}//for
	}//HS_PopulatePages
	function HS_SelectPage(PageName){
		var FieldHandler = document.composer_console.page;
		for(k=0;k<FieldHandler.options.length;k++){
			if(FieldHandler.options[k].value == PageName){
				FieldHandler.selectedIndex = k;
				break;
			}//if
		}//for
	}//HS_SelectPage
	function HS_ResizeFrame(FrameHeight,FrameID){
		var FrameHandler = document.getElementById(FrameID);
		if(FrameID == "composer_preview")
			FrameHeight+= 100;
		FrameHandler.style.height = FrameHeight;
	}//HS_ResizeFrame
//-->
</script>
';
	
	$theme = $GLOBALS["Get"]->val("theme");
	$page  = $GLOBALS["Get"]->val("page");
	
	$data["onload"] = "HS_InitPages();HS_PopulatePages(document.composer_console.theme,document.composer_console.page);HS_SelectPage('".$page."')";	
	
	$data["theme"] = $theme;
	$data["page"]  = $page;
	$data["theme_name"] = $data["themes"][$theme];
	$data["page_name"]  = $pages[$theme][$page];
	
	$encoding = extract_encoding("html",$theme);
	
	$title = admin_title($title_id);
	
	if($GLOBALS["moderator"]){
		$logo = "moderator_console_small.gif";
		$path = "../administrator/";
	}//if
	else{
		$logo = "admin_console_small.gif";
		$path = "./";
	}//else
	
	?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $encoding; ?>">
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $path; ?>gfx/style.css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<?php echo $data["javascript"]; ?>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" onLoad="<?php echo $data["onload"]; ?>">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr><td class="composer_header"><table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr><td><?php
		admin_output_image($logo);
		?></td>
		<td align="right"><?php
		admin_output_image("page_composer.gif");
		?></td></tr>
	</table></td></tr>
	<tr><td class="composer_subheader"><table cellpadding="2" cellspacing="0" border="0" width="100%">
		<form action='index.php' method='post' name='composer_console'>
		<input type='hidden' name='section' value='composer'>
		<tr><td><table cellpadding="0" cellspacing="2" border="0">
			<tr>				
				<td><?php
				$options = $data["themes"];
				admin_form_element( array ("type" => "select", "name" => "theme", "options" => $options, "value" => $data["theme"], "javascript" => "onChange='HS_PopulatePages(document.composer_console.theme,document.composer_console.page)'") );
				?></td>
				<td><?php				
				admin_form_element( array ("type" => "select", "name" => "page", "options" => array (), "value" => $data["page"]) );
				?></td>
				<td><?php
				admin_form_element( array ("type" => "button", "value" => "Load Page") );
				?></td>
			</tr>
		</form>
		</table></td>
		<td align="right"><table cellpadding="0" cellspacing="2" border="0">
		<form action='index.php' method='post'>
		<input type='hidden' name='section' value='composer'>
		<input type='hidden' name='action' value='newpage'>
			<tr><td class="white_body">Page Name:</td><td><?php
			admin_form_element( array ("type" => "input", "size" => 30, "name" => "name") );
			?></td>
			<td align="center"><?php
			admin_form_element( array ("type" => "button", "value" => "Create New Page") );
			?></td></tr>
		</form>
		</table></td></tr>
	</table></td></tr> 
</table>
<?php

	if($data["theme"] && $data["page"]){
		
		?><table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr><td class="lined blue_bcg white_body padded" align="center">Structure</td></tr>
		<tr><td class="black-lined"><iframe scrolling="no" name="composer_editor" border="0" frameborder="0" style="border:0" width="100%" height="500" src="index.php?section=composer&action=structure&theme=<?php echo $data["theme"] ?>&page=<?php echo $data["page"]; ?>"></iframe></td></tr>
		<tr><td class="lined blue_bcg white_body padded" align="center">Preview</td></tr>
		<tr><td class="black-lined"><iframe scrolling="no" name="composer_preview" border="0" frameborder="0" style="border:0" width="100%" height="500" src="index.php?section=composer&action=page"></iframe></td></tr>
		<?php

	}//if

?>
</body></html><?php
	
}//composer_console

function composer_structure(){
	
	admin_validate();

	$theme = $GLOBALS["Get"]->val("theme");
	$page  = $GLOBALS["Get"]->val("page");
	
	$xml = implode("",file(DOC_ROOT."/themes/".$theme."/layout/".$page.".inc.php"));
	$data["javascript"] = "<script language='JavaScript'><!--\nvar Theme=\"".$theme."\";\n//--></script>\n";
	$data["javascript"].= xml2js($xml);
	$data["onload"].= "HS_CurrentStructure();
	HS_BuildPage();
	HS_PullOutput();HS_CheckSize();HS_PreviewPage();";
	$page_values = array (
		"per_id" => 100000,
		"recipient" => 100000,
		"pho_id" => 100000,
		"mes_id" => 100000,
		"blg_id" => 100000,
		"cls_id" => 100000,
		"clb_id" => 100000,
		"evn_id" => 100000,
		"pst_id" => 100000,
		"cmp_id" => 12,
		"crd_id" => 100000,
		"vid_id" => 100000,
		"mus_id" => 100000,
		"frm_id" => 100000,
		"top_id" => 100000,
		"pst_id" => 100000,
		"template" => "default",
		"composer" => 1
	);
	$data["page_values"] = "";
	while(list($key,$val) = each($page_values)){
		$data["page_values"].= "<input type='hidden' name='".$key."' value='".$val."'>";
	}//while
	$data["theme"] = $theme;
	$data["page"]  = $page;
	
	$encoding = extract_encoding("html",$theme);
	
	if($GLOBALS["moderator"]){
		$path = "../administrator/";
	}//if
	else{
		$path = "./";
	}//else
	
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $encoding; ?>">
<link rel="stylesheet" type="text/css" href="<?php echo $path; ?>gfx/style.css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
var HS_Path = "<?php echo $path; ?>";
//-->
</script>
<?php echo $data["javascript"]; ?>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" onLoad="<?php echo $data["onload"]; ?>"><?php
	
	include(DOC_ROOT."/administrator/templates/composer_structure.inc.php");
	
?></body></html><?php
	
}//composer_strusture

function composer_page(){

	admin_validate();

	$theme = $GLOBALS["Get"]->val("theme");
	$page  = $GLOBALS["Get"]->val("page");
	$pro   = $GLOBALS["Get"]->val("pro");
	$structure = stripslashes(html_entity_decode($GLOBALS["Get"]->val("structure")));
	
	if(!$structure)
		$structure = 0;

	if($theme && $page){
		if($pro == "save"){
			$layout_file = DOC_ROOT."/themes/".$theme."/layout/".$page.".inc.php";
			$file_handler = fopen($layout_file,"w");
			fwrite($file_handler,$structure);
			fclose($file_handler);
		}//if
		
		$data["theme"] = $theme;
		$data["page"]  = $page;
		$data["structure"] = $structure;		
		composer_output($data);
	}//if
	else{
		include(DOC_ROOT."/administrator/templates/blank.inc.php");
		exit;
	}//else

}//composer_page

function composer_output($data){

	if($data["theme"] && $data["page"]){
		
		$GLOBALS["smarty"]->compile_dir  = DOC_ROOT."/themes/".$data["theme"]."/templates/templates_c";
        $GLOBALS["smarty"]->template_dir = DOC_ROOT."/themes/".$data["theme"]."/templates/source";
        $GLOBALS["smarty"]->config_dir   = DOC_ROOT."/themes/".$data["theme"]."/templates/configs";
        $GLOBALS["smarty"]->cache_dir    = DOC_ROOT."/themes/".$data["theme"]."/templates/cache";
		$GLOBALS["smarty"]->assign("root","../themes/".$data["theme"]."/gfx");
		$GLOBALS["smarty"]->assign("url","..");
		$GLOBALS["smarty"]->force_compile = 1;
		
		include (DOC_ROOT."/themes/".$data["theme"]."/config/settings.inc.php");
		$GLOBALS["smarty"]->assign("settings",$settings);
		
		$GLOBALS["THEME"] = $data["theme"];
	
		$pdetails = explode("_",$data["page"]);
		$p_details["page"] = array_shift($pdetails);
		$p_details["section"] = implode("_",$pdetails);
		$p_details["items_file"] = $data["page"];
		$GLOBALS["page_details"][code] = "<script language=\"JavaScript\">
<!--
document.onclick = HS_DisableClicks;
function HS_DisableClicks(){
	return false;
}//HS_DisableClicks
function HS_ShowContent(){
	var FrameHeight = document.body.scrollHeight;
	parent.HS_ResizeFrame(FrameHeight,'composer_preview');
}//HS_ShowContent
//-->
</script>";
		$GLOBALS["page_details"]["onload"] = "HS_ShowContent();";
	
		build_page($p_details,0,$data["structure"]);

	}//if
	
}//composer_output

function composer_edit_template(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$file  = stripslashes(html_entity_decode(hs_ereg_replace("&#124;","|",$GLOBALS["Get"]->val("file"))));
	
	$files = handle_empties(explode("|",$file));
	$content = "";
	
	foreach($files as $file){
		
		if(!eregi("\./|\.\./",$file)){
	
			if(file_exists(DOC_ROOT."/themes/".$theme."/templates/source/".$file) && is_file(DOC_ROOT."/themes/".$theme."/templates/source/".$file)){
				$f = fopen(DOC_ROOT."/themes/".$theme."/templates/source/".$file,"r");
				$content.= fread($f,filesize(DOC_ROOT."/themes/".$theme."/templates/source/".$file))."|||--|||";
				fclose($f);
			}//if
			
		}//if
		
	}//foreach
	
	print($content);
	
}//compsoer_edit_template

function composer_save_template(){
	
	admin_validate();
	
	$theme = $GLOBALS["Get"]->val("theme");
	$file  = stripslashes(html_entity_decode(hs_ereg_replace("&#124;","|",$GLOBALS["Get"]->val("file"))));
	$content  = stripslashes(html_entity_decode(hs_ereg_replace("&#124;","|",$GLOBALS["Get"]->val("content"))));
	
	$files = handle_empties(explode("|",$file));
	$contents = handle_empties(explode("|||--|||",$content));
		
	for($i=0;$i<count($files);$i++){
		
		if(!eregi("\./|\.\./",$file)){
	
			if(file_exists(DOC_ROOT."/themes/".$theme."/templates/source/".$files[$i]) && is_file(DOC_ROOT."/themes/".$theme."/templates/source/".$files[$i])){
				$f = fopen(DOC_ROOT."/themes/".$theme."/templates/source/".$files[$i],"w");
				fwrite($f,$contents[$i]);
				fclose($f);
			}//if
			
		}//if
		
	}//for
	
}//compsoer_save_template

function xml2js($xml){

	$parser = xml_parser_create();
	xml_parse_into_struct($parser,$xml,$xml_elements,$xml_index);

	$jsarray = "";
	foreach($xml_elements as $element){

		$tag        = hs_strtolower($element["tag"]);
		$type       = $element["type"];
		$value      = $element["value"];
		$level      = $element["level"];
		$attributes = $element["attributes"];

		if($tag == 'header' && $type == 'complete'){
			$jsarray.= "HS_Structure['header'] = new Array();";
			$jsarray.= "HS_Structure['header']['type'] = \"header\";";
			$jsarray.= "HS_Structure['header']['file'] = \"".$value."\";";
			$jsarray.= "HS_Structure['header']['parent'] = \"\";";
		}//if
		elseif($tag == 'footer' && $type == 'complete'){
			$jsarray.= "HS_Structure['footer'] = new Array();";
			$jsarray.= "HS_Structure['footer']['type'] = \"footer\";";
			$jsarray.= "HS_Structure['footer']['file'] = \"".$value."\";";
			$jsarray.= "HS_Structure['footer']['parent'] = \"\";";
		}//elseif
		elseif($tag == 'column' && $type == 'open'){
			$column = $attributes["ID"];
			$jsarray.= "HS_Structure[".$column."] = new Array();";
			$jsarray.= "HS_Structure[".$column."]['width']  = \"".$attributes["WIDTH"]."\";";
			$jsarray.= "HS_Structure[".$column."]['type']   = \"column\";";
			$jsarray.= "HS_Structure[".$column."]['id']     = \"".$column."\";";
			$jsarray.= "HS_Structure[".$column."]['parent'] = \"\";";
		}//elseif
		elseif($tag == 'cell' && $type == 'open'){
			$cell = $attributes["ID"];
			$cell_id = 0;
			$jsarray.= "HS_Structure[".$column."][".$cell."] = new Array();";
			$jsarray.= "HS_Structure[".$column."][".$cell."]['parent'] = \"[".$column."]\";";
			$jsarray.= "HS_Structure[".$column."][".$cell."]['type']  = \"cell\";";
			$jsarray.= "HS_Structure[".$column."][".$cell."]['id']    = \"".$cell."\";";
		}//elseif
		elseif($tag == 'container' && $type == 'open'){
			$container[$level] = "[".$column."][".$cell."][".$cell_id."]";
			$container_id = 0;
			$jsarray.= "HS_Structure[".$column."][".$cell."][".$cell_id."] = new Array();";
			$jsarray.= "HS_Structure[".$column."][".$cell."][".$cell_id."]['id']    = \"".$attributes["ID"]."\";";
			$jsarray.= "HS_Structure[".$column."][".$cell."][".$cell_id."]['type']  = \"container\";";
			$jsarray.= "HS_Structure[".$column."][".$cell."][".$cell_id."]['open']  = \"".$attributes["OPEN"]."\";";
			$jsarray.= "HS_Structure[".$column."][".$cell."][".$cell_id."]['close'] = \"".$attributes["CLOSE"]."\";";
			$jsarray.= "HS_Structure[".$column."][".$cell."][".$cell_id."]['parent'] = \"[".$column."][".$cell."]\";";
			$cell_id++;
		}//elseif
		elseif($tag == 'container' && $type == 'close'){
			$container[$level] = "";
		}//elseif
		elseif($tag == 'block' && $type == 'open'){
			if($container[$level-1]!=''){
				$block_path = $container[$level-1]."[".$container_id."]";
				$parent = $container[$level-1];
			}
			else{
				$block_path = "[".$column."][".$cell."][".$cell_id."]";
				$parent = "[".$column."][".$cell."]";
			}

			$block[$level] = $block_path;
			$block_path = "HS_Structure".$block_path;
			$template_id = 0;
			$jsarray.= $block_path." = new Array();";
			$jsarray.= $block_path."['id']        = \"".$attributes["ID"]."\";";
			$jsarray.= $block_path."['type']      = \"block\";";
			$jsarray.= $block_path."['open']      = \"".$attributes["OPEN"]."\";";
			$jsarray.= $block_path."['close']     = \"".$attributes["CLOSE"]."\";";
			$jsarray.= $block_path."['assign']    = \"".$attributes["ASSIGN"]."\";";
			$jsarray.= $block_path."['btype']     = \"".$attributes["BTYPE"]."\";";
			$jsarray.= $block_path."['parent']    = \"".$parent."\";";
			if($container[$level-1]!='')
				$container_id++;
			else
				$cell_id++;

		}//elseif
		elseif($tag == 'template' && $type == 'complete'){
			$jsarray.= "HS_Structure".$block[$level-1]."[".$template_id."] = new Array();";
			$jsarray.= "HS_Structure".$block[$level-1]."[".$template_id."]['file']   = \"".$value."\";";
			$jsarray.= "HS_Structure".$block[$level-1]."[".$template_id."]['parent'] = \"".$block[$level-1]."\";";
			$jsarray.= "HS_Structure".$block[$level-1]."[".$template_id."]['type']   = \"template\";";
			$jsarray.= "HS_Structure".$block[$level-1]."[".$template_id."]['id']     = \"".$template_id."\";";
			$template_id++;
		}//elseif

	}//foreach

$javascript = <<<JSCODE
<script language="JavaScript" src="../jscript/composer.js"></script>
<script language="JavaScript">
function HS_CurrentStructure(){
HS_Structure = new Array;
JSCODE;
$javascript.= hs_ereg_replace(";",";\n",$jsarray);
$javascript.= <<<JSCODE
}//HS_CurrentStructure
</script>
JSCODE;

	return $javascript;

}//xml2js

?>