<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
		<title>资料修改-会员中心-<?php echo $cfg_webname;?></title>
		<link rel="stylesheet" href="/static/web/css/font-awesome.min.css">
		<link rel="stylesheet" href="/static/web/css/bootstrap.min.css">
		<link rel="stylesheet" href="/static/web/css/style.css">
	</head>
	<body class="body-bg">
		<?php obtaintheme('top.htm');?>
		<main class="container py-3">
			<div class="row">
				<?php
				$_menu_edtex = true;
				$_menu_edtitem = 'base';
				?>
				<?php include(DEDEMEMBER."/templets/menu.htm");?>
				<div class="col-md-9">
					<div class="pannel-main-container shadow-sm rounded">
						<form name="form2" action="<?php echo $cfg_memberurl;?>/edit_baseinfo.php" method="post" enctype="multipart/form-data" onsubmit="return checkSubmit();">
							<input type="hidden" name="_csrf_token" value="<?php echo $GLOBALS['csrf_token'];?>">
							<input type="hidden" name="dopost" value="save">
							<input type="hidden" id="newface" name="newface">
							<div class="mb-5 text-center">
								<input id="iptNewface" type="file" name="iptNewface" class="d-none">
								<p class="mb-2"><img id="face" src="<?php echo empty($row['face'])? $cfg_staticurl.'/web/img/admin.png' : $row['face'];?>" class="user-img-md"></p>
								<p class="mb-2"><?php echo $cfg_ml->M_LoginID;?></p>
								<span class="btn btn-success btn-sm" id="btnChangeFace">修改</span>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="iptUname">昵称：</label>
								<div class="col-sm-9"><input type="text" name="uname" id="iptUname" class="form-control" value="<?php echo $row['uname'];?>" required="required" placeholder="请输入昵称"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="iptUserpwd">新密码：</label>
								<div class="col-sm-9"><input type="password" name="userpwd" id="iptUserpwd"	class="form-control" placeholder="修改密码，无需修改忽略"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="iptUserpwdok">确认新密码：</label>
								<div class="col-sm-9"><input type="password" name="userpwdok" id="iptUserpwdok"	class="form-control" placeholder="请再次输入修改密码，无需修改忽略"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="newsafequestion">新安全问题：</label>
								<div class="col-sm-9"><?php echo GetSafequestion(0,'newsafequestion');?></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="iptNewsafeanswer">新问题答案：</label>
								<div class="col-sm-9"><input type="text" name="newsafeanswer" id="iptNewsafeanswer" class="form-control" placeholder="请设置或回答安全问题，无需修改忽略"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="safequestion">修改安全问题：</label>
								<div class="col-sm-9"><?php echo GetSafequestion($row['safequestion'],'safequestion');?></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="iptSafeanswer">修改问题答案：</label>
								<div class="col-sm-9"><input type="text" name="safeanswer" id="iptSafeanswer" class="form-control" placeholder="请选择安全问题后设置新安全问题，无需修改忽略"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label" for="iptEmail">邮箱：</label>
								<div class="col-sm-9">
									<input type="email" name="email" id="iptEmail" autocomplete="off" class="form-control" value="<?php echo $row['email'];?>" required="required" placeholder="请输入邮箱，绑定会员账号">
								</div>
							</div>
							<div class="form-group row">
								<span class="col-sm-3 col-form-label">性别：</span>
								<div class="col-sm-9 input-text">
									<label><input type="radio" name="sex" value="男" <?php if ($row['sex']=='男') echo 'checked';?>> 男</label>
									<label><input type="radio" name="sex" value="女" <?php if ($row['sex']=='女') echo 'checked';?>> 女</label>
									<label><input type="radio" name="sex" value="保密" <?php if ($row['sex']=='保密') echo 'checked';?>> 保密</label>
								</div>
							</div>
							<div class="text-center"><button type="submit" class="btn btn-success btn-sm">保存</button></div>
						</form>
					</div>
				</div>
			</div>
		</main>
		<?php obtaintheme('foot.htm');?>
		<script>
			function checkSubmit() {
				if (document.form2.oldpwd.value == '') {
					document.form2.oldpwd.focus();
					ShowMsg("请您填写密码");
					return false;
				}
				if (document.form2.userpwdok.value != document.form2.userpwd.value) {
					document.form2.userpwdok.focus();
					ShowMsg("两次密码不一致");
					return false;
				}
				if (document.form2.email.value == "") {
					document.form2.email.focus();
					ShowMsg("请您填写邮箱");
					return false;
				}
				if (document.form2.uname.value == "") {
					document.form2.uname.focus();
					ShowMsg("请您填写昵称");
					return false;
				}
			}
			$(document).ready(function() {
				$("#btnChangeFace").click(function() {
					$("#iptNewface").click();
				});
				$("#iptNewface").change(function(val) {
					var formData = new FormData();
					var fileData = $('#iptNewface')[0].files[0];
					formData.append('file', fileData);
					$.ajax({
						url: '<?php echo $cfg_memberurl;?>/api.php?action=upload&type=face',
						type: 'POST',
						data: formData,
						processData: false,
						contentType: false,
						success: function(result) {
							if (result.code === 0) {
								$("#face").attr('src', result.data);
								$("#newface").val(result.data);
							} else {
								ShowMsg(result.error.message);
							}
						},
						error: function(xhr, status, error) {
							alert(error); //处理上传失败后的回调
						}
					});
				});
			});
		</script>
	</body>
</html>