Fix HTTP 500 on live after login, unify database config in config.php, sanitize env example, and harden pentest security
This commit is contained in:
+80
-44
@@ -43,11 +43,16 @@ $formattedSelectedDate = $dutchFullDays[(int)date('N', $selectedTs)] . ' ' . dat
|
||||
$formattedWeekRange = date('j', $mondayTs) . ' ' . $dutchShortMonths[(int)date('n', $mondayTs)] . ' – ' . date('j', $sundayTs) . ' ' . $dutchShortMonths[(int)date('n', $sundayTs)] . ' ' . date('Y', $sundayTs);
|
||||
|
||||
// 1. 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;
|
||||
try {
|
||||
$stmtInt = $db->prepare("SELECT * FROM integrations WHERE user_id = ?");
|
||||
$stmtInt->execute([$userId]);
|
||||
foreach ($stmtInt->fetchAll() as $row) {
|
||||
$userIntegrations[$row['provider']] = $row;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log("Fout bij ophalen integraties: " . $e->getMessage());
|
||||
ensure_tables_exist($db);
|
||||
}
|
||||
|
||||
$isOutlookConnected = !empty($userIntegrations['OUTLOOK']['access_token']) && empty($userIntegrations['OUTLOOK']['is_demo_mode']);
|
||||
@@ -58,12 +63,18 @@ $weekOutlookEvents = [];
|
||||
$isLiveOutlook = false;
|
||||
|
||||
if ($isOutlookConnected) {
|
||||
// Haal afspraken op voor het volledige datumbereik van de week
|
||||
$weekOutlookEvents = microsoft_fetch_events_range($userId, $weekStart, $weekEnd);
|
||||
$isLiveOutlook = true;
|
||||
try {
|
||||
// Haal afspraken op voor het volledige datumbereik van de week
|
||||
$weekOutlookEvents = microsoft_fetch_events_range($userId, $weekStart, $weekEnd);
|
||||
$isLiveOutlook = true;
|
||||
|
||||
// Synchroniseer / reconcilieer Fociz taken direct met actuele Outlook data
|
||||
microsoft_reconcile_tasks_with_outlook($userId, $weekStart, $weekEnd, $weekOutlookEvents);
|
||||
// Synchroniseer / reconcilieer Fociz taken direct met actuele Outlook data
|
||||
microsoft_reconcile_tasks_with_outlook($userId, $weekStart, $weekEnd, $weekOutlookEvents);
|
||||
} catch (Throwable $e) {
|
||||
error_log("Outlook synchronisatiefout in planner: " . $e->getMessage());
|
||||
$isLiveOutlook = false;
|
||||
$weekOutlookEvents = [];
|
||||
}
|
||||
} else {
|
||||
// Demo data indien Microsoft Outlook nog niet gekoppeld is
|
||||
$weekOutlookEvents = [
|
||||
@@ -101,45 +112,64 @@ if ($isOutlookConnected) {
|
||||
}
|
||||
|
||||
// 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]);
|
||||
$dailyPlan = $stmtPlan->fetch();
|
||||
$dailyPlan = null;
|
||||
try {
|
||||
$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' => ''];
|
||||
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 (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)
|
||||
");
|
||||
$stmtCreatePlan->execute([$userId, $selectedDate, $defaultGoal]);
|
||||
$planId = (int)$db->lastInsertId();
|
||||
$dailyPlan = ['id' => $planId, 'plan_date' => $selectedDate, 'focus_goal' => $defaultGoal, 'notes' => ''];
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log("Fout bij dagplanning ophalen/aanmaken: " . $e->getMessage());
|
||||
ensure_tables_exist($db);
|
||||
$dailyPlan = ['id' => 0, 'plan_date' => $selectedDate, 'focus_goal' => 'Mijn belangrijkste doel van vandaag behalen', 'notes' => ''];
|
||||
}
|
||||
|
||||
$planId = !empty($dailyPlan['id']) ? (int)$dailyPlan['id'] : 0;
|
||||
|
||||
// 3. Haal taken op voor de geselecteerde dag (vers bijgewerkt na eventuele reconciliatie)
|
||||
$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();
|
||||
$tasks = [];
|
||||
try {
|
||||
$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, $planId]);
|
||||
$tasks = $stmtTasks->fetchAll() ?: [];
|
||||
} catch (Throwable $e) {
|
||||
error_log("Fout bij ophalen taken: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// 4. 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'],
|
||||
];
|
||||
try {
|
||||
$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]);
|
||||
foreach ($stmtWeekTasks->fetchAll() as $row) {
|
||||
$weekTaskStats[$row['plan_date']] = [
|
||||
'total' => (int)$row['total_tasks'],
|
||||
'completed' => (int)$row['completed_tasks'],
|
||||
];
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log("Fout bij weekstatistieken ophalen: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Groepeer Outlook afspraken per datum
|
||||
@@ -174,9 +204,15 @@ for ($i = 0; $i < 7; $i++) {
|
||||
}
|
||||
|
||||
// 5. 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']);
|
||||
$jiraIssues = [];
|
||||
$isJiraLive = false;
|
||||
try {
|
||||
$jiraData = jira_get_user_issues($userId);
|
||||
$jiraIssues = $jiraData['issues'] ?? [];
|
||||
$isJiraLive = !empty($jiraData['success']) && empty($jiraData['is_demo']);
|
||||
} catch (Throwable $e) {
|
||||
error_log("Fout bij ophalen Jira issues: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Filter Outlook events die afkomstig zijn van Fociz taken voor de geselecteerde dag om duplicaten op de tijdlijn te voorkomen
|
||||
$dayOutlookEvents = $outlookEventsByDate[$selectedDate] ?? [];
|
||||
|
||||
Reference in New Issue
Block a user