<?php
require_once('header.php');
require_once('check_user.php');

$old = flc_request(trim($_POST["oldpwd"]));
$password = md5(trim($_POST["pwd"]));

if ($_POST["oldpwd"]!=''){
	$sql="select * from {$tablepre}scuser where ID='".$_SESSION["uid"]."' and Password='".md5($old)."'";
	$row   = $db->get_row($sql);
	if (empty($row )){
       $response_arr = array("status" => 0,"message"  => '原密码不正确!');
       echo json_encode($response_arr);
       exit;
    }else{
       $db->exec("update {$tablepre}scuser set Password='".$password."' where ID=".$_SESSION["uid"]);
	   $_SESSION["pwd"]=$password;
       $response_arr = array("status" => 1,"message"  => '密码修改成功!');
       echo json_encode($response_arr);
       exit;
    }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{$site_name}</title>
<meta name="keywords" content="{$site_key}">
<meta name="description" content="{$site_desc}">
<link href="css/dialog.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/fonts.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="js/superslide.js"></script>
<script src="js/code.js"></script>
<script src="js/tn_code.js"></script>
<script src="js/sucai.js"></script>
<script src="js/MiniDialog.js"></script>
<script src="js/masonry.js"></script>

<link type="image/png" href="favicon.ico" rel="shortcut icon">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</head>
<script>
function chk_reg(form){
	var chk=true
	if (!out_oldpwd()){chk=false}
	if (!out_pwd()){chk=false}
	if (!out_pwd2()){chk=false}
	if(chk){
		var oldpwd = $("#oldpwd").val();
		var pwd  = $("#pwd").val();
		$.post("modpwd.php", {oldpwd: oldpwd, pwd: pwd},function(data){
		   var rs=eval('('+data+')');
           var msg=rs.message;
		   if (rs.status==0){
		      Dialog.warn("修改失败", msg);
		   }
		   if (rs.status==1){
		      Dialog.success("修改成功", msg);
		   }
        });
	}
	return false;
}

function out_oldpwd(){
	var str=document.getElementById("oldpwd").value;
	var chk=true;
	if (str==''){chk=false;}
	if (chk){
        document.getElementById("oldpw").innerHTML='';
	}else{
		document.getElementById("oldpw").innerHTML='<font color=red>请输入原来的密码</font>';
		document.form.oldpwd.focus();
	}
	return chk;
}

function out_pwd(){
	var str=document.getElementById("pwd").value;
	var chk=true;
	if (str=='' || str.length<6 || str.length>12){chk=false;}
	if (chk){
        document.getElementById("pw").innerHTML='';
	}else{
		document.getElementById("pw").innerHTML='<font color=red>密码长度为6-12位数字或字符</font>';
		document.form.pwd.focus();
	}
	return chk;
}

function out_pwd2(){
    var str1=document.getElementById("pwd").value;
	var str2=document.getElementById("pwd2").value;
	var chk=true;
	if (str2=='' || str2.length<6 || str2.length>12 || str1!=str2){chk=false;}
	if (chk){
        document.getElementById("pw2").innerHTML='';
	}else{
		document.getElementById("pw2").innerHTML='<font color=red>两次输入的密码必须一致</font>';
		document.form.pwd2.focus();
	}
	return chk;
}

</script>
<body style="background-color: #FFFFFF;">
  <form action="" method="post" name="form">
  <table width="100%" border="0" class="font16">
	  <tr>
		<td width="25%" height="15" align="right" ></td>
		<td width="75%"></td>
	  </tr>
	  <tr>
		<td height="60" align="right" >原密码：</td>
		<td>
		  <input name="oldpwd" type="text" class="myinput" id="oldpwd" onBlur="out_oldpwd(this.value);" style="width:300px;">
		  *<p id="oldpw" style="font-size: 14px;">请输入您原来的密码</p></td>
	  </tr>
	  <tr>
		<td height="60" align="right">新密码：</td>
		<td><input name="pwd" type="password" class="myinput" id="pwd" onBlur="out_pwd(this.value);" style="width:300px;">
		*<p id="pw" style="font-size: 14px;">登录密码请输入6-12位字符</p>
		</td>
	  </tr>
	  <tr>
		<td height="60" align="right">确认密码：</td>
		<td><input name="pwd2" type="password" class="myinput" id="pwd2" onBlur="out_pwd2(this.value);" style="width:300px;">
		*<p id="pw2" style="font-size: 14px;">登录密码请输入6-12位字符</p>
		</td>
	  </tr>
	  <tr>
		<td height="60" align="right"></td>
		<td height="60" align="left">
		<input id="mybtn" class="mybtn" name="mybtn" type="button" value=" 确认修改 " onClick="chk_reg(form);" style="width:172px;cursor:pointer;">
		</td>
	  </tr>
  </table>
  </form>
</body>
</html>