123 lines
5.6 KiB
PHP
123 lines
5.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Handle activity deletion
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['activity_id_to_delete'])) {
|
|
$activityIdToDelete = $_POST['activity_id_to_delete'];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("DELETE FROM activities WHERE id = ?");
|
|
$stmt->execute([$activityIdToDelete]);
|
|
} catch (PDOException $e) {
|
|
error_log("Database error: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// Handle new activity creation
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['activity_name'])) {
|
|
$activityName = trim($_POST['activity_name']);
|
|
$activityDate = trim($_POST['activity_date']);
|
|
$activityNotes = trim($_POST['activity_notes']);
|
|
|
|
if (!empty($activityName)) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO activities (name, activity_date, notes) VALUES (?, ?, ?)");
|
|
$stmt->execute([$activityName, $activityDate, $activityNotes]);
|
|
} catch (PDOException $e) {
|
|
error_log("Database error: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch all activities
|
|
$activities = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT id, name, activity_date, notes FROM activities ORDER BY activity_date DESC, created_at DESC");
|
|
$activities = $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>Activity 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">Activity Planner</h1>
|
|
<p class="text-center text-gray-500">Plan your winter adventures.</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 Activity</h2>
|
|
<form method="POST" action="planner.php" class="space-y-4">
|
|
<div>
|
|
<label for="activity_name" class="block text-sm font-medium text-gray-700">Activity Name</label>
|
|
<input type="text" id="activity_name" name="activity_name" 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>
|
|
<label for="activity_date" class="block text-sm font-medium text-gray-700">Date</label>
|
|
<input type="date" id="activity_date" name="activity_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="activity_notes" class="block text-sm font-medium text-gray-700">Notes</label>
|
|
<textarea id="activity_notes" name="activity_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 Activity</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div>
|
|
<h2 class="text-2xl font-bold mb-4">Planned Activities</h2>
|
|
<div class="space-y-4">
|
|
<?php if (empty($activities)): ?>
|
|
<p class="text-gray-500">No activities planned yet.</p>
|
|
<?php else: ?>
|
|
<?php foreach ($activities as $activity): ?>
|
|
<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($activity['name']); ?></h3>
|
|
<p class="text-sm text-gray-600"><?php echo htmlspecialchars($activity['activity_date']); ?></p>
|
|
<p class="text-sm mt-1"><?php echo htmlspecialchars($activity['notes']); ?></p>
|
|
</div>
|
|
<form method="POST" action="planner.php">
|
|
<input type="hidden" name="activity_id_to_delete" value="<?php echo $activity['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>
|