<?php $__env->startSection('content'); ?>
<style>
	.site_fullwi .select2-container{ width:100% !important;}
</style>
<?php
$session_paperstyle_id=Session::get('session_paperstyle_id');
?>
    <div class="content-wrapper">
        <section class="content-header">
            <h1 class="pull-left">
               Add Question
            </h1>
            <p>&nbsp;</p>
        </section>

        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <?php echo Form::open(['url' => 'admin/question/savequestion', 'files' =>true, 'method' => 'post','id'=>'myform' ,'class' => 'ajax_submit','autocomplete'=>'off', 'novalidate'=>'true']); ?>

                    <div class="box box-primary">
                        <div class="box-header with-border ">
                            <h3 class="box-title">Enter Details  <b>Board:-</b><?php echo e($question->board->name); ?> , <b>Medium:-</b><?php echo e($question->medium->name); ?>, <b>Standard:-</b><?php echo e($question->standard->name); ?>, <b>Subject:-</b><?php echo e($question->subject->name); ?>, <b>Chapter:-</b><?php echo e($question->chapter->name); ?></h3>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <input type="hidden" name="question_id" value="<?php echo e($question_id); ?>">
                                <div class="col-md-6 col-md-offset-3">
								   <?php echo $__env->make('flash', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                                    <div class="form-group site_fullwi <?php echo e($errors->has('paperstyle_id') ? ' has-error' : ''); ?>">
										<label class="control-label">Paper Style <span class="text-danger">*</span></label>
										<?php if(!empty($session_paperstyle_id)): ?>
										<?php echo Form::select('paperstyle_id',['' => '---- Select Mark ----'] +App\Model\Paperstyle::all()->pluck('name','id')->toArray() ,$session_paperstyle_id, ['class' => 'form-control ','required'=>'required','id'=>'paperstyle_id','onchange'=>'setdata();']); ?>

									    <?php else: ?>
										<?php echo Form::select('paperstyle_id',['' => '---- Select Mark ----'] +App\Model\Paperstyle::all()->pluck('name','id')->toArray() ,null, ['class' => 'form-control ','required'=>'required','id'=>'paperstyle_id','onchange'=>'setdata();']); ?>

										<?php endif; ?>
										<span class="help-block" id="error_category_id"><strong><?php echo e($errors->first('paperstyle_id')); ?></strong></span>
									</div>
									<div class="form-group question_type_view site_fullwi <?php echo e($errors->has('question_type') ? ' has-error' : ''); ?>" style="display:none;">
										<label class="control-label">Question Type</label>
										<?php echo Form::select('question_type',array('Question' => 'Question','Option' => 'Option') ,null, ['class' => 'form-control ','id'=>'question_type','onchange'=>'setdata();']); ?>

										<span class="help-block" id="error_size"><strong><?php echo e($errors->first('question_type')); ?></strong></span>
									</div>
									
									<div id="category_list">
									
									</div>
									<div class="form-group <?php echo e($errors->has('question') ? ' has-error' : ''); ?>">
										<label class="control-label">Question <span class="text-danger">*</span></label>
										<?php echo Form::textarea('question',null, ['class' => 'form-control','required'=>'required','rows'=>'2','id'=>'question']); ?>

										<span class="help-block" id="error_name"><strong><?php echo e($errors->first('question')); ?></strong></span>
									</div>
									<div class="form-group answer <?php echo e($errors->has('answer') ? ' has-error' : ''); ?>" style="display:none;">
										<label class="control-label">Answer <span class="text-danger">*</span></label>
										<?php echo Form::textarea('answer',null, ['class' => 'form-control','rows'=>'2']); ?>

										<span class="help-block" id="error_name"><strong><?php echo e($errors->first('answer')); ?></strong></span>
									</div>
									<div class="form-group option <?php echo e($errors->has('option1') ? ' has-error' : ''); ?>" style="display:none;">
										<label class="control-label">Option 1 (True Answer)<span class="text-danger">*</span></label>
										<?php echo Form::text('option1',null, ['class' => 'form-control']); ?>

										<span class="help-block" id="error_name"><strong><?php echo e($errors->first('option1')); ?></strong></span>
									</div>
									<div class="form-group option <?php echo e($errors->has('option2') ? ' has-error' : ''); ?>" style="display:none;">
										<label class="control-label">Option 2 <span class="text-danger">*</span></label>
										<?php echo Form::text('option2',null, ['class' => 'form-control']); ?>

										<span class="help-block" id="error_name"><strong><?php echo e($errors->first('option2')); ?></strong></span>
									</div>
									<div class="form-group option <?php echo e($errors->has('option3') ? ' has-error' : ''); ?>" style="display:none;">
										<label class="control-label">Option 3 <span class="text-danger">*</span></label>
										<?php echo Form::text('option3',null, ['class' => 'form-control']); ?>

										<span class="help-block" id="error_name"><strong><?php echo e($errors->first('option3')); ?></strong></span>
									</div>
									<div class="form-group option <?php echo e($errors->has('option4') ? ' has-error' : ''); ?>" style="display:none;">
										<label class="control-label">Option 4 <span class="text-danger">*</span></label>
										<?php echo Form::text('option4',null, ['class' => 'form-control']); ?>

										<span class="help-block" id="error_name"><strong><?php echo e($errors->first('option4')); ?></strong></span>
									</div>
									 <button type="submit" class="btn btn-primary pull-right">Submit</button>
                                </div>
                            </div>
                        </div>
						<?php if(!$record->isEmpty()): ?>	
						<div class="box-body">
						    <div class="table-responsive">
    							<table class="table table-bordered" id="myTable">
    							<thead>
    							  <tr>
    								<th>Mark</th>
    								<th width="600px">Question</th>
    								<th width="800px">Answer</th>
    								<th>Action</th>
    							  </tr>
    							  <?php $__currentLoopData = $record; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    							  <tr>
    								<td><?php echo e($r->paperstyle->name); ?></td>
    								<td><?php echo $r->question; ?></td>
    								<?php if($r->question_type == 'Question'): ?>
    								     <td><?php echo $r->answer; ?></td>
    							    <?php else: ?>
    									<td><b>Option 1 (True Answer):-</b><?php echo e($r->option1); ?><br>
    									<b>Option 2:-</b><?php echo e($r->option2); ?><br>
    									<b>Option 3:-</b><?php echo e($r->option3); ?><br>
    									<b>Option 4:-</b><?php echo e($r->option4); ?></td>
    								<?php endif; ?>	
    								<td>
    								<a href="<?php echo e(url('admin/question/updatequestion/'.$r->id)); ?>" class="btn btn-info btn-sm" title="Edit"><i class="fa fa-pencil"></i></a>
    								<a href="#" data-id="<?php echo e($r->id); ?>" class="btn btn-danger btn-sm data-delete btndelete" title="Delete"><i class="fa fa-trash"></i></a>
    								</td>
    							  </tr>
    							  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    							</thead>
    							</table>
							</div>
							<div class="pull-right">
							<?php echo e($record->links()); ?>

							</div>
						</div>
						<?php endif; ?>
                        <div class="box-footer">
                            <a href="<?php echo e(route($route.'index')); ?>" type="submit"
                               class="btn btn-default pull-left">Back</a>
                        </div>
                    </div>
                    <?php echo Form::close(); ?>

                </div>
            </div>
        </section>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
<script>

        /*ClassicEditor
            .create( document.querySelector( '#question' ), {} )
            .catch( error => {
                console.error( error );
            } );*/
    </script>
<script>

CKEDITOR.env.isCompatible = true; 
var mathElements = [
        'math',
        'maction',
        'maligngroup',
        'malignmark',
        'menclose',
        'merror',
        'mfenced',
        'mfrac',
        'mglyph',
        'mi',
        'mlabeledtr',
        'mlongdiv',
        'mmultiscripts',
        'mn',
        'mo',
        'mover',
        'mpadded',
        'mphantom',
        'mroot',
        'mrow',
        'ms',
        'mscarries',
        'mscarry',
        'msgroup',
        'msline',
        'mspace',
        'msqrt',
        'msrow',
        'mstack',
        'mstyle',
        'msub',
        'msup',
        'msubsup',
        'mtable',
        'mtd',
        'mtext',
        'mtr',
        'munder',
        'munderover',
        'semantics',
        'annotation',
        'annotation-xml'
      ];
	CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.16.2/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
	CKEDITOR.replace('question', {
		extraPlugins: 'ckeditor_wiris,image2,uploadimage',
		extraAllowedContent: mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)',
		filebrowserUploadUrl: "<?php echo e(route('admin.question.upload', ['_token' => csrf_token() ])); ?>",
		filebrowserUploadMethod: 'form',
		removeButtons: 'ExportPdf,Form,ImageButton',
		filebrowserBrowseUrl : "<?php echo e(asset('ckeditor/filemanager/dialog.php')); ?>?type=2&editor=ckeditor&fldr=",
		filebrowserImageBrowseUrl : "<?php echo e(asset('ckeditor/filemanager/dialog.php')); ?>?type=1&editor=ckeditor&fldr=",
	});
	CKEDITOR.replace('answer', {
		extraPlugins: 'ckeditor_wiris,image2,uploadimage',
		extraAllowedContent: mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)',
		filebrowserUploadUrl: "<?php echo e(route('admin.question.upload', ['_token' => csrf_token() ])); ?>",
		filebrowserUploadMethod: 'form',
		removeButtons: 'ExportPdf,Form,ImageButton',
		filebrowserBrowseUrl : "<?php echo e(asset('ckeditor/filemanager/dialog.php')); ?>?type=2&editor=ckeditor&fldr=",
		filebrowserImageBrowseUrl : "<?php echo e(asset('ckeditor/filemanager/dialog.php')); ?>?type=1&editor=ckeditor&fldr=",
	});
</script>
<script src="https://www.wiris.net/demo/plugins/app/WIRISplugins.js?viewer=image"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.js-example-basic-multiple').select2();
		setdata();
    });
	function setdata(){
		var paperstyle_id = $('#paperstyle_id').val();
		var question_type = $('#question_type').val();
		if(paperstyle_id == 1){
			$(".question_type_view").show();
			if(question_type == 'Question'){
				$(".answer").show();
				$(".option").hide();
			}
			else{
				$(".option").show();
				$(".answer").hide();
			}
		}
		else{
			$(".question_type_view").hide();
			$('#question_type').val('Question');
			$(".answer").show();
			$(".option").hide();
		}
		getcategory(paperstyle_id);
		
	}
	function savepaperstyle(paperstyle_id) {
		$.ajax({
			url: "<?php echo e(url('admin/savepaperstyle')); ?>",
			type: 'POST',
			data: {
				"paperstyle_id": paperstyle_id, "_token": "<?php echo e(csrf_token()); ?>",
			},
			success: function (data) {
				
			}
		});
	}
	function getcategory(paperstyle_id) {
		$.ajax({
			url: "<?php echo e(url('admin/getcategory')); ?>",
			type: 'POST',
			data: {
				"paperstyle_id": paperstyle_id, "_token": "<?php echo e(csrf_token()); ?>",
			},
			success: function (data) {
				savepaperstyle(paperstyle_id);
				$("#category_list").html(data);
			}
		});
	}
	/*CKEDITOR.config.removeButtons = 'Image';
	CKEDITOR.replace('question');*/
	
	/*$('#paperstyle_id').on('change', function() {
		paperstyle();
	});*/
	
	/*function paperstyle() {
		var paperstyle_id = $('#paperstyle_id').val();
		var question_type = $('#question_type').val();
		savepaperstyle(paperstyle_id);
	  
	  if(paperstyle_id == 1){
		  $(".question_type_view").show();
		  if(question_type == 'Question'){
			  getcategory(paperstyle_id);
			 $(".answer").show();
			 $(".option").hide();
			 $(".category_view_2").show();
			 $('.category_view_2').prop("disabled", false);
		  }else{
			  $(".answer").hide();
			  $(".category_view_2").hide();
			   $('.category_view_2').prop("disabled", true);
			  $(".option").show();
		  }
	  }else{
		  if((paperstyle_id == 2) || (paperstyle_id == 3)){
			  getcategory(paperstyle_id);
			  $(".category_view_2").show();
			  $('.category_view_2').prop("disabled", false);
		  }
		  else{
			  console.log(paperstyle_id);
			  $(".category_view_2").hide();
			  $('.category_view_2').prop("disabled", true);
		  }		  
		  $(".question_type_view").hide();
		  $('#question_type').val('Question').change();
		  console.log($('#question_type').val());
		  $(".answer").show();
		  $(".option").hide();
	  }
	}	
	
	$('#question_type').on('change', function() {
	  var question_type = $('#question_type').val();
	  if(question_type == 'Question'){
		  $(".option").hide();
		  $(".answer").show();
		  $(".category_view_2").show();
		  $('#paperstyle_id').val();
		  console.log(paperstyle_id);
		  $('.category_view_2').prop("disabled", false);
	  }else{
		  $(".option").show();
		  $(".answer").hide();
		  $(".category_view_2").hide();
		  $('.category_view_2').prop("disabled", true);
	  }
	});*/
	
	/*$(document).on('change', 'select[name=paperstyle_id]', function () {
		var paperstyle_id = $(this).val();
		savepaperstyle(paperstyle_id);
		getcategory(paperstyle_id);
	});*/

	/*function savepaperstyle(paperstyle_id) {
		$.ajax({
			url: "<?php echo e(url('admin/savepaperstyle')); ?>",
			type: 'POST',
			data: {
				"paperstyle_id": paperstyle_id, "_token": "<?php echo e(csrf_token()); ?>",
			},
			success: function (data) {
				
			}
		});
	}*/
	/*function getcategory(paperstyle_id) {
		var question_type = $('#question_type').val();
		if( (question_type=='Question') || paperstyle_id == 1 || paperstyle_id == 2 || paperstyle_id == 3){
			$.ajax({
				url: "<?php echo e(url('admin/getcategory')); ?>",
				type: 'POST',
				data: {
					"paperstyle_id": paperstyle_id, "_token": "<?php echo e(csrf_token()); ?>",
				},
				success: function (data) {
					$("#category_list").html(data);
				}
			});
		}

	}*/
</script>

<script type="text/javascript">
$(".btndelete").on('click', function () {
            var obj = $(this);
            var id = $(this).attr('data-id');

            if (confirm("Are you sure to Question?")) {
                $.ajax({
                    type: "DELETE",
                    url: "<?php echo e(url('admin/question/deletequestion')); ?>/" + id,
                    data: {
                        id: id,
                        _token: "<?php echo e(csrf_token()); ?>"
                    },
                    dataType: 'json',
                    success: function (resp) {
                        alert(resp.message);
                        location.reload();
                    },
                    error: function (e) {
                        
                    }
                });
            }
        });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>