<?

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

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


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

	$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=GET 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/login0.htm');
	$array['{MIDDLE_PANEL_CONTENT}'] .= "</form>";
	
	if($uid!='SATURN') $array['{MIDDLE_PANEL_CONTENT}'] = '您已經登入！如要重新登入，必須先 <a href="module.php?page=member_out">登出系統</a>，才能夠執行這個動作唷！';
	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	return $buffer;
}

//處理登入
function step1()
{
	global $page,$temp_array,$uid;	
	
	if(!$temp_array[0]) error_message("您的【報名編號】欄沒有輸入唷!");
	if(!$temp_array[1]) error_message("您的【密碼】欄沒有輸入唷!");
	
	$temp_array[0] = $temp_array[0] -930000;	
	
	$pas = sql_b("SELECT password FROM member WHERE id = '$temp_array[0]'");
	
	//echo $pas[0][0].'<br>'.$temp_array[1];
	
	if($pas[0][0]!=md5($temp_array[1]))
	{
		error_message("您的報名編號或是密碼不對，再檢查一下吧^^");
	}
	else
	{
		pass_message("恭喜您! 登入完成!");
		$uid = $temp_array[0] + 930000;
	}	
	
	$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/login1.htm');
	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);	
	
	return $buffer;
}
?>