<?php
/* @var $this MultichoiceController */
/* @var $model Multichoice */
/* @var $form CActiveForm */
?>
<style type="text/css">
		.items,.items2{list-style:none;}
</style>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'multichoice-form',
	'enableAjaxValidation'=>false,
)); ?>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>128,'maxlength'=>256)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'tigan'); ?>
		<?php echo $form->textArea($model,'tigan',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'tigan'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'tizhi'); ?>
		<ul style="padding-left:35px;margin-top:-15px;">
			<?php 
			$arr=explode('^-^',$model->tizhi);
			$arraz=$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');
			$qq=0;
			$radio_count=count($arr);
			foreach($arr as $value)
			{ 
			if($qq==0){ ?>
				<li class="items2">A&nbsp;&nbsp;<input type="text" name="Multichoice[tizhi][]" value="<?php echo $value;?>" class="required" maxlength="64" size="70"/></li>
			<?php $qq=1;} else{ ?>
				<li class="items"><?php echo $arr_; ?>&nbsp;&nbsp;<input type="text" name="Multichoice[tizhi][]" value="<?php echo $value;?>" class="required" maxlength="64" size="70"/></li>
			<?php }$arr_=next($arr_az);} ?>
				<span id="all_items"></span>
		</ul>
		<?php echo $form->error($model,'tizhi'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'); ?>
		<?php echo CHtml::button('增加选项',array('onclick'=>'add_item()')); ?>
		<?php echo CHtml::button('减少选项',array('onclick'=>'reduce_item()')); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'answer'); ?>
		<?php $qq=0;
		for($i=0;$i<$radio_count;$i++) { 
			if($i==0){
		?>
		<label><input type="checkbox" class="required" name="Multichoice[answer][]" value=0 <?php for($j=0;$j<strlen($model->answer);$j++){if(substr($model->answer,$j,1)=='A') echo "checked=checked";}?> />A</label>
		<?php }else{ ?>
		<span class="daan" style="padding-left:5px"><label><input type="checkbox" <?php for($j=0;$j<strlen($model->answer);$j++){if(substr($model->answer,$j,1)==$arr_) echo "checked=checked";} ?> class="required" value="<?php echo $i?>" name="Multichoice[answer][]"><?php echo $arr_?></label></span>
		<?php }$arr_=next($arraz);} ?>
		<span id="all_answer"></span>
		<?php echo $form->error($model,'answer'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'knowledgepoint_id'); ?>
		<?php echo $form->dropDownList($model,'knowledgepoint_id',$data,array('empty'=>'暂无')); ?>
		<?php echo $form->error($model,'knowledgepoint_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'charpter_id'); ?>
		<?php echo $form->dropDownList($model,'charpter_id',$data2); ?>
		<?php echo $form->error($model,'charpter_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'frequency'); ?>
		<?php echo $form->textField($model,'frequency'); ?>
		<?php echo $form->error($model,'frequency'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'difficulty'); ?>
		<?php echo $form->textField($model,'difficulty'); ?>
		<?php echo $form->error($model,'difficulty'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'forbidden'); ?>
		<?php echo $form->checkBox($model,'forbidden'); ?>
		<?php echo $form->error($model,'forbidden'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? '创建' : '保存'); ?>
	</div>

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

</div><!-- form -->
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    CKEDITOR.replace("Multichoice[tigan]",
      {
        skin: "v2", width:"835", height:"200",color:"#AADC6E",toolbar:"Full",language:'zh-cn',
		filebrowserBrowseUrl : '<?php echo Yii::app()->request->baseUrl?>/ckfinder/ckfinder.html',
		filebrowserImageBrowseUrl : '<?php echo Yii::app()->request->baseUrl?>/ckfinder/ckfinder.html?Type=Images',
		filebrowserFlashBrowseUrl : '<?php echo Yii::app()->request->baseUrl?>/ckfinder/ckfinder.html?Type=Flash',
		filebrowserUploadUrl : '<?php echo Yii::app()->request->baseUrl?>/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
		filebrowserImageUploadUrl : '<?php echo Yii::app()->request->baseUrl?>/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
		filebrowserFlashUploadUrl : '<?php echo Yii::app()->request->baseUrl?>/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
      });	  
</script>
<script type="text/javascript">
function add_item()
{
    //alert('d');
	var arr=['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','-'];
	var index=count=$(".items").size();
	if(arr[index]=='-') return false;
	$("#all_items").before('<li class="items">'+arr[index]+'&nbsp;&nbsp;<input type="text" name="Multichoice[tizhi][]" class="required" maxlength="64" size="70"/></li>'); 
	index2=index+1;
	$("#all_answer").before('<span class="daan" style="padding-left:5px"><label><input type="checkbox" class="required" value="'+index2+'" name="Multichoice[answer][]">'+arr[index]+'</label></span>');
}
function reduce_item()
{
    var count=$(".items").size()-1;//alert(count);
	$(".items:eq(" + count + ")").remove();//$(".items").eq( count ).remove();另一种写法
	$(".daan").eq( count ).remove();
}
</script>