 <!-- Main content -->
<section class="content" style="zoom : 90%;">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <div class="row">
              <div class="col-sm-6">
                <h3 class="card-title">Detail Riwayat Barang ( <?php echo $page[2]; ?> )</h3>
              </div>
              <div class="col-sm-6">
                <ol class="float-sm-right mb-0">
                </ol>
              </div>
            </div>
          </div>
              <!-- /.card-header -->
          <div class="card-body">
            <table id="example1" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th>No</th>
                <th>Nama Barang</th>
                <th>Jumlah Barang</th>
                <th>Status</th>
                <th>Waktu</th>
                <th>Keterangan</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php
                $no = 1;
                $aserver = mysqli_query($con,"SELECT * FROM gudang WHERE id_data_server = '$page[1]' AND nama = '$page[2]'");
                while ($server = mysqli_fetch_assoc($aserver)) 
                {
              ?>
              <tr>
                <td style="max-width: 30px;"><?php echo $no; ?></td>
                <td style="max-width: 200px;"><?php echo $server['nama']; ?></td>
                <td style="max-width: 200px;"><?php echo $server['jumlah']; ?></td>
                <td style="max-width: 200px;"><?php echo $server['status']; ?></td>
                <td style="max-width: 200px;"><?php echo $server['start_time']; ?></td>
                <td style="max-width: 30px;"><?php echo $server['keterangan']; ?></td>
                <td>
                  <form method="post">
                    <a type="button" class="btn btn-secondary btn-sm m-1" data-toggle="modal" data-target="#staticEdit<?php echo $server['id']; ?>">Edit</a>
                    <input type="submit" class="btn btn-danger btn-sm m-1" name="hapus<?php echo $server['id']; ?>" value="Hapus">
                  </form>
                </td>
              </tr>
              <div class="modal fade" id="staticEdit<?php echo $server['id']; ?>" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <form method="post" enctype="multipart/form-data">
                      <div class="modal-header bg-secondary">
                        <h5 class="modal-title" id="staticBackdropLabel">Ubah Data Barang ( <?php echo $server['nama']; ?> )</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <div class="row">
                          <div class="card-body pb-0">
                            <div class="form-group">
                              <label>Jenis Barang</label>
                              <select class="form-control" name="jenis" required="required">
                                <option value="Baru" <?php if($server['jenis'] == 'Baru'){echo "selected";} ?>>Baru</option>
                                <option value="Bekas" <?php if($server['jenis'] == 'Bekas'){echo "selected";} ?>>Bekas</option>
                              </select>
                            </div>
                            <div class="form-group">
                              <label>Jumlah</label>
                              <input type="text" value="<?php echo $server['jumlah'] ?>" class="form-control" name="jumlah" required="required">
                            </div>
                            <div class="form-group">
                              <label>Keterangan</label>
                              <textarea  class="form-control" name="keterangan" required="required" rows="5"><?php echo $server['keterangan'] ?></textarea>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <input type="submit" name="tambah<?php echo $server['id']; ?>" class="btn btn-primary" value="Simpan">
                      </div>
                    </form>
                    <?php
                   if (isset($_POST['tambah'.$server['id']])) {
                        $waktu = date('Y-m-d H:i:s');

                        $sql = "INSERT INTO gudang (id_data_server, id_user_akses, start_time, nama, status, jenis, masuk, keterangan) 
                                VALUES (:ids, :userId, :waktu, :nama, 'masuk', :jenis, :jumlah, :keterangan)";
                        $sql = "UPDATE gudang SET jenis = :jenis, jumlah = :jumlah, keterangan = :keterangan WHERE id = :id ";
                        try {
                            // Prepare the statement
                            $stmt = $pdo->prepare($sql);
                            $stmt->bindParam(':jenis', $_POST['jenis']);
                            $stmt->bindParam(':jumlah', $_POST['jumlah']);
                            $stmt->bindParam(':keterangan', $_POST['keterangan']);
                            $stmt->bindParam(':id', $server['id']);

                            // Execute the statement
                            $stmt->execute();
                            sweetAlert("Data telah di Ubah", "success");

                        } catch (PDOException $e) {
                            // Handle error
                            // echo 'Error: ' . $e->getMessage();
                            sweetAlert($e->getMessage(), "error");
                        }
                    }
                    ?>
                  </div>
                </div>
              </div>
            <?php

            if (isset($_POST['hapus'.$server['id']]))
            {
              $iddata = $server['id'];
              deleteAlert("gudang",$iddata );
            }
             $no ++; } ?>
              </tbody>
            </table>
          </div>
          <!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container-fluid -->
</section>