<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'member_check.php';

$action=$_GET["action"];
if($action=="save"){
  $M_email=$_POST["M_email"];
  $M_pwd=$_POST["M_pwd"];
  $_POST["M_id"]=$M_id;

  if($M_email!=""){
    mysqli_query($conn, member("info_edit",$_POST));
    if($M_pwd!=""){
      mysqli_query($conn, member("pwd_edit",$_POST));
    }
    die("success");
  }else{
    die("error");
  }
}

if($action=="refresh"){
  $_POST["M_id"]=$M_id;
  mysqli_query($conn,member("key_refresh",$_POST));
  die($key);
}
?>
<!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>
<link rel="icon" href="../media/<?php echo $C_ico?>" type="image/ico">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
<script type="text/javascript" src="../upload/upload.js"></script>
<style type="text/css">
.showpic{height: 60px;border: solid 1px #DDDDDD;padding: 5px;}
</style>
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
  <?php require 'nav.php';?>
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <form class="form-horizontal" id="form">
          <div class="col-md-6">
            <div class="card">
              <div class="card-header"><h4>编辑信息</h4></div>
              <div class="card-body">
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">会员帐号</label>
                    <div class="col-xs-12">
                      <?php echo $M_login;?>
                    </div>
                  </div>
                  
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">登录密码</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" name="M_pwd" value="" placeholder="已加密保存，留空则不修改">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">电子邮箱</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" name="M_email" value="<?php echo $M_email?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">key</label>
                    <div class="col-xs-12">
                      <span id="M_key"><?php echo $M_key;?></span> <button type="button" class="btn btn-xs btn-info" onclick="refresh()">重置</button>
                    </div>
                  </div>

              </div>
            </div>
            <button type="button" onClick="save()" class="btn btn-primary">保存</button>
          </div>

          

        </form>
          

        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>

<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>

<script type="text/javascript">
    function save(){
      lightyear.loading('show');
        $.ajax({
                url:'?action=save',
                type:'post',
                data:$("#form").serialize(),
                success:function (data) {
                lightyear.loading('hide');
                if(data=="success"){
                  lightyear.notify("保存成功", 'success', 100);
                }else{
                  lightyear.notify(data, 'danger', 100);
                }
                }
              });
      }

  function refresh(){
    $.ajax({
          url:'?action=refresh',
          success:function (data) {
          lightyear.loading('hide');
            $("#M_key").html(data);
            lightyear.notify("重置成功", 'success', 100);
          }
        });
  }
  var path=window.location.pathname;
  $("a").each(function(){
    if(path.indexOf($(this).attr("href"))!=-1){
      console.log($(this).attr("href"));
      $(this).parent("li").addClass("active");
      $(this).parent("li").parent("ul").parent("li").addClass("open active");
    }
  });
</script>
</body>
</html>