<?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 . '/';

$person_id = $this->session->userdata('person_id');
$directory = 'content-library/' . $person_info->url . '/my-work-file/' . $quiz_url;
if (is_dir($directory)) {
    $_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 . '/';
} else {
    $_SESSION['upload_dir'] = '/source/' . $person_info->url . '/';
    $_SESSION['current_path'] = '../source/' . $person_info->url . '/';
}
?>
<div class="col-sm-10">
    <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-10">
                        <span style="color: red"><?php echo validation_errors(); ?></span>
                        <?php
                        $url = 'super-admin/' . $quiz_info->url . '/edit-quiz-multiple-choice-question/' . $question_info->question_id;
                        echo form_open($url, 'class="" id="formID2" name="mcqForm" onsubmit="return check_form();"');
                        ?>
                        <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 $this->utility_model->view_tinyMce_information($quiz_creator->quiz_created_by, $quiz_url, $question_info->question_details);
                                            //   echo $question_info->question_details;
                                        }
                                        ?>
                                </textarea>
                                <input type="hidden" class="form-control" id="question_type" name="question_type" value="1"  >
                                <?php echo form_error('question_details'); ?>
                                <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 validate[required]"  
                                               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">
                                    </div>
                                    <div class="col-sm-6 padding-zero">
                                        <input type="number" 
                                               data-errormessage-value-missing="Time limit required!"
                                               class="form-control validate[required]"  
                                               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)">
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                        <div class="col-sm-10 col-sm-offset-1">
                            <div class="radio radio-success">
                                <br>
                                <h4>Answers:</h4>
                                <?php
                                $i = 0;
                                $char = 'A';
                                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 ($v_option->question_option_status == 1) {
                                                   echo 'checked';
                                               }
                                               ?>>
                                        <label for="a1" class=""><Strong>(<?php echo $char; ?>)</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 set_value('option[]');
                                                      } else {
                                                          echo $this->utility_model->view_tinyMce_information($quiz_creator->quiz_created_by, $quiz_url, $v_option->question_option);
                                                          //  echo $v_option->question_option;
                                                      }
                                                      ?></textarea>
                                    </div>
                                    <?php
                                    $i++;
                                    $char++;
                                }
                                ?>
                                <br/>
                            </div>
                        </div>
                        <div class=" col-sm-12" >
                            <br/>
                            <br/>
                            <div class="col-sm-4"></div>
                            <div class="col-sm-4">
                                <button class="btn btn-success">Update Question</button>
                            </div>
                            <div class="col-sm-4"></div>
                            <div class="col-sm-4">
                                <a class="btn btn-success" href="javascript:void(0)" id="finish_button1"> Skip </a>
                            </div>

                            <script>
                                $('#finish_button1').click(function () {
                                    window.location.href = '<?php echo base_url() . 'super-admin/quiz/' . $quiz_info->url . '/question'; ?>';
                                });
                            </script>
                        </div>
                        <?php echo form_close(); ?>
                    </div>
                </div>

            </div>

        </div>

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

</div>


<script>
    function checkQuizType(quizURL, questionID, objID) {
        if (quizURL) {
            var xmlhttp = create_xmlhttp();
            var serverPage = '<?php echo base_url(); ?>get-quiz-required-information-edit/' + quizURL + '/' + questionID;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    document.getElementById(objID).innerHTML = xmlhttp.responseText;
                }
            };
            xmlhttp.send(null);
        } else {
            _(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>