<style>
#demo {
  text-align: center; 
  font-size: 60px; 
} 
</style>
<div>
<hr class="">
<div class="container target">
    <div class="row">
        <div class="col-sm-3 col-xs-12">
            <?php 
            if(empty($user_img)){
                //echo "<img class='img-circle img-responsive' src='http://slmhighschool.com/edusolution/./images/avatar.png'>";
                   
                }
                else{
                    foreach($user_img as $value){
                        if(!empty($value)){
                            $profile = $value;
                        }
                    }
                    //echo "<img class='img-circle img-responsive' src='http://slmhighschool.com/edusolution/$profile'>";
                }
            ?>
        </div>
        
        <div class="col-sm-9 col-xs-12">
            <div class="row">
                <div class="col-md-6">
                   <p><b>Name:<?php echo $student_name; ?></b></p> 
                </div>
                
                <div class="col-md-6">
                   <p><b>Class:<?php echo $paper_history['class_name']; ?></b></p> 
                </div>
            </div>
            
            <div class="row">
                <div class="col-md-6">
                   <p><b>Subject:<?php echo $paper_history['name']; ?></b></p> 
                </div>
                
                <div class="col-md-6">
                   <p><b>Time Allowed:<?php echo $paper_history['time']; ?></b></p> 
                </div>
            </div>
            
        </div>
       
     
    </div>
  <br>
        <div class="row">
            
            <div class="col-sm-8 col-xs-12" style="" contenteditable="false">
                <div class="panel panel-default">
                    <div style="background:#A8CD1B;color:white;font-weight: bold;" class="panel-heading">Questions</div>
                    <div class="panel-body"> 
                    <?php
                    $segmnt=$this->uri->segment(3);
                    if(empty($segmnt))
                    {
                        $segmnt=1;
                    }else{
                        $segmnt=$segmnt+1;
                    }
                    ?>
                    
                        <form action="<?php echo base_url();?>Test/start_test/<?php echo $segmnt;?>" method="post">
                            <input type="hidden" name="paper_id" value="<?php echo $paper_history['id'];?>">
                            <input type="hidden" name="question_id" value="<?php if(!empty($paper[0]['id'])){ echo $paper[0]['id'];};?>">
                            <input type="hidden" name="cadet_id" value="<?php echo $cadet_id;?>">
                            
                          <?php
                              if(!empty($paper))
                              {
                                  $auto_checker;
                                 foreach($paper as $row)
                                 {
                                    if(!empty($paper[0]['id'])){
                                       $q_id=$paper[0]['id'];
                                       $t_id=$paper_history['id'];
                                       $c_id=$cadet_id;
                                       $auto_checker=$this->db->select('answer')
                                                              ->from('paper_result')
                                                              ->where('test_id',$t_id)
                                                              ->where('question_no',$q_id)
                                                              ->where('cadet_id',$c_id)
                                                              ->get()->row_array()['answer'];
                                
                                                                     
                                   } 
                                   
                                    $table_validator=$row['is_mcq'];
                                    if($table_validator==0){?>
                                        <input type="hidden" name="mcq_validator" value="mcq">
                                        <p><?php echo $row['question'];?></p>
                                        <input type="radio" name="optradio" required value="a" <?php if(!empty($auto_checker)){ if($auto_checker=="a"){ echo "checked";}}?>><?php echo $row['option1'];?><br>
                                        <input type="radio" name="optradio" value="b" <?php if(!empty($auto_checker)){ if($auto_checker=="b"){ echo "checked";}}?>><?php echo $row['option2'];?><br>
                                        <input type="radio" name="optradio" value="c" <?php if(!empty($auto_checker)){ if($auto_checker=="c"){ echo "checked";}}?>><?php echo $row['option3'];?><br>
                                        <input type="radio" name="optradio" value="d" <?php if(!empty($auto_checker)){ if($auto_checker=="d"){ echo "checked";}}?>><?php echo $row['option4'];?>
                                   <?php }else{ ?>
                                        <input type="hidden" name="mcq_validator" value="truefalse">
                                        <p><?php echo $row['true_words'];?></p>
                                        <input type="radio" name="optradio" required value="T" <?php if(!empty($auto_checker)){ if($auto_checker=="T"){ echo "checked";}}?>><?php echo "T";?><br>
                                        <input type="radio" name="optradio" value="F" <?php if(!empty($auto_checker)){ if($auto_checker=="F"){ echo "checked";}}?>><?php echo "F";?><br>
                                 
                                   <?php } ?>

                            <?php     } }?>
                            <br><br>
                            <?php
                             if(!empty($paper[0]['id'])){
                              if(empty($auto_checker)){?>
                            <button type="submit" class="btn btn-primary">Submit</button>
                            
                            <?php }} ?>
                            <a href="<?php echo base_url();?>Test/result_list" style="float:right"  class="btn btn-success cssbuttongo">End Test</a>
                          </div>
                          
                        </form>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $this->pagination->create_links();?>
                    </div>
                </div>
                
            <div class="col-sm-4 col-xs-12">
                <!--left col-->
                <ul class="list-group">
                    <li class="list-group-item text-muted" style="background:#DF3D82;color:white;font-weight: bold;" contenteditable="false">Timer</li>
                    <br>
                <!--<h2 style="color:red" id="demo"></h2>-->
                    <h1 style="color:red" class="countdown"></h1>
                </ul>
            </div>
            <!--/col-3-->
    
            </div>
                         
        </div>
                 
    </div>
              
   </hr>
</div>
<script>
var time=0;
        $.ajax({
          type: "POST",
          data:{test_id:<?php echo $paper_history['id'];?>,cadet_id:<?php echo $cadet_id;?>},
          url: "<?php echo base_url();?>Test/get_time",
          
          success: function(time){
 
              //Updated Code
                  var timer2 = time;
                //  alert(timer2);
                  var interval = setInterval(function() {
                
                
                  var timer = timer2.split(':');
                  //by parsing integer, I avoid all extra string processing
                  var minutes = parseInt(timer[0], 10);
                  var seconds = parseInt(timer[1], 10);
                  --seconds;
                  minutes = (seconds < 0) ? --minutes : minutes;
                  if (minutes < 0) clearInterval(interval);
                  seconds = (seconds < 0) ? 59 : seconds;
                  seconds = (seconds < 10) ? '0' + seconds : seconds;
                  //minutes = (minutes < 10) ?  minutes : minutes;
                  $('.countdown').html(minutes + ':' + seconds);
                  timer2 = minutes + ':' + seconds;
                 // alert(timer2);
                  if(timer2=="-1:59")
                  {
                       var href = $('.cssbuttongo').attr('href');
                       window.location.href = href;
                  }
                }, 1000);

     
        
         }
        });
        
</script>
