<?php
require_once "labClass.php";
$con = new labClass();
$c=0; 
$users = $con->getAllUsers();
?>
 
<div class="container mt-4">
  <div class="card shadow border-0 rounded-4">
    <div class="card-body">
      <h4 class="text-center mb-3">Registered login secret</h4>
      <table class="table table-striped table-bordered text-center align-middle">
        <thead class="table-dark">
          <tr>
            <th>ID</th>
            <th>Description/ Username</th>
            <th>Password</th>
            <th>Created At</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <?php if ($users): ?>
            <?php foreach ($users as $u):
            $c++;
            ?>
             <tr>
        <td colspan="5"><sub id="rsp<?=$c?>"></sub></td>
        </tr>
            <tr>
            <td width="5%">
             <input name="id<?=$c?>" disabled="true" id="id<?=$c?>" type="text"  
            value="<?= htmlspecialchars($u['id']) ?>" 
            style="width:100%; background:transparent; border:none; outline:none; color:inherit;display:none;" />
            <?= htmlspecialchars($u['id']) ?>
           </td>
                
                <td><?= htmlspecialchars($u['username']) ?></td>
                <td><?= htmlspecialchars($u['password']) ?></td>
                <td><?= htmlspecialchars($u['created_at']) ?> :By:<?= htmlspecialchars($u['postBy']) ?></td>
                <td>
                 <button type="submit" onclick=" 
            const id = $.trim($('#id<?=$c?>').val()); 
            if (id!='') {
              $.post('secretDelPro.php', {delete:1,id:id }, function(response) {
                $('#rsp<?=$c?>').html(response);
              });
            }
          " class="btn btn-danger">DELETE</button></td>
              </tr>
            <?php endforeach; ?>
          <?php else: ?>
            <tr><td colspan="5">No users found</td></tr>
          <?php endif; ?>
        </tbody>
      </table>
       
    </div>
  </div>
</div>

 