<?php
include '../../config/conn.php';
?>
<div class="col" role="main">
    <div class="">
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-10 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title" style="text-transform: capitalize;">
                        <h2>History Aktivitas<small></small></h2>

                        <div class="clearfix"></div>
                    </div>
                    <div class="divider-dashed"></div>
                    
                     <form action="?module=<?php echo "$_GET[module]";?>&periode=y" enctype="multipart/form-data" method="POST">


                <div class="well" style="overflow: auto">

                  <div class="col-md-12 col-sm-12 col-xs-12" style="padding: 4px;">
                    <label for="nama">Pilih Periode :</label>
                  </div>

                  <div class="col-md-6 col-sm-12 col-xs-12" style="padding: 4px;">

                    <div class="input-group">
                      <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                      <input type="text" autocomplete="off" class="form-control " id="tanggal" required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                  echo $tanggal1;
                                                                                                                } else {
                                                                                                                  echo "";
                                                                                                                } ?>" name="tanggal1">
                      <div class="input-group-addon" style="background:white;"><small>Sampai</small></i></div>
                      <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                      <input type="text" autocomplete="off" class="form-control " required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                    echo $tanggal2;
                                                                                                  } else {
                                                                                                    echo "";
                                                                                                  } ?>" id="tanggal2" name="tanggal2">
                    </div>
                  </div>

                  <div class="col-md-6 col-sm-12 col-xs-12" style="padding: 4px;">
                    <button type="submit" class="btn btn-primary btn-sm">Pilih</button>



              </form>


            </div>
                    
                    
                    <div class="x_content">

                        <table id="datatable" class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Waktu</th>
                                    <th>Aksi</th>
                                    <th>ID Transaksi</th>
                                    <th>Jenis Transaksi</th>
                                    <th>ID Data</th>
                                    <th>ID User</th>
                                    <th>Nama User</th>
                                    <th>Alamat MAC</th>
                                    <th>Nama Perangkat</th>

                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $no = 0;
                                
                                
                                  if ($_GET['periode'] == 'y') {
                                        $tanggal1 = $_POST['tanggal1'];
                                        $tanggal2 = $_POST['tanggal2'];
                                        $tgl1 = date('Y-m-d', strtotime($tanggal1));
                                        $tgl2 = date('Y-m-d', strtotime($tanggal2));
                                    $query = mysqli_query($conn, "SELECT * FROM daerah WHERE DATE(waktu) BETWEEN '$tgl1' AND '$tgl2' order by waktu DESC");
                                  } else {
                                $tglskrg= date('Y-m-d');
                                $query = mysqli_query($conn, "SELECT * FROM daerah WHERE DATE(waktu)='$tglskrg' ORDER BY waktu DESC");
                                  }
                                while ($row = mysqli_fetch_array($query)) {
                                    $no++;
                                    $mac_id = mysqli_query($conn, "SELECT * FROM mac_akses WHERE id='$row[id_mac]'");
                                    $id_mac = mysqli_fetch_array($mac_id);
                                ?>
                                    <tr>
                                        <td><?php echo $no; ?></td>
                                        <td><?php echo $row['waktu']; ?></td>

                                        <?php if ($row['aksi'] == "1") {
                                            echo "<td><i class='btn btn-success btn-xs'>Simpan</i></td>";
                                        } elseif ($row['aksi'] == "2") {
                                            echo "<td><i class='btn btn-warning btn-xs'>Edit</i></td>";
                                        } elseif ($row['aksi'] == "3") {
                                            echo "<td><i class='btn btn-danger btn-xs'>Hapus</i></td>";
                                        } ?>
                                        <td><?php echo $row['id_transaksi']; ?></td>
                                        <td><?php
                                            $jentran = mysqli_query($conn, "SELECT * FROM jenis_transaksi WHERE id_jenis='$row[id_jenis]'");
                                            $jt = mysqli_fetch_array($jentran);
                                            echo "$jt[nama_jenis]"; ?></td>

                                        <td><?php echo $row['id_data']; ?></td>
                                        <td><?php echo $row['id_pegawai']; ?></td>
                                        <td><?php
                                            $nama1 = mysqli_query($conn, "SELECT * FROM pegawai WHERE id_pegawai='$row[id_pegawai]'");
                                            $nama = mysqli_fetch_array($nama1);
                                            echo "$nama[nama]"; ?></td>
                                        <td><?php echo $id_mac['mac']; ?></td>
                                        <td><?php echo $id_mac['keterangan']; ?></td>

                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
</div>
</div>
</div><br>