PHP WebShell
Текущая директория: /var/www/bitcardoApp/backyard/user/wallets
Просмотр файла: wallets.php
<?
include '../common/header.php';
?>
<style>
.form-switch .form-check-input {
width: 2.5em;
height: 1.2em;
}
/* Green switch for active status */
.form-check-input.wallet-toggle:checked {
background-color: #198754 !important; /* Bootstrap's .bg-success */
border-color: #198754 !important;
}
</style>
<div class="nk-content nk-content-fluid">
<div class="container-xl wide-lg">
<div class="nk-content-body">
<div class="nk-block-head mt-5">
<div class="nk-block-between-md g-4">
<div class="nk-block-head-content">
<h5 class="nk-block-title fw-normal">Users Wallets</h5>
<div class="nk-block-des">
<p>List of users wallets!</p>
</div>
</div>
<div class="nk-block-head-content">
<ul class="nk-block-tools gx-3">
<li>
<a href="#" class="btn btn-primary"><span>Add New User Wallet</span></a>
</li>
</ul>
</div>
</div>
</div>
<div class="nk-block-body">
<?php
// Filters
$where = "WHERE 1=1";
$params = [];
$types = "";
// Email filter
if (!empty($_GET['email'])) {
$where .= " AND u.email LIKE ?";
$params[] = '%' . $_GET['email'] . '%';
$types .= "s";
}
// Coin filter
if (!empty($_GET['coin'])) {
$where .= " AND uw.coin = ?";
$params[] = $_GET['coin'];
$types .= "s";
}
// Wallet status filter
if (!empty($_GET['status'])) {
$where .= " AND uw.wallet_status = ?";
$params[] = $_GET['status'];
$types .= "s";
}
// Wallet address filter
if (!empty($_GET['wallet_add'])) {
$where .= " AND uw.wallet_add LIKE ?";
$params[] = '%' . trim($_GET['wallet_add']) . '%';
$types .= "s";
}
// Get total count (NO LIMIT/OFFSET here)
$countSql = "SELECT COUNT(*) as total
FROM user_wallets uw
JOIN users u ON uw.user_id = u.user_id
$where";
$countStmt = $conn->prepare($countSql);
if (!empty($params)) {
$countStmt->bind_param($types, ...$params);
}
$countStmt->execute();
$countResult = $countStmt->get_result();
$row = $countResult->fetch_assoc();
$total = $row['total'] ?? 0;
$countStmt->close();
// Pagination
$limit = 50;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$offset = ($page - 1) * $limit;
// Add limit/offset to params
$sqlParams = $params; // Copy filtered params
$sqlTypes = $types;
$sqlParams[] = $limit;
$sqlParams[] = $offset;
$sqlTypes .= "ii";
// Final SELECT query
$sql = "SELECT uw.wallet_id, uw.user_id, u.email, uw.wallet_add, uw.bank_name, uw.coin, uw.balance, uw.wallet_status
FROM user_wallets uw
JOIN users u ON uw.user_id = u.user_id
$where
ORDER BY uw.wallet_id DESC
LIMIT ? OFFSET ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param($sqlTypes, ...$sqlParams);
$stmt->execute();
$result = $stmt->get_result();
$wallets = [];
while ($row = $result->fetch_assoc()) {
$wallets[] = $row;
}
$stmt->close();
?>
<form method="get" class="row g-2 mb-3">
<div class="col-md-2">
<input type="text" name="email" class="form-control" placeholder="User Email" value="<?= htmlspecialchars($_GET['email'] ?? '') ?>">
</div>
<div class="col-md-2">
<input type="text" name="wallet_add" class="form-control" placeholder="Wallet Address" value="<?= htmlspecialchars($_GET['wallet_add'] ?? '') ?>">
</div>
<div class="col-md-2">
<select name="coin" class="form-select">
<option value="">All Coins</option>
<option value="btc" <?= ($_GET['coin'] ?? '') === 'btc' ? 'selected' : '' ?>>BTC</option>
<option value="eth" <?= ($_GET['coin'] ?? '') === 'eth' ? 'selected' : '' ?>>ETH</option>
<option value="ltc" <?= ($_GET['coin'] ?? '') === 'ltc' ? 'selected' : '' ?>>LTC</option>
<option value="usdt" <?= ($_GET['coin'] ?? '') === 'usdt' ? 'selected' : '' ?>>USDT</option>
<option value="sol" <?= ($_GET['coin'] ?? '') === 'sol' ? 'selected' : '' ?>>SOL</option>
<option value="ngn" <?= ($_GET['coin'] ?? '') === 'ngn' ? 'selected' : '' ?>>NGN</option>
</select>
</div>
<div class="col-md-2">
<select name="status" class="form-select">
<option value="">All Statuses</option>
<option value="active" <?= ($_GET['status'] ?? '') === 'active' ? 'selected' : '' ?>>Active</option>
<option value="inactive" <?= ($_GET['status'] ?? '') === 'inactive' ? 'selected' : '' ?>>Inactive</option>
</select>
</div>
<div class="col-md-4 d-flex justify-content-start">
<button class="btn btn-success me-2" type="submit">Filter</button>
<a href="wallets.php" class="btn btn-outline-secondary">Reset</a>
</div>
</form>
<!-- USERS WALLET TABLE -->
<table class="table table-striped table-responsive">
<thead>
<tr>
<th><input type="checkbox" id="selectAll"></th>
<th>S/N</th>
<th>User Email</th>
<th>Wallet Address</th>
<th>Bank</th>
<th>coin</th>
<th>Balance</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php $sn = 1; foreach ($wallets as $wallet): ?>
<tr>
<td><input type="checkbox" name="selected_wallets[]" value="<?= $wallet['wallet_id'] ?>"></td>
<td><?= $sn++ ?></td>
<td><?= htmlspecialchars($wallet['email']) ?></td>
<td><?= htmlspecialchars($wallet['wallet_add']) ?></td>
<td><?= htmlspecialchars($wallet['bank_name']) ?></td>
<td><?= strtoupper($wallet['coin']) ?></td>
<td><?= number_format($wallet['balance'], 2) ?></td>
<td class="text-center">
<?php if ($wallet['wallet_status'] === 'active'): ?>
<span class="badge bg-success">Active</span>
<?php else: ?>
<span class="badge bg-danger">Inactive</span>
<?php endif; ?>
</td>
<td class="text-center">
<div class="form-check form-switch">
<input class="form-check-input wallet-toggle"
type="checkbox"
data-id="<?= $wallet['wallet_id'] ?>"
data-email="<?= $wallet['email'] ?>"
<?= ($wallet['wallet_status'] === 'active') ? 'checked' : '' ?>>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
$totalPages = max(1, ceil($total / $limit));
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$currentPage = max(1, min($currentPage, $totalPages));
echo '<nav><ul class="pagination justify-content-center">';
// Preserve filters
$query = $_GET;
// First & Prev
if ($currentPage > 1) {
$query['page'] = 1;
echo "<li class='page-item'><a class='page-link' href='?" . http_build_query($query) . "'>First</a></li>";
$query['page'] = $currentPage - 1;
echo "<li class='page-item'><a class='page-link' href='?" . http_build_query($query) . "'>Prev</a></li>";
}
// Determine range for middle pages
$start = max(1, $currentPage - 1);
$end = min($totalPages, $currentPage + 1);
// Ensure always 3 pages if possible
if ($currentPage == 1) $end = min($totalPages, 3);
if ($currentPage == $totalPages) $start = max(1, $totalPages - 2);
// Middle Pages
for ($i = $start; $i <= $end; $i++) {
$query['page'] = $i;
$active = $i == $currentPage ? 'active' : '';
echo "<li class='page-item $active'><a class='page-link' href='?" . http_build_query($query) . "'>$i</a></li>";
}
// Next & Last
if ($currentPage < $totalPages) {
$query['page'] = $currentPage + 1;
echo "<li class='page-item'><a class='page-link' href='?" . http_build_query($query) . "'>Next</a></li>";
$query['page'] = $totalPages;
echo "<li class='page-item'><a class='page-link' href='?" . http_build_query($query) . "'>Last</a></li>";
}
echo '</ul></nav>';
?>
</div>
</div>
</div>
</div>
<!-- Confirm Toggle Modal -->
<div class="modal fade" id="walletStatusModal" tabindex="-1" aria-labelledby="walletStatusModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="walletStatusModalLabel">Confirm Wallet Status Change</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="walletStatusMessage">
<!-- Dynamic message goes here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-success" id="confirmWalletStatusBtn">Yes, Proceed</button>
</div>
</div>
</div>
</div>
<script>
document.querySelectorAll('.wallet-toggle').forEach(toggle => {
toggle.addEventListener('change', function () {
const walletId = this.dataset.id;
const email = this.dataset.email;
const newStatus = this.checked ? 'active' : 'inactive';
const actionText = this.checked ? 'activate' : 'suspend';
if (!confirm(`Are you sure you want to ${actionText} wallet for ${email}?`)) {
this.checked = !this.checked; // revert
return;
}
fetch('toggle_wallet.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `wallet_id=${walletId}&new_status=${newStatus}`
})
.then(res => res.json())
.then(data => {
if (!data.success) {
alert('Failed to update wallet status');
this.checked = !this.checked; // revert on failure
}
})
.catch(() => {
alert('Network error');
this.checked = !this.checked;
});
});
});
</script>
<? include '../common/footer.php'; ?>Выполнить команду
Для локальной разработки. Не используйте в интернете!