<a name="top"></a>
<?php
$this->breadcrumbs=array(
	'考试中心'=>array('/exammanage/index'),
	$title
);
$arr_az=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$i=0;$j=1;

?>
<?php 
/*这一段是示例代码，可以作为参考的例子
echo CHtml::radioButtonList('business_nature','国有',
             array('国有'=>'国有',
                '民营'=>'民营',
                '合资'=>'合资',
                '集体'=>'集体',
                '其它'=>'其它',
             ),array('separator'=>'<br/><br/>')); 
		 
foreach($data_danxuan as $value)
{	
	$arr=explode('^-^',$value['tizhi']);
	foreach($arr as $k=>$v){
		$arr[$k]=$arr_az[$i].'、'.$v;
		$i++;
	}
	$i=0;
	echo "<p>第 {$j} 题</p>";
	echo "<p>{$value['title']}</p>";
	echo CHtml::radioButtonList('singlechoice['.$value['id'].']','',$arr,array('separator'=>'<br/><br/>')); 
	echo CHtml::checkBoxList('multichoice['.$value['id'].']',array(0,1),$arr,array('separator'=>'<br/><br/>')); 
	$j++;
	echo "<hr/>";
}
echo '<hr class="space" />';			 
*/
?>

<?php if(Yii::app()->user->hasFlash('submitmark')): ?>

<div class="flash-success">
	<?php echo Yii::app()->user->getFlash('submitmark'); ?>
	<?php echo CHtml::link('查看成绩',array('/score/admin/exam_id/'.$exam_id)) ?>
</div>
<?php else: ?>

	<div class="exampleE notice" style="height:54px;line-height:54px"><span style="color:red;font-size:54px;font-family:'黑体'">离考试结束还有：</span>
		<div class="timer" style="height:54px;float:right;"></div>
	</div>
<?php if($reexam) {?>
<br/>
<div class="flash-notice">您正在进行补考，加油...一定要及格！</div>
<?php }?>
<div class="flash-notice">本试题满分是：<?php echo $totalscore;?>分</div>
<div class="">
<?php
echo "<h2>第一部分：单项选择题(每小题：{$dan_fenzhi}分)</h2>";
$form=$this->beginWidget('CActiveForm', array(
	'id'=>'exam-form',
	'enableAjaxValidation'=>false,
	'action'=>array('receive'),
	'htmlOptions'=>array('onsubmit'=>'return check();','enctype' =>'multipart/form-data'),
)); 

?>
<?php
foreach($data_danxuan as $value)
{	
	//echo "<div style='background-color:red;'>";
	
	$arr=explode('^-^',$value['tizhi']);
	foreach($arr as $k=>$v){
		$arr[$k]=$arr_az[$i].'、'.CHtml::encode($v);
		$i++;
	}
	$i=0;
	echo "<p><a name='single_bookmark{$j}'></a>第 {$j} 题</p>";
	echo "<p>{$value['tigan']}</p><p></p>";
	echo CHtml::radioButtonList('singlechoice['.$value['id'].']','',$arr,array('separator'=>'<br/><br/>','validate'=>"required:true",'style'=>'cursor: pointer','onclick'=>"single('dan$j',this)",'labelOptions'=>array('style'=>'cursor: pointer;'))); 
	echo "<br/><br/>";
	if(!$exammode){echo CHtml::link('【参考知识点】',$this->createUrl('knowledgepoint/view',array('id'=>$value['knowledgepoint_id'])),array('target'=>'_blank'));}
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
	echo CHtml::ajaxLink('【收藏此题】',array('favorites/fav/','type'=>'single','id'=>$value['id']),array('update' =>'#fav_single'.$value['id']));
	echo "<span id=\"fav_single".$value['id']."\" style='color:red'></span>";
	echo CHtml::button('设为待定',array('onclick'=>"pend('dan$j',this)",'style'=>"float:right"));
	$j++;
	echo "<hr/>";

	//echo "</div>";
}
echo '<hr class="space" />';

$i=0;$j=1;
echo "<h2>第二部分：多项选择题(每小题：{$duo_fenzhi}分)</h2>";
foreach($data_duoxuan as $value)
{	
	$arr=explode('^-^',$value['tizhi']);
	foreach($arr as $k=>$v){
		$arr[$k]=$arr_az[$i].'、'.CHtml::encode($v);
		$i++;
	}
	$i=0;
	echo "<p><a name='multi_bookmark{$j}'></a>第 {$j} 题</p>";
	echo "<p>{$value['tigan']}</p><p></p>";
	echo CHtml::checkBoxList('multichoice['.$value['id'].']',array(),$arr,array('separator'=>'<br/><br/>','validate'=>"required:true, minlength:1",'style'=>'cursor: pointer','onchange'=>"multi('duo$j',this)",'labelOptions'=>array('style'=>'cursor: pointer;'))); 

	echo "<br/><br/>";
	if(!$exammode){echo CHtml::link('参考知识点',$this->createUrl('knowledgepoint/view',array('id'=>$value['knowledgepoint_id'])),array('target'=>'_blank'));}
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
	echo CHtml::ajaxLink('【收藏此题】',array('favorites/fav/','type'=>'multi','id'=>$value['id']),array('update' =>'#fav_multi'.$value['id']));
	echo "<span id=\"fav_multi".$value['id']."\" style='color:red'></span>";
	echo CHtml::button('设为待定',array('onclick'=>"pend('duo$j',this)",'style'=>"float:right"));
	$j++;
	echo "<hr/>";
}
echo '<hr class="space" />';
$i=0;$j=1;
echo "<h2>第三部分：判断题(每小题：{$pan_fenzhi}分)</h2>";
foreach($data_panduan as $value)
{	
	echo "<p><a name='judge_bookmark{$j}'></a>第 {$j} 题</p>";
	echo "<p>{$value['tigan']}</p><p></p>";

	echo CHtml::radioButtonList('judge['.$value['id'].']','',array('正确','错误'),array('separator'=>'','validate'=>"required:true",'style'=>'cursor: pointer','onclick'=>"judge('pan$j',this)",'labelOptions'=>array('style'=>'cursor: pointer;'))); 

	echo "<br/><br/>";
	if(!$exammode){echo CHtml::link('参考知识点',$this->createUrl('knowledgepoint/view',array('id'=>$value['knowledgepoint_id'])),array('target'=>'_blank'));}
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
	echo CHtml::ajaxLink('【收藏此题】',array('favorites/fav/','type'=>'judge','id'=>$value['id']),array('update' =>'#fav_judge'.$value['id']));
	echo "<span id=\"fav_judge".$value['id']."\" style='color:red'></span>";
	echo CHtml::button('设为待定',array('onclick'=>"pend('pan$j',this)",'style'=>"float:right"));
	$j++;
	echo "<hr/>";	
}

echo '<hr class="space" />';
$i=0;$j=1;
echo "<h2>第四部分：操作题(每小题：{$cao_fenzhi}分)</h2>";
foreach($data_caozuo as $value)
{	
	echo "<p><a name='operate_bookmark{$j}'></a>第 {$j} 题</p>";
	echo "<p>{$value['tigan']}</p>";
	echo "<p><a href='{$value['tizhi']}'>点此下载待修改文件</a></p><p></p>";
	echo "<p>上传已修改好的文件：";
	echo CHtml::activeFileField($model,'operateAnswer['.$value['id'].']',array('class'=>"required",'onchange'=>"operate('cao$j',this)"));
	echo "</p>";

	echo "<br/><br/>";
	if(!$exammode){echo CHtml::link('参考知识点',$this->createUrl('knowledgepoint/view',array('id'=>$value['knowledgepoint_id'])),array('target'=>'_blank'));}
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
	echo CHtml::ajaxLink('【收藏此题】',array('favorites/fav/','type'=>'operate','id'=>$value['id']),array('update' =>'#fav_operate'.$value['id']));
	echo "<span id=\"fav_operate".$value['id']."\" style='color:red'></span>";
	echo CHtml::button('设为待定',array('onclick'=>"pend('cao$j',this)",'style'=>"float:right"));
	$j++;
	echo "<hr/>";	
}

?>
<?php 
echo CHtml::hiddenField('dan_list',$dan_list);
echo CHtml::hiddenField('duo_list',$duo_list);
echo CHtml::hiddenField('pan_list',$pan_list);
echo CHtml::hiddenField('reexam',$reexam);
?>
<div class="flash-error">在所有试题做完之后才能交卷（色块全为绿色）。点击交卷按钮后，请等待系统验证您是否已做完，勿重复点击！</div>
<div class="row buttons">
	<?php echo CHtml::submitButton('交卷',array('disabled'=>'disabled','id'=>'yes')); ?>
	<?php //echo CHtml::submitButton('交卷',array('id'=>'yes')); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<div class="flash-notice" id="submit_notice">正在提交您的试卷......，在此期间不要做任何无关操作（如刷新、后退和关闭等），请耐心等待服务器回应！</div>
<style type="text/css">
<!--
	.tip{list-style-type: none;display:inline-block;width: 20px;height: 20px;background-color: silver;margin:1px;float: left;cursor: pointer;}
	.done{background-color:green;}
	.mark{background-color:red;}
	.error{font-size:20px;}
-->
</style>
<div style="position: fixed;bottom: 5px;left:5px;background:white;width:220px;">
<?php echo CHtml::link('回到顶部↑',"#top");?><?php echo CHtml::link('回到底部↓',"#bottom",array('style'=>'float:right'));?>
</div>
<div style="position: fixed;bottom: 5px;right:5px;background:white">
<div ><span style="background-color: silver;">灰色</span>：未做；
	<span style="background-color: green;">绿色</span>：已做；
	<span style="background-color: red;">红色</span>：待定
</div>
<hr style="margin-bottom:0px"/>
<div style="text-align:center">单选题</div>
<div style="border: solid 1px blue;width:220px;padding:1px;text-align:center;">
<?php for($j=1;$j<=count($data_danxuan);$j++) {?>
<a class="tip dan<?php echo $j;?>" href="#single_bookmark<?php echo $j;?>"><?php echo $j;?></a>
<?php }?>

<div style="clear:left"></div>
</div>

<div style="text-align:center">多选题</div>
<div style="border: solid 1px blue;width:220px;padding:1px;text-align:center;">
<?php for($j=1;$j<=count($data_duoxuan);$j++) {?>
<a class="tip duo<?php echo $j;?>" href="#multi_bookmark<?php echo $j;?>"><?php echo $j;?></a>
<?php }?>

<div style="clear:left"></div>
</div>

<div style="text-align:center">判断题</div>
<div style="border: solid 1px blue;width:220px;padding:1px;text-align:center;">
<?php for($j=1;$j<=count($data_panduan);$j++) {?>
<a class="tip pan<?php echo $j;?>" href="#judge_bookmark<?php echo $j;?>"><?php echo $j;?></a>
<?php }?>

<div style="clear:left"></div>
</div>

<div style="text-align:center">操作题</div>
<div style="border: solid 1px blue;width:220px;padding:1px;text-align:center;min-height:23px">
<?php for($j=1;$j<=count($data_caozuo);$j++) {?>
<a class="tip cao<?php echo $j;?>" href="#operate_bookmark<?php echo $j;?>"><?php echo $j;?></a>
<?php }?>

<div style="clear:left"></div>
</div>
</div>
<a name="bottom"></a>
<?php endif; ?>


<?php echo CHtml::cssFile('/css/form_validator/css/screen.css',"screen")?>
<?php echo CHtml::scriptFile('/css/form_validator/jquery.metadata.js')?>
<?php echo CHtml::scriptFile('/css/form_validator/jquery.validate.js')?>
<?php echo CHtml::scriptFile('/css/form_validator/additional-methods.js')?>
<?php echo CHtml::scriptFile('/css/form_validator/messages_zh.js')?>
<?php echo CHtml::scriptFile('/css/countdown/jquery.spriteTimer-1.3.6.js')?>

<script type="text/javascript">
$.metadata.setType("attr", "validate");
var s=<?php echo $examtime*60 ?>;

$(document).ready(function(){
	
	$("#exam-form").validate({
		errorPlacement:function(error,element){  
		error.appendTo(element.parent().prev());  
		},
		success:function(){
		
		window.onbeforeunload = function() 
		{ 	
			$("#submit_notice").show();
			return ;
			//return '如果所有试题均已做完，就可以离开此页了！';
			
		}
		
		
		},
		onbeforeunload:false,
		}
	);
	$("#submit_notice").hide();
	$('.exampleE .timer').spriteTimer({
		'seconds':<?php echo $examtime*60 ?>,
		'isCountDown': true,
		'digitImagePath': '/css/countdown/numbers.png',
		'callback': runWhenFinished2,
		'everySecondCallback': function(currentSeconds){
			if(currentSeconds/60<=<?php echo $beforesubmit?>){//alert('可以交卷了');
			$('.exampleE').css({'background':'yellow'});
			$("#yes").attr('disabled',false);
			}
			if((s-currentSeconds)%60==0)
			{
				//alert('dd');
				updatetime(currentSeconds);
				if(currentSeconds==60){
				updatetime(0);
				}
			}
			
		},
		
	});
	if(<?php echo $examtime*60 ?>==0){$("#yes").attr('disabled',false);}
})
	function runWhenFinished2() {

		$('#exam-form').submit();
	}
</script>
<script type="text/javascript">
function check()
{
	return true;
	//$("#student-form").
}
    function updatetime(currentSeconds){
        $.post('<?php echo Yii::app()->request->baseUrl.'/invigilator/updatetime'?>',{newtime:currentSeconds/60})
    }
	
window.onbeforeunload = function() 
{ 
	return '如果所有试题均已做完，就可以离开此页了！';
	
}
function single(myclass,qq)
{
	//alert('.'+name);
	var name2="\'"+$(qq).attr('name')+"\'";//alert(name2);
	if($("input:radio[name="+name2+"]:checked").val()!=null)
	{
		$('.'+myclass).addClass('done');
	}else
	{
		$('.'+myclass).removeClass('done');
	}
}
function multi(myclass,qq)
{
	//alert('.'+name);
	var name2="\'"+$(qq).attr('name')+"\'";
	//alert(name2);
	//alert($("input:checkbox[name=+name2+]:checked").val());
	
	var aa="";
	//aa=$("input:checkbox[class=+myclass+]:checked").attr("value");
	
	$("input:checkbox[name="+name2+"]:checked").each(function(){ //$("[name="+name2+"][checked]")
	if("\'"+$(this).attr('name')+"\'"==name2)
	{
		aa+=$(this).val() 
	}
	}) 
	//alert(aa);
	if(aa!='')//if (typeof(x) == "undefined")或这样
	{
		$('.'+myclass).addClass('done');
	}else
	{
		$('.'+myclass).removeClass('done');
		//alert('d');
	}

	//if($("input:checkbox[name=+name2+]:checked").val()==null)
	//{
		
	//}
	
}
function judge(myclass,qq)
{
	//alert('.'+name);
	var name2="\'"+$(qq).attr('name')+"\'";//alert(name2);
	if($("input:radio[name="+name2+"]:checked").val()!=null)
	{
		$('.'+myclass).addClass('done');
	}else
	{
		$('.'+myclass).removeClass('done');
	}
}
function operate(myclass,qq)
{
	//alert('.'+name);
	var name2=$(qq).attr('id');//alert(name2);alert($('#'+name2).val());
	if($('#'+name2).val()!='')
	{
		$('.'+myclass).addClass('done');
	}else
	{
		$('.'+myclass).removeClass('done');
	}
}
function pend(myclass,qq)
{
	$(qq).attr('value')=='取消待定'?$(qq).attr('value','设为待定'):$(qq).attr('value','取消待定');
	$('.'+myclass).toggleClass('mark');
}
</script>