Compare commits

...

1 Commits

Author SHA1 Message Date
Flatlogic Bot
65d71ae74f v1 2025-11-23 19:41:44 +00:00
12 changed files with 971 additions and 144 deletions

277
admin.php Normal file
View File

@ -0,0 +1,277 @@
<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: /login.php");
exit;
}
$userId = $_SESSION['user_id'];
$db = db();
// Check if user is admin
$stmt = $db->prepare("SELECT role FROM users WHERE id = ?");
$stmt->execute([$userId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user || $user['role'] !== 'admin') {
header("Location: /dashboard.php");
exit;
}
// Admin-specific actions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Edit Subscription
if (isset($_POST['edit_subscription'])) {
$subscription_id = $_POST['subscription_id'];
$name = $_POST['name'];
$cost = $_POST['cost'];
$renewal_date = $_POST['renewal_date'];
$category = $_POST['category'];
$frequency = $_POST['frequency'];
$stmt = $db->prepare("UPDATE subscriptions SET name = ?, cost = ?, renewal_date = ?, category = ?, frequency = ? WHERE id = ?");
$stmt->execute([$name, $cost, $renewal_date, $category, $frequency, $subscription_id]);
}
// Delete Subscription
elseif (isset($_POST['delete_subscription'])) {
$subscription_id = $_POST['subscription_id'];
$stmt = $db->prepare("DELETE FROM subscriptions WHERE id = ?");
$stmt->execute([$subscription_id]);
}
// TODO: Add user management actions (e.g., edit, delete user, reset password)
header("Location: admin.php");
exit;
}
// Fetch aggregated metrics
$totalUsers = $db->query("SELECT COUNT(*) FROM users")->fetchColumn();
$totalSubscriptions = $db->query("SELECT COUNT(*) FROM subscriptions")->fetchColumn();
$totalValue = $db->query("SELECT SUM(cost) FROM subscriptions")->fetchColumn();
// Fetch all users and subscriptions
$users = $db->query("SELECT id, name, email, role, is_active, created_at FROM users ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
$subscriptions = $db->query("SELECT s.*, u.name as user_name FROM subscriptions s JOIN users u ON s.user_id = u.id ORDER BY s.renewal_date ASC")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel - Subscription Manager</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container-fluid">
<a class="navbar-brand" href="/admin.php">Admin Panel</a>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<span class="navbar-text me-3">Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?> (Admin)!</span>
</li>
<li class="nav-item">
<a href="/dashboard.php" class="btn btn-outline-secondary me-2">My Dashboard</a>
</li>
<li class="nav-item">
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-5">
<!-- Aggregated Metrics -->
<div class="row mb-4">
<div class="col-md-4">
<div class="card text-white bg-primary">
<div class="card-body">
<h5 class="card-title">Total Users</h5>
<p class="card-text fs-2 fw-bold"><?php echo $totalUsers; ?></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-success">
<div class="card-body">
<h5 class="card-title">Total Subscriptions</h5>
<p class="card-text fs-2 fw-bold"><?php echo $totalSubscriptions; ?></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-info">
<div class="card-body">
<h5 class="card-title">Total Value Tracked</h5>
<p class="card-text fs-2 fw-bold">$<?php echo number_format($totalValue ?? 0, 2); ?></p>
</div>
</div>
</div>
</div>
<!-- User Management -->
<div class="card shadow-sm mb-5">
<div class="card-header">
<h4 class="mb-0">User Management</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Active</th>
<th>Joined</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<tr>
<td><?php echo htmlspecialchars($u['name']); ?></td>
<td><?php echo htmlspecialchars($u['email']); ?></td>
<td><?php echo htmlspecialchars($u['role']); ?></td>
<td><?php echo $u['is_active'] ? 'Yes' : 'No'; ?></td>
<td><?php echo date("Y-m-d", strtotime($u['created_at'])); ?></td>
<td>
<button class="btn btn-sm btn-outline-secondary" disabled>Edit</button>
<a href="reset-password.php?user_id=<?php echo $u['id']; ?>" class="btn btn-sm btn-outline-warning" target="_blank">Reset Password</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Subscription Management -->
<div class="card shadow-sm">
<div class="card-header">
<h4 class="mb-0">All Subscriptions</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Subscription</th>
<th>Cost</th>
<th>Renewal Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($subscriptions as $sub): ?>
<tr>
<td><?php echo htmlspecialchars($sub['user_name']); ?></td>
<td><?php echo htmlspecialchars($sub['name']); ?></td>
<td>$<?php echo number_format($sub['cost'], 2); ?></td>
<td><?php echo htmlspecialchars($sub['renewal_date']); ?></td>
<td>
<button class="btn btn-sm btn-outline-secondary edit-btn"
data-id="<?php echo $sub['id']; ?>"
data-name="<?php echo htmlspecialchars($sub['name']); ?>"
data-cost="<?php echo $sub['cost']; ?>"
data-renewal_date="<?php echo $sub['renewal_date']; ?>"
data-category="<?php echo htmlspecialchars($sub['category']); ?>"
data-frequency="<?php echo htmlspecialchars($sub['frequency']); ?>"
data-bs-toggle="modal" data-bs-target="#editSubscriptionModal">Edit</button>
<form method="POST" style="display: inline-block;" onsubmit="return confirm('Are you sure you want to delete this subscription?');">
<input type="hidden" name="subscription_id" value="<?php echo $sub['id']; ?>">
<button type="submit" name="delete_subscription" class="btn btn-sm btn-outline-danger">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Edit Subscription Modal (for Admin) -->
<div class="modal fade" id="editSubscriptionModal" tabindex="-1" aria-labelledby="editSubscriptionModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editSubscriptionModalLabel">Edit Subscription</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" id="edit_subscription_id" name="subscription_id">
<div class="mb-3">
<label for="edit_name" class="form-label">Subscription Name</label>
<input type="text" class="form-control" id="edit_name" name="name" required>
</div>
<div class="mb-3">
<label for="edit_cost" class="form-label">Monthly Cost (USD)</label>
<input type="number" step="0.01" class="form-control" id="edit_cost" name="cost" required>
</div>
<div class="mb-3">
<label for="edit_renewal_date" class="form-label">Next Renewal Date</label>
<input type="date" class="form-control" id="edit_renewal_date" name="renewal_date" required>
</div>
<div class="mb-3">
<label for="edit_category" class="form-label">Category</label>
<input type="text" class="form-control" id="edit_category" name="category" placeholder="e.g., Streaming, Software">
</div>
<div class="mb-3">
<label for="edit_frequency" class="form-label">Frequency</label>
<select class="form-select" id="edit_frequency" name="frequency">
<option>Monthly</option>
<option>Yearly</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="edit_subscription" class="btn btn-primary">Save Changes</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var editSubscriptionModal = document.getElementById('editSubscriptionModal');
editSubscriptionModal.addEventListener('show.bs.modal', function (event) {
var button = event.relatedTarget;
var id = button.getAttribute('data-id');
var name = button.getAttribute('data-name');
var cost = button.getAttribute('data-cost');
var renewal_date = button.getAttribute('data-renewal_date');
var category = button.getAttribute('data-category');
var frequency = button.getAttribute('data-frequency');
var modalTitle = editSubscriptionModal.querySelector('.modal-title');
var modalBodyInputId = editSubscriptionModal.querySelector('#edit_subscription_id');
var modalBodyInputName = editSubscriptionModal.querySelector('#edit_name');
var modalBodyInputCost = editSubscriptionModal.querySelector('#edit_cost');
var modalBodyInputRenewalDate = editSubscriptionModal.querySelector('#edit_renewal_date');
var modalBodyInputCategory = editSubscriptionModal.querySelector('#edit_category');
var modalBodyInputFrequency = editSubscriptionModal.querySelector('#edit_frequency');
modalTitle.textContent = 'Edit ' + name;
modalBodyInputId.value = id;
modalBodyInputName.value = name;
modalBodyInputCost.value = cost;
modalBodyInputRenewalDate.value = renewal_date;
modalBodyInputCategory.value = category;
modalBodyInputFrequency.value = frequency;
});
});
</script>
</body>
</html>

27
assets/css/custom.css Normal file
View File

@ -0,0 +1,27 @@
/* Custom Styles */
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.hero-section {
margin-top: 5rem;
margin-bottom: 5rem;
}
.cta-button {
padding: 0.75rem 1.5rem;
font-size: 1.25rem;
font-weight: 500;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.cta-button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.footer {
background-color: #f8f9fa;
}

1
assets/js/main.js Normal file
View File

@ -0,0 +1 @@
// Main javascript file

273
dashboard.php Normal file
View File

@ -0,0 +1,273 @@
<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: /login.php");
exit;
}
$userId = $_SESSION['user_id'];
$db = db();
// Handle Add/Edit/Delete Actions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Add Subscription
if (isset($_POST['add_subscription'])) {
$name = $_POST['name'];
$cost = $_POST['cost'];
$renewal_date = $_POST['renewal_date'];
$category = $_POST['category'];
$frequency = $_POST['frequency'];
$stmt = $db->prepare("INSERT INTO subscriptions (user_id, name, cost, renewal_date, category, frequency) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$userId, $name, $cost, $renewal_date, $category, $frequency]);
}
// Edit Subscription
elseif (isset($_POST['edit_subscription'])) {
$subscription_id = $_POST['subscription_id'];
$name = $_POST['name'];
$cost = $_POST['cost'];
$renewal_date = $_POST['renewal_date'];
$category = $_POST['category'];
$frequency = $_POST['frequency'];
$stmt = $db->prepare("UPDATE subscriptions SET name = ?, cost = ?, renewal_date = ?, category = ?, frequency = ? WHERE id = ? AND user_id = ?");
$stmt->execute([$name, $cost, $renewal_date, $category, $frequency, $subscription_id, $userId]);
}
// Delete Subscription
elseif (isset($_POST['delete_subscription'])) {
$subscription_id = $_POST['subscription_id'];
$stmt = $db->prepare("DELETE FROM subscriptions WHERE id = ? AND user_id = ?");
$stmt->execute([$subscription_id, $userId]);
}
header("Location: dashboard.php"); // Redirect to avoid form resubmission
exit;
}
// Fetch Subscriptions and Calculate Total Spend
$stmt = $db->prepare("SELECT * FROM subscriptions WHERE user_id = ? ORDER BY renewal_date ASC");
$stmt->execute([$userId]);
$subscriptions = $stmt->fetchAll(PDO::FETCH_ASSOC);
$totalMonthlySpend = 0;
foreach ($subscriptions as $sub) {
$totalMonthlySpend += (float)$sub['cost'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Subscription Manager</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container-fluid">
<a class="navbar-brand" href="#">Subscription Manager</a>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<span class="navbar-text me-3">Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</span>
</li>
<li class="nav-item">
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-5">
<!-- Total Spend Card -->
<div class="row mb-4">
<div class="col-md-4">
<div class="card text-white" style="background: linear-gradient(45deg, #0D6EFD, #0DCAF0);">
<div class="card-body">
<h5 class="card-title">Total Monthly Spend</h5>
<p class="card-text fs-2 fw-bold">$<?php echo number_format($totalMonthlySpend, 2); ?></p>
</div>
</div>
</div>
</div>
<!-- Subscriptions Table -->
<div class="card shadow-sm">
<div class="card-header d-flex justify-content-between align-items-center">
<h4 class="mb-0">Your Subscriptions</h4>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addSubscriptionModal">Add Subscription</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Cost</th>
<th>Renewal Date</th>
<th>Category</th>
<th>Frequency</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($subscriptions)): ?>
<tr>
<td colspan="6" class="text-center">No subscriptions yet. Add one to get started!</td>
</tr>
<?php else: ?>
<?php foreach ($subscriptions as $sub): ?>
<tr>
<td><?php echo htmlspecialchars($sub['name']); ?></td>
<td>$<?php echo number_format($sub['cost'], 2); ?></td>
<td><?php echo htmlspecialchars($sub['renewal_date']); ?></td>
<td><?php echo htmlspecialchars($sub['category']); ?></td>
<td><?php echo htmlspecialchars($sub['frequency']); ?></td>
<td>
<button class="btn btn-sm btn-outline-secondary edit-btn"
data-id="<?php echo $sub['id']; ?>"
data-name="<?php echo htmlspecialchars($sub['name']); ?>"
data-cost="<?php echo $sub['cost']; ?>"
data-renewal_date="<?php echo $sub['renewal_date']; ?>"
data-category="<?php echo htmlspecialchars($sub['category']); ?>"
data-frequency="<?php echo htmlspecialchars($sub['frequency']); ?>"
data-bs-toggle="modal" data-bs-target="#editSubscriptionModal">Edit</button>
<form method="POST" style="display: inline-block;" onsubmit="return confirm('Are you sure you want to delete this subscription?');">
<input type="hidden" name="subscription_id" value="<?php echo $sub['id']; ?>">
<button type="submit" name="delete_subscription" class="btn btn-sm btn-outline-danger">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Add Subscription Modal -->
<div class="modal fade" id="addSubscriptionModal" tabindex="-1" aria-labelledby="addSubscriptionModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addSubscriptionModalLabel">Add New Subscription</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="name" class="form-label">Subscription Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="cost" class="form-label">Monthly Cost (USD)</label>
<input type="number" step="0.01" class="form-control" id="cost" name="cost" required>
</div>
<div class="mb-3">
<label for="renewal_date" class="form-label">Next Renewal Date</label>
<input type="date" class="form-control" id="renewal_date" name="renewal_date" required>
</div>
<div class="mb-3">
<label for="category" class="form-label">Category</label>
<input type="text" class="form-control" id="category" name="category" placeholder="e.g., Streaming, Software">
</div>
<div class="mb-3">
<label for="frequency" class="form-label">Frequency</label>
<select class="form-select" id="frequency" name="frequency">
<option>Monthly</option>
<option>Yearly</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="add_subscription" class="btn btn-primary">Save Subscription</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Subscription Modal -->
<div class="modal fade" id="editSubscriptionModal" tabindex="-1" aria-labelledby="editSubscriptionModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editSubscriptionModalLabel">Edit Subscription</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST">
<div class="modal-body">
<input type="hidden" id="edit_subscription_id" name="subscription_id">
<div class="mb-3">
<label for="edit_name" class="form-label">Subscription Name</label>
<input type="text" class="form-control" id="edit_name" name="name" required>
</div>
<div class="mb-3">
<label for="edit_cost" class="form-label">Monthly Cost (USD)</label>
<input type="number" step="0.01" class="form-control" id="edit_cost" name="cost" required>
</div>
<div class="mb-3">
<label for="edit_renewal_date" class="form-label">Next Renewal Date</label>
<input type="date" class="form-control" id="edit_renewal_date" name="renewal_date" required>
</div>
<div class="mb-3">
<label for="edit_category" class="form-label">Category</label>
<input type="text" class="form-control" id="edit_category" name="category" placeholder="e.g., Streaming, Software">
</div>
<div class="mb-3">
<label for="edit_frequency" class="form-label">Frequency</label>
<select class="form-select" id="edit_frequency" name="frequency">
<option>Monthly</option>
<option>Yearly</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="edit_subscription" class="btn btn-primary">Save Changes</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var editSubscriptionModal = document.getElementById('editSubscriptionModal');
editSubscriptionModal.addEventListener('show.bs.modal', function (event) {
var button = event.relatedTarget;
var id = button.getAttribute('data-id');
var name = button.getAttribute('data-name');
var cost = button.getAttribute('data-cost');
var renewal_date = button.getAttribute('data-renewal_date');
var category = button.getAttribute('data-category');
var frequency = button.getAttribute('data-frequency');
var modalTitle = editSubscriptionModal.querySelector('.modal-title');
var modalBodyInputId = editSubscriptionModal.querySelector('#edit_subscription_id');
var modalBodyInputName = editSubscriptionModal.querySelector('#edit_name');
var modalBodyInputCost = editSubscriptionModal.querySelector('#edit_cost');
var modalBodyInputRenewalDate = editSubscriptionModal.querySelector('#edit_renewal_date');
var modalBodyInputCategory = editSubscriptionModal.querySelector('#edit_category');
var modalBodyInputFrequency = editSubscriptionModal.querySelector('#edit_frequency');
modalTitle.textContent = 'Edit ' + name;
modalBodyInputId.value = id;
modalBodyInputName.value = name;
modalBodyInputCost.value = cost;
modalBodyInputRenewalDate.value = renewal_date;
modalBodyInputCategory.value = category;
modalBodyInputFrequency.value = frequency;
});
});
</script>
</body>
</html>

20
db/migrate.php Normal file
View File

@ -0,0 +1,20 @@
<?php
require_once 'config.php';
try {
$pdo = db();
$migrations = glob(__DIR__ . '/migrations/*.sql');
sort($migrations);
foreach ($migrations as $migration) {
$sql = file_get_contents($migration);
$pdo->exec($sql);
echo "Executed migration: $migration\n";
}
echo "All migrations executed successfully.\n";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage());
}

View File

@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`role` ENUM('user', 'admin') NOT NULL DEFAULT 'user',
`is_active` BOOLEAN NOT NULL DEFAULT TRUE,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

View File

@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS `subscriptions` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`user_id` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`cost` DECIMAL(10, 2) NOT NULL,
`renewal_date` DATE,
`category` VARCHAR(255),
`frequency` ENUM('Monthly', 'Yearly') DEFAULT 'Monthly',
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
);

182
index.php
View File

@ -1,150 +1,44 @@
<?php <!DOCTYPE html>
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Style</title> <title><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Subscription Manager'); ?></title>
<?php <meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Stop losing money on unused subscriptions.'); ?>">
// Read project preview data from environment <meta property="og:title" content="<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Subscription Manager'); ?>">
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? ''; <meta property="og:description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Stop losing money on unused subscriptions.'); ?>">
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; <meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
?> <meta name="twitter:card" content="summary_large_image">
<?php if ($projectDescription): ?> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Meta description --> <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<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>
</head> </head>
<body> <body>
<main>
<div class="card"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<h1>Analyzing your requirements and generating your website…</h1> <div class="container">
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes"> <a class="navbar-brand" href="/"><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Subscription Manager'); ?></a>
<span class="sr-only">Loading…</span> <div class="d-flex">
</div> <a href="/login.php" class="btn btn-outline-primary me-2">Login</a>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p> <a href="/signup.php" class="btn btn-primary">Sign Up</a>
<p class="hint">This page will update automatically as the plan is implemented.</p> </div>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</div> </div>
</main> </nav>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC) <main class="container">
</footer> <div class="hero-section text-center py-5">
<h1 class="display-4 fw-bold">Stop Losing Money on Unused Subscriptions</h1>
<p class="lead col-lg-6 mx-auto">Track your recurring payments, manage your subscriptions, and take control of your spending with one simple tool.</p>
<a href="/signup.php" class="btn btn-lg btn-primary cta-button">Get Started Free</a>
</div>
</main>
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<span class="text-muted">&copy; <?php echo date("Y"); ?> <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Subscription Manager'); ?>. All rights reserved.</span>
</div>
</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> </body>
</html> </html>

113
login.php Normal file
View File

@ -0,0 +1,113 @@
<?php
require_once 'db/config.php';
session_start();
$errors = [];
if (isset($_SESSION['user_id'])) {
header("Location: /dashboard.php");
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email)) {
$errors[] = 'Email is required.';
}
if (empty($password)) {
$errors[] = 'Password is required.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
header("Location: /dashboard.php");
exit;
} else {
$errors[] = 'Invalid email or password.';
}
} catch (PDOException $e) {
$errors[] = "Database error: " . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">Subscription Manager</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="/signup.php">Sign Up</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h2 class="card-title text-center">Login to your Account</h2>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="login.php" method="POST">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
<div class="card-footer text-center">
<p>Don't have an account? <a href="signup.php">Sign up</a></p>
</div>
</div>
</div>
</div>
</div>
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<span class="text-muted">© <?php echo date("Y"); ?> Subscription Manager</span>
</div>
</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>

6
logout.php Normal file
View File

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: /login.php");
exit;

64
reset-password.php Normal file
View File

@ -0,0 +1,64 @@
<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: /login.php");
exit;
}
$adminId = $_SESSION['user_id'];
$db = db();
// Check if user is admin
$stmt = $db->prepare("SELECT role FROM users WHERE id = ?");
$stmt->execute([$adminId]);
$adminUser = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$adminUser || $adminUser['role'] !== 'admin') {
die("Access Denied.");
}
if (!isset($_GET['user_id'])) {
die("User ID not specified.");
}
$userIdToReset = $_GET['user_id'];
// Generate a new random password
$newPassword = bin2hex(random_bytes(8)); // 16 characters
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
// Update the user's password
$stmt = $db->prepare("UPDATE users SET password = ? WHERE id = ?");
$stmt->execute([$hashedPassword, $userIdToReset]);
// Fetch user name for display
$stmt = $db->prepare("SELECT name, email FROM users WHERE id = ?");
$stmt->execute([$userIdToReset]);
$userToReset = $stmt->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Reset - Admin</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="alert alert-success">
<h4 class="alert-heading">Password Reset Successful!</h4>
<p>The password for user <strong><?php echo htmlspecialchars($userToReset['name']); ?> (<?php echo htmlspecialchars($userToReset['email']); ?>)</strong> has been reset.</p>
<hr>
<p class="mb-0">New Password: <code><?php echo $newPassword; ?></code></p>
</div>
<div class="alert alert-danger">
<strong>Security Warning:</strong> This is a temporary and insecure password reset method. Please advise the user to change their password immediately. A proper, secure password reset flow (e.g., via email with a token) should be implemented.
</div>
<a href="/admin.php" class="btn btn-primary">Back to Admin Panel</a>
</div>
</body>
</html>

132
signup.php Normal file
View File

@ -0,0 +1,132 @@
<?php
require_once 'db/config.php';
$errors = [];
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$password_confirm = $_POST['password_confirm'] ?? '';
if (empty($name)) {
$errors[] = 'Name is required.';
}
if (empty($email)) {
$errors[] = 'Email is required.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email format.';
}
if (empty($password)) {
$errors[] = 'Password is required.';
}
if ($password !== $password_confirm) {
$errors[] = 'Passwords do not match.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = 'Email already exists.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
$stmt->execute([$name, $email, $hashed_password]);
// Start session and log the user in
session_start();
$_SESSION['user_id'] = $pdo->lastInsertId();
$_SESSION['user_name'] = $name;
header("Location: /dashboard.php");
exit;
}
} catch (PDOException $e) {
$errors[] = "Database error: " . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">Subscription Manager</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="/login.php">Login</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h2 class="card-title text-center">Create your Account</h2>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="signup.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="password_confirm" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Sign Up</button>
</div>
</form>
</div>
<div class="card-footer text-center">
<p>Already have an account? <a href="login.php">Log in</a></p>
</div>
</div>
</div>
</div>
</div>
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<span class="text-muted">© <?php echo date("Y"); ?> Subscription Manager</span>
</div>
</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>