diff --git a/add_food.php b/add_food.php new file mode 100644 index 0000000..e2a317d --- /dev/null +++ b/add_food.php @@ -0,0 +1,172 @@ + + +prepare("INSERT INTO food_log (food_name, calories) VALUES (?, ?)"); + $stmt->execute([$food_name, $calories]); + + $success_message = "Successfully added $food_name with $calories calories!"; + } catch (PDOException $e) { + $error_message = "Error: Could not record the food. " . $e->getMessage(); + } + } else { + $error_message = "Please fill out all fields correctly."; + } +} +?> + + + + + + Add Food - Calorie Tracker + + + + + + + + + + + +
+
+

Add Food

+
+ +
+ +
+ +

Redirecting you home...

+
+ + +
+ +
+ + +
+
+ + +
+ +
+
+ +
+
+ + +
+ +
+ + +
+ +
+ +
+
+ +
+ + +
+ + + + + diff --git a/add_sale.php b/add_sale.php deleted file mode 100644 index 826c058..0000000 --- a/add_sale.php +++ /dev/null @@ -1,117 +0,0 @@ - "Lean Beef Mince", - "image" => "assets/pasted-20251121-114725-33d5afd9.jpg", - "calories" => 150, - "protein" => 20, - "carbs" => 0, - "fat" => 7, - ], - [ - "name" => "Chicken Breast", - "image" => "assets/vm-shot-2025-11-21T11-47-05-928Z.jpg", - "calories" => 165, - "protein" => 31, - "carbs" => 0, - "fat" => 3.6, - ], - [ - "name" => "Salmon Fillet", - "image" => "https://images.pexels.com/photos/3296279/pexels-photo-3296279.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", - "calories" => 208, - "protein" => 20, - "carbs" => 0, - "fat" => 13, - ], - [ - "name" => "Broccoli", - "image" => "https://images.pexels.com/photos/4057737/pexels-photo-4057737.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", - "calories" => 55, - "protein" => 3.7, - "carbs" => 11, - "fat" => 0.6, - ], -]; - -require_once __DIR__ . '/db/config.php'; - -$success_message = ""; -$error_message = ""; - -if ($_SERVER["REQUEST_METHOD"] == "POST") { - if (!empty($_POST['product_name']) && !empty($_POST['quantity']) && is_numeric($_POST['quantity'])) { - try { - $product_name = $_POST['product_name']; - $quantity = (int)$_POST['quantity']; - - $pdo = db(); - $stmt = $pdo->prepare("INSERT INTO sales (product_name, quantity) VALUES (?, ?)"); - $stmt->execute([$product_name, $quantity]); - - $success_message = "Successfully added $quantity sale(s) for $product_name!"; - } catch (PDOException $e) { - $error_message = "Error: Could not record the sale. " . $e->getMessage(); - } - } else { - $error_message = "Please fill out all fields correctly."; - } -} -?> - - - - - - Add Sale - Sales Tracker - - - - - - - -
-
- -

Add a New Sale

-
- -
- -
- -
- - - -
- -
- - -
-
- - -
- -
- - -
- -
- -
-
-
-
- - - diff --git a/assets/css/custom.css b/assets/css/custom.css index 506b198..77d42e4 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -214,3 +214,48 @@ body { main.p-3 { padding-bottom: 100px !important; /* Space for bottom nav */ } + +.food-search-container { + position: relative; +} + +#search_results { + position: absolute; + top: 100%; + left: 0; + right: 0; + background: #1f1f3d; + border: 1px solid rgba(255, 255, 255, 0.2); + border-top: none; + border-radius: 0 0 15px 15px; + z-index: 1000; + max-height: 300px; + overflow-y: auto; +} + +.search-results-list { + list-style: none; + padding: 0; + margin: 0; +} + +.search-results-list li { + padding: 15px; + border-bottom: 1px solid rgba(255, 255, 255, 0.1); + cursor: pointer; + transition: background-color 0.2s; +} + +.search-results-list li:last-child { + border-bottom: none; +} + +.search-results-list li:hover { + background-color: rgba(255, 255, 255, 0.1); +} + +.search-results-list li span { + color: #aaa; + font-size: 0.9em; +} + diff --git a/assets/pasted-20251121-115632-d3e25129.png b/assets/pasted-20251121-115632-d3e25129.png new file mode 100644 index 0000000..a3ef0e7 Binary files /dev/null and b/assets/pasted-20251121-115632-d3e25129.png differ diff --git a/assets/pasted-20251121-121911-9a3aea89.png b/assets/pasted-20251121-121911-9a3aea89.png new file mode 100644 index 0000000..7bccab2 Binary files /dev/null and b/assets/pasted-20251121-121911-9a3aea89.png differ diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..009b98a --- /dev/null +++ b/dashboard.php @@ -0,0 +1,133 @@ +query("SELECT food_name, calories, sale_date FROM food_log ORDER BY sale_date DESC"); + $food_log_data = $stmt->fetchAll(); + + if ($food_log_data) { + $total_foods = count($food_log_data); + $total_calories = array_sum(array_column($food_log_data, 'calories')); + + foreach ($food_log_data as $food) { + if (!isset($calories_by_food[$food['food_name']])) { + $calories_by_food[$food['food_name']] = 0; + } + $calories_by_food[$food['food_name']] += $food['calories']; + } + arsort($calories_by_food); + } +} catch (PDOException $e) { + $error_message = "Error fetching food log data: " . $e->getMessage(); +} +?> + + + + + + Dashboard - Calorie Tracker + + + + + + + +
+
+ +

Dashboard

+
+ +
+ +
+ +
+ +
+ No food logged yet. Add a food item to see your stats here. +
+ +
+
+ + Total Foods +
+
+ + Total Calories +
+
+ +

Calories by Food

+
+ + + + + + + + + $calories): ?> + + + + + + +
FoodTotal Calories
+
+ +

Recent Entries

+
+ + + + + + + + + + + + + + + + + +
FoodCaloriesDate
+
+ +
+
+ + + + + + diff --git a/index.php b/index.php index 8254c90..d0a1758 100644 --- a/index.php +++ b/index.php @@ -12,7 +12,7 @@ $products = [ ['id' => 8, 'name' => 'Almonds', 'calories' => 579, 'protein' => 21, 'carbs' => 22, 'fat' => 49], ]; -$projectName = $_SERVER['PROJECT_NAME'] ?? 'Sales & Nutrition'; +$projectName = $_SERVER['PROJECT_NAME'] ?? 'Calorie Tracker'; ?> @@ -22,7 +22,7 @@ $projectName = $_SERVER['PROJECT_NAME'] ?? 'Sales & Nutrition'; <?= htmlspecialchars($projectName) ?> @@ -52,7 +52,7 @@ $projectName = $_SERVER['PROJECT_NAME'] ?? 'Sales & Nutrition';
-

Products

+

Food Library

Home - + - Add Sale + Add Food - + - Stats + Dashboard
diff --git a/stats.php b/stats.php deleted file mode 100644 index d81e5c2..0000000 --- a/stats.php +++ /dev/null @@ -1,133 +0,0 @@ -query("SELECT product_name, quantity, sale_date FROM sales ORDER BY sale_date DESC"); - $sales_data = $stmt->fetchAll(); - - if ($sales_data) { - $total_sales = count($sales_data); - $total_quantity = array_sum(array_column($sales_data, 'quantity')); - - foreach ($sales_data as $sale) { - if (!isset($sales_by_product[$sale['product_name']])) { - $sales_by_product[$sale['product_name']] = 0; - } - $sales_by_product[$sale['product_name']] += $sale['quantity']; - } - arsort($sales_by_product); - } -} catch (PDOException $e) { - $error_message = "Error fetching sales data: " . $e->getMessage(); -} -?> - - - - - - Sales Stats - Sales Tracker - - - - - - - -
-
- -

Sales Statistics

-
- -
- -
- -
- -
- No sales data yet. Add a sale to see statistics here. -
- -
-
- - Total Sales -
-
- - Items Sold -
-
- -

Sales by Product

-
- - - - - - - - - $quantity): ?> - - - - - - -
ProductTotal Quantity Sold
-
- -

Recent Sales

-
- - - - - - - - - - - - - - - - - -
ProductQuantityDate
-
- -
-
- - - - - -