<?php
//
require_once '../../vendor/autoload.php';
include('../../class/Database.php');
include('header.php');
//
//
use PhpOffice\PhpWord\TemplateProcessor;
//
$object = new Database;
//
?>

  <!-- 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>Surat Keluar</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">Surat Keluar</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">
                <a href="../forms/surat_keluar.php"><button type="button" class="btn  btn-primary" >Tambah Surat Keluar</button></a>
                <!--h3 class="card-title">DataTable with default features</h3-->
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table id="example1" class="table table-bordered table-hover">
                  <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>
                  
                  </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,
      "processing" : true,
    "serverSide" : true,
    "order" : [],
    "ajax" : {
      url:"surat_keluar2_action.php",
      type:"POST",
      data:{action:'fetch'}
    },
    "columnDefs":[
      {
        "targets":[8,9],
        "orderable":false,
      },
    ],
      "buttons": ["excel", "pdf", "print", "colvis"],
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');

    //
    $('.edit_button').click(function() {
      var no_urut = $(this).data('id');
      var kode_naskah = $(this).data('status');
      $.ajax({        
        success: function (response) {
          //
            my_form=document.createElement('FORM');
            my_form.name='myForm';
            my_form.method='POST';
            my_form.action='../forms/surat_keluar.php';

            my_tb=document.createElement('INPUT');
            my_tb.type='TEXT';
            my_tb.name='myInput';
            my_tb.value= no_urut;
            my_form.appendChild(my_tb);
            my_tb2=document.createElement('INPUT');
            my_tb2.type='TEXT';
            my_tb2.name='kode_naskah';
            my_tb2.value= kode_naskah;
            my_form.appendChild(my_tb2);
            document.body.appendChild(my_form);
            my_form.submit();
            },
            error: function(e){
                alert('Error: '+e);
            }  
        });
    });
    $('.status_button').click(function() {
      var no_urut = $(this).data('id');
      var kode_naskah = $(this).data('status');
      if(confirm("Apa Anda Yakin ingin memberi nomor?"))
      {
        $.ajax({        
        success: function (response) {
          //
            my_form=document.createElement('FORM');
            my_form.name='myForm';
            my_form.method='POST';
            my_form.action='../tables/surat_keluar.php';

            my_tb=document.createElement('INPUT');
            my_tb.type='TEXT';
            my_tb.name='action';
            my_tb.value= 'ubah_nomor';
            my_form.appendChild(my_tb);
            my_tb2=document.createElement('INPUT');
            my_tb2.type='TEXT';
            my_tb2.name='id';
            my_tb2.value= no_urut;
            my_form.appendChild(my_tb2);
            my_tb3=document.createElement('INPUT');
            my_tb3.type='TEXT';
            my_tb3.name='kode_naskah';
            my_tb3.value= kode_naskah;
            my_form.appendChild(my_tb3);
            document.body.appendChild(my_form);
            my_form.submit();
            },
            error: function(e){
                alert('Error: '+e);
            }  
        });
        //alert("Kasih nomor "+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();
  if($_POST["action"] = 'add_surat')  echo "toastr.success('Data berhasil disimpan.'); ";
  elseif($_POST["action"] = 'edit_surat')  echo "toastr.success('Data berhasil diubah.'); ";
  }
 ?>
</script>
</body>
</html>
