<%@ 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>
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -->
<html>
<head>
<title>试题编辑</title>
<%@ include file="../common/top.jsp"%>
<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' />
<link rel="stylesheet" href="${ctx}/resources/css/app/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="${ctx}/resources/css/style.css" type="text/css" />
<link rel="stylesheet" href="${ctx}/resources/css/alertify.core.css" type="text/css" media='screen' />
<link rel="stylesheet" href="${ctx}/resources/css/alertify.default.css" type="text/css" media='screen' />

<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/ckeditor4.5.9/ckeditor.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/lib/bootstrap.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/alertify.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/bootstrap-waitingfor.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/question/quesForEdit.js"></script>
<script type="text/javascript" src="${ctx}/jsp/question/mng.jsp"></script>
<style>
.table{width: 100%}
.table-bordered{border-collapse:collapse;border:none;}
.table-bordered th{border:solid #c9c9c9 1px;padding:2px 2px 2px 2px;}
.table-bordered td{border:solid #c9c9c9 1px;padding:2px 2px 2px 2px;}

.searchTbl th{padding:2px 5px 2px 10px;height: 30px;vertical-align: middle;}
.searchTbl td{padding:2px 5px 2px 10px;height: 30px;vertical-align: middle;}
select {
	margin: 0px;
}
input[type="text"] {
	margin: 0px;
}
i {font-style:italic;}
em {font-style:italic;}
.myMargin1{
	margin-left: 25px;
}
</style>
<script type="text/javascript">
var restQuesDetailsMap = {};
var bookEnableDateMap = {};
var saveType = null;

<c:forEach items="${books}" var="book">
<c:if test="${book.enableDate != null}">
bookEnableDateMap[${book.id}] = ${book.enableDate.time};
</c:if>
</c:forEach>

$(document).ready(function(){
	<security:authorize ifAnyGranted="processManagement">
	$("#questionNo").attr("readonly",false);
	</security:authorize>
	//$(document).mask('正在加载数据，请稍等...');
	setTimeout(function(){
		${param.fun}(${param.paramStr});
		$("#answer-tr").css("visibility","visible");
		//$(document).unmask();
	},500);
});

function initAddQuesParam(param){
	restQuesDetailsMap = {};
	saveType = "ADD";
	$("#paperId").val(param.paperId);
	$("#score").val(param.score);
	$("#courseId").val(param.courseId);
	$("#bookId").val(param.bookId);
	$("#chapterSize").val(param.chapterSize);
	questionChange();
}

function initEditQuesParam(param){
	restQuesDetailsMap = {};
	saveType = "EDIT";
	$("#tipDiv").hide();
	$("#paperId").val(param.paperId);
	$("#quesId").val(param.quesId);
	$("#chapterSize").val(param.chapterSize);
	//$(document).mask('正在加载试题，请稍等...');
	$.post('${ctx}/question/quesDetail/' + param.quesId,{},function(res){
		//$(document).unmask();
		if(res.flag=='failed'){
           alertify.alert(res.msgs);
           return false;
		}else{
			var quesTypeName = res.questionType.name;
			$("#quesTypeId").val(res.questionType.id);
			$("#score").val(res.question.score);
			$("#questionNo").val(res.question.questionNo);
			$("#scoreForShow").text(res.question.score - 0);
			$("#courseId").val(res.question.courseId);
			$("#bookId").val(res.question.bookId);
			if(res.question.enableTime){
				var enableTime = new Date(res.question.enableTime);
				var enableTimeYear = enableTime.getFullYear();
				var enableTimeMonth = enableTime.getMonth()+1;
				$('#enableTimeYear').val(enableTimeYear);
				$('#enableTimeMonth').val(enableTimeMonth);
			}
			$('#enableTime').datebox('setValue', formatDate(res.question.enableTime));
			$('#setTime').datebox('setValue', formatDate(res.question.setTime));
			var assessmentDemand = !res.question.assessmentDemand ? '' : res.question.assessmentDemand;
			$('input[name="assessmentDemand"][value="' + assessmentDemand + '"]').attr("checked",true);
			var estimateDifficultyCode = !res.question.estimateDifficultyCode ? '10' : res.question.estimateDifficultyCode;
			$('input[name="estimateDifficultyCode"][value="' + estimateDifficultyCode + '"]').attr("checked",true);
			var abilityCode = !res.question.abilityCode ? 'A' : res.question.abilityCode;
			$('input[name="abilityCode"][value="' + abilityCode + '"]').attr("checked",true);
			$("#chapter").val(res.question.chapter);
			$("#section").val(res.question.section);
			$("#item").val(res.question.item);
			$("#page").val(res.question.page);
			$("#body-content").html(res.question.bodyHtml);
			questionChange();
			if(quesTypeName=="单项选择题" || quesTypeName=="单选题" || quesTypeName=="单选"){
				for(var i=0;i<4;i++){
					var opt = null;
					if(res.options && res.options.length > i){
						opt = res.options[i];
					}else{
						opt = {isCorrectOption:'0',content:''};
					}
					if(opt.isCorrectOption == '1'){
						$("input[name=optionsRadios]").eq(i).attr("checked",true);
					}
					var str=(String.fromCharCode(i+65));
					$("#"+str+"_radio_input").html(opt.contentHtml);
				}
			}else if(quesTypeName=="多项选择题" || quesTypeName=="多选题" || quesTypeName=="多选"){
				for(var i=0;i<5;i++){
					var opt = null;
					if(res.options && res.options.length > i){
						opt = res.options[i];
					}else{
						opt = {isCorrectOption:'0',content:''};
					}
					$("input[name=optionsCKs]").eq(i).attr("checked",opt.isCorrectOption == '1');
					var str=(String.fromCharCode(i+65));
					$("#"+str+"_checkbox_input").html(opt.contentHtml);
				}
			}else{
				$("#answer-content").html(res.question.answerHtml);
			}
			if(res.isUsedByPaper){
				$("#infoDiv").show();
				$("#saveBtn").attr("disabled",true);
			}
			
			$("#setTeacherName").html("");
			for(var i=0;i<res.setTeachers.length;i++){
				var teacher = res.setTeachers[i];
				$("<option value='" + teacher.name + "'>" + teacher.name + "</option>").appendTo($("#setTeacherName"));
			}
			$("#setTeacherName").val(res.question.setTeacherName);
			
		}
	});
	$("#auditBtn").show();
	$("#logBtn").show();
}

function audit(){
	
	parent.audit($("#quesId").val());
	console(11111);
	//audit($("#quesId").val());
}

function getAuditLogs(){
	parent.getAuditLogs($("#quesId").val());
	//getAuditLogs($("#quesId").val());
}

function closeWin(){
	try{
		parent.closeAddQuestionDiv();
	}catch(e){
		//do nothing
		window.close();
	}
	try{
		parent.closeEditQuestionDiv();
	}catch(e){
		//do nothing
		window.close();
	}
}
</script>
</head>
<body style="overflow: auto;">
<form id="questionUpdateFrm" action="${ctx}/question/insert" method="post">
<input type="hidden" id="paperId" />
<input type="hidden" id="detailId" />
<input type="hidden" id="quesId" value="0"/>
<input type="hidden" id="pqtId"/>
<input type="hidden" id="courseId"/>
<input type="hidden" id="chapterSize"/>
<div class="page-bodyList">
			    <table class="table table-bordered searchTbl">
					<tr>
						<th nowrap="nowrap" style="width: 65px;">题型<span style="color:red">*</span></th>
						<td>
							<select name="quesTypeId" id="quesTypeId" style="width: 270px;" onchange="questionChange()">
<c:forEach items="${questionTypes}" var="quesType">
<option value="${quesType.id}">${quesType.name}</option>
</c:forEach>
							</select>
						</td>
					
						<th>考核要求</th>
						<td>
						    <input  type="radio" name="assessmentDemand" value="" checked id="assessmentDemand"/><label for="assessmentDemand">无&nbsp;</label>
						    <input  type="radio" name="assessmentDemand" value="A" id="assessmentDemandA"/><label for="assessmentDemandA">1.重点内容 </label>  
                            <input  type="radio" name="assessmentDemand" value="B" id="assessmentDemandB"/><label for="assessmentDemandB">2.次重要内容</label> 
                            <input  type="radio" name="assessmentDemand" value="C" id="assessmentDemandC"/><label for="assessmentDemandC">3.一般内容</label> 
						</td>
						<th>预计难度</th>
						<td>
						    <input  type="radio" name="estimateDifficultyCode" id="estimateDifficultyCode10" value="10"/><label for="estimateDifficultyCode10">A易　　</label>
                            <input  type="radio" name="estimateDifficultyCode" id="estimateDifficultyCode20" value="20"/><label for="estimateDifficultyCode20">B中等偏易　</label>
                            <input  type="radio" name="estimateDifficultyCode" id="estimateDifficultyCode30" value="30"/><label for="estimateDifficultyCode30">C中等偏难　</label>
                            <input  type="radio" name="estimateDifficultyCode" id="estimateDifficultyCode40" value="40"/><label for="estimateDifficultyCode40">D难　　</label>
						</td>
					</tr>
					<tr>
						 <th nowrap="nowrap">教材</th>
	                     <td>
							<select name="bookId" id="bookId" style="width: 270px;">
<c:forEach items="${books}" var="book">
<option value="${book.id}">${book.name}</option>
</c:forEach>
							</select>
						</td>
	                     <th>知识点</th>
	                     <td>
	                            <input type="text" id="chapter" name="chapter" style="width:20px;" maxlength="2"/>&nbsp;章<span style="color:red">*</span>
                                <input type="text" id="section" name="section" style="width:20px;" maxlength="3"/>&nbsp;节
                                <input type="text" id="item" name="item" style="width:20px;" maxlength="4"/>&nbsp;目
                                <input type="text" id="page" name="page" style="width:20px;margin: 0px;" maxlength="5"/>&nbsp;页
                        </td>
						<th>能力要求</th>
						<td>
						    <div>
                                <input  type="radio" name="abilityCode" id="abilityCodeA" value="A"/><label for="abilityCodeA">A识记　</label>
                                <input  type="radio" name="abilityCode" id="abilityCodeB" value="B"/><label for="abilityCodeB">B理解　　　</label>
                                <input  type="radio" name="abilityCode" id="abilityCodeC" value="C"/><label for="abilityCodeC">C简单应用　</label>
                                <input  type="radio" name="abilityCode" id="abilityCodeD" value="D"/><label for="abilityCodeD">D综合应用　</label>
                            </div>
						</td>
					</tr>
					<tr>
						<th>满分值<span style="color:red">*</span></th>
						<td>
							<input type="text" id="score" style="width: 50px;"/>
							<span style="margin-left: 10px;">启用时间</span>
							<span><input type="text" name="enableTimeYear" id="enableTimeYear" maxlength="4" style="width: 60px;"/>年-<select name="enableTimeMonth" id="enableTimeMonth" style="width: 50px;">
      	<option value=""></option>
      	<option value="1">1</option>
      	<option value="4">4</option>
      	<option value="7">7</option>
      	<option value="10">10</option>
      </select>月
							<span style="display: none;"><input type="text" name="enableTime" id="enableTime" class="easyui-datebox" placeholder="yyyy-mm-dd" style="width: 120px;" maxlength="10"/></span></span>
						</td>
						<th>命题时间<span style="color:red">*</span></th>
						<td>
						<span><input type="text" name="setTime" id="setTime" class="easyui-datebox" placeholder="yyyy-mm-dd" style="width: 120px;" maxlength="10"/></span>
						<span class="myMargin1">命题教师</span><span style="color:red">*</span>
						<select name="setTeacherName" id="setTeacherName" style="width: 120px;">
<c:forEach items="${setTeachers}" var="teacher">
<option value="${teacher.name}">${teacher.name}</option>
</c:forEach>
						</select></td>
						<th>题号<span style="color:red">*</span></th>
						<td><input type="text" id="questionNo" name="questionNo" style="width:270px;" readonly="readonly"/></td>
					</tr>
                    <tr>
							<th>题干<span style="color:red">*</span></th>
							<td colspan="5" style="margin: 0px;padding: 0px;">								
								<div id="body-content" class="box-content " field="body" name="题干" title="点击输入内容" contenteditable="true" style="height:100px;width:95%;max-width: 95%;">
								</div>
							</td>
				   </tr>
				   <tr id="answer-tr" style="visibility: hidden;">
							<th><span id="answer_td">答案</span><span style="color:red">*</span></th>
							<td colspan="5" style="margin: 0px;padding: 0px;">
								<div id="answer-content" class="box-content " field="answer" name="选项及答案" title="点击输入内容" contenteditable="true" style="height:120px;width:95%;max-width: 95%;"></div>
								<div class="container" id="container" style="width:95%;margin: 0px;padding: 0px;">
									<div id="Choose">
										<div>
											 <div class="RadioContent">
												<table style="width:100%">
													<tr>
														<td style="width:30px;"><input	type="radio" name="optionsRadios" value="A" class="validate[required] radio"/>A.</td>
														<td><div class="col-lg-5 col-sm-5" id="A_radio_input" contenteditable="true" style="height:25px;"></div></td>
													</tr>
													<tr>
														<td style="width:30px;"><input	type="radio" name="optionsRadios" value="B" class="validate[required] radio"/>B.</td>
														<td><div class="col-lg-5 col-sm-5" id="B_radio_input" contenteditable="true" style="height:25px;"></div></td>
													</tr>
													<tr>
														<td style="width:30px;"><input	type="radio" name="optionsRadios" value="C" class="validate[required] radio"/>C.</td>
														<td><div class="col-lg-5 col-sm-5" id="C_radio_input" contenteditable="true" style="height:25px;"></div></td>
													</tr>
													<tr>
														<td style="width:30px;"><input	type="radio" name="optionsRadios" value="D" class="validate[required] radio"/>D.</td>
														<td><div class="col-lg-5 col-sm-5" id="D_radio_input" contenteditable="true" style="height:25px;"></div></td>
													</tr>														
												</table>
											</div>
										</div>
										<div class="CheckboxContent">
											<table style="width:100%">
												<tr>
													<td style="width:30px;"><input type="checkbox" name="optionsCKs" value="A" class="validate[required] checkbox "/>A.</td>
													<td><div class="col-lg-5 col-sm-5" id="A_checkbox_input" contenteditable="true" style="height:25px;"></div></td>
												</tr>
												<tr>
													<td style="width:30px;"><input type="checkbox" name="optionsCKs" value="B" class="validate[required] checkbox "/>B.</td>
													<td><div class="col-lg-5 col-sm-5" id="B_checkbox_input" contenteditable="true" style="height:25px;"></div></td>
												</tr>
												<tr>
													<td style="width:30px;"><input type="checkbox" name="optionsCKs" value="C" class="validate[required] checkbox "/>C.</td>
													<td><div class="col-lg-5 col-sm-5" id="C_checkbox_input" contenteditable="true" style="height:25px;"></div></td>
												</tr>
												<tr>
													<td style="width:30px;"><input type="checkbox" name="optionsCKs" value="D" class="validate[required] checkbox "/>D.</td>
													<td><div class="col-lg-5 col-sm-5" id="D_checkbox_input" contenteditable="true" style="height:25px;"></div></td>
												</tr>
												<tr>
													<td style="width:30px;"><input type="checkbox" name="optionsCKs" value="E" class="validate[required] checkbox "/>E.</td>
													<td><div class="col-lg-5 col-sm-5" id="E_checkbox_input" contenteditable="true" style="height:25px;"></div></td>
												</tr>
											</table>											
										</div>
									</div>
								</div>
							</td>
						</tr>
			    </table>
			    <div id="infoDiv" style="display: none;color: red">*当前试题已经被试卷引用了，不能修改</div>
			    <div style="text-align:center;">
				    <input type="button" id="saveBtn" style="margin-top: 10px;width: 60px;height: 25px;" class="btn btn-small btn-primary" onclick="goSave('${ctx }')" value="保存" />
				    <security:authorize ifAnyGranted="quesAuditor,processManagement">
				    <input type="button" id="auditBtn" style="margin-top: 10px;width: 60px;height: 25px;display: none;" class="btn btn-small btn-primary myMargin1" onclick="audit()" value="审核" />
				    </security:authorize>
				    <input type="button" id="logBtn" style="margin-top: 10px;width: 60px;height: 25px;display: none;" class="btn btn-small btn-primary myMargin1" onclick="getAuditLogs()" value="日志" />
				    <input type="button" style="margin-top: 10px;width: 60px;height: 25px;" class="btn btn-small btn-primary myMargin1" onclick="closeWin()" value="关闭" />
			    </div>
</div>
</form>
</body>
</html>
