<?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('Documents Successfully Uploaded!','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 Student List</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">
                     Student
                    </li>
                    <li class="breadcrumb-item"><a href="registration.php">Add Student</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>Student ID</th>
                          <th>Student Name</th>
                          <th>Date of Birth</th>      
                          <th>Reg. Date</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        
                              <?php
                                
                                $obj=new Database();
                                $obj->select('students','*',null,null,'id DESC',null);
                                $result=$obj->getResult(); 
                               
                                $c=1;                              
                                foreach($result as list("id"=>$id,"student_id"=>$b_no,"name"=>$name,"dob"=>$dob,"date"=>$date))
                                {
                                  echo "<tr><td>$c</td><td class='id'><a href='#'>$b_no</a></td><td>$name</td><td>$dob</td><td>$date</td><td><a href='#?s_id=".$b_no."' class='badge btn-info btn-view' data-id=".$id."><span class='mdi-delete'></span></a></td></tr>";
                                  $c=$c+1;
                                }
                                ?>
                      </tbody>
                      
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <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>
<div class="modal" id="myModal">
  <div class="modal-dialog" style="max-width: 72%;">
    <div class="modal-content">
      <form action="" method="POST" id="formView">
      <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Student Details</h4>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>
      <!-- Modal body -->
      <div class="modal-body">
                
                   
                   <div class="row">                                                    
                                                 <div class="col-md-4">                                       
                                                               <div class="card-body">
                                                                   
                                                                    <div class="form-group row">
                                                                        <label for="s_id"
                                                                        class="col-sm-3 text-end  col-form-label">Student ID</label>
                                                                        <div class="col-sm-9">
                                                                            <input type="text" class="form-control" id="s_id" name="s_id" readonly/>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                        S. Name</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">
                                                                        F. Name</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="text" class="form-control" id="f_name" name="f_name" readonly/>
                                                                        </div>
                                                                    </div>       
                                                                </div>
                                                            
                                                    </div>
                                                    <div class="col-md-4">
                                                    <div class="card-body">
                                                                   
                                                                   <div class="form-group row">
                                                                       <label for="s_id"
                                                                       class="col-sm-3 text-end control-label col-form-label">Gender</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="gender" name="gender"  readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                       DOB</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="dob" name="dob" readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                       Reg Date</label>
                                                                       <div class="col-sm-9">
                                                                       <input type="text" class="form-control" id="reg_date" name="reg_date" readonly/>
                                                                       </div>
                                                                   </div>       

                                                               </div>
                                                    </div>  
                                                    <div class="col-md-4">
                                                    <div class="card-body">                        
                                                                   <div class="form-group row">
                                                                       <label for="s_id"
                                                                       class="col-sm-3 text-end control-label col-form-label">Mobile No</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="mobile" name="mobile" readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                       Other No</label>
                                                                       <div class="col-sm-9">
                                                                           <input type="text" class="form-control" id="o_no" name="o_no" readonly/>
                                                                       </div>
                                                                   </div>
                                                                   <div class="form-group row">
                                                                       <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                       Email</label>
                                                                       <div class="col-sm-9">
                                                                       <input type="text" class="form-control" id="email" name="email" readonly/>
                                                                       </div>
                                                                   </div>       
                                                                   <div class="form-group row">
                                                                       <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                                                                       Address</label>
                                                                       <div class="col-sm-9">
                                                                       <textarea type="text" class="form-control" 
                                                                       rows="2"  id="address" name="address" readonly></textarea>
                                                                       </div>
                                                                   </div>  
                                                               </div>
                                                    </div>  
                                                    <div class="col-md-6">
                                                        <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                                        <tr><td>   
                                                            <div class="card-body">                                                  
                                                              <div class="table-responsive" style="width:100%; height:200px; overflow:auto;">    
                                                                <table id="data-table" class="table">
                                                                  <thead class="table-light">
                                                                    <tr>
                                                                      <th scope="col">S.No</th>
                                                                      <th scope="col">Documents</th>                                                           
                                                                      <th scope="col">Documents No</th>
                                                                      
                                                                    </tr>
                                                                  </thead>
                                                                  <tbody id="tbody">                       
                                                                        
                                                                  </tbody>                  
                                                                </table>  
                                                                </div> 
                                                          </div>
                                                          </td></tr>    
                                                          </table> 
                                                    </div>
                                                    <div class="col-md-6">
                                                      <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                                      <tr><td>   
                                                          <div class="card-body">                                                  
                                                            <div class="table-responsive" style="width:100%; height:200px; overflow:auto;">    
                                                              <table id="data-table" class="table">
                                                                <thead class="table-light">
                                                                  <tr>
                                                                    <th scope="col">S.No</th>
                                                                    <th scope="col">Batch No</th>                                                           
                                                                    <th scope="col">Course Name</th>
                                                                    <th scope="col">Status</th>
                                                                  </tr>
                                                                </thead>
                                                                <tbody id="tbody2">                       
                                                                      
                                                                </tbody>                  
                                                              </table>  
                                                              </div> 
                                                        </div>
                                                        </td></tr>    
                                                        </table> 
                                                    </div>
     
                                          </div>
      <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" id="assign" class="btn btn-info">Assign Course</button>
          <button type="submit" id="attendence" class="btn btn-info">Add Attendence</button>
          <button id="a_exam" type="submit" class="btn btn-info" >Assign Exam</button>
          <button id="a_result" class="btn btn-info" id="save_data">Assign Results</button>
          <button id="pay_fee" type="submit" class="btn btn-info">Pay Fee</button>
          <button id="upload" type="submit" class="btn btn-info">Upload Documents</button>
          <button class='btn btn-danger' id='delete'>Delete Students</button>
          <button type="button" class="btn btn-primary" id="print">Print Formsheet</button>
        </div>
        </form>
    </div>
  </div>
</div>
</div>


          <!-- ============================================================== -->
          <!-- End PAge Content -->
          <!-- ============================================================== -->
          <!-- ============================================================== -->
          <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(){
    $("#assign").click(function() {      
        $("#formView").attr("action","assign-course.php");        
    });
    $("#attendence").click(function() {      
        $("#formView").attr("action","attendence.php");        
    });
    $("#a_exam").click(function() {      
        $("#formView").attr("action","student-exam.php");        
    });
    $("#a_result").click(function() {      
        $("#formView").attr("action","results.php");        
    });
    $("#pay_fee").click(function() {      
        $("#formView").attr("action","student-fee.php");        
    });
    $("#upload").click(function() {      
        $("#formView").attr("action","documentation.php");        
    });
    $("#delete").click(function() {      
      var id=$("#s_id").val();  
      var name=$("#s_name").val();  
      if (confirm('Do you really want to Delete Students?\n\n('+id+') '+name,"")) {
        $.ajax({
                                url:"../admin/core/delete.php",
                                method:"post",
                                data: {
                                   id:id,
                                   state:'std',                          
                                },
                                success: function(data){                        
                                  if(data.length===1)
                                  {
                                    //$("#id").closest('tr').remove();
                                    showAlert('Stundents Successfully Deleted!','success');
                                    setTimeout(function(){window.location='./students.php';}, 2000);                                   
                                  }
                                }
                            }); 


      } 

    });
    $("#zero_config").DataTable();  
    $(".id").click(function() {
         var id = $(this).closest('tr').find('td.id').text();            
                           $.ajax({
                                url:"../admin/core/fetch-student.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'info',                                
                                },
                                success: function(data){ 

                                    $.each(data,function(key,value){  
                                          $('#s_id').val(id);                           
                                          $('#s_name').val(value['name']);
                                          $('#f_name').val(value['father_name']);    
                                          $('#gender').val(value['gender']);  
                                          $('#dob').val(value['dob']);  
                                          $('#mobile').val(value['mobile_no']);  
                                          $('#o_no').val(value['o_contact_no']);  
                                          $('#email').val(value['email']);     
                                          $('#reg_date').val(value['date']);     
                                          $('#address').val(value['address']);  
                                                                                       
                                        })
                                }
                            });
                            $.ajax({
                                url:"../admin/core/fetch-student.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'doc',                                
                                },
                                success: function(data){ 
                                  var c=0;
                                    $('#tbody').empty();
                                    $.each(data,function(key,value){  
                                          c=c+1;                                  
                                          $('#tbody').append('<tr><td>'+c+'</td><td><a href="#" class="btn-view" data-id='+value['path']+'>'+value['document_name']+'</a></td><td>'+value['document_no']+'</td></tr>');                                                         
                                        })
                                }
                            });
                            $.ajax({
                                url:"../admin/core/fetch-student.php",
                                method:"post",
                                data: {
                                    id:id,
                                    state:'course',                                
                                },
                                success: function(data){ 
                                  var c=0;
                                    $('#tbody2').empty();
                                    $.each(data,function(key,value){  
                                          c=c+1;                                  
                                          $('#tbody2').append('<tr><td>'+c+'</td><td><a href="Invoice.php?batch_no='+value['batch_no']+'">'+value['batch_no']+'</a></td><td>'+value['course_name']+'</td><td>'+value['status']+'</td></tr>');                                                         
                                        })
                                }
                            });
         $("#myModal").modal('show');
     });

      $("#data-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="./docs/'+$(this).data("id")+'" draggable="false" style="max-width:400px;width:390px;height:400px;"></object>';                        
          $('#myModal').modal('toggle'); $('#view').modal('show');
          $("#modal_body").empty();
          $("#modal_body").append(total1);

     });
     $("#zero_config").on("click", "#id", function() {              
                var id = $(this).data("id");                      
                       
      });
 });
    </script>
  </body>
</html>