<?php
$question_type = $this->session->userdata('question_type');
$this->session->unset_userdata('question_type');
?>
<input type="hidden" id="baseUrl" value="<?php echo base_url(); ?>"><br>
<input type="hidden" id="quizUrl" value="<?php echo $quiz_url; ?>"><br>
<div class="col-sm-8">
    <div class="row col-sm-12">
        <div role="tabpanel">
            <!-- Nav tabs -->
            <ul class="nav nav-tabs gray_ttc" role="tablist">
                <li role="presentation" class="<?php
                if ($question_type == 1) {
                    echo 'active';
                } else if ($question_type == NULL) {
                    echo 'active';
                }
                ?>">
                    <a href="#mcq" aria-controls="mcq" role="tab" data-toggle="tab">Multiple Choice</a>
                </li>

                <li role="presentation" class="<?php
                if ($question_type == 2) {
                    echo 'active';
                }
                ?>">
                    <a href="#true_false" aria-controls="true_false" role="tab" data-toggle="tab">True False</a>
                </li>
                <li role="presentation" class="<?php
                if ($question_type == 4) {
                    echo 'active';
                }
                ?>">
                    <a href="#fill" aria-controls="fill" role="tab" data-toggle="tab">Fill in the blank</a>
                </li>
            </ul>

            <!-- Tab panes -->
            <div class="tab-content">
                <div class="col-sm-12">
                    <br>
                    <div id="message">
                        <?php
                        $message = $this->session->userdata('message');
                        if ($message) {
//                            echo $message;
                            $this->session->unset_userdata('message');
                        }
                        ?>
                    </div>
                    <br>
                </div>

                <div role="tabpanel" class="tab-pane col-sm-12 <?php
                if ($question_type == 1) {
                    echo 'active';
                } else if ($question_type == NULL) {
                    echo 'active';
                }
                ?>" id="mcq" style="padding: 0">

                    <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;padding-top: 10px;padding-bottom: 10px;font-weight: bold">
                        <div class="col-sm-3" style="padding:10px 0">Question Name</div>
                        <div class="col-sm-1" style="padding:10px 0">Marks</div>
                        <div class="col-sm-1" style="padding:10px 0">Time</div>
                        <div class="col-sm-4" style="padding:10px 0">Correct Answer</div>
                        <div class="col-sm-3" style="padding:10px 0">Action</div>

                    </div>
                    <div class="col-sm-12"><br></div> 
<!--------------------------------------------------- start mcq ----------------------------------------->
                    <?php
                    if ($mcq) {
                        $i = 0;
                        foreach ($mcq as $v_question) {
                            ?>
                            <div class="col-sm-12 <?php
                            if ($i % 2 == 0) {
                                echo 'gray';
                            } else {
                                echo 'white';
                            }
                            ?> text-center" >

                                <div id="actions<?php echo $v_question->question_id; ?>">
                                    <div class="col-sm-3 tinymce-img-responsive" style="padding:10px 0">
                                        <?php
                                        $question_details = $v_question->question_details;
                                       // echo $question_details;
                                        echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $question_details);
                                        ?>
                                    </div>
                                    <div class="col-sm-1" style="padding:10px 0"><?php echo $v_question->points_per_answer; ?></div>
                                    <div class="col-sm-1" style="padding:10px 0"><?php echo $v_question->time_limit; ?></div>
                                    <div class="col-sm-4 tinymce-img-responsive" style="padding:10px 0">
                                        <?php
                                        $c_answer = $mcq_currect_answer[$v_question->question_id]->question_option;
                                       //echo $c_answer;
                                       echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $c_answer);
                                        ?>
                                    </div>

                                    <div class="col-sm-3" style="padding:10px 0" >

                                        <a href="<?php echo base_url() . $quiz_info->url . '/edit-multiple-choice-question/' . $v_question->question_id ?>"><i class="fa fa-edit" title="Edit"></i>
                                        </a>
                                        <span>&nbsp;&nbsp;</span>

                                        <?php
                                        $question_status = $v_question->question_status;
                                        $question_id = $v_question->question_id;
                                        if ($question_status == 0) {
                                            ?>
                                            <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'activate-question/' . $v_question->question_id; ?>', 'Active', <?php echo $v_question->question_id; ?>)">
                                                <i class="fa  fa-user-plus" title="Active"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } else if ($question_status == 1) { ?>
                                            <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'inactivate-question/' . $question_id; ?>', 'Inactive', <?php echo $v_question->question_id; ?>)">
                                                <i class="fa  fa-user-times" title="Inactive"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } else if ($question_status == 2) { ?>
                                            <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'activate-question/' . $question_id; ?>', 'Active', <?php echo $v_question->question_id; ?>)">
                                                <i class="fa  fa-user-plus" title="Active"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } ?>

                                        <?php if ($question_status != 2) { ?>
                                            <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'archive-question/' . $question_id; ?>', 'Delete', <?php echo $v_question->question_id; ?>)">
                                                <i class="fa fa-trash-o" title="Delete"></i>
                                            </a>&nbsp;&nbsp;
                                        <?php } ?>

                                    </div>
                                    <div class="col-sm-12"><br></div> 
                                </div>
                            </div>

                            <?php
                            $i++;
                        }
                    } else {
                        echo 'You do not have any Multiple Choise question for this Quiz';
                    }
                    echo $multiple_choice_pagination_link;
                    ?>
                    
                </div>
<!-----------------------------------------------end mcq -------------------------------------->
<!----------------------------------------------start true false ---------------------------------->
                <div role="tabpanel" class="tab-pane col-sm-12 <?php
                if ($question_type == 2) {
                    echo 'active';
                }
                ?>" id="true_false" style="padding: 0">

                    <div class="col-sm-12" style="padding: 0"> 
                        <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;padding-top: 10px;padding-bottom: 10px;font-weight: bold">
                            <div class="col-sm-3" style="padding:10px 0">Question Name</div>
                            <div class="col-sm-1" style="padding:10px 0">Marks</div>
                            <div class="col-sm-1" style="padding:10px 0">Time</div>
                            <div class="col-sm-4" style="padding:10px 0">Correct Answer</div>
                            <div class="col-sm-3" style="padding:10px 0">Action</div>
                        </div>
                        <div class="col-sm-12"><br></div> 

                        <?php
                        if ($true_false_question) {
                            $i = 0;
                            foreach ($true_false_question as $v_question) {
                                ?>
                                <div class="col-sm-12 <?php
                                if ($i % 2 == 0) {
                                    echo 'gray';
                                } else {
                                    echo 'white';
                                }
                                ?> text-center" >
                                    <div id="actions<?php echo $v_question->question_id; ?>">
                                        <div class="col-sm-3 tinymce-img-responsive" style="padding:10px 0">
                                            <?php
                                            $question_details = $v_question->question_details;
                                            echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $question_details);
                                           // echo $question_details;
                                            ?>
                                        </div>
                                        <div class="col-sm-1" style="padding:10px 0"><?php echo $v_question->points_per_answer; ?></div>
                                        <div class="col-sm-1" style="padding:10px 0"><?php echo $v_question->time_limit; ?></div>
                                        <div class="col-sm-4" style="padding:10px 0">
                                            <?php
                                            $question_option = $true_false_currect_answer[$v_question->question_id]->question_option;
                                            echo $question_option;
                                            ?>
                                        </div>

                                        <div class="col-sm-3" style="padding:10px 0">

                                            <a href="<?php echo base_url() . $quiz_info->url . '/edit-true-false-question/' . $v_question->question_id ?>"><i class="fa fa-edit" title="Edit"></i>
                                            </a>
                                            <span>&nbsp;&nbsp;</span>


                                            <?php
                                            $question_status = $v_question->question_status;
                                            $question_id = $v_question->question_id;
                                            if ($question_status == 0) {
                                                ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'activate-question/' . $v_question->question_id; ?>', 'Active', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa  fa-user-plus" title="Active"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } else if ($question_status == 1) { ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'inactivate-question/' . $question_id; ?>', 'Inactive', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa  fa-user-times" title="Inactive"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } else if ($question_status == 2) { ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'activate-question/' . $question_id; ?>', 'Active', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa  fa-user-plus" title="Active"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } ?>

                                            <?php if ($question_status != 2) { ?>
                                                <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'archive-question/' . $question_id; ?>', 'Delete', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa fa-trash-o" title="Delete"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } ?>

                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12"><br></div> 
                                <?php
                                $i++;
                            }
                        } else {
                            echo 'You do not have any True False question for this Quiz';
                        }
                        echo $true_false_pagination_link;
                        ?>
                          
                    </div>
                </div>
<!------------------------------------------ end true false ---------------------------------------->

<!--------------------------------------------------- start fill in the blanks ------------------------->

                <div role="tabpanel" class="tab-pane col-sm-12 <?php
                if ($question_type == 4) {
                    echo 'active';
                }
                ?>" id="fill" style="padding: 0">

                    <div class="col-sm-12" style="padding: 0"> 
                        <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;padding-top: 10px;padding-bottom: 10px;font-weight: bold">
                            <div class="col-sm-3" style="padding:10px 0">Question Name</div>
                            <div class="col-sm-1" style="padding:10px 0">Marks</div>
                            <div class="col-sm-1" style="padding:10px 0">Time</div>
                            <div class="col-sm-4" style="padding:10px 0">Correct Answer</div>
                            <div class="col-sm-3" style="padding:10px 0">Action</div>

                        </div>
                        <div class="col-sm-12"><br></div> 

                        <?php
                        if ($fill_blank_question) {
                            $i = 0;
                            foreach ($fill_blank_question as $v_question) {
                                ?>
                                <div class="col-sm-12 <?php
                                if ($i % 2 == 0) {
                                    echo 'gray';
                                } else {
                                    echo 'white';
                                }
                                ?> text-center" >

                                    <div id="actions<?php echo $v_question->question_id; ?>">
                                        <div class="col-sm-3 tinymce-img-responsive" style="padding:10px 0">
                                            <?php
                                            $question_details = $v_question->question_details;
                                            echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $question_details);
                                            ?>
                                        </div>
                                        <div class="col-sm-1" style="padding:10px 0"><?php echo $v_question->points_per_answer; ?></div>
                                        <div class="col-sm-1" style="padding:10px 0"><?php echo $v_question->time_limit; ?></div>
                                        <div class="col-sm-4 tinymce-img-responsive" style="padding:10px 0">
                                            <?php
                                            $question_option = $fill_blank_question_currect_answer[$v_question->question_id]->question_option;
                                            echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $question_option);
                                            ?>
                                        </div>

                                        <div class="col-sm-3" style="padding:10px 0">

                                            <a href="<?php echo base_url() . $quiz_info->url . '/edit-fill-blank-question/' . $v_question->question_id ?>"><i class="fa fa-edit" title="Edit"></i>
                                            </a>
                                            <span>&nbsp;&nbsp;</span>
                                            <?php
                                            $question_status = $v_question->question_status;
                                            $question_id = $v_question->question_id;
                                            if ($question_status == 0) {
                                                ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'activate-question/' . $v_question->question_id; ?>', 'Active', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa  fa-user-plus" title="Active"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } else if ($question_status == 1) { ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'inactivate-question/' . $question_id; ?>', 'Inactive', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa  fa-user-times" title="Inactive"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } else if ($question_status == 2) { ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'activate-question/' . $question_id; ?>', 'Active', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa  fa-user-plus" title="Active"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } ?>

                                            <?php if ($question_status != 2) { ?>
                                                <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'archive-question/' . $question_id; ?>', 'Delete', <?php echo $v_question->question_id; ?>)">
                                                    <i class="fa fa-trash-o" title="Delete"></i>
                                                </a>&nbsp;&nbsp;
                                            <?php } ?>

                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12"><br></div> 
                                    <?php
                                    $i++;
                                }
                            } else {
                                echo 'You do not have any Fill in the blank question for this Quiz';
                            }
                            ?>
                    </div>
                </div>
<!--------------------------------------------end fill in the blanks --------------------------------->
            </div>
        </div>
    </div><!-- /.row gray_ttc -->
</div>

<script>

    function checkForAction(url, action, questionID) { // check for Active Inactives
        swal({
            title: "",
            text: "Are you sure you want to " + action + " this Question?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#8CC73F',
            confirmButtonText: 'Yes',
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
        function (isConfirm) {
            if (isConfirm) {
                var xmlhttp = create_xmlhttp();
                var serverPage = url;
                xmlhttp.open("GET", serverPage);
                xmlhttp.onreadystatechange = function ()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        document.getElementById("actions" + questionID).innerHTML = xmlhttp.responseText;
                        document.getElementById("message").innerHTML = 'Question Successfully ' + action;
                    }
                };
                xmlhttp.send(null);
            } else {
                return;
            }
        });
    }

</script>
<script src="<?php echo base_url('front_end_resource/quiz/quiz.js');?>" type="text/javascript"></script>