<?

if (!isset($_SESSION)) //判斷是否已經開啟SESSION
{
	header("Cache-control:private");
session_start();


}//開起SESSION}
$mid=$_SESSION['mId'];
include("../function.php");
check_login();
putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");
if($mid!=''){



require_once("../db.php");

$msg='';


	 
//$tMsn=$_POST['tMsn'];
$tPhone=$_POST['tPhone'];
$tEmail=$_POST['tEmail'];
 $tTraffic=$_POST['tTraffic'];
$tElse=$_POST['tElse'];
if($tElse==''){$tElse="無";}
else{$tElse=nl2br(htmlspecialchars($tElse));}

$rId=$_POST['rId'];
$mId=$_POST['mId'];
/*
foreach($tTraffic as $tmp){

	$traffic[]=$tmp;

}
$traff = implode ("-", $traffic);

print_r($traffic[]);
echo $traffic[0];*/
//echo $str=implode("-",$traffic);

/*------------------空白判斷-----------------------*/


if(empty($tPhone))
{
	$msg.="請輸入您的電話!!";
	/*
	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"請輸入您的電話!\");";
	echo "history.go(-1)";
	echo "</script></body>
        	</html>";
        	*/
}
else if(empty($tEmail))
{
	$msg.="請輸入您的E-mail!!";
	/*
	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"請輸入您的E-mail!!\");";
	echo "history.go(-1)";
	echo "</script></body>
        	</html>";*/
}
else if(empty($tTraffic))
{
	$msg.="請至少選擇一種交通方式";
	/*
	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"請至少選擇一種交通方式\");";
	echo "history.go(-1)";
	echo "</script></body>
        	</html>";
		*/	

}
else if ($msg=='')
{
 //$tMsn=nl2br(htmlspecialchars($tMsn));
  $tPhone=nl2br(htmlspecialchars($tPhone));
   $tEmail=nl2br(htmlspecialchars($tEmail));
    $tTraffic=nl2br(htmlspecialchars($tTraffic));
 $tmp = explode ("-", $tTraffic);
 foreach($tmp as $x){
 	if($x!='')
 	$ser_str[]=$x; 
 	}

$traff=implode("-",$ser_str);
//Update 'take' 
$str = oci_parse($conn,"INSERT INTO TAKES (TPHONE,TEMAIL,TRAFFIC,TELSE,RID,MID) VALUES 
		('$tPhone','$tEmail','$traff','$tElse','$rId','$mId')") or die('Insert error');
oci_execute($str);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
	

//Prepare to UPDATE rLimit
$str2 = oci_parse($conn,"SELECT RLIMIT,RLIMIT_1 FROM RAISE WHERE RID='$rId'") or die('Insert error');
oci_execute($str2);
$row=oci_fetch_object($str2);


$rLimit_1 = $row->rLimit_1+1;
//Update rLimit
$str3 = oci_parse($conn,"UPDATE RAISE SET RLIMIT_1 = $rLimit_1 WHERE RID='$rId'") or die('Insert error');
oci_execute($str3);

//if rLimit_1 goes to rLimit
if($rLimit_1==$row->rLimit){   
$str4 = oci_parse($conn,"UPDATE RAISE SET RSTATE ='2' where RID='$rId'") or die('Insert error');
oci_execute($str4);


	}
/*		
echo "<script>";
echo "location.href=\"show_raise_detail.php?rId=$rId\";";
echo "</script>";
*/
}else{
	echo $msg;
	
	}

//echo mysql_error();




?>
<?
}else{echo "請先登入";}
?>