Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20fc17bb56 | ||
|
|
3d63e8cf87 |
14
assets/css/custom.css
Normal file
14
assets/css/custom.css
Normal file
@ -0,0 +1,14 @@
|
||||
body {
|
||||
font-family: 'Inter', sans-serif;
|
||||
background-color: #F8F9FA;
|
||||
}
|
||||
|
||||
.gradient-header {
|
||||
background: linear-gradient(to right, #0D6EFD, #0A58CA);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 0.375rem;
|
||||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
7
assets/js/main.js
Normal file
7
assets/js/main.js
Normal file
@ -0,0 +1,7 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const toastElList = [].slice.call(document.querySelectorAll('.toast'));
|
||||
const toastList = toastElList.map(function (toastEl) {
|
||||
return new bootstrap.Toast(toastEl, { delay: 3000 });
|
||||
});
|
||||
toastList.forEach(toast => toast.show());
|
||||
});
|
||||
@ -1,17 +1,70 @@
|
||||
<?php
|
||||
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||
define('DB_HOST', '127.0.0.1');
|
||||
define('DB_NAME', 'app_30972');
|
||||
define('DB_USER', 'app_30972');
|
||||
define('DB_PASS', '9eb17a13-4a89-4e11-8517-0c201096e935');
|
||||
// db/config.php
|
||||
function db(): ?PDO {
|
||||
static $pdo = null;
|
||||
if ($pdo !== null) {
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
function db() {
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
return $pdo;
|
||||
$host = getenv('DB_HOST') ?: '127.0.0.1';
|
||||
$port = getenv('DB_PORT') ?: '3306';
|
||||
$db = getenv('DB_NAME') ?: 'app_35256';
|
||||
$user = getenv('DB_USER') ?: 'app_35256';
|
||||
$pass = getenv('DB_PASS') ?: '0297656a-e7ff-4e19-adc5-34bd6e744b8f';
|
||||
$charset = 'utf8mb4';
|
||||
|
||||
$dsn = "mysql:host=$host;port=$port;dbname=$db;charset=$charset";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$pdo = new PDO($dsn, $user, $pass, $options);
|
||||
run_migrations($pdo);
|
||||
return $pdo;
|
||||
} catch (\PDOException $e) {
|
||||
error_log($e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function run_migrations(PDO $pdo): void {
|
||||
$migrations_dir = __DIR__ . '/migrations';
|
||||
if (!is_dir($migrations_dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdot = $pdo->query("SHOW TABLES LIKE 'migrations'");
|
||||
$table_exists = $pdot->rowCount() > 0;
|
||||
|
||||
if (!$table_exists) {
|
||||
$pdo->exec("CREATE TABLE migrations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
migration VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT migration FROM migrations");
|
||||
$stmt->execute();
|
||||
$run_migrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$migration_files = glob($migrations_dir . '/*.sql');
|
||||
foreach ($migration_files as $file) {
|
||||
$migration_name = basename($file);
|
||||
if (!in_array($migration_name, $run_migrations)) {
|
||||
$sql = file_get_contents($file);
|
||||
if ($sql === false) continue;
|
||||
$pdo->exec($sql);
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migration_name]);
|
||||
}
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
error_log("Migration failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
17
db/migrations/001_create_initial_tables.sql
Normal file
17
db/migrations/001_create_initial_tables.sql
Normal file
@ -0,0 +1,17 @@
|
||||
CREATE TABLE IF NOT EXISTS categories (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL UNIQUE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT IGNORE INTO categories (name) VALUES ('Food'), ('Pharmacy'), ('Transport'), ('Shopping'), ('Sports'), ('Entertainment'), ('Groceries'), ('House hold Items'), ('Education');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS expenses (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
amount DECIMAL(10, 2) NOT NULL,
|
||||
category_id INT NOT NULL,
|
||||
payment_method VARCHAR(255) NOT NULL,
|
||||
notes TEXT,
|
||||
expense_date DATE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (category_id) REFERENCES categories(id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
356
index.php
356
index.php
@ -1,150 +1,226 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
|
||||
|
||||
|
||||
$pdo = db();
|
||||
$message = null;
|
||||
$message_type = '';
|
||||
|
||||
if (!$pdo) {
|
||||
$message = "Database connection failed. Please check configuration.";
|
||||
$message_type = 'danger';
|
||||
} else {
|
||||
// Handle Delete
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['delete'])) {
|
||||
$id_to_delete = filter_input(INPUT_GET, 'delete', FILTER_VALIDATE_INT);
|
||||
if ($id_to_delete) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM expenses WHERE id = ?");
|
||||
$stmt->execute([$id_to_delete]);
|
||||
$_SESSION['message'] = 'Expense deleted successfully.';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
} catch (PDOException $e) {
|
||||
$_SESSION['message'] = 'Error deleting expense: ' . $e->getMessage();
|
||||
$_SESSION['message_type'] = 'danger';
|
||||
}
|
||||
}
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle Add
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_expense'])) {
|
||||
$amount = filter_input(INPUT_POST, 'amount', FILTER_VALIDATE_FLOAT);
|
||||
$category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT);
|
||||
$payment_method = htmlspecialchars(trim($_POST['payment_method']));
|
||||
$expense_date = $_POST['expense_date']; // Basic validation, consider more robust date validation
|
||||
$notes = htmlspecialchars(trim($_POST['notes']));
|
||||
|
||||
if ($amount && $category_id && !empty($payment_method) && !empty($expense_date)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO expenses (amount, category_id, payment_method, expense_date, notes) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$amount, $category_id, $payment_method, $expense_date, $notes]);
|
||||
$_SESSION['message'] = 'Expense added successfully!';
|
||||
$_SESSION['message_type'] = 'success';
|
||||
} catch (PDOException $e) {
|
||||
$_SESSION['message'] = 'Error adding expense: ' . $e->getMessage();
|
||||
$_SESSION['message_type'] = 'danger';
|
||||
}
|
||||
} else {
|
||||
$_SESSION['message'] = 'Please fill all required fields correctly.';
|
||||
$_SESSION['message_type'] = 'warning';
|
||||
}
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Flash message handling
|
||||
if (isset($_SESSION['message'])) {
|
||||
$message = $_SESSION['message'];
|
||||
$message_type = $_SESSION['message_type'];
|
||||
unset($_SESSION['message']);
|
||||
unset($_SESSION['message_type']);
|
||||
}
|
||||
|
||||
// Fetch data for display
|
||||
$categories = [];
|
||||
$expenses = [];
|
||||
if ($pdo) {
|
||||
try {
|
||||
$categories = $pdo->query("SELECT * FROM categories ORDER BY name ASC")->fetchAll();
|
||||
$expenses = $pdo->query("SELECT e.*, c.name as category_name FROM expenses e JOIN categories c ON e.category_id = c.id ORDER BY e.expense_date DESC, e.id DESC LIMIT 20")->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
$message = "Error fetching data: " . $e->getMessage();
|
||||
$message_type = 'danger';
|
||||
}
|
||||
}
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Personal Expense Tracker</title>
|
||||
<meta name="description" content="A personal expense tracker web application built with Flatlogic.">
|
||||
<meta name="keywords" content="expense tracker, budget, finance, personal finance, money management, flatlogic generator">
|
||||
<meta property="og:title" content="Personal Expense Tracker">
|
||||
<meta property="og:description" content="A personal expense tracker web application built with Flatlogic.">
|
||||
<meta property="og:image" content="">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="">
|
||||
|
||||
<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="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
|
||||
<div id="liveToast" class="toast show" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="toast-header bg-<?php echo $message_type; ?> text-white">
|
||||
<strong class="me-auto"><?php echo $message_type === 'success' ? 'Success' : 'Notice'; ?></strong>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="toast-body">
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
<?php endif; ?>
|
||||
|
||||
<header class="p-4 mb-4 gradient-header">
|
||||
<div class="container">
|
||||
<h1 class="h3">Personal Expense Tracker</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<div class="row g-4">
|
||||
<!-- Add Expense Form -->
|
||||
<div class="col-lg-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="h5 mb-0">Add New Expense</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="index.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="amount" class="form-label">Amount</label>
|
||||
<input type="number" step="0.01" class="form-control" id="amount" name="amount" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="expense_date" class="form-label">Date</label>
|
||||
<input type="date" class="form-control" id="expense_date" name="expense_date" value="<?php echo date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="category_id" class="form-label">Category</label>
|
||||
<select class="form-select" id="category_id" name="category_id" required>
|
||||
<option value="">Select Category</option>
|
||||
<?php foreach ($categories as $category): ?>
|
||||
<option value="<?php echo $category['id']; ?>"><?php echo htmlspecialchars($category['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="payment_method" class="form-label">Payment Method</label>
|
||||
<input type="text" class="form-control" id="payment_method" name="payment_method" required value="Cash">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="notes" class="form-label">Notes</label>
|
||||
<textarea class="form-control" id="notes" name="notes" rows="2"></textarea>
|
||||
</div>
|
||||
<button type="submit" name="add_expense" class="btn btn-primary w-100">
|
||||
<i class="bi bi-plus-circle"></i> Add Expense
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recent Transactions -->
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="h5 mb-0">Recent Transactions</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Amount</th>
|
||||
<th>Category</th>
|
||||
<th>Payment Method</th>
|
||||
<th>Notes</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($expenses)): ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">No expenses recorded yet.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($expenses as $expense): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($expense['expense_date']); ?></td>
|
||||
<td>$<?php echo htmlspecialchars(number_format($expense['amount'], 2)); ?></td>
|
||||
<td><?php echo htmlspecialchars($expense['category_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($expense['payment_method']); ?></td>
|
||||
<td><?php echo htmlspecialchars($expense['notes']); ?></td>
|
||||
<td>
|
||||
<a href="index.php?delete=<?php echo $expense['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this expense?');">
|
||||
<i class="bi bi-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="container mt-4 text-center text-muted">
|
||||
<p>© <?php echo date("Y"); ?> Personal Expense Tracker. Built with Flatlogic.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user