Files
zibo-dashboard/public/userarea/manutenzioni/equipment.php
T
2026-08-12 21:29:55 +03:00

561 lines
36 KiB
PHP

<?php include(__DIR__ . '/../include/headscript.php'); ?>
<?php
require_once __DIR__ . '/include/functions.php';
$pdo = mnt_pdo();
if (!userCan('maintenance.equipment.view')) {
http_response_code(403);
exit('Permesso negato.');
}
$canManage = userCan('maintenance.manage');
$canSeeMaintenances = userCan('maintenance.maintenances.view');
$equipmentId = isset($_GET['id']) && is_numeric($_GET['id']) ? (int)$_GET['id'] : 0;
$stmt = $pdo->prepare("
SELECT e.*,
c.name AS category_name, c.color AS category_color,
pl.name AS line_name, pl.line_number,
d.name AS department_name,
cf.stored_name AS cover_stored
FROM inv_equipment e
LEFT JOIN inv_categories c ON c.id = e.category_id
LEFT JOIN production_lines pl ON pl.id = e.line_id
LEFT JOIN departments d ON d.id = e.department_id
LEFT JOIN inv_equipment_files cf ON cf.id = e.cover_file_id
WHERE e.id = ?
");
$stmt->execute([$equipmentId]);
$equipment = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$equipment) {
http_response_code(404);
exit('Attrezzatura non trovata.');
}
// Photos and documents
$stmt = $pdo->prepare("SELECT * FROM inv_equipment_files WHERE equipment_id = ? ORDER BY created_at ASC");
$stmt->execute([$equipmentId]);
$files = $stmt->fetchAll(PDO::FETCH_ASSOC);
$photos = array_values(array_filter($files, fn($f) => $f['kind'] === 'photo'));
$documents = array_values(array_filter($files, fn($f) => $f['kind'] !== 'photo'));
// Maintenances
$maintenances = [];
$interventionsByMaintenance = [];
if ($canSeeMaintenances) {
$stmt = $pdo->prepare("
SELECT m.*,
CONCAT(a.first_name, ' ', a.last_name) AS assignee_name,
CONCAT(s.first_name, ' ', s.last_name) AS supervisor_name,
sup.supplier_name,
(SELECT COUNT(*) FROM maint_interventions i WHERE i.maintenance_id = m.id) AS intervention_count,
(SELECT COUNT(*) FROM maint_maintenance_files f WHERE f.maintenance_id = m.id) AS file_count
FROM maint_maintenances m
LEFT JOIN employees a ON a.id = m.assignee_employee_id
LEFT JOIN employees s ON s.id = m.supervisor_employee_id
LEFT JOIN suppliers sup ON sup.idsupplier = m.supplier_id
WHERE m.equipment_id = ?
ORDER BY m.is_active DESC, m.code ASC, m.title ASC
");
$stmt->execute([$equipmentId]);
$maintenances = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = $pdo->prepare("
SELECT i.*,
CONCAT(e.first_name, ' ', e.last_name) AS operator_full_name,
sup.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 sup ON sup.idsupplier = i.supplier_id
WHERE i.equipment_id = ?
ORDER BY i.performed_at DESC, i.id DESC
");
$stmt->execute([$equipmentId]);
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $intervention) {
$interventionsByMaintenance[(int)$intervention['maintenance_id']][] = $intervention;
}
}
$formData = mnt_form_data($pdo);
$statuses = mnt_equipment_statuses();
$statusLabels = mnt_lookup($pdo, 'maint_status', ['planned' => 'Pianificato', 'in_progress' => 'In corso', 'completed' => 'Completato']);
$resultLabels = mnt_lookup($pdo, 'maint_result', []);
$typeLabels = mnt_intervention_types();
$executionLabels = mnt_execution_types();
$MNT_TITLE = $equipment['name'];
?>
<!doctype html>
<html lang="it">
<head>
<?php include __DIR__ . '/include/page_head.php'; ?>
</head>
<body>
<?php include __DIR__ . '/include/wrapper_open.php'; ?>
<?php include(__DIR__ . '/../include/navbar.php'); ?>
<?php include(__DIR__ . '/../include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<nav aria-label="breadcrumb" class="mb-3">
<ol class="breadcrumb" style="background:transparent;padding:0;margin:0;font-size:0.85rem">
<li class="breadcrumb-item"><a href="manutenzioni/index.php">Registro attrezzature</a></li>
<li class="breadcrumb-item active" aria-current="page"><?= mnt_h($equipment['name']) ?></li>
</ol>
</nav>
<div class="card mnt-card mb-3">
<div class="card-header d-flex align-items-center justify-content-between flex-wrap gap-2">
<h5 class="d-flex align-items-center gap-2 flex-wrap">
<span class="mnt-cat-dot" style="background: <?= mnt_h($equipment['category_color'] ?? '#adb5bd') ?>"></span>
<?= mnt_h($equipment['name']) ?>
<span class="mnt-badge mnt-badge-status-<?= mnt_h($equipment['status']) ?>">
<?= mnt_h($statuses[$equipment['status']] ?? $equipment['status']) ?>
</span>
</h5>
<div class="header-actions d-flex gap-2 flex-wrap">
<a href="manutenzioni/print.php?id=<?= (int)$equipment['id'] ?>" target="_blank"
class="btn btn-mnt-outline d-inline-flex align-items-center gap-2">
<i class="fa-solid fa-print"></i><span>Scheda PDF</span>
</a>
<?php if ($canManage): ?>
<button class="btn btn-mnt-outline d-inline-flex align-items-center gap-2" id="btnEditEquipment">
<i class="fa-solid fa-pen"></i><span>Modifica</span>
</button>
<button class="btn btn-mnt-primary d-inline-flex align-items-center gap-2" id="btnAddMaintenance">
<i class="fa-solid fa-plus"></i><span>Nuova manutenzione</span>
</button>
<?php endif; ?>
</div>
</div>
</div>
<div class="row g-3">
<!-- ------------------------------------------------ left: data -->
<div class="col-12 col-lg-4">
<div class="card mnt-card mb-3">
<div class="card-header"><h5><i class="fa-solid fa-circle-info me-2"></i>Dati</h5></div>
<div class="card-body">
<?php if (!empty($equipment['cover_stored'])): ?>
<img src="manutenzioni/ajax/download_file.php?scope=equipment&id=<?= (int)$equipment['cover_file_id'] ?>"
alt="" class="w-100 mb-3" style="border-radius:.5rem;object-fit:cover;max-height:220px">
<?php endif; ?>
<dl class="mb-0">
<div class="mnt-kv"><dt>Categoria</dt><dd><?= mnt_h($equipment['category_name'] ?? '—') ?></dd></div>
<?php if ($equipment['line_name']): ?>
<div class="mnt-kv"><dt>Linea</dt><dd>Linea <?= (int)$equipment['line_number'] ?> — <?= mnt_h($equipment['line_name']) ?></dd></div>
<?php endif; ?>
<div class="mnt-kv"><dt>Matricola</dt><dd><?= mnt_h($equipment['registration_number'] ?: '—') ?></dd></div>
<div class="mnt-kv"><dt>Numero di serie</dt><dd><?= mnt_h($equipment['serial_number'] ?: '—') ?></dd></div>
<div class="mnt-kv"><dt>Lotto / partita</dt><dd><?= mnt_h($equipment['batch_lot'] ?: '—') ?></dd></div>
<div class="mnt-kv"><dt>Costruttore</dt><dd><?= mnt_h($equipment['manufacturer'] ?: '—') ?></dd></div>
<div class="mnt-kv"><dt>Tipo</dt><dd><?= mnt_h($equipment['tool_type'] ?: '—') ?></dd></div>
<div class="mnt-kv"><dt>Acquisto</dt><dd><?= mnt_format_date($equipment['purchase_date']) ?></dd></div>
<div class="mnt-kv"><dt>Messa in servizio</dt><dd><?= mnt_format_date($equipment['commissioning_date']) ?></dd></div>
<div class="mnt-kv"><dt>Reparto</dt><dd><?= mnt_h($equipment['department_name'] ?: '—') ?></dd></div>
<div class="mnt-kv"><dt>Ubicazione</dt><dd><?= mnt_h($equipment['location'] ?: '—') ?></dd></div>
</dl>
<?php if ($equipment['description']): ?>
<div class="mnt-section-title mt-3">Descrizione</div>
<div class="small"><?= nl2br(mnt_h($equipment['description'])) ?></div>
<?php endif; ?>
<?php if ($equipment['notes']): ?>
<div class="mnt-section-title mt-3">Note</div>
<div class="small"><?= nl2br(mnt_h($equipment['notes'])) ?></div>
<?php endif; ?>
</div>
</div>
<div class="card mnt-card mb-3">
<div class="card-header d-flex align-items-center justify-content-between">
<h5><i class="fa-solid fa-images me-2"></i>Foto</h5>
<?php if ($canManage): ?>
<button class="btn btn-mnt-outline btn-sm" id="btnAddPhotos">
<i class="fa-solid fa-plus"></i>
</button>
<input type="file" id="photoInput" accept="image/*" multiple hidden>
<?php endif; ?>
</div>
<div class="card-body">
<?php if (!$photos): ?>
<p class="text-muted small mb-0">Nessuna foto caricata.</p>
<?php else: ?>
<div class="mnt-photo-grid">
<?php foreach ($photos as $photo): ?>
<div class="mnt-photo-item <?= (int)$equipment['cover_file_id'] === (int)$photo['id'] ? 'is-cover' : '' ?>">
<a href="manutenzioni/ajax/download_file.php?scope=equipment&id=<?= (int)$photo['id'] ?>" target="_blank">
<img src="manutenzioni/ajax/download_file.php?scope=equipment&id=<?= (int)$photo['id'] ?>"
alt="<?= mnt_h($photo['original_name']) ?>">
</a>
<?php if ($canManage): ?>
<div class="photo-tools">
<button class="btn-set-cover" data-id="<?= (int)$photo['id'] ?>" title="Usa come copertina">
<i class="fa-solid fa-star"></i>
</button>
<button class="btn-del-photo" data-id="<?= (int)$photo['id'] ?>" title="Elimina">
<i class="fa-solid fa-trash"></i>
</button>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<div class="card mnt-card">
<div class="card-header d-flex align-items-center justify-content-between">
<h5><i class="fa-solid fa-folder-open me-2"></i>Documenti</h5>
<?php if ($canManage): ?>
<button class="btn btn-mnt-outline btn-sm" id="btnAddDocs">
<i class="fa-solid fa-plus"></i>
</button>
<input type="file" id="docInput" multiple hidden>
<?php endif; ?>
</div>
<div class="card-body">
<?php if (!$documents): ?>
<p class="text-muted small mb-0">Nessun documento caricato.</p>
<?php else: ?>
<?php foreach ($documents as $document): ?>
<div class="mnt-file-row">
<i class="fa-solid fa-file text-muted"></i>
<a class="file-name" target="_blank"
href="manutenzioni/ajax/download_file.php?scope=equipment&id=<?= (int)$document['id'] ?>">
<?= mnt_h($document['original_name']) ?>
</a>
<?php if ($canManage): ?>
<button class="btn-action btn-action-delete btn-del-doc" data-id="<?= (int)$document['id'] ?>">
<i class="fa-solid fa-trash"></i>
</button>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<!-- --------------------------------------- right: maintenances -->
<div class="col-12 col-lg-8">
<div class="card mnt-card">
<div class="card-header"><h5><i class="fa-solid fa-screwdriver-wrench me-2"></i>Manutenzioni</h5></div>
<div class="card-body">
<?php if (!$canSeeMaintenances): ?>
<p class="text-muted small mb-0">Non hai i permessi per vedere le manutenzioni.</p>
<?php elseif (!$maintenances): ?>
<div class="empty-state">
<i class="fa-solid fa-screwdriver-wrench"></i>
<p>Nessuna manutenzione definita per questa attrezzatura.<br>
Un'attrezzatura senza manutenzioni è esclusa dalle pianificazioni.</p>
</div>
<?php else: ?>
<div id="maintenanceList">
<?php foreach ($maintenances as $maintenance): ?>
<?php
$state = mnt_due_state($maintenance['next_due_date'], (int)$maintenance['alert_days']);
$badge = mnt_due_badge($state, $maintenance['frequency_unit']);
$interventions = $interventionsByMaintenance[(int)$maintenance['id']] ?? [];
?>
<div class="mnt-item-card" data-id="<?= (int)$maintenance['id'] ?>"
style="--row-color: <?= $maintenance['is_critical'] ? '#dc3545' : 'var(--mnt-primary)' ?>;<?= (int)$maintenance['is_active'] === 0 ? 'opacity:.6' : '' ?>">
<div class="d-flex justify-content-between align-items-start gap-2 flex-wrap">
<div class="flex-grow-1">
<div class="ic-title">
<?php if ($maintenance['code']): ?>
<span class="mnt-badge mnt-badge-soft me-1"><?= mnt_h($maintenance['code']) ?></span>
<?php endif; ?>
<?= mnt_h($maintenance['title']) ?>
<?php if ($maintenance['is_critical']): ?>
<span class="mnt-badge mnt-badge-critical ms-1">Critica</span>
<?php endif; ?>
<?php if ((int)$maintenance['is_active'] === 0): ?>
<span class="mnt-badge mnt-badge-none ms-1">Disattivata</span>
<?php endif; ?>
</div>
<div class="ic-meta">
<?= mnt_h($typeLabels[$maintenance['intervention_type']] ?? '') ?> ·
<?= mnt_h($executionLabels[$maintenance['execution_type']] ?? '') ?>
<?php if ($maintenance['supplier_name']): ?>
(<?= mnt_h($maintenance['supplier_name']) ?>)
<?php endif; ?>
· <?= mnt_h(mnt_format_frequency(
$maintenance['frequency_value'] !== null ? (int)$maintenance['frequency_value'] : null,
$maintenance['frequency_unit'],
$maintenance['frequency_note']
)) ?>
</div>
<div class="ic-meta">
Ultimo: <strong><?= mnt_format_date($maintenance['last_done_date']) ?></strong> ·
Prossimo: <strong><?= mnt_format_date($maintenance['next_due_date']) ?></strong>
<span class="mnt-badge <?= $badge['class'] ?> ms-1"><?= $badge['label'] ?></span>
</div>
<?php if ($maintenance['assignee_name'] || $maintenance['supervisor_name']): ?>
<div class="ic-meta">
<?php if ($maintenance['assignee_name']): ?>
Incaricato: <strong><?= mnt_h($maintenance['assignee_name']) ?></strong>
<?php endif; ?>
<?php if ($maintenance['supervisor_name']): ?>
· Responsabile: <strong><?= mnt_h($maintenance['supervisor_name']) ?></strong>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($maintenance['description']): ?>
<div class="ic-meta"><?= nl2br(mnt_h($maintenance['description'])) ?></div>
<?php endif; ?>
<?php if ((int)$maintenance['file_count'] > 0): ?>
<div class="ic-meta"><i class="fa-solid fa-paperclip"></i> <?= (int)$maintenance['file_count'] ?> istruzioni</div>
<?php endif; ?>
</div>
<div class="d-flex gap-1 flex-shrink-0">
<?php if ($canManage): ?>
<button class="btn-action btn-action-done btn-register" title="Registra intervento">
<i class="fa-solid fa-check"></i>
</button>
<button class="btn-action btn-action-edit btn-edit-maintenance" title="Modifica">
<i class="fa-solid fa-pen"></i>
</button>
<button class="btn-action btn-action-delete btn-delete-maintenance"
title="Elimina" data-title="<?= mnt_h($maintenance['title']) ?>"
data-count="<?= (int)$maintenance['intervention_count'] ?>">
<i class="fa-solid fa-trash"></i>
</button>
<?php endif; ?>
</div>
</div>
<?php if ($interventions): ?>
<div class="mt-3">
<button class="btn btn-sm btn-light w-100 btn-toggle-history" type="button">
<i class="fa-solid fa-clock-rotate-left me-1"></i>
Storico interventi (<?= count($interventions) ?>)
</button>
<div class="mnt-timeline mt-3" style="display:none">
<?php foreach ($interventions as $intervention): ?>
<div class="mnt-timeline-item" data-intervention-id="<?= (int)$intervention['id'] ?>">
<div class="tl-date">
<?= mnt_format_date($intervention['performed_at']) ?>
· <?= mnt_h($statusLabels[$intervention['status']] ?? $intervention['status']) ?>
<?php if ($intervention['result']): ?>
· <?= mnt_h($resultLabels[$intervention['result']] ?? $intervention['result']) ?>
<?php endif; ?>
</div>
<div class="tl-body">
<?php
$operator = $intervention['operator_full_name'] ?: $intervention['operator_name'];
?>
<?php if ($operator): ?>
<strong><?= mnt_h($operator) ?></strong>
<?php endif; ?>
<?php if ($intervention['supplier_name']): ?>
<span class="text-muted">(<?= mnt_h($intervention['supplier_name']) ?>)</span>
<?php endif; ?>
<?php if ($intervention['notes']): ?>
<div><?= nl2br(mnt_h($intervention['notes'])) ?></div>
<?php endif; ?>
<?php if ($intervention['materials']): ?>
<div class="small text-muted">Materiali: <?= mnt_h($intervention['materials']) ?></div>
<?php endif; ?>
<div class="d-flex align-items-center gap-2 mt-1 flex-wrap">
<?php if ($intervention['signature_path']): ?>
<img src="manutenzioni/ajax/download_file.php?scope=signature&id=<?= (int)$intervention['id'] ?>"
alt="Firma" style="height:38px;border:1px solid #e6eef0;border-radius:.3rem;background:#fff">
<?php endif; ?>
<?php if ((int)$intervention['file_count'] > 0): ?>
<span class="small text-muted"><i class="fa-solid fa-paperclip"></i> <?= (int)$intervention['file_count'] ?></span>
<?php endif; ?>
<?php if ($canManage): ?>
<button class="btn-action btn-action-edit btn-edit-intervention" title="Modifica">
<i class="fa-solid fa-pen"></i>
</button>
<button class="btn-action btn-action-delete btn-delete-intervention" title="Elimina">
<i class="fa-solid fa-trash"></i>
</button>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include(__DIR__ . '/../include/footer.php'); ?>
</div>
<?php if ($canManage): ?>
<?php include __DIR__ . '/include/equipment_modal.php'; ?>
<?php include __DIR__ . '/include/maintenance_modal.php'; ?>
<?php include __DIR__ . '/include/intervention_modal.php'; ?>
<?php endif; ?>
<?php include(__DIR__ . '/../jsinclude.php'); ?>
<script>
$(function () {
const EQUIPMENT_ID = <?= (int)$equipment['id'] ?>;
const EQUIPMENT_NAME = <?= json_encode($equipment['name'], JSON_UNESCAPED_UNICODE) ?>;
$('#maintenanceList').on('click', '.btn-toggle-history', function () {
$(this).next('.mnt-timeline').slideToggle(150);
});
<?php if ($canManage): ?>
// ---------------------------------------------------- equipment
$('#btnEditEquipment').on('click', function () {
$.getJSON('manutenzioni/ajax/get_equipment.php', { id: EQUIPMENT_ID })
.done(res => {
if (res.success) { mntOpenEquipmentModal(res.equipment); }
else { Swal.fire({ icon: 'error', title: 'Errore', text: res.message }); }
});
});
function uploadEquipmentFiles(input, kind) {
if (!input.files.length) return;
const form = new FormData();
form.append('scope', 'equipment');
form.append('owner_id', EQUIPMENT_ID);
form.append('kind', kind);
Array.from(input.files).forEach(f => form.append('files[]', f));
$.ajax({
url: 'manutenzioni/ajax/upload_file.php',
method: 'POST', data: form, processData: false, contentType: false, dataType: 'json'
}).done(res => {
if (res.success) { location.reload(); }
else { Swal.fire({ icon: 'error', title: 'Errore', text: res.message }); }
}).fail(() => Swal.fire({ icon: 'error', title: 'Errore di rete' }));
}
$('#btnAddPhotos').on('click', () => $('#photoInput').click());
$('#photoInput').on('change', function () { uploadEquipmentFiles(this, 'photo'); });
$('#btnAddDocs').on('click', () => $('#docInput').click());
$('#docInput').on('change', function () { uploadEquipmentFiles(this, 'file'); });
$('.btn-set-cover').on('click', function () {
$.post('manutenzioni/ajax/set_cover.php', { file_id: $(this).data('id') })
.done(res => res.success ? location.reload() : Swal.fire({ icon: 'error', title: 'Errore', text: res.message }));
});
$('.btn-del-photo, .btn-del-doc').on('click', function () {
const id = $(this).data('id');
Swal.fire({
title: 'Eliminare il file?', icon: 'warning', showCancelButton: true,
confirmButtonText: 'Elimina', cancelButtonText: 'Annulla', confirmButtonColor: '#dc3545'
}).then(r => {
if (!r.isConfirmed) return;
$.post('manutenzioni/ajax/delete_file.php', { scope: 'equipment', id: id })
.done(res => res.success ? location.reload() : Swal.fire({ icon: 'error', title: 'Errore', text: res.message }));
});
});
// -------------------------------------------------- maintenance
$('#btnAddMaintenance').on('click', function () {
mntOpenMaintenanceModal(null, EQUIPMENT_ID);
});
$('#maintenanceList').on('click', '.btn-edit-maintenance', function () {
const id = $(this).closest('[data-id]').data('id');
$.getJSON('manutenzioni/ajax/get_maintenance.php', { id: id })
.done(res => {
if (!res.success) { Swal.fire({ icon: 'error', title: 'Errore', text: res.message }); return; }
const data = res.maintenance;
data.files = res.files;
mntOpenMaintenanceModal(data, EQUIPMENT_ID);
});
});
$('#maintenanceList').on('click', '.btn-delete-maintenance', function () {
const $btn = $(this);
const id = $btn.closest('[data-id]').data('id');
const count = parseInt($btn.data('count') || 0, 10);
Swal.fire({
title: `Eliminare "${$btn.data('title')}"?`,
html: count > 0 ? `<p>Verranno eliminati anche <strong>${count}</strong> interventi registrati.</p>` : '',
icon: 'warning', showCancelButton: true,
confirmButtonText: 'Elimina', cancelButtonText: 'Annulla', confirmButtonColor: '#dc3545'
}).then(r => {
if (!r.isConfirmed) return;
$.post('manutenzioni/ajax/delete_maintenance.php', { id: id })
.done(res => res.success ? location.reload() : Swal.fire({ icon: 'error', title: 'Errore', text: res.message }));
});
});
// ------------------------------------------------- interventions
$('#maintenanceList').on('click', '.btn-register', function () {
const id = $(this).closest('[data-id]').data('id');
$.getJSON('manutenzioni/ajax/get_maintenance.php', { id: id })
.done(res => {
if (!res.success) { Swal.fire({ icon: 'error', title: 'Errore', text: res.message }); return; }
mntOpenInterventionModal(null, {
id: res.maintenance.id,
title: res.maintenance.title,
equipment_name: EQUIPMENT_NAME,
supplier_id: res.maintenance.supplier_id
});
});
});
$('#maintenanceList').on('click', '.btn-edit-intervention', function () {
const interventionId = $(this).closest('[data-intervention-id]').data('intervention-id');
const maintenanceId = $(this).closest('[data-id]').data('id');
$.getJSON('manutenzioni/ajax/get_interventions.php', { id: interventionId })
.done(res => {
if (!res.success) { Swal.fire({ icon: 'error', title: 'Errore', text: res.message }); return; }
const data = res.intervention;
data.files = res.files;
mntOpenInterventionModal(data, {
id: maintenanceId,
title: '',
equipment_name: EQUIPMENT_NAME
});
});
});
$('#maintenanceList').on('click', '.btn-delete-intervention', function () {
const interventionId = $(this).closest('[data-intervention-id]').data('intervention-id');
Swal.fire({
title: 'Eliminare l\'intervento?',
text: 'La data della prossima manutenzione verrà ricalcolata.',
icon: 'warning', showCancelButton: true,
confirmButtonText: 'Elimina', cancelButtonText: 'Annulla', confirmButtonColor: '#dc3545'
}).then(r => {
if (!r.isConfirmed) return;
$.post('manutenzioni/ajax/delete_intervention.php', { id: interventionId })
.done(res => res.success ? location.reload() : Swal.fire({ icon: 'error', title: 'Errore', text: res.message }));
});
});
<?php endif; ?>
});
</script>
</body>
</html>