<?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 Login<small></small></h2>

                        <div class="clearfix"></div>
                    </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="divider-dashed"></div>
                    <div class="x_content">

                        <table id="datatable" class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Waktu</th>
                                    <th>ID User</th>
                                    <th>Nama</th>
                                    <th>Alamat MAC</th>
                                    <th>Keterangan</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 log WHERE DATE(waktu) BETWEEN '$tgl1' AND '$tgl2' order by waktu DESC");
                                  } else {
                                    $tglskrg= date('Y-m-d');
                                    $query = mysqli_query($conn, "SELECT * FROM log 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[mac]'");
                                    $id_mac = mysqli_fetch_array($mac_id);
                                ?>
                                    <tr>
                                        <td><?php echo $no; ?></td>
                                        <td><?php echo $row['waktu']; ?></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>

<!-- Modal -->
<div class="modal fade" id="modalAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Tambah MAC perangkat</h4>
            </div>
            <div class="modal-body">
                <!-- start form for validation -->
                <form action="?module=<?php echo $_GET['module']; ?>&aksi=simpan" enctype="multipart/form-data" method="POST">



                    <label for="nama">Alamat MAC * gunakan pemisah "-":</label>
                    <input type="text" class="form-control" name="mac" autocomplete="off" required />
                    <br>
                    <label for="nama">Keterangan:</label>
                    <input type="text" class="form-control" name="keterangan" autocomplete="off" required />


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
                <button type="submit" class="btn btn-success btn-sm">Simpan</button>
            </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_delete">
    <div class="modal-dialog">
        <div class="modal-content" style="margin-top:100px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" style="text-align:center;">Apakah anda yakin menghapus data ini ?</h4>
            </div>
            <div class="modal-footer" style="margin:0px; border-top:0px; text-align:center;">
                <a href="#" class="btn btn-danger btn-sm" id="delete_link">Hapus</a>
                <button type="button" class="btn btn-success btn-sm" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>