66 lines
1.9 KiB
PHP
66 lines
1.9 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$response = [
|
|
'success' => false,
|
|
'attachments' => [],
|
|
'message' => ''
|
|
];
|
|
|
|
try {
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
throw new Exception('ID matrice non valido');
|
|
}
|
|
|
|
$idmatrice = (int)$_GET['id'];
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$sql = "SELECT
|
|
id,
|
|
matrice_id,
|
|
file_name,
|
|
file_path,
|
|
file_type,
|
|
description,
|
|
sort_order,
|
|
created_at,
|
|
updated_at
|
|
FROM matrice_attachments
|
|
WHERE matrice_id = :matrice_id
|
|
ORDER BY sort_order ASC, id DESC";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([':matrice_id' => $idmatrice]);
|
|
|
|
$attachments = [];
|
|
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$relativePath = ltrim((string)$row['file_path'], '/\\');
|
|
|
|
$attachments[] = [
|
|
'id' => (int)$row['id'],
|
|
'matrice_id' => (int)$row['matrice_id'],
|
|
'file_name' => $row['file_name'],
|
|
'file_path' => $relativePath,
|
|
'file_url' => $relativePath,
|
|
'file_type' => $row['file_type'],
|
|
'description' => $row['description'] ?? '',
|
|
'sort_order' => (int)($row['sort_order'] ?? 0),
|
|
'created_at' => !empty($row['created_at']) ? date('d/m/Y H:i', strtotime($row['created_at'])) : '',
|
|
'updated_at' => !empty($row['updated_at']) ? date('d/m/Y H:i', strtotime($row['updated_at'])) : ''
|
|
];
|
|
}
|
|
|
|
$response['success'] = true;
|
|
$response['attachments'] = $attachments;
|
|
} catch (Throwable $e) {
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
|
exit;
|