46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
require_once(__DIR__ . '/auth_check.php');
|
|
header('Content-Type: application/json');
|
|
require_once(__DIR__ . '/../../class/db-functions.php');
|
|
|
|
try {
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
echo json_encode(['success' => false, 'message' => 'ID non valido.']);
|
|
exit;
|
|
}
|
|
|
|
$id = (int)$_GET['id'];
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM scad_deadlines WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$deadline = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$deadline) {
|
|
echo json_encode(['success' => false, 'message' => 'Scadenza non trovata.']);
|
|
exit;
|
|
}
|
|
|
|
// Get assigned employee IDs
|
|
$empStmt = $pdo->prepare("SELECT employee_id FROM scad_deadline_employee WHERE deadline_id = ?");
|
|
$empStmt->execute([$id]);
|
|
$deadline['employee_ids'] = $empStmt->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
// Parse departments into array
|
|
$deadline['department_names'] = [];
|
|
if (!empty($deadline['departments'])) {
|
|
$deadline['department_names'] = array_map('trim', explode(',', $deadline['departments']));
|
|
}
|
|
|
|
// Get attachments
|
|
$attStmt = $pdo->prepare("SELECT id, original_name, mime_type, size, created_at FROM scad_deadline_attachments WHERE deadline_id = ? ORDER BY created_at DESC");
|
|
$attStmt->execute([$id]);
|
|
$deadline['attachments'] = $attStmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode(['success' => true, 'data' => $deadline]);
|
|
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
|
}
|