<?php
//echo $total_question;
if (isset($_SESSION['pageload']) && $_SESSION['pageload'] < $total_question) {
    $_SESSION['pageload'] = $_SESSION['pageload'] + 1;
    $i = $_SESSION['pageload'];
} else {
    $_SESSION['pageload'] = 0;
    $i = $_SESSION['pageload'];
}


$min = 0;
$max = $total_question - 1;
if ($quiz_info->quiz_random_static == 1) {
    $quiz_ques_limit = $quiz_info->total_number_of_question;
} else {
    $quiz_ques_limit = $total_question;
}

if ($total_question >= $quiz_ques_limit) {
    $limit = $quiz_ques_limit;
} else {
    $limit = $total_question;
}


if ($i > $limit - 1) {
    $this->session->unset_userdata('pre_q');
    $str_slug = url_title("tt quiz result", 'dash', TRUE);
    redirect("public_quiz/save_quiz_result/" . $quiz_info->url);
}

//if ($quiz_info->quiz_random_static == 1) {
//    $q = rand($min, $max);
//    $pre_q = '';
//    $pre_q = $this->session->userdata('pre_q');
//    while (strstr($pre_q, $q . '. ')) {
//        $q = rand($min, $max);
//    }
//} else {
    $q = $i;
//}
//if ($pre_q) {
//    $sdata['pre_q'] = $pre_q . $q . '. ';
//    $this->session->set_userdata($sdata);
//}

echo '<h1>'.$this->session->userdata('pre_q').'</h1>'
?>

<script src="<?php echo base_url()?>resource_library/jquery/jquery.countdown360.js" type="text/javascript"></script>
<div class="col-sm-12 form-group">
    <div class="col-sm-6 form-group">
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <!-- TT one -->
        <ins class="adsbygoogle"
             style="display:block"
             data-ad-client="ca-pub-3140114751019908"
             data-ad-slot="5137628623"
             data-ad-format="auto"></ins>
        <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </div>

    <div class="col-sm-6 form-group">
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <!-- TT two -->
        <ins class="adsbygoogle"
             style="display:block"
             data-ad-client="ca-pub-3140114751019908"
             data-ad-slot="9567828225"
             data-ad-format="auto"></ins>
        <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </div>
</div>
<div class="col-sm-12 form-group">
    <div class="row ">
        <form action="<?php echo base_url() . 'public-quiz/' . $quiz_info->quiz_public_id . '/quiz_marking'; ?>" 
              method="post" name="quiz_form" enctype="multipart/form-data"
              onsubmit="return getElapsedTime()">

            <input type="hidden" name="points_per_answer" value="<?php echo $question[$q]->points_per_answer ?>" >
            <input type="hidden" name="question_type" value="<?php echo $question[$q]->question_type ?>" >
            <input type="hidden" name="question_id" value="<?php echo $question[$q]->question_id ?>" >
            <?php
//            $question_id_arr = Array();
//            if($this->session->userdata('sess_ques_id')){
//                $question_id_arr = $this->session->userdata('sess_ques_id');
//                $question_id_arr[] = $question[$q]->question_id;
//            }else{
//                $question_id_arr[] = $question[$q]->question_id;
//            }
//            $this->session->set_userdata('sess_ques_id',$question_id_arr);
//            $sess_quiz['ques_id'][$q] = $question[$q]->question_id;
//            $this->session->set_userdata($sess_quiz);
//            $this->quiz_model->set_question_id($question[$q]->question_id);
            ?>
            <div class="col-sm-12 padding-zero text-left"><h3><?php echo $quiz_info->quiz_name; ?> Quiz</h3></div>
            <div class="col-sm-12 padding-zero"><br></div>
            <div class="col-sm-12 gray">
                <div class="col-sm-8  padding-zero text-left">
                    <div class="col-sm-12 text-left" style="padding: 0 0 5px 20px;">
                        <div class="form-group col-sm-12 tinymce-img-responsive2">
                            <div class="col-sm-1 padding-zero text-center col-xs-2"> <?php echo ($i + 1) . '.'; ?></div>
                            <div class="col-sm-11 padding-zero col-xs-10 text-select-none">
                                <?php
                                $question_details = $question[$q]->question_details;
                                echo $this->utility_model->view_tinyMce_information($quiz_info->quiz_created_by, $quiz_info->url, $question_details);
                                ?>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">  <hr><br>  </div>

                    <div class="col-sm-12 text-left" style="padding: 0 0 5px 20px;">
                        <div class="form-group col-sm-12">
                            <?php if ($question[$q]->question_type == 3) { ?>
                                <!--<br/>-->
                                <h4>Write Your Answer:</h4>
                                <textarea name='desc_answer' class='col-sm-8'></textarea>
                            <?php } elseif ($question[$q]->question_type == 4) { ?>
                                <br/><h4>Write Your Answer:</h4>

                                <textarea class="form-control resoulation1280" name="quiz_description[]" rows="4">
                                    <?php echo set_value('quiz_description'); ?>
                                </textarea>
                            <?php } else {
                                ?>

                                <div  class="radio radio-success" style="margin: 0">
                                    <?php foreach ($options[$question[$q]->question_id] as $v_option) { ?>
                                        <div class="form-group col-sm-8 tinymce-img-responsive2 text-select-none" >
                                            <?php
                                            $v = $v_option->question_option_id;
                                            $c_answer = $v_option->question_option;
                                            ?>

                                            <input  data-errormessage-value-missing="!" 
                                                    class="validate[required] text-input radio"  
                                                    type="radio"
                                                    name='status[]' id='route'   value='<?php echo $v; ?>'
                                                    onclick="">
                                            <label for="free">
                                                <?php
                                                echo $this->utility_model->view_tinyMce_information($quiz_info->quiz_created_by, $quiz_info->url, $c_answer);
                                                ?>
                                            </label>
                                            <input type='hidden' name='option_id[]' value='<?php echo $v_option->question_option_id; ?>'>
                                        </div>                                                                                                 
                                    <?php } ?>
                                </div>
                                <?php
                            }

                            $time = $question[$q]->time_limit * 60;
                            $min = $question[$q]->time_limit;
                            ?> 
                        </div>
                        <!-------------- view answer -------------->
                        <div class="col-sm-12">                             
                            <a href="javascript:void(0)" id="view_answer" onclick="viewAnswer()"> View Answer </a>                            
                        </div>
                        <div class="col-sm-12">                             
                            <!--<a href="javascript:void(0)" id="view_answer" onclick="viewAnswer()"> View Answer </a>-->                            

                            <div id="correct_answer" style="display:none"> 

                                <div class="col-sm-3 align-left" id="answer_text">Correct Answer is :</div>
                                <div class="col-sm-5">
                                    <?php echo $this->utility_model->view_tinyMce_information($quiz_info->quiz_created_by, $quiz_info->url, $correct_answer[$question[$q]->question_id]->question_option);
                                    ?> 
                                </div>
                            </div>                            
                        </div>
                        <input type='hidden' name='hidden_value' id="" value='<?php echo $correct_answer[$question[$q]->question_id]->question_option_id; ?>'>
                        <!----------- end view answer -------------->
                        <input type='hidden' name='taken_time' id="taken_time" value=''>
                    </div>
                    <div class="col-sm-12"><br></div>                    
                    <div class="form-group col-sm-2 col-sm-offset-4"> 
                        <input type="submit" class="btn btn-success" name="submit_btn" value="Submit" >
                    </div>
                    <div class="form-group col-sm-2 text-left"> 
                        <input type="submit" class="btn btn-success skip" name="submit_btn" value="Skip" >
                    </div>
                    <div class="form-group col-sm-3 "></div>
                    <div class="col-sm-12"><br></div>
                </div>
                <div class="col-sm-4 padding-zero">

                    <div class="row">
                        <div class="col-sm-12"><br><br><br></div>
                        <div id="countdown">
                            <canvas id="countdown360_countdown" width="150" height="150">
                                <span id="countdown-text" role="status" aria-live="assertive"></span>
                            </canvas>
                        </div>

                        <script type="text/javascript" charset="utf-8">

                            var countdown = $("#countdown").countdown360({
                                radius: 60,
                                seconds: <?php echo $time; ?>,
                                fontColor: '#FFFFFF',
                                autostart: false,
                                onComplete: function () {
                                    console.log('done');
                                    location.reload();
                                }
                            });

                            countdown.start();
                            console.log('countdown360 ', countdown);

                            $(document).on("click", "submit_btn", function (e) {

                                e.preventDefault();
                                var type = $(this).attr("data-type");
                                if (type === "time-remaining")
                                {
                                    var timeRemaining = countdown.getTimeRemaining();
                                    alert(timeRemaining);
                                } else
                                {
                                    var timeElapsed = countdown.getElapsedTime();
                                    alert(timeElapsed);
                                }

                            });

                            function getElapsedTime() {
//                                alert(countdown.getElapsedTime());
                                document.getElementById('taken_time').value = countdown.getElapsedTime();
                                return true;
                            }

                        </script>
                    </div>
                </div>
            </div>
            <div class="col-sm-12"><br></div>
        </form>
        <?php
       //$this->session->set_userdata('sess_ques_id',$question_id_arr);
//                $this->session->set_userdata('sess_selected_ans',$selected_ans);
//echo $this->session->userdata('pre_q');
//echo '<pre>';
//$sess_ques_id = $this->session->userdata('sess_ques_id');
//$sess_selected_ans = $this->session->userdata('sess_selected_ans');
//if($sess_ques_id){
//$result_details = array_combine($sess_ques_id, $sess_selected_ans );
////print_r($sess_ques_id);
////print_r($sess_selected_ans);
//print_r($result_details);
//echo count($result_details);
//}


        ?>
    </div>
</div>

<div class="col-sm-12 form-group">
    <div class="col-sm-6 form-group">
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <!-- TT three -->
        <ins class="adsbygoogle"
             style="display:block"
             data-ad-client="ca-pub-3140114751019908"
             data-ad-slot="2044561420"
             data-ad-format="auto"></ins>
        <script>
                            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </div>
    <div class="col-sm-6 form-group">
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <!-- TT four -->
        <ins class="adsbygoogle"
             style="display:block"
             data-ad-client="ca-pub-3140114751019908"
             data-ad-slot="8060742220"></ins>
        <script>
                            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </div>
</div>
<style>
    .skip{
        padding: 6px 18px;
    }
</style>
<script>
    //this block of code used for disabling copy
    $(document).ready(function () {
        document.oncontextmenu = new Function("return false");//Disabling right-click
        document.onselectstart = new Function("return false"); //Disabling text selection in web page //below javascript is used for Disabling text selection in web page
    });
</script>
<script src="<?php echo base_url(); ?>front_end_resource/quiz/quiz.js" type="text/javascript"></script>

