<?php  
 include ("../../controller/session/session-checker-teacher-student-admin-parents.php");
    mysqli_set_charset($link, 'utf8');
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="../img/favicon/<?php echo $Favicon; ?>">
    <title>Question Page | <?php echo $PrimaryName.' '.$SecondaryName; ?></title>
    <!-- Bootstrap Core CSS -->
    <link href="../library/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!--This page css - Morris CSS -->
    
    <link rel="stylesheet" href="../library/plugins/morrisjs/morris.css">
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
    
    <!-- Custom CSS -->
    <link href="../css/style-student.php" rel="stylesheet">
     <link href="../css/blueStudent.php" id="theme" rel="stylesheet">
    <!-- You can change the theme colors from here -->
  <script type="text/javascript" src="tinymce5/tinymce.min.js"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->


<style>
.dot {
  height: 15px;
  width: 15px;
  background-color: #55ce63;
  Opacity: 0.8;
  border-radius: 50%;
  display: inline-block;
}
.dott {
  height: 15px;
  width: 15px;
  background-color: #2f3d4a;
  Opacity: 0.8;
  border-radius: 50%;
  display: inline-block;
}
.dottt {
  height: 15px;
  width: 15px;
  background-color: #009efb;
  Opacity: 0.8;
  border-radius: 50%;
  display: inline-block;
}
</style>
</head>

<body class="fix-header card-no-border logo-center">
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
    </div>
    <!-- ============================================================== -->
    <!-- Main wrapper - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <div id="main-wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->
        <header class="topbar chimaPrimaryColor">
        <!-- <?php include ('../includes/header-student.php'); ?> -->
        </header>
        <!-- ============================================================== -->
        <!-- End Topbar header -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
                <!-- Sidebar navigation-->
                <aside class="left-sidebar">
                               
                    <!-- <?php include ('../includes/menu-student.php'); ?> -->
                 </aside>
                <!-- End Sidebar navigation -->
        <!-- ============================================================== -->
        <!-- End Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Page wrapper  -->
        <!-- ============================================================== -->
            <!-- Page wrapper  -->
        <!-- ============================================================== -->
        <div class="page-wrapper" >
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <div id="scrolletheory"></div>
                    <div class="row">  

                        <div class="col-sm-8" style="height: 100%; width: 100%; margin-top: 20px;">
                            <div class="card">
                                <div class="card-body" style="background-color: rgb(255, 255, 255); height: 100%; width: 100%; box-shadow: 1px 3px 10px #C4DDEB;">
                                    <?php
                                        $cbtid = $_GET['cbt_id'];
                                        $UserID = $_GET['UserID'];

                                        $select_questiondisplay = "SELECT * FROM `cbtsetquestionssettings` WHERE CampusID = '$CampusID' AND `cbtsetquestionssettingsID` = '$cbtid'";
                                        $select_questiondisplay_result = mysqli_query($link,$select_questiondisplay);
                                        $select_questiondisplay_result_cnt = mysqli_num_rows($select_questiondisplay_result);
                                        $select_questiondisplay_result_cnt_row = mysqli_fetch_assoc($select_questiondisplay_result);

                                        $questionvar =  $select_questiondisplay_result_cnt_row['question'];
                                        $theoquestion =  $select_questiondisplay_result_cnt_row['TheoryQuestion'];
                                        $AssesementCategory = $select_questiondisplay_result_cnt_row['AssesementCategory'];

                                        $questionvarnew = explode(',',$questionvar);
                                        $questionvarnew_theory = explode(',',$theoquestion);
                                        // print_r($questionvarnew);
                                        $arraynew = array();
                                        $correctanswer = array();
                                    
                                            echo '<input type="hidden" value="0" id="nxtprevquestion">
                                            <input type="hidden" value="" id="currentanwernxt">
                                            <input type="hidden" value="1" id="questionNo">';

                                            echo '<input type="hidden" value="0" id="nxtprevquestiontheory">
                                            <textarea hidden="hidden"  id="currentanwernxttheory"></textarea>
                                            <input type="hidden" value="1" id="questionNotheory">';
                                            
                                            
                                            if($AssesementCategory == 'Objective')
                                            {
                                                echo '<input type="hidden" value="theo" id="questiontype">';
                                            }else{
                                                    echo '<input type="hidden" value="obj" id="questiontype">';
                                            }

                                            echo '<div class="row">';
                                                
                                                foreach($questionvarnew as $arrquestion)
                                                {
                                                        $arrquestion;

                                                            $select_question = "SELECT * FROM `questionbank` WHERE `QuestionBankID`='$arrquestion' AND CampusID ='$CampusID' GROUP BY QuestionBankID ASC";
                                                            $select_question_result = mysqli_query($link, $select_question);
                                                            $select_question_result_cnt = mysqli_num_rows($select_question_result);
                                                            $select_question_result_cnt_row = mysqli_fetch_assoc($select_question_result);
                                                        
                                                            $qustionall = $select_question_result_cnt_row['question'];
                                                            $Questionid_1 = $select_question_result_cnt_row['QuestionBankID'];
                                                            $optionA = $select_question_result_cnt_row['optionA'];
                                                            $optionB = $select_question_result_cnt_row['optionB'];
                                                            $optionC = $select_question_result_cnt_row['optionC'];
                                                            $optionD = $select_question_result_cnt_row['optionD'];
                                                            $canswer = $select_question_result_cnt_row['answer'];

                                                            $questionobl = (object) [
                                                                'question' => $qustionall,
                                                                'optionA' => $optionA,
                                                                'optionB' => $optionB,
                                                                'optionC' => $optionC,
                                                                'optionD' => $optionD,
                                                            ];
                                                            $arraynew[] = $questionobl;
                                                            $correctanswer[] = $canswer;
                                                        
                                                }

                                                $ecodedquestions = json_encode($arraynew,JSON_FORCE_OBJECT);
                                                $currectanswer = implode(',',$correctanswer);

                                                // foreach($questionvarnew_theory as  $theoquestionnew)
                                                // {
                                                //     $theoquestionnew;

                                                //     $select_question = "SELECT * FROM `questionbank` WHERE `QuestionBankID`='$theoquestionnew' AND CampusID='$CampusID' GROUP BY QuestionBankID ASC";
                                                //     $select_question_result = mysqli_query($link, $select_question);
                                                //     $select_question_result_cnt = mysqli_num_rows($select_question_result);
                                                //     $select_question_result_cnt_row = mysqli_fetch_assoc($select_question_result);
                                                
                                                //     $qustionall = str_replace('"','\"',$select_question_result_cnt_row['question']);
                                                //     $Questionid_1 = $select_question_result_cnt_row['QuestionBankID'];
                                                    

                                                //     $questionobl_theory = (object) [
                                                //         'question' => $qustionall
                                                        
                                                //     ];

                                                //     $arraynew_theory[] =  $questionobl_theory;
                                                        
                                                        
                                                // }
                                                // $ecodedquestionstheory = json_encode($arraynew_theory);
                                                        

                                            echo '</div>';  

                                                echo '<input type="hidden" id="currectquestionID" value="'.$currectanswer.'">';
                                                $num = 1;
                                                $selectsettings = "SELECT * FROM `cbtquestionsanswers` WHERE InstitutionID = '$CampusID' AND  `cbtsetquestionssettingsID` = '$cbtid' AND StudentID='$UserID'";
                                                $selectsettings_result = mysqli_query($link,$selectsettings);
                                                $selectsettings_result_cnt = mysqli_num_rows($selectsettings_result);
                                                $Selectsettings_result_cnt_row = mysqli_fetch_assoc($selectsettings_result);
                                    ?>
                                                            
                                    <?php
                                        if($AssesementCategory == 'Theory')
                                        {
                                        
                                            if($selectsettings_result_cnt > 0)
                                            {
                                                    $countQ = 0;
                                                    $settingarr2 = $Selectsettings_result_cnt_row['question'];
                                                    $Select = "SELECT * FROM `questionbank` WHERE `QuestionBankID`='$settingarr2' AND InstitutionID='$InstitutionID' GROUP BY QuestionBankID ASC  LIMIT 1";
                                                    $selectQuery = mysqli_query($link, $Select);
                                                    $fetch2 = mysqli_num_rows($selectQuery);
                                                    
                                                    if($fetch2 == 0){
                                                                                
                                                        echo '<div class="alert alert-info alert-dismissible d-flex align-items-center show">
                                                                <i class="fa fa-info-circle"></i>
                                                            <strong class="mx-2">Hey!</strong>Please no question attached to this settings.
                                                            </div>
                                                            <a  href="cbtSetting.php"  class="close" aria-label="Close" style="color:red; margin-right:20px;"><i clas="fa fa-back"></i>Back
                                                            </a>'
                                                                ;
                                                    }
                                                    else{
                                                        while($fetch = mysqli_fetch_array($selectQuery))
                                                        {
                                                                $countQ =  $countQ + 1;
                                                        //    $rowid1 =    $Selectsettings_result_cnt_row['cbtsetquestionssettings'];  

                                                            $question = $fetch['question'];
                                                            $optionA =  $fetch['optionA'];
                                                            $optionB =  $fetch['optionB'];
                                                            $optionC =  $fetch['optionC'];
                                                            $optionD =  $fetch['optionD'];
                                                            $images =   $fetch['images'];
                                                            $rowid =    $fetch['QuestionBankID'];

                                                                            
                                                    }
                                                }
                                            }
                                        

                                        ?>
                                        <!--|||||||||||||||||ONLY OBJ EXAM |||||||||||||||||\\-->
                                        <div id ="displayResults">
                                            <a  href="#"   id="locationTocbtsetting" class="close" aria-label="Close" style="color:red; margin-right:20px;"><i clas="fa fa-plus"></i>Exit
                                            </a>
                                            <h1 style="font-style: italic; margin-top: 10px;">(Question <?php echo $countQ;?>)</h1>

                                                <div class="myborder"></div> 
                                            <div class = "question" style="margin-top: 50px; margin-left: 20px;">
                                                    

                                                        <div style="margin-top: 50px; margin-left: 20px;">
                                                            <h4><?php echo $question; ?></h4>

                                                                <?php  

                                                                    $studentID = $_GET['UserID'];
                                                                        // GET QUESTION ANSWERED ID//
                                                                        $answer = "SELECT * FROM cbtquestionsanswers WHERE 

                                                                        cbtsettingsID = '$cbtid' AND StudentID = '$studentID' AND question IN ($rowid)
                                                                                    ORDER BY cbtquestionsanswersID  ASC LIMIT 1";
                                                                        $answerQuery = mysqli_query($link, $answer);  
                                                                        $fetchanswer = mysqli_fetch_assoc($answerQuery);
                                                                        $fetchanswerRow = mysqli_num_rows($answerQuery);
                                                                        

                                                                        $getAnswer = $fetchanswer['studentAnswer'];

                                                                        if($getAnswer == "A"){

                                                                            $check = "checked";

                                                                            echo ' <h5 style="color: black;">a)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                            <h5 style="color: black;">b)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                        
                                                                            <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                            <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</label></h5>';
                                                                        }
                                                                        elseif($getAnswer == "B"){
                                                                                $check = "checked";
                                                                                echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                                <h5 style="color: black;">b)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                            
                                                                                <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                                <h5 style="color: black;">d)   <input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</label></h5>';
                                                                        }
                                                                        elseif($getAnswer == "C"){
                                                                                    $check = "checked";
                                                                                    echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                                <h5 style="color: black;">b)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                            
                                                                                <h5 style="color: black;">c)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                                <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</h5>';
                                                                    
                                                                        }
                                                                        elseif($getAnswer == "D"){
                                                                                    $check = "checked";
                                                                                        echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                                        <h5 style="color: black;">b)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                                    
                                                                                        <h5 style="color: black;">c)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                                        <h5 style="color: black;">d)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$option.'</label></h5>';
                                                                                    
                                                                        }
                                                                        elseif($getAnswer == "0"){

                                                                                            echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1"><?php echo  $optionA;?></label></h5>

                                                                                            <h5 style="color: black;">b)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2"><?php echo  $optionB;?></label></h5>
                                                                                        
                                                                                            <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3"><?php echo  $optionC;?></label></h5>
                                                        
                                                                                            <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4"><?php echo  $optionD;?></label></h5>';
                                                                                        
                                                                        }else{
                                                                            echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                            <h5 style="color: black;">b)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                        
                                                                            <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>
                                        
                                                                            <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</label></h5>';
                                                                        }

                                                        
                                                                ?>
                                                        </div> 

                                                    <div class="row" style="margin-top: 75px;">
                                                        <div class="col-sm-10">
                                                            <div>
                                                                <small style="color: red;">
                                                                    <b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br> to the question
                                                                    by the right before the time runs out. You can also select any<br>question below to answer. 
                                                                    Don't forget to click Submit when you are done.
                                                                </small>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <hr/>

                                                    <div class="row" style="margin-top: 30px;">
                                                        <div class="col-sm-9 col-xs-9 col-md-9">
                                                            <!--<button type="button" style="font-size: 15px;" data-id="<?php echo $countQ;?>" disabled value="PREV" class="btn waves-effect waves-light btn-rounded btn-secondary previous">Previous</button>-->
                                                        </div>

                                                        <div class="col-sm-3 col-xs-4 col-md-3">
                                                            <button type="button" style="font-size: 15px;" value="NEXT"  data-id ="<?php echo $countQ;?>" class="btn waves-effect waves-light btn-rounded btn-success next">Next</button>
                                                        </div>
                                                    </div>
                                            </div>            
                                        </div>  
                                        <!--|||||||||||||||||ONLY OBJ EXAM |||||||||||||||||\\-->

                                    <?php
                                                
                                        }elseif($AssesementCategory == 'Both')
                                        {

                                            $studentID = $_GET['UserID'];

                                            if($selectsettings_result_cnt > 0)
                                            {
                                                    $countQ = 0;
                                                    
                                                        $settingarr2 = $Selectsettings_result_cnt_row['TheoryQuestion'];
                                                    
                                                    
                                                                
                                                    $Select = "SELECT * FROM `questionbank` WHERE `QuestionBankID`='$settingarr2' AND InstitutionID='$InstitutionID' GROUP BY QuestionBankID ASC  LIMIT 1";
                                                    $selectQuery = mysqli_query($link, $Select);
                                                    $fetch2 = mysqli_num_rows($selectQuery);
                                                    
                                                    if($fetch2 == 0){
                                                                                
                                                        echo '<div class="alert alert-info alert-dismissible d-flex align-items-center show">
                                                                    <i class="fa fa-info-circle"></i>
                                                                <strong class="mx-2">Hey!</strong>Please no question attached to this settings.
                                                                </div>
                                                                <a  href="cbtSetting.php"  class="close" aria-label="Close" style="color:red; margin-right:20px;"><i clas="fa fa-back"></i>Back
                                                                </a>'
                                                                ;
                                                    }
                                                    else{
                                                        while($fetch = mysqli_fetch_array($selectQuery))
                                                        {
                                                                $countQ =  $countQ + 1;
                                                                //    $rowid1 =    $Selectsettings_result_cnt_row['cbtsetquestionssettings'];  

                                                            $question = $fetch['question'];
                                                            $optionA =  $fetch['optionA'];
                                                            $optionB =  $fetch['optionB'];
                                                            $optionC =  $fetch['optionC'];
                                                            $optionD =  $fetch['optionD'];
                                                            $images =   $fetch['images'];
                                                            $rowid =    $fetch['QuestionBankID'];

                                                                            
                                                    }
                                                }
                                            }

                                        ?>
                                    <!--|||||||||||||||||ONLY THEORY EXAM |||||||||||||||||\\-->
                                            <div id="displayteoryform">
                                                        
                                                <a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a>
                                                        <h1 style="font-style: italic; margin-top: 10px;">(Question <?php echo $countQ;?>)</h1>
                                                    <?php
                                                        echo'<h6>'.$question.'</h6><br>';
                                                        
                                                    ?>
                
                                                            <label>Enter your Answer in the Field Below</label>
                                                            
                                                        <textarea id="optionA1" class="wrs_div_box example question" contenteditable="true" tabindex="0" spellcheck="true" role="textbox"></textarea>



                                                            <div class="row" style="margin-top: 75px;">
                                                                <div class="col-sm-10">
                                                                    <div>
                                                                        <small style="color: red;">
                                                                            <b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish
                                                                            before the time runs out. You can also click on Previous to go backward. 
                                                                            Don't forget to click Submit when you are done.
                                                                        </small>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <hr/>

                                                            <div class="row" style="margin-top: 30px;">
                                                                <div class="col-sm-9 col-xs-9 col-md-9">
                                                                    <!--<button type="button" style="font-size: 15px;" data-id="<?php echo $countQ;?>" disabled value="PREV" class="btn waves-effect waves-light btn-rounded btn-secondary previous">Previous</button>-->
                                                                </div>

                                                                <div class="col-sm-3 col-xs-4 col-md-3">
                                                                    
                                                                    <button type="button" style="font-size: 15px;" value="NEXT"  data-id="<?php $countQ = 1; echo $countQ;?>" class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button>
                                                                </div>
                                                            </div>
                            
                                                    </div>
                                            <!--|||||||||||||||||ONLY THEORY EXAM |||||||||||||||||\\-->
                                    <?php

                                    }elseif($AssesementCategory == 'Both')
                                    {
                                            
                                        $studentID = $_GET['UserID'];
                                    ?>

                                    <!--|||||||||||||||||OBJ BEFORE THEORY EXAM |||||||||||||||||\\-->
                                                        
                                    <div id ="displayResults">
                                        <?php
                                            
                                            if($selectsettings_result_cnt > 0)
                                            {
                                                    $countQ = 0;
                                                    $settingarr2 = $Selectsettings_result_cnt_row['question'];
                                                    $Select = "SELECT * FROM `questionbank` WHERE `QuestionBankID`='$settingarr2' AND InstitutionID='$InstitutionID' GROUP BY QuestionBankID ASC  LIMIT 1";
                                                    $selectQuery = mysqli_query($link, $Select);
                                                    $fetch2 = mysqli_num_rows($selectQuery);
                                                    
                                                    if($fetch2 == 0){
                                                                                
                                                        echo '<div class="alert alert-info alert-dismissible d-flex align-items-center show">
                                                                    <i class="fa fa-info-circle"></i>
                                                                <strong class="mx-2">Hey!</strong>Please no question attached to this settings.
                                                                </div>
                                                                <a  href="cbtSetting.php"  class="close" aria-label="Close" style="color:red; margin-right:20px;"><i clas="fa fa-back"></i>Back
                                                                </a>'
                                                                ;
                                                    }
                                                    else{
                                                    while($fetch = mysqli_fetch_array($selectQuery))
                                                    {
                                                            $countQ =  $countQ + 1;
                                                        //    $rowid1 =    $Selectsettings_result_cnt_row['cbtsetquestionssettings'];  

                                                            $question = $fetch['question'];
                                                            $optionA =  $fetch['optionA'];
                                                            $optionB =  $fetch['optionB'];
                                                            $optionC =  $fetch['optionC'];
                                                            $optionD =  $fetch['optionD'];
                                                            $images =   $fetch['images'];
                                                            $rowid =    $fetch['QuestionBankID'];

                                                                            
                                                    }
                                                }
                                            }
                                        ?>
                                        <a  href="#"   id="locationTocbtsetting" class="close" aria-label="Close" style="color:red; margin-right:20px;"><i clas="fa fa-plus"></i>Exit
                                        </a>
                                        <h1 style="font-style: italic; margin-top: 10px;">(Question <?php echo $countQ;?>)</h1>

                                        <div class="myborder"></div> 
                                        <div class = "question" style="margin-top: 50px; margin-left: 20px;">
                                                        
                                            <div style="margin-top: 50px; margin-left: 20px;">
                                                <h4><?php echo $question; ?></h4>

                                                        <?php  
                                                                
                                                                $studentID = $_GET['UserID'];
                                                                // GET QUESTION ANSWERED ID//
                                                                $answer = "SELECT * FROM cbtquestionsanswers WHERE 

                                                                        cbtsettingsID = '$cbtid' AND StudentID = '$studentID' AND question IN ($rowid)
                                                                                    ORDER BY cbtquestionsanswersID  ASC LIMIT 1";
                                                                        $answerQuery = mysqli_query($link, $answer);  
                                                                        $fetchanswer = mysqli_fetch_assoc($answerQuery);
                                                                        $fetchanswerRow = mysqli_num_rows($answerQuery);
                                                                

                                                                $getAnswer = $fetchanswer['studentAnswer'];

                                                                if($getAnswer == "A"){

                                                                    $check = "checked";

                                                                    echo ' <h5 style="color: black;">a)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                    <h5 style="color: black;">b)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                
                                                                    <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                    <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</label></h5>';
                                                                }
                                                                elseif($getAnswer == "B"){
                                                                        $check = "checked";
                                                                        echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                        <h5 style="color: black;">b)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                    
                                                                        <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                        <h5 style="color: black;">d)   <input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</label></h5>';
                                                                }
                                                                elseif($getAnswer == "C"){
                                                                            $check = "checked";
                                                                            echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                        <h5 style="color: black;">b)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                    
                                                                        <h5 style="color: black;">c)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                        <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</h5>';
                                                            
                                                                }
                                                                elseif($getAnswer == "D"){
                                                                            $check = "checked";
                                                                                echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                                <h5 style="color: black;">b)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                            
                                                                                <h5 style="color: black;">c)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>

                                                                                <h5 style="color: black;">d)   <input class="radioBtnClass" '.$check.' name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$option.'</label></h5>';
                                                                            
                                                                }
                                                                elseif($getAnswer == "0"){

                                                                                    echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1"><?php echo  $optionA;?></label></h5>

                                                                                    <h5 style="color: black;">b)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2"><?php echo  $optionB;?></label></h5>
                                                                                
                                                                                    <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3"><?php echo  $optionC;?></label></h5>
                                                
                                                                                    <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4"><?php echo  $optionD;?></label></h5>';
                                                                                
                                                                }else{
                                                                                    echo ' <h5 style="color: black;">a)   <input class="radioBtnClass"   name="group1" type="radio" id="radio_1" value = "A"/><label for="radio_1">'.$optionA.'</label></h5>

                                                                                    <h5 style="color: black;">b)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'.$optionB.'</label></h5>
                                                                                
                                                                                    <h5 style="color: black;">c)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'.$optionC.'</label></h5>
                                                
                                                                                    <h5 style="color: black;">d)   <input class="radioBtnClass"  name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'.$optionD.'</label></h5>';
                                                                }

                                                
                                                    ?>
                                            </div> 

                                            <div class="row" style="margin-top: 75px;">
                                                <div class="col-sm-10">
                                                    <div>
                                                        <small style="color: red;">
                                                            <b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br> to the question
                                                            by the right before the time runs out. You can also select any<br>question below to answer. 
                                                            Don't forget to click Submit when you are done.
                                                        </small>
                                                    </div>
                                                </div>
                                            </div>
                                            <hr/>

                                            <div class="row" style="margin-top: 30px;">
                                                <div class="col-sm-9 col-xs-9 col-md-9">
                                                    <!--<button type="button" style="font-size: 15px;" data-id="<?php echo $countQ;?>" disabled value="PREV" class="btn waves-effect waves-light btn-rounded btn-secondary previous">Previous</button>-->
                                                </div>

                                                <div class="col-sm-3 col-xs-4 col-md-3">
                                                    <button type="button" style="font-size: 15px;" value="NEXT"  data-id ="<?php echo $countQ;?>" class="btn waves-effect waves-light btn-rounded btn-success next">Next</button>
                                                </div>
                                            </div>

                                        </div>       
                                    </div>   
                                                    
                                    <!--|||||||||||||||||OBJ BEFORE THEORY EXAM |||||||||||||||||\\-->
                            
                                        
                                    <!--|||||||||||||||||THEORY AFTER OBJ EXAM |||||||||||||||||\\-->
                                    <div id="displayteoryform">

                                            <?php

                                                if($selectsettings_result_cnt > 0)
                                                {
                                                
                                                $settingarr2 = $Selectsettings_result_cnt_row['TheoryQuestion'];
                                                    
                                                            
                                                $Select = "SELECT * FROM `questionbank` WHERE `QuestionBankID`='$settingarr2' AND InstitutionID='$InstitutionID' GROUP BY QuestionBankID ASC  LIMIT 1";
                                                $selectQuery = mysqli_query($link, $Select);
                                                $fetch2 = mysqli_num_rows($selectQuery);
                                                    
                                                if($fetch2 == 0){
                                                                                
                                                        echo '<div class="alert alert-info alert-dismissible d-flex align-items-center show">
                                                                    <i class="fa fa-info-circle"></i>
                                                                <strong class="mx-2">Hey!</strong>Please no question attached to this settings.
                                                                </div>
                                                                <a  href="cbtSetting.php"  class="close" aria-label="Close" style="color:red; margin-right:20px;"><i clas="fa fa-back"></i>Back
                                                                </a>'
                                                                ;
                                                }
                                                else{
                                                        while($fetch = mysqli_fetch_array($selectQuery))
                                                        {
                                                            $countQ =  $countQ + 1;
                                                        //    $rowid1 =    $Selectsettings_result_cnt_row['cbtsetquestionssettings'];  

                                                            $question = $fetch['question'];
                                                            $optionA =  $fetch['optionA'];
                                                            $optionB =  $fetch['optionB'];
                                                            $optionC =  $fetch['optionC'];
                                                            $optionD =  $fetch['optionD'];
                                                            $images =   $fetch['images'];
                                                            $rowid =    $fetch['QuestionBankID'];
                                                                            
                                                    }
                                                }
                                                }

                                                        
                                            ?>

                                                    
                                                <a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a>
                                                    <h1 style="font-style: italic; margin-top: 10px;">(Question <?php  $countQ = 1;echo $countQ;?>)</h1>
                                                    <?php
                                                        echo'<h4>'.$question.'</h4><br>';
                                                        
                                                    ?>
                                                    <label>Enter your Answer in the Field Below</label>
                                                    <textarea id="optionA1" class="wrs_div_box example question" contenteditable="true" tabindex="0" spellcheck="true" role="textbox"></textarea>
                                                        <div class="row" style="margin-top: 75px;">
                                                            <div class="col-sm-10">
                                                                <div>
                                                                    <small style="color: red;">
                                                                        <b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish
                                                                        before the time runs out. You can also click on Previous to go backward. 
                                                                        Don't forget to click Submit when you are done.
                                                                    </small>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <hr/> 

                                                        <div class="row" style="margin-top: 30px;">
                                                            <div class="col-sm-9 col-xs-9 col-md-9"> 
                                                                <!--<button type="button" style="font-size: 15px;" data-id="" disabled value="PREV" class="btn waves-effect waves-light btn-rounded btn-secondary previous">Previous</button>-->
                                                            </div>

                                                            <div class="col-sm-3 col-xs-4 col-md-3">
                                                                    <button type="button" style="font-size: 15px;" value="NEXT"  data-id ="<?php echo $countQ;?>" class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button>
                                                            </div>
                                                        </div>
                        
                                    </div>
                                    <!--|||||||||||||||||THEORY AFTER OBJ EXAM |||||||||||||||||\\-->
                                                                                

                                    <?php
                                        }
                                    ?>

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

                        <div  class="col-sm-4" style="height: 100%; width: 100%; margin-top: 20px;">
                            <div class="card">
                                <div class="card-body" style="background-color: rgb(255, 255, 255); box-shadow: 1px 3px 10px #C4DDEB;">
                                    <?php
                                
                                        $Select = "SELECT * FROM `cbtsetquestionssettings` WHERE  `cbtsetquestionssettingsID` = '$cbtid'";
                                        $selectQuery = mysqli_query($link, $Select);

                                        while($fetch = mysqli_fetch_array($selectQuery))
                                        {
                                            
                                            $subject =  $fetch['SubjectOrCourseID'];

                                            $Select1 = "SELECT * FROM  `subjectorcourse` WHERE  SubjectOrCourseID = '$subject'";
                                            $selectQuery1 = mysqli_query($link, $Select1);
                                            $fetch2 = mysqli_fetch_array($selectQuery1);
                                            $subjectName = $fetch2['SubjectOrCourseTitle'];
                                            $date = $fetch['AssesementDate'];
                                                
                                                $time1 =  strtotime($fetch['AssesementStartTime']);
                                                $time2  =  strtotime($fetch['AssesementEndTime']);
                                                
                                                
                                                $difference = $time2 - $time1;   
                                                
                                                
                                                
                                                    
                                                    
                                                
                                                    $hour = ($difference / 3600);
                                                    ;
                                                    $hour = ($hour % 24);
                                                    
                                                    $minute = ($difference / 60 % 60);
                                                    
                                                    $seconds = ($difference % 60);
                                                    
                                                        //   $totaldiff = $hour + $minute + $seconds;
                                                
                                                        $totaldiff = strtotime($hour.':'.$minute .':'.$seconds);

                                                
                                                
                                                
                                                            $midnight = strtotime('12:00:00 AM');
                                                
                                                            $midtwo =  strtotime(date('h:i:sa',$midnight));

                                                                
                                        }
                                                

                                    ?>

                                    <h2 align="center">Time Left</h2>
                                    <h3 style="color:#FF0000; font-size:30px;" align="center" >
                                        <span id='timer'></span>
                                    </h3>
                                        
                    
                                    <div class="row" style="margin-top: 40px;">
                                        <div class="col-sm-12 col-xs-12 col-md-12">
                                            <?php

                                                $selectques_set2 = "SELECT * FROM `cbtquestionsanswers` WHERE InstitutionID = '$CampusID' AND  `cbtsetquestionssettingsID` = '$cbtid' AND StudentID='$UserID'";
                                                $selectquws_set2_result = mysqli_query($link, $selectques_set2);
                                                $selectques_set2_result_cnt = mysqli_num_rows($selectquws_set2_result);
                                                $selectques_set2_result_cnt_row = mysqli_fetch_assoc($selectquws_set2_result);

                                                if($selectques_set2_result_cnt > 0)
                                                {
                                                        $countkey = 0;
                                                        $counquestion_num =1;
                                                        $countkey = 0;
                                                        $counquestion_numtheory =1;
                                                        $countkeytheory = 0;

                                                        $selectqustion2 =  $selectques_set2_result_cnt_row['question'];   
                                                        $splitques2 = explode(',', $selectqustion2);
                                                        
                                                            $selectqustion_theory =  $selectques_set2_result_cnt_row['TheoryQuestion'];   
                                                            $splitques2_theory = explode(',', $selectqustion_theory);
                                                        
                                                        
                                                            if($getstatusforquestion == '0')
                                                            {
                                                            foreach($splitques2 as $slit2arr)
                                                            {
                                                                        $counquestion_num++; 
                                                                        $countkey++;

                                                                        $newquenum  =   $counquestion_num -1;
                                                                        $questionkey2  =  $countkey -1;
                                                                        
                                                                        $slit2arr; 
                                                                
                                                                        $Select1 = "SELECT * FROM  `questionbank` WHERE  `InstitutionID` = '$InstitutionID'  AND QuestionBankID='$slit2arr' ORDER BY QuestionBankID ASC";
                                                                        $selectQuery1 = mysqli_query($link, $Select1);
                                                                        $fetch1 = mysqli_fetch_array($selectQuery1);

                                                                
                                                                        $question =  $fetch1['question'];
                                                                        $optionA =  $fetch1['optionA'];
                                                                        $optionB =  $fetch1['optionB'];
                                                                        $optionC =  $fetch1['optionC'];
                                                                        $optionD =  $fetch1['optionD'];

                                                                        $cbt_setting_id =  $fetch1['QuestionBankID'];
                                                                        
                                                                        
                                                                            
                                                                        

                                                                        $fetchData = "SELECT studentAnswer FROM cbtquestionsanswers WHERE   `cbtsettingsID` = '$cbtid' AND StudentID='$UserID' ORDER BY cbtquestionsanswersID ASC";
                                                                        $fetchDataQuery = mysqli_query($link, $fetchData);
                                                                        $fetchDataResult = mysqli_fetch_assoc($fetchDataQuery);
                                                                        $fetchDataResultRow = mysqli_num_rows($fetchDataQuery);

                                                                        echo '<button style="font-weight: 600;  font-size: 14px; margin: 2px;" id="'.$newquenum.'" type="button" data-id="'.$questionkey2.'" class="btn btn-success viewer">'.$newquenum.'</button>';
                                                                }

                                                                        echo '<div class="row" style="margin-top: 20px; margin-left: 10px;">
                                                                        <div class="col-sm-3 col-xs-3 col-md-3">
                                                                            <button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal"   value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-primary submit">Submit</button>
                                                                        </div>
                                                                        </div>';
                                                            }elseif($getstatusforquestion == '1')
                                                            {
                                                                            foreach($splitques2_theory as $slit2arr_theory)
                                                                            {
                                                                                        $counquestion_num++; 
                                                                                        $countkey++;

                                                                                            $newquenum  =   $counquestion_num -1;
                                                                                        $questionkey2  =  $countkey -1;
                                                                                    
                                                                                        $slit2arr_theory; 
                                                                                
                                                                                        $Select1 = "SELECT * FROM  `questionbank` WHERE  `InstitutionID` = '$InstitutionID'  AND QuestionBankID='$slit2arr_theory'  AND `QuestionCategory`='Essay' ORDER BY QuestionBankID ASC";
                                                                                        $selectQuery1 = mysqli_query($link, $Select1);
                                                                                        $fetch1 = mysqli_fetch_array($selectQuery1);

                                                                                
                                                                                                $question =  $fetch1['question'];
                                                                                        

                                                                                                $cbt_setting_id =  $fetch1['QuestionBankID'];
                                                                                        
                                                                                        
                                                                                            
                                                                                    

                                                                                        $fetchData = "SELECT studentAnswer FROM cbtquestionsanswers WHERE   `cbtsettingsID` = '$cbtid' AND StudentID='$UserID' ORDER BY cbtquestionsanswersID ASC";
                                                                                        $fetchDataQuery = mysqli_query($link, $fetchData);
                                                                                        $fetchDataResult = mysqli_fetch_assoc($fetchDataQuery);
                                                                                        $fetchDataResultRow = mysqli_num_rows($fetchDataQuery);

                                                                                        echo '<button style="font-weight: 600;  font-size: 14px; margin: 2px;" id="'.$newquenum.'" type="button" data-id="'.$questionkey2.'" class="btn btn-success viewertheory">'.$newquenum.'</button>';
                                                                            } 
                                                                            
                                                                                        echo '<div class="row" style="margin-top: 20px; margin-left: 10px;">
                                                                                                <div class="col-sm-3 col-xs-3 col-md-3">
                                                                                                        <button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal_theory"   value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-primary submittheory">Submit</button>
                                                                                                </div>
                                                                                        </div>';
                
                                                            }elseif($getstatusforquestion == '2')
                                                            {

                                                        

                                                                        echo '<div id="onbnumdiv">';
                                                                                foreach($splitques2 as $slit2arr)
                                                                                {
                                                                                            $counquestion_num++; 
                                                                                            $countkey++;

                                                                                            $newquenum  =   $counquestion_num -1;
                                                                                            $questionkey2  =  $countkey -1;
                                                                                            
                                                                                            $slit2arr; 
                                                                                    
                                                                                            $Select1 = "SELECT * FROM  `questionbank` WHERE  `InstitutionID` = '$InstitutionID'  AND QuestionBankID='$slit2arr' ORDER BY QuestionBankID ASC";
                                                                                            $selectQuery1 = mysqli_query($link, $Select1);
                                                                                            $fetch1 = mysqli_fetch_array($selectQuery1);

                                                                                    
                                                                                            $question =  $fetch1['question'];
                                                                                            $optionA =  $fetch1['optionA'];
                                                                                            $optionB =  $fetch1['optionB'];
                                                                                            $optionC =  $fetch1['optionC'];
                                                                                            $optionD =  $fetch1['optionD'];

                                                                                            $cbt_setting_id =  $fetch1['QuestionBankID'];
                                                                                            
                                                                                            
                                                                                                
                                                                                        

                                                                                            $fetchData = "SELECT studentAnswer FROM cbtquestionsanswers WHERE   `cbtsettingsID` = '$cbtid' AND StudentID='$UserID' ORDER BY cbtquestionsanswersID ASC";
                                                                                            $fetchDataQuery = mysqli_query($link, $fetchData);
                                                                                            $fetchDataResult = mysqli_fetch_assoc($fetchDataQuery);
                                                                                            $fetchDataResultRow = mysqli_num_rows($fetchDataQuery);

                                                                                            echo '<button style="font-weight: 600;  font-size: 14px; margin: 2px;" id="'.$newquenum.'" type="button" data-id="'.$questionkey2.'" class="btn btn-success viewer">'.$newquenum.'</button>';
                                                                                    }   

                                                                                    echo '<div class="row" style="margin-top: 20px; margin-left: 10px;">
                                                                                    <div class="col-sm-3 col-xs-3 col-md-3">
                                                                                        <button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal"   value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-primary submit">Submit</button>
                                                                                    </div>
                                                                                    </div>';
                                                                            
                                                                    echo '</div>';  
                                                                    
                                                                    
                                                                    echo '<div id="theorynumdiv">';

                                                                                        foreach($splitques2_theory as $slit2arr_theory)
                                                                                        {
                                                                                                    $counquestion_numtheory++; 
                                                                                                    $countkeytheory++;
        
                                                                                                    $newquenumtheory  =   $counquestion_numtheory -1;
                                                                                                    $questionkey2theory  =  $countkeytheory -1;
                                                                                                
                                                                                                    $slit2arr_theory; 
                                                                                            
                                                                                                    $Select1 = "SELECT * FROM  `questionbank` WHERE  `InstitutionID` = '$InstitutionID'  AND QuestionBankID='$slit2arr_theory'  AND `QuestionCategory`='Essay' ORDER BY QuestionBankID ASC";
                                                                                                    $selectQuery1 = mysqli_query($link, $Select1);
                                                                                                    $fetch1 = mysqli_fetch_array($selectQuery1);
        
                                                                                            
                                                                                                        $question =  $fetch1['question'];
                                                                                                
        
                                                                                                        $cbt_setting_id =  $fetch1['QuestionBankID'];
                                                                                                    
                                                                                                    
                                                                                                        
                                                                                                
        
                                                                                                    $fetchData = "SELECT studentAnswer FROM cbtquestionsanswers WHERE   `cbtsettingsID` = '$cbtid' AND StudentID='$UserID' ORDER BY cbtquestionsanswersID ASC";
                                                                                                    $fetchDataQuery = mysqli_query($link, $fetchData);
                                                                                                    $fetchDataResult = mysqli_fetch_assoc($fetchDataQuery);
                                                                                                    $fetchDataResultRow = mysqli_num_rows($fetchDataQuery);
        
                                                                                                    echo '<button style="font-weight: 600;  font-size: 14px; margin: 2px;" id="'.$newquenumtheory.'" type="button" data-id="'.$questionkey2theory.'" class="btn btn-success viewertheory">'.$newquenumtheory.'</button>';
                                                                                        }  

                                                                                        echo '<div class="row" style="margin-top: 20px; margin-left: 10px;">
                                                                                        <div class="col-sm-3 col-xs-3 col-md-3">
                                                                                                <button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal_theory" data-id ="'.$countQ.'"   value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-primary submittheory">Submit</button>
                                                                                        </div>
                                                                                            </div>';
                                                                    echo '</div>';  
                                                                }                     
                                                }

                                            ?> 
                                        </div>
                                        
                                    </div>

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


                        <!--==== Submit Modal objective==== -->
                        <div class="modal" id="submitClassModal" tabindex="-1" aria-labelledby="submitClassModalLabel" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-scrollable">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h2 style="margin-left: 30%;">Are you Sure?</h2>
                                            <br>               
                                    </div>
                                    <div class="modal-body" align="Center">
                                        <div id="submittedmsg"></div>
                                        <div><i style="color: #ff0000; font-size: 40px;" class="mdi mdi-close" ></i></div>
                                        <p>Do you really want to Submit?<br>Make Sure you have answered all the Question</p>
                                    </div>
                                    <div align="Center" style="margin-bottom: 40px;">
                                        <button type="button" class="btn chimaCancelBtn" data-dismiss="modal">Cancel</button>
                                        <button type="button" id="submited" class="btn chimaProceedBtn" data-dismiss="modal" style="width: 120px;" >Yes!</button>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <!--==== Submit Modal Theory==== -->
                        <div class="modal" id="submitClassModal_theory" tabindex="-1" aria-labelledby="submitClassModal_theoryLabel" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-scrollable">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h2 style="margin-left: 30%;">Are you Sure?</h2>
                                        <br>               
                                    </div>
                                    <div class="modal-body" align="Center">
                                        <div id="submittedmsg"></div>
                                        <div><i style="color: #ff0000; font-size: 40px;" class="mdi mdi-close" ></i></div>
                                        <p>Do you really want to Submit?<br>Make Sure you have answered all the Question</p>
                                        </div>
                                    <div align="Center" style="margin-bottom: 40px;">
                                        <button type="button" class="btn chimaCancelBtn" data-dismiss="modal">Cancel</button>
                                        <button type="button" id="submited_theory" class="btn chimaProceedBtn" data-dismiss="modal" style="width: 120px;" >Yes!</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--==== Exit Modal==== -->

                        <!--==== Class Modal==== -->
                        <div class="modal" id="exitClassModal" tabindex="-1" aria-labelledby="exitClassModalLabel" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-scrollable">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h2 style="margin-left: 30%;">Are you Sure?</h2>
                                            <br>               
                                    </div>
                                    <div class="modal-body" align="Center">
                                        <div><i style="color: #ff0000; font-size: 40px;" class="mdi mdi-close" ></i></div>
                                        <p>Do you really want to Exit?<br>Please note that this process cannot be reversed</p>
                                    </div>
                                    <div align="Center" style="margin-bottom: 40px;">
                                        <button type="button" class="btn chimaCancelBtn" data-dismiss="modal">Cancel</button>
                                        <button type="button" id="exit-btn" class="btn chimaProceedBtn"  style="width: 120px;" data-dismiss="modal">Yes!</button>
                                    </div>
                                </div>
                            </div>    
                        </div>
                        <!--==== Exit Class Modal==== -->

                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
                    </div>
                    <!-- ============================================================== -->
                    <!-- End Container fluid  -->
                    <!-- ============================================================== -->
                    <!-- ============================================================== -->
                    <!-- footer -->
                    <!-- ============================================================== -->
                    <!-- <?php include ('../includes/footer.php'); ?> -->
                    <!-- ============================================================== -->
                    <!-- End footer -->
                    <!-- ============================================================== -->
          </div>
            <!-- ============================================================== -->
            <!-- End Page wrapper  -->
            <!-- ============================================================== -->
    </div>
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="../library/plugins/jquery/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="../library/plugins/bootstrap/js/popper.min.js"></script>

    <script src="../library/plugins/bootstrap/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="../js/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="../js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="../js/sidebarmenu.js"></script>
    <!--stickey kit -->
    <script src="../library/plugins/sticky-kit-master/dist/sticky-kit.min.js"></script>
    <script src="../library/plugins/sparkline/jquery.sparkline.min.js"></script>
    <!--Custom JavaScript -->
    <script src="../js/custom.min.js"></script>
    <!--morris JavaScript -->
    <script src="../library/plugins/raphael/raphael-min.js"></script>
    <script src="../library/plugins/morrisjs/morris.min.js"></script>
    <!-- sparkline chart -->
    <!-- Footable -->
    <script src="../library/plugins/footable/js/footable.all.min.js"></script>
    <script src="../library/plugins/bootstrap-select/bootstrap-select.min.js" type="text/javascript"></script>
    <!--FooTable init-->
    
    <script src="../js/footable-init.js"></script>

    <!-- Bootstrap tether Core JavaScript -->
    <!-- slimscrollbar scrollbar JavaScript -->
    <!--Wave Effects -->
    <!--Menu sidebar -->
    <!--stickey kit -->
    <!--Custom JavaScript -->
    <script src="../library/plugins/sparkline/jquery.charts-sparkline.js"></script>
    <!-- ============================================================== -->
    <!-- Style switcher -->
    <!-- ============================================================== -->
    



    <script src="../library/plugins/sparkline/jquery.sparkline.min.js"></script>
    <script src="../js/dashboard4.js"></script>
    <!-- ============================================================== -->
    <!-- Style switcher -->
    <!-- ============================================================== -->
    <script src="../library/plugins/styleswitcher/jQuery.style.switcher.js"></script>
    <script src="../library/plugins/datatables/jquery.dataTables.min.js"></script>
    <!-- start - This is for export functionality only -->
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    
    <script src="../js/notify.js"></script>
    
  <script type="text/javascript" src="tinymce5/wirislib.js"></script>

<!-----Next and Prev Button---->

  <script>
        $(document).ready(function() {   
            createEditorInstance();
        });  

        $(document).ready(function() {   
               var examstatus = <?php echo $getstatusforquestion; ?>;
                  var questiontype = $('#questiontype').val();
                  
                //   localStorage.setItem("questiontype", questiontype);
                    var questiontypegotten = localStorage.getItem('questiontype');


                    if(questiontypegotten == '' || questiontypegotten === null)
                    {
                            var newvartype = questiontype;
                    }else
                    {
                                  var newvartype = questiontypegotten;
                    }

                    if(examstatus == '2')
                    {
                          
    
                            if(newvartype == 'obj')
                            {
                                    $("#displayteoryform").hide() ;  
                                    $("#theorynumdiv").hide() ;  
    
                                    $("#displayResults").show() ;  
                                    $("#onbnumdiv").show();            
                            }else if(newvartype == 'theo')
                            {
                                    $("#displayteoryform").show() ;  
                                    $("#theorynumdiv").show() ;  
    
                                    $("#displayResults").hide() ;  
                                    $("#onbnumdiv").hide();  
                                            
                            }else
                            {
                                    $("#displayteoryform").hide() ;  
                                    $("#theorynumdiv").hide() ;  
                                    
                                    $("#displayResults").show() ;  
                                    $("#onbnumdiv").show();     
                            }
    
                                       
    
    
                    }
              
                      
       });        

  </script>

<script>
    $(document).ready(function() {
        createEditorInstance();
    });
</script>

<script>

  $(document).ready(function(){

       //Click PREVIOUS OBJECTIVE QUESTION   
        $("body").on('click', '.previous', function(){

               $("html,body").animate({
                        scrollTop: 0
                    }, 'fast'); 

            //   localStorage.removeItem("questionkey");
            //   localStorage.removeItem("questionanser");
            //   localStorage.removeItem("questionNo");

                var cbt_id = '<?php echo $cbtid?>';
                var UserID = '<?php echo $UserID?>';
                var InstitutionID  = <?php echo $InstitutionID;?>;
                var currentkeyvalue = parseInt($('#nxtprevquestion').val());
                var arrayanwer = $('#currentanwernxt').val();
                var getanswerarr = arrayanwer.split(",");
                 
                var questionNo =  parseInt($('#questionNo').val());

         
               
             if($("input[type='radio'].radioBtnClass").is(':checked')) {
                     var answer = $("input[type='radio'].radioBtnClass:checked").val();
                     const jsontext = <?php echo $ecodedquestions; ?>;
                     const result  = JSON.stringify(jsontext)
                     const obj = JSON.parse(result);
                     var lengthofquestion_object = Object.keys(obj).length;
                     var newkeyvalue =  parseInt(currentkeyvalue);
                     var newarraykey = newkeyvalue -1;
                     var newquestionNo = questionNo - 1;
                      getanswerarr[currentkeyvalue] = answer;
                    
                    var newquestion = obj[newarraykey].question;
                    var newoptionA = obj[newarraykey].optionA;
                    var newoptionB = obj[newarraykey].optionB;
                    var newoptionC = obj[newarraykey].optionC;
                    var newoptionD = obj[newarraykey].optionD;


                    $("#displayResults").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal"  class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  '+newquestionNo+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass"  name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button id="prevbtn" type="button" style="font-size:15px;" id="disable"  value="PREV"    class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;" id=""  value="NEXT"  class="btn waves-effect waves-light btn-rounded btn-success  next">Next</button></div></div>');
                   
                    if(newquestionNo < 0)
                     {
                          $('#prevbtn').hide('slow');
                         $('.previous').prop('disabled',true);
                         
                     }else
                     {
                      
                        $('#currentanwernxt').val(getanswerarr);
                        $('#nxtprevquestion').val(newarraykey);
                        $('#questionNo').val(newquestionNo);
                        // $.notify("Question Succesfully Answered", "success"); 
                           $('.previous').prop('disabled', false);
                     }

                    
                       if(getanswerarr[newarraykey] == 'A')
                        {
                              $('#radio_1').prop('checked',true);
                              $('#radio_2').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',false);
                        }else if(getanswerarr[newarraykey] == 'B')
                        {
                              $('#radio_2').prop('checked',true);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',false);
                        }else if(getanswerarr[newarraykey] == 'C')
                        {
                              $('#radio_2').prop('checked',false);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',true);
                              $('#radio_4').prop('checked',false);
                        }else if(getanswerarr[newarraykey] == 'D')
                        {
                              $('#radio_2').prop('checked',false);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',true);          
                        }else
                        {
                              $('#radio_2').prop('checked',false);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',false);  
                       }

                        
                            
                           
                            localStorage.setItem("questionkey", $('#nxtprevquestion').val());
                            localStorage.setItem("questionanser",  $('#currentanwernxt').val());  
                            localStorage.setItem("questionNo", $('#questionNo').val());

            }else{
                        var answer = 0;  
                        const jsontext = <?php echo $ecodedquestions; ?>;
                        const result  = JSON.stringify(jsontext)
                        const obj = JSON.parse(result);
                        var lengthofquestion_object = Object.keys(obj).length;
                        var newkeyvalue =  parseInt(currentkeyvalue);
                        var newarraykey = newkeyvalue -1;
                        var newquestionNo = questionNo - 1;
                       
                        var newquestion = obj[newarraykey].question;
                        var newoptionA = obj[newarraykey].optionA;
                        var newoptionB = obj[newarraykey].optionB;
                        var newoptionC = obj[newarraykey].optionC;
                        var newoptionD = obj[newarraykey].optionD;

                       
                     $("#displayResults").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  '+newquestionNo+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass" name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button id="prevbtn" type="button" style="font-size: 15px;"   value="PREV"     class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;"   value="NEXT"  class="btn waves-effect waves-light btn-rounded btn-success next">Next</button></div></div>');

                    



                     if(newquestionNo < 0)
                     {
                            $('#prevbtn').hide('slow');
                          $('.previous').prop('disabled',true);
                        
                         
                     }else
                     {
                         $('#nxtprevquestion').val(newarraykey);
                          $('#questionNo').val(newquestionNo);
                         $('.previous').prop('disabled', false);
                     }

                     if(getanswerarr[newarraykey] == 'A')
                        {
                              $('#radio_1').prop('checked',true);
                              $('#radio_2').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',false);
                        }else if(getanswerarr[newarraykey] == 'B')
                        {
                              $('#radio_2').prop('checked',true);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',false);
                        }else if(getanswerarr[newarraykey] == 'C')
                        {
                              $('#radio_2').prop('checked',false);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',true);
                              $('#radio_4').prop('checked',false);
                        }else if(getanswerarr[newarraykey] == 'D')
                        {
                              $('#radio_2').prop('checked',false);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',true);          
                        }else
                        {
                              $('#radio_2').prop('checked',false);
                              $('#radio_1').prop('checked',false);
                              $('#radio_3').prop('checked',false);
                              $('#radio_4').prop('checked',false);     
                              $.notify("Question Not Answered", "warning");
                        }
                     
                        localStorage.setItem("questionkey", $('#nxtprevquestion').val());
                        localStorage.setItem("questionanser",  $('#currentanwernxt').val());  
                        localStorage.setItem("questionNo", $('#questionNo').val());
                     
                    
                       

              
            }
        });
         //Click PREVIOUS OBJECTIVE QUESTION 

        //Click NXT OBJECTIVE QUESTION   
        $("body").on('click', '.next', function(){
            $("html,body").animate({
                    scrollTop: 0
                }, 'fast'); 

            // localStorage.removeItem("questionkey");
            // localStorage.removeItem("questionanser");
            // localStorage.removeItem("questionNo");

            var cbt_id = <?php echo $cbtid?>;
            var UserID = '<?php echo $UserID?>';
            var InstitutionID  = <?php echo $InstitutionID;?>;
            var currentkeyvalue = parseInt($('#nxtprevquestion').val());
            var arrayanwer = $('#currentanwernxt').val();
            var getanswerarr = arrayanwer.split(",");
            var questionNo =  parseInt($('#questionNo').val());
                
            
    
            if($("input[type='radio'].radioBtnClass").is(':checked')) {
                var answer = $("input[type='radio'].radioBtnClass:checked").val();

                    const jsontext = <?php echo $ecodedquestions; ?>;
                    const result  = JSON.stringify(jsontext);
                    const obj = JSON.parse(result);
                    var lengthofquestion_object = Object.keys(obj).length;
                    getanswerarr[currentkeyvalue] = answer;
                    var newkeyvalue =  parseInt(currentkeyvalue);
                    var newarraykey = newkeyvalue + 1;
                    var newquestionNo = questionNo + 1;
                    
                    $('#currentanwernxt').val(getanswerarr);
                
                    if( newquestionNo > lengthofquestion_object )
                    {
                    //    newarraykey = newarraykey-1;  
                        
                        
                        $('.next').prop('disabled', true);
                        $('.previous').prop('disabled', false);
                        $('#submitnex').html('<button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal"   value="NEXT" class="btn waves-effect waves-light btn-rounded btn-success submit">Submit</button>')
                        
                    }else
                    {
                        $('#questionNo').val(newquestionNo);  
                        $('#nxtprevquestion').val(newarraykey);
                        
                        $('.next').prop('disabled', false); 
                        $('.previous').prop('disabled', false);
                    
                    }
                    

                    var newquestion = obj[newarraykey].question;
                    var newoptionA = obj[newarraykey].optionA;
                    var newoptionB = obj[newarraykey].optionB;
                    var newoptionC = obj[newarraykey].optionC;
                    var newoptionD = obj[newarraykey].optionD;
                    
                        $("#displayResults").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal"   class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  '  +newquestionNo+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass" name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button type="button" style="font-size: 15px;"   value="PREV" data-id=""    class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div id="submitnex" class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;"   value="NEXT" class="btn waves-effect waves-light btn-rounded btn-success next">Next</button></div></div>');
                    

                    if(getanswerarr[newarraykey] == 'A')
                    {
                            $('#radio_1').prop('checked',true);
                            $('#radio_2').prop('checked',false);
                            $('#radio_3').prop('checked',false);
                            $('#radio_4').prop('checked',false);
                    }else if(getanswerarr[newarraykey]  == 'B')
                    {
                            $('#radio_2').prop('checked',true);
                            $('#radio_1').prop('checked',false);
                            $('#radio_3').prop('checked',false);
                            $('#radio_4').prop('checked',false);
                    }else if (getanswerarr[newarraykey]  == 'C')
                    {
                            $('#radio_2').prop('checked',false);
                            $('#radio_1').prop('checked',false);
                            $('#radio_3').prop('checked',true);
                            $('#radio_4').prop('checked',false);
                    }else if(getanswerarr[newarraykey]  == 'D')
                    {
                            $('#radio_2').prop('checked',false);
                            $('#radio_1').prop('checked',false);
                            $('#radio_3').prop('checked',false);
                            $('#radio_4').prop('checked',true);          
                    }else
                    {
                        
                            $('#radio_2').prop('checked',false);
                            $('#radio_1').prop('checked',false);
                            $('#radio_3').prop('checked',false);
                            $('#radio_4').prop('checked',false);     
                    }

                        
                        localStorage.setItem("questionkey", $('#nxtprevquestion').val());
                        localStorage.setItem("questionanser", $('#currentanwernxt').val());  
                        localStorage.setItem("questionNo", $('#questionNo').val());

                    
            }else
            {
                
                var answer = 0;  
                const jsontext = <?php echo $ecodedquestions; ?>;
                const result  = JSON.stringify(jsontext)
                const obj = JSON.parse(result);
                var lengthofquestion_object = Object.keys(obj).length;
                
                var newkeyvalue =  parseInt(currentkeyvalue);
                var newarraykey = newkeyvalue + 1;
                var questionAswered = $("#currentanwernxt").val();
                var anwerToArray = questionAswered.split(",");
                var newquestionNo = questionNo + 1;
                
                if(newquestionNo > lengthofquestion_object)
                {
                    $('.next').prop('disabled', true);
                    $('#submitnex').html('<button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal"  value="NEXT" class="btn waves-effect waves-light btn-rounded btn-success submit">Submit</button>')
                    
                }else
                {
                    $('#questionNo').val(newquestionNo);  
                    $('#nxtprevquestion').val(newarraykey);
                    $('.next').prop('disabled', false); 
                    // $.notify("Question Not Answered", "warning");   
                }
                        
                var newquestion = obj[newarraykey].question;
                var newoptionA = obj[newarraykey].optionA;
                var newoptionB = obj[newarraykey].optionB;
                var newoptionC = obj[newarraykey].optionC;
                var newoptionD = obj[newarraykey].optionD;

                        
                $("#displayResults").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal"  class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  ' +newquestionNo+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass" name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button type="button" style="font-size: 15px;"   value="PREV"     class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div id="submitnex" class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;"   value="NEXT"  class="btn waves-effect waves-light btn-rounded btn-success next">Next</button></div></div>');


                if(getanswerarr[newarraykey] == 'A')
                {
                    
                        $('#radio_1').prop('checked',true);
                        $('#radio_2').prop('checked',false);
                        $('#radio_3').prop('checked',false);
                        $('#radio_4').prop('checked',false);
                }else if(getanswerarr[newarraykey] == 'B')
                {
                    
                        $('#radio_2').prop('checked',true);
                        $('#radio_1').prop('checked',false);
                        $('#radio_3').prop('checked',false);
                        $('#radio_4').prop('checked',false);
                }else if(getanswerarr[newarraykey] == 'C')
                {
                    
                        $('#radio_2').prop('checked',false);
                        $('#radio_1').prop('checked',false);
                        $('#radio_3').prop('checked',true);
                        $('#radio_4').prop('checked',false);
                }else if(getanswerarr[newarraykey] == 'D')
                {
                        $('#radio_2').prop('checked',false);
                        $('#radio_1').prop('checked',false);
                        $('#radio_3').prop('checked',false);
                        $('#radio_4').prop('checked',true);    
                }else
                {
                    
                        $('#radio_2').prop('checked',false);
                        $('#radio_1').prop('checked',false);
                        $('#radio_3').prop('checked',false);
                        $('#radio_4').prop('checked',false);  
                        
                }

                localStorage.setItem("questionkey", $('#nxtprevquestion').val());
                localStorage.setItem("questionanser", $('#currentanwernxt').val());  
                localStorage.setItem("questionNo", $('#questionNo').val());
        
            }
                
        });
        //Click NXT OBJECTIVE QUESTION 
    });




    $("body").on('click', '.previoustheory', function(){
        tinyMCE.triggerSave();
                    // var questionkey_local = localStorage.getItem('questionkeytheory');
                    // var questionanser_local = localStorage.getItem('questionansertheory');
                    // var questionno_local = localStorage.getItem('questionNotheory');
                  

                   
                              $("html,body").animate({
                                    scrollTop: 0
                                }, 'fast'); 

                                    
                                  var answer =  [];
                                    
                                    $m = 1;
                                    $.each($(".example"), function(){
                                        answer.push($(this).val()+"Nil##");
                                        $m++;
                                    });
            
                                    var cbt_id = <?php echo $cbtid?>;
                                    var UserID = '<?php echo $UserID?>';
                                    var InstitutionID  = <?php echo $InstitutionID;?>;
                                    var currentkeyvalue = parseInt($('#nxtprevquestiontheory').val());
                                                         
                                    var arrayanwer = $('#currentanwernxttheory').val();
                                    var getanswerarr = arrayanwer.split(",");
                                    var questionNo =  parseInt($('#questionNotheory').val());
                                    
                                    
                                         const jsontext = <?php echo $ecodedquestionstheory; ?>;
                                        const result  = JSON.stringify(jsontext);
                                        const obj = JSON.parse(result);
                                        var lengthofquestion_object = Object.keys(obj).length;
                                    
                                        var newkeyvalue =  parseInt(currentkeyvalue);
                                        var newarraykey = newkeyvalue - 1;
                                        var newquestionNo = questionNo - 1;
                                                 
                   
                        if(answer == '##' || answer == 'Nil##' || answer == 'Nil')
                        {

                                              $.notify("Not  Answered", "warning");
                                               
                                                var newanswer = 'Nil##';
                                               
                                                
                                                var newquestion = obj[newarraykey].question;
                                                getanswerarr[newkeyvalue] = newanswer;
                                            
                                            
                                              

                                                             var questionkey = localStorage.getItem('questionkeytheory');
                                                            var questionansernew= localStorage.getItem('questionansertheory');
                                                            var questionno = localStorage.getItem('questionNotheory');
                                            
                                                             var questionanswer2_again = questionansernew.split(",");
                                                             var newanswerload_new =  questionanswer2_again[newarraykey];
                                                            
                                                              let resultreplacestring = newanswerload_new.toString();
                                                              let resultreplace = resultreplacestring.replace(/Nil##/g, "");
                                                              

                                                            if(resultreplace == 'Nil' || resultreplace  == '##' || resultreplace == 'Nil##')
                                                            {
                                                                    var newanswerload  = '';
                                                            }else
                                                            {
                                                                         var newanswerload  = resultreplace;
                                                
                                                            }
                                                               
                                                                   
                                                           
                                                            $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + newquestionNo + ')'+'</h1><h6>'+newquestion+'</h6><br>   <label>Enter your Answer in the Field Below</label><textarea id="optionA1" class="wrs_div_box example question" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;"  value="PREV" id="prevbtntheory" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3" id="submitnextheory"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                                                            resetEditor();
                                                            createEditorInstance();
                                                            tinyMCE.get('optionA1').setContent(newanswerload);
                                                            
                                                                            
                                                                  if(newkeyvalue = 0)
                                                                {
                                                                        
                                                                      // $('#prevbtntheory').hide('slow');
                                                                        $('.previoustheory').prop('disabled',true);
                                                                }else
                                                                {
                                                                    $('.previoustheory').prop('disabled', false);
                                                                    $('#currentanwernxttheory').val(getanswerarr);
                                                                    $('#nxtprevquestiontheory').val(newarraykey);
                                                                    $('#questionNotheory').val(newquestionNo);
                                                                     // $.notify("Question Succesfully Answered", "success"); 
                                                                      //    alert('hello');
                                                                }
                                                
                                                            localStorage.setItem("questionkeytheory", $('#nxtprevquestiontheory').val());
                                                            localStorage.setItem("questionansertheory",  $('#currentanwernxttheory').val());  
                                                            localStorage.setItem("questionNotheory", $('#questionNotheory').val());
                        }else
                        {
                            
                                    
                                     
                                                var newquestion = obj[newquestionNo].question;
                                                 getanswerarr[newarraykey] = answer;
                                                 
                                                
                                                
                                 
                         
                                                var questionkey = localStorage.getItem('questionkeytheory');
                                                var questionansernew = localStorage.getItem('questionansertheory');
                                                var questionno = localStorage.getItem('questionNotheory');
                                                
                                                
                                                  
                                                   
                                                var questionanswer2 = questionansernew.split(",");
                                                var newanswerload_new = questionanswer2[newarraykey];
                                
                                                let resultreplacestring = newanswerload_new.toString();
                                               
                                                let resultreplace = resultreplacestring.replace(/Nil##/g, "");
                                                
                                                 if(resultreplace == 'Nil' || resultreplace == '##' || resultreplace == 'Nil##')
                                                 {
                                                        var  newanswerload  = '';
                                                }else
                                                {        
                                                    var newanswerload  = resultreplace;     
                                                }
                                       
                                                        
                                                $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + newquestionNo + ')'+'</h1><h6>'+newquestion+'</h6><br><label>Enter your Answer in the Field Below</lable><textarea id="optionA1" class="wrs_div_box example question" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;" disabled value="PREV" id="prevbtntheory" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3" id="submitnextheory"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                                                resetEditor();
                                                createEditorInstance();
                                                tinyMCE.get('optionA1').setContent(newanswerload);
                                                            
                                                
         
                                                  if(newquestionNo < 0)
                                                 {
                                                    $('#prevbtntheory').hide('slow');
                                                    $('.previoustheory').prop('disabled',true);
                                                }else
                                                {
                                                    $('.previoustheory').prop('disabled', false);
                                                    $('#currentanwernxttheory').val(getanswerarr);
                                                    $('#nxtprevquestiontheory').val(newarraykey);
                                                    $('#questionNotheory').val(newquestionNo);
                                                  }
                                                
                                                        
                                                        
                                                localStorage.setItem("questionkeytheory", $('#nxtprevquestiontheory').val());
                                                localStorage.setItem("questionansertheory",  $('#currentanwernxttheory').val());  
                                                localStorage.setItem("questionNotheory", $('#questionNotheory').val());
                          }
                     

           
        });

      $("body").on('click', '.nexttheory', function(){
          tinyMCE.triggerSave();

        // localStorage.removeItem("questionkey");
        // localStorage.removeItem("questionanser");
        // localStorage.removeItem("questionNo");

                                         

        $("html,body").animate({
                        scrollTop: 0
                    }, 'fast');  
                     
                       

                      var answer =  [];
                        
                        $m = 1;
                        $.each($(".example"), function(){
                            answer.push($(this).val()+"Nil##");
                            $m++;
                        });

                        var cbt_id = <?php echo $cbtid?>;
                        var UserID = '<?php echo $UserID?>';
                        var InstitutionID  = <?php echo $InstitutionID;?>;
                        var currentkeyvalue = parseInt($('#nxtprevquestiontheory').val());
                                             
                        var arrayanwer = $('#currentanwernxttheory').val();
                        var getanswerarr = arrayanwer.split(",");
                        var questionNo =  parseInt($('#questionNotheory').val());
                        
                        // alert(answer);


                        
                        const jsontext = <?php echo $ecodedquestionstheory; ?>;
                        const result  = JSON.stringify(jsontext);
                        const obj = JSON.parse(result);
                        var lengthofquestion_object = Object.keys(obj).length;
                    
                        var newkeyvalue =  parseInt(currentkeyvalue);
                        var newarraykey = newkeyvalue + 1;
                        var newquestionNo = questionNo + 1;
                            // alert(newquestionNo)
                        // alert(answer);
                                 
                             if(answer == '##' || answer =='Nil##' || answer == 'Nil')
                             {
                                  
                                 

                                            $.notify("Not  Answered", "warning"); 
                                             var newanswer = 'Nil##';
                                             getanswerarr[newkeyvalue] = newanswer;
                                             
                                                    if(newquestionNo > lengthofquestion_object)
                                                    {
                                                            // newarraykey = newarraykey-1;  
                                                         
                                                            $('.nexttheory').prop('disabled', true);
                                                            // $('.previoustheory').prop('disabled', false);
                                                            $('#submitnextheory').html('<button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal_theory"    class="btn waves-effect waves-light btn-rounded btn-success submittheory">Submit</button>')
                                                            
                                                    }else
                                                    {
                                                            $('#questionNotheory').val(newquestionNo);  
                                                            $('#nxtprevquestiontheory').val(newarraykey);
                                                            $('#currentanwernxttheory').val(getanswerarr);
                                                        
                                                            $('.nexttheory').prop('disabled', false); 
                                                            $('.previoustheory').prop('disabled', false);
                                                            
                                                    
                                                    }
                                    
                                                            var newquestion = obj[newarraykey].question;
                                                            
                                                                   
                                                            //   if (!(localStorage.getItem("questionkeytheory") == true || localStorage.getItem("questionkeytheory") == false)) {
                                                                
                                                            //               var newanswerload  = '';
                                                            //  }else
                                                            //  {
                                                            //                                 var questionkey = localStorage.getItem('questionkeytheory');
                                                            //                                 var questionansernew = localStorage.getItem('questionansertheory');
                                                            //                                 var questionno = localStorage.getItem('questionNotheory');
                                                                            
                                                                                            //  var questionanswer2_again = newarraykey.split(",");
                                                                                             var newanswerload_new =  getanswerarr[newarraykey];
                                                                                            
                                                                                              let resultreplacestring = newanswerload_new.toString();
                                                                                              let resultreplace = resultreplacestring.replace(/Nil##/g, "");
                                
                                
                                                                                            if(resultreplace == 'Nil' || resultreplace  == '##' || resultreplace == 'Nil##')
                                                                                            {
                                                                                                    var newanswerload  = '';
                                                                                            }else
                                                                                            {
                                                                                        
                                                                                                  var newanswerload  = resultreplace;
                                                                                
                                                                                            }    
                                                            //  }
                                                  
                                                   
                                                          
                                                               
                                                           
                                                            $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + newquestionNo + ')'+'</h1><h6>'+newquestion+'</h6><br>   <label>Enter your Answer in the Field Below</lable><textarea id="optionA1" class="wrs_div_box example question" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;"  value="PREV" id="prevbtntheory" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3" id="submitnextheory"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                                                            resetEditor();
                                                            createEditorInstance();
                                                            tinyMCE.get('optionA1').setContent(newanswerload);                                                   


                                            
                                                            localStorage.setItem("questionkeytheory", $('#nxtprevquestiontheory').val());
                                                            localStorage.setItem("questionansertheory", $('#currentanwernxttheory').val());  
                                                            localStorage.setItem("questionNotheory", $('#questionNotheory').val());
                                                               
                                          
                             }else
                             {
                               
                            
                                                        getanswerarr[newkeyvalue] = answer;
                                                       

                                                    if(newquestionNo > lengthofquestion_object)
                                                    {
                                                            // newarraykey = newarraykey-1;  
                                                    
                                                            $('.nexttheory').prop('disabled', true);
                                                            $('.previoustheory').prop('disabled', false);
                                                            $('#submitnextheory').html('<button type="button" style="font-size: 15px;" data-toggle="modal" data-target="#submitClassModal_theory"   value="NEXT" class="btn waves-effect waves-light btn-rounded btn-success submittheory">Submit</button>')
                                                            
                                                    }else
                                                    {
                                                            $('#questionNotheory').val(newquestionNo);  
                                                            $('#nxtprevquestiontheory').val(newarraykey);
                                                            $('#currentanwernxttheory').val(getanswerarr);
                                                        
                                                            $('.nexttheory').prop('disabled', false); 
                                                            $('.previoustheory').prop('disabled', false);
                                                    
                                                    }
                                      
                                                          var newquestion = obj[newarraykey].question;
                                                          
                                                           
                                                            
                                                            //  if(!(localStorage.getItem("questionkeytheory") == true || localStorage.getItem("questionkeytheory") == false)) {
                                                                
                                                            //                  var newanswerload  = '';
                                                            //  }else
                                                            //  {  
                                                            //                  var questionkey = localStorage.getItem('questionkeytheory');
                                                            //                  var questionansernew= localStorage.getItem('questionansertheory');
                                                            //                  var questionno = localStorage.getItem('questionNotheory');   
                                                                        
                                                                        
                                                                            // var questionanswer2_again = questionansernew.split(",");
                                                                            var newanswerload_new =  getanswerarr[newarraykey];
                                                                            
                                                                            let resultreplace = newanswerload_new.toString();
                                                                            let resultreplacenew = resultreplace.replace(/Nil##/g, "");
                
                                                                            if(resultreplacenew == 'Nil' || resultreplacenew == '##' || resultreplacenew == 'Nil##')
                                                                            {
                                                                                      var  newanswerload  = '';
                                                                            }else
                                                                            {
                                                                                    var newanswerload  = resultreplacenew;
                                                                            }
                                                                 
                                                            //  }
                                                            
                                                            
                                                          
                                              
                                                            $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + newquestionNo + ')'+'</h1><h6>'+newquestion+'</h6><br>   <label>Enter your Answer in the Field Below</lable><textarea id="optionA1" class="wrs_div_box example question" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;"  value="PREV" id="prevbtntheory" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3" id="submitnextheory"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                                                            resetEditor();
                                                            createEditorInstance();
                                                            tinyMCE.get('optionA1').setContent(newanswerload);                                               
                        
                        
                                                        
                                                            localStorage.setItem("questionkeytheory", $('#nxtprevquestiontheory').val());
                                                            localStorage.setItem("questionansertheory", $('#currentanwernxttheory').val());  
                                                            localStorage.setItem("questionNotheory", $('#questionNotheory').val());

                                 }
                        
                   
                        
       
                  
    });

    </script>


    <script>
        $(document).ready(function(){
                
                // view by number objective start here
                $("body").on("click",".viewer", function(){
                    
                                                
                                    $("html,body").animate({
                                        scrollTop: 0
                                    }, 'fast'); 

                                var questionid  = $(this).attr("id");
                                var arrayanwer = $('#currentanwernxt').val();
                                var getanswerarr = arrayanwer.split(",");
                                var countkey = $(this).data("id");
                                var previouskeyvalue = parseInt($('#nxtprevquestion').val());
                                var questionNo =  parseInt($('#questionNo').val());

                            

                                const jsontext = <?php echo $ecodedquestions;?>;
                                const result  = JSON.stringify(jsontext)
                                const obj = JSON.parse(result);
                                var lengthofquestion_object = Object.keys(obj).length;
                            

                            if($("input[type='radio'].radioBtnClass").is(':checked')) 
                            {
                                    var answer = $("input[type='radio'].radioBtnClass:checked").val();
                                    var newquestion = obj[countkey].question;
                                    var newoptionA = obj[countkey].optionA;
                                    var newoptionB = obj[countkey].optionB;
                                    var newoptionC = obj[countkey].optionC;
                                    var newoptionD = obj[countkey].optionD;
                                        getanswerarr[previouskeyvalue] = answer;

                                        $('#nxtprevquestion').val(countkey);
                                        $('#currentanwernxt').val(getanswerarr);
                                        $('#questionNo').val(questionid);

                                        $("#displayResults").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal"  class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  '  +questionid+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass" name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button type="button" style="font-size: 15px;"   value="PREV"     class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;"   value="NEXT"  class="btn waves-effect waves-light btn-rounded btn-success next">Next</button></div></div>');
                                        
                                            if(getanswerarr[countkey] == 'A')
                                            {
                                                $('#radio_1').prop('checked',true);
                                                $('#radio_2').prop('checked',false);
                                                $('#radio_3').prop('checked',false);
                                                $('#radio_4').prop('checked',false);
                                            }else if(getanswerarr[countkey] == 'B')
                                            {
                                                $('#radio_2').prop('checked',true);
                                                $('#radio_1').prop('checked',false);
                                                $('#radio_3').prop('checked',false);
                                                $('#radio_4').prop('checked',false);
                                            }else if(getanswerarr[countkey] == 'C')
                                            {
                                                $('#radio_2').prop('checked',false);
                                                $('#radio_1').prop('checked',false);
                                                $('#radio_3').prop('checked',true);
                                                $('#radio_4').prop('checked',false);
                                            }else if(getanswerarr[countkey] == 'D')
                                            {
                                                $('#radio_2').prop('checked',false);
                                                $('#radio_1').prop('checked',false);
                                                $('#radio_3').prop('checked',false);
                                                $('#radio_4').prop('checked',true);          
                                            }else
                                            {
                                                $('#radio_2').prop('checked',false);
                                                $('#radio_1').prop('checked',false);
                                                $('#radio_3').prop('checked',false);
                                                $('#radio_4').prop('checked',false);     
                                                // $.notify("Question Not Answered", "warning");
                                            }
                        
                                                

                                            localStorage.setItem("questionkey", $('#nxtprevquestion').val());
                                            localStorage.setItem("questionanser", $('#currentanwernxt').val());  
                                            localStorage.setItem("questionNo", $('#questionNo').val());
                            }
                            else
                            {
                                    answer = 0;
                                    var newquestion = obj[countkey].question;
                                    var newoptionA = obj[countkey].optionA;
                                    var newoptionB = obj[countkey].optionB;
                                    var newoptionC = obj[countkey].optionC;
                                    var newoptionD = obj[countkey].optionD;
                                
                                    $('#nxtprevquestion').val(countkey);
                                    $('#questionNo').val(questionid);

                                    $("#displayResults").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  '  +questionid+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass" name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button type="button" style="font-size: 15px;"   value="PREV"     class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;"   value="NEXT"  class="btn waves-effect waves-light btn-rounded btn-success next">Next</button></div></div>');
                                
                                    


                                if(getanswerarr[countkey] == 'A')
                                {
                                
                                    $('#radio_1').prop('checked',true);
                                    $('#radio_2').prop('checked',false);
                                    $('#radio_3').prop('checked',false);
                                    $('#radio_4').prop('checked',false);
                                }else if(getanswerarr[countkey]  == 'B')
                                {
                                
                                    $('#radio_2').prop('checked',true);
                                    $('#radio_1').prop('checked',false);
                                    $('#radio_3').prop('checked',false);
                                    $('#radio_4').prop('checked',false);
                                }else if(getanswerarr[countkey]  == 'C')
                                {
                                    $('#radio_2').prop('checked',false);
                                    $('#radio_1').prop('checked',false);
                                    $('#radio_3').prop('checked',true);
                                    $('#radio_4').prop('checked',false);
                                }else if(getanswerarr[countkey]  == 'D')
                                {
                                    $('#radio_2').prop('checked',false);
                                    $('#radio_1').prop('checked',false);
                                    $('#radio_3').prop('checked',false);
                                    $('#radio_4').prop('checked',true);          
                                }else
                                {
                                
                                    $('#radio_2').prop('checked',false);
                                    $('#radio_1').prop('checked',false);
                                    $('#radio_3').prop('checked',false);
                                    $('#radio_4').prop('checked',false);     
                                }

                                    localStorage.setItem("questionkey", $('#nxtprevquestion').val());
                                    localStorage.setItem("questionanser", $('#currentanwernxt').val());  
                                    localStorage.setItem("questionNo", $('#questionNo').val());

                            }
                    });
                        // view by number objective start here

                });
        

        // view by number theory  start here
        $("body").on("click",".viewertheory", function(){
                    tinyMCE.triggerSave();
                    var answer =  [];
                    $m = 1;
                    $.each($(".example"), function(){
                        answer.push($(this).val()+"Nil##");
                        $m++;
                    });

                    var questionid  = $(this).attr("id");
                    var arrayanwer = $('#currentanwernxttheory').val();
                
                    var countkey = $(this).data("id");
                    var currentkeyvalue = parseInt($('#nxtprevquestiontheory').val());
                        const jsontext = <?php echo $ecodedquestionstheory;?>;
                        const result  = JSON.stringify(jsontext)
                        const obj = JSON.parse(result);
                        var lengthofquestion_object = Object.keys(obj).length;

                    // var newquestion = obj[questionkey].question;
                    
                    // var newanswerload = questionanswer2[questionkey];
                    
                                    var getanswerarr = arrayanwer.split(",");
                
                    
                    if(answer == '##' || answer == 'Nil##' || answer == 'Nil')
                    {
                                    var answernew = "Nil##";
                                    var newquestion = obj[countkey].question;
                                    // var newkeyfound =  countkey -1;
                                    
                                        getanswerarr[currentkeyvalue] = answernew;
                                        
            
                                        
                                            
                                            

                                            
                                                    
                                                        //   if (!(localStorage.getItem("questionkeytheory") == true || localStorage.getItem("questionkeytheory") == false)) {
                                                            
                                                        //               var newanswerload  = '';
                                                        //  }else
                                                        //  {
                                                                                        var questionkey = localStorage.getItem('questionkeytheory');
                                                                                        var questionansernew = localStorage.getItem('questionansertheory');
                                                                                        var questionno = localStorage.getItem('questionNotheory');
                                                                        
                                                                                            var questionanswer2_again = questionansernew.split(",");
                                                                                            var newanswerload_new =  questionanswer2_again[countkey];
                                                                                        
                                                                                            let resultreplacestring = newanswerload_new.toString();
                                                                                            let resultreplace = resultreplacestring.replace(/Nil##/g, "");
                            
                            
                                                                                        if(resultreplace == 'Nil' || resultreplace  == '##' || resultreplace == 'Nil##')
                                                                                        {
                                                                                                var newanswerload  = '';
                                                                                        }else
                                                                                        {
                                                                                    
                                                                                                var newanswerload  = resultreplace;
                                                                            
                                                                                        }   
                                                                                        //  alert(newanswerload);
                                                                                        
                                                        //  }
                                                        

                                                        

                                    

                                        
                                        $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + questionid + ')'+'</h1><h4>'+newquestion+'</h4><br><label>Enter your Answer in the Field Below</lable><textarea id="optionA1" class="wrs_div_box example" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;"  value="PREV" id="prevbtntheory" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                                        resetEditor();
                                        createEditorInstance();
                                        tinyMCE.get('optionA1').setContent(newanswerload);    
                                        
                                        $('#nxtprevquestiontheory').val(countkey);
                                            $('#currentanwernxttheory').val(getanswerarr);
                                            $('#questionNotheory').val(questionid);
                                        
                                        
                                        localStorage.setItem("questionkeytheory", $('#nxtprevquestiontheory').val());
                                        localStorage.setItem("questionansertheory", $('#currentanwernxttheory').val());  
                                        localStorage.setItem("questionNotheory", $('#questionNotheory').val());


                    }else
                    {

                        
                                                var newquestion = obj[countkey].question;
                    
                                            //   var newkeyfound =  countkey -1;
                                        
                                                    getanswerarr[currentkeyvalue] = answer;

                                        

                                                    $('#nxtprevquestiontheory').val(countkey);
                                                $('#currentanwernxttheory').val(getanswerarr);
                                                $('#questionNotheory').val(questionid);

                                            
                                                // var questionanswer2_again = arrayanwer.split(",");
                                                // var newanswerload_new =  questionanswer2_again[currentkeyvalue];
                                                
                                                
                                                        
                                                        
                                                        // if (!(localStorage.getItem("questionkeytheory") == true || localStorage.getItem("questionkeytheory") == false)) {
                                                            
                                                        //               var newanswerload  = '';
                                                        //  }else
                                                        //  {
                                                                                        var questionkey = localStorage.getItem('questionkeytheory');
                                                                                        var questionansernew = localStorage.getItem('questionansertheory');
                                                                                        var questionno = localStorage.getItem('questionNotheory');
                                                                        
                                                                                            var questionanswer2_again = questionansernew.split(",");
                                                                                            var newanswerload_new =  questionanswer2_again[countkey];
                                                                                        
                                                                                            let resultreplacestring = newanswerload_new.toString();
                                                                                            let resultreplace = resultreplacestring.replace(/Nil##/g, "");
                            
                            
                                                                                        if(resultreplace == 'Nil' || resultreplace  == '##' || resultreplace == 'Nil##')
                                                                                        {
                                                                                                var newanswerload  = '';
                                                                                        }else
                                                                                        {
                                                                                    
                                                                                                var newanswerload  = resultreplace;
                                                                            
                                                                                        }    
                                                                                        
                                                        //  }
                                            
                                            
                                            
                                                
                                                

                                                $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + questionid + ')'+'</h1><h4>'+newquestion+'</h4><br><label>Enter your Answer in the Field Below</lable><textarea id="optionA1" class="wrs_div_box example" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;"  value="PREV" id="prevbtn" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                                                resetEditor();
                                                createEditorInstance();
                                                tinyMCE.get('optionA1').setContent(newanswerload);
                                                
                                                    localStorage.setItem("questionkeytheory", $('#nxtprevquestiontheory').val());
                                                    localStorage.setItem("questionansertheory", $('#currentanwernxttheory').val());  
                                                    localStorage.setItem("questionNotheory", $('#questionNotheory').val());
                    }
                    

                    
                        
                        
        });
            // view by number theory  end here
    </script>

    <script>
        $(document).ready(function(){
            // submit obj   here
            var examstatus = <?php echo $getstatusforquestion; ?>;
            var questype = $('#questiontype').val();

            $("body").on("click",".submit", function(){
                
                var cbt_id = <?php echo $cbtid;?>;
                var UserID = '<?php echo $UserID;?>';
                var InstitutionID = <?php echo $InstitutionID;?>;
                    
                $('body').on('click','#submited',function(){
                    
                            var getanswerarr = [];
                            $.each($('#currentanwernxt'),function(){
                                getanswerarr.push($(this).val());
                            });
                            
                            var currectAnswers = [];
                            $.each($('#currectquestionID'),function(){
                                currectAnswers.push($(this).val());
                            });
                        

                        $.ajax({
                            url:"../controller/scripts/student/cbtAnswer.php",
                            method:"POST",
                            data:{cbt_id:cbt_id,UserID:UserID,InstitutionID:InstitutionID,getanswerarr:getanswerarr,currectAnswers:currectAnswers,questype:questype},
                            success:function(data){
                                            $('#submittedmsg').html(data);

                                        
                                                    
                                            if(examstatus == 2)
                                            {
                                                
                                                localStorage.removeItem("questiontype");
                                                var theoryrtpe  =  'theo';
                                                localStorage.setItem("questiontype", theoryrtpe);
                                                

                                                        
                                                $('#questiontype').val('theo');
                                            

                                                $("#displayteoryform").show() ;  
                                                $("#theorynumdiv").show() ;  

                                                $("#displayResults").hide() ;  
                                                $("#onbnumdiv").hide();  
                                                
                                        }else
                                            {
                                                setTimeout(function () {
                                                    $.notify("Question Succesfully Submitted", "success"); 
                                                    location.href = 'cbtOnboardingPageFinish.php?UserID=<?php echo $UserID ; ?> &&cbt_id=<?php echo $cbtid ;?>';
                                                }, 500);
                                                
                                                                                localStorage.removeItem('mid');
                                                                        localStorage.removeItem('timeLeft'+'<?php echo $subject ;?>'+'<?php echo $cbtid ;?>'+'<?php echo $studentID ;?>');
                                            }

                                        localStorage.removeItem("questionkey");
                                        localStorage.removeItem("questionanser");  
                                        localStorage.removeItem("questionNo");

                                        localStorage.removeItem("questionkeytheory");
                                        localStorage.removeItem("questionansertheory");  
                                        localStorage.removeItem("questionNotheory");
                                        

                            
                                //$('#post_modal').modal('show');
                                
                            }
                        });
                        
                });
            

            });
            
            $("body").on("click","#cbtsubmitsunny", function(){
                
                var cbt_id = <?php echo $cbtid;?>;
                var UserID = '<?php echo $UserID;?>';
                var InstitutionID = <?php echo $InstitutionID;?>;
                
                
                var getanswerarr = [];
                $.each($('#currentanwernxt'),function(){
                    getanswerarr.push($(this).val());
                });
                
                var currectAnswers = [];
                $.each($('#currectquestionID'),function(){
                    currectAnswers.push($(this).val());
                });
                
                $.ajax({
                            url:"../controller/scripts/student/cbtAnswer.php",
                            method:"POST",
                            data:{cbt_id:cbt_id,UserID:UserID,InstitutionID:InstitutionID,getanswerarr:getanswerarr,currectAnswers:currectAnswers,questype:questype},
                            success:function(data){
                                            $('#submittedmsg').html(data);

                                        
                                                    
                                            if(examstatus == 2)
                                            {
                                                
                                                localStorage.removeItem("questiontype");
                                                var theoryrtpe  =  'theo';
                                                localStorage.setItem("questiontype", theoryrtpe);
                                                

                                                        
                                                $('#questiontype').val('theo');
                                            

                                                $("#displayteoryform").show() ;  
                                                $("#theorynumdiv").show() ;  

                                                $("#displayResults").hide() ;  
                                                $("#onbnumdiv").hide();  
                                                
                                        }else
                                            {
                                                setTimeout(function () {
                                                    $.notify("Question Succesfully Submitted", "success"); 
                                                    location.href = 'cbtOnboardingPageFinish.php?UserID=<?php echo $UserID ; ?> &&cbt_id=<?php echo $cbtid ;?>';
                                                }, 500);
                                                
                                                                                localStorage.removeItem('mid');
                                                                        localStorage.removeItem('timeLeft'+'<?php echo $subject ;?>'+'<?php echo $cbtid ;?>'+'<?php echo $studentID ;?>');
                                            }

                                        localStorage.removeItem("questionkey");
                                        localStorage.removeItem("questionanser");  
                                        localStorage.removeItem("questionNo");

                                        localStorage.removeItem("questionkeytheory");
                                        localStorage.removeItem("questionansertheory");  
                                        localStorage.removeItem("questionNotheory");
                                        

                            
                                //$('#post_modal').modal('show');
                                
                            }
                        });
                
            });


            // submit theory   here
            $("body").on("click",".submittheory", function(){
                var cbt_id = <?php echo $cbtid;?>;
                var UserID = '<?php echo $UserID;?>';
                var InstitutionID = <?php echo $InstitutionID;?>;
                
                    
                
                $('body').on('click','#submited_theory',function(){
                    
                            var getanswerarr = [];
                            $.each($('#currentanwernxttheory'),function(){
                                getanswerarr.push($(this).val());
                            });
                            
                            
                        

                        $.ajax({
                            url:"../controller/scripts/student/cbtAnswertheory.php",
                            method:"POST",
                            data:{cbt_id:cbt_id,UserID:UserID,InstitutionID:InstitutionID,getanswerarr:getanswerarr,questype:questype},
                            success:function(data){
                                            $('#submittedmsg_theory').html(data);

                                        

                                        
                                        

                                                    localStorage.removeItem("questionkey");
                                                    localStorage.removeItem("questionanser");  
                                                    localStorage.removeItem("questionNo");

                                                    localStorage.removeItem("questionkeytheory");
                                                    localStorage.removeItem("questionansertheory");  
                                                    localStorage.removeItem("questionNotheory");
                                                    localStorage.removeItem('questiontype');
                                                    localStorage.removeItem('mid');
                                                    localStorage.removeItem('timeLeft'+'<?php echo $subject ;?>'+'<?php echo $cbtid ;?>'+'<?php echo $studentID ;?>');

                                                    
                                                setTimeout(function () {
                                                    $.notify("Question Succesfully Submitted", "success"); 
                                                    location.href = 'cbtOnboardingPageFinish.php?UserID=<?php echo $UserID ; ?> &&cbt_id=<?php echo $cbtid ;?>';
                                                }, 500);
                            
                                //$('#post_modal').modal('show');
                                
                            }
                        });
                        
                });
            

            });


        });
    </script>
    <!-- Submit Question End-->

     <script>
        
        $(document).ready(function(){
                // OBJECT ON DOCUMENT READY LOAD QUSETION 

                var questionkey = localStorage.getItem('questionkey');
                var questionanser = localStorage.getItem('questionanser');
                var questionno = localStorage.getItem('questionNo');
            
                if(isNaN(questionkey) || isNaN(questionno) || questionanser == '')
                {

                }else
                {
                    

                            var questionanswer2 = questionanser.split(",")

                            $('#nxtprevquestion').val(questionkey);
                            $('#currentanwernxt').val(questionanser); 
                            $('#questionNo').val(questionno); 

                            const jsontext = <?php echo $ecodedquestions;?>;
                            const result  = JSON.stringify(jsontext)
                            const obj = JSON.parse(result);
                            var lengthofquestion_object = Object.keys(obj).length;

                            var newquestion = obj[questionkey].question;
                            var newoptionA = obj[questionkey].optionA;
                            var newoptionB = obj[questionkey].optionB;
                            var newoptionC = obj[questionkey].optionC;
                            var newoptionD = obj[questionkey].optionD;
                            
                            

                                $("#displayResults").html('<a id="locationTocbtsetting"  data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a> <h1 style="font-style: italic; margin-top: 10px;">('+'Question  '  +questionno+')</h1><div class="myborder"></div><div class="question" style="margin-top: 50px; margin-left: 20px;"><h4>'+newquestion+'</h4><h5 style="color: black;"> a)<input class="radioBtnClass" name="group1"  type="radio" id="radio_1" value = "A"/><label for="radio_1">'+newoptionA+'</label></h5> <h5 style="color: black;">b)<input class="radioBtnClass" name="group1" type="radio" id="radio_2" value = "B" /><label for="radio_2">'+newoptionB+'</label></h5><h5 style="color: black;">c)<input class="radioBtnClass" name="group1" type="radio" id="radio_3" value = "C" /><label for="radio_3">'+newoptionC+'</label></h5><h5 style="color: black;">d)<input class="radioBtnClass" name="group1" type="radio" id="radio_4" value = "D" /><label for="radio_4">'+newoptionD+'</label></h5></div> <div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly pick the correct option using the mouse to select the answer<br>to the question by the right before the time runs out. You can also select any<br>question below to answer. Dont forget to click Submit when you are done.</small></div></div></div><div class="row" style="margin-top: 50px;"> <div class="col-sm-9 col-xs-9 col-md-9"><button type="button" style="font-size: 15px;"   value="PREV"     class="btn waves-effect waves-light btn-rounded btn-success previous">Previous</button></div><div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;"   value="NEXT"  class="btn waves-effect waves-light btn-rounded btn-success next">Next</button></div></div>');
                            
                                

                            


                            if(questionanswer2[questionkey] == 'A')
                            {
                            
                                $('#radio_1').prop('checked',true);
                                $('#radio_2').prop('checked',false);
                                $('#radio_3').prop('checked',false);
                                $('#radio_4').prop('checked',false);
                            }else if(questionanswer2[questionkey]  == 'B')
                            {
                            
                                $('#radio_2').prop('checked',true);
                                $('#radio_1').prop('checked',false);
                                $('#radio_3').prop('checked',false);
                                $('#radio_4').prop('checked',false);
                            }else if(questionanswer2[questionkey]  == 'C')
                            {
                                $('#radio_2').prop('checked',false);
                                $('#radio_1').prop('checked',false);
                                $('#radio_3').prop('checked',true);
                                $('#radio_4').prop('checked',false);
                            }else if(questionanswer2[questionkey]  == 'D')
                            {
                                $('#radio_2').prop('checked',false);
                                $('#radio_1').prop('checked',false);
                                $('#radio_3').prop('checked',false);
                                $('#radio_4').prop('checked',true);          
                            }else
                            {
                            
                                $('#radio_2').prop('checked',false);
                                $('#radio_1').prop('checked',false);
                                $('#radio_3').prop('checked',false);
                                $('#radio_4').prop('checked',false);     
                            }

                                

                    
                            }

        });
        // OBJECTIVE ON DOCUMENT READY LOAD QUSETION 

        $(document).ready(function(){
                // ANSWER ON DOCUMENT READY LOAD QUSETION 
                
            var questionkey = localStorage.getItem('questionkeytheory');
            var questionanser= localStorage.getItem('questionansertheory');
            var questionno = localStorage.getItem('questionNotheory');
        
            const jsontext = <?php echo $ecodedquestionstheory;?>;
            const result  = JSON.stringify(jsontext)
            const obj = JSON.parse(result);
            var lengthofquestion_object = Object.keys(obj).length;

            var newquestion = obj[questionkey].question;

            var questionanswer2 = questionanser.split(",");
            var newanswerload_new = questionanswer2[questionkey];

            let resultreplacestring = newanswerload_new.toString();
            
            let resultreplace = resultreplacestring.replace(/Nil##/g, "");
            
                if(resultreplace == 'Nil' || resultreplace == '##' ||  resultreplace == 'Nil##')
                {
                    var  newanswerload  = '';
            }else
            {        
                        var newanswerload  = resultreplace;     
            }
    
                $('#nxtprevquestiontheory').val(questionkey);
                $('#currentanwernxttheory').val(questionanswer2); 
                $('#questionNotheory').val(questionno); 
    
                    
        
                $("#displayteoryform").html('<a id="locationTocbtsetting" data-toggle="modal" data-target="#exitClassModal" class="close" aria-label="Close" style="color:red; margin-right:20px;cursor:pointer;"><i clas="fa fa-plus"></i>Exit</a><h1 style="font-style: italic; margin-top: 10px;">' + '('+'Question ' + questionno + ')'+'</h1><h6>'+newquestion+'</h6><br><label>Enter your Answer in the Field Below</lable><textarea id="optionA1" class="wrs_div_box example" contenteditable="true" tabindex="0" spellcheck="true" role="textbox">'+newanswerload+'</textarea><div class="row" style="margin-top: 75px;"><div class="col-sm-10"><div><small style="color: red;"><b>Note:</b> Kindly Input your answer in the field provided above <br> click on next to get the next question if wish before the time runs out. You can also click on Previous to go backward.  Don\'t forget to click Submit when you are done.</small id=meno""> </div></div> </div><hr/><div class="row" style="margin-top: 30px;"> <div class="col-sm-9 col-xs-9 col-md-9"> <button type="button" style="font-size: 15px;"  value="PREV" id="prevbtn" class="btn waves-effect waves-light btn-rounded btn-success previoustheory">Previous</button> </div> <div class="col-sm-3 col-xs-4 col-md-3"><button type="button" style="font-size: 15px;" value="NEXT"   class="btn waves-effect waves-light btn-rounded btn-success nexttheory">Next</button></div></div>');
                resetEditor();
                createEditorInstance();
                tinyMCE.get('optionA1').setContent(newanswerload);
                                                    
                                    
                    
            // ANSWER ON DOCUMENT READY LOAD QUSETION 
        });
 

    </script>

    <script>

        $('body').on('click','#locationTocbtsetting',function(){
                
                var cbt_id = <?php echo $cbtid;?>;
                var UserID = '<?php echo $UserID;?>';
                var InstitutionID = <?php echo $InstitutionID;?>;

            $('body').on('click','#exit-btn',function(){
    
                var getanswerarr = [];
                $.each($('#currentanwernxt'),function(){
                    getanswerarr.push($(this).val());
                }); 

                var currectAnswers = [];
                $.each($('#currectquestionID'),function(){
                    currectAnswers.push($(this).val());
                });

                $.ajax({
                    url:"../controller/scripts/student/cbtAnswer.php",
                    method:"POST",
                    data:{cbt_id:cbt_id,UserID:UserID,InstitutionID:InstitutionID,getanswerarr:getanswerarr,currectAnswers:currectAnswers},
                    success:function(data){
                        $('#submittedmsg').html(data);
                                localStorage.removeItem("questionkey");
                                localStorage.removeItem("questionanser");  
                                localStorage.removeItem("questionNo");
                                localStorage.removeItem('mid');


                                    localStorage.removeItem("questionkeytheory");
                                    localStorage.removeItem("questionansertheory");  
                                    localStorage.removeItem("questionNotheory");
                                    localStorage.removeItem('questiontype');
                                
                                    localStorage.removeItem('timeLeft'+'<?php echo $subject ;?>'+'<?php echo $cbtid ;?>'+'<?php echo $studentID ;?>');
                    
                        //$('#post_modal').modal('show');
                        setTimeout(function() {
                                $.notify("Question Succesfully Submitted", "success"); 
                            location.href = 'cbtOnboardingPageFinish.php?UserID=<?php echo $UserID ; ?> &&cbt_id=<?php echo $cbtid ;?>';
                        }, 500);
                    }
                });
        
            });
        });
                          
    </script>

    <!-- Timer--->
    <script>
        
        window.onload = function () {

            var midnight = '<?php echo $midtwo;?>';
            //    alert(midnight); 
                
            localStorage.setItem('mid',midnight);
            let timeInterval = <?php echo $totaldiff;?>;
        
            //check if you have the last counter value
            let timeLeft = localStorage.getItem(subid);
            // alert(timeInterval);
        
            if (isNaN(timeLeft) || timeLeft == null) {
                //save the current interval
                localStorage.setItem(subid, timeInterval);
            } else if (timeLeft == 0) {
                //save the current interval
                localStorage.setItem(subid, timeInterval);
            } else {
                // take the last saved value
                timeInterval = timeLeft;
            }

            countDown(timeInterval, function () {
            });
        };

        var subid = 'timeLeft'+'<?php echo $subject ;?>'+'<?php echo $cbtid ;?>'+'<?php echo $studentID ;?>';
                        // alert(subid);
        var timer;
        var i = 60;
        function countDown(i, callback) {
            //callback = callback || function(){};

        timer = setInterval(function () {

                hours = parseInt( i / 3600 ) % 24;
                minutes = parseInt(i / 60, 10) % 60;
                seconds = parseInt(i % 60, 10);
            

                hours =   hours < 10 ? "0" + hours : hours
                minutes = minutes < 10 ? "0" + minutes : minutes;
                seconds = seconds < 10 ? "0" + seconds : seconds;

                document.getElementById("timer").innerHTML =  hours + ":" + minutes + ":"  + seconds;
            
            
            // alert(minutes);
            //   var indexofi = i.split(",");
            //   let lastindexofid = indexofi.lastIndexOf();
            var midnight =  localStorage.getItem('mid');

                if(i == midnight){
                        //setConfirmUnload(false);
                        //$("#quiz_form").submit();

                    
                            var cbt_id = <?php echo $cbtid;?>;
                            var UserID = '<?php echo $UserID;?>';
                            var InstitutionID = <?php echo $InstitutionID;?>; 
                                var getanswerarr = [];
                                $.each($('#currentanwernxt'),function(){
                                    getanswerarr.push($(this).val());
                                }); 

                                var currectAnswers = [];
                                $.each($('#currectquestionID'),function(){
                                    currectAnswers.push($(this).val());
                                });

                                // $.ajax({
                                //     url:"../controller/scripts/student/cbtAnswer.php",
                                //     method:"POST",
                                //     data:{cbt_id:cbt_id,UserID:UserID,InstitutionID:InstitutionID,getanswerarr:getanswerarr,currectAnswers:currectAnswers},
                                //     success:function(data){
                                //         $('#submittedmsg').html(data);
                                //                 localStorage.removeItem("questionkey");
                                //                 localStorage.removeItem("questionanser");  
                                //                 localStorage.removeItem("questionNo");
                                //                 localStorage.removeItem('mid');

                                //                 localStorage.removeItem("questionkeytheory");
                                //                 localStorage.removeItem("questionansertheory");  
                                //                 localStorage.removeItem("questionNotheory");
                                //                 localStorage.removeItem('questiontype');
                                //                 window.location="cbtOnboardingPageFinish.php?UserID=<?php echo $UserID ; ?> &&cbt_id=<?php echo $cbtid ;?>";
                                //                 localStorage.removeItem('timeLeft'+'<?php echo $subject ;?>'+'<?php echo $cbtid ;?>'+'<?php echo $studentID ;?>');
                                //     }
                                // });
                    
                    }else{

                        // update the persisted time interval
                        localStorage.setItem(subid, i);
    
                        i-- || (clearInterval(timer), callback());
                    }

        }, 1000);
        }
                

    </script>
    <!--End Timer-->

</body>

</html>

        