189 lines
8.2 KiB
PHP
189 lines
8.2 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']) : '';
|
|
|
|
$ads = [];
|
|
$total_ads = 0;
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Build query
|
|
$sql = "SELECT a.*, u.nickname FROM ads a JOIN users u ON a.user_id = u.id";
|
|
$count_sql = "SELECT COUNT(*) FROM ads a JOIN users u ON a.user_id = u.id";
|
|
$params = [];
|
|
|
|
if (!empty($search)) {
|
|
$sql .= " WHERE u.nickname LIKE :search OR a.currency LIKE :search OR a.ad_type LIKE :search";
|
|
$count_sql .= " WHERE u.nickname LIKE :search OR a.currency LIKE :search OR a.ad_type LIKE :search";
|
|
$params[':search'] = '%' . $search . '%';
|
|
}
|
|
|
|
// Get total count for pagination
|
|
$stmt = $pdo->prepare($count_sql);
|
|
$stmt->execute($params);
|
|
$total_ads = $stmt->fetchColumn();
|
|
$total_pages = ceil($total_ads / $limit);
|
|
|
|
// Get ads for the current page
|
|
$sql .= " ORDER BY a.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();
|
|
$ads = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (Exception $e) {
|
|
error_log($e->getMessage());
|
|
}
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>awallwt - Ads 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" href="users.php">
|
|
<span data-feather="users"></span>
|
|
Users
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" 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">Ads</h1>
|
|
<div class="btn-toolbar mb-2 mb-md-0">
|
|
<form method="GET" action="ads.php" class="d-flex">
|
|
<input class="form-control me-2" type="search" name="search" placeholder="Seller, Currency, Type..." 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 Ads (<?php echo $total_ads; ?>)</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Seller</th>
|
|
<th>Type</th>
|
|
<th>Currency</th>
|
|
<th>Price</th>
|
|
<th>Available</th>
|
|
<th>Status</th>
|
|
<th>Created At</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($ads)): ?>
|
|
<tr>
|
|
<td colspan="9" class="text-center">No ads found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($ads as $ad): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($ad['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($ad['nickname']); ?></td>
|
|
<td><span class="badge <?php echo $ad['ad_type'] == 'SELL' ? 'bg-danger' : 'bg-success'; ?>"><?php echo htmlspecialchars($ad['ad_type']); ?></span></td>
|
|
<td><?php echo htmlspecialchars($ad['currency']); ?></td>
|
|
<td><?php echo htmlspecialchars($ad['fixed_price'] ?? 'N/A'); ?> <?php echo htmlspecialchars($ad['payment_currency']); ?></td>
|
|
<td><?php echo htmlspecialchars($ad['available_amount']); ?></td>
|
|
<td><span class="badge bg-light text-dark"><?php echo htmlspecialchars($ad['status']); ?></span></td>
|
|
<td><?php echo htmlspecialchars($ad['created_at']); ?></td>
|
|
<td>
|
|
<a href="#" class="btn btn-sm btn-primary">View</a>
|
|
<a href="#" class="btn btn-sm btn-warning">Pause</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>
|