9262b09c4d
- Implemented roadmap.php for managing roadmap items with filtering options by quarter and status. - Added a service worker (sw.js) to handle push notifications and click events for calendar appointments. - Created users.php for admin to manage team members and invitations, including user creation and deletion functionalities.
115 lines
3.9 KiB
PHP
115 lines
3.9 KiB
PHP
<?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()]);
|
|
}
|
|
|