loreng

Form

Apr 23rd, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.  
  4.     include '../system/class.php';
  5.     $user = new User();
  6.     if(isset($_GET['id']) && isset($_GET['do']))
  7.     {
  8.         if($_GET['do'] == "delete")
  9.         {
  10.             $id = $_GET['id'];
  11.             $user->doDeleteFromKeranjang($id);
  12.             header("Location: keranjang.php");
  13.         }
  14.     }
  15.  
  16.     if(isset($_POST['buat_transaksi']))
  17.     {
  18.         $isbn = $_POST['isbn'];
  19.         if($isbn == NULL)
  20.         {
  21.             header("Location: keranjang.php");
  22.         }
  23.         $no = 0;
  24.         $arrayCount = count($isbn);
  25.         if($arrayCount > 3)
  26.         {
  27.             echo "GAGAL!";
  28.         }
  29.         else
  30.         {
  31.             date_default_timezone_set('Asia/Jakarta');
  32.             $date = date('Y-m-d H:i:s');
  33.             $batas_ambil = date('Y-m-d H:i:s',strtotime('+1 days', strtotime($date)));
  34.             $tanggal_pinjam = date('Y-m-d H:i:s');
  35.             $tanggal_kembali = date('Y-m-d',strtotime('+3 weeks', strtotime($batas_ambil)));
  36.             $kode_transaksi = $user->getKT();
  37.             $status = "wishlist";
  38.             $id_peminjam = $user->getIdUser($_SESSION['PEMINJAM']);
  39.             $doTransaksi = $user->doCreateTransaksiNEW($kode_transaksi,$id_peminjam,$isbn,$batas_ambil,$tanggal_pinjam,$tanggal_kembali,$status);
  40.             if($doTransaksi === true)
  41.             {
  42.             echo "<script>alert('Berhasil Melakukan Transaksi!');window.location.href = 'index.php';</script>";            
  43.             }
  44.             else
  45.             {
  46.             echo "<script>
  47.                             alert('" . $doTransaksi . "');
  48.                             window.location.href = 'keranjang.php';
  49.                         </script>";
  50.             }
  51.         }
  52.     }
  53. ?>
  54. <!DOCTYPE html>
  55. <html>
  56.     <head>
  57.         <!-- Title -->
  58.         <title>Keranjang - User Perpustkaan</title>
  59.         <!-- CSS -->
  60.         <link rel="stylesheet" type="text/css" href="<?php echo HostUrl();?>/assets/bs4/css/bootstrap.min.css">
  61.     </head>
  62.     <body>
  63. <!-- NAV-BAR -->
  64. <?php include("prax/nav.php"); ?>
  65.  
  66.         <br>
  67.         <div class="container">
  68.             <div class="row">
  69.                 <div class="col">
  70.                     <h3>Daftar Keranjang Anda!</h3>
  71.                 </div>
  72.             </div>
  73.             <div class="row">
  74.                 <div class="col">
  75.                     <p>Dibawah ini adalah daftar keranjang Anda!</p>
  76.                 </div>
  77.             </div>
  78.             <hr>
  79.             <form method="POST"><table class="table table-bordered table-striped">
  80.                 <thead  class="thead-dark">
  81.                     <tr>
  82.                         <th style="width: 3%;" class="text-center">No</th>
  83.                         <th>Judul</th>
  84.                         <th class="text-center">Aksi</th>
  85.                     </tr>
  86.                 </thead>
  87.                 <tbody>
  88. <?php
  89.     $username = $_SESSION['PEMINJAM'];
  90.     $no = 1;
  91.     $get = $user->getDataKeranjang($username);
  92.     for ($i=0; $i < count($get) ; $i++) {
  93. ?>
  94.                     <tr>
  95.                         <input type="hidden" name="isbn[]" value="<?php echo $get[$i][2];?>">
  96.                         <td class="text-center"><?php echo $no;?></td>
  97.                         <td><?php echo $get[$i][5];?></td>
  98.                         <td class="text-center">
  99.                             <a href="?id=<?php echo $get[$i][0]?>&do=delete">Delete</a>
  100.                         </td>
  101.                     </tr>
  102. <?php
  103.     $no++;
  104.     }
  105. ?>
  106.  
  107.                 </tbody>
  108.                 <tfoot>
  109.                     <tr>
  110.                         <td colspan="4">
  111.                             <button name="buat_transaksi" class="btn btn-primary">Buat Transaksi</button>
  112.                         </td>
  113.                     </tr>
  114.                 </tfoot>
  115.             </table></form>
  116.         </div>
  117.     <script src="<?php echo HostUrl();?>/assets/bs3/js/jquery.min.js"></script>
  118.     <script src="<?php echo HostUrl();?>/assets/bs3/js/bootstrap.min.js"></script>
  119.     <script src="<?php echo HostUrl();?>/assets/bs3/js/popover.min.js"></script>
  120.     </body>
  121. </html>
Advertisement
Add Comment
Please, Sign In to add comment