PHP WebShell
Текущая директория: /var/www/bitcardoApp/user/data
Просмотр файла: rates.php
<?php
include '../common/header.php';
// Fetch Card Brands
$brands = [];
$res = $conn->query("SELECT * FROM card_brands WHERE status=1");
while ($row = $res->fetch_assoc()) {
$brands[$row['cbrand_id']] = $row;
}
// Fetch Gift Cards (Buy rates only, status=1)
$giftCards = [];
$sql = "SELECT g.*, b.card_brand, b.brand_icon
FROM gift_cards g
JOIN card_brands b ON g.cbrand_id = b.cbrand_id
WHERE g.status=1";
$res = $conn->query($sql);
while ($row = $res->fetch_assoc()) {
$row['type'] = 'Card';
$row['icon'] = $row['brand_icon'];
$row['code'] = trim($row['card_brand'] . ' ' . $row['demon']);
$row['badge'] = '<span class=\"badge bg-warning text-dark\">10 min</span>';
$row['trade_url'] = 'sell_card.php?id=' . $row['gc_id'];
$row['rate'] = $row['buy_price'];
$row['rate_currency'] = $row['card_curr'] ?? 'USD';
$row['rate_str'] = '₦' . number_format($row['buy_price'], 2) . '/' . htmlspecialchars($row['rate_currency']);
$giftCards[] = $row;
}
// Fetch Crypto Coins (Hide NGN, use NGN rate for TUSDT)
$coins = [];
$tusdt = null;
$otherCoins = [];
$ngn_rate = null;
$sql = "SELECT * FROM coin_rates";
$res = $conn->query($sql);
while ($row = $res->fetch_assoc()) {
if (strtoupper($row['coin']) === 'NGN') {
$ngn_rate = $row;
continue; // Skip NGN display
}
$row['type'] = 'Crypto';
$row['icon'] = $row['coin_icon'] ?? strtolower($row['coin']) . '.png';
$row['code'] = strtoupper($row['coin']);
$row['badge'] = '<span class=\"badge bg-success\">Instant</span>';
$row['trade_url'] = '../crypto/swap_crypto.php?coin=' . urlencode($row['coin']);
if (strtoupper($row['coin']) === 'TUSDT') {
// Placeholder, actual rate will be filled after the loop using NGN
$tusdt = $row;
} else {
$row['rate_str'] = 'Buy: $' . number_format($row['buy_rate'], 2) . '/' . htmlspecialchars($row['coin']) .
'<br>Sell: $' . number_format($row['sell_rate'], 2) . '/' . htmlspecialchars($row['coin']);
$row['display_code'] = ($row['coin_name'] ? trim($row['coin_name']) . ' (' . strtoupper($row['coin']) . ')' : strtoupper($row['coin']));
$otherCoins[] = $row;
}
}
// Now update TUSDT card to use NGN rates
if ($tusdt && $ngn_rate) {
$tusdt['rate_str'] = 'Buy: ₦' . number_format($ngn_rate['buy_rate'], 2) . '/TUSDT<br>Sell: ₦' . number_format($ngn_rate['sell_rate'], 2) . '/TUSDT';
$tusdt['display_code'] = 'Tether (TUSDT)';
}
// Sort otherCoins by asset name (display_code)
usort($otherCoins, function($a, $b) {
return strcasecmp($a['display_code'], $b['display_code']);
});
// Merge all assets: Cards, TUSDT (with NGN rate), then other crypto
$currencies = [];
foreach ($giftCards as $g) {
$currencies[] = [
'code' => $g['code'],
'icon' => $g['icon'],
'rate' => $g['rate'],
'type' => $g['type'],
'badge' => $g['badge'],
'trade_url' => $g['trade_url'],
'rate_str' => $g['rate_str'],
'search_type' => 'Card'
];
}
if ($tusdt && $ngn_rate) {
$currencies[] = [
'code' => $tusdt['display_code'],
'icon' => $tusdt['icon'],
'rate' => $ngn_rate['sell_rate'],
'type' => $tusdt['type'],
'badge' => $tusdt['badge'],
'trade_url' => $tusdt['trade_url'],
'rate_str' => $tusdt['rate_str'],
'search_type' => 'Crypto'
];
}
foreach ($otherCoins as $c) {
$currencies[] = [
'code' => $c['display_code'],
'icon' => $c['icon'],
'rate' => $c['sell_rate'],
'type' => $c['type'],
'badge' => $c['badge'],
'trade_url' => $c['trade_url'],
'rate_str' => $c['rate_str'],
'search_type' => 'Crypto'
];
}
?>
<!-- Main Container -->
<div class="container mt-3">
<div class="row">
<? include '../common/nav.php'; ?>
<main class="col-md-9 col-lg-10 px-md-5 mb-5">
<? include '../common/page-header.php'; ?>
<div class="container my-4 px-md-5">
<div class="d-flex justify-content-center align-items-center mb-3">
<h4 class="mb-0 text-center">Currency Rates</h4>
</div>
<div class="row">
<div class="col-8 offset-md-4 col-md-3">
<input type="text" id="currencySearch" class="form-control mb-4" placeholder="Search currency (e.g., USD)">
</div>
<div class="col-4 col-md-3">
<select id="typeFilter" class="form-select w-auto">
<option value="all">All Types</option>
<option value="Card">Card</option>
<option value="Crypto">Crypto</option>
</select>
</div>
</div>
<div class="row" id="currencyList"></div>
<div class="text-center mt-3">
<center>
<button id="showMoreBtn" class="btn btn-outline-secondary">Show more</button>
</center>
</div>
</div>
</main>
</div>
</div>
<script>
const currencies = <?= json_encode($currencies) ?>;
const listContainer = document.getElementById('currencyList');
const showMoreBtn = document.getElementById('showMoreBtn');
const searchInput = document.getElementById('currencySearch');
const typeFilter = document.getElementById('typeFilter');
let visibleCount = 0;
function renderCards(reset = false) {
if (reset) {
listContainer.innerHTML = '';
visibleCount = 0;
}
const searchQuery = searchInput.value.toLowerCase();
const typeQuery = typeFilter.value;
const filtered = currencies.filter(item =>
item.code.toLowerCase().includes(searchQuery)
&& (typeQuery === 'all' || item.search_type === typeQuery)
);
const itemsToShow = filtered.slice(0, visibleCount + 6);
listContainer.innerHTML = '';
itemsToShow.forEach(item => {
const card = document.createElement('div');
card.className = 'currency-col p-2 d-flex currency-card visible';
card.innerHTML = `
<a href="${item.trade_url}" class="card shadow-sm w-100 text-decoration-none text-dark">
<div class="card-body d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
<img src="../../assets/icons/${item.icon}" width="32" class="me-3" style="object-fit:contain;max-height:32px;">
<div>
<strong>${item.code}</strong>
<div class="d-flex align-items-center gap-1 mt-1">
<small class="text-muted">${item.type}</small>
${item.badge}
</div>
</div>
</div>
<div class="text-end">
<div class="fw-semibold small mt-1">${item.rate_str}</div>
</div>
</div>
</a>
`;
listContainer.appendChild(card);
});
visibleCount = itemsToShow.length;
showMoreBtn.style.display = visibleCount < filtered.length ? 'block' : 'none';
}
showMoreBtn.addEventListener('click', () => renderCards());
searchInput.addEventListener('input', () => renderCards(true));
typeFilter.addEventListener('change', () => renderCards(true));
renderCards();
</script>
<? include '../common/footer.php'; ?>
Выполнить команду
Для локальной разработки. Не используйте в интернете!