<?php
include_once 'header.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">Add Documents 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">
                     Student
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">
                    <a href="#" >Add Documents</a>
                    </li>
                  </ol>
                </nav>
              </div>
            </div>
          </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->   
<!-- The Modal -->

<div class="container-fluid"> <div class="card">
                              <div class="row">                                                    
                                                 <div class="col-md-6">
                                                       
                                                            <form class="form-horizontal" id="form" action="./core/documentation.php" method="post" enctype="multipart/form-data">
                                                                <div class="card-body">
                                                                   
                                                                    <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">
                              
                                                                            <select class="form-control" id="s_id" name="s_id" >
                                                                                  <option></option>
                                                                                  <option><?php if(isset($_POST['s_id'])){ echo $_POST['s_id'];} ?></option>
                                                                                       
                                                                            </select>
                                                                          </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                        <label for="s_name" class="col-sm-3 text-end control-label col-form-label">
                                                                        Student 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">
                                                                        Father Name</label>
                                                                        <div class="col-sm-9">
                                                                        <input type="text" class="form-control" id="fname" name="fname" readonly/>
                                                                        </div>
                                                                    </div>       
                                               
                                                                    <div class="form-group row">
                                                                        <label for="doc_name" class="col-sm-3 text-end control-label col-form-label">Documents</label>
                                                                        <div class="col-sm-9">
                                                                            <select class="form-control" id="doc_name" name="doc_name">
                                                                                  <option></option>
                                                                                  <option value='Adhar Card'>Adhar Card</option>
                                                                                  <option value='Pan Card'>Pan Card</option>
                                                                                  <option value='Apaar Id'>Apaar ID</option>
                                                                                  <option value='Light Bill'>Light Bill</option>
                                                                                  <option value='Hsc Certificate'>Hsc Certificate</option>
                                                                                  <option value='Ssc Certificate'>Ssc Certificate</option>
                                                                                  <option value='Passport Photo'>Passport Photo</option>
                                                                                  <option value='Signature'>Signature</option>
                                                                                  <option value='Thumb'>Thumb</option>            
                                                                            </select>
                                                                        </div>
                                                                    </div>
                                                                    
                                                                    <div class="form-group row">
                                                                            <label for="doc_no" class="col-sm-3 text-end control-label col-form-label">Document No</label>
                                                                            <div class="col-sm-9">
                                                                                <input type="text" class="form-control date-inputmask" id="doc_no" name="doc_no" placeholder=""/>
                                                                            </div>
                                                                    </div>
                                                                    <div class="form-group row">
                                                                            <label for="file" class="col-sm-3 text-end control-label col-form-label">Path</label>
                                                                            <div class="col-sm-9">
                                                                                <input type="file" accept="application/pdf,image/jpeg" class="form-control date-inputmask" id="file" name="file"/>
                                                                            </div>
                                                                    </div>
                                                                    <div class="border-top">
                                                                        <div class="card-body">
                                                                          <button type="submit" id="save_data" class="btn btn-primary">
                                                                            Upload Document 
                                                                          </button>
                                                                        </div>
                                                                  </div>  
                                                              
                                                                </div>
                                                            </form>  
                                                    </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:300px; 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>
                                                                  <th scope="col">Action</th>
                                                                </tr>
                                                              </thead>
                                                              <tbody id="tbody">                       
                                                                    
                                                              </tbody>                  
                                                            </table>  
                                                            </div> 
                                                      </div>
                                                      </td></tr>    
                                                       </table> 
                                                     </div>        
                                                    </div>      
      </div>
      <!-- Modal footer --> 
</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>


          <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();
                  $("#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>';                        
                            $('#view').modal('show');
                            $("#modal_body").empty();
                            $("#modal_body").append(total1);
                        
                  });
                  $("#data-table").on("click","#btn-del",function(){
                    if (confirm('Are you sure want to Delete Documents!',"")) { 
                      var id=$(this).data("id");
                      //$(this).closest('tr').remove();
                      $.ajax({
                                  url:"core/delete.php",
                                  method:"post",
                                  data: {
                                    id:id,
                                    state:'docs',                          
                                  },
                                  success: function(data){                        
                                    if(data.length===1)
                                    {                            
                                      showAlert('Documents Successfully Deleted!','success');
                                      setTimeout(function(){window.location='./students.php';}, 2000);                                   
                                    }
                                  }
                              }); 
                            }

                  });
                  $('#doc_name').change(function(){
                      if($("#doc_name").val()=='Adhar Card'){
                           $('#doc_no').attr('placeholder','Please Enter 12 Digit Adhar No');   
                      }
                      else if($("#doc_name").val()=='Pan Card'){
                           $('#doc_no').attr('placeholder','Please Enter 10 Char PAN No');   
                      }
                      else if($("#doc_name").val()=='Light Bill'){
                           $('#doc_no').attr('placeholder','Please Enter Consumer No');   
                      }
                      else if($("#doc_name").val()=='Hsc Certificate'){
                           $('#doc_no').attr('placeholder','Please Enter Hsc Certificate No');   
                      }
                      else if($("#doc_name").val()=='Ssc Certificate'){
                           $('#doc_no').attr('placeholder','Please Enter Ssc Certificate No');   
                      }
                      else if($("#doc_name").val()=='Apaar Id'){
                           $('#doc_no').attr('placeholder','Please Enter Apaar ID No');   
                      }
                      else
                      {
                        $('#doc_no').attr('placeholder','N/a');  
                      }
                  });
                  $('#s_id').change(function(){
                            var name = $("#s_id").val();
                            if(name.length===0){
                                    $('#s_name').val('');
                                    $('#fname').val('');                                  
                                    $('#doc_name').val(null).trigger('change');  
                              return 0;
                            }
                            $.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');                               
                                    }
                                }
                            }); 
                            
                            $.ajax({
                                url:"core/fetch_documents.php",
                                method:"post",
                                data: {
                                    name:name,                          
                                },
                                success: function(data){
                                  var c=0;
                                  $('#tbody').empty();
                                  $.each(data,function(key,value){
                                      c=c+1;                                      
                                     if(c<=10)
                                      {
                                        $("option[value='"+value['document_name']+"']").remove();
                                       
                                        $('#tbody').append('<tr><td>'+c+'</td><td class="btn-view" data-id="'+value['path']+'"><a href="#">'+value['document_name']+'</a></td><td>'+value['document_no']+'</td><td><button type="button" class="btn btn-danger" id="btn-del" data-id='+value['id']+'>X</button></tr>');                                                                                                            
                                      }
                                  })
                                
                                }
                            });                  
                });
               
              $("#form").submit(function(e){
                    var s_name = $("#s_name").val();
                    var doc_no = $("#doc_no").val();
                    var doc_name = $("#doc_name").val();               
                    var file = $("#file").val();                                 
                    if((s_name.length===0)||(doc_no.length===0)||(doc_name.length===0)||(file.length===0))
                    {
                       e.preventDefault(e);
                       showAlert('some field is empty!','warning');
                        return 0;
                      }  
   
               });

</script>

  </body>
</html>