<?php

function aa_h($v)
{
    return htmlspecialchars(
        (string)$v,
        ENT_QUOTES,
        'UTF-8'
    );
}

?>

<div class="container-fluid py-4">

<div class="card shadow-sm border-0 mb-4"
style="border-radius:24px;">

<div class="card-body">

<h3 class="fw-bold mb-3">

<i class="fa fa-shield-halved text-primary"></i>

Access Audit Enterprise

</h3>

<form
method="get"
class="row g-3">

<div class="col-md-3">

<input
type="text"
name="q"
value="<?= aa_h($search ?? '') ?>"
class="form-control"
placeholder="Search menu/url/module">

</div>

<div class="col-md-3">

<select
name="role"
class="form-select">

<option value="">
All Roles
</option>

<?php foreach($roles as $r): ?>

<option
value="<?= aa_h($r['code']) ?>"
<?= ($roleFilter ?? '')===$r['code']
? 'selected'
: '' ?>>

<?= aa_h($r['code']) ?>

</option>

<?php endforeach; ?>

</select>

</div>

<div class="col-md-2">

<select
name="per_page"
class="form-select">

<?php foreach([25,50,100,250] as $pp): ?>

<option
value="<?= $pp ?>"
<?= ($perPage ?? 50)==$pp
? 'selected'
: '' ?>>

<?= $pp ?>

</option>

<?php endforeach; ?>

</select>

</div>

<div class="col-md-4">

<button
class="btn btn-primary">

<i class="fa fa-filter"></i>

Filter

</button>

<a
href="/easychair/admin/access-audit"
class="btn btn-outline-secondary">

Reset

</a>

</div>

</form>

</div>

</div>

<div class="card shadow-sm border-0">

<div class="card-body p-0">

<div class="table-responsive">

<table
class="table table-hover align-middle mb-0">

<thead class="table-dark">

<tr>

<th>Role</th>
<th>Menu</th>
<th>URL</th>
<th>View</th>
<th>Create</th>
<th>Update</th>
<th>Delete</th>

</tr>

</thead>

<tbody>

<?php foreach($rows as $r): ?>

<tr>

<td>
<?= aa_h($r['role_code']) ?>
</td>

<td>
<?= aa_h($r['label']) ?>
</td>

<td>
<code>
<?= aa_h($r['url']) ?>
</code>
</td>

<td>
<?= !empty($r['can_view'])
? '<span class="badge bg-success">YES</span>'
: '<span class="badge bg-secondary">NO</span>' ?>
</td>

<td>
<?= !empty($r['can_create'])
? '<span class="badge bg-info">YES</span>'
: '<span class="badge bg-secondary">NO</span>' ?>
</td>

<td>
<?= !empty($r['can_update'])
? '<span class="badge bg-warning">YES</span>'
: '<span class="badge bg-secondary">NO</span>' ?>
</td>

<td>
<?= !empty($r['can_delete'])
? '<span class="badge bg-danger">YES</span>'
: '<span class="badge bg-secondary">NO</span>' ?>
</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

</div>

<div class="d-flex justify-content-between align-items-center mt-4">

<div>

Rows:
<?= number_format($totalRows ?? 0) ?>

</div>

<div>

<?php if(($page ?? 1)>1): ?>

<a
class="btn btn-sm btn-outline-primary"
href="?<?= http_build_query(array_merge($_GET,['page'=>$page-1])) ?>">

Prev

</a>

<?php endif; ?>

<span class="mx-2">

Page
<?= (int)$page ?>
/
<?= (int)$totalPages ?>

</span>

<?php if(($page ?? 1)<($totalPages ?? 1)): ?>

<a
class="btn btn-sm btn-outline-primary"
href="?<?= http_build_query(array_merge($_GET,['page'=>$page+1])) ?>">

Next

</a>

<?php endif; ?>

</div>

</div>

</div>
