<?php

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

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

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

							switch($action){

								case '':
									holidays();
									break;
									
								case 'edit':
									edit_holiday();
									break;
									
								case 'save':
									save_holiday();
									break;
									
								case 'delete':
									delete_holiday();
									break;

							}//switch

						///////////////////////////////////////
						
function holidays(){
	
	admin_validate();
	
	$data["themes"] = array ();
	$data["themes"] = admin_get_themes();
	$data["holidays"] = array();
	
	$theme = $GLOBALS["Get"]->val("theme");
	
	if(empty($theme))
		$theme = $GLOBALS["THEME"];
	
	if($theme){
	$data["theme"] = $theme;
	include(DOC_ROOT."/themes/".$theme."/holidays.inc.php");
	while(list($key,$val) = each($holidays)){
		$holiday = array();
		$holiday["hld_id"] = $key;
		$holiday["name"] = $val["name"];
		$dets = explode("/",$val["date"]);
		$date = mktime(0,0,1,$dets[1],1,date("Y"));
		$month = date("F",$date);
		$holiday["date"] = $month.": ".$dets[0];			
		$holiday["type"] = ($val["type"] == "h") ? "Official Holiday" : "Non-official Holiday";
		$holiday["edit"] = "index.php?section=holidays&action=edit&theme=".$theme."&hld_id=".$key;
		$holiday["delete"] = "index.php?section=holidays&action=delete&theme=".$theme."&hld_id=".$key;
		$data["holidays"][] = $holiday;
	}//while
	$layout[0] = "holidays";
	}//if
	
	$data["section"] = "customize";
	$data["subsection"] = 11;
	$data["title_id"] = "17";	
	admin_output($layout,$data);
	
}//holidays

function edit_holiday(){
	
	$theme  = $GLOBALS["Get"]->val("theme");
	$hld_id = $GLOBALS["Get"]->type_val("hld_id","integer");
	
	include(DOC_ROOT."/themes/".$theme."/holidays.inc.php");
	
	if($hld_id){
	
		$data["name"]   = $holidays[$hld_id]["name"];	
		$dets = explode("/",$holidays[$hld_id]["date"]);		
		$data["month"] = $dets[1];	
		if(is_numeric($dets[0]))
			$data["day"] = $dets[0];
		else
			$data["descr"] = $dets[0];
					
		$data["type"] = $holidays[$hld_id]["type"];
		
	}//if
	else{
		
		$vals = array("name","month","day","descr","type");
		$data = $GLOBALS["Get"]->arr($vals,1);
		
	}//else
	
	$data["link"] = "index.php?section=holidays&theme=".$theme;
	$data["section"] = "customize";
	$data["subsection"] = 11;
	$data["title_id"] = "17";	$data["theme"] = $theme;
	$data["hld_id"] = $hld_id;
	
	$layout[0] = "edit_holiday";
	
	admin_output($layout,$data);
	
}//edit_holiday

function save_holiday(){
	
	$theme  = $GLOBALS["Get"]->val("theme");
	$hld_id = $GLOBALS["Get"]->type_val("hld_id","integer");
	
	$vals = array("name","month","day","descr","type");
	$values = $GLOBALS["Get"]->arr($vals,1);
	
	if(empty($values["name"]) || empty($values["month"]) || (empty($values["day"]) && empty($values["descr"]))){
		$GLOBALS["aerr_id"] = 10;
		edit_holiday();
		exit;
	}//if
	
	include(DOC_ROOT."/themes/".$theme."/holidays.inc.php");
	
	if(!$hld_id)
		$hld_id = @max(array_keys($holidays))+1;
		
	$holiday["name"] = $values["name"];
	if($values["descr"])
		$holiday["date"] = $values["descr"]."/".$values["month"];
	else
		$holiday["date"] = $values["day"]."/".$values["month"];
		
	$holiday["type"] = $values["type"];
	
	$holidays[$hld_id] = $holiday;
	
	$write_str = "<?php\n\n";
	$write_str.= go_through_array("\$holidays",$holidays);
	$write_str.= "\n?>";
	
	$file_handler = fopen(DOC_ROOT."/themes/".$theme."/holidays.inc.php","w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	load_page("index.php?section=holidays&theme=".$theme);
	
}//save_holiday

function delete_holiday(){
	
	admin_validate();
	
	$theme  = $GLOBALS["Get"]->val("theme");
	$hld_id = $GLOBALS["Get"]->val("hld_id");
	
	include(DOC_ROOT."/themes/".$theme."/holidays.inc.php");
	
	if(is_array($hld_id)){
		foreach($hld_id as $id){
			unset($holidays[$id]);
		}//foreach
	}//if
	elseif($hld_id)
		unset($holidays[$hld_id]);
		
	$write_str = "<?php\n\n";
	$write_str.= go_through_array("\$holidays",$holidays);
	$write_str.= "\n?>";
	
	$file_handler = fopen(DOC_ROOT."/themes/".$theme."/holidays.inc.php","w");
	fwrite($file_handler,$write_str);
	fclose($file_handler);
	
	load_page("index.php?section=holidays&theme=".$theme);
	
}//delete_holiday
						
?>