126 lines
6.1 KiB
PHP
126 lines
6.1 KiB
PHP
<?php
|
|
// user_ads.php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Hardcoded user ID for demonstration
|
|
$current_user_id = 1;
|
|
|
|
$ads = [];
|
|
$error = '';
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Fetch active ads, joining with users table to get seller's nickname and rating
|
|
$stmt = $pdo->query(
|
|
"SELECT
|
|
a.id, a.ad_type, a.currency, a.payment_currency, a.fixed_price,
|
|
a.available_amount, a.min_amount, a.max_amount, a.bank_name,
|
|
u.nickname AS seller_nickname, u.rating AS seller_rating
|
|
FROM ads a
|
|
JOIN users u ON a.user_id = u.id
|
|
WHERE a.status = 'ACTIVE' AND a.user_id != {$current_user_id}
|
|
ORDER BY a.created_at DESC"
|
|
);
|
|
$ads = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$error = "Database error: " . $e->getMessage();
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Browse Ads</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">P2P Platform</a>
|
|
<div class="collapse navbar-collapse">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="create_ad.php"><i class="bi bi-plus-circle"></i> Create Ad</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="logout.php"><i class="bi bi-box-arrow-right"></i> Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1>Browse Ads</h1>
|
|
<div>
|
|
<!-- Filter/Search form can go here in the future -->
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (empty($ads)): ?>
|
|
<div class="alert alert-info text-center">
|
|
<p class="h4">No active ads found.</p>
|
|
<p>Be the first to <a href="create_ad.php">create one</a>!</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="row row-cols-1 g-4">
|
|
<?php foreach ($ads as $ad): ?>
|
|
<div class="col">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between">
|
|
<div>
|
|
<h5 class="card-title mb-1">
|
|
<i class="bi bi-person-circle"></i> <?php echo htmlspecialchars($ad['seller_nickname']); ?>
|
|
<span class="badge bg-success"><i class="bi bi-star-fill"></i> <?php echo number_format($ad['seller_rating'], 1); ?></span>
|
|
</h5>
|
|
<p class="card-text text-muted small">Seller</p>
|
|
</div>
|
|
<div class="text-end">
|
|
<a href="initiate_deal.php?ad_id=<?php echo $ad['id']; ?>" class="btn btn-<?php echo $ad['ad_type'] === 'SELL' ? 'primary' : 'warning'; ?>">
|
|
<?php echo $ad['ad_type'] === 'SELL' ? 'Buy' : 'Sell'; ?> <?php echo htmlspecialchars($ad['currency']); ?>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<hr>
|
|
<div class="row">
|
|
<div class="col-6 col-md-3">
|
|
<span class="text-muted d-block">Price</span>
|
|
<strong><?php echo number_format($ad['fixed_price'], 2); ?> <?php echo htmlspecialchars($ad['payment_currency']); ?></strong>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<span class="text-muted d-block">Available</span>
|
|
<strong><?php echo rtrim(rtrim(number_format($ad['available_amount'], 8), '0'), '.'); ?> <?php echo htmlspecialchars($ad['currency']); ?></strong>
|
|
</div>
|
|
<div class="col-6 col-md-3 mt-3 mt-md-0">
|
|
<span class="text-muted d-block">Limits</span>
|
|
<strong><?php echo rtrim(rtrim(number_format($ad['min_amount'], 2), '0'), '.'); ?> - <?php echo rtrim(rtrim(number_format($ad['max_amount'], 2), '0'), '.'); ?> <?php echo htmlspecialchars($ad['payment_currency']); ?></strong>
|
|
</div>
|
|
<div class="col-6 col-md-3 mt-3 mt-md-0">
|
|
<span class="text-muted d-block">Payment</span>
|
|
<strong><?php echo htmlspecialchars($ad['bank_name']); ?></strong>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<footer class="text-center mt-5 mb-3">
|
|
<p class="text-muted">© <?php echo date("Y"); ?> P2P Platform</p>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|