130 lines
6.0 KiB
PHP
130 lines
6.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Handle travel plan deletion
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['plan_id_to_delete'])) {
|
|
$planIdToDelete = $_POST['plan_id_to_delete'];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("DELETE FROM travel_plans WHERE id = ?");
|
|
$stmt->execute([$planIdToDelete]);
|
|
} catch (PDOException $e) {
|
|
error_log("Database error: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// Handle new travel plan creation
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['destination'])) {
|
|
$destination = trim($_POST['destination']);
|
|
$startDate = trim($_POST['start_date']);
|
|
$endDate = trim($_POST['end_date']);
|
|
$notes = trim($_POST['notes']);
|
|
|
|
if (!empty($destination)) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO travel_plans (destination, start_date, end_date, notes) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$destination, $startDate, $endDate, $notes]);
|
|
} catch (PDOException $e) {
|
|
error_log("Database error: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch all travel plans
|
|
$plans = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT id, destination, start_date, end_date, notes FROM travel_plans ORDER BY start_date DESC, created_at DESC");
|
|
$plans = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
error_log("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>Travel Planner</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Lora:wght@400;700&family=Nunito:wght@400;700&display=swap" rel="stylesheet">
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<style>
|
|
body {
|
|
font-family: 'Nunito', sans-serif;
|
|
background-color: #FFFBEB;
|
|
color: #374151;
|
|
}
|
|
h1, h2, h3, h4, h5, h6 {
|
|
font-family: 'Lora', serif;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="flex flex-col items-center justify-center min-h-screen">
|
|
|
|
<div class="w-full max-w-4xl mx-auto bg-white rounded-xl shadow-lg p-6">
|
|
<div class="mb-6">
|
|
<h1 class="text-4xl font-bold text-center text-gray-800">Travel Planner</h1>
|
|
<p class="text-center text-gray-500">Organize your upcoming trips.</p>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
|
|
<div>
|
|
<h2 class="text-2xl font-bold mb-4">Add New Travel Plan</h2>
|
|
<form method="POST" action="travel.php" class="space-y-4">
|
|
<div>
|
|
<label for="destination" class="block text-sm font-medium text-gray-700">Destination</label>
|
|
<input type="text" id="destination" name="destination" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-yellow-500 focus:ring-yellow-500 sm:text-sm p-2">
|
|
</div>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label for="start_date" class="block text-sm font-medium text-gray-700">Start Date</label>
|
|
<input type="date" id="start_date" name="start_date" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-yellow-500 focus:ring-yellow-500 sm:text-sm p-2">
|
|
</div>
|
|
<div>
|
|
<label for="end_date" class="block text-sm font-medium text-gray-700">End Date</label>
|
|
<input type="date" id="end_date" name="end_date" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-yellow-500 focus:ring-yellow-500 sm:text-sm p-2">
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label for="notes" class="block text-sm font-medium text-gray-700">Notes</label>
|
|
<textarea id="notes" name="notes" rows="3" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-yellow-500 focus:ring-yellow-500 sm:text-sm p-2"></textarea>
|
|
</div>
|
|
<div>
|
|
<button type="submit" class="w-full px-4 py-2 bg-yellow-500 text-white font-bold rounded-md hover:bg-yellow-600">Add Travel Plan</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div>
|
|
<h2 class="text-2xl font-bold mb-4">Your Travel Plans</h2>
|
|
<div class="space-y-4">
|
|
<?php if (empty($plans)): ?>
|
|
<p class="text-gray-500">No travel plans yet.</p>
|
|
<?php else: ?>
|
|
<?php foreach ($plans as $plan): ?>
|
|
<div class="p-4 bg-gray-50 rounded-lg shadow flex justify-between items-start">
|
|
<div>
|
|
<h3 class="font-bold text-lg"><?php echo htmlspecialchars($plan['destination']); ?></h3>
|
|
<p class="text-sm text-gray-600"><?php echo htmlspecialchars($plan['start_date']); ?> to <?php echo htmlspecialchars($plan['end_date']); ?></p>
|
|
<p class="text-sm mt-1"><?php echo htmlspecialchars($plan['notes']); ?></p>
|
|
</div>
|
|
<form method="POST" action="travel.php">
|
|
<input type="hidden" name="plan_id_to_delete" value="<?php echo $plan['id']; ?>">
|
|
<button type="submit" class="text-red-500 hover:text-red-700 font-semibold">Delete</button>
|
|
</form>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="text-center mt-8">
|
|
<a href="index.php" class="text-yellow-500 hover:underline">Back to Home</a>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|