<?php
     include_once('connect.php');
    session_start(); 
    
    // Check if the user is logged in
    if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
         echo "<script type='text/javascript'>window.location.href = 'index.php';</script>"; // Redirect to login page
        exit();
    }
    
    
    include_once('head.php');
?>
<head>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script type="text/javascript" language="javascript" >
      $(document).ready(function() {
        var dataTable = $('#tc-grid').DataTable( {
          "processing": true,
          "serverSide": true,
          "ajax":{
            url :"view_data.php", // json datasource
            type: "post",  // method  , by default get
            data: {id: 'tc'},
            error: function(){  // error handling
              $(".tc-grid-error").html("");
              $("#tc-grid").append('<tbody class="tc-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
              $("#tc-grid_processing").css("display","none");
              
            }
          }
        } );
      } );
    </script>
</head>

  <main id="main" class="main">

    <div class="pagetitle">
      
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.html">Home</a></li>
          <li class="breadcrumb-item active">View TC</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

     <section class="section">
      <div class="row">
        <div class="col-lg-11">
          <div class="card">
            <div class="card-body">
              <div class="row mb-3 bord-bottom" >
             <div class="col-lg-5"><h5 class="card-title">View All TC</h5></div>
              <div class="col-lg-5"><h5 class="card-title title-right"><a href="add_tc.php" class="btn btn-secondary">Add TC</a></h5></div>
              </div>
              
              <div class="sb2-2-1">
                    <div class="inn-title pt-20 ">
                        <h4></h4>
                        <p></p>
                    </div >
                    <div class="bor  ">
                         <table id="tc-grid"  cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
                        <thead>
                          <tr>
                            <th>Sl No.</th>
                            <!-- <th>tc Title</th> -->
                            <th>TC File</th>
                            <th>Edit</th>
                            <th>Delete</th>
                          </tr>
                        </thead>
                      </table>
                    </div>
                </div>
            </div>
          </div>

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

    <!-- Delete Modal HTML -->disclosure.html
    <div id="myModal" class="modal fade">
      <div class="modal-dialog">
        <div class="modal-content">
          <form>             
            <div class="modal-header">            
              <h4 class="modal-title">Delete tc</h4>
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
              <input type="hidden" id="id_d" name="id" class="form-control">          
              <p>Are you sure you want to delete these Records?</p>
              <p class="text-warning"><small>This action cannot be undone.</small></p>
            </div>
            <div class="modal-footer">
              <input type="hidden" value="deltc" name="type">
              <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
              <button type="button" class="btn btn-danger" id="delete" name="delete">Delete</button>
            </div>
          </form>
        </div>
      </div>
    </div>
    <!--delete modal ends-->

  </main><!-- End #main -->

  <?php
        include_once('footer.php');
   ?>
  
   
   <!-- Ajax-->
    <script type="text/javascript">
   
    $(document).on("click", ".delete", function() { 
      var id=$(this).attr("data-id");
      $('#id_d').val(id);
      
    });

    $("#delete").click(function() {     
      $.ajax({
        url: "delete_data.php",
        type: "POST",
        cache: false,
        data:{
          type:'deltc',
          id: $("#id_d").val()
        },
        success: function(dataResult){
          alert("TC deleted");
            $("#"+dataResult).remove();
            location.reload();
        
        }
      });
    });

    $("#file").change(function() {
    var file = this.files[0];
    var fileType = file.type;
    var match = ['application/pdf', 'application/msword', 'application/vnd.ms-office', 'image/jpeg', 'image/png', 'image/jpg'];
    if(!((fileType == match[0]) || (fileType == match[1]) || (fileType == match[2]) || (fileType == match[3]) || (fileType == match[4]) || (fileType == match[5]))){
        alert('Sorry, only PDF, DOC, JPG, JPEG, & PNG files are allowed to upload.');
        $("#file").val('');
        return false;
    }
});
    </script>
     <script type="text/javascript">
        function goBack() {
          window.history.back();
        }

    </script>

   