Implementeer live Microsoft 365 Outlook en Atlassian Jira integraties met agendasync en taakimport
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* AJAX API voor Integraties (Outlook, Teams, Jira)
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../includes/auth.php';
|
||||
require_once __DIR__ . '/../includes/integrations/microsoft.php';
|
||||
require_once __DIR__ . '/../includes/integrations/jira.php';
|
||||
|
||||
$user = require_auth();
|
||||
$db = get_db_connection();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$action = $_GET['action'] ?? ($_POST['action'] ?? '');
|
||||
|
||||
try {
|
||||
// 1. Jira Verbinding Testen & Optioneel Opslaan
|
||||
if ($action === 'test_jira') {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$domain = trim($input['jira_domain'] ?? '');
|
||||
$email = trim($input['jira_email'] ?? '');
|
||||
$apiToken = trim($input['jira_api_token'] ?? '');
|
||||
$save = !empty($input['save']);
|
||||
|
||||
// Als er geen nieuw token is meegegeven, kijk of er een opgeslagen token is
|
||||
if (empty($apiToken)) {
|
||||
$stmt = $db->prepare("SELECT settings FROM integrations WHERE user_id = ? AND provider = 'JIRA'");
|
||||
$stmt->execute([$user['id']]);
|
||||
$saved = json_decode($stmt->fetchColumn() ?: '{}', true);
|
||||
$apiToken = $saved['jira_api_token'] ?? '';
|
||||
if (empty($domain)) $domain = $saved['jira_domain'] ?? '';
|
||||
if (empty($email)) $email = $saved['jira_email'] ?? '';
|
||||
}
|
||||
|
||||
$res = jira_test_connection($domain, $email, $apiToken);
|
||||
|
||||
if ($res['success'] && $save) {
|
||||
$jiraUser = $res['user'];
|
||||
$settings = json_encode([
|
||||
'jira_domain' => jira_normalize_domain($domain),
|
||||
'jira_email' => $email,
|
||||
'jira_api_token' => $apiToken,
|
||||
'account_name' => $jiraUser['displayName'] ?? '',
|
||||
'account_id' => $jiraUser['accountId'] ?? '',
|
||||
]);
|
||||
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO integrations (user_id, provider, is_enabled, is_demo_mode, settings, last_sync_at)
|
||||
VALUES (?, 'JIRA', 1, 0, ?, NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
is_enabled = 1,
|
||||
is_demo_mode = 0,
|
||||
settings = VALUES(settings),
|
||||
last_sync_at = NOW()
|
||||
");
|
||||
$stmt->execute([$user['id'], $settings]);
|
||||
|
||||
// Wis eventuele oude sessie cache
|
||||
unset($_SESSION["jira_issues_user_{$user['id']}"]);
|
||||
}
|
||||
|
||||
echo json_encode($res);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2. Jira Issues Ophalen (Toegewezen aan de gebruiker)
|
||||
if ($action === 'get_jira_issues') {
|
||||
$force = !empty($_GET['force']) || !empty($_POST['force']);
|
||||
$res = jira_get_user_issues($user['id'], $force);
|
||||
echo json_encode($res);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. Outlook Agenda Afspraken Ophalen
|
||||
if ($action === 'get_outlook_events') {
|
||||
$date = $_GET['date'] ?? date('Y-m-d');
|
||||
$events = microsoft_fetch_today_events($user['id'], $date);
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'date' => $date,
|
||||
'events' => $events,
|
||||
'count' => count($events),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 4. Integratie Ontkoppelen
|
||||
if ($action === 'disconnect') {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$provider = strtoupper(trim($input['provider'] ?? ''));
|
||||
|
||||
if ($provider === 'OUTLOOK') {
|
||||
microsoft_disconnect($user['id']);
|
||||
echo json_encode(['success' => true, 'message' => 'Microsoft Outlook ontkoppeld']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($provider === 'JIRA') {
|
||||
jira_disconnect($user['id']);
|
||||
echo json_encode(['success' => true, 'message' => 'Atlassian Jira ontkoppeld']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['error' => 'Onbekende provider']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['error' => 'Onbekende actie']);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
+7
-3
@@ -53,11 +53,15 @@ try {
|
||||
$stmtPlan->execute([$user['id'], $date]);
|
||||
$planId = $db->lastInsertId();
|
||||
|
||||
$source = !empty($data['source']) ? substr(trim($data['source']), 0, 50) : 'FOCIZ';
|
||||
$externalId = !empty($data['external_id']) ? substr(trim($data['external_id']), 0, 100) : null;
|
||||
$externalUrl = !empty($data['external_url']) ? trim($data['external_url']) : null;
|
||||
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO tasks (user_id, daily_plan_id, title, priority, time_block_start, status)
|
||||
VALUES (?, ?, ?, ?, ?, 'TODO')
|
||||
INSERT INTO tasks (user_id, daily_plan_id, title, priority, time_block_start, status, source, external_id, external_url)
|
||||
VALUES (?, ?, ?, ?, ?, 'TODO', ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([$user['id'], $planId, $title, $priority, $timeBlockStart]);
|
||||
$stmt->execute([$user['id'], $planId, $title, $priority, $timeBlockStart, $source, $externalId, $externalUrl]);
|
||||
$taskId = (int)$db->lastInsertId();
|
||||
|
||||
echo json_encode([
|
||||
|
||||
Reference in New Issue
Block a user