159 lines
7.3 KiB
PHP
159 lines
7.3 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// If user is not logged in, redirect to login page
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("Location: login.php");
|
|
exit();
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$user = null;
|
|
$balance = 0;
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT full_name, balance FROM users WHERE id = :id");
|
|
$stmt->execute(['id' => $user_id]);
|
|
$user = $stmt->fetch();
|
|
$balance = $user['balance'] ?? 0;
|
|
} catch (PDOException $e) {
|
|
// Handle db error
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>UBPay Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">
|
|
<i class="bi bi-wallet2"></i> UBPay
|
|
</a>
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle"></i> <?php echo htmlspecialchars($user['full_name'] ?? 'User'); ?>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
|
|
<li><a class="dropdown-item" href="#">Profile</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container mt-4">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<h1 class="h3 mb-4">Welcome, <?php echo htmlspecialchars(explode(' ', $user['full_name'])[0] ?? 'User'); ?>!</h1>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- Wallet Balance -->
|
|
<div class="col-md-6 col-lg-4 mb-4">
|
|
<div class="card text-white" style="background: linear-gradient(135deg, #00A859 0%, #007B5F 100%);">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Wallet Balance</h5>
|
|
<p class="display-4 fw-bold">R<?php echo number_format($balance, 2); ?></p>
|
|
<p class="card-text text-white-50">Available Funds</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Quick Actions -->
|
|
<div class="col-md-6 col-lg-8 mb-4">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title mb-3">Quick Actions</h5>
|
|
<div class="d-grid gap-2 d-sm-flex">
|
|
<a href="send-money.php" class="btn btn-primary flex-fill"><i class="bi bi-send"></i> Send Money</a>
|
|
<a href="pay-merchant.php" class="btn btn-secondary flex-fill"><i class="bi bi-shop"></i> Pay Merchant</a>
|
|
<button class="btn btn-info flex-fill"><i class="bi bi-phone"></i> Buy Airtime</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Recent Transactions -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Recent Transactions</h5>
|
|
<?php
|
|
try {
|
|
$pdo = db();
|
|
// Create table if not exists
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS transactions (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
description VARCHAR(255) NOT NULL,
|
|
amount DECIMAL(10, 2) NOT NULL,
|
|
type VARCHAR(50) NOT NULL,
|
|
notes TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
)");
|
|
|
|
// Fetch transactions for the logged-in user
|
|
$stmt = $pdo->prepare("SELECT description, amount, type, notes, created_at FROM transactions WHERE user_id = :user_id ORDER BY created_at DESC LIMIT 10");
|
|
$stmt->execute(['user_id' => $user_id]);
|
|
$transactions = $stmt->fetchAll();
|
|
|
|
if (count($transactions) > 0) {
|
|
echo '<ul class="list-group list-group-flush">';
|
|
foreach ($transactions as $tx) {
|
|
$amount_class = $tx['amount'] > 0 ? 'text-success' : 'text-danger';
|
|
$icon = $tx['amount'] > 0 ? 'bi-arrow-down-circle-fill' : 'bi-arrow-up-circle-fill';
|
|
$amount_prefix = $tx['amount'] > 0 ? '+' : '-';
|
|
$formatted_amount = 'R' . number_format(abs($tx['amount']), 2);
|
|
|
|
echo '<li class="list-group-item d-flex justify-content-between align-items-center">';
|
|
echo '<div>';
|
|
echo '<i class="bi ' . $icon . ' ' . $amount_class . '"></i>';
|
|
echo '<strong class="ms-2">' . htmlspecialchars($tx['description']) . '</strong>';
|
|
echo '<small class="d-block text-muted">' . htmlspecialchars($tx['type']) . '</small>';
|
|
if (!empty($tx['notes'])) {
|
|
echo '<small class="d-block text-muted fst-italic">' . htmlspecialchars($tx['notes']) . '</small>';
|
|
}
|
|
echo '</div>';
|
|
echo '<span class="' . $amount_class . ' fw-bold">' . $amount_prefix . ' ' . $formatted_amount . '</span>';
|
|
echo '</li>';
|
|
}
|
|
echo '</ul>';
|
|
} else {
|
|
echo '<p class="text-muted">No recent transactions.</p>';
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo '<p class="text-danger">Database error: Could not fetch transactions.</p>';
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="text-center text-muted py-4">
|
|
© 2025 UBPay. All Rights Reserved.
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|