<?php session_start();?>
<?php include'../includes/db.php';?>
<?php include'../includes/functions.php';?>

<?php
$sn = 0;
$fetch = "SELECT * FROM users  
          ORDER BY userId DESC ";
$stmt = $pdo->prepare($fetch);
$stmt->execute([]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $sn++;
    $userId     = $row['userId'];
    $userName   = $row['name'];
    $mobile     = $row['phone_number'];
    $roles      = $row['roles'];
    $email      = $row['email_address'];
    $password   = $row['password'];

    ?>
    <tr>
        <td>
            <input type="checkbox" name="checkBoxArray[]" value="<?= $userId ?>" class='checkBoxes'>
        </td>
        <td><?= $sn ?></td>
        <td><?= $userName; ?></td>
        <td><?= $mobile; ?></td>
        <td><?= $email; ?></td>
        <td><?= $roles; ?></td>
        <td>
            <button type="button" class="btn btn-primary" onclick="openModal('modal-<?= $userId ?>')">
                Edit <i class="fa fa-edit"></i>
            </button>
            
        </td>
    </tr>

    <!-- Edit Modal -->
    <?php EditUsers();?>
<!-- End while loop -->

<?php }?>
<?php UpdateUser();?>