<?php
//
include('../../class/Database.php');
include('header.php');
//
$object = new Database;
//


$main_query = "
    SELECT id_surat,kode_naskah,jenis_naskah.jenis_naskah,nomor,perihal,tujuan,klasifikasi,satuan_kerja,tanggal,tanda_tangan,template,surat_keluar.status FROM surat_keluar INNER JOIN jenis_naskah,satuan_kerja,tanda_tangan WHERE surat_keluar.jenis_naskah=jenis_naskah.kode_naskah AND satuan_kerja.kode_satker=surat_keluar.satker AND ttd=tanda_tangan.kode_ttd ";

?>


  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>DataTables</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">DataTables</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">DataTable with default features</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table id="example1" class="table table-bordered table-striped">
                  <thead>
                  <tr>
                    <th>jenis naskah</th>
                    <th>nomor surat</th>
                    <th>perihal</th>
                    <th>tujuan</th>
                    <th>satuan kerja</th>
                    <th>tanggal</th>
                    <th>penanda tangan</th>
                    <th>template</th>
                    <th>setujui</th>
                    <th></th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php
                    $object->query = $main_query;
                    $result = $object->get_result();
                    foreach($result as $row)
                    {
                      echo '<tr><td>'.$row["jenis_naskah"].'</td>';
                      echo '<td>'.$row["nomor"].'</td>';
                      echo '<td>'.$row["perihal"].'</td>';
                      echo '<td>'.$row["tujuan"].'</td>';
                      echo '<td>'.$row["satuan_kerja"].'</td>';
                      echo '<td>'.$row["tanggal"].'</td>';
                      echo '<td>'.$row["tanda_tangan"].'</td>';
                      $file_extension = pathinfo($row["template"], PATHINFO_EXTENSION);
                      if($file_extension=='docx')
                      {
                        echo '<td><center><a href="'.$row["template"].'"><i class="fas fa-file-word" style="font-size:36px;color:blue"></i></a></center></td>';
                      }
                      else {
                        echo '<td><center><a href="'.$row["template"].'"><i class="fas fa-file-pdf" style="font-size:36px;color:red"></i></a></center></td>';
                      }
                      if($row["status"] == 0) 
                      {
                        echo '<td><button type="button" name="status_button" class="btn btn-primary btn-sm status_button" data-id="'.$row["id_surat"].'" data-status="'.$row["kode_naskah"].'"> Approve </button></td>';
                        
                      } else echo '<td><hidden></hidden></td>';
                      echo '<td><div align="center">
                      <button type="button" name="edit_button" class="btn btn-warning btn-circle btn-sm edit_button" data-id="'.$row["id_surat"].'"><i class="fas fa-edit"></i></button>
                      </div></td></tr>';
                    }
                  ?>
                  
                  </tbody>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <footer class="main-footer">
    <div class="float-right d-none d-sm-block">
      <b>Version</b> 3.2.0
    </div>
    <strong>Copyright &copy; 2014-2021 <a href="https://adminlte.io">AdminLTE.io</a>.</strong> All rights reserved.
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<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/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/jszip/jszip.min.js"></script>
<script src="../../plugins/pdfmake/pdfmake.min.js"></script>
<script src="../../plugins/pdfmake/vfs_fonts.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>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- Toastr -->
<script src="../../plugins/toastr/toastr.min.js"></script>
<!-- Page specific script -->
<script type="text/javascript" language="javascript" >
 $(document).ready(function(){
    var dataTable = $("#example1").DataTable({
      "fixedColumns": true,
      "scrollX": true,
      "responsive": true, 
      "lengthChange": false, 
      "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');

    //
    $('.edit_button').click(function() {
      var no_urut = $(this).data('id');
      alert( "Ediiiittttt "+no_urut);
    });

});
 <?php
  if(isset($_POST["penandatangan"]))
  {
  //echo '<script>alert( "Form successful submitted! '.implode(", ",$_POST["select23"]).'");</script>';
  /*echo '<script>alert( "Form successful submitted! ';
  foreach($_POST["select23"] as $value) {
    echo $qtyOut = $value." ";
  }
  echo '")</script>;';*/
  //echo '<script>alert( "'.$_POST["penandatangan"].'-'.$_POST["kodettd"].'");</script>';
  //$object->query = "
  //  INSERT INTO tanda_tangan (tanda_tangan, kode_ttd) 
  //  VALUES ('".$_POST["penandatangan"]."', '".$_POST["kodettd"]."')";
  //$object->execute();
  echo "toastr.success('Data berhasil disimpan.'); ";
  }
 ?>
</script>
</body>
</html>
