Mackey30/deepsite-project-w4btd
0
1<?php2// Database connection3$host = 'localhost';4$dbname = 'farmflow';5$username = 'root';6$password = '';7 8try {9 $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);10 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);11} catch(PDOException $e) {12 $pdo = null;13}14 15// Fetch all tasks16$tasks = [];17if ($pdo) {18 try {19 $stmt = $pdo->query("SELECT * FROM tasks ORDER BY due_date ASC, priority DESC");20 $tasks = $stmt ? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];21 } catch(PDOException $e) {22 $tasks = [];23 }24}25 26// Sample tasks if none exist27if (empty($tasks)) {28 $tasks = [29 ['id' => 1, 'title' => 'Check drip irrigation lines', 'description' => 'Inspect all drip lines in Zone 2 for clogs or leaks', 'due_date' => date('Y-m-d'), 'priority' => 'high', 'status' => 'pending', 'assigned_to' => 'John'],30 ['id' => 2, 'title' => 'Calibrate moisture sensors', 'description' => 'Recalibrate sensors A2 and A3 in Zone 3', 'due_date' => date('Y-m-d', strtotime('+1 day')), 'priority' => 'medium', 'status' => 'in_progress', 'assigned_to' => 'Sarah'],31 ['id' => 3, 'title' => 'Review weekly water usage', 'description' => 'Analyze water consumption reports', 'due_date' => date('Y-m-d', strtotime('+2 days')), 'priority' => 'low', 'status' => 'pending', 'assigned_to' => 'John'],32 ['id' => 4, 'title' => 'Fertilizer application - Zone 2', 'description' => 'Apply nitrogen fertilizer to vegetable crops', 'due_date' => date('Y-m-d', strtotime('+3 days')), 'priority' => 'high', 'status' => 'pending', 'assigned_to' => 'Mike'],33 ['id' => 5, 'title' => 'Clean water filters', 'description' => 'Replace and clean main irrigation filters', 'due_date' => date('Y-m-d', strtotime('-1 day')), 'priority' => 'medium', 'status' => 'completed', 'assigned_to' => 'Sarah', 'completed_at' => date('Y-m-d H:i:s')],34 ];35}36 37// Handle form submission38if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_task'])) {39 $title = $_POST['task_title'];40 $description = $_POST['description'];41 $due_date = $_POST['due_date'];42 $priority = $_POST['priority'];43 $assigned_to = $_POST['assigned_to'];44 45 if ($pdo) {46 try {47 $stmt = $pdo->prepare("INSERT INTO tasks (title, description, due_date, priority, status, assigned_to, created_at) VALUES (?, ?, ?, ?, 'pending', ?, NOW())");48 $stmt->execute([$title, $description, $due_date, $priority, $assigned_to]);49 header('Location: tasks.php?added=1');50 exit;51 } catch(PDOException $e) {52 $error = "Failed to add task";53 }54 }55}56 57// Handle status update58if (isset($_GET['complete']) && isset($_GET['id'])) {59 $id = intval($_GET['id']);60 if ($pdo) {61 $stmt = $pdo->prepare("UPDATE tasks SET status = 'completed', completed_at = NOW() WHERE id = ?");62 $stmt->execute([$id]);63 }64 header('Location: tasks.php');65 exit;66}67 68$added = isset($_GET['added']) ? true : false;69$filter = isset($_GET['filter']) ? $_GET['filter'] : 'all';70 71function getPriorityColor($priority) {72 return $priority == 'high' ? 'text-red-600 bg-red-50' : ($priority == 'medium' ? 'text-amber-600 bg-amber-50' : 'text-blue-600 bg-blue-50');73}74 75function getStatusColor($status) {76 return $status == 'completed' ? 'text-green-600 bg-green-50' : ($status == 'in_progress' ? 'text-blue-600 bg-blue-50' : 'text-gray-600 bg-gray-50');77}78?>79<!DOCTYPE html>80<html lang="en">81<head>82 <meta charset="UTF-8">83 <meta name="viewport" content="width=device-width, initial-scale=1.0">84 <title>Tasks - Farmflow Optimizer</title>85 <script src="https://cdn.tailwindcss.com"></script>86 <script src="https://unpkg.com/lucide@latest"></script>87 <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@600;700&display=swap" rel="stylesheet">88 89 <script>90 tailwind.config = {91 theme: {92 extend: {93 colors: {94 sage: {95 50: '#f6f7f4', 100: '#e8ebe3', 200: '#d5dbd0', 300: '#b8c4b0',96 400: '#95a58a', 500: '#7c8a6e', 600: '#5f6e52', 700: '#4d5843',97 800: '#3f4837', 900: '#353c2f',98 }99 },100 fontFamily: {101 sans: ['Inter', 'sans-serif'],102 serif: ['Playfair Display', 'serif'],103 }104 }105 }106 }107 </script>108 <style>109 body { background-color: #fafbf9; color: #2c3e2d; }110 .glass-card { background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.5); }111 .nav-link { position: relative; transition: all 0.3s ease; }112 .nav-link::after { content: ''; position: absolute; width: 0; height: 2px; bottom: -4px; left: 0; background-color: #7c8a6e; transition: width 0.3s ease; }113 .nav-link:hover::after { width: 100%; }114 </style>115</head>116<body class="font-sans antialiased">117 118 <!-- Navigation -->119 <nav class="fixed w-full z-50 glass-card border-b border-sage-200">120 <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">121 <div class="flex justify-between items-center h-20">122 <div class="flex items-center space-x-3">123 <div class="bg-sage-500 text-white p-2 rounded-xl">124 <i data-lucide="sprout" class="w-6 h-6"></i>125 </div>126 <div>127 <h1 class="font-serif text-xl font-bold text-sage-900">Farmflow</h1>128 <p class="text-xs text-sage-600 uppercase tracking-wider">Optimizer</p>129 </div>130 </div>131 <div class="hidden md:flex items-center space-x-8">132 <a href="index.php" class="nav-link text-sage-600 font-medium hover:text-sage-800">Dashboard</a>133 <a href="sensors.php" class="nav-link text-sage-600 font-medium hover:text-sage-800">Sensors</a>134 <a href="schedules.php" class="nav-link text-sage-600 font-medium hover:text-sage-800">Schedules</a>135 <a href="tasks.php" class="nav-link text-sage-800 font-medium hover:text-sage-600">Tasks</a>136 <a href="reports.php" class="nav-link text-sage-600 font-medium hover:text-sage-800">Reports</a>137 </div>138 <div class="hidden md:flex items-center space-x-4">139 <button onclick="document.getElementById('add-task-modal').classList.remove('hidden')" class="flex items-center space-x-2 bg-sage-500 hover:bg-sage-600 text-white px-4 py-2 rounded-lg transition">140 <i data-lucide="plus" class="w-4 h-4"></i>141 <span class="text-sm font-medium">New Task</span>142 </button>143 </div>144 <div class="md:hidden flex items-center">145 <button id="mobile-menu-btn" class="text-sage-600 hover:text-sage-800 p-2">146 <i data-lucide="menu" class="w-6 h-6"></i>147 </button>148 </div>149 </div>150 </div>151 </nav>152 153 <!-- Main Content -->154 <main class="pt-24 pb-16 px-4 sm:px-6 lg:px-8">155 <div class="max-w-7xl mx-auto">156 157 <!-- Header -->158 <div class="flex flex-col md:flex-row md:items-center md:justify-between mb-8">159 <div>160 <h1 class="font-serif text-3xl font-bold text-sage-900">Farm Tasks</h1>161 <p class="mt-2 text-sage-600">Manage daily operations and maintenance tasks</p>162 </div>163 <div class="mt-4 md:mt-0 flex space-x-2">164 <a href="tasks.php?filter=all" class="px-4 py-2 rounded-lg text-sm font-medium <?php echo $filter == 'all' ? 'bg-sage-600 text-white' : 'bg-white text-sage-700 border border-sage-300'; ?>">All</a>165 <a href="tasks.php?filter=pending" class="px-4 py-2 rounded-lg text-sm font-medium <?php echo $filter == 'pending' ? 'bg-sage-600 text-white' : 'bg-white text-sage-700 border border-sage-300'; ?>">Pending</a>166 <a href="tasks.php?filter=completed" class="px-4 py-2 rounded-lg text-sm font-medium <?php echo $filter == 'completed' ? 'bg-sage-600 text-white' : 'bg-white text-sage-700 border border-sage-300'; ?>">Completed</a>167 <a href="tasks.php?filter=urgent" class="px-4 py-2 rounded-lg text-sm font-medium <?php echo $filter == 'urgent' ? 'bg-red-600 text-white' : 'bg-white text-red-700 border border-red-300'; ?>">Urgent</a>168 </div>169 </div>170 171 <?php if ($added): ?>172 <div class="mb-6 p-4 bg-green-50 border border-green-200 rounded-xl flex items-center">173 <i data-lucide="check-circle" class="w-5 h-5 text-green-600 mr-3"></i>174 <span class="text-green-800">Task added successfully!</span>175 </div>176 <?php endif; ?>177 178 <!-- Stats -->179 <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">180 <div class="bg-white rounded-xl p-4 shadow-sm border border-sage-100 text-center">181 <p class="text-2xl font-bold text-sage-900"><?php echo count(array_filter($tasks, fn($t) => $t['status'] != 'completed')); ?></p>182 <p class="text-xs text-sage-600 mt-1">Pending</p>183 </div>184 <div class="bg-white rounded-xl p-4 shadow-sm border border-sage-100 text-center">185 <p class="text-2xl font-bold text-blue-600"><?php echo count(array_filter($tasks, fn($t) => $t['status'] == 'in_progress')); ?></p>186 <p class="text-xs text-sage-600 mt-1">In Progress</p>187 </div>188 <div class="bg-white rounded-xl p-4 shadow-sm border border-sage-100 text-center">189 <p class="text-2xl font-bold text-red-600"><?php echo count(array_filter($tasks, fn($t) => $t['priority'] == 'high' && $t['status'] != 'completed')); ?></p>190 <p class="text-xs text-sage-600 mt-1">High Priority</p>191 </div>192 <div class="bg-white rounded-xl p-4 shadow-sm border border-sage-100 text-center">193 <p class="text-2xl font-bold text-green-600"><?php echo count(array_filter($tasks, fn($t) => $t['status'] == 'completed')); ?></p>194 <p class="text-xs text-sage-600 mt-1">Completed Today</p>195 </div>196 </div>197 198 <!-- Tasks List -->199 <div class="space-y-4">200 <?php 201 $filteredTasks = $tasks;202 if ($filter == 'pending') $filteredTasks = array_filter($tasks, fn($t) => $t['status'] != 'completed');203 if ($filter == 'completed') $filteredTasks = array_filter($tasks, fn($t) => $t['status'] == 'completed');204 if ($filter == 'urgent') $filteredTasks = array_filter($tasks, fn($t) => $t['priority'] == 'high' && $t['status'] != 'completed');205 206 foreach ($filteredTasks as $task): 207 $isOverdue = $task['due_date'] < date('Y-m-d') && $task['status'] != 'completed';208 ?>209 <div class="bg-white rounded-2xl p-6 shadow-sm border border-sage-100 <?php echo $isOverdue ? 'border-l-4 border-l-red-400' : ''; ?>">210 <div class="flex items-start justify-between">211 <div class="flex-1">212 <div class="flex items-center space-x-3 mb-2">213 <h3 class="font-semibold text-sage-900 <?php echo $task['status'] == 'completed' ? 'line-through text-sage-400' : ''; ?>"><?php echo htmlspecialchars($task['title']); ?></h3>214 <span class="px-2 py-1 rounded-full text-xs font-medium <?php echo getPriorityColor($task['priority']); ?>">215 <?php echo ucfirst($task['priority']); ?>216 </span>217 <span class="px-2 py-1 rounded-full text-xs font-medium <?php echo getStatusColor($task['status']); ?>">218 <?php echo str_replace('_', ' ', ucfirst($task['status'])); ?>219 </span>220 <?php if ($isOverdue): ?>221 <span class="px-2 py-1 rounded-full text-xs font-medium text-red-600 bg-red-50">Overdue</span>222 <?php endif; ?>223 </div>224 <p class="text-sm text-sage-600 mb-3"><?php echo htmlspecialchars($task['description']); ?></p>225 <div class="flex items-center space-x-6 text-sm text-sage-500">226 <div class="flex items-center space-x-1">227 <i data-lucide="calendar" class="w-4 h-4"></i>228 <span>Due: <?php echo date('M d, Y', strtotime($task['due_date'])); ?></span>229 </div>230 <div class="flex items-center space-x-1">231 <i data-lucide="user" class="w-4 h-4"></i>232 <span><?php echo $task['assigned_to']; ?></span>233 </div>234 <?php if ($task['status'] == 'completed' && isset($task['completed_at'])): ?>235 <div class="flex items-center space-x-1 text-green-600">236 <i data-lucide="check-circle" class="w-4 h-4"></i>237 <span>Completed <?php echo date('M d H:i', strtotime($task['completed_at'])); ?></span>238 </div>239 <?php endif; ?>240 </div>241 </div>242 243 <div class="flex items-center space-x-2 ml-4">244 <?php if ($task['status'] != 'completed'): ?>245 <a href="tasks.php?complete=1&id=<?php echo $task['id']; ?>" class="p-2 bg-green-50 hover:bg-green-100 text-green-600 rounded-lg transition" title="Mark Complete">246 <i data-lucide="check" class="w-5 h-5"></i>247 </a>248 <?php endif; ?>249 <button onclick="editTask(<?php echo $task['id']; ?>)" class="p-2 bg-sage-50 hover:bg-sage-100 text-sage-600 rounded-lg transition">250 <i data-lucide="edit" class="w-5 h-5"></i>251 </button>252 </div>253 </div>254 </div>255 <?php endforeach; ?>256 257 <?php if (empty($filteredTasks)): ?>258 <div class="text-center py-12">259 <i data-lucide="clipboard-check" class="w-16 h-16 text-sage-300 mx-auto mb-4"></i>260 <p class="text-sage-600">No tasks found</p>261 </div>262 <?php endif; ?>263 </div>264 </div>265 </main>266 267 <!-- Add Task Modal -->268 <div id="add-task-modal" class="hidden fixed inset-0 z-50 overflow-y-auto">269 <div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">270 <div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" onclick="document.getElementById('add-task-modal').classList.add('hidden')"></div>271 <span class="hidden sm:inline-block sm:align-middle sm:h-screen">​</span>272 <div class="inline-block align-bottom bg-white rounded-2xl text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full">273 <div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">274 <h3 class="text-lg font-semibold text-sage-900 mb-4">Add New Task</h3>275 <form method="POST" action="">276 <div class="space-y-4">277 <div>278 <label class="block text-sm font-medium text-sage-700 mb-1">Task Title</label>279 <input type="text" name="task_title" required class="w-full px-3 py-2 border border-sage-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-sage-500">280 </div>281 <div>282 <label class="block text-sm font-medium text-sage-700 mb-1">Description</label>283 <textarea name="description" rows="3" class="w-full px-3 py-2 border border-sage-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-sage-500"></textarea>284 </div>285 <div class="grid grid-cols-2 gap-4">286 <div>287 <label class="block text-sm font-medium text-sage-700 mb-1">Due Date</label>288 <input type="date" name="due_date" required class="w-full px-3 py-2 border border-sage-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-sage-500">289 </div>290 <div>291 <label class="block text-sm font-medium text-sage-700 mb-1">Priority</label>292 <select name="priority" class="w-full px-3 py-2 border border-sage-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-sage-500">293 <option value="low">Low</option>294 <option value="medium">Medium</option>295 <option value="high">High</option>296 </select>297 </div>298 </div>299 <div>300 <label class="block text-sm font-medium text-sage-700 mb-1">Assigned To</label>301 <select name="assigned_to" class="w-full px-3 py-2 border border-sage-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-sage-500">302 <option>John</option>303 <option>Sarah</option>304 <option>Mike</option>305 </select>306 </div>307 </div>308 <div class="mt-6 flex space-x-3">309 <button type="button" onclick="document.getElementById('add-task-modal').classList.add('hidden')" class="flex-1 py-2 border border-sage-300 text-sage-700 rounded-lg hover:bg-sage-50">Cancel</button>310 <button type="submit" name="add_task" class="flex-1 py-2 bg-sage-600 text-white rounded-lg hover:bg-sage-700">Add Task</button>311 </div>312 </form>313 </div>314 </div>315 </div>316 </div>317 318 <script>319 lucide.createIcons();320 document.getElementById('mobile-menu-btn').addEventListener('click', () => {321 document.getElementById('mobile-menu').classList.toggle('hidden');322 });323 function editTask(id) {324 alert('Edit task ' + id + ' would open here');325 }326 </script>327</body>328</html>