<?php
 $nowtime = strtotime(date('H:i:s')) + strtotime(date('Y-m-d'));
?>
<div class="wrapper">

  <!-- Navbar -->
  <nav class="main-header navbar navbar-expand-md navbar-light navbar-white">
    <div class="container">
      <a href="index.php" class="navbar-brand">

        <span class="brand-text font-weight-light">Siplabs</span>
      </a>

      <button class="navbar-toggler order-1" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse order-3" id="navbarCollapse">
        <!-- Left navbar links -->
        <ul class="navbar-nav">
          <li class="nav-item">
            <a href="<?php echo base_url('peminjam') ?>" class="nav-link">Beranda</a>
          </li>
          <li class="nav-item">
            <a href="<?php echo base_url('peminjam/jadwal') ?>" class="nav-link">Jadwal</a>
          </li>
          <li class="nav-item">
            <a href="<?php echo base_url('peminjam/inventaris') ?>" class="nav-link">Inventaris</a>
          </li>
        </ul>
      </div>

      <!-- Right navbar links -->
      <ul class="order-1 order-md-3 navbar-nav navbar-no-expand ml-auto">
      <li class="nav-item dropdown no-arrow">
      <?php $userprofile = $this->db->get_where('user',['id_user'=>$user])->row_array(); ?>
                <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="mr-2 d-none d-lg-inline text-gray-600 large"><?php echo $this->session->nama_lengkap; ?></span>
                      <img class="img-profile rounded"
                    src="<?php echo base_url('files/userprofil/' . $userprofile['image']) ?>" width="20px" border-radius= "50%">
              </a>
            <!-- Dropdown - User Information -->
              <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"
                aria-labelledby="userDropdown">
                  <a class="dropdown-item " href="<?php echo base_url('peminjam/profil');?>">
                      <i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
                      Profile
                  </a>
                <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logout">
                        <i class="fas fa-power-off fa-sm fa-fw mr-2 text-gray-400"></i>
                        Logout
                    </a>
               </div>
        </li>
      </ul>
    </div>
  </nav>
  <!-- /.navbar -->

  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark"> Peminjaman Inventaris</h1>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

     <!-- Main content -->
     <div class="content">
      <div class="container">
        <?php echo $this->session->flashdata('message'); ?>
        <div class="row">
          <?php foreach ($inventaris as $inv) : ?>
            <div class="col-md-4">
              <div class="card card-success">
                <div class="card-header">
                  <!-- menampilkan nama ruangan pada card -->
                  <h3 class="card-title"><?php echo $inv->nama_inv ?> <?= $inv->jenis ?></h3>

                  <div class="card-tools">
                    <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i>
                    </button>
                  </div>
                  <!-- /.card-tools -->
                </div>
                <!-- /.card-header -->
                <div class="card-body text-center">
                  <img src="<?php echo base_url('/files/inventaris/'. $inv->image);?> " width="200"><br><br>
                  <?php
                  $cek_user = $this->db->query('SELECT * FROM pinjam_inv INNER JOIN inventaris,user WHERE pinjam_inv.id_inv=inventaris.id_inv AND pinjam_inv.status= 0 AND pinjam_inv.id_user=' . $user . ' AND inventaris.id_inv=' . $inv->id_inv)->result();
                  if ($cek_user) { ?>
                  <button class="btn btn-info" data-toggle="modal" data-target="#pinjam" disabled="">Menunggu konfirmasi</button>
                  <a href="<?= base_url('peminjam/batalpinjaminv/' . $user . '/' . $inv->id_inv) ?>" class="btn btn-danger" onclick="return confirm('Batalkan peminjaman?')" title="Batalkan peminjaman"><i class="fas fa-times"></i></a>
                  <?php } else { ?>
                      <button class="btn btn-primary" data-id_inv="<?= $inv->id_inv ?>" data-toggle="modal" data-target="#pinjaminv">Pinjam</button>
                    
                  <?php }?>
                </div>
                <!-- /.card-body -->
              </div>
              <!-- modal pinjam ruangan -->

              <!-- /.card -->
            </div>
            <?php endforeach ?>
          <!-- FITUR BOOKING -->
          
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content -->
  </div>
</div>
<!-- ./wrapper -->
<div class="modal fade" id="pinjaminv">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <form role="form" action="<?= base_url('peminjam/pinjam_inv'); ?>" method="POST" enctype="multipart/form-data">
                <div class="modal-header">
                    <h4 class="modal-title">Pinjam Inventaris</h4>
                    <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="card-body">
                        <input type="hidden" id="pinjam_id_user" name="id_user" value="<?php echo $user; ?>">
                        <input type="hidden" id="pinjam_id_inv" name="id_inv" value="<?php echo $inv->id_inv ?>">
                        <div class="form-group">
                            <label>Username</label>
                            <input type="text" id="pinjam_username" name="username" readonly class="form-control" value="<?php if (isset($username)) {echo $username;  } ?>">
                        </div>
                        <div class="form-group">
                            <label>Nama Inventaris</label>
                            <select id="id_inv" name="id_inv" class="form-control">
                                <?php
                                $ruangan2 = $this->db->get('inventaris')->result();
                                foreach ($ruangan2 as $r2) : ?>
                                    <option value="<?php echo $r2->id_inv ?>"><?php echo $r2->nama_inv ?> - <?php echo $r2->jenis ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="">Tanggal Pinjam</label>
                            <input type="date" id="tgl_pinjam" name="tgl_pinjam" class="form-control" value="<?php echo date('Y-m-d', time()); ?>">
                        </div>

                    <!-- /.card-body -->
                </div>
                <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
                    <button type="submit" name="tambah" class="btn btn-primary pinjam">Pinjam</button>
                </div>
            </form>
            
        </div>
        


