File: //home/awaldron/_accomods/admin.accomods.com/users.php
<?php
include '_helpers.php';
$accessSet = 0;
if (isset($_GET['access'])) {
$accessSet = set_user_access( $_GET['access'], $_GET['uid'] );
}
// GET THE USERS
$db = connectDB();
$sql = "SELECT id, email, fname, lname, phone, school_code, school_name, expires, access, date_registered FROM users ORDER BY access DESC, lname ASC, fname ASC";
$result = $db->query($sql);
include '_header.php';
?>
<style>
.btn { font-size: 12px; padding: 2px 8px; }
table { margin-bottom: 100px; }
tr.striked td { color: #777; text-decoration: line-through; }
td.expired { color: #CC0000; font-weight: bold; }
</style>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1>Manage Users</h1>
<p><a href="/">Back to Admin Panel</a></p>
<hr/>
<p><a href="/users_edit.php?uid=new" class="btn btn-success btn-lg">Create New User</a></p>
<?php
if ($accessSet === 1) { echo '<div class="alert alert-success"><b>User '.($_GET['access']==0 ? 'Disabled' : 'Enabled').' Successfully</b></div>'; }
if ($accessSet === -1) { echo '<div class="alert alert-danger"><b>User Update Failed - Please Try Again</b></div>'; }
?>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">Filter Table:</span>
<input type="text" class="form-control" id="tbl-filter">
</div>
<table class="table table-striped table-hover" style="font-size:14px;">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Contact</th>
<th scope="col">School</th>
<th scope="col">License</th>
<th scope="col">Expires</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody id='tbl-body'>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$expires = str_replace('-', '', $row['expires']);
$today = date('Ymd');
$expired = $today > $expires;
$find = [' ', '@', '.'];
$repl = ['', '', ''];
$id = str_replace($find, $repl, strtolower($row['lname'].$row['fname'].$row['email'].$row['school_name'].$row['school_code']));
echo '<tr class="'.($row['access']==0 ? 'striked' : '').'" rel="'.$id.'">';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['lname'].', '.$row['fname'].'</td>';
echo '<td>
<a href="mailto:'.$row['email'].'">'.$row['email'].'</a>
<br/><a href="tel:'.$row['phone'].'">'.$row['phone'].'</a>
</td>';
echo '<td>'.$row['school_name'].'</td>';
echo '<td>'.$row['school_code'].'</td>';
echo '<td nowrap="nowrap" class="'.($expired ? 'expired' : '').'">'.$row['expires'].'</td>';
echo '<td nowrap="nowrap">';
echo '<a href="/users_edit.php?uid='.$row['id'].'" class="btn btn-success btn-sm">Edit</a> ';
if ($row['access']==1) echo '<a href="/users.php?access=0&uid='.$row['id'].'" class="btn btn-danger btn-sm">Disable</a>';
if ($row['access']==0) echo '<a href="/users.php?access=1&uid='.$row['id'].'" class="btn btn-primary btn-sm">Re-Enable</a>';
echo '</td>';
echo '</tr>';
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#tbl-filter").keyup(function(){
var query = $(this).val().toLowerCase().replace(/ /g,'');
console.log('query', query);
if (query.length >= 3) {
$("#tbl-body tr").hide();
$("#tbl-body tr[rel*='"+query+"']").show();
} else {
$("#tbl-body > tr").show();
}
});
});
</script>
<?php
$db->close();
include '_footer.php';
?>