<?php
$_SESSION['upload_dir'] = '/content-library/' . $person_info->url . '/my-work-file/'.$quiz_url.'/';
$_SESSION['current_path'] = '../content-library/' . $person_info->url . '/my-work-file/'.$quiz_url.'/';
?>
<div class="col-sm-8">
    <div class="row gray_ttc">
        <div role="tabpanel">
            <?php
            $question_type = $this->session->userdata('question_type');
            $this->session->unset_userdata('question_type');
            ?>
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="<?php
                if (set_value('question_type') == 1) {
                    echo 'active';
                } else if ($question_type == 1) {
                    echo 'active';
                } else if (!$question_type) {
                    echo 'active';
                }
                ?>">
                    <a href="#home" aria-controls="home" role="tab" data-toggle="tab">Multiple Choice</a>
                </li>

            </ul>

            <!-- Tab panes -->
            <div class="tab-content">

                <div role="tabpanel" class="tab-pane col-sm-12 <?php
                if (set_value('question_type') == 1) {
                    echo 'active';
                } else if ($question_type == 1) {
                    echo 'active';
                } else if (!$question_type) {
                    echo 'active';
                }
                ?>" id="home">

                    <div class="form-group col-sm-12">
                        <?php //echo validation_errors(); //id="formID2" ?>
                        <form class="cmxform" id="formID2" action="<?php echo base_url() . $quiz_info->url . '/edit-multiple-choice-question/' . $question_info->question_id; ?>" method="post" name="mcqForm" enctype="multipart/form-data" >
                            <div class="col-sm-12">
                                <div>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <textarea 
                                       data-errormessage-value-missing="Question  is required!" 
                                       class="form-control validate[required] resoulation1280"  
                                       id="mc_details" 
                                       name="question_details"
                                       placeholder="Please Type Your question" >
                                    <?php
                                       if (set_value('question_details')) {
                                           echo set_value('question_details');
                                       } else {
                                           //echo $question_info->question_details;
                                           echo $this->utility_model->view_tinyMce_information($person_id, $quiz_url, $question_info->question_details);
                                       }
                                       ?>
                                </textarea>

                                    <input type="hidden" class="form-control" id="question_type" name="question_type" value="1"  >
                                    <span style="color:red"><?php echo form_error('question_details'); ?></span>
                                    <div class="form-group  required" ></div>
                                </div> 
                                <input type="hidden" name="quiz_id" id="quiz_id" value="<?php echo $quiz_info->url; ?>">


                                <?php if ($quiz_info->quiz_random_static == '2') { ?>

                                    <br/>   
                                    <div class="form-group  required" ></div>
                                    <div id="quiz_required_information_mcq">
                                        <div class="col-sm-6 padding-zero">
                                            <input type="number" 
                                                   data-errormessage-value-missing="Mark is required!" 
                                                   class="form-control"  
                                                   id="points_per_answer" name="points_per_answer" value="<?php echo $question_info->points_per_answer; ?>"   
                                                   onchange = "checkNegative(this.value, 'marks3', 'marks_err3');"  
                                                   placeholder="Type  question Marks" 
                                                   title="Type  question Marks">
                                            <span style="color:red"><?php echo form_error('points_per_answer'); ?></span>
                                        </div>

                                        <div class="col-sm-6 padding-zero">
                                            <input type="number" 
                                                   data-errormessage-value-missing="Time limit required!"
                                                   class="form-control"  
                                                   id="time_limit" name="time_limit" value="<?php echo $question_info->time_limit; ?>"  
                                                   onchange = "checkNegative(this.value, 'time_limit3', 'time_err3');" 
                                                   placeholder="Type Time Limit (In minute)" 
                                                   title="Type Time Limit (In minute)">
                                            <span style="color:red"><?php echo form_error('time_limit'); ?></span>
                                        </div>
                                    </div>

                                <?php } ?>
                                    
                            </div>
                            <div class="col-sm-12">
                                <div class="radio radio-success">
                                    <br>
                                    <h4>Answers:</h4>
                                    <?php
                                    $i = 0;
//                                    echo '<pre>';
//                                    print_r($question_options[0]->question_option_status);
//                                    exit();
                                    //foreach ($question_options as $v_option) {
                                        ?>

                                        <div class="form-group col-sm-12">
                                            <!--<label for="option"><h3>(A)</h3></label>-->
                                            <input data-errormessage-value-missing="Please Select Currect Answer!" 
                                                   class="form-control validate[required] showCorrect mc_forminput" 
                                                   type="radio" name="status" value="<?php echo $i; ?>" id="a1" <?php
                                                   if ($question_options[0]->question_option_status == 1) {
                                                       echo 'checked';
                                                   }
                                                   ?>>
                                            <label for="a1" class=""><Strong>(A)</strong>This answer option is correct</label>
                                            <textarea name="option[]" 
                                                      data-errormessage-value-missing="Please provide an option!" 
                                                      class="form-control validate[required] resoulation1280" ><?php
//                                                            if (!set_value('option[]')) {
//                                                                echo form_error('options[]');
//                                                            } else {
                                                                //echo $v_option->question_option;
                                                                echo $this->utility_model->view_tinyMce_information($person_id, $quiz_url, $question_options[0]->question_option);
                                                            //}
                                                            ?></textarea>
                                           </div> <?php echo form_error('options[]'); ?>
                                        
                                        <div class="form-group col-sm-12">
                                            <!--<label for="option"><h3>(A)</h3></label>-->
                                            <input data-errormessage-value-missing="Please Select Currect Answer!" 
                                                   class="form-control validate[required] showCorrect mc_forminput" 
                                                   type="radio" name="status" value="<?php echo ++$i; ?>" id="b1" <?php
                                                   if ($question_options[1]->question_option_status == 1) {
                                                       echo 'checked';
                                                   }
                                                   ?>>
                                            <label for="b1" class=""><Strong>(B)</strong>This answer option is correct</label>
                                            <textarea name="option[]" 
                                                      data-errormessage-value-missing="Please provide an option!" 
                                                      class="form-control validate[required] resoulation1280" ><?php
//                                                          if (!set_value('option[]')) {
//                                                              echo form_error('options[]');
//                                                          } else {
                                                              //echo $v_option->question_option;
                                                            echo $this->utility_model->view_tinyMce_information($person_id, $quiz_url, $question_options[1]->question_option);
                                                          //}
                                                          ?></textarea>
                                            </div><?php echo form_error('options[]'); ?>
                                        
                                        <div class="form-group col-sm-12">
                                            <!--<label for="option"><h3>(A)</h3></label>-->
                                            <input data-errormessage-value-missing="Please Select Currect Answer!" 
                                                   class="form-control validate[required] showCorrect mc_forminput" 
                                                   type="radio" name="status" value="<?php echo ++$i; ?>" id="c1" <?php
                                                   if ($question_options[2]->question_option_status == 1) {
                                                       echo 'checked';
                                                   }
                                                   ?>>
                                            <label for="c1" class=""><Strong>(C)</strong>This answer option is correct</label>
                                            <textarea name="option[]" 
                                                      data-errormessage-value-missing="Please provide an option!" 
                                                      class="form-control validate[required] resoulation1280" ><?php
//                                                          if (!set_value('option[]')) {
//                                                              echo form_error('options[]');
//                                                          } else {
                                                              //echo $v_option->question_option;
                                                            echo $this->utility_model->view_tinyMce_information($person_id, $quiz_url, $question_options[2]->question_option);
                                                          //}
                                                          ?></textarea>
                                           </div> <?php echo form_error('options[]'); ?>
                                        
                                        <div class="form-group col-sm-12">
                                            <!--<label for="option"><h3>(A)</h3></label>-->
                                            <input data-errormessage-value-missing="Please Select Currect Answer!" 
                                                   class="form-control validate[required] showCorrect mc_forminput" 
                                                   type="radio" name="status" value="<?php echo ++$i; ?>" id="d1" <?php
                                                   if ($question_options[3]->question_option_status == 1) {
                                                       echo 'checked';
                                                   }
                                                   ?>>
                                            <label for="d1" class=""><Strong>(D)</strong>This answer option is correct</label>
                                            <textarea name="option[]" 
                                                      data-errormessage-value-missing="Please provide an option!" 
                                                      class="form-control validate[required] resoulation1280" ><?php
//                                                          if (!set_value('option[]')) {
//                                                              echo form_error('options[]');
//                                                          } else {
                                                              //echo $v_option->question_option;
                                                            echo $this->utility_model->view_tinyMce_information($person_id, $quiz_url, $question_options[3]->question_option);
                                                          //}
                                                          ?></textarea>
                                            </div><?php echo form_error('options[]'); ?>
                                        

                                     <br/>
                                </div>
                            </div>

                            <div class=" col-sm-12" >
                                <br/>
                                <br/>
                                <div class="col-sm-4"></div>
                                <div class="col-sm-2">
                                    <button class="btn btn-success">Update</button>
                                </div>                               
                                <div class="col-sm-2">
                                    <a class="btn btn-success skip" href="javascript:void(0)" id="finish_button1"> Skip </a>
                                </div>
                                <div class="col-sm-4"></div>
                                <script>
                                    $('#finish_button1').click(function () {
                                        window.location.href = '<?php echo base_url() . 'quiz/' . $quiz_info->url.'/question'; ?>';
                                    });
                                </script>
                            </div>

                        </form>
                    </div>
                </div>

            </div>

        </div>

    </div><!-- /.row gray_ttc -->

</div>
<style>
    .skip{
        padding:6px 20px;
    }
</style>

<script>
    function checkQuizType(quizURL, questionID, objID) {
        alert(questionID);
        var xmlhttp = false;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            xmlhttp = new XMLHttpRequest();
        }

        if (quizURL) {
            serverPage = '<?php echo base_url(); ?>get-quiz-required-information-edit/' + quizURL + '/' + questionID;
            xmlhttp.open("GET", serverPage);
            //        alert(serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                //            alert(xmlhttp.readyState);
                //            alert(xmlhttp.status);
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
//                                    alert(xmlhttp.responseText);
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;

                }
            }
            xmlhttp.send(null);
        } else {
            document.getElementById(objID).innerHTML = '';
        }
    }

</script>


<script type="text/javascript">


    document.forms['mcqForm'].elements['quiz_id'].value = '<?php
                                    if (set_value('quiz_id')) {
                                        echo set_value('quiz_id');
                                    } else {
                                        echo $quiz_info->url;
                                    }
                                    ?>';
    document.forms['mcqForm'].elements['topic_id'].value = '<?php
                                    if (set_value('topic_id')) {
                                        echo set_value('topic_id');
                                    } else {
                                        echo $question_info->topic_id;
                                    }
                                    ?>';
    document.forms['mcqForm'].elements['status'].value = '<?php
                                    if (set_value('status')) {
                                        echo set_value('status');
                                    } else {
                                        echo '2';
                                    }
                                    ?>';


</script>