<?

//將頁面處理值送回主模組	

function main_page()
{	
	global $action;
	
	//流程控制
	switch ($action)
	{   
      		
		//確認資料
   		case "step1":      	
      		$buffer = step1();      		
      		break;
        
	        //預設畫面(提示報名注意事項)
   		default:
      		$buffer = step0();      		
      		break;
	}	
	
	return $buffer;
}


//預設頁	
function step0()
{
	global $page;

	$buffer = "<br>";
	
	$array['{TOP1_A}'] = "熱　情";
	$array['{TOP1_B}'] = "智　慧";
	$array['{TOP1_C}'] = "科　技";
	
	$buffer .= read_and_parser("top1.php",$array);	
	unset($array);	
	
	$array['{MIDDLE_PANEL_TITLE}'] = '繳　費　管　理';
	$array['{MIDDLE_PANEL_CONTENT}'] = "<form method=POST action=administrator.php name=f>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= "<input type=hidden name=page value=$page>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= "<input type=hidden name=action value=step1>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= file_get_contents('require/pay01.htm');
	$array['{MIDDLE_PANEL_CONTENT}'] .= "</form>";
	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	return $buffer;
}

//處理登入
function step1()
{
	global $page,$temp_array;
	
	if(!$temp_array[0]) error_message("您的【報名序號】欄沒有輸入唷!");
	if(!$temp_array[1]) error_message("您的【入帳金額】欄沒有輸入唷!");
	
	
	$buffer = "<br>";
	
	$array['{TOP1_A}'] = "熱　情";
	$array['{TOP1_B}'] = "智　慧";
	$array['{TOP1_C}'] = "科　技";
	
	$buffer .= read_and_parser("top1.php",$array);
	unset($array);
	
	/*程式開始*/
	//----------------------------------------------------------------------	
	
	$array['{MIDDLE_PANEL_TITLE}'] = '繳　費　管　理';
	$array['{MIDDLE_PANEL_CONTENT}'] = file_get_contents('require/pay02.htm');	
	
	/*查詢資料*/		
	
	$temp_array[0] = $temp_array[0] - 930000;	
	$query = "SELECT amount,remind,pay_ok FROM member WHERE id = '$temp_array[0]'";
	$info = sql_b($query);
	
	//if(!sizeof($info)) error_message("無此資料!");
	
	/*交易處理*/
	
	$info[0][1] = $info[0][0] - $temp_array[1];
	if($info[0][1]<=0)
	{
		$info[0][2] = 1;
	}
	else
	{
		$info[0][2] = 0;
	}
	
	$a = $info[0][1];
	$b = $info[0][2];
	
	
	sql_a("UPDATE member SET remind = '$a', pay_ok = '$b', pay_time = NOW() WHERE id = '$temp_array[0]'");
					
	/*套 Template*/			
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);	
	
	return $buffer;
}
?>