<?php

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

						///////////////////////////////////////
							
						admin_validate_section("design",3);
						$action = $GLOBALS["Get"]->val("action");
								
							switch($action){
										
								case '':
									manage_templates();
									break;
									
								case 'edit':
									edit_template();
									break;
								
								case 'save':
									save_template();
									break;
									
								case 'delete':
									delete_template();
									break;
									
							}//switch
							
						///////////////////////////////////////
						
function manage_templates(){
	
	admin_validate();
	
	$data["section"] = "design";
	$data["subsection"] = 3;
	$data["title_id"] = "48";	
	$data["profiles"] = templates_list("profiles");
	$data["blogs"] = templates_list("blogs");
	$data["classifieds"] = templates_list("classifieds");
	$data["events"] = templates_list("events");
	$data["clubs"] = templates_list("clubs");
	$data["ecards"] = templates_list("ecards");
	
	$layout[0] = "templates_list";
	
	admin_output($layout,$data);
	
}//manage_templates

function templates_list($type){
	
	$templates = array();
	
	$folder = DOC_ROOT."/templates/".$type;
	
	$dir = opendir($folder);
	while($subfolder = readdir($dir)){
		if($subfolder!="." && $subfolder!=".." && file_exists($folder."/".$subfolder."/settings.xml")){
			$template_data = extract_template_data($folder."/".$subfolder."/settings.xml");
			$template["name"]   = $template_data["name"];
			$template["edit"]   = "index.php?section=templates&action=edit&type=".$type."&template=".$template_data["path"];
			if($template_data["path"] == "default")
				$template["delete"] = "";
			else
				$template["delete"] = "index.php?section=templates&action=delete&type=".$type."&template=".$template_data["path"];			
			$templates[] = $template;
		}//if
	}//while
	closedir($dir);
	
	return $templates;
	
}//templates_list

function edit_template(){
	
	admin_validate();
	
	$type = $GLOBALS["Get"]->val("type");
	$template = $GLOBALS["Get"]->val("template");
	
	$data = extract_template_data(DOC_ROOT."/templates/".$type."/".$template."/settings.xml");
	
	$data["type"] = $type;
	$data["template"] = $template;
	$data["section"] = "design";
	$data["subsection"] = 3;
	$data["title"] = "Handshakes::Admin Console - Public Templates";	
	$data["link"] = "index.php?section=templates";
	
	$layout[0] = "edit_template";
	
	admin_output($layout,$data);
	
}//edit_template

function save_template(){
	
	admin_validate();
	
	$type = $GLOBALS["Get"]->val("type");
	$template = $GLOBALS["Get"]->val("template");
	$name = $GLOBALS["Get"]->val("name");
	
	$settings_file = DOC_ROOT."/templates/".$type."/".$template."/settings.xml";
	
	$data = extract_template_data($settings_file);
	$data["name"] = $name;
	
	$colors = extract_template_colors($settings_file);
	
	load_template_colors($settings_file,$data,$colors);
	
	load_page("index.php?section=templates&action=edit&type=".$type."&template=".$template);
	
}//save_template

function delete_template(){
	
	admin_validate();
	
	$type = $GLOBALS["Get"]->val("type");
	$template = $GLOBALS["Get"]->val("template");	
	
	handle_folder_clean_total(DOC_ROOT."/templates/".$type."/".$template);
	
	load_page("index.php?section=templates");
	
}//delete_template
						
?>