<?

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

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=module.php>";
	$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/change_pwd.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("您的【密碼】欄沒有輸入唷!");	
	if(!$temp_array[3]) error_message("您的【新密碼】欄沒有輸入唷!");	
	if(!$temp_array[4]) 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/change_pwd2.htm');	
	
	/*查詢資料*/		
	
	$temp_array[0] = $temp_array[0] - 930000;
	$temp_array[1] = MD5($temp_array[1]);
	
	$info = sql_b("SELECT id FROM member WHERE id = '$temp_array[0]' AND password = '$temp_array[1]'");
	
	if(!sizeof($info)) error_message("查無您的報名資料，請再重新嘗試一次，看是否輸入錯誤!");
	
	/*設定新密碼*/	
	
	$temp_array[3]!=$temp_array[4] ? error_message("兩次密碼輸入的不一致，再檢查一下吧^^") : $temp_array[3] = MD5($temp_array[3]);
	
	sql_a("UPDATE member SET password = '$temp_array[3]' WHERE id = '$temp_array[0]'");
	
	/*執行替換*/	
	
	$temp_a = $array['{MIDDLE_PANEL_CONTENT}'];
	$temp_a = str_replace('{S_PWD}',$temp_array[4],$temp_a);
	$array['{MIDDLE_PANEL_CONTENT}']= $temp_a;
		
	/*套 Template*/			
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);	
	
	return $buffer;
}
?>