<?php session_start();
//unset($_SESSION['StartTime']);
require_once 'config.php';
$user_id = $_SESSION['User']['id'];
$PageName = "Start Test"; 
$testid = $_GET['testid'];
$deptid = $_GET['deptid'];
$courseid = $_GET['courseid'];
$sql = "SELECT * FROM tbl_result WHERE TestId='$testid' AND UserId='$user_id'";
$rncnt = getRow($sql);
if($rncnt > 0){
  echo "<script>alert('Already Given Test!');window.location.href='test-series.php?deptid=$deptid&courseid=$courseid&page=test-series&tblname=tbl_test_series';</script>";
  exit();
}
$MainPage="Skill-Test";
$Page = "Skill-Test";
if(!isset($_SESSION['StartTime'])){
$CurrTime = date('H:i:s');
$_SESSION['StartTime'] = $CurrTime;
}
?>
<!doctype html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="generator" content="">
     <title><?php echo $Proj_Title; ?></title>

    <!-- manifest meta -->
    <meta name="apple-mobile-web-app-capable" content="yes">

    <!-- Favicons -->
    <link rel="apple-touch-icon" href="img/favicon180.png" sizes="180x180">
    <link rel="icon" href="img/favicon32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="img/favicon16.png" sizes="16x16" type="image/png">

    <!-- Material icons-->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <!-- Google fonts-->
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&amp;display=swap" rel="stylesheet">

    <!-- swiper CSS -->
    <link href="vendor/swiper/css/swiper.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/style.css" rel="stylesheet" id="style">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">

<link rel="icon" type="image/x-icon" href="assets/img/favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
<link rel="stylesheet" href="assets/fonts/fontawesome.css">
<link rel="stylesheet" href="assets/fonts/ionicons.css">
<link rel="stylesheet" href="assets/fonts/linearicons.css">
<link rel="stylesheet" href="assets/fonts/open-iconic.css">
<link rel="stylesheet" href="assets/fonts/pe-icon-7-stroke.css">
<link rel="stylesheet" href="assets/fonts/feather.css">

<link rel="stylesheet" href="assets/css/bootstrap-material.css">
<link rel="stylesheet" href="assets/css/shreerang-material.css">
<link rel="stylesheet" href="assets/css/uikit.css">

<link rel="stylesheet" href="assets/libs/perfect-scrollbar/perfect-scrollbar.css">
<link rel="stylesheet" href="assets/libs/flot/flot.css">
<link rel="stylesheet" href="assets/libs/datatables/datatables.css">
<link rel="stylesheet" href="assets/libs/smartwizard/smartwizard.css">
<link rel="stylesheet" href="assets/libs/select2/select2.css">
<link rel="stylesheet" href="assets/libs/bootstrap-multiselect/bootstrap-multiselect.css">
<link rel="stylesheet" href="assets/libs/bootstrap-select/bootstrap-select.css">
<link rel="stylesheet" href="assets/libs/quill/editor.css">
<link rel="stylesheet" href="assets/libs/bootstrap-markdown/bootstrap-markdown.css">
<link rel="stylesheet" href="assets/libs/quill/typography.css">
<link rel="stylesheet" href="assets/libs/growl/growl.css">
<link rel="stylesheet" href="assets/libs/toastr/toastr.css">
<link rel="stylesheet" href="assets/libs/bootstrap-sweetalert/bootstrap-sweetalert.css">
<link rel="stylesheet" href="assets/css/pages/chat.css">
<link rel="stylesheet" href="assets/css/pages/authentication.css">

<link rel="stylesheet" href="assets/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.css">
<link rel="stylesheet" href="assets/libs/dragula/dragula.css">
<link rel="stylesheet" href="assets/css/pages/products.css">
<link rel="stylesheet" href="assets/libs/bootstrap-tagsinput/bootstrap-tagsinput.css">
<link rel="stylesheet" href="assets/libs/dropzone/dropzone.css">

<link rel="stylesheet" href="assets/css/pages/tickets.css">
<link rel="stylesheet" href="assets/libs/flow-js/flow.css">
<link rel="stylesheet" href="assets/libs/blueimp-gallery/gallery.css">
<link rel="stylesheet" href="assets/libs/blueimp-gallery/gallery-indicator.css">
<link rel="stylesheet" href="assets/css/responsive.bootstrap-2.2.3.min.css">
<link rel="stylesheet" type="text/css" href="css/style2.css" />


</head>

<body class="body-scroll d-flex flex-column h-100 menu-overlay">
    <!-- screen loader -->
   
   
   <?php 
$testid = $_GET['testid'];
$deptid = $_GET['deptid'];
$courseid = $_GET['courseid'];
$sql = "SELECT ts.*,td.Name As Department,tc.Name As Course FROM tbl_test_series ts 
         LEFT JOIN tbl_departments td ON ts.DeptId = td.id 
         LEFT JOIN tbl_courses tc ON ts.CourseId = tc.id WHERE ts.id='$testid'"; 
$row = getRecord($sql);
$DeptId = $row['DeptId'];
$CourseId = $row['CourseId'];
$TestDate = $row['StartDate'];
$TestName = $row['TestName'];
$EndTime = $row['Timing'];
$expiresec = $EndTime*60;

$StartDate = date('Y-m-d');
$EndDate = date('Y-m-d');
$StartTime = $_SESSION['StartTime'];
$StartTime = $StartDate . "" . $StartTime;
$time1 = strtotime($StartTime);

$EndTime = date("H:i:s",strtotime($StartTime." +".$EndTime." minutes"));
$EndTime = $EndDate . "" . $EndTime;
$time2 = strtotime($EndTime);

$Curr_time = date('Y-m-d H:i:s');
$currenttime = strtotime(date('Y-m-d H:i:s'));

$remaingtime = abs($time2 - $currenttime);
                

 if(isset($_POST['submit'])){
    $keys   = $_POST['id'];
   $TestId = $_POST['TestId'];
   $DeptId = $_POST['DeptId'];
   $CourseId = $_POST['CourseId'];
   $StudId = $_POST['StudId'];
   $Answer = $_POST['Options'];
   $CorrectAns = $_POST['CorrectAns'];
   $option1 = $_POST['Option11'];
   $option2 = $_POST['Option22'];
   $option3 = $_POST['Option33'];
   $option4 = $_POST['Option44'];
   $subid = $_POST['subid'];
   $CreatedDate = date('Y-m-d');
   $CreatedTime = date('h:i a');

   $sql22 = "INSERT INTO tbl_result SET UserId='$StudId',TestId='$TestId',DeptId='$DeptId',CourseId='$CourseId',Status='1',TestDate='$CreatedDate',CreatedDate='$CreatedDate',CreatedTime='$CreatedTime'";
   $conn->query($sql22);
   $ResultId = mysqli_insert_id($conn);
   $result = array();
      foreach ($keys as $id => $key) {
          $result[$key] = array(
              '0' => $keys[$id],
              '1' => $Answer[$id],
              '2' => $CorrectAns[$id],     
              '3' => $option1[$id], 
              '4' => $option2[$id],
              '5' => $option3[$id],  
              '6' => $option4[$id],   
              '7' => $subid[$id],
          ); 
      }

      if(is_array($result))
          {
              foreach($result as $row => $value)
              {
                $QuesId = $value[0];
                $Answer = $value[1];
                $CorrectAns = $value[2];
                $Option1 = $value[3];
                $Option2 = $value[4];
                $Option3 = $value[5];
                $Option4 = $value[6];
                $SubjectId = $value[7];
                 if($Answer == ''){
                  $GivenAns = 11;
                 }
                 else{
                  $GivenAns = $Answer;
                 }
               $sql22 = "INSERT INTO tbl_result_answer SET ResultId='$ResultId',UserId='$StudId',TestId='$TestId',DeptId='$DeptId',CourseId='$CourseId',QuesId='$QuesId',SubjectId='$SubjectId',Answer='$GivenAns',CorrectAns='$CorrectAns',CreatedDate='$CreatedDate',CreatedTime='$CreatedTime'";
                $conn->query($sql22);
               }
          } 

    $sql2 = "SELECT * FROM tbl_result_answer WHERE ResultId='$ResultId' AND UserId='$StudId' AND Answer=11";
    $rncnt2 = getRow($sql2);

    $sql5 = "SELECT * FROM tbl_result_answer WHERE ResultId='$ResultId' AND UserId='$StudId' AND Answer!=11";
    $rncnt5 = getRow($sql5);

    $TotCorrAns = 0;
    $sql3 = "SELECT Answer,id FROM tbl_question_answer WHERE TestSeriesId='$TestId'";
    $rncnt3 = getRow($sql3);
    $row3 = getList($sql3);
    foreach($row3 as $result){
      $QuesId = $result['id'];
      $CorrAns = $result['Answer'];
      $sql4 = "SELECT * FROM tbl_result_answer WHERE QuesId='$QuesId' AND ResultId='$ResultId' AND Answer!=11";
      $row4 = getRecord($sql4);
      $GiveAnswer = $row4['Answer'];
       //echo $CorrAns." - ".$GiveAnswer."&nbsp;";
      if($CorrAns == $GiveAnswer){
       
           $TotCorrAns = $TotCorrAns + 1;
      }
    }
     $wrong = $rncnt5 - $TotCorrAns;

     $sql6 = "SELECT * FROM tbl_test_series WHERE id='$TestId'";
     $row6 = getRecord($sql6);
     $CorrectPts = $row6['CorrectMark'];
     $IncorrectPts = $row6['IncorrectMark'];
     $UnattemptedPts = $row6['UnattemptedMark'];
     $tot_result = ($TotCorrAns* $CorrectPts) + ($wrong*$IncorrectPts) + ($rncnt2*$UnattemptedPts);
     $outofmarks = $rncnt3*$CorrectPts;
     $percentage = ($tot_result/$outofmarks) * 100;

     $sql7 = "UPDATE tbl_result SET Marks='$tot_result',OutOfMarks='$outofmarks',Percentage='$percentage' WHERE TestId='$TestId' AND UserId='$StudId'";
     $conn->query($sql7);
     unset($_SESSION['StartTime']);
mysqli_close($conn);?>
<script type="text/javascript">
    setTimeout(function () { 
      swal({
    title: "Your result submitted successfully",
     type: "success",
  showCancelButton: false,
  confirmButtonColor: "#a5dc86",
  confirmButtonText: "Ok",
  closeOnConfirm: false,
  closeOnCancel: false
},
function(isConfirm){
  if (isConfirm) {
   window.location.href = "test-series.php?deptid=<?php echo $deptid;?>&courseid=<?php echo $courseid;?>&page=test-series&tblname=tbl_test_series";
  }
  else {
     window.location.href = "test-series.php?deptid=<?php echo $deptid;?>&courseid=<?php echo $courseid;?>&page=test-series&tblname=tbl_test_series";
  }
});
      });
    </script>
    <?php 
 }  
?>        



    <!-- Begin page content -->
    <main class="flex-shrink-0 main">
        <!-- Fixed navbar -->
        <?php include_once 'back-header.php'; ?>
        <!-- page content start -->
        <div class="main-container">
            <div class="container">
                <div class="layout-content">
<input type="hidden" id="time1" value="<?php echo $time1; ?>">
<input type="hidden" id="time2" value="<?php echo $time2; ?>">
<input type="hidden" id="expiresec" value="<?php echo $expiresec;?>">
<input type="hidden" id="remaingsec" value="<?php echo $remaingtime;?>">
<div class=" flex-grow-1 container-p-y">
 <span style="float:right;">Test Date: <?php echo date("d/m/Y"); ?></span><br>
 <h3 style="text-align:center;"><?php echo $TestName; ?>
 
 <span id="timer" style="float: right !important;"></span>
 </h3>
<strong style="color:red;text-align: center;">(Dont Reload the page...)</strong><br>
<div class="card mb-4">
<div class="">
<form id="smartwizard-6" novalidate="novalidate" action="" method="POST" enctype="multipart/form-data" autocomplete="off">
<h2 style="color:red;text-align: center;display: none; font-size:16px;" id="error_msg">Your Exam Time End! Please Submit Test...</h2>


<ul class="card px-4 pt-3 mb-3" style="display:none;">
<?php 
$i = 1;
 $sql2 = "SELECT * FROM tbl_question_answer WHERE TestSeriesId='$testid' ORDER BY QueNo ASC";
 $rncnt2 = getRow($sql2);
$row2 = getList($sql2);
foreach($row2 as $result){
?>   
<li>
<a href="#smartwizard-6-step-<?php echo $i;?>" class="mb-3">
<span class="sw-done-icon ion ion-md-checkmark"></span>
<span class="sw-number"><?php echo $i;?></span>
<div class="text-muted small">FIRST STEP</div>
Job Info
</a>
</li>
<?php $i++;} ?>

</ul>
<div class="mb-3 showopts">
  <input type="hidden" name="TotQues" id="TotQues" value="<?php echo $rncnt2; ?>">
 <input type="hidden" name="TestId" id="TestId" value="<?php echo $testid; ?>">
   <input type="hidden" name="DeptId" id="DeptId" value="<?php echo $DeptId; ?>">
   <input type="hidden" name="CourseId" id="CourseId" value="<?php echo $CourseId; ?>">
   <input type="hidden" name="TestDate" id="TestDate" value="<?php echo $TestDate; ?>">
   <input type="hidden" name="StudId" id="StudId" value="<?php echo $_SESSION['User']['id']; ?>">
   <input type="hidden" name="action" value="submit">
<?php 
$i = 1;
$sql2 = "SELECT * FROM tbl_question_answer WHERE TestSeriesId='$testid' ORDER BY QueNo ASC";
$row2 = getList($sql2);
foreach($row2 as $result){
?>   
<div id="smartwizard-6-step-<?php echo $i;?>" class="card animated fadeIn">
<div class="">    
<div class="scp-quizzes-data">
   <?php if($result['Type'] == 'Text'){?>
  <h3 style="font-size: 16px;"><?php echo $i;?>. <?php echo $result['Question']; ?></h3>
<?php } else{?>
   <h3><?php echo $i;?>.</h3>
   <img src="../uploads/<?php echo $result['Photo']; ?>" style="height: 250px;">
<?php } ?>
   <input type="hidden" name="id[<?php echo $result["id"]; ?>]" value="<?php echo $result["id"]; ?>">
   <input type="hidden" name="subid[<?php echo $result["id"]; ?>]" value="<?php echo $result["SubjectId"]; ?>">
    <input type="hidden" value="<?php echo $result["Answer"]; ?>" name="CorrectAns[<?php echo $result["id"]; ?>]">
    <input type="radio" name="Options[<?php echo $result["id"]; ?>]" id="inculdefile1<?php echo $result["id"]; ?>" value="1">
    <label for="inculdefile1<?php echo $result["id"]; ?>"><?php echo $result['OptNo1']; ?>. <?php echo $result['Option1']; ?></label>
    <input type="hidden" name="Option11[<?php echo $result["id"]; ?>]" value="<?php echo $result["Option1"]; ?>">
    <br/>

    <input type="radio"  name="Options[<?php echo $result["id"]; ?>]" id="inculdefile2<?php echo $result["id"]; ?>"  value="2">
       <label for="inculdefile2<?php echo $result["id"]; ?>"><?php echo $result['OptNo2']; ?>. <?php echo $result['Option2']; ?></label>
   <input type="hidden" name="Option22[<?php echo $result["id"]; ?>]" value="<?php echo $result["Option2"]; ?>">
   <br/>

    <input type="radio" name="Options[<?php echo $result["id"]; ?>]" id="inculdefile3<?php echo $result["id"]; ?>"  value="3">
       <label for="inculdefile3<?php echo $result["id"]; ?>"><?php echo $result['OptNo3']; ?>. <?php echo $result['Option3']; ?></label>
       <input type="hidden" name="Option33[<?php echo $result["id"]; ?>]" value="<?php echo $result["Option3"]; ?>">
        <br/>

    <input type="radio" name="Options[<?php echo $result["id"]; ?>]" id="inculdefile4<?php echo $result["id"]; ?>"  value="4">
     <label for="inculdefile4<?php echo $result["id"]; ?>"><?php echo $result['OptNo4']; ?>. <?php echo $result['Option4']; ?></label>
     <input type="hidden" name="Option44[<?php echo $result["id"]; ?>]" value="<?php echo $result["Option4"]; ?>"> 
 </div>

</div>
</div>
<?php $i++;} ?>
</div>



</form>
</div>  
</div>
</div>


</div>
            <br><br><br><br>
            </div>
        </div>
    </main>


    <!-- Required jquery and libraries -->

    <script src="js/popper.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- cookie js -->
    <script src="js/jquery.cookie.js"></script>

    <!-- Swiper slider  js-->
    <script src="vendor/swiper/js/swiper.min.js"></script>

    <!-- Customized jquery file  -->
    <script src="js/main.js"></script>
    <script src="js/color-scheme-demo.js"></script>


    <!-- page level custom script -->
    <script src="js/app.js"></script>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="assets/js/pace.js"></script>
<script src="assets/libs/popper/popper.js"></script>
<script src="assets/js/bootstrap.js"></script>
<script src="assets/js/sidenav.js"></script>
<script src="assets/js/layout-helpers.js"></script>
<script src="assets/js/material-ripple.js"></script>

<script src="assets/libs/perfect-scrollbar/perfect-scrollbar.js"></script>
<script src="assets/libs/eve/eve.js"></script>
<script src="assets/libs/flot/flot.js"></script>
<script src="assets/libs/flot/curvedLines.js"></script>
<script src="assets/libs/chart-am4/core.js"></script>
<script src="assets/libs/chart-am4/charts.js"></script>
<script src="assets/libs/chart-am4/animated.js"></script>

<script src="assets/js/demo.js"></script>
<script src="assets/js/analytics.js"></script>
<script src="assets/js/pages/dashboards_index.js"></script>


<script src="assets/libs/datatables/datatables.js"></script>
<script src="assets/js/pages/tables_datatables.js"></script>
<script src="assets/libs/validate/validate.js"></script>
<script src="assets/libs/select2/select2.js"></script>
<script src="assets/js/pages/forms_validation.js"></script>
<script src="assets/libs/bootstrap-select/bootstrap-select.js"></script>
<script src="assets/libs/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="assets/js/pages/forms_selects.js"></script>
<script src="assets/libs/bootstrap-tagsinput/bootstrap-tagsinput.js"></script>
<script src="assets/js/pages/forms_editors.js"></script>
<script src="assets/libs/markdown/markdown.js"></script>
<script src="assets/libs/bootstrap-markdown/bootstrap-markdown.js"></script>
<script src="assets/js/pages/forms_pickers.js"></script>
<script>
        // Quill does not support IE 10 and below so don't load it to prevent console errors
        if (typeof document.documentMode !== 'number' || document.documentMode > 10) {
            document.write('\x3Cscript src="assets/libs/quill/quill.js">\x3C/script>');
        }
    </script>
<script src="assets/js/pages/ui_notifications.js"></script>
<script src="assets/libs/growl/growl.js"></script>
<script src="assets/libs/toastr/toastr.js"></script>    
<script src="assets/js/pages/ui_tooltips.js"></script>
<script src="assets/js/pages/ui_modals.js"></script>
<script src="assets/libs/bootstrap-sweetalert/bootstrap-sweetalert.js"></script>
<script src="assets/js/pages/pages_teams.js"></script>
<script src="assets/js/pages/pages_chat.js"></script>
<script src="assets/libs/bootbox/bootbox.js"></script>

<script src="assets/libs/moment/moment.js"></script>
<script src="assets/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js"></script>
<script src="assets/libs/dragula/dragula.js"></script>
<script src="assets/js/pages/pages_e-commerce_product-edit.js"></script>
<script src="assets/js/pages/pages_tickets_edit.js"></script>
<script src="assets/libs/bootstrap-tagsinput/bootstrap-tagsinput.js"></script>
<script src="assets/libs/dropzone/dropzone.js"></script>
<script src="assets/js/pages/forms_file-upload.js"></script>
<script src="assets/js/pages/forms_wizard.js"></script>
<script src="assets/libs/smartwizard/smartwizard.js"></script>
<script src="assets/js/pages/pages_e-commerce_product-item.js"></script>
<script src="assets/libs/blueimp-gallery/gallery.js"></script>
<script src="assets/libs/blueimp-gallery/gallery-fullscreen.js"></script>
<script src="assets/libs/blueimp-gallery/gallery-indicator.js"></script>
<script src="assets/js/pages/forms_extras.js"></script>

<script src="assets/libs/vanilla-text-mask/vanilla-text-mask.js"></script>
<script src="assets/libs/vanilla-text-mask/text-mask-addons.js"></script>
<script src="assets/libs/knob/knob.js"></script>
<script src="assets/libs/bootstrap-maxlength/bootstrap-maxlength.js"></script>
<script src="assets/libs/pwstrength-bootstrap/pwstrength-bootstrap.js"></script>
<script src="assets/js/dataTables.responsive-2.2.3.min.js"></script>
<script src="assets/js/responsive.bootstrap-2.2.3.min.js"></script>



    
    <script type="text/javascript">
 
 function refresh() {
    var time1 = $('#time1').val();
    var time2 = $('#time2').val();
    var action = "getTestSeriesTime";
     $.ajax({
    url:"ajax_files/ajax_dropdown.php",
    method:"POST",
    data : {action:action,time1:time1,time2:time2},
    success:function(data)
    {
      console.log(data);
      if(data == 2){
        //alert("Your Exam Time End");
        $('.showopts').css("display","none");
        $('#error_msg').show();
        $('.btn-finish').css("display","block");
        $('.sw-btn-next').css("display","none");
        $('.sw-btn-prev').css("display","none");
    }
  }
    });
   }

    $(document).ready(function() {
        //alert("ok");
      var remaingsec = $('#remaingsec').val();
      timer(remaingsec);
     var pageRefresh = 1000; //5 s
    setInterval(function() {
        refresh();
    }, pageRefresh);
});

    $(function() {
  $('.smartwizard-example').smartWizard({
    autoAdjustHeight: false,
    backButtonSupport: false,
    useURLhash: false,
    showStepURLhash: false
  });

  // Change markup for vertical wizards
  //

  $('#smartwizard-4 .sw-toolbar').appendTo($('#smartwizard-4 .sw-container'));
  $('#smartwizard-5 .sw-toolbar').appendTo($('#smartwizard-5 .sw-container'));
});

// With validation
$(function() {
  var $form = $('#smartwizard-6');
  var TotQues = $('#TotQues').val();
  var $btnFinish = $('<button class="btn-finish btn btn-primary hidden mr-2" type="submit" name="submit" style="display:none;">Submit Test</button>');

  // Set up validator
  $form.validate({
    errorPlacement: function errorPlacement(error, element) {
      $(element).parents('.form-group').append(
        error.addClass('invalid-feedback small d-block')
      )
    },
    highlight: function(element) {
      $(element).addClass('is-invalid');
    },
    unhighlight: function(element) {
      $(element).removeClass('is-invalid');
    },
    rules: {
      'wizard-confirm': {
        equalTo: 'input[name="wizard-password"]'
      }
    }
  });

  // Initialize wizard
  $form
    .smartWizard({
      autoAdjustHeight: false,
      backButtonSupport: false,
      useURLhash: false,
      showStepURLhash: false,
      toolbarSettings: {
        toolbarExtraButtons: [$btnFinish]
      }
    })
    .on('leaveStep', function(e, anchorObject, stepNumber, stepDirection) {
      // stepDirection === 'forward' :- this condition allows to do the form validation
      // only on forward navigation, that makes easy navigation on backwards still do the validation when going next
      if (stepDirection === 'forward'){ return $form.valid(); }
      return true;
    })
    .on('showStep', function(e, anchorObject, stepNumber, stepDirection) {
      var $btn = $form.find('.btn-finish');
      // Enable finish button only on last step
      //alert(stepNumber);
      if (stepNumber === TotQues-1) {
        $btn.removeClass('hidden');
        $btn.css("display","block");
        $('.sw-btn-next').css("display","none");
      } else {
        $btn.addClass('hidden');
         $btn.css("display","none");
          $('.sw-btn-next').css("display","block");
      }
    });

  // Click on finish button

});
</script>

<script type="text/javascript">
  let timerOn = true;

function timer(remaining) {
  var m = Math.floor(remaining / 60);
  var s = remaining % 60;
  
  m = m < 10 ? '0' + m : m;
  s = s < 10 ? '0' + s : s;
  document.getElementById('timer').innerHTML = m + ':' + s;
  remaining -= 1;
  
  if(remaining >= 0 && timerOn) {
    setTimeout(function() {
        timer(remaining);
    }, 1000);
    return;
  }

  if(!timerOn) {
    // Do validate stuff here
    return;
  }
  
  // Do timeout stuff here
  //alert('Timeout for otp');
  $('#resendotp').show();
  $('#resendotp').text('Resend Otp');
      $('#timer').hide();

}


</script>
    
</body>

</html>
