<%@ 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" %>
    <style type="text/css">.sort {
        color: #0663A2;
        cursor: pointer;
    }</style>
</head>
<body>
<div id="importBox" class="hide">
    <form id="importForm" action="${ctx}/admin/exam/student/import" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
        <input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
        <a href="${ctx}/admin/exam/student/template">下载模板</a>
    </form>
</div>
<div id="breachImportBox" class="hide">
    <form id="breachImportForm" action="${ctx}/admin/exam/student/breachImport" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input id="breachUploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
        <input id="breachBtnImportSubmit" class="btn btn-primary" type="submit" value="违纪考生导入"/>
        <a href="${ctx}/admin/exam/student/breachTemplate">下载模板</a>
    </form>
</div>
<div id="absentImportBox" class="hide">
    <form id="absentImportForm" action="${ctx}/admin/exam/student/absentImport" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input id="absentUploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
        <input id="absentBtnImportSubmit" class="btn btn-primary" type="submit" value="缺考考生导入"/>
        <a href="${ctx}/admin/exam/student/absentTemplate">下载模板</a>
    </form>
</div>
<div id="uploadImportBox" class="hide">
    <form id="uploadImportForm" action="${ctx}/admin/exam/student/uploadImport" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input id="studentUploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
        <input id="uploadBtnImportSubmit" class="btn btn-primary" type="submit" value="多媒体考生上传导入"/>
        <a href="${ctx}/admin/exam/student/uploadTemplate">下载模板</a>
    </form>
</div>
<form id="searchForm" action="${ctx}/admin/exam-param/student" method="post" class="breadcrumb form-search">
    <input type="hidden" id="pageNumber" name="pageNumber" value="${query.pageNumber }"/>
    <input type="hidden" id="pageSize" name="pageSize" value="${query.pageSize}"/>
    <div>
        <label>姓名</label>
        <input type="text" name="name" value="${query.name}" maxlength="10" class="input-mini studentQuery"/>
        <label>准考证号</label>
        <input type="text" name="examNumber" value="${query.examNumber}" maxlength="50" class="input-small studentQuery"/>
        <label>密号</label>
        <input type="text" name="secretNumber" value="${query.secretNumber}" maxlength="50" class="input-small studentQuery"/>
        <label>学号</label>
        <input type="text" name="studentCode" value="${query.studentCode}" maxlength="30" class="input-small studentQuery"/>
        <label>科目</label>
        <select class="input-large studentQuery" id="subjectCode" name="subjectCode">
            <option value="">请选择</option>
            <c:forEach items="${subjectList }" var="subject">
                <option value="${subject.code }" <c:if test="${query.subjectCode eq subject.code }">selected</c:if>>${subject.code}-${subject.name}</option>
            </c:forEach>
        </select>
        <br><br>
        <label>层次</label>
        <select class="input-small studentQuery" id="subjectLevel" name="subjectLevel">
            <option value="">请选择</option>
            <c:forEach items="${levelList }" var="level">
                <option value="${level}" <c:if test="${query.subjectLevel eq level }">selected</c:if>>${level}</option>
            </c:forEach>
        </select>
        <label>专业类型</label>
        <select class="input-small studentQuery" id="subjectCategory" name="subjectCategory">
            <option value="">请选择</option>
            <c:forEach items="${categoryList }" var="category">
                <option value="${category}" <c:if test="${query.subjectCategory eq category }">selected</c:if>>${category}</option>
            </c:forEach>
        </select>
        
        <label>状态</label>
        <select id="upload" name="upload" class="input-small studentQuery">
            <option value="">不限</option>
            <option value="1" <c:if test="${query.upload!=null && query.upload==true}">selected</c:if>>已上传</option>
            <option value="0" <c:if test="${query.upload!=null && query.upload==false}">selected</c:if>>未上传</option>
        </select>
        <select id="absent" name="absent" class="input-small studentQuery">
            <option value="">不限</option>
            <option value="1" <c:if test="${query.absent!=null && query.absent==true}">selected</c:if>>缺考</option>
            <option value="0" <c:if test="${query.absent!=null && query.absent==false}">selected</c:if>>正常</option>
        </select>
        <select id="breach" name="breach" class="input-small studentQuery">
            <option value="">不限</option>
            <option value="1" <c:if test="${query.breach!=null && query.breach==true}">selected</c:if>>违纪</option>
            <option value="0" <c:if test="${query.breach!=null && query.breach==false}">selected</c:if>>正常</option>
        </select>
        <select id="manualAbsent" name="manualAbsent" class="input-small studentQuery">
            <option value="">不限</option>
            <option value="1" <c:if test="${query.manualAbsent!=null && query.manualAbsent==true}">selected</c:if>>人工指定缺考</option>
            <option value="0" <c:if test="${query.manualAbsent!=null && query.manualAbsent==false}">selected</c:if>>正常</option>
        </select>
        <br><br>
        <label>签到表编号</label>
        <input type="text" name="packageCode" value="${query.packageCode}" maxlength="30" class="input-mini studentQuery"/>
        <label>批次编号</label>
        <input type="text" name="batchCode" value="${query.batchCode}" maxlength="30" class="input-mini studentQuery"/>
        <label>电厂</label>
        <input type="text" name="college" value="${query.college}" maxlength="64" class="input-mini studentQuery"/>
        <label>机组</label>
        <input type="text" name="className" value="${query.className}" maxlength="64" class="input-mini studentQuery"/>
        <label>总评</label>
        <input type="text" name="teacher" value="${query.teacher}" maxlength="64" class="input-mini studentQuery"/>
        <label>考点</label>
        <input type="text" name="examSite" value="${query.examSite}" maxlength="64" class="input-mini studentQuery"/>
        <label>考场</label>
        <input type="text" name="examRoom" value="${query.examRoom}" maxlength="64" class="input-mini studentQuery"/>
        <label>扫描张数</label>
        <input type="number" name="sheetCount" value="${query.sheetCount}" maxlength="64" class="input-mini digits studentQuery"/>
        <br><br>
        &nbsp;<input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
        <c:if test="${web_user.schoolAdmin==true}">
            &nbsp;<a href="${ctx}/admin/exam/student/add" class="btn btn-primary">添加</a>
            &nbsp;<input id="btnImport" class="btn" type="button" value="导入"/>
            <c:if test="${examType!='MULTI_MEDIA' }">
                &nbsp;<div class="btn-group">
                <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                    导入名单<span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="##" id="breachBtnImport">违纪名单</a></li>
                    <li><a href="##" id="absentBtnImport">缺考名单</a></li>
                    <!--                             <li><a href="##" id="uploadBtnImport">多媒体上传名单</a></li> -->
                </ul>
                </div>
            </c:if>
        </c:if>
       <%--  <c:if test="${query.totalCount>0 && query.totalCount<=10000}"> --%>
            &nbsp;<input id="export-button" class="btn" type="button" value="导出"/>
      <%--   </c:if> --%>
    </div>
</form>
<form id="exportForm" action="${ctx}/admin/exam/student/export" method="post" class="breadcrumb form-search hide">
		<input type="text" name="name" value="${query.name}" maxlength="10" class="input-mini"/>
        <input type="text" name="examNumber" value="${query.examNumber}" maxlength="50" class="input-small"/>
        <input type="text" name="secretNumber" value="${query.secretNumber}" maxlength="50" class="input-small"/>
        <input type="text" name="studentCode" value="${query.studentCode}" maxlength="30" class="input-small"/>
        <input type="text" name="subjectCode" value="${query.subjectCode}"  class="input-small"/>
        <input type="text" name="subjectLevel" value="${query.subjectLevel}"  class="input-small"/>
		<input type="text" name="subjectCategory" value="${query.subjectCategory}" maxlength="20" class="input-small"/>
   		<input type="text" name="upload" value="${query.upload}" class="input-small"/>
		<input type="text" name="absent" value="${query.absent}" class="input-small"/>
		<input type="text" name="breach" value="${query.breach}" class="input-small"/>
		<input type="text" name="manualAbsent" value="${query.manualAbsent}" class="input-small"/>
		<input type="text" name="packageCode" value="${query.packageCode}" class="input-mini"/>
		<input type="text" name="batchCode" value="${query.batchCode}" class="input-mini"/>
        <input type="text" name="college" value="${query.college}" maxlength="64" class="input-mini"/>
        <input type="text" name="className" value="${query.className}" maxlength="64" class="input-mini"/>
        <input type="text" name="teacher" value="${query.teacher}" maxlength="64" class="input-mini"/>
        <input type="text" name="examSite" value="${query.examSite}" maxlength="64" class="input-mini"/>
        <input type="text" name="examRoom" value="${query.examRoom}" maxlength="64" class="input-mini"/>
        <input type="number" name="sheetCount" value="${query.sheetCount}" maxlength="64" class="input-mini"/>
</form>
<tags:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th>准考证号</th>
        <th>密号</th>
        <th>姓名</th>
        <th>学号</th>
        <th>科目</th>
        <th>试卷类型</th>
        <th>层次</th>
        <th>专业类型</th>
        <th>扫描识别</th>
        <th>扫描张数</th>
        <th>人工指定</th>
        <th>批次编号</th>
        <th>签到表编号</th>
        <th>电厂</th>
        <th>机组</th>
        <th>总评</th>
        <th>考点</th>
        <th>考场</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${studentList}" var="student">
        <tr>
            <td>${student.examNumber}</td>
            <td>${student.secretNumber}</td>
            <td>${student.name}</td>
            <td>${student.studentCode}</td>
            <td>${student.subjectCode}-${student.subjectName}</td>
            <td>${student.paperType}</td>
            <td>${student.subject.level}</td>
            <td>${student.subject.category}</td>
            <td>
                <c:if test="${student.upload==true}">
                    <c:if test="${examType!='MULTI_MEDIA'}">
                        <a class="sheet-link" href="##" data-sheet-url="${student.sheetUrlString}" data-answer-url="<c:if test="${student.answerUrl!=null}">${fileServer}${student.answerUrl}</c:if>"
                           data-title="${student.examNumber}&nbsp;&nbsp;${student.name}&nbsp;&nbsp;客观总分${student.objectiveScoreString}&nbsp;&nbsp;主观总分${student.subjectiveScoreString}&nbsp;&nbsp;全卷总分${student.totalScoreString}">已上传</a>
                    </c:if>
                    <c:if test="${examType=='MULTI_MEDIA'}">
                        已上传
                    </c:if>
                    &nbsp;
                    <c:if test="${student.absent==true}">
                        缺考
                    </c:if>
                    <c:if test="${student.absent==false}">
                        正常
                    </c:if>
                </c:if>
                
                <c:if test="${student.upload==false}">
                    未上传
                </c:if>
            
            </td>
            <td><fmt:formatNumber value="${student.sheetCount/2}" type="number" maxFractionDigits="0"/></td>
            <td>
                <c:if test="${student.breach==true}">
                    <c:if test="${web_user.schoolAdmin==true}">
                        <a href="##" onclick="updateBreach(${student.id});">违纪</a></c:if>
                    <c:if test="${web_user.schoolAdmin!=true}">违纪</c:if>
                </c:if>
                <c:if test="${student.breach==false}">
                    正常
                </c:if>
                &nbsp;
                <c:if test="${student.manualAbsent==true}">
                    人工指定
                </c:if>
                <c:if test="${student.manualAbsent==false}">
                    正常
                </c:if>
            </td>
            <td>${student.batchCode}</td>
            <td>
                <c:if test="${student.packageUrlString!=null && student.packageUrlString!=''}">
                    <a class="package-link" href="##" data-image-url="${student.packageUrlString}" data-title="${student.packageCode}">${student.packageCode}</a>
                </c:if>
                <c:if test="${student.packageUrlString==null || student.packageUrlString==''}">
                    ${student.packageCode}
                </c:if>
            </td>
            <td>${student.college}</td>
            <td>${student.className}</td>
            <td>${student.teacher}</td>
            <td>${student.examSite}</td>
            <td>${student.examRoom}</td>
            <td>
                <c:if test="${web_user.schoolAdmin==true}">
                    <a href="${ctx}/admin/exam/student/update?id=${student.id}" class="update-btn">修改</a>
                    <c:if test="${examType!='MULTI_MEDIA'}">
                        &nbsp;
                        <a href="${ctx}/admin/exam/student/delete?id=${student.id}" onclick="return confirmx('确认要删除该考生吗？', this.href)">删除</a>
                    </c:if>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pagination">${query}</div>
<%@include file="/WEB-INF/views/include/sheetView.jsp" %>
<%@include file="/WEB-INF/views/include/imageView.jsp" %>
<script type="text/javascript">

    $(document).ready(function () {
    	var s=localStorage.getItem("studentQuery");
    	if(s!="" && s!=null && s!=undefined){
    		var studentQuery = JSON.parse(s);
    		var pageN =1;
    		var pageS =20;
    		 for (var i = 0; i < studentQuery.length; i++) {
    			var value = studentQuery[i].value;
    			if(value!="" && value!=null && value!=undefined){
	    			var name = studentQuery[i].name;
    				$('[name='+name+']').attr('value',value);
    				if(name=='pageNumber'){
    					pageN = value;
    				}
    				if(name=='pageSize'){
    					pageS = value;
    				}
    			} 
    		};
    		localStorage.setItem("studentQuery","");
    		page(pageN, pageS);
    	}
        $('.sheet-link').click(function () {
            initSheetPopover($(this).attr('data-title'), '${fileServer}', $(this).attr('data-sheet-url'), $(this).attr('data-answer-url'));
            return false;
        });
        $('.package-link').click(function () {
            initImagePopover($(this).attr('data-title'), '${fileServer}', $(this).attr('data-image-url'));
            return false;
        });
        $("#searchForm").validate({
            submitHandler: function (form) {
                loading('正在提交，请稍等...');
                form.submit();
            },
            errorContainer: "#messageBox",
            errorPlacement: function (error, element) {
                $("#messageBox").text("输入有误，请先更正。");
                if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                    error.appendTo(element.parent().parent());
                } else {
                    error.insertAfter(element);
                }
            }
        });
    });

    $('#packageCode').click(function () {
        $('#collapse1 > div > ul > li:nth-child(5)').addClass('active');
    });

    $("#btnImport").click(function () {
        $.jBox($("#importBox").html(), {
            title: "导入数据", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#breachBtnImport").click(function () {
        $.jBox($("#breachImportBox").html(), {
            title: "导入数据", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#absentBtnImport").click(function () {
        $.jBox($("#absentImportBox").html(), {
            title: "导入数据", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#uploadBtnImport").click(function () {
        $.jBox($("#uploadImportBox").html(), {
            title: "导入数据", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#export-button").click(function () {
        $("#exportForm").attr("action", "${ctx}/admin/exam/student/export");
        $("#exportForm").submit();
    });

    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").attr("action", "${ctx}/admin/exam/student");
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#pageSize").val('${query.pageSize}');
        $("#searchForm").attr("action", "${ctx}/admin/exam/student");
        $("#searchForm").submit();
        return false;
    }

    function updateBreach(studentId) {
        top.$.jBox.confirm("确认要将该考生违纪重置为正常？", "提示", function (v, h, f) {
            if (v == "ok") {
                var url = '${ctx}/admin/exam/student/updateBreach?id=' + studentId;
                $.ajax({
                    url: url,
                    type: "POST",
                    success: function (val) {
                        if (val.success) {
                            window.location.href = "${ctx}/admin/exam/student";
                        }
                    }
                })
            }
        });
    }
    
    $('.update-btn').click(function () {
    	localStorage.setItem("studentQuery", JSON.stringify($("#searchForm").serializeArray()));
    });
</script>
</body>
</html>