<?php
$question_type = $this->session->userdata('question_type');
$this->session->unset_userdata('question_type');
//$person_id = $this->session->userdata('person_id');
//$quiz_url= $this->session->userdata();
?>
<div class="col-sm-10">
    <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 == 3) {
                    echo 'active';
                }
                ?>">
                    <a href="#desc" aria-controls="desc" role="tab" data-toggle="tab">Descriptive Question</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) {
                            $this->session->unset_userdata('message');
                        }
                        ?>
                    </div>
                    <br>
                </div>
<!--------------------------------- start mcq--------------------------------------->
                <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> 

                    <?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">
                                        
                                        <div class="col-sm-2 text-right">
                                           <?php 
                                          echo $this->super_admin_quiz_model->show_question_no($quiz_info->quiz_id, $v_question->question_id).'.';   
                                            ?>
                                        </div>
                                        <div class="col-sm-10 tinymce-img-responsive text-left padding-zero">
                                            <?php
                                            $question_details = $v_question->question_details;                                       
                                            echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $question_details);                          
                                            ?>                                                   
                                        </div>
                                       
                                    </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 $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('super-admin/' . $quiz_info->url . '/edit-quiz-multiple-choice-question/' . $v_question->question_id); ?>"><i class="fa fa-edit" title="Edit"></i>
                                        </a>&nbsp;&nbsp;&nbsp;
                                        <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() . 'super-admin/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() . 'super-admin/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() . 'super-admin/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 ($person_info->person_role == 6) { ?>
                                            <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/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';
                    }
                    ?>

                </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">
                                             
                                        <div class="col-sm-2 text-right">
                                           <?php 
                                          echo $this->super_admin_quiz_model->show_question_no($quiz_info->quiz_id, $v_question->question_id).'.';   
                                            ?>
                                        </div>
                                        <div class="col-sm-10 tinymce-img-responsive text-left padding-zero">
                                            <?php
                                            $question_details = $v_question->question_details;                                       
                                            echo $this->utility_model->view_tinyMce_information($quiz_creator, $quiz_url, $question_details);                          
                                            ?>                                                   
                                        </div>
                                        </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() . 'super-admin/' . $quiz_info->url . '/edit-true-false-question/' . $v_question->question_id ?>"><i class="fa fa-edit" title="Edit"></i>
                                            </a>&nbsp;&nbsp;&nbsp;
                                            <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() . 'super-admin/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() . 'super-admin/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() . 'super-admin/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 ($person_info->person_role == 6) { ?>
                                                <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/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';
                        }
                        ?>

                    </div>
                </div>
<!--------------------------------- end true false --------------------------------------->
<!--------------------------------- start descriptive --------------------------------------->
                <div role="tabpanel" class="tab-pane col-sm-12 <?php
                if ($question_type == 3) {
                    echo 'active';
                }
                ?>" id="desc" 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 ($descriptive_question) {
                            $i = 0;
                            foreach ($descriptive_question as $v_desc_question) {
                                ?>
                                <div class="col-sm-12 <?php
                                if ($i % 2 == 0) {
                                    echo 'gray';
                                } else {
                                    echo 'white';
                                }
                                ?> text-center" >

                                    <div id="actions<?php echo $v_desc_question->question_id; ?>">
                                        <div class="col-sm-3" style="padding:10px 0">
                                            <?php
                                            $question_details = $v_question->question_details;
                                            echo $question_details;
                                            ?>
                                        </div>
                                        <div class="col-sm-1" style="padding:10px 0"><?php echo $v_desc_question->points_per_answer; ?></div>
                                        <div class="col-sm-1" style="padding:10px 0"><?php echo $v_desc_question->time_limit; ?></div>
                                        <div class="col-sm-4" style="padding:10px 0">
                                            <?php
                                            $question_option = $descriptive_question_currect_answer[$v_desc_question->question_id]->question_option;
                                            echo $question_option;
                                            ?>
                                        </div>

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

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


                                            <?php
                                            $question_status = $v_desc_question->question_status;
                                            $question_id = $v_desc_question->question_id;
                                            if ($question_status == 0) {
                                                ?>
                                                <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/activate-question/' . $question_id; ?>', 'Active', <?php echo $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() . 'super-admin/inactivate-question/' . $question_id; ?>', 'Inactive', <?php echo $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() . 'super-admin/activate-question/' . $question_id; ?>', 'Active', <?php echo $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() . 'super-admin/archive-question/' . $question_id; ?>', 'Delete', <?php echo $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 Descriptive question for this Quiz';
                        }
                        ?>
                    </div>
                </div>
<!--------------------------------- end descriptive --------------------------------------->
<!--------------------------------- start fill in the blank --------------------------------------->
                <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 $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() . 'super-admin/' . $quiz_info->url . '/edit-fill-blank-question/' . $v_question->question_id ?>"><i class="fa fa-edit" title="Edit"></i>
                                            </a>&nbsp;&nbsp;&nbsp;
                                            <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() . 'super-admin/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() . 'super-admin/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() . 'super-admin/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() . 'super-admin/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 blank --------------------------------------------->
            </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>