<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户管理</title>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />
<style>
.myInput{
	width: 140px;height: 20px;margin: 10px;
}
</style>
<%@ include file="../../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript">
	function hideAllLab(){
		$("#oldLab").hide();
		$("#newLab").hide();
		$("#confirmLab").hide();
	}

	function changePassword(){
		hideAllLab();
		$("#oldPassword").val($.trim($("#oldPassword").val()));
		if($("#oldPassword").val()==""){
			$("#oldLab").text("*请输入原密码");
			$("#oldLab").show();
			$("#oldPassword").focus();
			return;
		}

		$("#newPassword").val($.trim($("#newPassword").val()));
		if($("#newPassword").val()==""){
			$("#newLab").text("*请输入新密码");
			$("#newLab").show();
			$("#newPassword").focus();
			return;
		}

		$("#againPassword").val($.trim($("#againPassword").val()));
		if($("#againPassword").val()==""){
			$("#confirmLab").text("*请输入确认密码");
			$("#confirmLab").show();
			$("#againPassword").focus();
			return;
		}
		
			if($("#newPassword").val()!=$("#againPassword").val()){
				$("#confirmLab").text("*两次输入密码不一致");
				$("#confirmLab").show();
				$("#againPassword").select();
				return;
			}
			
			if($("#againPassword").val().length>16||$("#newPassword").val().length>16){
				$("#confirmLab").text("*新密码长度不能大于16");
				$("#confirmLab").show();
				$("#againPassword").select();
				return;
			}else{
				var obj={
						"id" : $("#userId").val(),
						"password" : $("#oldPassword").val()
				};
				var User = JSON.stringify(obj);
				
				
				$.ajax({
					type : "POST",
					url : "${ctx}/user/validateOldPassword",
					data : User,
					contentType : "application/json; charset=utf-8",
					dataType : "json",
					success : function(callback) {
						callback = eval(callback);
						if(callback.type=="success"){
							var obj={
									"id" : $("#userId").val(),
									"password" : $("#newPassword").val()
							};
							var User = JSON.stringify(obj);
							$.ajax({
								type : "POST",
								url : "${ctx}/user/changePassword",
								data : User,
								contentType : "application/json; charset=utf-8",
								dataType : "json",
								success : function(callback) {
									callback = eval(callback);
									if(callback.type=="success"){
										$.messager.alert('提示','修改密码成功!');
										$('#w').window('close');
									}else{
										$.messager.alert('提示','修改密码失败!');
										$('#w').window('close');
									}
								}
							});
						}else{
							$("#oldLab").text("*请输入正确的原密码");
							$("#oldLab").show();
						}
					}
				});
			}
	}
	
	function setValue(id){
		$("#userId").val(id);
	}
	
	$(document).ready(function(){
		{
			$.post('${ctx}/question/statMyAuditJob',{},function(res){
				if(res.flag=='failed'){
		           $.messager.alert('提示', res.msg, 'error', function () {
		        	$('#statDiv').html(res.msg);
		           });
				}else{
					$('#statDg').datagrid({data:res.auditorJob});
				}
			});
		}
	});
</script>
</head>
<body>
	<%@ include file="../../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../../common/sub_menu.jsp"%>
		<div class="page" id="page" >
		<div class="page-header">个人信息</div>
		<div class="page-body">
		<div class="box" style="width:60%">
	  	<div class="box-header">基本信息
	  	    <a id="link-user" class="link fr ico-edit-16" href="javascript:void(0)" style="margin-right:15px;" onclick="$('#w').window('open');setValue('${user.id}')">修改密码</a>
  	    </div>
		<ul class="property-panel">
	  		<li class="property-item">
	  			<label class="property-name">姓名：</label>
	  			<span class="property-value" >${user.name}</span>
	  		</li>
	  		<li class="property-item">
	  			<label class="property-name" style="width: 100px;">上次登录时间：</label>
	  			<span class="property-value" ><fmt:formatDate value="${lastLoginDate}" pattern="HH:mm:ss MM/dd/yyyy"/></span>
	  		</li>
	  	</ul>
	  	</div>
	  	<!-- 
	  	<div style="height:10px;" ></div>
	  	<div class="box" style="width:60%">
	  	<div class="box-header">权限信息</div>
	  	<ul class="property-panel">
	  		<li class="property-item">
	  			<label class="property-name">当前角色：</label>
	  			<input type="hidden" id="createdBy" value="${user.id} "/>
	  			<span class="property-value" >
	  			      ${role.name } 
	  			</span>
	  		</li>
	  		
	  		<li class="property-item">
	  			<label class="property-name">课程：</label>
	  			<span class="property-value" ><c:forEach var="cour" items="${courses}" varStatus="stat">${cour.name }<c:if test="${!stat.last}">，</c:if></c:forEach> </span>
	  		</li>
	  	</ul>
	  	</div>
	  	 -->
	  	<security:authorize ifAnyGranted="quesAuditor">
	  	<div style="height:10px;" ></div>
	  	<div class="box" style="width:60%">
	  	<div class="box-header">审题报表</div>
	  		<div id="statDiv">
	  		<table id="statDg" class="easyui-datagrid"
	                     data-options="fitColumns:true,singleSelect:true,striped:true,pagination:false">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'courseName',width:150">负责的课程</th>
	                             <th data-options="field:'draftNum',width:100">当前草稿数量</th>
	                             <th data-options="field:'approvedNum',width:100">审核通过的题量</th>
	                             <th data-options="field:'rejectedNum',width:100">审核拒绝的数量</th>
	                             <th data-options="field:'statTotalNum',width:100">审核题量总计</th>
	                         </tr>
	                     </thead>
        	</table>
        	</div>
	  	</div>
	  	</security:authorize>
		</div>   
		
		</div>
		</div>
		
		<div style="display: none;">
		<div id="w" class="easyui-window" title="修改密码" data-options="modal:true,closed:true,iconCls:'icon-save',collapsible:true" style="width:430px;height:260px;">
			<div style="margin-top: 20px;"align="center">
				<input type="hidden" id="userId" value="" />
				<div>
						<table width="410px;">
							<tr>
								<td style="width: 110px;" align="right">原密码:</td>
								<td><input type="password" id="oldPassword" class="myInput" maxlength="20"/><label style="display: none;color: red;" id="oldLab" >*原密码不正确</label></td>
							</tr>
							<tr>
								<td align="right">新密码:</td>
								<td><input type="password" id="newPassword" class="myInput" maxlength="20"/><label style="display: none;color: red;" id="newLab" >*两次输入密码不一致</label></td>
							</tr>
							<tr>
								<td align="right">确认密码:</td>
								<td><input type="password" id="againPassword" class="myInput" maxlength="20"/><label style="display: none;color: red;" id="confirmLab" >*两次输入密码不一致</label></td>
							</tr>
							<tr align="center">
								<td colspan="2" ><input type="button" value="提交" class="btn" onclick="changePassword()"/></td>
							</tr>
						</table>
				</div>
			</div>
		</div>
		</div>
</body>
</html>