<?php 
$this->load->helper('text');
$view_person_id = $this->session->userdata('view_person_id');
$person_id = $this->session->userdata('person_id');
$person_role = $this->session->userdata('person_role');
$profile_url = $this->session->userdata('profile_url');
$this->load->library('cf');

?>

<div class="col-sm-12 text-left" style="padding: 5px 0 0 20px">
    <span><i class="fa fa-star fa-2x">&nbsp;&nbsp;&nbsp;</i>Learn through careful planning and implementation!</span>
</div>                   
<?php if ($all_quiz) { ?> 
    <div class="col-sm-12 text-left gray" style="padding-left: 20px">                                             
        <!------------------- top skill -------------------------------->
        <div class="col-sm-12 padding-zero" >
            <div id ="top_skill" class="col-sm-12 gray_ttc text-left " style="border-bottom: 2px solid #8CC73F;padding-top: 10px;padding-bottom: 10px;font-weight: bold; display: none">
                <div class="col-sm-4" style="padding:10px 0">Quiz Name</div>
                <div class="col-sm-3" style="padding:10px 0">Mark</div>
                <div class="col-sm-3" style="padding:10px 0"> Time to Complete</div>         
                <div class="col-sm-2" style="padding:10px 0">Action</div>
            </div>
            <?php
            $i = 0;
            foreach ($all_quiz as $v_quiz) {
                ++$i;
                $quiz_id = $v_quiz->quiz_id;
                $quiz_status = $v_quiz->quiz_status;
                $url = $v_quiz->url;
                $quiz_pulication_status = $v_quiz->quiz_pulication_status;
                $quiz_result_permission = $quiz_result[$v_quiz->quiz_id]->quiz_result_permission;
                $quiz_result_status = $quiz_result[$v_quiz->quiz_id]->quiz_result_status;
                if (($quiz_result_permission == 1) || ($person_id && $quiz_result_permission == 2) || (in_array($person_id, $final_array) && $quiz_result_permission == 3 ) || ($quiz_result[$v_quiz->quiz_id]->person_id == $person_id && $quiz_result_permission == 4)) {
                    if (($quiz_result_status == 0 && $person_id == $quiz_result[$v_quiz->quiz_id]->person_id) || $quiz_result_status == 1) {
                        ?>
                        <div class="<?php
                        if ($i % 2 == 0) {
                            echo 'row gray';
                        } else {
                            echo 'row white';
                        }
                        ?> col-sm-12 text-left" >
                            <div class="col-sm-4" > <?php echo $v_quiz->quiz_name; ?></div>
                            <div class="col-sm-3" style="padding:10px 0">
                                <div class="col-sm-2 text-left ">
                                    <?php echo $quiz_result[$v_quiz->quiz_id]->quiz_total_marks; ?> &nbsp; 
                                </div>
                                <div class="col-sm-10 pull-left ">
                                    <?php
                                    if ($rank[$v_quiz->quiz_id] <= 5) {
                                        echo "<button class='btn btn-success pull-left'>  Top " . 5 . "</button>";
                                    } else if ($rank[$v_quiz->quiz_id] <= 10) {
                                        echo "<button class='btn btn-success pull-left'>  Top " . 10 . "</button>";
                                    } else if ($rank[$v_quiz->quiz_id] <= 25) {
                                        echo "<button class='btn btn-success pull-left'>  Top " . 25 . "</button>";
                                    }
                                    ?>  
                                </div>
                            </div>
                            <div class="col-sm-3" style="padding:10px 0">
                                <?php
                                $quiz_total_time = 0;
                                if ($v_quiz->quiz_random_static == 1) {
                                    $quiz_total_time = ($quiz_questions[$v_quiz->quiz_id][0]->time_limit * 60) * $v_quiz->total_number_of_question;
                                } else {
                                    foreach ($quiz_questions[$v_quiz->quiz_id] as $value) {
                                        $quiz_total_time += $value->time_limit;
                                    }
                                    $quiz_total_time = $quiz_total_time * 60;
                                }
                                echo $this->cf->sec2view($quiz_result[$v_quiz->quiz_id]->quiz_finish_time) . ' / ' . $this->cf->sec2view($quiz_total_time);
                                ?>
                            </div>
                            <div class="col-sm-2" style="padding:10px 0">
                                <!---------------------- top skill action ---------------------------->        

                                <?php if ($view_person_id == $person_id) { ?>
                                    <a href="<?php echo base_url() . 'quiz/' . $v_quiz->quiz_public_id . '/result'; ?>"><i class="fa  fa-th" title="Details Quiz Result"></i></a>&nbsp;&nbsp;    
                                    <?php if ($quiz_result[$v_quiz->quiz_id]->quiz_result_status == 0) { ?>
                                        <a href="javascript:void(0)" id="activequizresult" data-toggle="modal" data-target="#activequizresultalert<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id; ?>"><i class="fa fa-user-plus" title="Active"></i>&nbsp;&nbsp;</a>
                                        <a href="javascript:void(0)" id="inactivquizresult" style="display:none" data-toggle="modal" data-target="#inactivquizresultalert<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id; ?>"><i class="fa fa-user-times" title="Inactive"></i>&nbsp;&nbsp;</a>
                                    <?php } else if ($quiz_result[$v_quiz->quiz_id]->quiz_result_status == 1) { ?>
                                        <a href="javascript:void(0)" id="activequizresult" style="display:none" data-toggle="modal" data-target="#activequizresultalert<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id; ?>"><i class="fa fa-user-plus" title="Active"></i>&nbsp;&nbsp;</a>
                                        <a href="javascript:void(0)" id="inactivquizresult" data-toggle="modal" data-target="#inactivquizresultalert<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id; ?>"><i class="fa fa-user-times" title="Inactive"></i>&nbsp;&nbsp;</a>
                                    <?php } ?>
                                    <a href="<?php echo base_url() . 'quiz/' . $v_quiz->quiz_public_id . '/start-quiz'; ?>" target="_blank"><i class="fa  fa-reply" title="Retake"></i></a>
                                <?php } else { ?>
                                    <a href="<?php echo base_url() . 'quiz/' . $v_quiz->quiz_public_id . '/' . $profile_url . '/profile-detail-result'; ?>" target="_blank"><i class="fa  fa-th" title="Details Quiz Result"></i></a>&nbsp;&nbsp;    
                                    <a href="<?php echo base_url() . 'quiz/' . $v_quiz->quiz_public_id . '/start-quiz'; ?>" target="_blank"><i class="fa  fa-reply" title="Join Quiz"></i></a>
                                <?php } ?>
                                <div class="modal" style="" id="activequizresultalert<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id ?>" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                                    <div class='modal-dialog'>
                                        <div class='modal-content' style='top: 180px;border: 5px solid #80c12c;border-top: 20px solid #80c12c !important;margin: 0 auto;max-width: 400px'>           
                                            <div class='modal-body text-center' style='padding-bottom: 0px;'>
                                                <span class='text-center'>Are you sure want to Active this quiz result?</span>
                                            </div>
                                            <div class='modal-footer'>
                                                <div  class='col-sm-12 text-center'>  
                                                    <span class='col-sm-3 col-sm-offset-3'>
                                                        <button type='button' class='btn btn-danger  col-sm-12' data-dismiss='modal' style='font-size: 14px;'>No</button>
                                                    </span> 
                                                    <span class='col-sm-3'>
                                                        <button onclick="activequizresult('<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id ?>')" class='btn btn-success col-sm-12' data-dismiss='modal'>Yes</button>
                                                    </span>

                                                </div>
                                            </div>            
                                        </div>
                                    </div>
                                </div>
                                <div class="modal" style="" id="inactivquizresultalert<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id ?>" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                                    <div class='modal-dialog'>
                                        <div class='modal-content' style='top: 180px;border: 5px solid #80c12c;border-top: 20px solid #80c12c !important;margin: 0 auto;max-width: 400px'>           
                                            <div class='modal-body text-center' style='padding-bottom: 0px;'>
                                                <span class='text-center'>Are you sure want to Inactive this quiz result?</span>
                                            </div>
                                            <div class='modal-footer'>
                                                <div  class='col-sm-12 text-center'>  
                                                    <span class='col-sm-3 col-sm-offset-3'>
                                                        <button type='button' class='btn btn-danger  col-sm-12' data-dismiss='modal' style='font-size: 14px;'>No</button>
                                                    </span> 
                                                    <span class='col-sm-3'>
                                                        <button onclick="inactivequizresult('<?php echo $quiz_result[$v_quiz->quiz_id]->quiz_result_id ?>')" class='btn btn-success col-sm-12' data-dismiss='modal'>Yes</button>
                                                    </span>

                                                </div>
                                            </div>            
                                        </div>
                                    </div>
                                </div>
                                <!------------------ end  top skill action ------------------------>                
                            </div>
                        </div>                     
                        <script>
                            $(document).ready(function () {
                                document.getElementById('top_skill').style.display = 'block';
                            });
                        </script>                    
                        <?php
                    }
                }
            }
            ?>
        </div>       
        <!--------------------------- end top skill -------------------->
    </div>
    <?php
} else {
    echo '';
}
echo $pagination_link;
?>