Aanpassingen planner en ai

This commit is contained in:
2026-09-12 13:24:00 +02:00
parent bc33c0bd1a
commit 8714038db2
5 changed files with 1173 additions and 142 deletions
+2 -2
View File
@@ -395,9 +395,9 @@ try {
];
if ($provider === 'gemini' || strpos(strtolower($model), 'gemini') !== false) {
$aiRes = fociz_ai_chat_gemini($testMessages, ['max_tokens' => 20, 'temperature' => 0.1], $testSettings);
$aiRes = fociz_ai_chat_gemini($testMessages, ['max_tokens' => 500, 'temperature' => 0.1], $testSettings);
} else {
$aiRes = fociz_ai_chat_openai($testMessages, ['max_tokens' => 20, 'temperature' => 0.1], $testSettings);
$aiRes = fociz_ai_chat_openai($testMessages, ['max_tokens' => 500, 'temperature' => 0.1], $testSettings);
}
$latency = round((microtime(true) - $t0) * 1000);
+13 -9
View File
@@ -121,14 +121,14 @@ try {
// 6. E-mail direct inplannen in Fociz dagplanning
if ($action === 'plan_email') {
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
$messageId = trim($input['message_id'] ?? '');
$subject = trim($input['subject'] ?? 'E-mail actiepunt');
$planDate = trim($input['plan_date'] ?? date('Y-m-d'));
$messageId = trim($input['message_id'] ?? $input['mail_id'] ?? '');
$subject = trim($input['title'] ?? $input['subject'] ?? 'E-mail actiepunt');
$planDate = trim($input['plan_date'] ?? $input['date'] ?? date('Y-m-d'));
$timeBlockStart = !empty($input['time_block_start']) ? trim($input['time_block_start']) : null;
$durationMinutes = (int)($input['duration_minutes'] ?? 30);
$priority = in_array($input['priority'] ?? '', ['P1', 'P2', 'P3']) ? $input['priority'] : 'P2';
$webLink = trim($input['web_link'] ?? 'https://outlook.office.com/mail/');
$sender = trim($input['sender'] ?? '');
$sender = trim($input['sender'] ?? $input['sender_name'] ?? '');
if (empty($subject)) {
echo json_encode(['success' => false, 'error' => 'Onderwerp is verplicht.']);
@@ -137,8 +137,8 @@ try {
if ($durationMinutes <= 0) $durationMinutes = 30;
$timeBlockEnd = null;
if (!empty($timeBlockStart)) {
$timeBlockEnd = !empty($input['time_block_end']) ? trim($input['time_block_end']) : null;
if (!empty($timeBlockStart) && empty($timeBlockEnd)) {
try {
$dtEnd = new DateTime("{$planDate} {$timeBlockStart}:00", new DateTimeZone('Europe/Amsterdam'));
$dtEnd->modify("+{$durationMinutes} minutes");
@@ -155,9 +155,13 @@ try {
$stmtPlan->execute([$userId, $planDate]);
$planId = (int)$db->lastInsertId();
$taskTitle = "✉️ " . $subject;
if (!empty($sender)) {
$taskTitle .= " (van " . $sender . ")";
// Als er een custom titel is ingevoerd, gebruik die direct, anders maak een nette titel
$taskTitle = $subject;
if (isset($input['subject']) && !isset($input['title'])) {
$taskTitle = "✉️ " . $subject;
if (!empty($sender) && strpos($taskTitle, $sender) === false) {
$taskTitle .= " (van " . $sender . ")";
}
}
$stmtTask = $db->prepare("
+47 -4
View File
@@ -271,20 +271,22 @@ try {
}
}
$description = isset($data['description']) ? trim((string)$data['description']) : ($existingTask['description'] ?? null);
if ($newPlanId) {
$stmtUpdate = $db->prepare("
UPDATE tasks
SET title = ?, priority = ?, time_block_start = ?, time_block_end = ?, duration_minutes = ?, daily_plan_id = ?
SET title = ?, description = ?, priority = ?, time_block_start = ?, time_block_end = ?, duration_minutes = ?, daily_plan_id = ?
WHERE id = ? AND user_id = ?
");
$stmtUpdate->execute([$title, $priority, $timeBlockStart, $timeBlockEnd, $durationMinutes, $newPlanId, $taskId, $user['id']]);
$stmtUpdate->execute([$title, $description, $priority, $timeBlockStart, $timeBlockEnd, $durationMinutes, $newPlanId, $taskId, $user['id']]);
} else {
$stmtUpdate = $db->prepare("
UPDATE tasks
SET title = ?, priority = ?, time_block_start = ?, time_block_end = ?, duration_minutes = ?
SET title = ?, description = ?, priority = ?, time_block_start = ?, time_block_end = ?, duration_minutes = ?
WHERE id = ? AND user_id = ?
");
$stmtUpdate->execute([$title, $priority, $timeBlockStart, $timeBlockEnd, $durationMinutes, $taskId, $user['id']]);
$stmtUpdate->execute([$title, $description, $priority, $timeBlockStart, $timeBlockEnd, $durationMinutes, $taskId, $user['id']]);
}
echo json_encode([
@@ -645,6 +647,47 @@ try {
exit;
}
// 10b. Volledige taakdetails ophalen inclusief subtaken en dagplan informatie
if ($action === 'get_task_details') {
$taskId = (int)($_GET['task_id'] ?? ($_POST['task_id'] ?? 0));
if (!$taskId) {
echo json_encode(['error' => 'Taak-ID ontbreekt']);
exit;
}
$stmt = $db->prepare("
SELECT t.*, dp.plan_date, dp.focus_goal
FROM tasks t
LEFT JOIN daily_plans dp ON t.daily_plan_id = dp.id
WHERE t.id = ? AND t.user_id = ?
");
$stmt->execute([$taskId, $user['id']]);
$task = $stmt->fetch();
if (!$task) {
echo json_encode(['error' => 'Taak niet gevonden']);
exit;
}
// Subtaken ophalen
$stmtSub = $db->prepare("
SELECT id, task_id, title, is_completed, position, created_at
FROM task_subtasks
WHERE task_id = ? AND user_id = ?
ORDER BY position ASC, created_at ASC
");
$stmtSub->execute([$taskId, $user['id']]);
$subtasks = $stmtSub->fetchAll();
echo json_encode([
'success' => true,
'task' => $task,
'subtasks' => $subtasks,
]);
exit;
}
// 11. Zoek eerstvolgende vrije open blok binnen werktijden (Release v2.1)
if ($action === 'find_next_free_slot') {
$rawInput = json_decode(file_get_contents('php://input'), true);