<?php
//
include('../../class/Database.php');
//
$object = new Database;
if(!$object->is_login())
{
    header("location:".$object->base_url);
}
include('header.php');

//
if(isset($_POST["action"]))
  {
  if($_POST["action"]=='edit_ttd')
  {
    //$object->query = "UPDATE verifikator SET status = '".$_POST['kodettd']."', id_pejabat = '".$_POST['penandatangan']."' WHERE id_ttd = '".$_POST['hidden_id']."' ";
    //$object->execute();
  } elseif ($_POST["action"]=='add_verif') {
    $object->query = "  INSERT INTO verifikator (id_user, id_pejabat)  
    VALUES (1,'".$_POST["penandatangan"]."')";
    $object->execute();
  }
  
  }
//
$main_query = " SELECT * FROM verifikator INNER JOIN akun_user, jabatan WHERE verifikator.id_pejabat=akun_user.id_user AND akun_user.id_jabatan = jabatan.id_jabatan ";

?>
  <!-- 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>Verifikator</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">Verifikator</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/verifikator.php"><button type="button" class="btn  btn-primary" >Tambah Verifikator</button></a>
                <!--h3 class="card-title">DataTable with default features</h3-->
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table id="tandatangan" class="table table-bordered table-striped">
                  <thead>
                  <tr>
                    <th>Nama Penanda Tangan</th>
                    <th>Jabatan </th>
                    <th></th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php
                    $object->query = $main_query;
                    $result = $object->get_result();
                    foreach($result as $row)
                    {
                      echo '<tr><td>'.$row["nama"].'</td>';
                      echo '<td>'.$row["nama_jabatan"].'</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_verif"].'"><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 = $("#tandatangan").DataTable({
      "fixedColumns": true,
      "scrollX": true,
      "responsive": true, 
      "lengthChange": false, 
      "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
    }).buttons().container().appendTo('#tandatangan_wrapper .col-md-6:eq(0)');

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

          my_tb=document.createElement('INPUT');
          my_tb.type='TEXT';
          my_tb.name='myInput';
          my_tb.value= no_urut;
          my_form.appendChild(my_tb);
          document.body.appendChild(my_form);
          my_form.submit();
      },
      error: function(e){
          alert('Error: '+e);
      }  
});
    });

});
 <?php
  if(isset($_POST["action"]))
  {
  //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"]=='edit_verif')
  {
    echo "toastr.success('Data berhasil diubah '); ";
  } elseif($_POST["action"]=='add_verif'){
    echo "toastr.success('Data berhasil disimpan '); ";
  }
  
  }
 ?>
</script>
</body>
</html>
