SHARE
TWEET

listBuku2.php

a guest Dec 6th, 2016 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //$userID = "";
  3. $jum =0;
  4. session_start();
  5. function connectDB() {
  6.   $servername = "localhost";
  7.   $username = "root";
  8.   $password = "";
  9.   $dbname = "tappw";
  10.  
  11.       // Create connection
  12.   $conn = mysqli_connect($servername, $username, $password, $dbname);
  13.  
  14.       // Check connection
  15.   if (!$conn) {
  16.     die("Connection failed: " + mysqli_connect_error());
  17.   }
  18.   return $conn;
  19. }
  20.  
  21. function selectAllFromTableBook($table) {
  22.   $conn = connectDB();
  23.  
  24.   $sql = "SELECT user_id, book_id FROM $table";
  25.  
  26.   if(!$result = mysqli_query($conn, $sql)) {
  27.     die("Error: $sql");
  28.   }
  29.   mysqli_close($conn);
  30.   return $result;
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37. function selectBooksByUserId($userId) {
  38.   $conn = connectDB();
  39.   $sql = "SELECT book_id FROM loan WHERE user_id = $userId";
  40.  
  41.   if(!$result = mysqli_query($conn, $sql)) {
  42.     die("Error: $sql");
  43.   }
  44.   mysqli_query($conn, $sql);
  45.  
  46.   mysqli_close($conn);
  47.   return $result;
  48. }
  49.  
  50. function getBookDetailById($id) {
  51.  $conn = connectDB();
  52.  
  53.  $sql = "SELECT book_id, img_path, title, author, publisher, quantity FROM book WHERE book_id = $id";
  54.  
  55.  if(!$result = mysqli_query($conn, $sql)) {
  56.   die("Error: $sql");
  57. }
  58. mysqli_close($conn);
  59. return $result;
  60. }
  61.  
  62.     function balikanBuku($bookID) {
  63.       $conn = connectDB();
  64.       $IDuser = $_SESSION['user_id'];
  65.  
  66.       $sql  = "DELETE FROM loan WHERE user_id =$IDuser AND book_id=$bookID";
  67.       $sql2 = "UPDATE book SET quantity=$jum+1 WHERE book_id=$bookID";
  68.  
  69.  
  70.       // if(!$result = mysqli_query($conn, $sql)) {
  71.       //   die("Error: $sql");
  72.       // }
  73.       //
  74.       // if(!$result2 = mysqli_query($conn, $sql2)) {
  75.       //   die("Error: $sql2");
  76.       // }
  77.       // mysqli_close($conn);
  78.  
  79.     }
  80.  
  81. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  82.   if($_POST['command'] === 'bookDetail') {
  83.     getBookDetailById($_POST['bookDetail']);
  84.   }
  85.  
  86.   else if ($_POST['command'] === 'kembalikanBuku') {
  87.     balikanBuku($_POST['kembalikanBuku']);
  88.   }
  89.  
  90.  
  91. }
  92.  
  93. ?>
  94.  
  95. <!DOCTYPE html>
  96. <html lang="id">
  97. <head>
  98.   <title>PerpusOnline.com | Baca Buku ? Disini aja !</title>
  99.   <meta charset="utf-8">
  100.   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  101.   <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700">
  102.   <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/icon?family=Material+Icons">
  103.   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  104.   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  105.   <link rel="stylesheet" type="text/css" href="libs/bootstrap-material-design/dist/css/bootstrap-material-design.css">
  106.   <link rel="stylesheet" type="text/css" href="libs/bootstrap-material-design/dist/css/ripples.css">
  107.   <link rel="stylesheet" type="text/css" href="src/css/style.css">
  108.   <script type="text/javascript" src="libs/bootstrap-material-design/dist/js/material.js"></script>
  109.   <script type="text/javascript" src="libs/bootstrap-material-design/dist/js/ripples.js"></script>
  110.  
  111.  
  112.   <script type="text/javascript">
  113.     $(document).ready(function() {
  114.       $.material.init();
  115.       $.material.input();
  116.  
  117.       $("#show").click(function() {
  118.        $("#tabel").fadeToggle();
  119.      })
  120.  
  121.       $("#hide").click(function() {
  122.        $("#tabel").fadeOut();
  123.      })
  124.  
  125.       $("#drop").click(function() {
  126.         $("#login-dp").fadeToggle();
  127.       })
  128.     });
  129.   </script>
  130.  
  131. </head>
  132.  
  133. <body data-spy="scroll" data-target="#myScrollspy" data-offset="20">
  134.  
  135.  
  136.  <nav class="navbar navbar-fixed-top col-md-12">
  137.    <div class="container-fluid">
  138.      <div class="navbar-header">
  139.        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
  140.          <span class="icon-bar"></span>
  141.          <span class="icon-bar"></span>
  142.          <span class="icon-bar"></span>
  143.        </button>
  144.        <a class="navbar-brand" href="javascript:void(0)">PerpusOnline.com</a>
  145.      </div>
  146.      <div class="navbar-collapse collapse navbar-responsive-collapse" id="myScrollspy">
  147.        <form class="navbar-form navbar-left">
  148.          <div class="form-group">
  149.            <input type="text" class="form-control col-md-8" placeholder="Search">
  150.          </div>
  151.        </form>
  152.        <ul class="nav navbar-nav navbar-right">
  153.          <li><a href="index.php">Beranda</a></li>
  154.          <?php
  155.          if (isset($_SESSION['role'])) {
  156.            if ($_SESSION['role'] === "admin") {
  157.             echo "<li><a href='admin.php'>Tambah Buku</a></li>";
  158.           }elseif ($_SESSION['role'] === "user") {
  159.             // echo "<li><a href='listBuku.php'>Buku Dipinjam</a></li>";
  160.             echo "<li><a href='#tabel'>Buku Dipinjam</a></li>";
  161.           }
  162.         }
  163.         ?>
  164.         <!-- <li><a href="#tabel">Daftar Buku</a></li> -->
  165.         <?php
  166.         if (isset($_SESSION['role'])) {
  167.           $nama = $_SESSION['user'];
  168.           // $userID = getUserID($nama);
  169.           //echo "$nama";
  170.           echo "<script type='text/javascript'>
  171.          function logout() {
  172.            $.get('logout.php');
  173.            window.location.assign('index.php');
  174.            return false;
  175.          }
  176.        </script>
  177.        <li class='dropdown' >
  178.          <a href='#' id='drop' class='dropdown-toggle' data-toggle='dropdown'><b>Welcome $nama</b><span class='caret'></span></a>
  179.          <ul id='login-dp' class='dropdown-menu'>
  180.            <button type='submit' id='logout' style='color: black;' onclick='logout();' class='btn btn-primary btn-block'>Sign out</button>
  181.          </ul>
  182.        </li>";
  183.       }
  184.       else {
  185.         echo '
  186.        <li class="dropdown" >
  187.         <a href="#" id="drop" class="dropdown-toggle" data-toggle="dropdown">Login <span class="caret"></span></a>
  188.         <ul id="login-dp" class="dropdown-menu">
  189.           <li>
  190.            <div class="row">
  191.             <div class="col-md-12">
  192.              <form class="form-horizontal" role="form" method="post" action="login.php" accept-charset="UTF-8" id="login-nav">
  193.               <div class="form-group">
  194.                <label class="sr-only" for="inputUser">Username</label>
  195.                <input name="username" type="text" class="form-control input" id="inputUser" placeholder="Username" required>
  196.              </div>
  197.              <div class="form-group">
  198.                <label class="sr-only" for="inputPass">Password</label>
  199.                <input name="password" type="password" class="form-control input" id="inputPass" placeholder="Password" required>
  200.              </div>
  201.              <div class="col-md-10 col-md-offset-2">
  202.                <button type="submit" id="login" class="btn btn-primary btn-block">Sign in</button>
  203.              </div>
  204.            </form>
  205.          </div>
  206.        </div>
  207.      </li>
  208.    </ul>
  209.  </li>
  210.  ';
  211. }
  212. ?>
  213.  
  214. </ul>
  215. </div>
  216. </div>
  217. </nav>
  218. <br>
  219. <br>
  220. <br>
  221.  
  222. <div class="container" id="home">
  223.  
  224.  
  225.  <?php
  226.  
  227.  if (isset($_SESSION['role'])) {
  228.    $nama = $_SESSION['user'];
  229.    //$userID = $_SESSION['user_id'];
  230.      //echo "$nama";
  231.    echo "  <h1 class='perpus'>Welcome $nama !</h1>
  232.   <p id='descPerpus' class='text-primary'>Klik Tombol Dibawah Untuk Melihat Daftar Bukumu !</p>
  233.  
  234.   ";
  235.  }
  236.  ?>
  237.  
  238.  <button type="button" name="button" id="show" class="btn btn-raised btn-primary">Daftar Buku</button>
  239. </div>
  240.  
  241. <br>
  242. <br>
  243. <br>
  244.  
  245. <div class="container-fluid">
  246.  <div class="tableBook" id="tabel">
  247.    <table class="table table-striped table-hover table-bordered">
  248.      <thead>
  249.       <tr class="success">
  250.         <th class="head">Buku</th>
  251.         <th class="head">Judul</th>
  252.         <th class="head">Pengarang</th>
  253.         <th class="head">Penerbit</th>
  254.         <th class="head">Jumlah</th>
  255.         <th class="head">Action</th>
  256.       </tr>
  257.     </thead>
  258.     <tbody  >
  259.       <?php
  260.       $borrowed_books = mysqli_fetch_row(selectBooksByUserId($_SESSION['user_id']));
  261.       //echo print_r($borrowed_books);
  262.       $IDuser = $_SESSION['user_id'];
  263.  
  264.       foreach($borrowed_books as $keys => $bookId) {
  265.         $bookDetails = getBookDetailById($bookId);
  266.         while ($row = mysqli_fetch_row($bookDetails)) {
  267.          echo "<tr class='info'>";
  268.  
  269.          $currentBookId = null;
  270.          foreach($row as $key => $value) {
  271.           if ($key == 0) {
  272.             $currentBookId = $value;
  273.           }
  274.           else if ($key == 1) {
  275.             echo "<td>
  276.  
  277.            <a href='$value' data-toggle='tooltip' title='Click to See Book Image' ><img data-toggle='modal'
  278.              data-target='#myModal' src='$value'
  279.              alt='gambar buku' height='150' width='100'/></a>
  280.  
  281.  
  282.            </td>";
  283.                           //echo "<td><img  src='$value' alt='gambar buku' height='150' width='100'/></td>";
  284.           }
  285.           else if ($key == 5) {
  286.             $jum = $value;
  287.               echo "<td>$value</td>";
  288.           }
  289.           else {
  290.             echo "<td>$value</td>";
  291.           }
  292.         }
  293.         echo '<td>
  294.        <form action="listBuku2.php" method="post">
  295.         <input type="hidden" id="delete-userid" name="kembalikanBuku" value="'.$row[0].$_SESSION['user_id'].'">
  296.         <input type="hidden" id="delete-command" name="command" value="kembalikanBuku">
  297.         <button type="submit" class="btn btn-raised btn-primary">kembalikan Buku</b></button>
  298.  
  299.         <input type="hidden" id="delete-userid" name="bookDetail" value="'.$row[0].'">
  300.         <input type="hidden" id="delete-command" name="command" value="detail">
  301.         <button type="submit" class="btn btn-raised btn-primary">DETAILS</button>
  302.       </form>
  303.     </td>';
  304.      echo "</tr>";
  305.    }
  306.  }
  307.  ?>
  308. </tbody>
  309. </table>
  310. <button type="button" name="button" id="hide" class="btn btn-raised btn-primary">Tutup Daftar</button>
  311. <br>
  312. </div>
  313.  
  314. </div>
  315.  
  316. <div class="footer">
  317.   <hr>
  318.   <footer>
  319.     <p class="text-center"> &copy; 2016 PerpusOnline Inc.</p>
  320.   </footer>
  321. </div>
  322.  
  323.  
  324.  
  325. </body>
  326. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top