<?
if (!isset($_SESSION)) //判斷是否已經開啟SESSION
{
	header("Cache-control:private");
	session_start();
	}//開起SESSION}
	include("../function.php");
	check_login();
putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");
	$mId=$_SESSION['mId'];
	include("../db.php");

	$res = oci_parse($conn,"select * from MEMBER where MID='$mId'") or die('Insert error');
	oci_execute($res);
	$row=oci_fetch_object($res);

	if(!empty($_POST["password"]))
		 $password=($_POST["password"]);
	
	if(!empty($_POST["password1"]))
		$password1=($_POST["password1"]);

	if(!empty($_POST["password2"]))	
		$password2=($_POST["password2"]);

	$opa=$_POST["password2"];

	if(empty($password)||empty($password1)||empty($password2))
	{
	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"請輸入密碼!!\");";
	echo "location.href=\"member_data_edit.php?mId=$mId\";";
	echo "</script></body>	</html>";
	}
	else if($password1!= $password2)
	{
	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"新密碼與確認密碼不符 請重新輸入!!\");";
	echo "location.href=\"member_data_edit.php?mId=$mId\";";
	echo "</script></body>	</html>";
	}else if($password != $row->PASSWORD){
	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"新密碼與舊密碼不符 請重新輸入asdsd!!\");";
	echo "location.href=\"member_data_edit.php?mId=$mId\";";
	echo "</script></body>	</html>";
	}
	else if ($password == $row->PASSWORD && $password1==$password2)
	{
	$upd = oci_parse($conn,"UPDATE MEMBER SET PASSWORD='$password1' where MID='$mId'") or die('Insert error');
    oci_execute($upd);

	echo "<html>
        	<head>
        	<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
        	</head>
        	<body><script>";
	echo "alert(\"密碼修改成功!!\");";
	echo "location.href=\"member_data_edit.php?mId=$mId\";";
	echo "</script></body>	</html>";
	}

?>

