<?php 
session_start();
ob_start();
$idauto= $_SESSION['user_idd'];
include('../include/config.php');
//$query= mysqli_query($con,"DELETE FROM CBC2 where EID='21' AND Grad='GRADE 5' AND TMks=''"); 

if($_SESSION['user_idd']=='' || $_SESSION['user_idd']==null)
{
    header("location:../");  
}
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('F');
$year=$date->format('Y');

$query=mysqli_query($con,"select * FROM companydata");
while($row=mysqli_fetch_array($query))
{
$schname=$row["School"];
}
?>
 <html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?php echo $schname; ?></title>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <link rel="stylesheet" href="../plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <link rel="stylesheet" href="../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/toastr/toastr.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
  <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <link rel="stylesheet" href="../plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  <link rel="shortcut icon" href="../images/schicon.ico">

  <style>
      body{
         font-family:Spectral;
     }
     .classfive{
         font-size:12px;
     }
     
      .bigger{
          font-size:16px;
          font-family:Tahoma;
      }
      .farmamount
      {
          font-size:18px;
          color:red;
      }
      .requireds
      {
          color:red;
      }
      #tablefarmincome
      {
       font-size:14px;   
      }
      #tablebankdata
      {
          font-size:14px;
      }
      #idmonthincome
      {
          font-size:14px;
          font-family:Robot;
      }
       #tablebusdata, #tablestaffsss
      {
         font-size:12px;
      }
      #tableexams
      {
          font-size:11px;
          font-family:Tahoma;
      }
      .sc{max-width:60px;font-weight:bold;font-size:13px;font-family:Tahoma;}
      
     #examresult
      {
          font-size:11px;
          font-family:Tahoma;
      }
      
      #tableexpenditure
      {
          font-size:13px;
      }
      
      .incomeperclasstable
      {
          font-size:14px;
      }
      
      .bstaffedit{
          font-size:10px;
      }
      
      .btnstafdelete{
          font-size:10px;
      }
      
      .side{
          box-shadow: 0 0 0 10px #4fc3dc44,
	0 0 50px #4fc3dc, 0 0 100px #4fc3dc;
	border-radius: 5px;
      }
      
      
	 .fc-dayGridMonth-button{
        font-size:10px;
    }
    
    .fc-dayGridWeek-button{
        font-size:10px;
    }
    
    .fc-list-button{
        font-size:10px;
    }
    
    .fc-today-button{
        font-size:10px;
    }
    
    .fc-prev-button{
        font-size:11px;
    }
    
    .fc-next-button{
        font-size:11px;
    }
    #exeimprest
    {
        font-size:12px;
        font-family:Tahoma;
    }
    
    .marks{
        font-size:16px;
    }
  </style>
  
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="stylesheet" href="schedule/fullcalendar/lib/main.min.css">
<script src="schedule/fullcalendar/lib/main.min.js"></script>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
 <div class="wrapper">
  <?php
   if(isset($_GET['page']))
    {
     $pg=$_GET['page'];
    if($pg != '' || $pg != 'index.php')
    {
  include('../include/head.php');
  include('../include/sidebar1.php');
    }
    }
  ?>
  <!-- Preloader -->
<?php
   if(isset($_GET['page']))
    {
     $pg=$_GET['page'];
    if($pg != '' || $pg != 'index.php')
    {
     if($pg=='Home')
    {
     include('Exa.php');   
    }else if($pg=='E_Results')
    {
     include('result.php');   
    }
    else
    {
    ?>
    <script>
    window.location.href='../';
    </script>
    <?php
    // header("location:../index.php");
    }
    }
    }

  include('modals/Examsmodal.php');
  include('../include/footer.php');
  ?>
 <input type="hidden" value="<?php echo $_SESSION['name']; ?>" id="sessionholder" />
 <div class="modal" id="modalregstaffs">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Large Modal</h4>
              
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <p>One fine body&hellip;</p>
            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Save changes</button>
            </div>
          </div>
        </div>
      </div>
  </div>
 
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="../plugins/jquery-ui/jquery-ui.min.js"></script>
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<!-- ChartJS -->
<script src="../plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="../plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="../plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="../plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="../plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="../plugins/moment/moment.min.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="../plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="../plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.js"></script>
<script src="../dist/js/pages/dashboard.js"></script>
<script src="scripts/jquery-2excel.js"></script>
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>

<script>
  $(function () {
    $("#tablemarksentry").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": true,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#tatblextension .col-md-6:eq(0)');
  });
</script>

<script>
  $(function () {
    $("#incomeanalysis").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": true,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#divincomeanysis .col-md-6:eq(0)');
  });
</script>

<script>
  $(function () {
    $("#examresult").DataTable({
      "responsive": false, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('.divexamresult .col-md-6:eq(0)');
    
    $('#tableexams').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true,
      "responsive": true,
    });
  });
</script>

<script>
  $(function () {
    $("#tablact").DataTable({
      "responsive": true, "lengthChange": true, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#divtableact .col-md-6:eq(0)');
    
    $('#tablebusdat').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true,
      "responsive": true,
    });
  });
</script>

<script>
  $(function () {
    $("#tablecbc").DataTable({
      "responsive": true, "lengthChange": true, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#scoretable.col-md-6:eq(0)');
  });
</script>

 <script>
      $(document).ready(function() {
      $('.classfive').DataTable( {
      "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
      } );
      } );
 </script>
    
<script>
    $(document).ready(function() {
    $('#toexcel7').on('click', function(e)
    {
        var nam=document.getElementById('txtexamname').value;
        $(".classseventable").table2excel({
        exclude: ".leaveme",
        name: "Data",
        filename:nam,
    });
    });
    });
 </script> 
 
  <script>
    $(document).ready(function() {
       setInterval(function ()
        {
          var id= document.getElementById('exaamu').value;
          var grd= document.getElementById('gre').value;
          if(id=='' || grd=='')
          {
            document.getElementById("btnbtnaddla").disabled = true;
            $("#processs").removeClass("fa-spin");
          }else
          {
            document.getElementById("btnbtnaddla").disabled = false; 
            $("#processs").addClass("fa-spin");
          }
        }, 1000);   
   });
</script>

<script>
    $(document).ready(function() {
    $('#toexcel5').on('click', function(e)
    {
        var nam=document.getElementById('txtexamname').value;
        $(".classfive").table2excel({
        exclude: ".leaveme",
        name: "Data",
        filename:nam,
    });
    });
    });
 </script>

 <script>
    $(document).ready(function() {
    $('#toexcel8').on('click', function(e)
    {
        var nam=document.getElementById('txtexamname').value;
        $(".classeight").table2excel({
        exclude: ".leaveme",
        name: "Data",
        filename:nam,
    });
    });
    });
 </script>

 <script>
    $(document).ready(function() {
    $('#toexcel').on('click', function(e)
    {
        var nam=document.getElementById('txtexamname').value;
        $(".egzam").table2excel({
        exclude: ".leaveme",
        name: "Data",
        filename:nam,
    });
    });
    });
 </script>
 
<script>
$(document).ready(function() {
$('#btndown67').on('click', function(e)
{
    var exam= document.getElementById('examuname').value;
    $("#tablecbc").table2excel({
    exclude: ".leavethiss",
    name: "Data",
    filename: exam,
});
});
});
</script>

<script>
 $(function(){
  $("#notadded").select2();
 }); 
</script>

<script>
       $(document).ready(function() 
       {
        $("#thesavebtn").click(function()
        {
        var id = document.getElementById('notadded').value;
        var grd = document.getElementById('gre').value; 
        var exa = document.getElementById('exaamu').value;
        
         if(id=='' || grd=='' || exa=='')
         {
                $('#savemessagelana').html("Some data are missing").css('color', 'red');
                setInterval(function ()
                {
                 $('#savemessagelana').html("").css('color', 'red');
                }, 2500);
         }else
         {
           $.ajax({
           url:"savenotfound.php",
           method:"POST",
           data:{id,grd,exa},
           success:function(data)
           {
            if(data=='success')
            {
                $('#savemessagelana').html("Added. Refresh the data").css('color', 'green');
                setInterval(function ()
                {
                  $('#savemessagelana').html("").css('color', 'green');
                }, 2000);   
            }else
            {
             $('#savemessagelana').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#savemessagelana').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>

      <script>
    $(document).ready(function() 
     {
         
        setInterval(function ()
        {
            var ma= document.getElementById('matheee').value;
            var lang= document.getElementById('englii').value;
            var kis= document.getElementById('kisaaa').value;
            var cre= document.getElementById('bibleee').value;
            var CA= document.getElementById('creaaa').value;
            var ss= document.getElementById('Socii').value;
            var st= document.getElementById('stee').value;
            var agi= document.getElementById('agii').value;
            var pt= document.getElementById('pretec').value;
        
            if(ma==''){ma='0';}
            if(kis==''){kis='0';}
            if(cre==''){cre='0';}
            if(CA==''){CA='0';}
            if(ss=='' || ss==null){ss='0';}
            if(st=='' || st==null){st='0';}
            if(agi=='' || agi==null){agi='0';}
            if(lang==''){lang='0';}
            if(pt==''){pt='0';}
           
            const maa=parseInt(ma);
            const ki=parseInt(kis);
            const cr=parseInt(cre);
            const car=parseInt(CA);
            const sos=parseInt(ss);
            const tec=parseInt(st);
            const an=parseInt(agi);
            const lan=parseInt(lang);
            const ptt=parseInt(pt);
            const tot=maa+ki+cr+car+sos+tec+an+lan+ptt;
            $('#OPPP').val(tot);
        }, 500);
     });
     
 </script>
 
      <script>
    $(document).ready(function() 
     {
         
        setInterval(function ()
        {
            var ma= document.getElementById('mathee').value;
            var lang= document.getElementById('engli').value;
            var kis= document.getElementById('kisaa').value;
            var cre= document.getElementById('biblee').value;
            var CA= document.getElementById('creaa').value;
            var ss= document.getElementById('Soci').value;
            var st= document.getElementById('ste').value;
            var agi= document.getElementById('agi').value;
        
            if(ma==''){ma='0';}
            if(kis==''){kis='0';}
            if(cre==''){cre='0';}
            if(CA==''){CA='0';}
            if(ss=='' || ss==null){ss='0';}
            if(st=='' || st==null){st='0';}
            if(agi=='' || agi==null){agi='0';}
            if(lang==''){lang='0';}
           
            const maa=parseInt(ma);
            const ki=parseInt(kis);
            const cr=parseInt(cre);
            const car=parseInt(CA);
            const sos=parseInt(ss);
            const tec=parseInt(st);
            const an=parseInt(agi);
            const lan=parseInt(lang);
            const tot=maa+ki+cr+car+sos+tec+an+lan;
            $('#OPP').val(tot);
        }, 500);
     });
     
 </script>
   <script>
   
        function counttotal()
        {
            var ma= document.getElementById('mathee').value;
            var eng= document.getElementById('engli').value;
            var kis= document.getElementById('kisaa').value;
            var cre= document.getElementById('biblee').value;
            var ca= document.getElementById('creaa').value;
            var ss= document.getElementById('Soci').value;
            var st= document.getElementById('ste').value;
            var agi= document.getElementById('agi').value;
          
           if(ma=='' || ma==null ){ma='0';}
           if(kis=='' || kis==null){kis=0;}
           if(cre=='' || cre==null){cre='0';}
           if(ca=='' || ca==null){ca='0';}
           if(ss=='' || ss==null){ss='0';}
           if(st=='' || st==null){st='0';}
           if(agi=='' || agi==null){agi='0';}
           if(eng=='' || eng==null){eng='0';}

            const maa=parseInt(ma);
            const ki=parseInt(kis);
            const cr=parseInt(cre);
            const car=parseInt(ca);
            const sos=parseInt(ss);
            const tec=parseInt(st);
            const an=parseInt(agi);
            const enn=parseInt(eng);
     
            
           const tot=maa+ki+cr+car+sos+tec+an+enn;
            //$('#OPP').val(tot);
        }
    
 </script>
 
   <script>
    $(document).ready(function() 
     {
      $('#saveupper11').on('click', function()
      { 
            var ma= document.getElementById('mathee').value;
            var en= document.getElementById('engli').value;
            var kis= document.getElementById('kisaa').value;
            var id= document.getElementById('upper1id').value;
            var cre= document.getElementById('biblee').value;
            var ca= document.getElementById('creaa').value;
            var ss= document.getElementById('Soci').value;
            var st= document.getElementById('ste').value;
            var agi= document.getElementById('agi').value;
            var op= document.getElementById('OPP').value;
            
            var pt= "";
            var rpt= "";
            $.ajax({
            url:"saveupperscore.php",
            method:"POST",
            data:{id,ma,en,kis,cre,ca,ss,st,agi,op},
            success:function(data)
            {
            if(data=='success')
            {
            refresh();
            $('#Recordsmodal').modal('hide');
            
            setInterval(function ()
            {
            //$('#ExamEntry').modal('toggle');
            }, 100);
            
            }else
            {
            alert(data);
            }
            }
            }); 
      });
     });
 </script>
 
 
 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".recordsss", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".exadataid").val();
         $.ajax({
          url:"getresult2.php",
           method:"POST",
           data:{id:id}, 
           dataType:"json",
           success:function(data)
           { 
             $('#matheee').val(data.Math);
             $('#rmaaa').html(data.MA1);
             
             $('#englii').val(data.Eng);
             $('#ruengaaa').html(data.EN1);
             
            $('#kisaaa').val(data.Kis);
            $('#rukisaaa').html(data.KS1);
             
            $('#bibleee').val(data.CRE);
            $('#rubibleee').html(data.CR1);
            
            $('#Socii').val(data.SS);
            $('#rusocii').html(data.SS1);
            
            $('#creaaa').val(data.CA);
            $('#rucreaaa').html(data.CA1);
            
            $('#stee').val(data.ST);
            $('#rustee').html(data.ST1);
            
            $('#agii').val(data.AN);
            $('#ruagii').html(data.AN1);
            
            $('#pretec').val(data.PT);
            $('#rupretec').html(data.PT1);
            
             $('#OPPP').val(data.TMks);
            $('#ruOPPP').html(data.TRub);
            
             $('#upper1id').val(data.id);
             $('#learnerrr').html(data.nam+'-'+data.adm).css('color', 'red');
           }
          });
           $('#Modalupper').modal('show');
           
           setInterval(function ()
            {
              getoutof();
            }, 1000);  
       });
    
    });
  </script>
  
    <script>
    $(document).ready(function() 
     {
      $('#saveupper22').on('click', function()
      { 
            var ma= document.getElementById('matheee').value;
            var en= document.getElementById('englii').value;
            var kis= document.getElementById('kisaaa').value;
            var id= document.getElementById('upper1id').value;
            var cre= document.getElementById('bibleee').value;
            var ca= document.getElementById('creaaa').value;
            var ss= document.getElementById('Socii').value;
            var st= document.getElementById('stee').value;
            var agi= document.getElementById('agii').value;
            var op= document.getElementById('OPPP').value;
            var pt= document.getElementById('pretec').value;
  
            $.ajax({
            url:"saveupperscore2.php",
            method:"POST",
            data:{id,ma,en,kis,cre,ca,ss,st,agi,op,pt},
            success:function(data)
            {
            if(data=='success')
            {
            refresh();
            $('#Modalupper').modal('toggle');
   
            setInterval(function ()
            {
            //$('#ExamEntry').modal('toggle');
            }, 100);
            
            }else
            {
            alert(data);
            }
            }
            }); 
      });
     });
 </script>
 
    <script>
    $(document).ready(function() 
     {
      $('#saveupper2').on('click', function()
      { 
            var ma= document.getElementById('matheee').value;
            var en= document.getElementById('englii').value;
            var kis= document.getElementById('kisaaa').value;
            var id= document.getElementById('upper1id').value;
            var cre= document.getElementById('bibleee').value;
            var rcre= document.getElementById('rubibleee').value;
            var ca= document.getElementById('creaaa').value;
            var rca= document.getElementById('rucreaaa').value;
            var ss= document.getElementById('Socii').value;
            var rss= document.getElementById('rusocii').value;
            var st= document.getElementById('stee').value;
            var rst= document.getElementById('rustee').value;
            var agi= document.getElementById('agii').value;
            var ragi= document.getElementById('ruagii').value;
            var op= document.getElementById('OPPP').value;
            var rop= document.getElementById('ruOPPP').value;
            var rm= document.getElementById('rmaaa').value;
            var re= document.getElementById('ruengaaa').value;
            var rk= document.getElementById('rukisaaa').value;
            var pt= document.getElementById('pretec').value;
            var rpt= document.getElementById('rupretec').value;
            
            $.ajax({
            url:"savescore3.php",
            method:"POST",
            data:{id,ma,en,kis,rm,re,rk,cre,rcre,ca,rca,ss,rss,st,rst,agi,ragi,op,rop,pt,rpt},
            success:function(data)
            {
            if(data=='success')
            {
            refresh();
            $('#Modalupper').modal('toggle');
            //$('#Records').modal('toggle');
            //$('#ExamEntry').modal('toggle');
            
            setInterval(function ()
            {
            //$('#ExamEntry').modal('toggle');
            }, 100);
            
            }else
            {
            alert(data);
            }
            }
            }); 
      });
     });
 </script>

<script>
   function getoutof4() //For grade 4
   {
     var eid = document.getElementById("exaamu").value;
     var grd = document.getElementById("gre").value;
     
   $.ajax({
          url:"getoutoff46.php",
           method:"POST",
           data:{eid,grd}, 
           dataType:"json",
           success:function(data)
           { 
             $('#maxma4').html('(Max-'+data.MA+')').css('color', 'red');
             $('#maxen4').html('(Max-'+data.EN+')').css('color', 'red');
             $('#maxki4').html('(Max-'+data.KS+')').css('color', 'red');
             $('#maxcrr4').html('(Max-'+data.CRE+')').css('color', 'red');
             $('#maxca4').html('(Max-'+data.CA+')').css('color', 'red');
             $('#maxss4').html('(Max-'+data.SS+')').css('color', 'red');
             $('#maxst4').html('(Max-'+data.ST+')').css('color', 'red');
             $('#maxan4').html('(Max-'+data.AN+')').css('color', 'red');
           }
          });
   }
  </script>
 
 
 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".recordss", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".exadataid").val();
         $.ajax({
          url:"getresult2.php",
           method:"POST",
           data:{id}, 
           dataType:"json",
           success:function(data)
           { 
             $('#mathee').val(data.Math);
             $('#rmaa').html(data.MA1);
             
             $('#engli').val(data.Eng);
             $('#ruengaa').html(data.EN1);
             
            $('#kisaa').val(data.Kis);
            $('#rukisaa').html(data.KS1);
             
            $('#biblee').val(data.CRE);
            $('#rubiblee').html(data.CR1);
            
            $('#Soci').val(data.SS);
            $('#rusoci').html(data.SS1);
            
            $('#creaa').val(data.CA);
            $('#rucreaa').html(data.CA1);
            
            $('#ste').val(data.ST);
            $('#ruste').html(data.ST1);
            
            $('#agi').val(data.AN);
            $('#ruagi').html(data.AN1);
            
             $('#OPP').val(data.TMks);
            $('#ruOPP').html(data.TRub);
            
         
             $('#upper1id').val(data.id);
             //$('#').html();
             $('#learnerrrr').html(data.nam+'-'+data.adm).css('color', 'red');
           }
          });

           $('#Recordsmodal').modal('show');
           
           getoutof4(); 
       });
    
    });
  </script>

 <script>
     function refresh()
     {
 var exa=document.getElementById('exaamu').value;
 var grd=document.getElementById('gre').value;
 
 document.getElementById('exaexa').value=exa;
 document.getElementById('clcl').value=grd;

 $('#examlabel').html('Class: '+grd);

if(exa=='' || grd=='')
{
 alert('Select values in all fields');
}else{
    
 if(grd=='GRADE 4' || grd=='GRADE 5' || grd=='GRADE 6')   
    {
        $.ajax({
        url: "Secondlevelexam.php",
        type: "POST",
        cache: false,
        data:{exa:exa,grd:grd},
        success: function(data)
        {
        $('#scoretable').html(data); 
        }
        });
   
    }else if(grd=='GRADE 1' || grd=='GRADE 2' || grd=='GRADE 3')
    {
     
      $.ajax({
         url: "Firstlevelexam.php",
         //url: "getscoreonetwothree.php",
        type: "POST",
        cache: false,
        data:{exa:exa,grd:grd},
        success: function(data)
        {
        $('#scoretable').html(data); 
        // $('#scoretable').html(data); 
        }
        });  
    }else if(grd=='GRADE 7' || grd=='GRADE 8' || grd=='GRADE 9')
    {
        
      $.ajax({
         url: "upperexamlevel.php",
        type: "POST",
        cache: false,
        data:{exa:exa,grd:grd},
        success: function(data)
        {
        $('#scoretable').html(data); 
        // $('#scoretable').html(data); 
        }
        });   
    }else
    {
    alert('Invalid option !!!');
    }
}
     }
 </script>
 
  <script>
    $(document).ready(function() 
     {
      $('#savesave2').on('click', function()
      { 
            var ma= document.getElementById('mathe').value;
            var en= document.getElementById('enga').value;
            var kis= document.getElementById('kisa').value;
            var cre= document.getElementById('bible').value;
            var cra= document.getElementById('crea').value;
            var eva= document.getElementById('EAs').value;
            var op= document.getElementById('OP').value;


            //var rm= document.getElementById('rma').value;
          //  var re= document.getElementById('ruenga').value;
           // var rk= document.getElementById('rukisa').value;
           // var rub= document.getElementById('rubible').value;
           // var craa= document.getElementById('rucrea').value;
           // var ev= document.getElementById('ruEAs').value;
            var id= document.getElementById('mid').value;
            $.ajax({
            url:"savenewsco.php",
            method:"POST",
            data:{ma,en,kis,cre,eva,cra,op,id},
            success:function(data)
            {
            if(data=='success')
            {
            refresh();
            $('#Records').modal('hide');
            //$('#Records').modal('toggle');
            //$('#ExamEntry').modal('toggle');
            
            setInterval(function ()
            {
            //$('#ExamEntry').modal('toggle');
            }, 100);
            
            }else
            {
            alert(data);
            }
            }
            }); 
      });
     });
 </script>
 
 <script>
    $(document).ready(function() 
     {
      $('#savesave').on('click', function()
      { 
            var ma= document.getElementById('mathe').value;
            var en= document.getElementById('enga').value;
            var kis= document.getElementById('kisa').value;
            var cre= document.getElementById('bible').value;
            var cra= document.getElementById('crea').value;
            var eva= document.getElementById('EAs').value;
            var op= document.getElementById('OP').value;
           // var op2= document.getElementById('ruOP').value;

            //var rm= document.getElementById('rma').value;
           // var re= document.getElementById('ruenga').value;
           // var rk= document.getElementById('rukisa').value;
           // var rub= document.getElementById('rubible').value;
            //var craa= document.getElementById('rucrea').value;
           // var ev= document.getElementById('ruEAs').value;
            var id= document.getElementById('mid').value;
            
            $.ajax({
            url:"savesco.php",
            method:"POST",
            data:{ma,en,kis,cre,eva,cra,op,id},
            success:function(data)
            {
            if(data=='success')
            {
            refresh();
            $('#Records').modal('hide');
            //$('#Records').modal('toggle');
            //$('#ExamEntry').modal('toggle');
            
            setInterval(function ()
            {
            //$('#ExamEntry').modal('toggle');
            }, 100);
            
            }else
            {
            alert(data);
            }
            }
            }); 
      });
     });
 </script>
 
  <script>
    $(document).ready(function() 
     {
         
        setInterval(function ()
        {
            var ma= document.getElementById('mathe').value;
            var eng= document.getElementById('enga').value;
            var kis= document.getElementById('kisa').value;
            var cre= document.getElementById('bible').value;
            var CA= document.getElementById('crea').value;
            var EA= document.getElementById('EAs').value;
            
            if(ma==''){ma='0';}
            if(eng==''){eng='0';}
            if(kis==''){kis='0';}
            if(cre==''){cre='0';}
            if(CA==''){CA='0';}
            if(EA==''){EA='0';}
            
            const maa=parseInt(ma);
            const en=parseInt(eng);
            const ki=parseInt(kis);
            const cr=parseInt(cre);
            const car=parseInt(CA);
            const eac=parseInt(EA);
            
            const tot=maa+en+ki+cr+car+eac;
            $('#OP').val(tot);
        }, 500);
     });
 </script>
 
 
 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".records", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".exadataid").val();
       
         $.ajax({
          url:"getresult.php",
           method:"POST",
           data:{id:id}, 
           dataType:"json",
           success:function(data)
           { 
             $('#mathe').val(data.Math);
             $('#rma').html(data.Ruma);
             
             $('#enga').val(data.Eng);
             $('#ruenga').html(data.Ruen);
             
             $('#kisa').val(data.Kis);
             $('#rukisa').html(data.Ruks);
             
             $('#bible').val(data.CRE);
             $('#rubible').html(data.CRE1);
             
             $('#crea').val(data.CrA);
             $('#rucrea').html(data.CA1);
             
             $('#EAs').val(data.EA);
             $('#ruEAs').html(data.EA1);
             
             $('#OP').val(data.TMks);
             $('#ruOP').html(data.TRub);
             
             $('#mid').val(data.mid);
             //$('#').html();
             $('#learner').html(data.nam+'-'+data.adm).css('color', 'red');
           }
          });
           $('#Records').modal('show');
           
           setInterval(function ()
            {
              getoutof();
            }, 1000);  
       });
    
    });
  
  </script>
  
   <script>
   function getoutof()
   {
    var id = document.getElementById("mid").value;
   $.ajax({
          url:"getoutoff.php",
           method:"POST",
           data:{id:id}, 
           dataType:"json",
           success:function(data)
           { 
             //$('#maxma').html('(Max-'+data.MA+')');
             $('#maxma').html('(Max-'+data.MA+')').css('color', 'red');
             $('#maxen').html('(Max-'+data.EN+')').css('color', 'red');
             $('#maxki').html('(Max-'+data.KS+')').css('color', 'red');
             $('#maxcr').html('(Max-'+data.CRE+')').css('color', 'red');
             $('#maxca').html('(Max-'+data.CA+')').css('color', 'red');
             $('#maxea').html('(Max-'+data.EA+')').css('color', 'red');
             
             $(".max").css({fontSize: 10});
             //$('#ens').val(data.EN);
             //$('#kiss').val(data.KS);
             //$('#ilass').val(data.ILA);
             //$('#CRe').val(data.CRE);
            // $('#EAc').val(data.EA);
             //$('#CAr').val(data.CA);
           }
          });
   }
  </script>
 
  <script>
    $(document).ready(function() 
     {
      $('#savefetched').on('click', function(){  
     $("#tablecbc tbody tr").each(function (){
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".exadataid").val();
     var ma = currentRow.find(".scematt").val();
     var en = currentRow.find(".scengg").val();
     var kis = currentRow.find(".sckiss").val();
     var cre = currentRow.find(".cree").val();
     var craa = currentRow.find(".CRAA").val();
     var eva = currentRow.find(".EVAA").val();
     
      var rm = currentRow.find(".ruma").val();
      var re = currentRow.find(".ruen").val();
      var rk = currentRow.find(".ruks").val();
      var rla = currentRow.find(".rula").val();
      var cr = currentRow.find(".cre").val();
      var cra = currentRow.find(".CRA").val();
      var ev = currentRow.find(".EVA").val();
      
      var mk = currentRow.find(".tmks").val();
      var rub = currentRow.find(".trbu").val();
     
     //var exam = document.getElementById('exaexa').value;
     //var grd = document.getElementById('clcl').value;
     $.ajax({
         url:"savescores1.php",
           method:"POST",
           data:{ma:ma,en:en,kis:kis,rm:rm,re:re,rk:rk,rla:rla,mk:mk,rub:rub,cre:cre,craa:craa,eva:eva,cr:cr,cra:cra,ev:ev,id:id},
           success:function(data)
           {
    if(data=='success')
    {
    alert('Marks updated');
    }else
    {
    alert(data);
    }
           }
         }); 
       });   
    });
     });
  </script>
 <script>
    $(document).ready(function() 
     {
      $('#savealll').on('click', function(){  
        
      $("#tablecbc tbody tr").each(function (){
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".pupilidholder").val();
     var ma = currentRow.find(".scematt").val();
     var en = currentRow.find(".scengg").val();
     var kis = currentRow.find(".sckiss").val();
     var cre = currentRow.find(".cree").val();
     var craa = currentRow.find(".CRAA").val();
     var eva = currentRow.find(".EVAA").val();
     
      var rm = currentRow.find(".ruma").val();
      var re = currentRow.find(".ruen").val();
      var rk = currentRow.find(".ruks").val();
      var rla = currentRow.find(".rula").val();
      var cr = currentRow.find(".cre").val();
      var cra = currentRow.find(".CRA").val();
      var ev = currentRow.find(".EVA").val();
      
      var mk = currentRow.find(".tmks").val();
      var rub = currentRow.find(".trbu").val();
     
     var exam = document.getElementById('exaexa').value;
     var grd = document.getElementById('clcl').value;
     $.ajax({
           url:"savescores1.php",
           method:"POST",
           data:{pid:id,ma:ma,en:en,kis:kis,grd:grd,exa:exam,rm:rm,re:re,rk:rk,rla:rla,mk:mk,rub:rub,cre:cre,craa:craa,eva:eva,cr:cr,cra:cra,ev:ev},
           success:function(data)
           {
    if(data=='success')
    {
    alert('Marks updated');
    }else
    {
    alert(data);
    }
           }
         }); 
       });   
    });
     });
  </script>
 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".saveseven", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".pupilidholder").val();
     var ma = currentRow.find(".math").val();
     var en = currentRow.find(".english").val();
     var kis = currentRow.find(".kisw").val();
     var sis = currentRow.find(".Inter").val();
     var ss = currentRow.find(".SoS").val();
     var bs = currentRow.find(".BS").val();
     var angr = currentRow.find(".agri").val();
     var life = currentRow.find(".lifeski").val();
     var tech = currentRow.find(".ptech").val();
     var he = currentRow.find(".HE").val();
     var cre = currentRow.find(".cre").val();
     var pe = currentRow.find(".pee").val();
     var opt = currentRow.find(".opt").val();
     var mks = currentRow.find(".optmks").val();
     
     if(ma>50 || en>50 || kis>50 || sis>50 || ss>50 || bs>50 || angr>50 || life>50 || tech>50 || he>50 || cre>50 || pe>50 || mks>50 )
     {
         alert('Invalid score input');
     }else
     {
     var exam = document.getElementById('exaexa').value;
     var grd = document.getElementById('clcl').value;
      $.ajax({
           url:"savescoreseven.php",
           method:"POST",
           data:{pid:id,ma:ma,en:en,kis:kis,sis:sis,ss:ss,bs:bs,angr:angr,lif:life,tech:tech,he:he,cre:cre,pe:pe,opt:opt,mks:mks,grd:grd,exa:exam},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Successfully saved');
            setInterval(function ()
            {
            //window.location.href="Exams.php?page=Home";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            //window.location.href="Exams.php?page=Home";
            }, 2000);    
            }
           }
          });
      }
     
       });   
    });
  </script>
  
  
  <script>
     $(document).ready(function () 
    {
        $('#cla78').on('change', function()
        {
        $('#umas2').val('');
        $('#uens2').val('');
        $('#ukiss2').val('');
        $('#uCRe2').val('');
        $('#uEAc2').val('');
        $('#uCAr2').val('');
        $('#uSoS').val('');
        $('#uAnN').val('');
        $('#Ptec').val('');
        
        var cla=this.value;
        var id = document.getElementById("exaidholder").value;
        
        if(cla=='')
        {
        }else
        {
         $.ajax({
          url:"getexamsetting.php",
           method:"POST",
           data:{id:id,cla:cla}, 
           dataType:"json",
           success:function(data)
           { 
             $('#umas2').val(data.MA);
             $('#uens2').val(data.EN);
             $('#ukiss2').val(data.KS);
             $('#uCRe2').val(data.CRE);
             $('#uEAc2').val(data.ST);
             $('#uCAr2').val(data.CA);
             $('#uSoS').val(data.SS);
             $('#uAnN').val(data.AN);
             $('#Ptec').val(data.PT);
           }
          });
        }
        });
    });
</script>
  
<script>
     $(document).ready(function () 
    {
        $('#cla456').on('change', function()
        {
        $('#mas2').val('');
        $('#ens2').val('');
        $('#kiss2').val('');
        $('#CRe2').val('');
        $('#EAc2').val('');
        $('#CAr2').val('');
        $('#SoS').val('');
        $('#AnN').val('');
        
        var cla=this.value;
        var id = document.getElementById("exaidholder").value;
        
        if(cla=='')
        {
        }else
        {
         $.ajax({
          url:"getexamsetting.php",
           method:"POST",
           data:{id:id,cla:cla}, 
           dataType:"json",
           success:function(data)
           { 
             $('#mas2').val(data.MA);
             $('#ens2').val(data.EN);
             $('#kiss2').val(data.KS);
             $('#CRe2').val(data.CRE);
             $('#EAc2').val(data.ST);
             $('#CAr2').val(data.CA);
             $('#SoS').val(data.SS);
             $('#AnN').val(data.AN);
             
           }
          });
        }
        });
    });
</script>

<script>
     $(document).ready(function () 
    {
        $('#saveoutof3').on('click', function()
        {
        var id = document.getElementById("exaidholder").value;
        
        var ma = document.getElementById("umas2").value;
        var en = document.getElementById("uens2").value;
        var kis = document.getElementById("ukiss2").value;
        var cre = document.getElementById("uCRe2").value;
        var ins = document.getElementById("uEAc2").value;
        var an = document.getElementById("uAnN").value;
        var ca = document.getElementById("uCAr2").value;
        var ss = document.getElementById("uSoS").value;
        var pt = document.getElementById("Ptec").value;
         
        var cla = document.getElementById("cla78").value;
        if(cla=='')
        {
            alert('You must select class!');
        }else
        {
         $.ajax({
          url:"saveupperexam1.php",
           method:"POST",
           data:{eid:id,ma,en,kis,cre,ins,an,ca,ss,cla,pt}, 
           success:function(data)
           { 
            var da=data;
            if(da=='success')
            {
                alert('Saved');
            }else
            {
              alert(da);  
            }
           }
          });
        }
        });
    });
</script>
  
  
<script>
     $(document).ready(function () 
    {
        $('#saveoutofupper').on('click', function()
        {
        var id = document.getElementById("exaidholder").value;
        
        var ma = document.getElementById("mas2").value;
        var en = document.getElementById("ens2").value;
        var kis = document.getElementById("kiss2").value;
        var cre = document.getElementById("CRe2").value;
        var ins = document.getElementById("EAc2").value;
        var an = document.getElementById("AnN").value;
        var ca = document.getElementById("CAr2").value;
        var ss = document.getElementById("SoS").value;
        

        var cla = document.getElementById("cla456").value;
        if(cla=='')
        {
            alert('You must select class!');
        }else
        {
         $.ajax({
          url:"saveupperexam1.php",
           method:"POST",
           data:{id,ma,en,kis,cre,ins,an,ca,ss,cla}, 
           success:function(data)
           { 
            var da=data;
            if(da=='success')
            {
                alert('Saved');
            }else
            {
              alert(da);  
            }
           }
          });
        }
        });
    });
</script>

<script>
     $(document).ready(function () 
    {
        $('#saveoutof').on('click', function()
        {
        var id = document.getElementById("exaidholder").value;
        var ma = document.getElementById("mas").value;
        var en = document.getElementById("ens").value;
        var kis = document.getElementById("kiss").value;
        var cre = document.getElementById("CRe").value;
        var ea = document.getElementById("EAc").value;
        var ca = document.getElementById("CAr").value;
        
        var cla = document.getElementById("classclass").value;
        if(cla=='')
        {
            
        }else
        {
         $.ajax({
          url:"saveexamsettingdata.php",
           method:"POST",
           data:{id:id,cla:cla,ma:ma,kis:kis,en:en,cre:cre,ea:ea,ca:ca}, 
           success:function(data)
           { 
            var da=data;
            if(da=='success')
            {
                alert('Saved');
            }else
            {
              alert(da);  
            }
           }
          });
        }
        });
    });
</script>

<script>
     $(document).ready(function () 
    {
        $('#classclass').on('change', function()
        {
        $('#mas').val('');
        $('#ens').val('');
        $('#kiss').val('');
        $('#CRe').val('');
        $('#EAc').val('');
        $('#CAr').val('');
        
        var cla=this.value;
        var id = document.getElementById("exaidholder").value;
        
        if(cla=='')
        {
        }else
        {
         $.ajax({
          url:"getexamsetting.php",
           method:"POST",
           data:{id:id,cla:cla}, 
           dataType:"json",
           success:function(data)
           { 
             $('#mas').val(data.MA);
             $('#ens').val(data.EN);
             $('#kiss').val(data.KS);
             $('#ilass').val(data.ILA);
             $('#CRe').val(data.CRE);
             $('#EAc').val(data.EA);
             $('#CAr').val(data.CA);
           }
          });
        }
        });
    });
</script>

<script>
$(document).ready(function () 
{
$("#advancedbtn").click(function()
{ 
   var exa = document.getElementById("txtonee").value;
   document.getElementById('exammmmu').innerHTML=exa;
   $('#Examupdate').modal('hide');
   $('#modaladvanced').modal('show');
});
  });   
</script>

<script>
    $(document).ready(function() 
     {
     $("body").on("click", ".cbcsave", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".pupilidholder").val();
     var ma = currentRow.find(".scematt").val();
     var en = currentRow.find(".scengg").val();
     var kis = currentRow.find(".sckiss").val();
     var cre = currentRow.find(".cree").val();
     var craa = currentRow.find(".CRAA").val();
     var eva = currentRow.find(".EVAA").val();
     
      var rm = currentRow.find(".ruma").val();
      var re = currentRow.find(".ruen").val();
      var rk = currentRow.find(".ruks").val();
      var rla = currentRow.find(".rula").val();
      var cr = currentRow.find(".cre").val();
      var cra = currentRow.find(".CRA").val();
      var ev = currentRow.find(".EVA").val();
      
      alert(eva+' '+ev);
      
      var mk = currentRow.find(".tmks").val();
      var rub = currentRow.find(".trbu").val();
     
     
     var exam = document.getElementById('exaexa').value;
     var grd = document.getElementById('clcl').value;
     $.ajax({
          // url:"savescores1.php",
           method:"POST",
           data:{pid:id,ma:ma,en:en,kis:kis,ila:ila,grd:grd,exa:exam,rm:rm,re:re,rk:rk,rla:rla,mk:mk,rub:rub},
           success:function(data)
           {
    if(data=='success')
    {
    alert('Marks updated');
    }else
    {
    alert(data);
    }
           }
         }); 
       });   
    });
  </script>

<script>
    $(document).ready(function() 
     {
     $("body").on("click", ".cbcsavee", function(){  
     var currentRow = $(this).closest("tr");
         //alert(id);
     var id = currentRow.find(".pupilidholder").val();
     var ma = currentRow.find(".scemat").val();
     var en = currentRow.find(".sceng").val();
     var kis = currentRow.find(".sckis").val();
     var ila = currentRow.find(".ila").val();

     var exam = document.getElementById('exaexa').value;
     var grd = document.getElementById('clcl').value;
   
      $.ajax({
           //url:"savescores1.php",
           method:"POST",
           data:{pid:id,ma:ma,en:en,kis:kis,ila:ila,grd:grd,exa:exam},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Successfully saved
            ');
            setInterval(function ()
            {
            //window.location.href="Exams.php?page=Home";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            //window.location.href="Exams.php?page=Home";
            }, 2000);    
            }
           }
          });
     
       });   
    });
  </script>


 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".fafasave", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".pupilidholder").val();
     var ma = currentRow.find(".scemat").val();
     var en = currentRow.find(".sceng").val();
     var kis = currentRow.find(".sckis").val();
     var ila = currentRow.find(".ila").val();
     var cas = currentRow.find(".cass").val();
  
     var exam = document.getElementById('exaexa').value;
     var grd = document.getElementById('clcl').value;
  
      $.ajax({
          url:"savescores.php",
           method:"POST",
           data:{pid:id,ma:ma,en:en,kis:kis,ila:ila,cas:cas,grd:grd,exa:exam},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Successfully saved');
            setInterval(function ()
            {
            //window.location.href="Exams.php?page=Home";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            //window.location.href="Exams.php?page=Home";
            }, 2000);    
            }
           }
          });
     
       });   
    });
  </script>



<script>
$(document).ready(function (e) 
{
$("#filterpupils").click(function()
{
 var exa=document.getElementById('exaamu').value;
 var grd=document.getElementById('gre').value;
 
 document.getElementById('exaexa').value=exa;
 document.getElementById('clcl').value=grd;

 $('#examlabel').html('Class: '+grd);

if(exa=='' || grd=='')
{
 alert('Select values in all fields');
}else{
 if(grd=='GRADE 4' || grd=='GRADE 5' || grd=='GRADE 6')   
    {
   
       $.ajax({
         url: "Secondlevelexam.php",
        type: "POST",
        cache: false,
        data:{exa:exa,grd:grd},
        success: function(data)
        {
        $('#scoretable').html(data); 
        // $('#scoretable').html(data); 
        }
        }); 
    }else if(grd=='GRADE 1' || grd=='GRADE 2' || grd=='GRADE 3')
    {
     
      $.ajax({
         url: "Firstlevelexam.php",
         //url: "getscoreonetwothree.php",
        type: "POST",
        cache: false,
        data:{exa:exa,grd:grd},
        success: function(data)
        {
        $('#scoretable').html(data); 
        // $('#scoretable').html(data); 
        }
        });  
    }else if(grd=='GRADE 7' || grd=='GRADE 8' || grd=='GRADE 9')
    {
        
      $.ajax({
         url: "upperexamlevel.php",
        type: "POST",
        cache: false,
        data:{exa:exa,grd:grd},
        success: function(data)
        {
        $('#scoretable').html(data); 
        // $('#scoretable').html(data); 
        }
        });   
    }else
    {
        alert('Invalid option !!!');
    }
}
});
});
   </script>

 <script>
      $(document).ready(function(){ 
        makechart();
	function makechart()
	{
		$.ajax({
			url:"getchart.php",
			method:"POST",
			data:{action:'fetch'},
			dataType:"JSON",
			success:function(data)
			{
				var claz = [];
				var total = [];
				var color = [];

				for(var count = 0; count < data.length; count++)
				{
				claz.push(data[count].claz);
				total.push(data[count].total);
				color.push(data[count].color);
				}

				var chart_data = {
					labels:claz,
					datasets:[
						{  
							label:'Learners',
							backgroundColor:color,
							color:'#fff',
							data:total
						}
					]
				};

				var options = {
					responsive:true,
					scales:{
						yAxes:[{
							ticks:{
								min:0
							}
						}]
					}
				};

				var group_chart1 = $('#pie_chart');

				var graph1 = new Chart(group_chart1, {
					type:"pie",
					data:chart_data
				});
			
			}
		})
	}
        });
</script>

<script>
       $(document).ready(function() 
       {
        $("#saveexamm").click(function()
        {
        var tit = document.getElementById('txtonee').value;
        var sd = document.getElementById('txtthreee').value; 
        var ed = document.getElementById('txtfourr').value;
        var period = document.getElementById('txttwoo').value;
        var id = document.getElementById('exaidholder').value;
        var pview = document.getElementById('paview').value;
         if(tit=='' || period=='')
         {
            $('#exammsg').html("You must enter both Title and exam period").css('color', 'red');
            setInterval(function ()
            {
             $('#exammsg').html("").css('color', 'red');
            }, 2500);
         }else
         {
           $.ajax({
           url:"saveexam.php",
           method:"POST",
           data:{title:tit,sd,ed,peri:period,id,pview},
           success:function(data)
           {
            if(data=='Successfully saved')
            {
                $('#exammsgg').html("Successfully Updated").css('color', 'green');
                setInterval(function ()
                {
                  window.location.href="Exams.php?page=Home";
                }, 2000);   
            }else
            {
             $('#exammsgg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#exammsgg').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>

 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".exedit", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".examidd").val();
      $.ajax({
          url:"getexamdata.php",
           method:"POST",
           data:{id:id}, 
           dataType:"json",
           success:function(data)
           { 
             $('#txtonee').val(data.Title);
            // $('#labelclassteacher').html(data.Perid);
             $('#txttwoo').val(data.Period);
             $('#txtthreee').val(data.StartDate);
             $('#txtfourr').val(data.EndDate);
             $('#paview').val(data.View);
             $('#exaidholder').val(id);
             
           }
          });
          
          $('#Examupdate').modal('show'); 
       });   
    });
  </script>


<script>
       $(document).ready(function() 
       {
        $("#filterclass").click(function()
        {
        var exam = document.getElementById('examu').value;
        var kla = document.getElementById('klas').value; 
     
         if(exam=='' || kla=='')
         {
            alert('Kindly select both Exam and Class before proceeding');
         }else
         {
         window.location.href='linkclassfilter.php?exa='+exam+'&kla='+kla;
       }
       });
       }); 
  </script>

<script>
    setInterval(function ()
    {
        var lang = document.getElementById('langg').value;
        var comp = document.getElementById('compoo').value; 
        var lu= document.getElementById('lugaa').value; 
        var ins = document.getElementById('inshaa').value;
        var math = document.getElementById('mathh').value; 
        var sc = document.getElementById('scii').value; 
        var soc = document.getElementById('sociaa').value;
        var cre = document.getElementById('cree').value;
        //var total = document.getElementById('sstotall').innerHTML;
        
          if(lang==''){lang='0';}
          if(comp==''){comp='0';}
          if(lu==''){lu='0';}
          if(ins==''){ins='0';}
          if(math==''){math='0';}
          if(sc==''){sc='0';}
          if(soc==''){soc='0';}
          if(cre==''){cre='0';}
          //if(total==''){total='0';}
           
          const la=parseInt(lang);
          const co=parseInt(comp);
          const lug=parseInt(lu);
          const insh=parseInt(ins);
          const ma=parseInt(math);
          const sci=parseInt(sc);
          const soci=parseInt(soc);
          const cr=parseInt(cre);
          const tot=parseInt(total);
          
          var eng=la+co;
          var kiswa=lug+insh;
          //var socialcre=soci+cr;
          const too=soci+cr;
          var tota='';
        
     if(too<10)
    {
       tota=too+1; 
    }else if(too>9 && too<20)
    {
        tota=too+2; 
    }
    else if(too>19 && too<30)
    {
        tota=too+3; 
    }
    else if(too>29 && too<39)
    {
        tota=too+4; 
    }
    else if(too>39 && too<49)
    {
        tota=too+5; 
    }
    else if(too>49 && too<59)
    {
        tota=too+6; 
    }
    else if(too>59 && too<69)
    {
        tota=too+7; 
    }
    else if(too>69 && too<79)
    {
        tota=too+8; 
    }
    else if(too>79 && too<89)
    {
        tota=too+9; 
    }else if(too>89 && too<91)
    {
        tota=too+10; 
    }else if(too>90)
    {
        tota=100;
    }
    
          document.getElementById('sstotall').innerHTML=tota;
          document.getElementById('sicalcretota').value=tota;
          var total=la+co+lug+insh+ma+sci+tota;
        
          document.getElementById('kitotall').innerHTML=kiswa;
          document.getElementById('etotall').innerHTML=eng;
          document.getElementById('TMM').innerHTML=total+'/500';
          document.getElementById('TotalM').value=total;
          
          var pert=total*100/500;
          document.getElementById('tper').innerHTML='| '+pert+'%';
    
    }, 500);
</script>

<script>
function myFunctionn() 
{
  var id = document.getElementById("examid").value;
  if(id=='' || id==null)
  {
    document.getElementById("submarks").disabled = true; 
    document.getElementById("Selectpupi").value='';
    document.getElementById("Selectpupi").disabled = true;
    
    $('#labelclass').html('');
    $('#labelclassteacher').html('');
  }else
  {
      document.getElementById("submarks").disabled = false;
      document.getElementById("Selectpupi").disabled = false;
  }
}
</script>

<script>
function myFunction() {
  var id = document.getElementById("Selectpupi").value;
  var eid = document.getElementById("examid").value;
  ///alert(x);
  //document.getElementById("demo").innerHTML = "You selected: " + x;
  if(id=='' || id==null)
  {
    document.getElementById("submarks").disabled = true; 
    $('#labelclass').html('');
    $('#labelclassteacher').html('');
    
$('#langg').val('');
$('#compoo').val('');
$('#lugaa').val('');
$('#inshaa').val('');
$('#mathh').val('');
$('#scii').val('');
$('#sociaa').val('');
$('#cree').val('');
$('#CTremark').val('');

  }else
  {
    document.getElementById("submarks").disabled = false;
  }
  
   $.ajax({
          url:"getpupildetails.php",
           method:"POST",
           data:{id:id,eid:eid},
           dataType:"json",
           success:function(data)
           { 
             $('#labelclass').html(data.Claz);
             $('#labelclassteacher').html(data.nm);
             $('#langg').val(data.lang);
             $('#compoo').val(data.com);
             $('#lugaa').val(data.lugg);
             $('#inshaa').val(data.ins);
             $('#mathh').val(data.mat);
             $('#scii').val(data.sia);
             $('#sociaa').val(data.ss);
             $('#cree').val(data.cre);
             $('#CTremark').val(data.rema);
           }
          });
}
</script>

<script>
  function getenglish()
  {
    var lang = document.getElementById('lang').value;
    var comp = document.getElementById('compo').value;
    if(lang==''){lang='0';}
    if(comp==''){comp='0';}
    
    const la=parseInt(lang);
    const co=parseInt(comp);
    var tot=la+co;
    document.getElementById('etotal').innerHTML=tot;
  }
  
  function getkiswahili()
  {
    var lug = document.getElementById('luga').value;
    var insh = document.getElementById('insha').value;
    if(lug==''){lug='0';}
    if(insh==''){insh='0';}
    
    const lu=parseInt(lug);
    const ins=parseInt(insh);
    var tott=lu+ins;
    document.getElementById('kitotal').innerHTML=tott;
  }
  
  
  function getsscre()
  {
    var soc = document.getElementById('socia').value;
    var cre = document.getElementById('cre').value;
    if(soc==''){soc='0';}
    if(cre==''){cre='0';}
    
    const socials=parseInt(soc);
    const cr=parseInt(cre);
    var tota='';
    var too=socials+cr;
    if(too<10)
    {
       tota=too+1; 
    }else if(too>9 && too<20)
    {
        tota=too+2; 
    }
    else if(too>19 && too<30)
    {
        tota=too+3; 
    }
    else if(too>29 && too<40)
    {
        tota=too+4; 
    }
    else if(too>39 && too<50)
    {
        tota=too+5; 
    }
    else if(too>49 && too<60)
    {
        tota=too+6; 
    }
    else if(too>59 && too<70)
    {
        tota=too+7; 
    }
    else if(too>69 && too<80)
    {
        tota=too+8; 
    }
    else if(too>79 && too<90)
    {
        tota=too+9; 
    }else if(too==90)
    {
        tota=too+10; 
    }else if(too>90)
    {
        tota=100;
    }
    
    document.getElementById('sstotal').innerHTML=tota;
  }
</script>

<script>
       $(document).ready(function() 
       {
        $("#saveoutoff").click(function()
        {
        var lang = document.getElementById('lang').value;
        var comp = document.getElementById('compo').value; 
        var lu= document.getElementById('luga').value; 
        var ins = document.getElementById('insha').value;
        var math = document.getElementById('math').value; 
        var sc = document.getElementById('sci').value; 
        var soc = document.getElementById('socia').value;
        var cre = document.getElementById('cre').value;
        var total = document.getElementById('sstotal').innerHTML;
          
         if(comp=='' || lang=='' || lu=='' || ins=='' || math=='' || sc=='' ||  soc=='' || cre=='')
         {
                $('#message').html("All subjects must be filled").css('color', 'red');
                setInterval(function ()
                {
                 $('#message').html("").css('color', 'red');
                }, 2500);
         }else
         {
          if(lang==''){lang='0';}
          if(comp==''){comp='0';}
          if(lu==''){lu='0';}
          if(ins==''){ins='0';}
          if(math==''){math='0';}
          if(sc==''){sc='0';}
          if(soc==''){soc='0';}
          if(cre==''){cre='0';}
          if(total==''){total='0';}
           
          const la=parseInt(lang);
          const co=parseInt(comp);
          const lug=parseInt(lu);
          const insh=parseInt(ins);
          const ma=parseInt(math);
          const sci=parseInt(sc);
          const soci=parseInt(soc);
          const cr=parseInt(cre);
          const tot=parseInt(total);
          
          var totalm=la+co+lug+insh+ma+sci+tot;
           document.getElementById('totalmarks').innerHTML=totalm;
          
           $.ajax({
           url:"savesubjectsmarks.php",
           method:"POST",
           data:{la:la,co:co,lug:lug,insh:insh,ma:ma,sci:sci,soci:soci,cr:cr,total:total},
           success:function(data)
           {
            if(data=='Successfully saved')
            {
                $('#message').html("Successfully Saved").css('color', 'green');
                setInterval(function ()
                {
                 $('#message').html("").css('color', 'green');
                }, 2000);   
            }else
            {
             $('#message').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#message').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>


<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".deleteachers", function()
 { 
    var currentRow=$(this).closest("tr"); 
    var id = currentRow.find(".techerid").val();  
    let text = "Are you sure you want to delete this Imprest record?";
  if (confirm(text) == true)
  {
       $.ajax({
      url:"deleteclasst.php",
       method:"POST",
       data:{id:id},
       success:function(data)
       {
        if(data=='success')
        {
        $('#techersavemsg').html('Record deleted successfully').css('color', 'red'); 
        setInterval(function ()
        {
        window.location.href='Exams.php?page=Home';
        }, 3000);
        }
        else
        {
        $('#techersavemsg').html(data).css('color', 'red'); 
        
        setInterval(function ()
        {
        $('#techersavemsg').html('').css('color', 'red');
        }, 2000);
        } 
       }
       });
 }
      
 });
  });
</script>



<script>
$(document).ready(function (e) 
{
$("#modalimprestitems").submit(function()
{ 
 $('#expefeedback').html('').css('color', 'red'); 
 var tit=document.getElementById('itemu').value;

if(tit=='')
{
$('#expefeedback').html("You MUST enter expenses item").css('color', 'red');
  setInterval(function ()
    {
      $('#expefeedback').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"managexpenses.php",
    method:"POST",
    data:{tit:tit},
    success:function(data)
    {
        
    if(data=='success')
    {
     $('#expefeedback').html('Item saved successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#expefeedback').html('').css('color', 'red');
     window.location.href='index.php?page=Expenses';
    }, 3000);
    }
    else
    {
    $('#expefeedback').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#expefeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#expefeedback').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

<script>
$(document).ready(function (e) 
{
$("#addimpitems").click(function()
{ 
 $('#modalimprestitems').modal('show'); 
});
  });
  </script>

<script>
       $(document).ready(function() 
       {
        $("#btnuserdataupdate").click(function()
        {
        var id = document.getElementById('useridholderedit').value;
        var lev = document.getElementById('emplevel').value; 
        var aces = document.getElementById('systemacess').value; 

         if(lev=='' || aces==''  )
         {
            $('#mesage').html("All fields must be filled").css('color', 'red');
            
            setInterval(function ()
            {
            $('#mesage').html("").css('color', 'red');
            }, 3500);  
         }else
         {  
         $.ajax({
           url:"updateusersacessdata.php",
           method:"POST",
           data:{id:id,lev:lev,aces:aces},
           success:function(data)
           {    
            if(data=='success')
            {
                $('#mesage').html("Update successful").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=users";
                }, 2000);   
            }else
            {
             $('#mesage').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#mesage').html("").css('color', 'red');
            
                }, 2000);    
            }
           } 
           });
         }
    });
       }); 
  </script>


 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".deleteotherincome", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".otid").val();
     
     let text = "Are you sure you want to remove this data?";
     if (confirm(text) == true) 
     { 
      $.ajax({
           url:"removeotherincome.php",
           method:"POST",
           data:{id:id},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Record successfully deleted');
            setInterval(function ()
            {
            window.location.href="index.php?page=Other_Earning";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            window.location.href="index.php?page=Other_Earning";
            }, 2000);    
            }
           }
          });
     }
       });   
    });
  </script>


<script>
       $(document).ready(function() 
       {
        $("#submarks").click(function()
        {
        var lang = document.getElementById('langg').value;
        var comp = document.getElementById('compoo').value; 
        var lu= document.getElementById('lugaa').value; 
        var ins = document.getElementById('inshaa').value;
        var math = document.getElementById('mathh').value; 
        var sc = document.getElementById('scii').value; 
        var soc = document.getElementById('sociaa').value;
        var cre = document.getElementById('cree').value;
        var total = document.getElementById('sstotall').innerHTML;
        var remark = document.getElementById('CTremark').value; 
        var grd = document.getElementById('labelclass').innerHTML; 
        
        var sscr = document.getElementById('sicalcretota').value;
        var tm = document.getElementById('TotalM').value;
        
        var pid = document.getElementById('Selectpupi').value;
        var eid = document.getElementById('examid').value;
          
         if(comp=='' || lang=='' || lu=='' || ins=='' || math=='' || sc=='' ||  soc=='' || cre=='')
         {
                $('#outputmsg').html("All subjects must be filled").css('color', 'red');
                setInterval(function ()
                {
                 $('#outputmsg').html("").css('color', 'red');
                }, 2500);
         }else
         {
          if(lang==''){lang='0';}
          if(comp==''){comp='0';}
          if(lu==''){lu='0';}
          if(ins==''){ins='0';}
          if(math==''){math='0';}
          if(sc==''){sc='0';}
          if(soc==''){soc='0';}
          if(cre==''){cre='0';}
          if(total==''){total='0';}
           
          const la=parseInt(lang);
          const co=parseInt(comp);
          const lug=parseInt(lu);
          const insh=parseInt(ins);
          const ma=parseInt(math);
          const sci=parseInt(sc);
          const soci=parseInt(soc);
          const cr=parseInt(cre);
          const tot=parseInt(total);
          
          //var totalm=la+co+lug+insh+ma+sci+tot;
         $.ajax({
          url:"savemarksentries.php",
           method:"POST",
           data:{pid:pid,eid:eid,la:la,co:co,lug:lug,insh:insh,ma:ma,sci:sci,soci:soci,cr:cr,remark:remark,grd:grd,sscr:sscr,tm:tm},
           success:function(data)
           {    
            if(data=='Details saved successfully')
            {
            $('#outputmsg').html("Details saved successfully").css('color', 'green');
            setInterval(function ()
            {
                $('#outputmsg').html("").css('color', 'green');
             //window.location.href="index.php?page=Exams.php?page=Home";
            }, 2500);   
            }else
            {
             $('#outputmsg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
               $('#outputmsg').html("").css('color', 'red');
            
                }, 2000);    
            }
           } 
           });
      }
       });
       }); 
  </script>
  

  <script>
 $(document).ready(function (e) 
{
          $("#Selectpupi").click(function()
          {
              
          var pid=this.value;
          alert(pid);
          
          $.ajax({
          url:"getpupildetails.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           { 
               //var cl=data.Claz;
               //alert(cl);
             //$('#labelclass').html(data.Claz);
             //$('#otdatee').val(data.Date);
           }
          });
         //$('#modalotherincome').modal('show'); 
    });
});
    </script>

<script>
       $(document).ready(function() 
       {
        $("#saveexam").click(function()
        {
        var tit = document.getElementById('txtone').value;
        var sd = document.getElementById('txtthree').value; 
        var ed = document.getElementById('txtfour').value;
        var period = document.getElementById('txttwo').value;
        
         if(tit=='' || period=='')
         {
                $('#exammsg').html("You must enter both Title and exam period").css('color', 'red');
                setInterval(function ()
                {
                 $('#exammsg').html("").css('color', 'red');
                }, 2500);
         }else
         {
           $.ajax({
           url:"saveexam.php",
           method:"POST",
           data:{tit:tit,sd:sd,ed:ed,peri:period},
           success:function(data)
           {
            if(data=='Successfully saved')
            {
                $('#exammsg').html("Successfully Saved").css('color', 'green');
                setInterval(function ()
                {
                  window.location.href="Exams.php?page=Home";
                }, 2000);   
            }else
            {
             $('#exammsg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#exammsg').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>

<script>
 $(function(){
  $("#Selectpupi").select2();
 }); 
</script>

<script>
       $(document).ready(function() 
       {
        $("#finish").click(function()
        {
        var tea = document.getElementById('Selectteachers').value;
        var clas = document.getElementById('clazz').value; 
 
         if(tea=='' || clas=='')
         {
                $('#techersavemsg').html("Make sure you select both the teacher and his/her respective class").css('color', 'red');
                setInterval(function ()
                {
                 $('#techersavemsg').html("").css('color', 'red');
                }, 2500);
         }else
         {
           $.ajax({
           url:"saveteacher.php",
           method:"POST",
           data:{te:tea,claz:clas},
           success:function(data)
           {
            if(data=='Successfully saved')
            {
                $('#techersavemsg').html("Successfully Saved").css('color', 'green');
                setInterval(function ()
                {
                  window.location.href="Exams.php?page=Home";
                }, 2000);   
            }else
            {
             $('#techersavemsg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#techersavemsg').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>
  

 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".exadelete", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".examidd").val();
  
     
     let text = "Are you sure you want to remove this exam?";
     if (confirm(text) == true) 
     { 
      $.ajax({
          url:"removeexam.php",
           method:"POST",
           data:{id:id},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Exam data successfully deleted');
            setInterval(function ()
            {
            window.location.href="Exams.php?page=Home";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            window.location.href="Exams.php?page=Home";
            }, 2000);    
            }
           }
          });
     }
       });   
    });
  </script>
  
  <script>
        $(document).ready(function () 
        {
        $('#yearfilterincome').on('change', function()
        {
        var yr=this.value;
        window.location.href="index.php?page=Income&Year="+yr;
        });
        });
</script>

<script>
        $(document).ready(function () 
        {
        $('#yearfilter').on('change', function()
        {
        var yr=this.value;
        window.location.href="index.php?page=Expenditure&Year="+yr;
        });
        });
</script>

 <script>
 $(document).ready(function (e) 
 {
    setInterval(function ()
    {
      var session = document.getElementById('sessionholder').value;
      if(session=='' || session==null)
      {
        window.location.href='../';
      }
    }, 500);
 });
  </script> 

<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
   
<!--script src="schedule/js/scriptt.js"></script-->
   </body>
</html>
