<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>试题管理-试题列表</title>
<%@ include file="../common/top.jsp"%>
<link rel='stylesheet' type='text/css' href='${ctx}/resources/css/themes/default/easyui.css'/>
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/themes/icon.css"/>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link href='${ctx}/resources/css/user-center-style.css' rel='stylesheet' type='text/css' />

<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/validator.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/question/mng.jsp"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/uploadHandlers.js"></script>
<style>
@charset "utf-8";
.pages {text-align:center;width:100%;margin:20px auto;padding-top:20px;height:26px;overflow:hidden;}
.pages a {padding:5px;border:1px solid #CCC;margin:0px 5px;text-decoration:none;color:#333;}
.pages a:hover {border:1px solid #FC0;color:#F60;}
.pages .this {border:1px solid #FC0;color:#F60;}

.table-bordered{border-collapse:collapse;border:none;}
.table-bordered th{border:solid #c9c9c9 1px;padding:2px 2px 2px 2px;text-align: center;}
.table-bordered td{border:solid #c9c9c9 1px;padding:2px 2px 2px 2px;}

.title {text-align: center;background-color: #FFF9E7;}
.short {width: 30px;}
.container {width: 98%;margin: auto;padding-top: 15px;}
.caption {width: 100%;border-collapse:collapse;}
.info{width: 100%;border-collapse:collapse;}
.caption tr td{border: solid 1px #76abff;
color: #0047b8;
font-size: 16px;
font-weight: bold;
background:#ecfbff;
}
th{border: solid 1px #E0BF8D;}
.caption tr td select{width: 90%;}
.row{height: 30px;padding-top: 15px;}
.question-body {
    line-height: 1.5em;
    cursor: pointer;
    color: #333;
}

.bigBtn{width: 60px;height: 25px;}

.myTd3{border:solid windowtext 1px;padding:0px 2px 0px 2px;text-align:center;font-weight:bold;}

.myTd4{border:solid windowtext 1px;padding:0px 2px 0px 2px;}

.logDiv{
	margin-bottom: 10px;
	border-style: solid;
	border-width: 1px;
	border-color: #000000;
}

.myMargin1{
	margin-right: 10px;
}
.myMargin3{
	margin-right: 30px;
}
.myMargin4{
	margin-left: 3px;
}
.myTd1{
	width: 35px;
	text-align: left;
}
.myTd2{
	text-align: left;
}
.impLog{
	margin-top: 15px;
	margin-bottom: 10px;
	width: 480px;
	height: 180px;
	overflow: auto;
	border: 1px #000000 solid;
}
.impLog div{
	padding:4px 4px 4px 4px;
}
</style>
<script type="text/javascript">
<security:authorize ifAnyGranted="processManagement">
	var isQuesAuditor = false;
	<security:authorize ifAnyGranted="quesAuditor">
	isQuesAuditor = true;
	</security:authorize>

	function load(){
		$("#course").get(0).selectedIndex=0;
		$("#keyword").val("${questionId}");
		search('${ctx}','1');
	}

	var codeMap = {};
    <c:forEach items="${codes }" var="code">
    codeMap['${code.itemType}-${code.itemCode}'] = '${code.itemValue}';
    </c:forEach>

	function getAuditLogs(quesId){
		$(document).mask('正在查询审核日志，请稍等...');
		var param = {"quesId":quesId};
		$.post('${ctx}/question/getAuditLogs',param,function(res){
			$(document).unmask();
			if(res.flag=='failed'){
	           $.messager.alert('提示', res.msg, 'error', function () {
	        	   //do nothing
	           });
	           return false;
			}else{
				$('#showLogsDiv').html('');
				var htmlStr = '<table width="100%" class="table-bordered"><tr><th width="200">动作</th><th>备注</th></tr>';
				for(var i=0;i<res.auditLogs.length;i++){
					htmlStr = htmlStr + '<tr><td><div>' + res.auditLogs[i].createdByName + ' 于 ' + res.auditLogs[i].createdTimeStr + '</div><div>执行了操作：' + res.auditLogs[i].operCode + '</div></td><td class="myTd2"><div id="logRemark' + res.auditLogs[i].id + '"></div></td></tr>';
				}
				htmlStr = htmlStr + '</table>';
				$('#showLogsDiv').html(htmlStr);
				for(var i=0;i<res.auditLogs.length;i++){
					$('#logRemark' + res.auditLogs[i].id).text(res.auditLogs[i].remark);
				}
		    	$('#logListDiv').window('open');
			}
		});
	}
	
	//审核
	function audit(quesId){
		$("#quesIdForAudit").val(quesId);
		$("#auditRemark").val("");
		calculate_byte(200,'auditRemark','count');
		$('#auditDiv').window('open');
	}

	$(document).ready(function(){
		{//初始化审核意见输入框字符数控制
			$("#auditRemark").keydown(function(){
		    	calculate_byte(200,'auditRemark','count');
		    });
		    $("#auditRemark").keyup(function(){
		    	calculate_byte(200,'auditRemark','count');
		    });
		    $("#auditRemark").keypress(function(){
		    	calculate_byte(200,'auditRemark','count');
		    });
		}
	
		$("#saveAuditBtn").click(function(){
			$.messager.confirm("操作提示", "您确定要保存审核结果吗？", function (data) {
		        if (data) {
		        	$(document).mask('正在保存审核结果，请稍等...');
		        	var param = $('#formForAudit').serialize();
		        	$.post('${ctx}/question/saveAudit',param,function(res){
		    			$(document).unmask();
		    			if(res.flag=='failed'){
		    	           $.messager.alert('提示', res.msg, 'error', function () {
		    	        	   //do nothing
		    	           });
		    	           return false;
		    			}else{
		    				$('#auditDiv').window('close');
		    				refreshTbl();
		    			}
		    		});
		        }
		    });
			return false;
		});
		
		$("#cancelAuditBtn").click(function(){
	    	$('#auditDiv').window('close');
			return false;
	    });
		
		$("#keyword").keyup(function(){
			$('#queryBtn').click();
	    });

		{//加载SwfUpload上传组件
			loadQuesSwfUpload();
		}
		
		$("#impBtn").click(function(){
			$("#uploadedQuesAttId").val("");
			$("#impLogDiv").html("");
			$("#confirmUploadedQues").attr("disabled",true);
			$("#impQuesDiv").window('open'); 
		});
		
		$("#cancelUploadedQues").click(function(){
	    	$('#impQuesDiv').window('close');
			return false;
	    });
	});
	
	function toDelQues(quesId){
		$.messager.confirm("操作提示", "您确定要删除此题吗？（如果此题已被试卷使用，则不能被删除）", function (data) {
	        if (data) {
	        	$(document).mask('正在删除试题，请稍等...');
	        	$.post('${ctx}/question/delQues',{'quesId':quesId},function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				refreshTbl();
	    			}
	    		});
	        }
	    });
	}
	
	function toEditQues(courseId,quesId){
		var ques = {courseId:courseId,quesId:quesId};
		showQuesEditWin(ques);
	}

	function showQuesEditWin(ques){
		var paramStr = JSON.stringify(ques);
		var src = "${ctx}/question/questionForEdit?courseId=" + ques.courseId + "&fun=initEditQuesParam&paramStr=" + encodeURIComponent(paramStr);
		$("#quesEditDiv").window({top:$(document).scrollTop() + 20,
			left:$(document).scrollLeft() + 20,
			height:$(document).height()-40,
			width:$(document).width()-40,
			onResize:function(){
				var winBody = $("#quesEditDiv").window("body");
				$("#quesEditFrame").css({width:winBody.width(),
					height:winBody.height()
				});
			}
		});
		var winBody = $("#quesEditDiv").window("body");
		$("#quesEditFrame").css({width:winBody.width(),
			height:winBody.height()
		});
		$("#quesEditFrame").attr("src", src);
		$(document).mask('正在加载试题，请稍等...');
		window.setTimeout(function(){
			$(document).unmask();
			$("#quesEditDiv").window('open');
		},300);
	}

	function closeEditQuestionDiv(){
		$("#quesEditDiv").window('close');
	}
	</security:authorize>
	
	function loadQuesSwfUpload() {
		new SWFUpload({
			 upload_url :"${ctx}/attachment/upload",
			 post_params: {"userId":"${sessionScope.web_session_user.id}"},
			 use_query_string : false,
			  
			// File Upload Settings
			file_size_limit : "50 MB",	// 50MB
			
			file_types : "*.docx",
			file_types_description : "Word文档",
			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 : uploadQuesSuccess,
			upload_complete_handler : uploadComplete,
			
			// Button Settings
			button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
			button_placeholder_id : "spanQuesButtonPlaceholder",
			button_width: 180,
			button_height: 18,
			button_text : '<span class="button">点击这里上传试题Word<span class="buttonSmall"></span></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,
			button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
			
			
			// Flash Settings
			flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

			custom_settings : {
				upload_target : "importDivFileProgressContainer"
			},
			// Debug Settings
			debug: false //是否显示调试窗口
		});
	};

	function uploadQuesSuccess(file, serverData) {
		$(document).unmask();
		serverData=eval('(' + serverData + ')');
		if(serverData.flag=='success'){
			$("#uploadedQuesAttId").val(serverData.att.id);
			$("#impLogDiv").html("");
			$("#impLogDiv").append("<div>已上传文件：" + serverData.att.originalName + "</div>");
			$("#impLogDiv").append("<div>正在解析上传的文件...</div>");
			$(document).mask('正在解析，请稍等...');
			var param = {
					"attId":serverData.att.id
			};
			$.post('${ctx}/question/impQues',param,function(res){
				$(document).unmask();
				if(res.flag=='failed'){
		           $.messager.alert('提示', res.msg, 'error', function () {
		        	   //do nothing
		           });
		           return false;
				}else{
					for(var i in res.logs){
						$("#impLogDiv").append("<div>" + res.logs[i] + "</div>");
					}
					$('#impLogDiv').scrollTop($('#impLogDiv')[0].scrollHeight);
					if($('#impLogDiv').text().indexOf("成功导入")>=0){
						refreshTbl();
					}
				}
			});
		}else{
			$.messager.alert('提示',serverData.msg,'error');
		}
	}
	
	function checkSimilarity(){
    	$(document).mask('正在计算中，请稍等...');
    	$.ajax({
    		type : "POST",
    		url : "${ctx}/question/checkSimilarity",
    		data : {},
    		success : function(res) {
    			$(document).unmask();
    			$('#similarQuesListDg').datagrid({data:res.allSimilarQuestion});
    			$("#similarQuesListDiv").window({top:$(document).scrollTop() + 100});
				$('#similarQuesListDiv').window('open');
    		}
    	});
    }
</script>
</head>

<body onload="load()">
<%@ include file="../common/header.jsp"%>
<div>	
	<%@ include file="../common/sub_menu.jsp"%>
	<div id="page" style="margin-left: 0px;">
		<div class="page-header">试题管理-试题列表</div>
		<div class="page-body" >
			    <table class="caption">
			        <tbody>
			        <tr>
			            <td class="title">状态：</td>
			            <td>
			                <select id="status" name="statusCode">
			                    <option value="">全部</option>
			                    <c:forEach items="${status }" var="status">
			                    	<option value="${status.itemType}">${status.itemCode }</option>
			                    </c:forEach>
			                </select>
			            </td>
			            <td class="title">课程：</td>
			            <td style="width: 250px;">
			                <select id="course" name="courseId" onchange="courseChange('${ctx}')" style="width: 200px;">
			                    <option value="">全部课程</option>
			                    <c:forEach items="${courses }" var="c">
			                    <option value="${c.id }">${c.code}-${c.name }</option>
			                    </c:forEach>
			                </select>
			            </td>
			            <td class="title" >题型：</td>
			            <td>
			                <select id="typeId" name="typeId" onchange="questionChange('${ctx }')">
			                    <option value="">全部题型</option>
			                </select>
			            </td>
			            <td class="title">教材：</td>
			            <td>
			                <select id="bookId" name="bookId">
			                    <option value="0">全部教材</option>
			                </select>
			            </td>
			        </tr>
			        <tr>
			            <td class="title">知识点：</td>
			            <td>
			                <input placeholder="章" class="short" id="chapter" name="chapter" />
			                <input placeholder="节" class="short"  id="section" name="section"/>
			                <input placeholder="目" class="short" id="item" name="item"/>
			                <input placeholder="页" class="short" id="ye" name="page"/>
			            </td>
			            <td class="title">能力要求：</td>
			            <td>
			                <select id="abilityCode" name="abilityCode" style="width: 200px;">
			                	<option value="">请选择</option>
			                    <c:forEach items="${codes }" var="code">
			                    	<c:if test="${ code.itemType=='ABILITY'}">
			                    		<option value="${code.itemCode}">${code.itemValue }</option>
			                    	</c:if>
			                    </c:forEach>
			                </select>
			            </td>
			            <td class="title">预计难度：</td>
			            <td>
			                <select id="estimateDifficultyCode" name="estimateDifficultyCode">
			                    <option value="">请选择</option>
			                    <c:forEach items="${codes }" var="code">
			                    	<c:if test="${ code.itemType=='QUESTION_DIFFICULTY'}">
			                    		<option value="${code.itemCode}" id="${code.itemCode}">${code.itemValue }</option>
			                    	</c:if>
			                    </c:forEach>
			                </select>
			            </td>
			            <td class="title">考核要求：</td>
			            <td>
			                <select id="assessmentDemand" name="assessmentDemand">
			                	<option value="">请选择</option>
			                    <c:forEach items="${codes }" var="code">
			                    	<c:if test="${ code.itemType=='ASSESSMENT_DEMAND'}">
			                    		<option value="${code.itemCode}" id="${code.itemCode}">${code.itemValue }</option>
			                    	</c:if>
			                    </c:forEach>
			                </select>
			            </td>
			        </tr>
			        <tr>
			            <td class="title">关键字：</td>
			            <td colspan="2" style="border-right-style: hidden;" >
			            <input type="hidden"/>
			                <input placeholder="题号或关键字查询" style="width: 90%;" id="keyword"/>
			            </td>
			            <td colspan="5">
			            	<input type="submit" class="bigBtn myMargin3" id="queryBtn" value="查询" onclick="search('${ctx}','1')"/>
			            	<input type="submit" class="bigBtn myMargin3" id="impBtn" value="导入"/>
			            	<!-- <input type="button" style="width: 100px;" class="bigBtn" id="similarBtn" value="检查题目相似度" onclick="checkSimilarity()"/> -->
			            </td>
			        </tr>
			        </tbody>
			    </table>
		    <div class="row" id="row">
		    	
		    </div>
		    <table class="info questionList" style="font-size:13px;">
		        <tbody>
		        </tbody>
		    </table>
			<div class="pages"></div>
		</div>
	</div>	
</div>
<div style="display: none;">
	<div id="logListDiv" title="试题操作日志列表" class="easyui-window" data-options="modal:true,closed:true,maximizable:false,minimizable:false,resizable:true,iconCls:'icon-import'" style="width:600px;height:340px;padding:5px;overflow-x: hidden;">
		<div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
			<div id="showLogsDiv">
					
			</div>
		</div>
	</div>
	
	<div id="auditDiv" title="审核试题" class="easyui-window" data-options="modal:true,closed:true,maximizable:false,minimizable:false,resizable:false,iconCls:'icon-import'" style="width:420px;height:250px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
        	<form action="#" id="formForAudit">
				<input type="hidden" name="quesId" id="quesIdForAudit" value=""/>
				<table cellpadding="5">
					<tr>
						<td nowrap="nowrap">审核结果</td>
						<td>
							<input type="radio" name="auditResult" id="approved" value="QUESTION_APPROVED" checked="checked"/><label for="approved" class="myMargin3">通过</label>
							<input type="radio" name="auditResult" id="rejected" value="QUESTION_REJECTED"/><label for="rejected">拒绝</label>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">审核意见</td>
						<td><textarea rows="5" cols="50" style="width: 320px;" name="remark" id="auditRemark"></textarea><span id="count"></span></td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<button class="btn" id="saveAuditBtn">确定</button>
							<button class="btn" id="cancelAuditBtn">取消</button>
						</td>
					</tr>
				</table>
            </form>
        </div>
    </div>
	
	<div id="quesAddDiv" class="easyui-window" title="新建试题" data-options="modal:true,closed:true,iconCls:'icon-import',minimizable:false" style="width:400px;height:190px;padding:0px;overflow: hidden;margin: 0px;">
		<iframe frameborder="0" name="quesAddFrame" id="quesAddFrame" style="width:1010px;height:570px;" scrolling="auto" src="">
		</iframe>
	</div>
		
	<div id="quesEditDiv" class="easyui-window" title="编辑试题" data-options="modal:true,closed:true,iconCls:'icon-import',minimizable:false" style="width:400px;height:190px;padding:0px;overflow: hidden;margin: 0px;">
		<iframe frameborder="0" name="quesEditFrame" id="quesEditFrame" style="width:1010px;height:570px;" scrolling="auto" src="">
		</iframe>
	</div>
	
	<div id="impQuesDiv" title="上传试题Word" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import',minimizable:false" style="width:516px;height:310px;padding:10px;overflow: hidden;">
		<div><span id="spanQuesButtonPlaceholder"></span></div>
		<input type="hidden" id="uploadedQuesAttId"/>
		<div id="impLogDiv" class="impLog"></div>
		<table cellpadding="5" width="100%">
			<tr>
				<td align="center">
					<button class="btn" id="cancelUploadedQues">关闭</button>
				</td>
			</tr>
		</table>
	</div>
	
	<div id="similarQuesListDiv" title="相似题详情" class="easyui-window" data-options="modal:true,closed:true,minimizable:true,maximizable:true,resizable:true,iconCls:'icon-import'" style="width:560px;height:400px;padding:5px;overflow-x: hidden;">
		<table id="similarQuesListDg" class="easyui-datagrid"
	        data-options="fitColumns:true,singleSelect:true,striped:true,pagination:false,remoteSort:false">
	           <thead>
	             <tr class="title">
	               <th data-options="sortable:true,field:'similarQuestionNo',width:60">题目</th>
	               <th data-options="sortable:true,field:'similarity',width:30">相似度</th>
	             </tr>
	         </thead>
		</table>
	</div>
</div>
</body>
</html>