<?

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

function main_page()
{	
	global $action;
	
	//流程控制
	switch ($action)
	{   

		//寫入資料庫
   		case "step3":      	
      		$buffer = step3();      		
      		break;
      		
      		
		//確認資料
   		case "step2":      	
      		$buffer = step2();      		
      		break;
		
		//提供表單
   		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=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/reg0.htm');
	$array['{MIDDLE_PANEL_CONTENT}'] .= "</form>";
	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	return $buffer;
}

//第一步，表單提供
function step1()
{
	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?page=$page>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= "<input type=hidden name=action value=step2>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= file_get_contents('require/reg1.htm');
	$array['{MIDDLE_PANEL_CONTENT}'] .= "</form>";

	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	return $buffer;
}

//第二步，確認資料
function step2()
{
	global $page,$temp_array;
	
	if(!$temp_array[0]) error_message("您的【密碼】欄沒有輸入唷!");
	if(!$temp_array[1]) error_message("您的【密碼確認】欄沒有輸入唷!");
	$temp_array[0]!=$temp_array[1] ? error_message("兩次密碼輸入的不一致，再檢查一下吧^^") : $temp_array[0] = MD5($temp_array[0]); $temp_array[1] = '';
	if(!$temp_array[2]) error_message("您的【電子郵件】欄沒有輸入唷!");
	if(!$temp_array[3]) error_message("您的【姓名】欄沒有輸入唷!");
	if(!$temp_array[7]) error_message("您的【服務單位】欄沒有輸入唷!");
	if(!$temp_array[8]) error_message("您的【服務職稱】欄沒有輸入唷!");
	if(!$temp_array[9]) error_message("您的【郵遞區號】欄沒有輸入唷!");
	if(!$temp_array[10]) error_message("您的【聯絡地址】欄沒有輸入唷!");
	if(!$temp_array[11]) error_message("您的【聯絡電話】欄沒有輸入唷!");
	if(!$temp_array[21]) error_message("您的【收據抬頭】欄沒有輸入唷!");
	if(!$temp_array[22]) error_message("您的【統一編號】欄沒有輸入唷!，沒有可以輸入「無」");
	if(!$temp_array[22]=='無') $temp_array[22] = 0;
	
	$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?page=$page>";
	$array['{MIDDLE_PANEL_CONTENT}'] .= "<input type=hidden name=action value=step3>";
	
	/*陣列往下傳，準備送進資料庫*/
	foreach($temp_array as $key => $value)
	{
		$array['{MIDDLE_PANEL_CONTENT}'] .= "<INPUT TYPE=\"hidden\" NAME=\"temp_array[$key]\" VALUE=\"$value\">\n";
	}
	
	$array['{MIDDLE_PANEL_CONTENT}'] .= file_get_contents('require/reg2.htm');
	$array['{MIDDLE_PANEL_CONTENT}'] .= "</form>";
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	/*把確認值代換一次*/
	
	$temp_array[4]==0 ? $temp_array[4] = '男生' : $temp_array[4] = '女生';
	$temp_array[5]==0 ? $temp_array[5] = '教師' : $temp_array[5]==1 ? $temp_array[5] = '學生' : $temp_array[5] = '一般人士';
	$temp_array[6]==0 ? $temp_array[6] = '是' : $temp_array[6] = '否';
	$temp_array[12]==0 ? $temp_array[12] = '葷食' : $temp_array[12] = '素食';
	$temp_array[13]==0 ? $temp_array[13] = '不需要' : $temp_array[13] = '需要';
	$temp_array[14]==0 ? $temp_array[14] = '購買' : $temp_array[14] = '不購買';
	if($temp_array[22]==0) $temp_array[22] = '無';
		
	for($i=2;$i<23;$i++)
	{
		$buffer = str_replace('{' . ($i-1) . '}',$temp_array[$i],$buffer);
		if($i==16) $i = 20;
	}	
	
	return $buffer;
}


//第三步，寫入資料庫
function step3()
{
	global $page,$temp_array;
	
	
	/*計算金額*/
	switch($temp_array[5])
	{
		case 0:
		$temp_array[6] == 0 ? $aim = "mis_teacher" : $aim = "nomis_teacher" ;
		break;
		
		case 1:
		$temp_array[6] == 0 ? $aim = "mis_student" : $aim = "nomis_student" ;
		break;
		
		case 2:
		$temp_array[6] == 0 ? $aim = "mis_other" : $aim = "nomis_other" ;
		break;
		
	}
	
	$temp = sql_b("SELECT money FROM pay_setting WHERE status = '$aim'");
	$pay_money = $temp[0][0];
	
	
	/*開始寫入資料庫*/
	
	$sql  = "INSERT INTO member VALUES(NULL,NOW(),'$temp_array[0]'";
	
	for($i=2;$i<sizeof($temp_array);$i++)
	{
		$sql .= ",'$temp_array[$i]'";
	}
	$sql .= ",'$pay_money','$pay_money','0','0000-00-00 00:00:00')";
	
	$result = sql_i($sql);	

	$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/reg3.htm');	
	$buffer .= read_and_parser("middle.php",$array);
	unset($array);
	
	/* 查詢各項付款設定 */
	$temp = sql_b("SELECT money FROM pay_setting WHERE status = 'pay_way'");
	$kkk[] = $temp[0][0];
	
	$temp = sql_b("SELECT money FROM pay_setting WHERE status = 'pay_account'");
	$kkk[] = $temp[0][0];
	
	$temp = sql_b("SELECT money FROM pay_setting WHERE status = 'pay_accepter'");
	$kkk[] = $temp[0][0];
	
	$temp_ccc[] = $result + 920000;
	$temp_ccc[] = $temp_array[21];
	$temp_ccc[] = $temp_array[22];
	$temp_ccc[] = $pay_money;
	$temp_ccc[] = $kkk[0];
	$temp_ccc[] = "<font color=red><b>$kkk[1]</b></font>";
	$temp_ccc[] = $kkk[2];	
	
	for($i=0;$i<sizeof($temp_ccc);$i++)
	{
		$buffer = str_replace('{' . ($i+1) . '}',$temp_ccc[$i],$buffer);
	}

	//-------------------------------------------------------
	//寄信通知
	//--------------------------------------------------------------------

	$myname = "ICIM' 2004•國際資訊管理研討會"; 
	$myemail = "saturn@ax.com.tw"; 

	$contactname = $temp_array[3];; //收件人名稱(顯示)
	$contactemail = $temp_array[2];; //收件人郵件地址

	$message .= "線上報名完成通知信：<br>\n";
	$message .= "---------------------------------------------<br>\n";
	$message .= "報名編號：$temp_ccc[0]<br>\n";
	$message .= "收據抬頭：$temp_ccc[1]<br>\n";
	$message .= "統一編號：$temp_ccc[2]<br>\n";
	$message .= "繳費金額：<font color=blue><b>$temp_ccc[3]</b></font>元<br>\n";
	$message .= "付費方式：$temp_ccc[4]<br>\n";
	$message .= "帳　　號：$temp_ccc[5]<br>\n";
	$message .= "戶　　名：$temp_ccc[6]<br>\n";
	$message .= "---------------------------------------------<br>\n";
	$message .= "注意事項：<P>";
	$message .= "$temp_ccc[4]手續費請自行付費，請於「$temp_ccc[4]儲金存款通知單」上<br>「寄款人代號」欄位中註明報名編號。";
	$subject = "ICIM' 2004 報名完成 - 謝謝您!"; 

	$headers .= "MIME-Version: 1.0\r\n"; 
	$headers .= "Content-type: text/html; charset=big5\r\n"; 
	$headers .= "From: ".$myname." <".$myemail.">\r\n"; 
	$headers .= "To: ".$contactname." <".$contactemail.">\r\n"; 
	$headers .= "Reply-To: ".$myname." <$myreplyemail>\r\n"; 
	$headers .= "X-Priority: 1\r\n"; 
	$headers .= "X-MSMail-Priority: High\r\n"; 
	$headers .= "X-Mailer: Just My Server"; 

	@mail($contactemail, $subject, $message, $headers); 	
	$contactemail = "saturn@ax.com.tw";	
	@mail($contactemail, $subject, $message, $headers); 

	return $buffer;
}
?>