192 lines
8.1 KiB
PHP
192 lines
8.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Pagination
|
|
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
|
$limit = 20;
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
// Search
|
|
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
|
|
|
|
$users = [];
|
|
$total_users = 0;
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Build query
|
|
$sql = "SELECT * FROM users";
|
|
$count_sql = "SELECT COUNT(*) FROM users";
|
|
$params = [];
|
|
|
|
if (!empty($search)) {
|
|
$sql .= " WHERE nickname LIKE :search OR telegram_id LIKE :search";
|
|
$count_sql .= " WHERE nickname LIKE :search OR telegram_id LIKE :search";
|
|
$params[':search'] = '%' . $search . '%';
|
|
}
|
|
|
|
// Get total count for pagination
|
|
$stmt = $pdo->prepare($count_sql);
|
|
$stmt->execute($params);
|
|
$total_users = $stmt->fetchColumn();
|
|
$total_pages = ceil($total_users / $limit);
|
|
|
|
// Get users for the current page
|
|
$sql .= " ORDER BY created_at DESC LIMIT :limit OFFSET :offset";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
|
|
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
|
if (!empty($search)) {
|
|
$stmt->bindValue(':search', '%' . $search . '%');
|
|
}
|
|
$stmt->execute();
|
|
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (Exception $e) {
|
|
error_log($e->getMessage());
|
|
// Handle error, maybe show a message
|
|
}
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>awallwt - Users Management</title>
|
|
<meta name="robots" content="noindex, nofollow">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
|
|
<div class="sidebar-sticky pt-3">
|
|
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
|
|
<span>Admin Menu</span>
|
|
</h6>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="admin.php">
|
|
<span data-feather="home"></span>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="users.php">
|
|
<span data-feather="users"></span>
|
|
Users
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="ads.php">
|
|
<span data-feather="file-text"></span>
|
|
Ads
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="deals.php">
|
|
<span data-feather="repeat"></span>
|
|
Deals
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="disputes.php">
|
|
<span data-feather="alert-octagon"></span>
|
|
Disputes
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="settings.php">
|
|
<span data-feather="settings"></span>
|
|
Settings
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="main-content col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
|
<h1 class="h2">Users</h1>
|
|
<div class="btn-toolbar mb-2 mb-md-0">
|
|
<form method="GET" action="users.php" class="d-flex">
|
|
<input class="form-control me-2" type="search" name="search" placeholder="Search by Nickname or ID" value="<?php echo htmlspecialchars($search); ?>" aria-label="Search">
|
|
<button class="btn btn-outline-success" type="submit">Search</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">All Users (<?php echo $total_users; ?>)</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Nickname</th>
|
|
<th>Telegram ID</th>
|
|
<th>Rating</th>
|
|
<th>Verified</th>
|
|
<th>Role</th>
|
|
<th>Registered At</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($users)): ?>
|
|
<tr>
|
|
<td colspan="8" class="text-center">No users found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($users as $user): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['nickname']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['telegram_id']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['rating']); ?></td>
|
|
<td>
|
|
<span class="badge <?php echo $user['is_verified'] ? 'bg-success' : 'bg-secondary'; ?>">
|
|
<?php echo $user['is_verified'] ? 'Yes' : 'No'; ?>
|
|
</span>
|
|
</td>
|
|
<td><span class="badge bg-info"><?php echo htmlspecialchars(ucfirst($user['role'])); ?></span></td>
|
|
<td><?php echo htmlspecialchars($user['created_at']); ?></td>
|
|
<td>
|
|
<a href="#" class="btn btn-sm btn-primary">View</a>
|
|
<a href="#" class="btn btn-sm btn-danger">Block</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php if ($total_pages > 1): ?>
|
|
<div class="card-footer">
|
|
<nav aria-label="Page navigation">
|
|
<ul class="pagination justify-content-center mb-0">
|
|
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
|
<li class="page-item <?php echo $i == $page ? 'active' : ''; ?>">
|
|
<a class="page-link" href="?page=<?php echo $i; ?>&search=<?php echo urlencode($search); ?>"><?php echo $i; ?></a>
|
|
</li>
|
|
<?php endfor; ?>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|