<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<style>
 .first{width: 80px;}
 .dataInfo{text-align: center;width: 50px;color: red;}
 
</style>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

$(function(){
	swfuPaper = new SWFUpload({
	    upload_url :"${ctx}/examPaper/paperUpload/${paperBatch.id}",
	    use_query_string : false,
	    
	    
	   // File Upload Settings
	   file_size_limit : "1000 MB",  // 1000MB
	   file_types : "*.zip",
	   file_types_description : "所有文件",
	   file_upload_limit : "0",
	                   
	   file_queue_error_handler : fileQueueError,
	   file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
	   upload_progress_handler : uploadProgress,
	   upload_error_handler : uploadError,
	   upload_success_handler : uploadSuccess,
	   upload_complete_handler : uploadComplete,
	
	   // Button Settings
	   button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
	   button_placeholder_id : "paperspanButtonPlaceholder",
	   button_width: 220,
	   button_height: 18,
	   button_text : '<span class="button">导入试卷或答案</span><span style="color: red;">(上传zip压缩包)</span>',
	   button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
	   button_text_top_padding: 0,
	   button_text_left_padding: 18,
	   button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
	   button_cursor: SWFUpload.CURSOR.HAND,
	   
	   // Flash Settings
	   flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',
	
	   custom_settings : {
	       upload_target : "divFileProgressContainer"
	   },
	   // Debug Settings
	   debug: false  //是否显示调试窗口
	});
});
function load(){
	var obj={
			"batchId" :${paperBatch.id}
		};
	$.ajax({
		type : "POST",
		url : "${ctx}/examPaper/getTotalCount",
		data :  JSON.stringify(obj) ,
		contentType : "application/json; charset=utf-8",
		dataType : "json",
		success : function(callback) {
			callback=eval(callback);
			var Rhtml="  该批次下:已上传 "+callback.paperCount+" 套试卷 、"+callback.standardAnswerPathCount+" 套标答、"+callback.answerSheetPathCount+" 套专卡、" + callback.separatePaperPath + " 套分卷、已有 " + callback.wPaperPath + " 套网评卷、已有 "+callback.isStorageScannedCount+" 套试卷入库扫描。";
			$("#paperInfo").html(Rhtml);
		}
	});
}

function copyToClipboard(id){
	var txt=$("#URLData").val();
    if(window.clipboardData){
        window.clipboardData.clearData();   
        window.clipboardData.setData("Text", txt);   
        $.messager.alert('提示','复制成功!');
    } else if(navigator.userAgent.indexOf("Opera") != -1) {
         window.location = txt;
         $.messager.alert('提示','复制成功!');
    } else if (window.netscape) {   
         try {   
              netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
         } catch (e) {   
              alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");   
         }   
         var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
         if (!clip)   
              return;   
         var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
         if (!trans)   
              return;   
         trans.addDataFlavor('text/unicode');   
         var str = new Object();   
         var len = new Object();   
         var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
         var copytext = txt;   
         str.data = copytext;   
         trans.setTransferData("text/unicode",str,copytext.length*2);   
         var clipid = Components.interfaces.nsIClipboard;   
         if (!clip){
        	 return false;
         }
         clip.setData(trans,null,clipid.kGlobalClipboard);
         $.messager.alert('提示','复制成功!');
    }
}  
function printCode(url,batchId){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		var arr = new Array();
		var rows = $('#dg').datagrid("getSelections");
		for(var i =0;i<rows.length;i++){
			var rr=rows[i];
			arr.push(rr.id);
		}
		var win = open();
		win.location.href = url+"/examPaper/printCodeInfo/"+arr;
	}else{
		$.messager.confirm("操作提示", "是否打印该批次下所有的试卷条码?", function (data) {
			if (data) {
				var win = open();
				win.location.href = url+"/examPaper/printAllCodeInfo/"+batchId;
			}
		});
	}
}

function printAnswerCode(url,batchId){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		var arr = new Array();
		var rows = $('#dg').datagrid("getSelections");
		for(var i =0;i<rows.length;i++){
			var rr=rows[i];
			arr.push(rr.id);
		}
		var win = open();
		win.location.href = url+"/examPaper/printAnswerCodeInfo/"+arr;
	}else{
		$.messager.confirm("操作提示", "是否打印该批次下所有的答案条码?", function (data) {
			if (data) {
				var win = open();
				win.location.href = url+"/examPaper/printAllAnswerCodeInfo/"+batchId;
			}
		});
	}
}
function record(url,batchId){
	var grid = $('#dg');
	var options = grid.datagrid('getPager').data("pagination").options;
	var curr = options.pageNumber;
	var total = options.total;
	var max = Math.ceil(total/options.pageSize);
	
	
	/* var rowIndex=$('#dg1').datagrid('getRowIndex',$('#dg1').datagrid('getSelected')) ;
	alert(rowIndex); */
	var row = $('#dg').datagrid('getSelected');
	if (row){
		var arr = new Array();
		var rows = $('#dg').datagrid("getSelections");
		for(var i =0;i<rows.length;i++){
			var index=$('#dg').datagrid('getRowIndex',rows[i])+1;
			if(curr>1){
				index=(curr-1)*options.pageSize+index;
			}
			
			var rr=rows[i];
			arr.push(rr.id+"-"+index);
		}
		var win = open();
		win.location.href = url+"/examPaper/record/"+arr;
	}else{
		$.messager.confirm("操作提示", "是否打印该批次下所有的工作登记表?", function (data) {
			if (data) {
				var win = open();
				win.location.href = url+"/examPaper/recordByBatchId/"+batchId;
			}
		});
	}
}
function addPaperBtn(){
	$('#addPaper').window('open');
}
function checkCodeInfo(){
	var code=$("#paperCode").val();
	if(code.length==12){
		var obj={
				"code" :code
			};
		if(!isNaN(code.substr(0,11))){
			if(/^[A-Z]+$/.test(code.substr(11,12))){
				$.ajax({
					type : "POST",
					url : "${ctx}/examPaper/validataCode",
					data :  JSON.stringify(obj) ,
					contentType : "application/json; charset=utf-8",
					dataType : "json",
					success : function(callback) {
						callback=eval(callback);
						if(callback.result=='success'){
							$("#codeSuccess").show();
						}else{
							$("#codeFail").show();
							return;
						}
					}
				});
			}else{
				$("#codeError").show();
				return;
			}
		}else{
			$("#codeError").show();
			return;
		}
	}else{
		$("#codeError").show();
		return;
	}
}
function clearInfo(){
	$("#codeError").hide();
	$("#codeFail").hide();
	$("#codeSuccess").hide();
}
function addPaper(){
	var code=$("#paperCode").val();
	var status=$("#paperStatus").val();
	var isSpecialAnswerSheet=$("#paperIsSpecialAnswerSheet").val();
	var courseCode=$("#paperCourseCode").val();
	var courseName=$("#paperCourseName").val();
	var bookName=$("#paperBookName").val();
	var bookAuthor=$("#paperBookAuthor").val();
	var bookPress=$("#paperBookPress").val();
	var bookPressYear=$("#paperBookPressYear").val();
	var school=$("#paperSchool").val();
	
	
	if(code==''||status==''||isSpecialAnswerSheet==''||courseCode==''||courseName==''||bookName==''||bookAuthor==''||bookPress==''||bookPressYear==''||school==''){
		$.messager.alert('提示','不允许存在空值项','error');
		return;
	}
	
	var reg = new RegExp("/\d{11}[A-Z]/");
	if(code.length!=12){
		$.messager.alert('提示','试卷编码要求长度为12位','error');
		return;
	}
	
	if(!isNaN(code.substr(0,11))){
		if(/^[A-Z]+$/.test(code.substr(11,12))){
			
		}else{
			$.messager.alert('提示','试卷编码前11位要求是数字,最后一位为大写字母','error');
			return;
		}
	}else{
		$.messager.alert('提示','试卷编码前11位要求是数字','error');
		return;
	}
	
	if(courseCode.length!=5||isNaN(courseCode)){
		$.messager.alert('提示','课程代码一定是5位数字!','error');
		return;
	}
	var obj1={
			"code" :code
		};
	$.ajax({
		type : "POST",
		url : "${ctx}/examPaper/validataCode",
		data :  JSON.stringify(obj1) ,
		contentType : "application/json; charset=utf-8",
		dataType : "json",
		success : function(callback) {
			callback=eval(callback);
			if(callback.result=='success'){
				$("#codeSuccess").show();
				var obj={
						"code" :code,
						"status" :status,
						"isSpecialAnswerSheet" :isSpecialAnswerSheet,
						"courseCode" :courseCode,
						"courseName" :courseName,
						"bookName" :bookName,
						"bookAuthor" :bookAuthor,
						"bookPress" :bookPress,
						"bookPressYear" :bookPressYear,
						"school" :school,
					};
				$.ajax({
					type : "POST",
					url : "${ctx}/examPaper/addPaperInfo/"+${paperBatch.id},
					data :  JSON.stringify(obj) ,
					contentType : "application/json; charset=utf-8",
					dataType : "json",
					success : function(callback) {
						callback=eval(callback);
						if(callback.type=='success'){
							$('#dg').datagrid('reload');
							$("#paperCode").val("");
							$.messager.alert('提示','添加成功','info');
						}else{
							$.messager.alert('提示','添加失败','error');
						}
					}
				});
			}else{
				$("#codeFail").show();
				return;
			}
		}
	});
}

</script>
<div align="left" style="margin-left:10px;padding-bottom: 10px; color:#bf290b; font-size: 14px; font-weight:bold;" id="paperInfo"></div>
	<div title="试卷管理" style="padding:10px">
		<table id="dg" class="easyui-datagrid"
 data-options="
   url: '${ctx}/examPaper/queryPaper/${paperBatch.id}',
   fitColumns:true
   ,singleSelect:false
   ,striped:true
   ,pagination:true
   ,toolbar: '#tb',
   pageNumber:1,
   pageSize:10,
   onLoadSuccess:load
   ">
  <thead>
      <tr class="title">
          <th rowspan="2" data-options="field:'ck',checkbox:true"></th>
          <th rowspan="2" data-options="field:'code',width:100,editor:{type:'validatebox',options:{required:true}},styler:codeCellStyler,sortable:true">试卷编码</th>
          <th rowspan="2" data-options="field:'status',width:50 ,editor:{type:'combobox',
			                            options:{
			                                data:[{status:1,statusName:'毛坯'}
			                                     ,{status:2,statusName:'清样'}
			                                     ,{status:3,statusName:'启用'}],
			                                valueField:'status',
			                                editable:false,
                                            textField:'statusName',
			                                required:true }},styler:codeCellStyler,formatter: formatStatus">状态</th>
          <th rowspan="2" data-options="field:'isSpecialAnswerSheet',width:50 ,editable:false,formatter: formatZK,editor:{type:'combobox',
			                            options:{
			                                data:[{isSpecialAnswerSheet:1,name:'是'}
			                                     ,{isSpecialAnswerSheet:0,name:'不详'}],
			                                valueField:'isSpecialAnswerSheet',
			                                editable:false,
                                            textField:'name',
			                                required:true }},">专卡</th>
          <th rowspan="2" data-options="field:'courseCode',width:70,editor:{type:'validatebox',options:{required:true}},styler:codeCellStyler">课程代码</th>
          <th rowspan="2" data-options="field:'courseName',width:130,editor:{type:'validatebox',options:{required:true}},styler:codeCellStyler">课程名称</th>
          <th rowspan="2" data-options="field:'bookName',width:150,editor:{type:'validatebox',options:{required:true}}">教材名称</th>
          <th rowspan="2" data-options="field:'bookAuthor',width:80,editor:{type:'validatebox',options:{required:true}}">编者</th>
          <th rowspan="2" data-options="field:'bookPress',width:120,editor:{type:'validatebox',options:{required:true}}">出版社</th>
          <th rowspan="2" data-options="field:'bookPressYear',width:60,editor:{type:'validatebox',options:{required:true}}">版次</th>
          <th rowspan="2" data-options="field:'school',width:110,editor:{type:'validatebox',options:{required:true}}">学校</th>
          <th colspan="5" data-options="width:60">电子试卷</th>
          <th rowspan="2" data-options="field:'isStorageScanned',width:50,styler:cellStyler,formatter: formatBooleanData"><div style="padding-top: 20px;"><p>入库</p><p>扫描</p></div></th>
      </tr>
      <tr>
          <th data-options="field:'paperPath',width:30,styler:cellStyler,formatter: formatBooleanData">合卷</th>
          <th data-options="field:'standardAnswerPath',width:30,styler:cellStyler,formatter: formatBooleanData">标答</th>
          <th data-options="field:'separatePaperPath',width:30,styler:separatePaperCellStylerRuku,formatter:  formatSeparentPaperData">分卷</th>
          <th data-options="field:'wPaperPath',width:30,styler:separatePaperCellStylerRuku,formatter:  formatSeparentPaperData">网评卷</th>
          <th data-options="field:'answerSheetPath',width:30,styler:answerSheetDataCellStyler,formatter: formatAnswerSheetData">专卡</th>
      </tr>
  </thead>
</table>

<div id="tb" style="height:auto">
   <div style="margin-bottom:5px">
   		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-add',plain:true" onclick="addPaperBtn()">添加试卷</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-remove',plain:true" onclick="removeit()">删除</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-import-plan',plain:true" onclick="$('#w').window('open')">导入dbf</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-import-paper',plain:true" onclick="paperBtn()">电子试卷上传</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-barcode-scan',plain:true" onclick="barcodeScanStart('W3','入库扫描')">入库扫描</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-confirm',plain:true" onclick="checkOver()">结束检查</a>
        <a href="javascript:void(0)" id="print-mb" class="easyui-menubutton" data-options="menu:'#print-mm', iconCls:'easyui-icon-print',plain:true">打印</a>
        <div id="print-mm" style="width:150px;">
        	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-barcode',plain:true" onclick="printCode('${ctx}','${paperBatch.id}')">打印试卷条码</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-barcode',plain:true" onclick="printAnswerCode('${ctx}','${paperBatch.id}')">打印答案条码</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'easyui-icon-print',plain:true" onclick="record('${ctx}','${paperBatch.id}')">工作登记表</a>
        </div>
     </div>
     <div>
     <span style="color: red;"></span>
     <form id="search-form" method="post" >
                           试卷编码: <input id="code" name="code" style="width:150px;"/>
                           课程代码: 
        <input id="courseCode" name="courseCode" style="width:150px;"/>
        <span>电子试卷上传：</span>
        <select  id="rukuType" name="rukuType" style="width:150px;padding:0;">
            <option value="0"></option>
            <option value="3">试卷上传</option>
            <option value="6">试卷未上传</option>
            <option value="4">标答上传</option>
            <option value="7">标答未上传</option>
            <option value="5">专卡上传</option>
            <option value="8">专卡未上传</option>
            <option value="1">全部上传</option>
            <option value="2">未全部上传</option>
        </select>
        <span>入库扫描：</span>
        <select id="isStorageScanned" name="isStorageScanned" style="width:150px;padding:0;">
            <option value="2"></option>
            <option value="1">已扫描</option>
            <option value="0">未扫描</option>
        </select>
        <a href="#" class="easyui-linkbutton" iconCls="easyui-icon-search" id="searchDRAFT">查找</a>
        <a href="#" class="easyui-linkbutton clearSearch" iconCls="easyui-icon-undo" >清空条件</a>
        </form>
    </div>
</div>
	</div>

<div id="w2" class="easyui-window" title="导入试卷或答案" data-options="modal:true,closed:true,iconCls:'easyui-icon-import'" style="width:480px;height:200px;padding:10px;">
    <div id="do_import_paper_button">
        <div id="rukuPaperUploadMsg" ></div>
        <span id="paperspanButtonPlaceholder"></span>
    </div>
    <div id="error" style="display: none;padding-top: 10px;" align="center">
    	<input type="hidden" id="URLData"/>
        <table style="border-collapse: collapse;" class="tongjiTab">
        	<tr>
        		<td class="first"></td>
        		<td >试卷</td>
        		<td>答案</td>
        		<td>专卡</td>
        		<td>分卷</td>
        		<td>网评卷</td>
        	</tr>
        	<tr>
        		<td class="first">应导入</td>
        		<td class="dataInfo" id="YpaperData"></td>
        		<td class="dataInfo" id="YanswerData"></td>
        		<td class="dataInfo" id="YcardData">-</td>
        		<td class="dataInfo" id="YseparantPaperData">-</td>
        		<td class="dataInfo" id="YwPaperData">-</td>
        	</tr>
        	<tr>
        		<td class="first">已导入</td>
        		<td class="dataInfo" id="YipaperData"></td>
        		<td class="dataInfo" id="YianswerData"></td>
        		<td class="dataInfo" id="YicardData"></td>
        		<td class="dataInfo" id="YiseparantPaperData"></td>
        		<td class="dataInfo" id="YiwPaperData"></td>
        	</tr>
        	<tr>
        		<td class="first">导入失败</td>
        		<td class="dataInfo" id="SpaperData"></td>
        		<td class="dataInfo" id="SanswerData"></td>
        		<td class="dataInfo" id="ScardData"></td>
        		<td class="dataInfo" id="SseparantPaperData"></td>
        		<td class="dataInfo" id="SwPaperData"></td>
        	</tr>
        </table>
    </div>
    <div id="openFolder" style="display: none;padding-top: 10px;" align="center">
    </div>
</div>


<div id="addPaper" class="easyui-window" title="添加试卷" data-options="modal:true,closed:true,iconCls:'easyui-icon-add'" style="width:720px;height:330px;padding:10px;">
	<div id="paperInfo" style="padding-left: 40px;">
		<table>
			<tr>
				<td>试卷编码:</td>
				<td>
					<input type="text" name="code" style="width: 230px;"  id="paperCode"   onblur="checkCodeInfo()" onfocus="clearInfo()"/>
					<span style="color: red;display: none;" id="codeFail">×试卷编码输入不能存在重复的</span>
					<span style="color: green;display: none;" id="codeSuccess">√该试卷编码可用</span>
					<span style="color: red;display: none;" id="codeError">×试卷编码必须为12位 ,前11位是数字最后一位是字母并且大写</span>
				</td>
			</tr>
			<tr>
				<td>状态:</td>
				<td>
					<select name="status" style="width: 232px;" id="paperStatus">
						<option value="DRAFT">毛坯</option>
						<option value="FORMAL">清样</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>专卡:</td>
				<td>
					<select name="isSpecialAnswerSheet" style="width: 232px;" id="paperIsSpecialAnswerSheet">
						<option value="0">不详</option>
						<option value="1">是</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>课程代码:</td>
				<td><input type="text" name="courseCode" style="width: 230px;" id="paperCourseCode"/>
				<span style="color: green;" >提示:该字段一定是5位数字</span></td>
			</tr>
			<tr>
				<td>课程名称:</td>
				<td><input type="text" name="courseName" style="width: 230px;" id="paperCourseName"/></td>
			</tr>
			<tr>
				<td>教材名称:</td>
				<td><input type="text" name="bookName" style="width: 230px;" id="paperBookName"/>
				<span style="color: green;" >提示:该字段应该是书名号开头结尾</span></td>
			</tr>
			<tr>
				<td>编者:</td>
				<td><input type="text" name="bookAuthor" style="width: 230px;" id="paperBookAuthor"/></td>
			</tr>
			<tr>
				<td>出版社:</td>
				<td><input type="text" name="bookPress" style="width: 230px;" id="paperBookPress"/></td>
			</tr>
			<tr>
				<td>版次:</td>
				<td><input type="text" name="bookPressYear" style="width: 230px;" id="paperBookPressYear"/></td>
			</tr>
			<tr>
				<td>学校:</td>
				<td><input type="text" name="school" style="width: 230px;" id="paperSchool"/></td>
			</tr>
			<tr>
				<td colspan="2" style="padding-left: 120px;"><input type="button" value="添加" style="width: 60px;height: 30px;" onclick="addPaper()"/></td>
			</tr>
		</table>
	</div>
</div>