<?php
include_once("htui_header.php");

if (!empty($_POST)){
    
	$scuserid = $_SESSION["a_uid"];
    if (check_permission($scuserid,'rolelist.php',2)){

		$old_pwd = md5(flc_request($_POST["old_pwd"]));
		$newpwd  = md5(flc_request($_POST["qr_pwd"]));

		$sql = "select * from {$tablepre}scuser where ID='".$scuserid."' and Password='".$old_pwd."'";
        $row = $db->get_row($sql);
		if (empty($row)){
           $response_arr = array("status" => -1,"message"  => '旧密码不正确,修改失败');
	    }else{
		   $sql = "update {$tablepre}scuser set Password='".$newpwd."' where ID='".$scuserid."'";
		   $db->exec($sql);
		   $response_arr = array("status" => 1,"message"  => '密码修改成功');
	    }
	}else{
        $response_arr = array("status" => -1,"message"  => '对不起,您无权限操作!');
	}

    echo json_encode($response_arr);
    exit;
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>后台管理中心_飞天素材网</title>
<meta name="author" content="ftsucai.com">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/htstyle.css" rel="stylesheet">
<link href="../js/bootstrap-datepicker/bootstrap-datepicker3.min.css" rel="stylesheet">
<link href="../js/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
</head>
  
<body>

    <!--页面主要内容-->
    <main class="ftdms-layout-content">
      
      <div class="container-fluid" style="margin-bottom:90px;">
        
        <div class="row" style="margin-top:15px;">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header"><h4>修改密码</h4>
			  </div>
              <div class="card-body" style="padding:5px 20px;">
                
                <form class="form-horizontal" action="" method="post" id="form">

				  <div class="form-group">
                    <label class="col-xs-12" for="old_pwd">旧 密 码</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="old_pwd" name="old_pwd" value="">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="new_pwd">新 密 码</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="new_pwd" name="new_pwd" value="">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="qr_pwd">确认密码</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="qr_pwd" name="qr_pwd" value="">
                    </div>
                  </div><br>
                  
                  <div class="form-group">
                    <div class="col-xs-12">
					  <input type="hidden" name="role_id" id="role_id" value="<?php echo $id;?>">
					  <button class="btn btn-primary" type="button" id="submit">确认修改</button>
					  <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返回</button>
                    </div>
                  </div>
                </form>
				<br>
                
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.js"></script>
<script src="../js/perfect-scrollbar.min.js"></script>
<script src="../js/main.min.js"></script>
<script src="../js/bootstrap-notify.min.js"></script>
<script src="../js/tips.js"></script>
<script>
$("#submit").click(function(){

    var old_pwd = $("#old_pwd").val();
	var new_pwd = $("#new_pwd").val();
	var qr_pwd  = $("#qr_pwd").val();

	if (old_pwd==''){
		tips.notify('请输入旧的密码', 'warning', 200);
		return false;
	}
    
	if (new_pwd==''){
		tips.notify('请输入新的密码', 'warning', 200);
		return false;
	}
	
	if (qr_pwd==''){
		tips.notify('请输入确认密码', 'warning', 200);
		return false;
	}

	if (qr_pwd!=new_pwd){
		tips.notify('确认密码与新密码不一致', 'warning', 200);
		return false;
	}

    $.post("edit_pwd.php", $("#form").serialize(), function(data) {
		var rs  = eval('('+data+')');
        if(rs.status==1){
           tips.notify(rs.message, 'success', 200, 'ftsucai-name', 'top', 'center');
		}else{
		   tips.notify(rs.message, 'danger', 200);
		}
    });
	
});
</script>
</body>
</html>