<?php
session_start();
error_reporting(0);
if (!isset($_SESSION["mikhmon"])) {
  header("Location:../admin.php?id=login");
} else {
  $session = $_GET['session'];
  include('../include/config.php');
  include('../include/readcfg.php');
  include('../include/lang.php');
  include('../lang/'.$langid.'.php');
  include_once('../lib/routeros_api.class.php');
  include_once('../lib/formatbytesbites.php');
  $API = new RouterosAPI();
  $API->debug = false;
  $API->connect($iphost, $userhost, decrypt($passwdhost));
  $getuser = $API->comm("/ip/hotspot/user/print");
  $TotalReg = count($getuser);
}
?>
<div class="row">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h3><i class="fa fa-address-book"></i> Kosongkan MAC Address</h3>
      </div>
      <div class="card-body">
        <div class="row">
          <div class="col-6 pd-t-5 pd-b-5">
            <div class="input-group">
              <div class="input-group-4 col-box-6">
                <input id="filterClearMac" type="text" style="padding:5.8px;" class="group-item group-item-l" placeholder="Cari user">
              </div>
            </div>
          </div>
        </div>
        <div class="overflow mr-t-10 box-bordered" style="max-height: 75vh">
          <table id="clearMacTable" class="table table-bordered table-hover text-nowrap">
            <thead>
              <tr>
                <th class="align-middle text-center">Aksi</th>
                <th>Nama</th>
                <th>Profile</th>
                <th>Mac Address</th>
              </tr>
            </thead>
            <tbody>
              <?php
              for ($i = 0; $i < $TotalReg; $i++) {
                $u = $getuser[$i];
                $uid = $u['.id'];
                $uname = $u['name'];
                $uprofile = $u['profile'];
                $umac = $u['mac-address'];
                echo "<tr>";
                echo "<td class='text-center'><button class='btn bg-red' onclick=\"if(confirm('Kosongkan MAC untuk $uname?')){loadpage('./?clear-mac-user=$uid&session=$session');}\" ".($umac==''?'disabled':'')."><i class='fa fa-eraser'></i> Kosongkan</button></td>";
                echo "<td>$uname</td>";
                echo "<td>$uprofile</td>";
                echo "<td>$umac</td>";
                echo "</tr>";
              }
              ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  (function(){
    var input = document.getElementById('filterClearMac');
    input.addEventListener('keyup', function(){
      var q = this.value.toLowerCase();
      var rows = document.querySelectorAll('#clearMacTable tbody tr');
      for (var i=0;i<rows.length;i++){
        var t = rows[i].innerText.toLowerCase();
        rows[i].style.display = t.indexOf(q) > -1 ? '' : 'none';
      }
    });
  })();
</script>
