<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ 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>
<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' />
<style>
.myButton1{
	width: 52px;height: 26px;margin: 0px;
}
.myButton2{
	width: 59px;height: 26px;margin: 0px;
}
.myButton3{
	width: 79px;height: 26px;margin: 0px;
}
.myMargin1{
	margin-right: 8px;
}
.myMargin2{
	margin-right: 15px;
}
.myMargin3{
	margin-right: 25px;
}
.myMargin4{
	margin-left: 3px;
}

.optTable{
	padding: 0px;
}

.optTable td{
	padding-left: 0px;
	padding-right: 0px;
	text-align:left;
	vertical-align: middle;
}

.myWidth1{
	width: 18px;
}

.myWidth2{
	width: 200px;
}

.normalBorder{
	border-style: solid;
	border-width: 2px;
	border-color: #FFFFFF;
}

.curBorder{
	border-style: ridge;
	border-width: 2px;
	border-color: #FF0000;
}

.btnDiv{
	margin-top: 5px;
	margin-left: 10px;
}

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

.myTd1{
	width: 35px;
	text-align: left;
}

.myTd2{
	text-align: left;
}

.myTd3{border:solid windowtext 1pt;padding:0cm 5.4pt 0cm 5.4pt;text-align:center;font-weight:bold;}

.myTd4{border:solid windowtext 1pt;padding:0cm 5.4pt 0cm 5.4pt;}

.myTd5{border-style:none;padding:0cm 5.4pt 0cm 5.4pt;text-align:right;font-weight:bold;}

.myTd6{border-style:none;padding:0cm 5.4pt 0cm 5.4pt;text-align:left;}

p{white-space:sWrap;word-wrap:break-word;}

span{white-space:sWrap;word-wrap:break-word;}

.statTbl{
	border-collapse:collapse;border:none;width: 600px;margin-bottom: 10px;
}
.statTbl th{border:solid black 1px;padding:2px 2px 2px 2px;text-align: center;}
.statTbl td{border:solid black 1px;padding:2px 2px 2px 8px;}
</style>
<%@ include file="../common/top.jsp"%>
<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/js/validator.js"></script>
<%@ include file="../common/validation.jsp"%>
<title>智能组卷</title>

<script language="javascript">
var quesMap = {};//试题Map，用于缓存试题统计信息

$(document).ready(function(){
    $('#goBackBtn').click(function(){
    	window.history.go(-1);
    	return false;
    	//$('#autoGeneratedPapers').show();
    	//$('#generateForm').hide();
    	//selectTab();
    });
    
    $('#searchQuesBtn').click(function(){
        var param = {'keyword':$('#keywordForSearchQues').val(),'pcqtId':$('#pcqtIdForSearchQues').val()};
        param = $.extend(param, {page:1,rows:10});
        $('#availableQuesDg').datagrid('load',param);
        return false;
    });
    
    $("#availableQuesDg").datagrid({
    	onClickRow: function (rowIndex, rowData) {
    		$('#confirmQuesBtn').attr("disabled",false);
        },
        onDblClickRow: function (rowIndex, rowData) {
        	$('#confirmQuesBtn').click();
        }
    });
    
    $('#confirmQuesBtn').click(function(){
    	var selectedRow = $("#availableQuesDg").datagrid('getSelected');
    	if(selectedRow == null){
    		$.messager.alert('提示', "请选中一行后确定！", 'error');
    	}else{
    		curQues = selectedRow;
    		$.messager.confirm("操作提示", "您确定要换题吗？", function (data) {
                if (data) {
                	var hasRepeated = false;
            		$('[suoshuQt="' + curPcqtId + '"]').each(function(){
            			var detailId = $(this).attr('detailId');
            			var quesId = $(this).attr('quesId');
            			if(detailId != curDetailId && quesId == curQues.id){
            				hasRepeated = true;
            				$.messager.alert('提示', "该题已存在，请重新选择！", 'error');
            				return;
            			}
            		});
            		if(!hasRepeated){
            			changeQues(curDetailId,curQues);
            			$('#quesListDiv').window('close');
            		}
                }
            });
    	}
        return false;
    });
    
    $("[divType='quesDiv']").each(function(index,element){
    	$(this).mouseover(function(){
    		if(this.className != "curBorder"){
            	this.className = "curBorder";
    		}
        });
        $(this).mouseout(function(){
        	if(this.className != "normalBorder"){
            	this.className = "normalBorder";
        	}
        });
        var isLasts = index >= $("[divType='quesDiv']").length - 2;
        $(this).tooltip({
        	position: (isLasts ? 'top' : 'right'),
        	//content: '<span style="color:#fff">This is the tooltip message.</span>',
        	//hideEvent:null,
        	deltaX:(isLasts ? 0 : -8),
        	deltaY:(isLasts ? 8 : 0),
        	onShow: function(){
        		//quesId
        		var questionDiv = $(this);
        		var questionId = $(this).attr('quesId');
        		var paperId = $(this).parent().attr('suoshuSjForStat');
        		var quesKey = questionId + '|' + paperId;
        		var content = quesMap[quesKey];
        		if(content != null && content != ''){
        			questionDiv.tooltip('update',content);
            		questionDiv.tooltip('tip').css({
            			backgroundColor: '#EEE',
		        		borderColor: '#333',
		        		visibility: 'visible'
            		});
            		return;
        		}
        		var param = {'questionId':questionId,'paperId':paperId};
        		questionDiv.tooltip('update','正在统计中...');
        		questionDiv.tooltip('tip').css({
        			visibility: 'hidden',
        			backgroundColor: '#EEE',
        			borderColor: '#333'
        		});
        		$.ajax({
        			type : "POST",
        			global: false,
        			url : "${ctx}/zujuan/questionStat",
        			data : param,
        			success : function(res) {
        				if(res.flag=='failed'){
     		        		var content = '<span style="color:red">' + res.msg + '</span>';
     		        		questionDiv.tooltip('update',content);
     		        		questionDiv.tooltip('tip').css({
     		        			backgroundColor: '#FFF',
     		        			borderColor: '#000',
     		        			visibility: 'visible'
     		        		});
             				questionDiv.tooltip('reposition');
             			}else{
             				var papersSize = res.statResult.papersSize - 0;
             				var content = null;
             				if(papersSize == 0){
             					content = '<div style="color:#000">此题没有被其它试卷使用。</div>';
             				}else{
             					content = '<div style="color:#000">此题已被其它<span style="font-weight:bold;">' + papersSize + '</span>个试卷使用：</div>';
             					content = content + '<table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;border:none;">';
             					content = content + '<tr><td class="myTd3" nowrap="nowrap">试卷名称</td><td class="myTd3" nowrap="nowrap">状态</td><td class="myTd3" nowrap="nowrap">创建人</td><td class="myTd3" nowrap="nowrap">创建时间</td></tr>'
             					var papers = res.statResult.papers;
             					for(var i=0;i<papersSize;i++){
             						var paper = papers[i];
             						content = content + '<tr><td class="myTd4">' + paper.name + '</td><td class="myTd4">' + paper.statusName + '</td><td class="myTd4">' + paper.createdByName + '</td><td class="myTd4">' + paper.createdTimeStr + '</td></tr>';
             					}
             					content = content + '</table>';
             				}
             				var qustion = res.statResult.qustion;
             				content = content + '<div style="color:#000;margin-top:8px;">此题其他信息:</div>';
             				content = content + '<table cellpadding="0" cellspacing="0" border="0" style="border:none;">';
             				content = content + '<tr><td class="myTd5" nowrap="nowrap">知识点：</td><td class="myTd6">' + trimStr(qustion.chapter,'-') + "章" + trimStr(qustion.section,'-') + "节" + trimStr(qustion.item,'-') + "目" + trimStr(qustion.page,'-')+"页" + '</td></tr>';
             				content = content + '<tr><td class="myTd5" nowrap="nowrap">分值：</td><td class="myTd6">' + qustion.score + '</td></tr>';
             				content = content + '<tr><td class="myTd5" nowrap="nowrap">预计难度：</td><td class="myTd6">' + qustion.estimateDifficultyText + '</td></tr>';
             				content = content + '<tr><td class="myTd5" nowrap="nowrap">考核要求：</td><td class="myTd6">' + trimStr(qustion.assessmentDemandText,'--') + '</td></tr>';
             				//content = content + '<tr><td class="myTd5" nowrap="nowrap">层次：</td><td class="myTd6">' + qustion.gradeText + '</td></tr>';
             				content = content + '<tr><td class="myTd5" nowrap="nowrap">认知层次：</td><td class="myTd6">' + qustion.abilityText + '</td></tr>';
             				content = content + '</table>';
             				quesMap[quesKey] = content;
             				questionDiv.tooltip('update',content);
             				questionDiv.tooltip('tip').css({
     		        			backgroundColor: '#EEE',
     		        			borderColor: '#333',
     		        			visibility: 'visible'
     		        		});
             				questionDiv.tooltip('reposition');
             			}
        			}
        		});
        	}});
    });
    
    $(".panel-header.accordion-header").each(function(){
    	$(this).live('contextmenu',function(e){
    		var qtId = $(this).next().attr('qtId');
    		if(qtId != null && qtId != ''){
	    		curQtPanel = $(this).parent();
	    		//显示快捷菜单
	            $('#menu').menu('show', {
	                left: e.pageX,
	                top: e.pageY
	            });
    		}
            return false;
        });
    });
    
    $("#m-up").click(function(){
    	var selfDiv = curQtPanel;
    	var prevDiv = selfDiv.prev()
    	if(prevDiv.size() == 1){
    		selfDiv.insertBefore(prevDiv);
    		resetQuesSortNo(selfDiv);
    	}
    });
    
    $("#m-down").click(function(){
    	var selfDiv = curQtPanel;
    	var nextDiv = selfDiv.next()
    	if(nextDiv.size() == 1){
    		selfDiv.insertAfter(nextDiv);
    		resetQuesSortNo(selfDiv);
    	}
    });
    
    $("#cancelAuditBtn").click(function(){
    	$('#auditDiv').window('close');
    });
    
    $("#saveAuditBtn").click(function(){
    	$.messager.confirm("操作提示", "您确定要保存审核结果吗？", function (data) {
            if (data) {
            	$(document).mask('正在保存审核结果，请稍等...');
            	var param = $('#formForAudit').serialize();
            	$.post('${ctx}/zujuan/saveAudit',param,function(res){
        			$(document).unmask();
        			if(res.flag=='failed'){
        	           $.messager.alert('提示', res.msg, 'error', function () {
        	        	   //do nothing
        	           });
        	           return false;
        			}else{
        				reloadWin();
        			}
        		});
            }
        });
    });

    
    $("#auditRemark").keydown(function(){
    	calculate_byte(200,'auditRemark','count');
    });
    $("#auditRemark").keyup(function(){
    	calculate_byte(200,'auditRemark','count');
    });
    $("#auditRemark").keypress(function(){
    	calculate_byte(200,'auditRemark','count');
    });
    
    defaultTab();
    statQues();
});

function statQues(){
    $("[paperId]").each(function(index,element){
    	var sjId = $(this).attr("paperId");
    	var diffQuantityMap = {"10":0,"20":0,"30":0,"40":0};
    	var diffScoreMap = {"10":0,"20":0,"30":0,"40":0};
    	var abilityQuantityMap = {"A":0,"B":0,"C":0,"D":0};
    	var abilityScoreMap = {"A":0,"B":0,"C":0,"D":0};
    	var size = $(this).find("[detailForStat]").size();
    	var quesScoreArr = $(this).find("[quesScore]");
    	$(this).find("[detailForStat]").each(function(index,element){
        	var score = quesScoreArr.eq(index).attr("quesScore") - 0;
        	var detail = $(this).attr("detailForStat");
        	var arrTmp = detail.split('-');
        	var diff = arrTmp[0];
        	var ability = arrTmp[1];
        	diffQuantityMap[diff] = diffQuantityMap[diff] + 1;
        	diffScoreMap[diff] = (diffScoreMap[diff] - 0) + score;
        	abilityQuantityMap[ability] = abilityQuantityMap[ability] + 1;
        	abilityScoreMap[ability] = (abilityScoreMap[ability] - 0) + score;
        });
    	for(var tmp in diffQuantityMap){
    		var rate = ((new Number(diffQuantityMap[tmp] / size * 100)).toFixed(2) - 0) + "%";
    		$("#diff_quantity_" + tmp + "_" + sjId).html("<span style='float:left;width:30px;'>" + diffQuantityMap[tmp] + "</span>（" + rate + "）");
    	}

    	for(var tmp in diffScoreMap){
    		$("#diff_score_" + tmp + "_" + sjId).text(diffScoreMap[tmp]);
    	}

    	for(var tmp in abilityQuantityMap){
    		var rate = ((new Number(abilityQuantityMap[tmp] / size * 100)).toFixed(2) - 0) + "%";
    		$("#ability_quantity_" + tmp + "_" + sjId).html("<span style='float:left;width:30px'>" + abilityQuantityMap[tmp] + "</span>（" + rate + "）");
    	}

    	for(var tmp in abilityScoreMap){
    		$("#ability_score_" + tmp + "_" + sjId).text(abilityScoreMap[tmp]);
    	}
    });
}

function trimStr(str,defaultStr){
	if(str == null || str == ''){
		return defaultStr;
	}else{
		return str;
	}
}

	function defaultTab(){
		var sjIndex = getCookie('sjIndex');
		if(sjIndex != ''){
			var index = parseInt(sjIndex);
			$('#paperTabs').tabs('select',index);
		}
		setCookie('sjIndex','0');
	}

	var curPcqtId;
	var curDetailId;
	var curQues;
	var curQtPanel;
	
	function changeQues(detailId,quesInfo){
		$('[detailId="' + detailId + '"]').attr('quesId',quesInfo.id);
		
		var tbTmp = "<tr><td tdType='quesSortNo'></td><td><div detailForStat='" + quesInfo.estimateDifficultyCode + "-" + quesInfo.abilityCode + "' id='quesbody_" + detailId + "'/>";
		if(quesInfo.options && quesInfo.options.length > 0){
			tbTmp = tbTmp + "<table class='optTable'>";
			for(var i=0;i<quesInfo.options.length;i++){
				var opt = quesInfo.options[i];
				tbTmp = tbTmp + "<tr><td class='myWidth1'>" + opt.optionNoString + ".</td><td><span id='opt_" + detailId + "_" + opt.id + "'/></td></tr>";
			}
			tbTmp = tbTmp + "</table>"
		}
		tbTmp = tbTmp + "</td></tr>";
		var curQuTb = $('#ques_' + detailId);
		if(curQuTb.attr("backupData") == null || curQuTb.attr("backupData") == ""){
			curQuTb.attr("backupData",curQuTb.html());
		}
		curQuTb.html(tbTmp);
		$('#quesbody_' + detailId).html(quesInfo.bodyHtml);
		if(quesInfo.options && quesInfo.options.length > 0){
			for(var i=0;i<quesInfo.options.length;i++){
				var opt = quesInfo.options[i];
				$('#opt_' + detailId + '_' + opt.id).html(opt.contentHtml);
			}
		}
		$('#revBtn_' + detailId).css('visibility','visible');
		resetQuesSortNo(curQuTb);
		statQues();
	}
	
	function revertQues(tbId,pcId,pcqtId,detailId){
		$.messager.confirm("操作提示", "您确定要还原试题吗？", function (data) {
            if (data) {
            	var tb = $('#' + tbId);
				$('[detailId="' + detailId + '"]').attr('quesId',tb.attr("backupQuesId"));
				tb.html(tb.attr("backupData"));

				$('#revBtn_' + detailId).css('visibility','hidden');
				resetQuesSortNo(tb);
				statQues();
            }
        });
	}

    function selectTab(){
        var tabs = $('#paperTabs').tabs().tabs('tabs');
        for(var i=0; i<tabs.length; i++){
            tabs[i].panel('options').tab.unbind().bind('mouseenter',{index:i},function(e){
                $('#paperTabs').tabs('select', e.data.index);
            });
        }
    }
    
    function openChangeQuesWin(tbId,pcId,pcqtId,detailId){
    	curPcqtId = pcqtId;
    	curDetailId = detailId;
    	$('#keywordForSearchQues').val('');
    	$('#pcqtIdForSearchQues').val(pcqtId);
    	$('#detailIdForSearchQues').val(detailId);
    	$('#confirmQuesBtn').attr("disabled",true);
    	$('#quesListDiv').window('open');
    	$('#searchQuesBtn').click();
    }
    
    var randomArr = {};
    function randomQues(tbId,pcId,pcqtId,detailId){
    	$(document).mask('正在随机换题，请稍等...');
    	var quesIdList = [];
    	$('[suoshuQt="' + pcqtId + '"]').each(function(){
    		quesIdList[quesIdList.length] = $(this).attr('quesId');
    	});
    	var rndList = randomArr["" + pcqtId];
    	var rndListStr = '';
    	if(rndList != null && rndList.length > 0){
    		rndListStr = rndList.join(',');
    	}
    	var param = {
    			'pcqtId':pcqtId,
    			'detailId':detailId,
    			'curQuesIdListStr':quesIdList.join(','),
    			'rndListStr':rndListStr
    	};
    	$.post('${ctx}/zujuan/randomQues',param,function(res){
			$(document).unmask();
			if(res.flag=='failed'){
	           $.messager.alert('提示', res.msg, 'error', function () {
	        	   //do nothing
	           });
	           return false;
			}else{
				if(res.ques == null){
					$.messager.alert('提示', '对不起，没有可以换的题了!', 'warning' , function () {
			        	   //do nothing
			        });
			        return false;
				}
				var rndList = randomArr["" + pcqtId];
		    	if(rndList == null || rndList.length == 0){
		    		rndList = [];
		    		randomArr["" + pcqtId] = rndList;
		    	}
		    	rndList[rndList.length] = res.ques.id;
				changeQues(detailId,res.ques);
			}
		});
    }
    
    function goUp(btn){
    	var selfDiv = $(btn).parents("[divType='quesDiv']");
    	var prevDiv = selfDiv.prev()
    	if(prevDiv.size() == 1){
    		selfDiv.insertBefore(prevDiv);
    		resetQuesSortNo(selfDiv);
    	}
    }
    
    function goDown(btn){
    	var selfDiv = $(btn).parents("[divType='quesDiv']");
    	var nextDiv = selfDiv.next()
    	if(nextDiv.size() == 1){
    		selfDiv.insertAfter(nextDiv);
    		resetQuesSortNo(selfDiv);
    	}
    }
    
    function resetQuesSortNo(obj){
    	var quesIndex = 1;
    	var qtIndex = 1;
    	var sjDiv = obj.parents("[divType='sjDiv']");
    	sjDiv.find(".panel-header.accordion-header").find(".panel-title").each(function(){
    		var title = $(this).text();
    		var qtName = title.substring(title.indexOf("、"));
			$(this).text((qtIndex++) + qtName);
		});
    	sjDiv.find("[tdType='quesSortNo']").each(function(){
			$(this).text((quesIndex++) + ".");
		});
    }
    
    function saveSj(sjId){
    	$(document).mask('正在保存试卷，请稍等...');
    	var sjName = $('#sjName_' + sjId).val();
    	var sjHead = $('#sjHead_' + sjId).val();
    	var qtArrStr = '';
    	$("[suoshuSj='" + sjId + "']").each(function(){
    		var qtId = $(this).attr("qtId");
    		var detailArrStr = qtId + "@";
    		$("[suoshuQt='" + qtId + "']").each(function(){
    			var detailId = $(this).attr('detailId');
    			var quesId = $(this).attr('quesId');
    			detailArrStr = detailArrStr + detailId + ":" + quesId + "|";
    		});
    		qtArrStr = qtArrStr + detailArrStr + ";";
    	});
    	qtArrStr = qtArrStr.substring(0,qtArrStr.length - 1);
    	var param = {
    				'pcId':sjId,
	    			'pcName':sjName,
	    			'pcHead':sjHead,
	    			'qtArrStr':qtArrStr
    			};
    	$.post('${ctx}/zujuan/savePaper',param,function(res){
			$(document).unmask();
			if(res.flag=='failed'){
	           $.messager.alert('提示', res.msg, 'error', function () {
	        	   //do nothing
	           });
	           return false;
			}else{
				reloadWin();
			}
		});
    }
    
    function delSj(sjId){
    	$.messager.confirm("操作提示", "您确定要删除此试卷吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在删除，请稍等...');
	        	var param = {"paperId":sjId};
	        	$.post('${ctx}/zujuan/delete',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				var tabs = $('#paperTabs').tabs('tabs');
	    				if(tabs.length > 1){
	    					reloadWin();
	    				}else{
		    				window.history.go(-1);
	    				}
	    			}
	    		});
	        }
	    });
    }
    
    function submitAudit(sjId){
    	$.messager.confirm("操作提示", "您确定要提交审核吗？", function (data) {
            if (data) {
            	$(document).mask('正在提交审核，请稍等...');
            	var param = {"paperId":sjId};
            	$.post('${ctx}/zujuan/submitAudit',param,function(res){
        			$(document).unmask();
        			if(res.flag=='failed'){
        	           $.messager.alert('提示', res.msg, 'error', function () {
        	        	   //do nothing
        	           });
        	           return false;
        			}else{
        				reloadWin();
        			}
        		});
            }
        });	
    }
    
    function reloadWin(){
    	var tab = $('#paperTabs').tabs('getSelected');
    	var index = $('#paperTabs').tabs('getTabIndex',tab);
    	setCookie('sjIndex',index + '');
    	window.location.reload();
    }
    
    function audit(sjId){
    	$('#sjIdForAudit').val(sjId);
    	calculate_byte(200,'auditRemark','count');
    	$('#auditDiv').window('open');
    }
    
    function auditLog(sjId){
    	$(document).mask('正在查询审核日志，请稍等...');
    	var param = {"paperId":sjId};
    	$.post('${ctx}/zujuan/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 = '';
				for(var i=0;i<res.auditLogs.length;i++){
					htmlStr = htmlStr + '<div class="logDiv">';
					htmlStr = htmlStr + '<div><span class="myMargin1 myMargin4">操作时间:</span><span class="myMargin3">' + res.auditLogs[i].createdTimeStr + '</span><span class="myMargin1">操作类型:</span><span class="myMargin3">' + res.auditLogs[i].operCode + '</span><span class="myMargin1">操作人:</span><span>' + res.auditLogs[i].createdByName + '</span></div>';
					htmlStr = htmlStr + '<div><table width="100%"><tr><td class="myTd1" valign ="top" nowrap="nowrap">备注:</td><td class="myTd2"><div id="logRemark' + res.auditLogs[i].id + '"></div></td></tr></table></div>';
					htmlStr = htmlStr + '</div>';
				}
				$('#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 getCookie(c_name){
    	if (document.cookie.length>0){
    		c_start=document.cookie.indexOf(c_name + "=");
    		if (c_start!=-1){
    			c_start=c_start + c_name.length+1;
    			c_end=document.cookie.indexOf(";",c_start);
    			if(c_end==-1){c_end=document.cookie.length;}
    			return decodeURIComponent(document.cookie.substring(c_start,c_end));
    		}
    	}
    	return "";
    }

    function setCookie(c_name,value,expiredays){
    	var exdate = new Date();
    	exdate.setDate(exdate.getDate() + expiredays);
    	document.cookie = c_name+ "=" + encodeURIComponent(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    }
    
    function createWord(paperId,paperName){
    	$(document).mask('正在生成试卷，请稍等...');
    	$.ajax({
    		type : "POST",
    		url : "${ctx}/zujuan/previewPaper/" + paperId,
    		data : {}, 
    		success : function(paper) {
    			$(document).unmask();
    			if(paper.paperId){
    				$('#paperId').val(paper.paperId);
    				$('#paperName').val(paper.paperName);
    				$('#downloadForm').submit();
    			}else{
    				$.messager.alert('提示', "生成试卷失败，请刷新后操作!", 'error');
    			}
    		}
    	});
    }
</script>
</head>
<body style="overflow: hidden;">
    <%@ include file="../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../common/sub_menu.jsp"%>
        <div class="page" id="page" >
	        <div class="page-header" >试卷详情</div>
	        <div class="page-body">
	           <div id="generateForm" style="clear:both; ;float: none;">
                    <form id="search-form" action="${ctx}/zujuan/auto" method="post" >
                        <table class="searchTable" style="margin-bottom: 5px;">
                           <tr>
                               <th style="width: 80px;">课程：</th>
                               <td style="padding:0px 5px;width:180px;">
                                   ${pagerSkeleton.course.name}
                               </td>
                               <th style="width: 80px;">教材：</th>
                               <td style="padding:0px 5px;width:200px;">
                                   ${pagerSkeleton.book.name}
                               </td>
                               <th style="width: 80px;">细目表：</th>
                               <td style="padding:0px 5px;width:180px;">
                                  ${pagerSkeleton.name}
                               </td>
                               <td align="left" style="border-width: 0;padding-left: 10px;"><button class="btn" id="goBackBtn" style="margin-top:5px;">返回</button></td>
                            </tr>
                         </table>
                    </form>
                </div>
	            <div id="autoGeneratedPapers" style="clear:both; ;float: none;">
                   <div id="paperTabs" class="easyui-tabs" style="width:950px;height:auto;">
                    <c:forEach var='sj' items="${listSJ}"  varStatus="status">
                   		<c:set var="index" value="0" />
                        <div id="tab_${sj.id}" paperId="${sj.id}" divType="sjDiv" title="${status.count}.${sj.name}(${sj.statusName})" data-options="closable:false" style="padding:10px">
				           <div style="margin-bottom: 10px;"></div>
				           <div style="margin-bottom: 10px;">
				           		<span class="myMargin1">名称：</span><span class="myMargin2"><c:if test="${sj.status==0 || sj.status==4}"><security:authorize ifAnyGranted="PAPER_TEACHER" ><input type="text" name="sjName" id="sjName_${sj.id}" value="${sj.showName}" size="30"/></security:authorize><security:authorize ifNotGranted="PAPER_TEACHER">${sj.showName}</security:authorize></c:if><c:if test="${sj.status!=0 && sj.status!=4}">${sj.showName}</c:if></span>
				           		<span class="myMargin1">题头：</span><span class="myMargin2"><c:if test="${sj.status==0 || sj.status==4}"><security:authorize ifAnyGranted="PAPER_TEACHER" ><input type="text" name="sjHead" id="sjHead_${sj.id}" value="${sj.head}" size="31"/></security:authorize><security:authorize ifNotGranted="PAPER_TEACHER">${sj.head}</security:authorize></c:if><c:if test="${sj.status!=0 && sj.status!=4}">${sj.head}</c:if></span>
<c:if test="${sj.status==0 || sj.status==4}">
<security:authorize ifAnyGranted="PAPER_TEACHER" >
				           		<input type="button" value="保存" class="myButton1 myMargin2" onclick="saveSj('${sj.id}')"/>
				           		<input type="button" value="删除" class="myButton1 myMargin2" onclick="delSj('${sj.id}')"/>
				           		<input type="button" value="提交审核" class="myButton3 myMargin2" onclick="submitAudit('${sj.id}')"/>
</security:authorize>
</c:if>
<c:if test="${sj.status==1}">
<security:authorize ifAnyGranted="SECRETARY" >
				           		<input type="button" value="审核" class="myButton1 myMargin2" onclick="audit('${sj.id}')"/>
</security:authorize>
</c:if>
<c:if test="${sj.status!=0}">
				           		<input type="button" value="审核日志" class="myButton3 myMargin2" onclick="auditLog('${sj.id}')"/>
</c:if>
				           		<input type="button" value="Word" class="myButton1" onclick="createWord('${sj.id}')"/>
				           </div>
				           <div class="easyui-accordion" data-options="multiple:true">
				               <c:forEach var='qt' items="${sj.qtypeList}"  varStatus="status">
				                  <div divType="qtypeDiv" suoshuSjForStat='${sj.id}' <c:if test="${sj.status==0 || sj.status==4}"><security:authorize ifAnyGranted="PAPER_TEACHER" >suoshuSj='${sj.id}' qtId='${qt.id}'</security:authorize></c:if> title="${status.count}、${qt.name}（本大题共${qt.questionSum}小题，每题${fn:formatScore(qt.score)}分，共${fn:formatScore(qt.questionScores)}分）<c:if test="${qt.remark != null && qt.remark!= ''}">（${qt.remark}）</c:if>" data-options="collapsed:false" style="overflow:auto;padding:10px;">
						              <c:forEach var='detail' items="${qt.constructDetails}"  varStatus="statusxx">
						              <div divType="quesDiv" suoshuQt='${qt.id}' quesScore='${qt.score}' detailId='${detail.id}' quesId='${detail.question.id}' class="normalBorder">
<c:if test="${sj.status==0 || sj.status==4}">
<security:authorize ifAnyGranted="PAPER_TEACHER" >
							              <div class="btnDiv">
							              	<button class="myButton2 myMargin1" onclick="goUp(this);">↑上移</button>
							              	<button class="myButton2 myMargin1" onclick="goDown(this);">↓下移</button>
							              	<button class="myButton1 myMargin1" onclick="openChangeQuesWin('ques_${detail.id}','${sj.id}','${qt.id}','${detail.id}');">换题</button>
							              	<button class="myButton3 myMargin1" onclick="randomQues('ques_${detail.id}','${sj.id}','${qt.id}','${detail.id}');">随机换题</button>
							              	<button id="revBtn_${detail.id}" class="myButton1" style="visibility: hidden;" onclick="revertQues('ques_${detail.id}','${sj.id}','${qt.id}','${detail.id}');">还原</button>
							              </div>
</security:authorize>
</c:if>
								          <table class="paperQuestionTable">
								          	<tbody id="ques_${detail.id}" backupData="" backupQuesId="${detail.question.id}">
									             <tr>
									             <c:set var="index" value="${index+1}" />
									             	<td tdType="quesSortNo">${index}.</td>
									             	<td>
									             		<div detailForStat="${detail.question.estimateDifficultyCode}-${detail.question.abilityCode}">${detail.question.bodyHtml}</div>
										             <c:if test="${detail.question.options != null }">
										             <table class="optTable">
										                 <c:forEach var='option' items="${detail.question.options }">
										                 <tr><td class="myWidth1">${option.optionNoString }.</td><td>${option.contentHtml }</td></tr>
										                 </c:forEach>
										             </table>
										             </c:if>
									             	</td>
									             </tr>
									          </tbody>
								          </table>
						              </div>
						              </c:forEach>
						        </div>
				               </c:forEach>
						    </div>
						    <div style="margin-top: 10px;">
						    	<div style="font-size: 16px;">统计信息：</div>
						    	<table class="statTbl">
						    		<tr>
						    			<th>预计难度</th>
						    			<th>题量</th>
						    			<th>分值</th>
						    			<th>认知层次</th>
						    			<th>题量</th>
						    			<th>分值</th>
						    		</tr>
						    		<tr>
						    			<td>A.易</td>
						    			<td id="diff_quantity_10_${sj.id}"></td>
						    			<td id="diff_score_10_${sj.id}"></td>
						    			<td>I.识记</td>
						    			<td id="ability_quantity_A_${sj.id}"></td>
						    			<td id="ability_score_A_${sj.id}"></td>
						    		</tr>
						    		<tr>
						    			<td>B.中等偏易</td>
						    			<td id="diff_quantity_20_${sj.id}"></td>
						    			<td id="diff_score_20_${sj.id}"></td>
						    			<td>II.理解</td>
						    			<td id="ability_quantity_B_${sj.id}"></td>
						    			<td id="ability_score_B_${sj.id}"></td>
						    		</tr>
						    		<tr>
						    			<td>C.中等偏难</td>
						    			<td id="diff_quantity_30_${sj.id}"></td>
						    			<td id="diff_score_30_${sj.id}"></td>
						    			<td>III.简单应用</td>
						    			<td id="ability_quantity_C_${sj.id}"></td>
						    			<td id="ability_score_C_${sj.id}"></td>
						    		</tr>
						    		<tr>
						    			<td>D.难</td>
						    			<td id="diff_quantity_40_${sj.id}"></td>
						    			<td id="diff_score_40_${sj.id}"></td>
						    			<td>IV.综合应用</td>
						    			<td id="ability_quantity_D_${sj.id}"></td>
						    			<td id="ability_score_D_${sj.id}"></td>
						    		</tr>
						    	</table>
						    </div>
				        </div>
                    </c:forEach>
				    </div>
	            </div>
	        </div>
        </div>
    </div>
<div style="display: none;">
    <div id="menu" class="easyui-menu" style="width:150px;">
	    <div id="m-up">↑上移</div>
	    <div id="m-down">↓下移</div>
	</div>
    
    <div id="quesListDiv" title="可用试题列表" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:555px;height:380px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;">
        	<form action="#" id="formForEdit">
        	<div style="text-align: left;margin-bottom: 5px;">
	<input type="text" id="keywordForSearchQues" placeholder="试题关键字"/>
	<input type="hidden" id="pcqtIdForSearchQues"/>
	<input type="hidden" id="detailIdForSearchQues"/>
	<input type="button" id="searchQuesBtn" value="查询" class="myButton1 myMargin2"/>
	<input type="button" id="confirmQuesBtn" value="确定" class="myButton1"/>
</div>
<table id="availableQuesDg" class="easyui-datagrid" style="width:530px;height:300px;" data-options="url:'${ctx}/zujuan/queryAvailableQues',fitColumns:true,singleSelect:true,pagination:true">
    <thead>
        <tr>
            <th data-options="field:'id',width:80">编号</th>
            <th data-options="field:'bodySummary',width:450">题干摘要</th>
        </tr>   
    </thead>
</table>
            </form>
        </div>
    </div>
    
    <div id="auditDiv" title="审核试题" class="easyui-window" data-options="modal:true,closed:true,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="paperId" id="sjIdForAudit"/>
	<table cellpadding="5">
		<tr>
			<td nowrap="nowrap">审核结果</td>
			<td>
				<input type="radio" name="auditResult" id="approved" value="2" checked="checked"/><label for="approved" class="myMargin3">通过</label>
				<input type="radio" name="auditResult" id="rejected" value="4"/><label for="rejected">拒绝</label>
			</td>
		</tr>
		<tr>
			<td nowrap="nowrap" valign="top">审核意见</td>
			<td><textarea rows="5" cols="50" name="remark" id="auditRemark"></textarea><span id="count"></span></td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input type="button" id="saveAuditBtn" value="确定" class="myButton1 myMargin2"/>
				<input type="button" id="cancelAuditBtn" value="取消" class="myButton1"/>
			</td>
		</tr>
	</table>
            </form>
        </div>
    </div>
    
    <div id="logListDiv" title="审核日志列表" class="easyui-window" data-options="modal:true,closed: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>
	    <form id="downloadForm" action="${ctx}/zujuan/previewPaper/downloadPaper" method="post">
	    	<input type="hidden" id="paperName" name="paperName"/>
	    	<input type="hidden" id="paperId" name="paperId"/>
	    </form>
    </div>
</div>
</body>
</html>