diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..bec4c3c --- /dev/null +++ b/admin.php @@ -0,0 +1,277 @@ +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); + +?> + + + + + + Admin Panel - Subscription Manager + + + + + + + +
+ +
+
+
+
+
Total Users
+

+
+
+
+
+
+
+
Total Subscriptions
+

+
+
+
+
+
+
+
Total Value Tracked
+

$

+
+
+
+
+ + +
+
+

User Management

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
NameEmailRoleActiveJoinedActions
+ + Reset Password +
+
+
+
+ + +
+
+

All Subscriptions

+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
UserSubscriptionCostRenewal DateActions
$ + +
+ + +
+
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..d2d5d75 --- /dev/null +++ b/assets/css/custom.css @@ -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; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..e6d207e --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1 @@ +// Main javascript file diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..bb6e243 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,273 @@ +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']; +} + +?> + + + + + + Dashboard - Subscription Manager + + + + + + + +
+ +
+
+
+
+
Total Monthly Spend
+

$

+
+
+
+
+ + +
+
+

Your Subscriptions

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameCostRenewal DateCategoryFrequencyActions
No subscriptions yet. Add one to get started!
$ + +
+ + +
+
+
+
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..0ebd448 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,20 @@ +exec($sql); + echo "Executed migration: $migration\n"; + } + + echo "All migrations executed successfully.\n"; + +} catch (PDOException $e) { + die("Migration failed: " . $e->getMessage()); +} + diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..23e893f --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -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 +); \ No newline at end of file diff --git a/db/migrations/002_create_subscriptions_table.sql b/db/migrations/002_create_subscriptions_table.sql new file mode 100644 index 0000000..393b524 --- /dev/null +++ b/db/migrations/002_create_subscriptions_table.sql @@ -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 +); \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..494d0ff 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,44 @@ - - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Subscription Manager'); ?> + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
- + + +
+
+

Stop Losing Money on Unused Subscriptions

+

Track your recurring payments, manage your subscriptions, and take control of your spending with one simple tool.

+ Get Started Free +
+
+ + + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..9a1c512 --- /dev/null +++ b/login.php @@ -0,0 +1,113 @@ +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(); + } + } +} +?> + + + + + + Login + + + + + + +
+
+
+
+
+

Login to your Account

+ + +
+ +

+ +
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..099a240 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +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); + +?> + + + + + + Password Reset - Admin + + + +
+
+

Password Reset Successful!

+

The password for user () has been reset.

+
+

New Password:

+
+
+ Security Warning: 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. +
+ Back to Admin Panel +
+ + diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..3bfbd2f --- /dev/null +++ b/signup.php @@ -0,0 +1,132 @@ +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(); + } + } +} +?> + + + + + + Sign Up + + + + + + +
+
+
+
+
+

Create your Account

+ + +
+ +

+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+ + + + + + + \ No newline at end of file