From 7d531ef9a4fc7002f7bb348fb2c19ae30b338ba0 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 11 Nov 2025 08:51:27 +0000 Subject: [PATCH] 1 --- admin.php | 221 ++++++++++++++++ assets/css/custom.css | 67 +++++ db/migrate.php | 20 ++ db/migrations/001_create_meals_table.sql | 9 + db/migrations/002_insert_sample_meals.sql | 17 ++ db/migrations/003_create_users_table.sql | 7 + db/migrations/004_add_role_to_users_table.sql | 1 + index.php | 245 +++++++----------- login.php | 105 ++++++++ logout.php | 6 + menu.php | 123 +++++++++ profile.php | 140 ++++++++++ promote_user.php | 28 ++ register.php | 119 +++++++++ 14 files changed, 963 insertions(+), 145 deletions(-) create mode 100644 admin.php create mode 100644 assets/css/custom.css create mode 100644 db/migrate.php create mode 100644 db/migrations/001_create_meals_table.sql create mode 100644 db/migrations/002_insert_sample_meals.sql create mode 100644 db/migrations/003_create_users_table.sql create mode 100644 db/migrations/004_add_role_to_users_table.sql create mode 100644 login.php create mode 100644 logout.php create mode 100644 menu.php create mode 100644 profile.php create mode 100644 promote_user.php create mode 100644 register.php diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..ecc9035 --- /dev/null +++ b/admin.php @@ -0,0 +1,221 @@ + 'Normal', 'V' => 'Vegetarian', 'G' => 'Vegan']; + return $types[$char] ?? 'Unknown'; +} + +$message = ''; +$error = ''; +$edit_meal = null; + +try { + $pdo = db(); + + // Handle Delete + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_id'])) { + $stmt = $pdo->prepare("DELETE FROM meals WHERE id = ?"); + $stmt->execute([$_POST['delete_id']]); + $message = 'Meal deleted successfully!'; + } + // Handle Add/Update + elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $day_of_week = $_POST['day_of_week'] ?? ''; + $meal_type = $_POST['meal_type'] ?? ''; + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? ''; + $id = $_POST['update_id'] ?? null; + + if (empty($day_of_week) || empty($meal_type) || empty($name)) { + $error = 'Please fill in all required fields (Day, Meal Type, Name).'; + } else { + if ($id) { + // Update + $stmt = $pdo->prepare("UPDATE meals SET day_of_week = ?, meal_type = ?, name = ?, description = ? WHERE id = ?"); + $stmt->execute([$day_of_week, $meal_type, $name, $description, $id]); + $message = 'Meal updated successfully!'; + } else { + // Insert + $stmt = $pdo->prepare("INSERT INTO meals (day_of_week, meal_type, name, description) VALUES (?, ?, ?, ?)"); + $stmt->execute([$day_of_week, $meal_type, $name, $description]); + $message = 'Meal added successfully!'; + } + } + } + + // Handle Edit - Fetch meal to edit + if (isset($_GET['edit_id'])) { + $stmt = $pdo->prepare("SELECT * FROM meals WHERE id = ?"); + $stmt->execute([$_GET['edit_id']]); + $edit_meal = $stmt->fetch(PDO::FETCH_ASSOC); + } + + // Fetch all meals for display + $stmt = $pdo->query("SELECT * FROM meals ORDER BY FIELD(day_of_week, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'), meal_type"); + $meals = $stmt->fetchAll(PDO::FETCH_ASSOC); + +} catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + $meals = []; +} + +?> + + + + + + Admin - Meal Management + + + + + + + + + + + +
+

Meal Management

+ + +
+ + +
+ + +
+
+ +
+
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ + + Cancel + +
+
+
+ +
+
+ Existing Meals +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
DayTypeNameDescriptionActions
No meals found. Add one above!
+ Edit +
+ + +
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..baad9aa --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,67 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Lato:wght@400;700&display=swap'); + +:root { + --primary-color: #4A90E2; + --secondary-color: #50E3C2; + --background-color: #F4F7F6; + --surface-color: #FFFFFF; + --text-color: #333333; + --text-muted-color: #6c757d; + --border-radius: 0.5rem; +} + +body { + font-family: 'Lato', sans-serif; + background-color: var(--background-color); + color: var(--text-color); +} + +h1, h2, h3, h4, h5, h6, .navbar-brand, .fw-bold { + font-family: 'Poppins', sans-serif; +} + +.btn-primary { + background-color: var(--primary-color); + border-color: var(--primary-color); + transition: all 0.3s ease; +} + +.btn-primary:hover { + transform: translateY(-2px); + box-shadow: 0 4px 12px rgba(0,0,0,0.1); +} + +.text-primary { + color: var(--primary-color) !important; +} + +.hero-section { + background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%); + padding: 6rem 0; + margin-bottom: 3rem; +} + +.navbar-brand { + color: var(--primary-color) !important; +} + +.nav-link.active { + font-weight: bold; + color: var(--primary-color) !important; +} + +.day-card { + border-radius: var(--border-radius); + transition: transform 0.3s ease, box-shadow 0.3s ease; +} + +.day-card:hover { + transform: translateY(-5px); + box-shadow: 0 8px 25px rgba(0,0,0,0.08); +} + +.meal-card { + background-color: #f8f9fa; + border-radius: var(--border-radius); + border: 1px solid #e9ecef; +} diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..2687a99 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,20 @@ +exec($sql); + echo "Successfully executed migration: " . basename($file) . "\n"; + } catch (PDOException $e) { + echo "Error executing migration: " . basename($file) . " - " . $e->getMessage() . "\n"; + } +} + diff --git a/db/migrations/001_create_meals_table.sql b/db/migrations/001_create_meals_table.sql new file mode 100644 index 0000000..c147b9e --- /dev/null +++ b/db/migrations/001_create_meals_table.sql @@ -0,0 +1,9 @@ + +CREATE TABLE IF NOT EXISTS meals ( + id INT AUTO_INCREMENT PRIMARY KEY, + day_of_week VARCHAR(20) NOT NULL, + meal_type CHAR(1) NOT NULL, + name VARCHAR(255) NOT NULL, + description TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/migrations/002_insert_sample_meals.sql b/db/migrations/002_insert_sample_meals.sql new file mode 100644 index 0000000..e261220 --- /dev/null +++ b/db/migrations/002_insert_sample_meals.sql @@ -0,0 +1,17 @@ +-- Sample Meals +INSERT INTO `meals` (`day_of_week`, `name`, `description`, `meal_type`) VALUES +('Monday', 'Spaghetti Bolognese', 'Classic Italian meat sauce with pasta', 'N'), +('Monday', 'Lentil Shepherd''s Pie', 'A hearty vegetarian shepherd''s pie with a lentil filling.', 'V'), +('Monday', 'Mushroom Risotto', 'Creamy risotto with fresh mushrooms', 'G'), +('Tuesday', 'Chicken Teriyaki', 'Grilled chicken with a sweet and savory teriyaki sauce', 'N'), +('Tuesday', 'Black Bean Burgers', 'Homemade black bean burgers on a whole wheat bun.', 'V'), +('Tuesday', 'Quinoa Salad', 'Healthy and refreshing quinoa salad with mixed vegetables', 'G'), +('Wednesday', 'Beef Tacos', 'Spicy ground beef in a crispy taco shell', 'N'), +('Wednesday', 'Spinach and Feta Stuffed Peppers', 'Bell peppers stuffed with a savory mixture of spinach, feta cheese, and rice.', 'V'), +('Wednesday', 'Vegetable Curry', 'A flavorful curry with a variety of fresh vegetables', 'G'), +('Thursday', 'Fish and Chips', 'Classic battered fish with a side of french fries', 'N'), +('Thursday', 'Eggplant Parmesan', 'Slices of breaded eggplant, fried and layered with cheese and tomato sauce.', 'V'), +('Thursday', 'Sweet Potato and Black Bean Burritos', 'Hearty burritos filled with a sweet and savory mixture.', 'G'), +('Friday', 'Pizza Salami', 'Classic pizza with tomato sauce, cheese, and salami', 'N'), +('Friday', 'Four Cheese Pizza', 'A delicious pizza topped with four different kinds of cheese.', 'V'), +('Friday', 'Vegan Pizza', 'Pizza with a variety of fresh vegetables and vegan cheese', 'G'); \ No newline at end of file diff --git a/db/migrations/003_create_users_table.sql b/db/migrations/003_create_users_table.sql new file mode 100644 index 0000000..355b1be --- /dev/null +++ b/db/migrations/003_create_users_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + email VARCHAR(100) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/migrations/004_add_role_to_users_table.sql b/db/migrations/004_add_role_to_users_table.sql new file mode 100644 index 0000000..5115ee0 --- /dev/null +++ b/db/migrations/004_add_role_to_users_table.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN role VARCHAR(50) NOT NULL DEFAULT 'user'; diff --git a/index.php b/index.php index 7205f3d..5e0d33e 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,105 @@ - - + + - - - New Style - - - - - - - - - - - - - - - - - - - + + + eMenza - School Meal Management + + + + + + + + + + + + + + -
-
-

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

-
-
- + + + +
+
+ +

Welcome, !

+ +

Welcome to eMenza

+ +

The future of school meal management is here. Simple, transparent, and efficient.

+ View This Week's Menu +
+
+ +
+
+
+
+
+
+ +

View Menus

+

Easily check the upcoming weekly menu with detailed descriptions and allergen info.

+
+
+
+
+
+
+ +

Order Ahead

+

Pre-order your meals for the week with just a few clicks. Cancel anytime before the deadline.

+
+
+
+
+
+
+ +

Easy Payments

+

Manage your balance and pay for your meals securely online or in person.

+
+
+
+
+
+
+ + + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..8a1c258 --- /dev/null +++ b/login.php @@ -0,0 +1,105 @@ +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['role'] = $user['role']; + $_SESSION['username'] = $user['username']; + header("Location: index.php"); + exit; + } else { + $error = 'Invalid email or password.'; + } + } catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Login - eMenza + + + + + + + + + + +
+

Login

+ + +
+ + +
+
+
+
+ + +
+
+ + +
+ +
+
+
+
+ + + + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..f83284d --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + 'Normal', 'V' => 'Vegetarian', 'G' => 'Vegan']; + return $types[$char] ?? 'Unknown'; +} + +$menu = []; +$error = ''; + +try { + $pdo = db(); + $stmt = $pdo->query("SELECT * FROM meals ORDER BY FIELD(day_of_week, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'), meal_type"); + $meals = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($meals as $meal) { + $menu[$meal['day_of_week']][] = [ + 'name' => $meal['name'], + 'option' => getMealTypeName($meal['meal_type']), + 'description' => $meal['description'], + 'allergens' => [] // Placeholder for allergens + ]; + } +} catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); +} +?> + + + + + + Weekly Menu - eMenza + + + + + + + + + + + + + + + + + + + +
+
+

This Week's Menu

+

Here are the meal options for the upcoming week. Orders can be placed until 10:00 AM for the next day.

+
+ +
+ $options): ?> +
+
+
+

+
+
+ +
+
+
+
:
+
+

+
+ + + +
+
+
+ +
+
+
+ +
+
+ + + + + + + diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..a1deb05 --- /dev/null +++ b/profile.php @@ -0,0 +1,140 @@ +prepare("SELECT * FROM users WHERE id = ?"); + $stmt->execute([$_SESSION['user_id']]); + $user = $stmt->fetch(); + + if ($user && password_verify($old_password, $user['password'])) { + $hashed_password = password_hash($new_password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("UPDATE users SET password = ? WHERE id = ?"); + $stmt->execute([$hashed_password, $_SESSION['user_id']]); + $message = 'Password changed successfully!'; + } else { + $error = 'Incorrect old password.'; + } + } catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + } + } +} + + +try { + $pdo = db(); + $stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); + $stmt->execute([$_SESSION['user_id']]); + $user = $stmt->fetch(); +} catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); +} + +?> + + + + + + Profile - eMenza + + + + + + + + + + +
+

Your Profile

+ + +
+ + +
+ + +
+
Your Information
+
+

Username:

+

Email:

+
+
+ +
+
Change Password
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + + + + + diff --git a/promote_user.php b/promote_user.php new file mode 100644 index 0000000..e86e78f --- /dev/null +++ b/promote_user.php @@ -0,0 +1,28 @@ +\n"); +} + +$email = $argv[1]; + +try { + $pdo = db(); + + $stmt = $pdo->prepare("UPDATE users SET role = 'admin' WHERE email = ?"); + $stmt->execute([$email]); + + if ($stmt->rowCount() > 0) { + echo "User with email '{$email}' has been promoted to admin.\n"; + } else { + echo "No user found with email '{$email}'.\n"; + } +} catch (PDOException $e) { + die("Database error: " . $e->getMessage() . "\n"); +} + diff --git a/register.php b/register.php new file mode 100644 index 0000000..a5488d8 --- /dev/null +++ b/register.php @@ -0,0 +1,119 @@ +prepare("SELECT * FROM users WHERE username = ? OR email = ?"); + $stmt->execute([$username, $email]); + if ($stmt->fetch()) { + $error = 'Username or email already exists.'; + } else { + // Hash password and insert user + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"); + $stmt->execute([$username, $email, $hashed_password]); + $message = 'Registration successful! You can now log in.'; + } + } catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Register - eMenza + + + + + + + + + + +
+

Create an Account

+ + +
+ + +
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + + + + +