Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../controllers/TaskController.php';
requireAdmin();
$taskController = new TaskController();
$currentUser = getCurrentUser();
$errors = [];
$success = '';
$mode = $_GET['mode'] ?? 'list'; // list, create, edit
$editTask = null;
// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'create') {
$data = [
'title' => trim($_POST['title'] ?? ''),
'description' => trim($_POST['description'] ?? ''),
'location' => trim($_POST['location'] ?? ''),
'date' => $_POST['date'] ?? '',
'created_by' => $currentUser['id']
];
$result = $taskController->createTask($data);
if ($result['success']) {
$success = $result['message'];
$mode = 'list';
} else {
$errors = $result['errors'];
}
} elseif ($action === 'update') {
$taskId = (int)$_POST['task_id'];
$data = [
'title' => trim($_POST['title'] ?? ''),
'description' => trim($_POST['description'] ?? ''),
'location' => trim($_POST['location'] ?? ''),
'date' => $_POST['date'] ?? ''
];
$result = $taskController->updateTask($taskId, $data);
if ($result['success']) {
$success = $result['message'];
$mode = 'list';
} else {
$errors = $result['errors'];
}
} elseif ($action === 'delete') {
$taskId = (int)$_POST['task_id'];
$result = $taskController->deleteTask($taskId);
if ($result['success']) {
$success = $result['message'];
} else {
$errors = $result['errors'];
}
}
}
// Get task for editing
if ($mode === 'edit' && isset($_GET['id'])) {
$editTask = $taskController->getTaskById((int)$_GET['id']);
if (!$editTask) {
$errors[] = 'Taak niet gevonden';
$mode = 'list';
}
}
// Get all tasks
$tasks = $taskController->getAllTasks();
$pageTitle = 'Beheer Taken';
include __DIR__ . '/../includes/header.php';
?>
<div class="space-y-6">
<div class="flex justify-between items-center">
<div>
<h1 class="text-3xl font-bold text-gray-900">Beheer Taken</h1>
<p class="text-gray-600 mt-2">Maak taken aan, bewerk of verwijder ze</p>
</div>
<?php if ($mode === 'list'): ?>
<a href="admin_tasks.php?mode=create" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Nieuwe Taak
</a>
<?php else: ?>
<a href="admin_tasks.php" class="inline-flex items-center px-4 py-2 bg-gray-600 text-white font-medium rounded-lg hover:bg-gray-700 transition-colors duration-200">← Terug</a>
<?php endif; ?>
</div>
<?php if (!empty($errors)): ?>
<div class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg">
<ul class="list-disc list-inside">
<?php foreach ($errors as $error): ?>
<li><?php echo e($error); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg">
<?php echo e($success); ?>
</div>
<?php endif; ?>
<?php if ($mode === 'list'): ?>
<!-- List Tasks -->
<?php if (empty($tasks)): ?>
<div class="card">
<div class="p-8 text-center">
<div class="text-6xl mb-4">📭</div>
<p class="text-gray-600 mb-4">Er zijn nog geen taken aangemaakt.</p>
<a href="admin_tasks.php?mode=create" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">Maak de eerste taak aan</a>
</div>
</div>
<?php else: ?>
<div class="card overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Titel</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Datum</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Locatie</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Vrijwilligers</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acties</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<?php foreach ($tasks as $task): ?>
<tr class="hover:bg-gray-50">
<td class="px-6 py-4">
<div class="text-sm font-medium text-gray-900"><?php echo e($task['title']); ?></div>
</td>
<td class="px-6 py-4 text-sm text-gray-500">
<?php echo formatDate($task['date']); ?>
</td>
<td class="px-6 py-4 text-sm text-gray-500">
<?php echo e($task['location']); ?>
</td>
<td class="px-6 py-4 text-sm text-gray-500">
<?php echo $task['current_volunteers']; ?>
</td>
<td class="px-6 py-4 text-sm space-x-2">
<a href="admin_tasks.php?mode=edit&id=<?php echo $task['id']; ?>"
class="text-blue-600 hover:text-blue-900 font-medium">Bewerken</a>
<form method="POST" action="admin_tasks.php" class="inline">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="task_id" value="<?php echo $task['id']; ?>">
<button type="submit" class="text-red-600 hover:text-red-900 font-medium"
onclick="return confirm('Weet je zeker dat je deze taak wilt verwijderen?')">
Verwijderen
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<?php elseif ($mode === 'create' || $mode === 'edit'): ?>
<!-- Create/Edit Form -->
<div class="card max-w-2xl">
<div class="p-6">
<h2 class="text-xl font-bold text-gray-900 mb-6">
<?php echo $mode === 'create' ? 'Nieuwe Taak Aanmaken' : 'Taak Bewerken'; ?>
</h2>
<form method="POST" action="admin_tasks.php" class="space-y-5">
<input type="hidden" name="action" value="<?php echo $mode === 'create' ? 'create' : 'update'; ?>">
<?php if ($mode === 'edit'): ?>
<input type="hidden" name="task_id" value="<?php echo $editTask['id']; ?>">
<?php endif; ?>
<div>
<label for="title" class="label">Titel *</label>
<input type="text" id="title" name="title" class="input"
value="<?php echo e($editTask['title'] ?? $_POST['title'] ?? ''); ?>" required>
</div>
<div>
<label for="description" class="label">Omschrijving *</label>
<textarea id="description" name="description" class="input"
rows="5" required><?php echo e($editTask['description'] ?? $_POST['description'] ?? ''); ?></textarea>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="location" class="label">Locatie *</label>
<input type="text" id="location" name="location" class="input"
value="<?php echo e($editTask['location'] ?? $_POST['location'] ?? ''); ?>" required>
</div>
<div>
<label for="date" class="label">Datum en tijd *</label>
<input type="datetime-local" id="date" name="date" class="input"
value="<?php echo isset($editTask['date']) ? date('Y-m-d\TH:i', strtotime($editTask['date'])) : ($_POST['date'] ?? ''); ?>" required>
</div>
</div>
<div class="flex items-center space-x-4">
<button type="submit" class="px-6 py-2.5 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">
<?php echo $mode === 'create' ? 'Taak Aanmaken' : 'Wijzigingen Opslaan'; ?>
</button>
<a href="admin_tasks.php" class="px-6 py-2.5 bg-gray-600 text-white font-medium rounded-lg hover:bg-gray-700 transition-colors duration-200">Annuleren</a>
</div>
</form>
</div>
</div>
<?php endif; ?>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>