prepare("SELECT * FROM daily_plans WHERE user_id = ? AND plan_date = ?"); $stmtPlan->execute([$userId, $today]); $dailyPlan = $stmtPlan->fetch(); if (!$dailyPlan) { $stmtCreatePlan = $db->prepare(" INSERT INTO daily_plans (user_id, plan_date, focus_goal) VALUES (?, ?, 'Mijn belangrijkste doel van vandaag behalen') "); $stmtCreatePlan->execute([$userId, $today]); $planId = (int)$db->lastInsertId(); $dailyPlan = ['id' => $planId, 'plan_date' => $today, 'focus_goal' => 'Mijn belangrijkste doel van vandaag behalen', 'notes' => '']; } // 2. Haal taken op voor vandaag $stmtTasks = $db->prepare(" SELECT * FROM tasks WHERE user_id = ? AND (daily_plan_id = ? 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 integratiestatussen op $stmtInt = $db->prepare("SELECT * FROM integrations WHERE user_id = ?"); $stmtInt->execute([$userId]); $userIntegrations = []; foreach ($stmtInt->fetchAll() as $row) { $userIntegrations[$row['provider']] = $row; } $isOutlookConnected = !empty($userIntegrations['OUTLOOK']['access_token']) && empty($userIntegrations['OUTLOOK']['is_demo_mode']); $outlookEvents = []; $isLiveOutlook = false; if ($isOutlookConnected) { $outlookEvents = microsoft_fetch_today_events($userId, $today); $isLiveOutlook = !empty($outlookEvents) || true; // Live koppeling is actief } // Fallback naar sandbox data indien Outlook niet live gekoppeld is if (!$isOutlookConnected || empty($outlookEvents)) { $outlookEvents = [ [ 'id' => 'evt-1', 'subject' => 'Daily Team Standup & Focus Sync', 'start' => '09:00', 'end' => '09:30', 'location' => 'Microsoft Teams', 'meeting_url' => 'https://teams.microsoft.com', 'source' => 'SANDBOX', ], [ 'id' => 'evt-2', 'subject' => 'Sprint & Roadmap Review met Stakeholders', 'start' => '11:00', 'end' => '12:00', 'location' => 'Vergaderruimte A & Teams', 'meeting_url' => 'https://teams.microsoft.com', 'source' => 'SANDBOX', ], [ 'id' => 'evt-3', 'subject' => 'Architectuur & MariaDB Database Evaluatie', 'start' => '14:30', 'end' => '15:30', 'location' => 'Online Teams Call', 'meeting_url' => 'https://teams.microsoft.com', 'source' => 'SANDBOX', ] ]; } // 4. Haal Jira issues op voor de snelle import widget $jiraData = jira_get_user_issues($userId); $jiraIssues = $jiraData['issues'] ?? []; $isJiraLive = !empty($jiraData['success']) && empty($jiraData['is_demo']); // 5. Tijdlijn uren bepalen $startHour = 8; $endHour = 18; foreach ($outlookEvents as $e) { if (!empty($e['start'])) { $h = (int)explode(':', $e['start'])[0]; if ($h < $startHour && $h >= 6) $startHour = $h; if ($h > $endHour && $h <= 22) $endHour = $h + 1; } } $hours = []; for ($h = $startHour; $h <= $endHour; $h++) { $hours[] = sprintf('%02d:00', $h); } // Nederlandse datumformattering $dutchDays = ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag']; $dutchMonths = ['', 'januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december']; $formattedDate = $dutchDays[date('w')] . ' ' . date('j') . ' ' . $dutchMonths[(int)date('n')] . ' ' . date('Y'); ?>
Pomodoro & diepe concentratie