<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>考试理管</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
</head>
<body>
	<%@include file="/WEB-INF/views/include/examInfoNavTabs.jsp" %>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>考试名称</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>${exam.name}</td>
				<td>${exam.status.name}</td>
				<td>
					<%-- <a class="btn btn-small btn-primary" href="${ctx }/admin/analysis/subject">❶科目参数设置</a>
					<a class="btn btn-small btn-info" href="${ctx}/admin/analysis/total">❷划线参数设置</a> --%>
					<a id="exam-Status" class="btn btn-small btn-warning" href="javascript:void(0);" onclick="calculate()">❸开始统分</a>
					<a class="btn btn-small btn-danger" href="javascript:void(0);" onclick="endedExam()">❹结束考试</a>
				</td>
			</tr>
		</tbody>
	</table>
<script type="text/javascript">
function calculate(){
	var url='${ctx}/admin/exam/calculate.json';
    $.ajax({
    url : url,
    type : "POST", 
    data: null,
    success : function(val) {
    	if(val.examStatus==0){
    		$("#exam-Status").html("❸开始统分");
    		$("#exam-Status").attr("onclick","calculate()");
    		$("#exam-Status").addClass("btn-warning");
    	}else if(val.examStatus==1){
    		$("#exam-Status").html("❸正在统分");
    		$("#exam-Status").removeClass("btn-warning");
    		$("#exam-Status").addClass("btn-inverse");
    		$("#exam-Status").removeAttr("onclick");
    	}else if(val.examStatus==2){
    		$("#exam-Status").html("❸统分结束");
    		$("#exam-Status").removeClass("btn-warning");
    		$("#exam-Status").addClass("btn-inverse");
    		$("#exam-Status").removeAttr("onclick");
    	}
   },
  	error:function(e){
      	$.jBox.info("通信发生错误，稍等片刻再重新提交！");
    	}
	})
}
function endedExam(){
	 var url='${ctx}/admin/exam/getexaminfo.json';
	    $.ajax( {
	    url : url,
	    type : "POST", 
	    data: null,
	    success : function(val) {
	    	if(val.status == "STATISTIC"){
	    		$.jBox.info("当前考试正在统计分析中，不能结束考试！");
	    		return false;
	    	}else if(val.status == "ENDED"){
	    		$.jBox.info("当前考试已结束！");
	    		return false;
	    	}else{
	    		finished();
	    	}
	    },
		error:function(e){
	    	$.jBox.info("通信发生错误，稍等片刻再重新提交！");
	    }
	    })
}
</script>	
</body>
</html>
