52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/auth_check.php';
|
|
|
|
mnt_require_permission('maintenance.maintenances.view');
|
|
|
|
try {
|
|
$pdo = mnt_pdo();
|
|
|
|
$maintenanceId = (int)($_GET['maintenance_id'] ?? 0);
|
|
$interventionId = (int)($_GET['id'] ?? 0);
|
|
|
|
if ($interventionId > 0) {
|
|
$stmt = $pdo->prepare("SELECT * FROM maint_interventions WHERE id = ?");
|
|
$stmt->execute([$interventionId]);
|
|
$intervention = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$intervention) {
|
|
mnt_json_fail('Intervento non trovato.');
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT id, original_name FROM maint_intervention_files WHERE intervention_id = ?");
|
|
$stmt->execute([$interventionId]);
|
|
|
|
mnt_json_ok([
|
|
'intervention' => $intervention,
|
|
'files' => $stmt->fetchAll(PDO::FETCH_ASSOC),
|
|
]);
|
|
}
|
|
|
|
if ($maintenanceId <= 0) {
|
|
mnt_json_fail('ID non valido.');
|
|
}
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT i.*,
|
|
CONCAT(e.first_name, ' ', e.last_name) AS operator_full_name,
|
|
s.supplier_name,
|
|
(SELECT COUNT(*) FROM maint_intervention_files f WHERE f.intervention_id = i.id) AS file_count
|
|
FROM maint_interventions i
|
|
LEFT JOIN employees e ON e.id = i.operator_employee_id
|
|
LEFT JOIN suppliers s ON s.idsupplier = i.supplier_id
|
|
WHERE i.maintenance_id = ?
|
|
ORDER BY i.performed_at DESC, i.id DESC
|
|
");
|
|
$stmt->execute([$maintenanceId]);
|
|
|
|
mnt_json_ok(['interventions' => $stmt->fetchAll(PDO::FETCH_ASSOC)]);
|
|
} catch (Throwable $e) {
|
|
mnt_json_fail('Errore: ' . $e->getMessage());
|
|
}
|