fixing
This commit is contained in:
parent
46b09acf12
commit
3268e0d6c2
654
html.php
654
html.php
@ -2,647 +2,57 @@
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
// Redirect ke login jika belum login
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: loginn.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// AMBIL DATA TERBARU DARI DATABASE, jangan pakai session saja
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$sql = "SELECT username, balance FROM users WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "i", $user_id);
|
||||
// Selalu ambil saldo dari DATABASE
|
||||
$query = "SELECT bank FROM users WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $query);
|
||||
mysqli_stmt_bind_param($stmt, "i", $_SESSION['user_id']);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
$data = mysqli_fetch_assoc($result);
|
||||
|
||||
// Update session dengan data terbaru dari database
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['balance'] = intval($user['balance']);
|
||||
|
||||
$username = $_SESSION['username'];
|
||||
$balance = $_SESSION['balance'];
|
||||
$currentBank = intval($data["bank"]);
|
||||
$_SESSION["bank"] = $currentBank;
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Blackjack [21] - OCA GameHub</title>
|
||||
|
||||
<link rel="stylesheet" href="cliff.css" />
|
||||
<style>
|
||||
/* ... semua CSS sebelumnya tetap ... */
|
||||
</style>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="login.css">
|
||||
<title>Top Up</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="table" role="application" aria-label="Blackjack tanpa iklan">
|
||||
<header>
|
||||
<h1> Blackjack [21] </h1>
|
||||
<div class="controls">
|
||||
<div style="display:flex;gap:12px;align-items:center;margin-bottom:8px;">
|
||||
<div>Signed in as: <strong id="username-display"><?php echo htmlspecialchars($username); ?></strong></div>
|
||||
<button id="topup-btn">Top Up</button>
|
||||
<a href="logout.php" onclick="return confirm('Yakin ingin logout?')">Logout</a>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="chip">Bank: <span id="balance"><?php echo number_format($balance, 0, ',', '.'); ?></span></div>
|
||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||
</div>
|
||||
<div class="bet">
|
||||
<input id="bet-input" type="number" min="1" value="50" />
|
||||
<button id="bet-btn">Pasang Taruhan</button>
|
||||
<button id="new-round" class="secondary"> Reset </button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<!-- ... game board tetap sama ... -->
|
||||
</main>
|
||||
<h2>Top Up Saldo</h2>
|
||||
|
||||
<!-- Top Up Modal -->
|
||||
<div id="topup-modal" class="modal" style="display: none;">
|
||||
<!-- ... modal content tetap sama ... -->
|
||||
<p>User: <b><?= $_SESSION['username'] ?></b></p>
|
||||
<p>Saldo Bank Sekarang: <b>Rp <?= number_format($currentBank, 0, ',', '.') ?></b></p>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div style="color:<?= $message_type == 'success' ? 'lime' : 'red' ?>;">
|
||||
<?= $message ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<footer>
|
||||
OCA GameHub - <code> Blackjack_[21] - </code> Semoga menang bosq
|
||||
</footer>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<label>Pilih Bank :</label><br>
|
||||
<input type="radio" name="bank_method" value="bca">BCA<br>
|
||||
<input type="radio" name="bank_method" value="bni">BNI<br>
|
||||
<input type="radio" name="bank_method" value="mandiri">Mandiri<br><br>
|
||||
|
||||
<label>Jumlah Top Up:</label>
|
||||
<input type="number" name="amount" required><br><br>
|
||||
|
||||
<button type="submit">Top Up</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<a href="html.php">Kembali</a>
|
||||
|
||||
<!-- SET GLOBAL VARIABLES DARI PHP -->
|
||||
<script>
|
||||
// Set global variables untuk JavaScript
|
||||
window.serverBalance = <?php echo $balance; ?>;
|
||||
window.userId = <?php echo $user_id; ?>;
|
||||
window.username = "<?php echo addslashes($username); ?>";
|
||||
</script>
|
||||
|
||||
<script src="ody git.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
// Redirect ke login jika belum login
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: loginn.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ambil data user dari database
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$sql = "SELECT username, balance FROM users WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "i", $user_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
|
||||
$username = $_SESSION['username'];
|
||||
$balance = $_SESSION['balance'];
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<!-- ... meta tags tetap sama ... -->
|
||||
<title>Blackjack [21] - OCA GameHub</title>
|
||||
|
||||
<!-- Tambah PHP untuk dynamic styling -->
|
||||
<style>
|
||||
/* ... semua CSS sebelumnya tetap ... */
|
||||
|
||||
/* Tambahan untuk user info */
|
||||
.user-info {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
background: rgba(0, 50, 0, 0.2);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||
}
|
||||
|
||||
.balance-display {
|
||||
font-size: 1.2em;
|
||||
color: #00FF00;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="table" role="application" aria-label="Blackjack tanpa iklan">
|
||||
<header>
|
||||
<h1> Blackjack [21] </h1>
|
||||
<div class="controls">
|
||||
<!-- Ganti bagian ini -->
|
||||
<div class="user-info">
|
||||
<div>Signed in as: <strong id="username-display"><?php echo htmlspecialchars($username); ?></strong></div>
|
||||
<button id="topup-btn">Top Up</button>
|
||||
<a href="logout.php" onclick="return confirm('Yakin ingin logout?')">Logout</a>
|
||||
</div>
|
||||
|
||||
<div class="info">
|
||||
<div class="chip">Bank: <span id="balance"><?php echo number_format($balance, 0, ',', '.'); ?></span></div>
|
||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||
</div>
|
||||
<!-- ... bagian bet tetap sama ... -->
|
||||
</div>
|
||||
</header>
|
||||
<!-- ... sisanya tetap sama ... -->
|
||||
|
||||
session_start();
|
||||
// If not logged in, redirect to login
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header('Location: loginn.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialize balance if not set
|
||||
if (!isset($_SESSION['balance'])) {
|
||||
$_SESSION['balance'] = 1000; // Default starting balance
|
||||
}
|
||||
|
||||
// Handle Top Up form
|
||||
$topup_response = '';
|
||||
$topup_success = false;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['bank_method'])) {
|
||||
$bank_method = $_POST['bank_method'] ?? '';
|
||||
$amount = (int)($_POST['amount'] ?? 0);
|
||||
|
||||
if (empty($bank_method)) {
|
||||
$topup_response = 'Pilih metode pembayaran terlebih dahulu.';
|
||||
} elseif ($amount <= 0) {
|
||||
$topup_response = 'Masukkan jumlah top up yang valid (lebih dari 0).';
|
||||
} else {
|
||||
$_SESSION['balance'] += $amount;
|
||||
$topup_response = 'Top up berhasil! Saldo: Rp ' . number_format($_SESSION['balance'], 0, ',', '.');
|
||||
$topup_success = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle balance update from game
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_balance'])) {
|
||||
$new_balance = (int)$_POST['update_balance'];
|
||||
if ($new_balance >= 0) {
|
||||
$_SESSION['balance'] = $new_balance;
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['status' => 'success', 'balance' => $_SESSION['balance']]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Blackjack [21] - OCA GameHub</title>
|
||||
|
||||
<link rel="stylesheet" href="cliff.css" />
|
||||
<style>
|
||||
/* Modal Styling */
|
||||
.modal {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: linear-gradient(135deg, rgba(10, 58, 26, 0.95), rgba(15, 122, 58, 0.95));
|
||||
border: 2px solid rgba(0, 255, 0, 0.4);
|
||||
border-radius: 15px;
|
||||
padding: 30px;
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 255, 0, 0.3);
|
||||
color: #88FF88;
|
||||
}
|
||||
|
||||
.modal-content h2 {
|
||||
color: #00FF00;
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
||||
}
|
||||
|
||||
.close-modal {
|
||||
color: #00FF00;
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.close-modal:hover {
|
||||
color: #FF6B6B;
|
||||
text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
|
||||
}
|
||||
|
||||
.modal-info {
|
||||
background: rgba(0, 100, 0, 0.2);
|
||||
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.modal-info p {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.modal-info strong {
|
||||
color: #00FF00;
|
||||
}
|
||||
|
||||
.topup-message {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 13px;
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
.topup-message.success {
|
||||
background: rgba(0, 255, 0, 0.2);
|
||||
border-color: #00FF00;
|
||||
color: #00FF00;
|
||||
}
|
||||
|
||||
.topup-message.error {
|
||||
background: rgba(255, 107, 107, 0.2);
|
||||
border-color: #FF6B6B;
|
||||
color: #FF9999;
|
||||
}
|
||||
|
||||
.form-group-modal {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group-modal label {
|
||||
display: block;
|
||||
color: #00FF00;
|
||||
font-size: 13px;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.bank-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.bank-choice {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.bank-choice input[type="radio"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.bank-btn {
|
||||
display: block;
|
||||
padding: 12px 8px;
|
||||
background: rgba(0, 100, 0, 0.2);
|
||||
border: 2px solid rgba(0, 255, 0, 0.3);
|
||||
border-radius: 6px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: #88FF88;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.bank-choice input[type="radio"]:checked + .bank-btn {
|
||||
background: rgba(0, 255, 0, 0.3);
|
||||
border-color: #00FF00;
|
||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
||||
color: #00FF00;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.bank-btn:hover {
|
||||
border-color: rgba(0, 255, 0, 0.6);
|
||||
background: rgba(0, 150, 0, 0.2);
|
||||
}
|
||||
|
||||
.form-group-modal input[type="number"] {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid rgba(0, 255, 0, 0.5);
|
||||
background: rgba(0, 100, 0, 0.1);
|
||||
color: #88FF88;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.form-group-modal input[type="number"]::placeholder {
|
||||
color: rgba(136, 255, 136, 0.5);
|
||||
}
|
||||
|
||||
.form-group-modal input[type="number"]:focus {
|
||||
outline: none;
|
||||
border-color: #00FF00;
|
||||
background: rgba(0, 150, 0, 0.2);
|
||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
||||
}
|
||||
|
||||
.quick-btn-group {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.quick-btn {
|
||||
padding: 8px;
|
||||
background: rgba(0, 255, 0, 0.2);
|
||||
border: 1px solid rgba(0, 255, 0, 0.4);
|
||||
color: #00FF00;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.quick-btn:hover {
|
||||
background: rgba(0, 255, 0, 0.3);
|
||||
border-color: #00FF00;
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.btn-modal-submit, .btn-modal-cancel {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.btn-modal-submit {
|
||||
background: linear-gradient(135deg, #00FF00, #00CC00);
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.btn-modal-submit:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(0, 255, 0, 0.6);
|
||||
}
|
||||
|
||||
.btn-modal-cancel {
|
||||
background: rgba(0, 255, 0, 0.2);
|
||||
color: #00FF00;
|
||||
border: 1px solid #00FF00;
|
||||
}
|
||||
|
||||
.btn-modal-cancel:hover {
|
||||
background: rgba(0, 255, 0, 0.3);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="table" role="application" aria-label="Blackjack tanpa iklan">
|
||||
<header>
|
||||
<h1> Blackjack [21] </h1>
|
||||
<div class="controls">
|
||||
<div style="display:flex;gap:12px;align-items:center;margin-bottom:8px;">
|
||||
<div>Signed in as: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></div>
|
||||
<button id="topup-btn" style="text-decoration:none;padding:6px 10px;background:#3b82f6;color:#fff;border-radius:6px;border:none;cursor:pointer;font-weight:bold;">Top Up</button>
|
||||
<a href="logout.php" style="text-decoration:none;padding:6px 10px;background:#ef4444;color:#fff;border-radius:6px;">Logout</a>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="chip">Bank: <span id="balance">0</span></div>
|
||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||
</div>
|
||||
<div class="bet">
|
||||
<input id="bet-input" type="number" min="1" value="50" />
|
||||
<button id="bet-btn">Pasang Taruhan</button>
|
||||
<button id="new-round" class="secondary"> Reset </button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div class="board" id="dealer-area">
|
||||
<div class="section-title">Dealer</div>
|
||||
<div class="hand" id="dealer-hand"></div>
|
||||
<div class="values" id="dealer-value"></div>
|
||||
</div>
|
||||
|
||||
<div class="board" id="player-area">
|
||||
<div class="section-title">Pemain</div>
|
||||
<div class="hand" id="player-hand"></div>
|
||||
<div class="values" id="player-value"></div>
|
||||
|
||||
<div class="actions" id="action-buttons">
|
||||
<button id="hit">Hit</button>
|
||||
<button id="stand">Stand</button>
|
||||
<button id="double">Double</button>
|
||||
</div>
|
||||
<div class="message" id="message"></div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Top Up Modal -->
|
||||
<div id="topup-modal" class="modal" style="display: none;">
|
||||
<div class="modal-content">
|
||||
<span class="close-modal" onclick="closeTopUpModal()">×</span>
|
||||
<h2>💳 Top Up Saldo</h2>
|
||||
|
||||
<div class="modal-info">
|
||||
<p>Pemain: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></p>
|
||||
<p>Saldo Saat Ini: <strong>Rp <span id="modal-balance">0</span></strong></p>
|
||||
</div>
|
||||
|
||||
<div id="topup-message" class="topup-message" style="display: none;"></div>
|
||||
|
||||
<form method="POST" action="html.php" id="topup-form">
|
||||
<div class="form-group-modal">
|
||||
<label>🏦 Pilih Bank</label>
|
||||
<div class="bank-grid">
|
||||
<div class="bank-choice">
|
||||
<input type="radio" id="m-bca" name="bank_method" value="bca" />
|
||||
<label for="m-bca" class="bank-btn">🏛️ BCA</label>
|
||||
</div>
|
||||
<div class="bank-choice">
|
||||
<input type="radio" id="m-mandiri" name="bank_method" value="mandiri" />
|
||||
<label for="m-mandiri" class="bank-btn">🏦 Mandiri</label>
|
||||
</div>
|
||||
<div class="bank-choice">
|
||||
<input type="radio" id="m-bni" name="bank_method" value="bni" />
|
||||
<label for="m-bni" class="bank-btn">🏤 BNI</label>
|
||||
</div>
|
||||
<div class="bank-choice">
|
||||
<input type="radio" id="m-cimb" name="bank_method" value="cimb" />
|
||||
<label for="m-cimb" class="bank-btn">💰 CIMB</label>
|
||||
</div>
|
||||
<div class="bank-choice">
|
||||
<input type="radio" id="m-ocbc" name="bank_method" value="ocbc" />
|
||||
<label for="m-ocbc" class="bank-btn">🏢 OCBC</label>
|
||||
</div>
|
||||
<div class="bank-choice">
|
||||
<input type="radio" id="m-ewallet" name="bank_method" value="ewallet" />
|
||||
<label for="m-ewallet" class="bank-btn">📱 e-Wallet</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group-modal">
|
||||
<label for="modal-amount">💵 Jumlah Top Up</label>
|
||||
<input id="modal-amount" name="amount" type="number" min="1" placeholder="Contoh: 50000" />
|
||||
<div class="quick-btn-group">
|
||||
<button type="button" class="quick-btn" onclick="setModalAmount(10000)">10K</button>
|
||||
<button type="button" class="quick-btn" onclick="setModalAmount(50000)">50K</button>
|
||||
<button type="button" class="quick-btn" onclick="setModalAmount(100000)">100K</button>
|
||||
<button type="button" class="quick-btn" onclick="setModalAmount(250000)">250K</button>
|
||||
<button type="button" class="quick-btn" onclick="setModalAmount(500000)">500K</button>
|
||||
<button type="button" class="quick-btn" onclick="setModalAmount(1000000)">1JT</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-buttons">
|
||||
<button type="submit" class="btn-modal-submit">Top Up</button>
|
||||
<button type="button" class="btn-modal-cancel" onclick="closeTopUpModal()">Batal</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
OCA GameHub - <code> Blackjack_[21] - </code> Semoga menang bosq
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Initialize balance from server BEFORE loading game script
|
||||
const serverBalance = <?php echo (int)$_SESSION['balance']; ?>;
|
||||
let gameBalance = serverBalance;
|
||||
// let balance = serverBalance; // Removed to avoid conflict with ody git.js
|
||||
</script>
|
||||
<script src="ody git.js"></script>
|
||||
<script>
|
||||
// Update display on load
|
||||
function updateBalanceDisplay() {
|
||||
document.getElementById('balance').textContent = gameBalance.toLocaleString('id-ID');
|
||||
const formattedBalance = gameBalance.toLocaleString('id-ID', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0
|
||||
});
|
||||
document.getElementById('modal-balance').textContent = formattedBalance;
|
||||
localStorage.setItem('playerBalance', gameBalance);
|
||||
}
|
||||
|
||||
updateBalanceDisplay();
|
||||
|
||||
// Modal Top Up
|
||||
const topupBtn = document.getElementById('topup-btn');
|
||||
const topupModal = document.getElementById('topup-modal');
|
||||
const topupForm = document.getElementById('topup-form');
|
||||
const topupMessage = document.getElementById('topup-message');
|
||||
const modalAmount = document.getElementById('modal-amount');
|
||||
|
||||
// Open modal
|
||||
topupBtn.addEventListener('click', function() {
|
||||
topupModal.style.display = 'flex';
|
||||
topupForm.reset();
|
||||
topupMessage.style.display = 'none';
|
||||
updateBalanceDisplay();
|
||||
});
|
||||
|
||||
// Close modal
|
||||
function closeTopUpModal() {
|
||||
topupModal.style.display = 'none';
|
||||
topupMessage.style.display = 'none';
|
||||
}
|
||||
|
||||
// Set amount
|
||||
function setModalAmount(amount) {
|
||||
document.getElementById('modal-amount').value = amount;
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
window.addEventListener('click', function(e) {
|
||||
if (e.target === topupModal) {
|
||||
closeTopUpModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle form submission
|
||||
topupForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const bankMethod = document.querySelector('input[name="bank_method"]:checked');
|
||||
const amount = parseInt(modalAmount.value);
|
||||
|
||||
if (!bankMethod) {
|
||||
showTopUpMessage('Pilih metode pembayaran terlebih dahulu.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount <= 0) {
|
||||
showTopUpMessage('Masukkan jumlah top up yang valid.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Submit form
|
||||
const formData = new FormData(topupForm);
|
||||
fetch('html.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
// Update balance from server response
|
||||
const newBalance = serverBalance + amount;
|
||||
gameBalance = newBalance;
|
||||
balance = newBalance;
|
||||
updateBalanceDisplay();
|
||||
|
||||
showTopUpMessage('✓ Top up berhasil! Saldo: Rp ' + gameBalance.toLocaleString('id-ID'), 'success');
|
||||
topupForm.reset();
|
||||
setTimeout(() => {
|
||||
closeTopUpModal();
|
||||
}, 2000);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showTopUpMessage('Terjadi kesalahan. Coba lagi.', 'error');
|
||||
});
|
||||
});
|
||||
|
||||
function showTopUpMessage(msg, type) {
|
||||
topupMessage.textContent = msg;
|
||||
topupMessage.className = 'topup-message ' + type;
|
||||
topupMessage.style.display = 'block';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
20
loginn.php
20
loginn.php
@ -95,4 +95,22 @@ if(isset($_POST['register'])){
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?
|
||||
<?
|
||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
|
||||
if ($row = mysqli_fetch_assoc($result)) {
|
||||
|
||||
if ($password === $row['password']) {
|
||||
|
||||
$_SESSION['user_id'] = $row['id'];
|
||||
$_SESSION['username'] = $row['username'];
|
||||
$_SESSION['bank'] = intval($row['bank']); // ← INI YANG PENTING
|
||||
|
||||
header("Location: html.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Not logged in']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$amount = intval($_POST['amount']);
|
||||
$bank_method = $_POST['bank_method'] ?? 'unknown';
|
||||
|
||||
// Validasi
|
||||
if ($amount <= 0 || $amount > 1000000) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid amount']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update balance di database
|
||||
$sql = "UPDATE users SET balance = balance + ? WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "ii", $amount, $user_id);
|
||||
|
||||
if (mysqli_stmt_execute($stmt)) {
|
||||
// Get new balance
|
||||
$sql2 = "SELECT balance FROM users WHERE id = ?";
|
||||
$stmt2 = mysqli_prepare($conn, $sql2);
|
||||
mysqli_stmt_bind_param($stmt2, "i", $user_id);
|
||||
mysqli_stmt_execute($stmt2);
|
||||
$result = mysqli_stmt_get_result($stmt2);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
|
||||
// Update session
|
||||
$_SESSION['balance'] = $user['balance'];
|
||||
|
||||
// Log transaction
|
||||
$log_sql = "INSERT INTO transactions (user_id, type, amount, description)
|
||||
VALUES (?, 'topup', ?, 'Top up via $bank_method')";
|
||||
$log_stmt = mysqli_prepare($conn, $log_sql);
|
||||
mysqli_stmt_bind_param($log_stmt, "ii", $user_id, $amount);
|
||||
mysqli_stmt_execute($log_stmt);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'new_balance' => $user['balance'],
|
||||
'message' => 'Top up successful'
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Database error']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
102
topupnew.php
Normal file
102
topupnew.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// === topup.php (digabung dengan html.php) ===
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
// Cek login
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: loginn.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ambil saldo terbaru dari database
|
||||
$query = "SELECT bank, username FROM users WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $query);
|
||||
mysqli_stmt_bind_param($stmt, "i", $_SESSION['user_id']);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
|
||||
$currentBank = intval($user["bank"]);
|
||||
$username = $user["username"];
|
||||
$_SESSION["bank"] = $currentBank;
|
||||
$_SESSION["username"] = $username;
|
||||
|
||||
$message = '';
|
||||
$message_type = '';
|
||||
|
||||
// Proses top up
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$bank_method = isset($_POST['bank_method']) ? $_POST['bank_method'] : '';
|
||||
$amount = isset($_POST['amount']) ? (int)$_POST['amount'] : 0;
|
||||
|
||||
if ($amount <= 0) {
|
||||
$message = 'Masukkan jumlah top up yang valid (lebih dari 0).';
|
||||
$message_type = 'error';
|
||||
} elseif (empty($bank_method)) {
|
||||
$message = 'Pilih metode pembayaran bank terlebih dahulu.';
|
||||
$message_type = 'error';
|
||||
} else {
|
||||
$newBalance = $currentBank + $amount;
|
||||
|
||||
// Update saldo ke database
|
||||
$update = "UPDATE users SET bank = ? WHERE id = ?";
|
||||
$stmt2 = mysqli_prepare($conn, $update);
|
||||
mysqli_stmt_bind_param($stmt2, "ii", $newBalance, $_SESSION['user_id']);
|
||||
mysqli_stmt_execute($stmt2);
|
||||
|
||||
$message = 'Top up berhasil! Saldo baru Anda: Rp ' . number_format($newBalance, 0, ',', '.');
|
||||
$message_type = 'success';
|
||||
|
||||
$_SESSION['bank'] = $newBalance;
|
||||
$currentBank = $newBalance;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Top Up Saldo - GameHub</title>
|
||||
<link rel="stylesheet" href="login.css" />
|
||||
</head>
|
||||
<body style="background:#000; color:white; font-family:Arial;">
|
||||
<div style="max-width:600px; margin:auto; padding:20px;">
|
||||
|
||||
<h1 style="color:#00FF00; text-align:center;">💳 Top Up Saldo</h1>
|
||||
|
||||
<div style="background:rgba(0,100,0,0.3); padding:15px; border-radius:10px; border:1px solid #00FF00; margin-bottom:20px;">
|
||||
<p>Pemain: <b style="color:#00FF00;"><?= htmlspecialchars($username) ?></b></p>
|
||||
<p>Saldo Saat Ini: <b style="color:#00FF00;">Rp <?= number_format($currentBank, 0, ',', '.') ?></b></p>
|
||||
</div>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div style="padding:12px; border-radius:8px; margin-bottom:15px; border:1px solid <?= $message_type=='success'?'#00FF00':'#FF6B6B' ?>; color:<?= $message_type=='success'?'#00FF00':'#FF9999' ?>;">
|
||||
<?= htmlspecialchars($message) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST" action="topup.php" style="background:rgba(0,100,0,0.2); padding:20px; border-radius:10px; border:1px solid #00FF00;">
|
||||
<label style="color:#00FF00;">🏦 Pilih Bank</label><br><br>
|
||||
|
||||
<label><input type="radio" name="bank_method" value="bca"> BCA</label><br>
|
||||
<label><input type="radio" name="bank_method" value="mandiri"> Mandiri</label><br>
|
||||
<label><input type="radio" name="bank_method" value="bni"> BNI</label><br>
|
||||
<label><input type="radio" name="bank_method" value="cimb"> CIMB Niaga</label><br>
|
||||
<label><input type="radio" name="bank_method" value="ocbc"> OCBC NISP</label><br>
|
||||
<label><input type="radio" name="bank_method" value="ewallet"> E-Wallet</label><br><br>
|
||||
|
||||
<label style="color:#00FF00;">💵 Jumlah Top Up</label>
|
||||
<input type="number" name="amount" min="1" placeholder="Contoh: 50000" required style="width:100%; padding:10px; border-radius:8px; margin-top:5px;">
|
||||
|
||||
<br><br>
|
||||
|
||||
<button type="submit" style="width:100%; padding:12px; background:#00FF00; border:none; border-radius:8px; font-weight:bold; cursor:pointer;">Lanjutkan Top Up</button>
|
||||
<br><br>
|
||||
<a href="html.php" style="display:block; text-align:center; padding:10px; color:#00FF00;">Kembali</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
include "koneksi.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Not logged in']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$balance = intval($data['balance']);
|
||||
|
||||
// Update balance di database
|
||||
$sql = "UPDATE users SET balance = ? WHERE id = ?";
|
||||
$stmt = mysqli_prepare($conn, $sql);
|
||||
mysqli_stmt_bind_param($stmt, "ii", $balance, $user_id);
|
||||
|
||||
if (mysqli_stmt_execute($stmt)) {
|
||||
// Update session
|
||||
$_SESSION['balance'] = $balance;
|
||||
|
||||
// Log transaction jika perlu
|
||||
if (isset($data['transaction'])) {
|
||||
$transaction = $data['transaction'];
|
||||
$log_sql = "INSERT INTO transactions (user_id, type, amount, description)
|
||||
VALUES (?, ?, ?, ?)";
|
||||
$log_stmt = mysqli_prepare($conn, $log_sql);
|
||||
mysqli_stmt_bind_param($log_stmt, "ssis",
|
||||
$user_id,
|
||||
$transaction['type'],
|
||||
$transaction['amount'],
|
||||
$transaction['description']
|
||||
);
|
||||
mysqli_stmt_execute($log_stmt);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'new_balance' => $balance,
|
||||
'message' => 'Balance updated successfully'
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Database error']);
|
||||
}
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user