Advertisement
gurumutant

Shopping Cart dg Session - Halaman Produk

Feb 2nd, 2020
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.29 KB | None | 0 0
  1. <!-- pages/produk.php -->
  2. <div class="container-fluid">
  3.           <!-- Page Heading -->
  4.           <div class="d-sm-flex align-items-center justify-content-between mb-4">
  5.             <h1 class="h3 mb-0 text-gray-800">Kategori Buku</h1>          
  6.           </div>
  7.            
  8.           <?php tampilPesan(); ?>
  9.           <div class="row"> <!-- start row untuk tabel -->
  10.             <div class="col-xl-12 col-md-12 mb-12">
  11.                 <table class="table table-striped" id="tabel_kategori">
  12.                     <thead>
  13.                     <tr>
  14.                         <th>ID Produk</th>
  15.                         <th>Nama Produk</th>
  16.                         <th>Stok</th>
  17.                         <th>Aksi</th>
  18.                     </tr>
  19.                     </thead>
  20.                     <tbody>
  21.                     <?php // mengambil data untuk ditampilkan di tabel
  22.                         $sql = "SELECT *
  23.                                FROM produk
  24.                                 ORDER BY prod_id DESC";
  25.                         $stmt = $conn->query($sql);
  26.                         while ($row = $stmt->fetch(PDO::FETCH_OBJ)):
  27.                     ?>
  28.                     <tr>
  29.                         <td><?= $row->prod_id; ?></td>
  30.                         <td><?= $row->prod_nama; ?></td>
  31.                         <td><?= $row->prod_stok; ?></td>
  32.                         <td>
  33.                             <a href="proses/add-cart.php?id=<?= $row->prod_id; ?>" data-remote="false" class="btn btn-info btn-sm" >Beli</a>
  34.                             <?php if(batasiTampilan([1,9])): ?>
  35.                             <a href="?p=kategori&id=<?= $row->Kode_Kategori; ?>" class="btn btn-sm btn-warning">Edit</a>
  36.                             <a href="proses/kategori-proses.php?id=<?= $row->Kode_Kategori; ?>" class="btn btn-sm btn-danger confirm">Hapus</a>
  37.                             <?php endif; ?>
  38.                         </td>
  39.                     </tr>  
  40.                         <?php endwhile; ?>
  41.                     </tbody>
  42.                 </table>
  43.             </div>
  44.           </div> <!-- end row untuk tabel -->
  45.         <!-- /.container-fluid -->
  46. </div>
  47. <!-- Modal -->
  48. <div id="myModal" class="modal fade" role="dialog">
  49.     <div class="modal-dialog">
  50.  
  51.         <!-- Modal content-->
  52.         <div class="modal-content">
  53.             <div class="modal-header">
  54.                 <h4 class="modal-title">Detail Kategori</h4>
  55.                 <button type="button" class="close" data-dismiss="modal">&times;</button>
  56.             </div>
  57.             <div class="modal-body">
  58.                 <p>Some text in the modal.</p>
  59.             </div>
  60.             <div class="modal-footer">
  61.                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  62.             </div>
  63.         </div>
  64.  
  65.     </div>
  66. </div>
  67. <script>
  68.     $(document).ready(function() {
  69.         $('#tabel_kategori').DataTable({
  70.             "language": {
  71.                 "url": "http://localhost/pwd2019/perpustakaan/vendor/datatables/Indonesian.json"
  72.             }
  73.         });
  74.  
  75.     });
  76.  
  77. $('a.confirm').bind('click',function(e) {
  78.     var baris = $(this).parents('tr');
  79.     e.preventDefault();
  80.     var url = $(this).attr('href');
  81.     Swal.fire({
  82.       title: 'Anda yakin untuk menghapus?',
  83.       text: "Data yang sudah dihapus tidak dapat dikembalikan lagi.",
  84.       type: 'warning',
  85.       showCancelButton: true,
  86.       confirmButtonColor: '#3085d6',
  87.       cancelButtonColor: '#d33',
  88.       confirmButtonText: 'Ya, saya yakin',
  89.       cancelButtonText: 'Tidak, saya khilaf'
  90.     }).then((result) => {
  91.       if (result.value) {
  92.         $.get(url).done(function(response) {
  93.             Swal.fire('Data berhasil dihapus').then((result) => {
  94.                     baris.remove();
  95.                 });
  96.         });
  97.       }
  98.     });
  99.  
  100. });
  101. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement