This commit is contained in:
2026-09-09 16:04:44 +02:00
8 changed files with 247 additions and 0 deletions
+145
View File
@@ -42,7 +42,53 @@ $dutchShortMonths = ['', 'jan', 'feb', 'mrt', 'apr', 'mei', 'jun', 'jul', 'aug',
$formattedSelectedDate = $dutchFullDays[(int)date('N', $selectedTs)] . ' ' . date('j', $selectedTs) . ' ' . $dutchMonths[(int)date('n', $selectedTs)] . ' ' . date('Y', $selectedTs);
$formattedWeekRange = date('j', $mondayTs) . ' ' . $dutchShortMonths[(int)date('n', $mondayTs)] . ' – ' . date('j', $sundayTs) . ' ' . $dutchShortMonths[(int)date('n', $sundayTs)] . ' ' . date('Y', $sundayTs);
<<<<<<< HEAD
// 1. Haal integratiestatussen op
=======
// 1. Haal dagplanning op of maak aan voor $selectedDate
$stmtPlan = $db->prepare("SELECT * FROM daily_plans WHERE user_id = ? AND plan_date = ?");
$stmtPlan->execute([$userId, $selectedDate]);
$dailyPlan = $stmtPlan->fetch();
if (!$dailyPlan) {
$defaultGoal = ($selectedDate === $today) ? 'Mijn belangrijkste doel van vandaag behalen' : 'Focusdoel voor deze dag bepalen';
$stmtCreatePlan = $db->prepare("
INSERT INTO daily_plans (user_id, plan_date, focus_goal)
VALUES (?, ?, ?)
");
$stmtCreatePlan->execute([$userId, $selectedDate, $defaultGoal]);
$planId = (int)$db->lastInsertId();
$dailyPlan = ['id' => $planId, 'plan_date' => $selectedDate, 'focus_goal' => $defaultGoal, 'notes' => ''];
}
// 2. Haal taken op voor de geselecteerde dag
$stmtTasks = $db->prepare("
SELECT * FROM tasks
WHERE user_id = ? AND (daily_plan_id = ? " . ($selectedDate === $today ? "OR daily_plan_id IS NULL" : "") . ")
ORDER BY is_completed ASC, priority ASC, time_block_start ASC, created_at DESC
");
$stmtTasks->execute([$userId, $dailyPlan['id']]);
$tasks = $stmtTasks->fetchAll();
// 3. Haal weekstatistieken voor taken op (aantal per dag)
$stmtWeekTasks = $db->prepare("
SELECT dp.plan_date, COUNT(t.id) as total_tasks, SUM(CASE WHEN t.is_completed = 1 THEN 1 ELSE 0 END) as completed_tasks
FROM daily_plans dp
LEFT JOIN tasks t ON t.daily_plan_id = dp.id AND t.user_id = ?
WHERE dp.user_id = ? AND dp.plan_date BETWEEN ? AND ?
GROUP BY dp.plan_date
");
$stmtWeekTasks->execute([$userId, $userId, $weekStart, $weekEnd]);
$weekTaskStats = [];
foreach ($stmtWeekTasks->fetchAll() as $row) {
$weekTaskStats[$row['plan_date']] = [
'total' => (int)$row['total_tasks'],
'completed' => (int)$row['completed_tasks'],
];
}
// 4. Haal integratiestatussen op
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
$stmtInt = $db->prepare("SELECT * FROM integrations WHERE user_id = ?");
$stmtInt->execute([$userId]);
$userIntegrations = [];
@@ -51,9 +97,12 @@ foreach ($stmtInt->fetchAll() as $row) {
}
$isOutlookConnected = !empty($userIntegrations['OUTLOOK']['access_token']) && empty($userIntegrations['OUTLOOK']['is_demo_mode']);
<<<<<<< HEAD
$outlookIntegrationSettings = json_decode($userIntegrations['OUTLOOK']['settings'] ?? '{}', true) ?: [];
$syncIntervalSeconds = isset($outlookIntegrationSettings['sync_interval_seconds']) ? (int)$outlookIntegrationSettings['sync_interval_seconds'] : 30;
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
$weekOutlookEvents = [];
$isLiveOutlook = false;
@@ -61,9 +110,12 @@ if ($isOutlookConnected) {
// Haal afspraken op voor het volledige datumbereik van de week
$weekOutlookEvents = microsoft_fetch_events_range($userId, $weekStart, $weekEnd);
$isLiveOutlook = true;
<<<<<<< HEAD
// Synchroniseer / reconcilieer Fociz taken direct met actuele Outlook data
microsoft_reconcile_tasks_with_outlook($userId, $weekStart, $weekEnd, $weekOutlookEvents);
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
} else {
// Demo data indien Microsoft Outlook nog niet gekoppeld is
$weekOutlookEvents = [
@@ -100,6 +152,7 @@ if ($isOutlookConnected) {
];
}
<<<<<<< HEAD
// 2. Haal dagplanning op of maak aan voor $selectedDate
$stmtPlan = $db->prepare("SELECT * FROM daily_plans WHERE user_id = ? AND plan_date = ?");
$stmtPlan->execute([$userId, $selectedDate]);
@@ -142,6 +195,8 @@ foreach ($stmtWeekTasks->fetchAll() as $row) {
];
}
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
// Groepeer Outlook afspraken per datum
$outlookEventsByDate = [];
foreach ($weekOutlookEvents as $evt) {
@@ -194,6 +249,7 @@ foreach ($dayOutlookEvents as $evt) {
$displayedOutlookEvents[] = $evt;
}
<<<<<<< HEAD
// Bereken initiële status-hash voor achtergrondsynchronisatie
$dayEventsForHash = [];
foreach ($displayedOutlookEvents as $e) {
@@ -218,6 +274,8 @@ $initialSyncHash = md5(json_encode([
'tasks' => $tasksForHash
]));
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
// 6. Tijdlijn uren & Werkdag Standaarden (Release v1.4)
$workdayStartStr = $workdaySettings['workday_start'] ?? '08:30';
$workdayEndStr = $workdaySettings['workday_end'] ?? '17:30';
@@ -280,12 +338,20 @@ for ($h = $startHour; $h <= $endHour; $h++) {
<!-- Integratie Status Badges -->
<div class="flex flex-wrap items-center gap-2">
<?php if ($isOutlookConnected): ?>
<<<<<<< HEAD
<div id="outlookSyncBadge" class="flex items-center space-x-2 px-3 py-1.5 rounded-xl bg-sky-50 dark:bg-sky-500/10 border border-sky-200/80 dark:border-sky-500/20 text-sky-800 dark:text-sky-300 text-xs font-medium shadow-2xs transition">
<span id="outlookSyncDot" class="w-2 h-2 rounded-full bg-sky-500"></span>
<span id="outlookSyncStatusText">Outlook 365 Live</span>
<span id="outlookLastSyncText" class="text-[10px] text-sky-600/70 dark:text-sky-400/60 font-mono hidden sm:inline">(synced <span id="syncTimeDisplay"><?= date('H:i') ?></span>)</span>
<button id="manualSyncBtn" onclick="triggerManualSync()" title="Nu handmatig synchroniseren met Outlook" class="p-0.5 hover:bg-sky-100 dark:hover:bg-sky-500/20 text-sky-600 hover:text-sky-900 dark:text-sky-400 dark:hover:text-white rounded transition cursor-pointer">
<i id="manualSyncIcon" data-lucide="refresh-cw" class="w-3 h-3"></i>
=======
<div class="flex items-center space-x-2 px-3 py-1.5 rounded-xl bg-sky-50 dark:bg-sky-500/10 border border-sky-200/80 dark:border-sky-500/20 text-sky-800 dark:text-sky-300 text-xs font-medium shadow-2xs">
<span class="w-2 h-2 rounded-full bg-sky-500 animate-pulse"></span>
<span>Outlook 365 Live</span>
<button onclick="location.reload()" title="Agenda Verversen" class="p-0.5 text-sky-600 hover:text-sky-900 dark:text-sky-400 dark:hover:text-white rounded transition">
<i data-lucide="refresh-cw" class="w-3 h-3"></i>
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
</button>
</div>
<?php else: ?>
@@ -505,16 +571,24 @@ for ($h = $startHour; $h <= $endHour; $h++) {
<label class="block text-[11px] font-medium text-slate-600 dark:text-slate-400 mb-1">Taaktitel</label>
<input type="text" id="newTaskTitle" placeholder="Wat moet er vandaag gedaan worden?" class="w-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl px-3 py-2 text-slate-900 dark:text-white text-xs placeholder-slate-400 dark:placeholder-slate-500 focus:outline-none focus:ring-1 focus:ring-indigo-500">
</div>
<<<<<<< HEAD
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3">
<div>
<label class="block text-[11px] font-semibold text-slate-700 dark:text-slate-300 mb-1">Prioriteit</label>
<select id="newTaskPriority" class="w-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl px-2.5 py-1.5 text-slate-900 dark:text-white text-xs focus:outline-none focus:ring-1 focus:ring-indigo-500">
=======
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<label class="block text-[11px] font-medium text-slate-600 dark:text-slate-400 mb-1">Prioriteit</label>
<select id="newTaskPriority" class="w-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl px-2.5 py-1.5 text-slate-900 dark:text-white text-xs focus:outline-none">
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
<option value="P1">P1 - Brandend / Focus</option>
<option value="P2" selected>P2 - Belangrijk (Standaard)</option>
<option value="P3">P3 - Regulier / Lage druk</option>
</select>
</div>
<div>
<<<<<<< HEAD
<label class="block text-[11px] font-semibold text-slate-700 dark:text-slate-300 mb-1">Starttijd</label>
<div class="relative">
<input type="text" id="newTaskTime" placeholder="Bijv. 09:30" class="w-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl pl-2.5 pr-7 py-1.5 text-slate-900 dark:text-white text-xs font-mono focus:outline-none focus:ring-1 focus:ring-indigo-500" oninput="onNewTaskTimeOrDurationChange('start')">
@@ -555,6 +629,22 @@ for ($h = $startHour; $h <= $endHour; $h++) {
</select>
<input type="number" id="newTaskCustomDuration" min="1" max="720" placeholder="Min" class="hidden w-20 bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl px-2 py-1.5 text-slate-900 dark:text-white text-xs font-mono focus:outline-none focus:ring-1 focus:ring-indigo-500" oninput="onNewTaskTimeOrDurationChange('custom_duration')">
</div>
=======
<label class="block text-[11px] font-medium text-slate-600 dark:text-slate-400 mb-1">Tijdblok (Starttijd)</label>
<input type="text" id="newTaskTime" placeholder="Bijv. 09:30" class="w-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl px-2.5 py-1.5 text-slate-900 dark:text-white text-xs font-mono focus:outline-none">
</div>
<div>
<label class="block text-[11px] font-medium text-slate-600 dark:text-slate-400 mb-1">Tijdsduur</label>
<select id="newTaskDuration" class="w-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-800 rounded-xl px-2.5 py-1.5 text-slate-900 dark:text-white text-xs focus:outline-none">
<?php
$defDuration = (int)($workdaySettings['default_task_duration'] ?? 30);
$durations = [15 => '15 minuten', 30 => '30 minuten', 45 => '45 minuten', 60 => '60 minuten (1 uur)', 90 => '90 minuten (1,5 uur)', 120 => '120 minuten (2 uur)'];
foreach ($durations as $mins => $label):
?>
<option value="<?= $mins ?>" <?= $defDuration === $mins ? 'selected' : '' ?>><?= $label ?></option>
<?php endforeach; ?>
</select>
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
</div>
</div>
@@ -613,7 +703,11 @@ for ($h = $startHour; $h <= $endHour; $h++) {
<?php if (!empty($task['time_block_start'])): ?>
<span class="text-[10px] text-slate-500 dark:text-slate-400 font-mono flex items-center space-x-1">
<i data-lucide="clock" class="w-2.5 h-2.5"></i>
<<<<<<< HEAD
<span><?= htmlspecialchars($task['time_block_start']) ?><?= !empty($task['time_block_end']) ? ' - ' . htmlspecialchars($task['time_block_end']) : '' ?><?= !empty($task['duration_minutes']) ? ' (' . (int)$task['duration_minutes'] . 'm)' : '' ?></span>
=======
<span><?= htmlspecialchars($task['time_block_start']) ?><?= !empty($task['time_block_end']) ? ' - ' . htmlspecialchars($task['time_block_end']) : '' ?></span>
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
</span>
<?php endif; ?>
<?php if (!empty($task['external_url'])): ?>
@@ -639,11 +733,16 @@ for ($h = $startHour; $h <= $endHour; $h++) {
<?php endif; ?>
<?php if (!$task['is_completed']): ?>
<<<<<<< HEAD
<button onclick="selectFocusTask('<?= htmlspecialchars(addslashes($task['title'])) ?>')" title="Koppel aan Focus Timer" class="p-1.5 rounded-lg text-slate-400 hover:text-amber-500 hover:bg-amber-500/10 transition cursor-pointer">
=======
<button onclick="selectFocusTask('<?= htmlspecialchars(addslashes($task['title'])) ?>')" title="Koppel aan Focus Timer" class="p-1.5 rounded-lg text-slate-400 hover:text-amber-500 hover:bg-amber-500/10 transition">
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
<i data-lucide="flame" class="w-3.5 h-3.5"></i>
</button>
<?php endif; ?>
<<<<<<< HEAD
<button onclick="openEditTaskModal(<?= htmlspecialchars(json_encode([
'id' => (int)$task['id'],
'title' => $task['title'],
@@ -658,6 +757,9 @@ for ($h = $startHour; $h <= $endHour; $h++) {
</button>
<button onclick="deleteTask(<?= $task['id'] ?>)" title="Verwijderen" class="p-1.5 rounded-lg text-slate-400 hover:text-red-600 dark:hover:text-red-400 hover:bg-red-500/10 opacity-0 group-hover:opacity-100 transition cursor-pointer">
=======
<button onclick="deleteTask(<?= $task['id'] ?>)" title="Verwijderen" class="p-1.5 rounded-lg text-slate-400 hover:text-red-600 dark:hover:text-red-400 hover:bg-red-500/10 opacity-0 group-hover:opacity-100 transition">
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
<i data-lucide="trash-2" class="w-3.5 h-3.5"></i>
</button>
</div>
@@ -873,6 +975,7 @@ for ($h = $startHour; $h <= $endHour; $h++) {
</div>
</div>
<<<<<<< HEAD
<!-- Modal: Taak & Tijdblok Bewerken (Vrij invullen van tijden & duur) -->
<div id="editTaskModal" class="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs hidden items-center justify-center p-4">
<div class="bg-white dark:bg-[#111622] border border-slate-200/90 dark:border-slate-800 rounded-2xl p-6 w-full max-w-lg shadow-2xl space-y-4">
@@ -967,6 +1070,8 @@ for ($h = $startHour; $h <= $endHour; $h++) {
</div>
</div>
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
<script>
// --- Focus Timer Logica (Release v1.4) ---
const pomodoroFocusTime = <?= (int)$workdaySettings['pomodoro_focus'] ?>;
@@ -1008,7 +1113,10 @@ function toggleTimer() {
clearInterval(timerInterval);
isRunning = false;
document.getElementById('timerToggleText').innerText = 'Hervatten';
<<<<<<< HEAD
saveTimerStateBeforeReload();
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
} else {
isRunning = true;
document.getElementById('timerToggleText').innerText = 'Pauzeren';
@@ -1019,7 +1127,10 @@ function toggleTimer() {
} else {
clearInterval(timerInterval);
isRunning = false;
<<<<<<< HEAD
sessionStorage.removeItem('fociz_timer_state');
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
document.getElementById('timerToggleText').innerText = 'Start Focus';
alert('Focus sessie voltooid! Neem even een korte pauze.');
}
@@ -1031,11 +1142,15 @@ function resetTimer() {
clearInterval(timerInterval);
isRunning = false;
timerSeconds = totalDuration;
<<<<<<< HEAD
sessionStorage.removeItem('fociz_timer_state');
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
document.getElementById('timerToggleText').innerText = 'Start Focus';
updateTimerDisplay();
}
<<<<<<< HEAD
function saveTimerStateBeforeReload() {
try {
if (isRunning || timerSeconds < totalDuration) {
@@ -1084,6 +1199,8 @@ window.addEventListener('beforeunload', () => {
saveTimerStateBeforeReload();
});
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
function selectFocusTask(title) {
document.getElementById('activeTaskDisplay').innerText = title;
}
@@ -1114,6 +1231,7 @@ async function saveGoal() {
}
}
<<<<<<< HEAD
// --- Tijdblok Hulpfuncties & Vrije Duur Berekening ---
function parseTimeToMinutes(str) {
if (!str || typeof str !== 'string') return null;
@@ -1247,6 +1365,8 @@ function setSelectedNewTaskDuration(mins) {
if (durationDisplay) durationDisplay.innerText = `${mins}m`;
}
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
function toggleAddTaskForm() {
const form = document.getElementById('addTaskForm');
form.classList.toggle('hidden');
@@ -1256,6 +1376,7 @@ function toggleAddTaskForm() {
}
function quickSchedule(hour) {
<<<<<<< HEAD
const form = document.getElementById('addTaskForm');
if (form && form.classList.contains('hidden')) {
form.classList.remove('hidden');
@@ -1268,12 +1389,20 @@ function quickSchedule(hour) {
const outlookCheckbox = document.getElementById('newTaskSyncOutlook');
if (outlookCheckbox) outlookCheckbox.checked = true;
document.getElementById('newTaskTitle')?.focus();
=======
toggleAddTaskForm();
const timeInput = document.getElementById('newTaskTime');
if (timeInput) timeInput.value = hour;
const outlookCheckbox = document.getElementById('newTaskSyncOutlook');
if (outlookCheckbox) outlookCheckbox.checked = true;
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
}
async function submitNewTask() {
const title = document.getElementById('newTaskTitle').value.trim();
const priority = document.getElementById('newTaskPriority').value;
const time = document.getElementById('newTaskTime').value.trim();
<<<<<<< HEAD
const endTime = document.getElementById('newTaskEndTime') ? document.getElementById('newTaskEndTime').value.trim() : '';
const duration = getSelectedNewTaskDurationMinutes();
const syncOutlook = document.getElementById('newTaskSyncOutlook') ? document.getElementById('newTaskSyncOutlook').checked : false;
@@ -1282,6 +1411,12 @@ async function submitNewTask() {
alert('Vul een taaktitel in.');
return;
}
=======
const duration = document.getElementById('newTaskDuration') ? parseInt(document.getElementById('newTaskDuration').value) : 30;
const syncOutlook = document.getElementById('newTaskSyncOutlook') ? document.getElementById('newTaskSyncOutlook').checked : false;
if (!title) return;
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
try {
const res = await fetch('/api/planner.php?action=add_task', {
@@ -1290,8 +1425,12 @@ async function submitNewTask() {
body: JSON.stringify({
title,
priority,
<<<<<<< HEAD
time_block_start: time,
time_block_end: endTime,
=======
time_block_start: time,
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
duration_minutes: duration,
sync_to_outlook: syncOutlook,
date: activePlannerDate
@@ -1311,6 +1450,7 @@ async function submitNewTask() {
}
}
<<<<<<< HEAD
// --- Taak & Tijdblok Bewerken Modal Logica ---
function openEditTaskModal(task) {
if (!task) return;
@@ -1499,6 +1639,8 @@ async function submitEditTask() {
}
}
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
async function syncTaskToOutlook(taskId, btn) {
if (!btn) return;
const originalHtml = btn.innerHTML;
@@ -1624,6 +1766,7 @@ async function aiSmartSchedule(btn) {
}
}
}
<<<<<<< HEAD
// --- Outlook 365 Auto-Sync & Achtergrond Controle ---
const isOutlookConnected = <?= $isOutlookConnected ? 'true' : 'false' ?>;
let currentSyncHash = '<?= $initialSyncHash ?? '' ?>';
@@ -1712,6 +1855,8 @@ document.addEventListener('DOMContentLoaded', () => {
});
}
});
=======
>>>>>>> dd738e670b78819c11e329da93db1b472808f195
</script>
<?php require_once __DIR__ . '/includes/footer.php'; ?>