<?php
include_once 'header.php';
if(isset($_GET['msg']))
{
  ?> 
   <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
      <script>
      var msg;
      var icon;
      function showAlert(msg,icon) {
          Swal.fire({
              title: msg,
              icon: icon,
              confirmButtonText: 'Close'
          });
      }
      $(document).ready(function($) {
        showAlert('Exam Record Successfully Added!','success');       
        setTimeout(function(){window.location.href =  window.location.href.split("?")[0];}, 2000); 
              });
  </script> 
    <?php
}
?>
<div class="page-wrapper">
        <!-- ============================================================== -->
        <!-- Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <div class="page-breadcrumb">
          <div class="row">
            <div class="col-12 d-flex no-block align-items-center">
              <h4 class="page-title">All  Results List of Student </h4>
              <div class="ms-auto text-end">
                <nav aria-label="breadcrumb">
                  <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="#">Dashboard</a></li>
                    <li class="breadcrumb-item active" aria-current="page">
                     Examination
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">
                    <a href="#" id="add">Add Results</a>
                    </li>
                  </ol>
                </nav>
              </div>
            </div>
          </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->   
        <div class="container-fluid row">
            <div class="col-12">  
              <div class="card">
                <div class="card-body">
                  <h5 class="card-title"> </h5>
                  <div class="table-responsive">
                    <table id="zero_config" class="table table-striped table-bordered">
                      <thead>
                      <tr>
                          <th>S.No</th>
                          <th>Batch No</th>
                          <th>Student Name</th>
                          <th>Exam Date</th>
                          <th>Result Date</th>
                          <th>Status</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>                       
                              <?php
                                
                                $obj=new Database();
                                $id='';
                                if(isset($_POST['s_id']))
                                {
                                    $id=" and student_id=".$_POST['s_id'];                                 
                                   
                                }
                                else{
                                   $id=null;
                                }
                                $s="er_date!=''".$id;
                                $obj->select('student_exam','*',null,$s,'id DESC',null);
                                $result=$obj->getResult(); 
                                $c=0;                                                             
                                foreach($result as list("id"=>$id,"batch_no"=>$batch_no,"student_name"=>$s_name,"er_date"=>$er_date,"exam_date"=>$e_date,"result_status"=>$status,"r_path"=>$path))
                                {                           
                                  $c=$c+1;
                                  echo "<tr><td>$c</td><td><a href='#' class='btn-view' data-id='".$path."'>$batch_no</a></td><td>$s_name</td><td>$e_date</td><td>$er_date</td><td>$status</td><td><button type='button' class='badge btn-info' ><span class='mdi-delete'></span></button>&nbsp;&nbsp;<button type='button' class='badge btn-danger btn-delete' data-id=".$id.">X</button></td></tr>";
                                }                 
                                ?>
                      </tbody>                  
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- ============================================================== -->
          <!-- End PAge Content -->
          <!-- ============================================================== -->
          <!-- ============================================================== -->
          <div class="modal fade" id="view" 
            tabindex="-1" 
            aria-labelledby="exampleModalLabel" 
            aria-hidden="true">          
            <div class="modal-dialog" style="max-width:25%;">
                <div class="modal-content">            
                    <div class="modal-body" style="margin:auto;">
                        <div id="modal_body"></div>
                     
                    </div>
                </div>
            </div>
        </div>
<!-- The Modal -->
<div class="modal" id="myModal">
  <div class="modal-dialog" style="max-width: 72%;">
    <div class="modal-content">
      <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Add Results of Student</h4>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>
      <!-- Modal body -->
      <div class="modal-body">
       <form class="form-horizontal" id="modelForm" action="core/student-exam.php" method="post" enctype="multipart/form-data">
                              <div class="row">                                                    
                                                 <div class="col-md-6">
                                                        <div class="card">
                                                          
                                                                <div class="card-body">
                                                                <input type="hidden" class="form-control" name="state" value="result" readonly/>
                                                                       
                                                                    <h4 class="card-title"></h4>
                                                                    <div class="form-group row">
                                                                        <label for="s_id"
                                                                        class="col-sm-3 text-end control-label col-form-label">Student ID</label>
                                                                        <div class="col-sm-9">
                                                                        <?php
                                                                        if(isset($_POST['s_id']))
                                                                        {
                                                                            echo "<select class='form-control' id='s_id' name='s_id'>";
                                                                            echo "<option></option><option>".$_POST['s_id']."</option></select>";
                                                                           
                                                                        }
                                                                        else
                                                                        {
                                                                          echo  "<input type='text' class='form-control' id='s_id' placeholder='Student ID'/>";

                                                                        }

                                                                        ?>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                        StudentName</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="s_name" name="s_name" readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                        Father Name</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="text" class="form-control" id="fname"  readonly/>
                                                                        </div>
                                                                    </div>       
                                               
                                                                    <div class="form-group row">
                                                                        <label for="batch_no" class="col-sm-3 text-end control-label col-form-label">Batch No</label>
                                                                        <div class="col-sm-9">
                                                                            <select class="form-control" id="batch_no" name="batch_no">
                                                                              
                                          
                                                                            </select>
                                                                        </div>
                                                                    </div>
                                                                    
                                                                    <div class="form-group row">
                                                                            <label for="c_name" class="col-sm-3 text-end control-label col-form-label">Exam Name</label>
                                                                            <div class="col-sm-9">
                                                                                <select class="form-control" id="c_name" name="c_name">
                                                                                    <option></option>
                                                                              
                                                                                </select>
                                                                          </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="e_type" class="col-sm-3 text-end control-label col-form-label">Exam Type</label>
                                                                        <div class="col-sm-9">
                                                                            <select class="form-control" id="e_type" name="e_type">
                                                                                <option></option>                                                                          
                                                                            </select>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                           
                                                        </div>                            
                                                    </div>
                                                    <div class="col-md-6">
                                                        <div class="card">                 
                                                                <div class="card-body">
                                                                    <h4 class="card-title"></h4>
                                                                    <div class="form-group row">
                                                                        <label for="_type" class="col-sm-3 text-end control-label col-form-label">Exam Cycle</label>
                                                                        <div class="col-sm-9">
                                                                            <select class="form-control" id="_type" name="_type">
                                                                                <option></option>                                                                          
                                                                            </select>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="ht_no" class="col-sm-3 text-end control-label col-form-label">
                                                                        HT No/R.No</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="ht_no" name="ht_no" readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="e_date" class="col-sm-3 text-end control-label col-form-label">
                                                                        Exam Date</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="text" class="form-control" id="e_date" name="e_date" readonly/>
                                                                        </div>
                                                                    </div>       
                                               
                                                                    <div class="form-group row">
                                                                        <label for="er_date" class="col-sm-3 text-end control-label col-form-label">
                                                                        Result Date</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="date" class="form-control" id="er_date" name="er_date"/>
                                                                        </div>
                                                                    </div>
                                                                    
                                                                    <div class="form-group row">
                                                                        <label for="file" class="col-sm-3 text-end control-label col-form-label">
                                                                        Result File</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="file" class="form-control" id="file" name="file" />
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="desc" class="col-sm-3 text-end control-label col-form-label">
                                                                        Result Status</label>
                                                                        <div class="col-sm-9">
                                                                        <select class="form-control" id="status" name="status">
                                                                              <option></option>
                                                                              <option>Passed</option>
                                                                              <option>Failed</option>
                                          
                                                                        </select>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                        </div>
                                                   
                                                         
                                                    </div>
                                                    <div class="modal-footer">
                                                      <button type="submit" class="btn btn-danger" id="save_data">Save Record</button>
                                                    </div>
                              </div>  </form>              
      </div>
      <!-- Modal footer -->
      

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

 




          <footer class="footer text-center">
          All Rights Reserved by ECI. Designed and Developed by
          <a href="https://www.ntlogix.in">NTLogix</a>.
        </footer>
       
   <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="../assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="../assets/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="../assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="../assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="../dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="../dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="../dist/js/custom.min.js"></script>
    <!-- this page js -->
    <script src="../assets/extra-libs/multicheck/datatable-checkbox-init.js"></script>
    <script src="../assets/extra-libs/multicheck/jquery.multicheck.js"></script>
    <script src="../assets/extra-libs/DataTables/datatables.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
   
    <script>
        
      var msg;
      var icon;
      function showAlert(msg,icon) {
          Swal.fire({
              title: msg,
              icon: icon,
              confirmButtonText: 'Close'
          });
      }
   
   $(document).ready(function(){
                  $("#zero_config").DataTable();
                  $("table").on("click",".btn-view",function(){

                        //var total='<iframe class="frame" style="overflow: hidden" src="./docs/'+$(this).data("id")+'" style="width:100%;height:380px;"></iframe>';
                        var total1='<object  data="../admin/result/'+$(this).data("id")+'" draggable="false" style="max-width:400px;width:390px;height:400px;"></object>';                        
                        $('#view').modal('show');
                        $("#modal_body").empty();
                        $("#modal_body").append(total1);

                  });
                  $("table").on("click",".btn-delete",function(){
                    var id = $('.btn-delete').data("id");
                    if (confirm('Do you really want to Delete Attendence!',"")) {                       
                    $.ajax({
                                url:"core/delete.php",
                                method:"post",
                                data: {
                                   id:id,
                                   state:'std_res',                          
                                },
                                success: function(data){                        
                                  if(data.length===1)
                                  {                            
                                    showAlert('Results List Successfully Deleted!','success');
                                    setTimeout(function(){window.location='./results.php';}, 2000);                                   
                                  }
                                }
                            });   
                          }

                    });
                  $("#save_data").click(function(e){
                    var e_date=$('#e_date').val();
                    var er_date=$('#er_date').val();
                    var status=$('#status').val();
                    var file=$('#file').val();
                    if((er_date.length===0)||(e_date.length===0)||(status.length===0))
                    {
                      e.preventDefault();
                      showAlert('some field is empty!','warning');
                      return 0;
                    }
                  });
                       
                  $('#add').click(function(e){                     
                        e.preventDefault();
                        $("#modelForm").get(0).reset()             
                      setTimeout(function(){$("#myModal").modal('show');}, 100);
                  });
           
                  $('#batch_no').change(function(){
                    var id = $("#batch_no").val();
                            $.ajax({
                                url:"core/fetch-exam.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'csm',                          
                                },
                                success: function(data){                                
                                      if(data)
                                      {
                                        $("#c_name").empty();
                                        $.each(data, function(key, value) {
                                                $('#c_name')
                                                      .append($('<option>', { value : value })
                                                      .text(value));
                                            });
                                       }    
                                }
                            });  
                  }); 
                  $('#c_name').change(function(){
                    var id = $("#c_name").val();
                    var batch_no = $("#c_name").val();
                            $.ajax({
                                url:"core/fetch-exam.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'exm1', 
                                    batch_no:batch_no,                         
                                },
                                success: function(data){                                
                                      if(data)
                                      {
                                        $("#e_type").empty();
                                        $.each(data, function(key, value) {
                                                $('#e_type')
                                                      .append($('<option>', { value : value })
                                                      .text(value));
                                            });
                                       }
                                          
                                }
                            });  
                  });
                  $('#e_type').change(function(){
                    var id = $("#e_type").val();
                    var batch_no = $("#batch_no").val();
                            $.ajax({
                                url:"core/fetch-exam.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'exm2', 
                                    batch_no:batch_no,                         
                                },
                                success: function(data){                                
                                      if(data)
                                      {
                                        $("#_type").empty();
                                        var c=0;
                                        $.each(data, function(key, value) {  
                                          if(value!==' '){ c=c+1;
                                            var s='EXAM-'+c;}else{var s=value;}                                                                       
                                                $('#_type')
                                                      .append($('<option>', { value : value })
                                                      .text(s));     
                                            });
                                       }
                                          
                                }
                            });  
                  });
                  $('#_type').change(function(){
                    var id = $("#_type").val();
                            $.ajax({
                                url:"core/fetch-exam.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'exm3',                                        
                                },
                                success: function(data){                                
                                    $('#e_date').val(data[0]['exam_date']);
                                    $('#ht_no').val(data[0]['ht_no']); 
                                    if(data[0]['r_path']!=='')
                                    {
                                      showAlert('Already Uploaded!','warning');
                                      $('#er_date').attr('type', 'text');
                                      $('#er_date').val(data[0]['er_date']);
                                    }
                                }
                            });  
                  });
                  $('#s_id').keypress(function (e) {    
    
                      var charCode = (e.which) ? e.which : event.keyCode    

                      if (String.fromCharCode(charCode).match(/[^0-9]/g))    

                          return false;                        

                  });
                  $('#s_id').change(function(){
                            var name = $("#s_id").val();
                            $.ajax({
                                url:"core/fetch_student.php",
                                method:"post",
                                data: {
                                    name:name,                          
                                },
                                success: function(data){ 
                                    $('#s_name').val(data[0].name);
                                    $('#fname').val(data[0].father_name);                                                              
                                    if(data===0)
                                    {                                   
                                    $('#name').val('');
                                    $('#fname').val('');                                  
                                    $('#batch_no').val(null).trigger('change');                               
                                    }
                                }
                            }); 
                            var id = $("#s_id").val();
                            $.ajax({
                                url:"core/fetch_asignCourse.php",
                                method:"post",
                                data: {
                                    id:id,                          
                                },
                                success: function(data){                                
                                      if(data)
                                      {
                                        $("#batch_no").empty();
                                        $.each(data, function(key, value) {
                                                $('#batch_no')
                                                      .append($('<option>', { value : value })
                                                      .text(value));
                                            });
                                       }
                                          
                                }
                            });                 
                });

      
    });

</script>

  </body>
</html>