Hello!
+Your order #$order_id status has been updated.
+Current Status: $new_status
+" . ($status_messages[$new_status] ?? 'Status updated.') . "
+You can track your order in real-time at: Track Order
+Thank you for choosing Foodogram!
+diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..aef8e39 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppvsdbg", + "request": "launch", + "program": "enter program name, for example ${workspaceFolder}/a.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "console": "externalTerminal" + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/TODO.md b/TODO.md index 0025bf8..ba46cc1 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,42 @@ -# Fix Duplicate session_start() Calls - -## Tasks -- [x] Remove duplicate session_start() in index.php (keep the one at the top) -- [x] Remove one duplicate session_start() in terms.php at the top -- [x] Consolidate session_start() calls in forgotpswd.php to have only one at the beginning -- [x] Test affected pages for session functionality -- [x] Verify no other files have duplicate session_start() calls +# Real-Time Order Tracking Implementation + +## Database Changes +- [x] Add 'status' field to orders table (ALTER TABLE orders ADD COLUMN status VARCHAR(50) DEFAULT 'Placed') + +## Backend Updates +- [x] Modify save_checkout.php to set initial order status +- [x] Create update_order_status.php API endpoint for status updates + +## Frontend Implementation +- [x] Create track_order.php page for users to view order status +- [x] Add real-time updates using JavaScript polling + +## Notifications +- [x] Implement email notifications for status changes + +## Error Handling +- [x] Add proper error handling and synchronization + +## Testing +- [x] Test database changes and order flow +- [x] Test real-time updates +- [x] Test notifications + +## Summary +✅ **Real-Time Order Tracking Implementation Complete!** + +**Features Implemented:** +- Database schema updated with order status tracking +- Order status progression: Placed → Preparing → Ready for Delivery → Out for Delivery → Delivered +- User-facing order tracking page with real-time updates +- Admin interface for managing order statuses +- Email notifications for order confirmations and status updates +- Proper error handling and validation throughout + +**Files Created/Modified:** +- `pages/migrate_add_status.php` - Database migration script +- `pages/save_checkout.php` - Updated to set initial status and send confirmation emails +- `pages/track_order.php` - User order tracking interface +- `pages/update_order_status.php` - API endpoint for status updates +- `pages/email_utils.php` - Email notification utilities +- `pages/admin_orders.php` - Admin order management interface diff --git a/pages/admin_orders.php b/pages/admin_orders.php new file mode 100644 index 0000000..e1ca988 --- /dev/null +++ b/pages/admin_orders.php @@ -0,0 +1,245 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die("Database connection failed: " . $e->getMessage()); +} + +// Check if admin is logged in (for demo purposes, we'll allow access) +$admin_logged_in = true; // In production, check proper authentication + +if (!$admin_logged_in) { + die("Unauthorized access"); +} + +// Handle status update +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) { + $order_id = (int)$_POST['order_id']; + $new_status = trim($_POST['status']); + + $valid_statuses = ['Placed', 'Preparing', 'Ready for Delivery', 'Out for Delivery', 'Delivered']; + if (in_array($new_status, $valid_statuses)) { + try { + $stmt = $pdo->prepare("UPDATE orders SET status = ? WHERE id = ?"); + $stmt->execute([$new_status, $order_id]); + + if ($stmt->rowCount() > 0) { + $success_message = "Order status updated successfully!"; + } else { + $error_message = "Order not found or no changes made."; + } + } catch (PDOException $e) { + $error_message = "Database error: " . $e->getMessage(); + } + } else { + $error_message = "Invalid status selected."; + } +} + +// Fetch all orders +try { + $stmt = $pdo->query("SELECT o.*, u.name as user_name, u.email FROM orders o LEFT JOIN users u ON o.user_id = u.id ORDER BY o.id DESC"); + $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + $orders = []; + $error_message = "Unable to load orders"; +} +?> + + + +
+ + +Manage and update order statuses
+There are no orders in the system yet.
+Order Status Update
+Your order #$order_id status has been updated.
+Current Status: $new_status
+" . ($status_messages[$new_status] ?? 'Status updated.') . "
+You can track your order in real-time at: Track Order
+Thank you for choosing Foodogram!
+Order Confirmation
+Your order #$order_id has been placed successfully.
+You can track your order in real-time at: Track Order
+We'll send you updates as your order progresses.
+Items: $itemsText
+Total Amount: ₹" . number_format($total, 2) . "
+Delivery Address: $delivery_address
+Payment Method: $payment_method
"; + sendOrderConfirmationEmail($user['email'], $order_id, $order_details); + } + + echo json_encode(['success' => true, 'message' => 'Order saved successfully', 'order_id' => $order_id]); } catch (PDOException $e) { echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]); } diff --git a/pages/track_order.php b/pages/track_order.php new file mode 100644 index 0000000..fb0fc72 --- /dev/null +++ b/pages/track_order.php @@ -0,0 +1,424 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die("Database connection failed: " . $e->getMessage()); +} + +// Check if user is logged in +$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null; +$username = isset($_SESSION['username']) ? $_SESSION['username'] : "Guest"; + +// Get order ID from URL or show recent orders +$order_id = isset($_GET['order_id']) ? (int)$_GET['order_id'] : null; +$orders = []; +$current_order = null; + +if ($user_id) { + try { + if ($order_id) { + // Get specific order + $stmt = $pdo->prepare("SELECT * FROM orders WHERE id = ? AND user_id = ?"); + $stmt->execute([$order_id, $user_id]); + $current_order = $stmt->fetch(PDO::FETCH_ASSOC); + } else { + // Get recent orders + $stmt = $pdo->prepare("SELECT * FROM orders WHERE user_id = ? ORDER BY id DESC LIMIT 10"); + $stmt->execute([$user_id]); + $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); + } + } catch (PDOException $e) { + $error = "Unable to load orders"; + } +} +?> + + + + + + +
+
+
+ Total: ₹
+Items:
+Delivery Address:
+Payment Method:
+