118 lines
3.8 KiB
PHP
118 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* AJAX API voor Roadmap Beheer
|
|
*/
|
|
|
|
require_once __DIR__ . '/../includes/auth.php';
|
|
$user = require_auth();
|
|
$db = get_db_connection();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$action = $_GET['action'] ?? ($_POST['action'] ?? '');
|
|
|
|
try {
|
|
// 1. Roadmap item toevoegen
|
|
if ($action === 'add_item') {
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$title = trim($data['title'] ?? '');
|
|
$description = trim($data['description'] ?? '');
|
|
$quarter = $data['quarter'] ?? 'Q3';
|
|
$type = $data['type'] ?? 'FEATURE';
|
|
$priority = $data['priority'] ?? 'MEDIUM';
|
|
$dueDate = !empty($data['due_date']) ? $data['due_date'] : null;
|
|
$jiraKey = !empty($data['jira_key']) ? trim($data['jira_key']) : null;
|
|
|
|
if (empty($title)) {
|
|
echo json_encode(['error' => 'Titel is verplicht']);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $db->prepare("
|
|
INSERT INTO roadmap_items (title, description, quarter, type, priority, status, progress, due_date, jira_issue_key, created_by_id)
|
|
VALUES (?, ?, ?, ?, ?, 'PLANNED', 0, ?, ?, ?)
|
|
");
|
|
$stmt->execute([$title, $description, $quarter, $type, $priority, $dueDate, $jiraKey, $user['id']]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
exit;
|
|
}
|
|
|
|
// 2. Status of voortgang bijwerken
|
|
if ($action === 'update_item') {
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$id = (int)($data['id'] ?? 0);
|
|
$status = $data['status'] ?? null;
|
|
$progress = isset($data['progress']) ? (int)$data['progress'] : null;
|
|
$jiraKey = isset($data['jira_key']) ? trim($data['jira_key']) : null;
|
|
|
|
$fields = [];
|
|
$params = [];
|
|
|
|
if ($status !== null) {
|
|
$fields[] = "status = ?";
|
|
$params[] = $status;
|
|
}
|
|
if (isset($data['quarter']) && in_array($data['quarter'], ['Q1', 'Q2', 'Q3', 'Q4'], true)) {
|
|
$fields[] = "quarter = ?";
|
|
$params[] = $data['quarter'];
|
|
}
|
|
if (isset($data['title']) && trim($data['title']) !== '') {
|
|
$fields[] = "title = ?";
|
|
$params[] = trim($data['title']);
|
|
}
|
|
if (isset($data['description'])) {
|
|
$fields[] = "description = ?";
|
|
$params[] = trim($data['description']);
|
|
}
|
|
if (isset($data['type'])) {
|
|
$fields[] = "type = ?";
|
|
$params[] = $data['type'];
|
|
}
|
|
if (isset($data['priority'])) {
|
|
$fields[] = "priority = ?";
|
|
$params[] = $data['priority'];
|
|
}
|
|
if (array_key_exists('due_date', $data)) {
|
|
$fields[] = "due_date = ?";
|
|
$params[] = !empty($data['due_date']) ? $data['due_date'] : null;
|
|
}
|
|
if ($progress !== null) {
|
|
$fields[] = "progress = ?";
|
|
$params[] = max(0, min(100, $progress));
|
|
}
|
|
if ($jiraKey !== null) {
|
|
$fields[] = "jira_issue_key = ?";
|
|
$params[] = $jiraKey;
|
|
}
|
|
|
|
if (!empty($fields)) {
|
|
$params[] = $id;
|
|
$sql = "UPDATE roadmap_items SET " . implode(", ", $fields) . " WHERE id = ?";
|
|
$stmt = $db->prepare($sql);
|
|
$stmt->execute($params);
|
|
}
|
|
|
|
echo json_encode(['success' => true]);
|
|
exit;
|
|
}
|
|
|
|
// 3. Item verwijderen
|
|
if ($action === 'delete_item') {
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$id = (int)($data['id'] ?? 0);
|
|
|
|
$stmt = $db->prepare("DELETE FROM roadmap_items WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode(['error' => 'Onbekende actie']);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
}
|
|
|