464 lines
19 KiB
PHP
464 lines
19 KiB
PHP
<?php include('../../include/headscript.php'); ?>
|
|
<?php
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$functions = $pdo->query("
|
|
SELECT f.*,
|
|
(SELECT COUNT(*) FROM scad_deadlines d WHERE d.function_id = f.id) AS deadline_count,
|
|
(SELECT COUNT(*) FROM scad_deadlines d WHERE d.function_id = f.id AND d.status <> 'completed') AS open_count
|
|
FROM scad_functions f
|
|
ORDER BY f.name ASC
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<?php
|
|
$scriptDir = dirname($_SERVER['SCRIPT_NAME']);
|
|
$baseHref = dirname(dirname($scriptDir)) . '/';
|
|
?>
|
|
<base href="<?= $baseHref ?>">
|
|
<?php include('../../cssinclude.php'); ?>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<title>Scadenzario - Funzioni</title>
|
|
<script>
|
|
if (window.innerWidth > 1024) {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.getElementById('appWrapper').classList.add('toggled');
|
|
});
|
|
}
|
|
</script>
|
|
<style>
|
|
:root {
|
|
--scad-primary: #5a8fd8;
|
|
--scad-primary-hover: #4578c0;
|
|
--scad-heading: #2c3e6b;
|
|
--scad-card-bg: linear-gradient(135deg, #f0f4ff 0%, #e8eeff 100%);
|
|
--scad-card-border: #dde4f0;
|
|
}
|
|
|
|
.scad-card {
|
|
border: none;
|
|
border-radius: 0.75rem;
|
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.scad-card .card-header {
|
|
background: var(--scad-card-bg);
|
|
border-bottom: 1px solid var(--scad-card-border);
|
|
padding: 1rem 1.25rem;
|
|
}
|
|
|
|
.scad-card .card-header h5 {
|
|
font-weight: 700;
|
|
color: var(--scad-heading);
|
|
margin: 0;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.scad-card .card-body {
|
|
padding: 1.25rem;
|
|
}
|
|
|
|
.btn-scad-primary {
|
|
background: var(--scad-primary);
|
|
border: none;
|
|
color: #fff;
|
|
font-weight: 600;
|
|
font-size: 0.85rem;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 0.5rem;
|
|
}
|
|
|
|
.btn-scad-primary:hover {
|
|
background: var(--scad-primary-hover);
|
|
color: #fff;
|
|
}
|
|
|
|
.btn-scad-outline {
|
|
background: transparent;
|
|
border: 1.5px solid var(--scad-primary);
|
|
color: var(--scad-primary);
|
|
font-weight: 600;
|
|
font-size: 0.85rem;
|
|
padding: 0.45rem 1rem;
|
|
border-radius: 0.5rem;
|
|
}
|
|
|
|
.btn-scad-outline:hover {
|
|
background: var(--scad-primary);
|
|
color: #fff;
|
|
}
|
|
|
|
.btn-action {
|
|
width: 32px;
|
|
height: 32px;
|
|
padding: 0;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border: none;
|
|
border-radius: 0.4rem;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.btn-action-edit {
|
|
background: rgba(90, 143, 216, 0.12);
|
|
color: var(--scad-primary);
|
|
}
|
|
|
|
.btn-action-edit:hover {
|
|
background: var(--scad-primary);
|
|
color: #fff;
|
|
}
|
|
|
|
.btn-action-delete {
|
|
background: rgba(220, 53, 69, 0.12);
|
|
color: #dc3545;
|
|
}
|
|
|
|
.btn-action-delete:hover {
|
|
background: #dc3545;
|
|
color: #fff;
|
|
}
|
|
|
|
.function-card {
|
|
background: #fff;
|
|
border: 1px solid var(--scad-card-border);
|
|
border-radius: 0.6rem;
|
|
padding: 0.85rem 0.95rem;
|
|
margin-bottom: 0.6rem;
|
|
}
|
|
|
|
.function-card .fc-name {
|
|
font-weight: 700;
|
|
color: var(--scad-heading);
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
.function-card .fc-stats {
|
|
display: flex;
|
|
gap: 0.75rem;
|
|
font-size: 0.8rem;
|
|
color: #6c757d;
|
|
margin: 0.5rem 0;
|
|
}
|
|
|
|
.function-card .fc-stats strong {
|
|
color: var(--scad-heading);
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 3rem 1rem;
|
|
color: #6c757d;
|
|
}
|
|
|
|
.empty-state i {
|
|
font-size: 3rem;
|
|
opacity: 0.3;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
@media (max-width: 575.98px) {
|
|
.scad-card .card-header {
|
|
flex-direction: column;
|
|
gap: 0.75rem;
|
|
align-items: flex-start !important;
|
|
}
|
|
|
|
.header-actions {
|
|
width: 100%;
|
|
}
|
|
|
|
.header-actions .btn {
|
|
width: 100%;
|
|
justify-content: center;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="wrapper" id="appWrapper">
|
|
<?php include('../../include/navbar.php'); ?>
|
|
<?php include('../../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="scadenzario/index.php">Scadenzario</a></li>
|
|
<li class="breadcrumb-item active" aria-current="page">Funzioni</li>
|
|
</ol>
|
|
</nav>
|
|
|
|
<div class="card scad-card">
|
|
<div class="card-header d-flex align-items-center justify-content-between flex-wrap gap-2">
|
|
<h5><i class="fa-solid fa-briefcase me-2"></i>Funzioni</h5>
|
|
|
|
<div class="header-actions d-flex gap-2 flex-wrap">
|
|
<a href="scadenzario/index.php" class="btn btn-scad-outline d-inline-flex align-items-center gap-2">
|
|
<i class="fa-solid fa-arrow-left"></i><span>Scadenzario</span>
|
|
</a>
|
|
|
|
<button class="btn btn-scad-primary d-inline-flex align-items-center gap-2" id="btnAddFunction">
|
|
<i class="fa-solid fa-plus"></i><span>Nuova Funzione</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<?php if (count($functions) === 0): ?>
|
|
<div class="empty-state">
|
|
<i class="fa-solid fa-briefcase"></i>
|
|
<p>Nessuna funzione definita.<br>Clicca <strong>"Nuova Funzione"</strong> per aggiungere la prima.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
|
|
<div id="functionsList">
|
|
|
|
<div class="d-md-none">
|
|
<?php foreach ($functions as $f): ?>
|
|
<div class="function-card"
|
|
data-id="<?= (int)$f['id'] ?>"
|
|
data-name="<?= htmlspecialchars($f['name'], ENT_QUOTES, 'UTF-8') ?>"
|
|
data-description="<?= htmlspecialchars($f['description'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
|
|
data-status="<?= htmlspecialchars($f['status'], ENT_QUOTES, 'UTF-8') ?>"
|
|
data-in-use="<?= (int)$f['deadline_count'] ?>">
|
|
|
|
<div class="fc-name"><?= htmlspecialchars($f['name'], ENT_QUOTES, 'UTF-8') ?></div>
|
|
|
|
<?php if (!empty($f['description'])): ?>
|
|
<div class="text-muted small mt-1"><?= htmlspecialchars($f['description'], ENT_QUOTES, 'UTF-8') ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="fc-stats">
|
|
<span>Scadenze: <strong><?= (int)$f['deadline_count'] ?></strong></span>
|
|
<span>Aperte: <strong><?= (int)$f['open_count'] ?></strong></span>
|
|
</div>
|
|
|
|
<div class="d-flex gap-1 justify-content-end">
|
|
<button class="btn-action btn-action-edit btn-edit" title="Modifica">
|
|
<i class="fa-solid fa-pen"></i>
|
|
</button>
|
|
<button class="btn-action btn-action-delete btn-delete" title="Elimina">
|
|
<i class="fa-solid fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div class="d-none d-md-block">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Nome</th>
|
|
<th>Descrizione</th>
|
|
<th class="text-center" style="width:120px">Scadenze</th>
|
|
<th class="text-center" style="width:120px">Aperte</th>
|
|
<th class="text-center" style="width:120px">Azioni</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($functions as $f): ?>
|
|
<tr data-id="<?= (int)$f['id'] ?>"
|
|
data-name="<?= htmlspecialchars($f['name'], ENT_QUOTES, 'UTF-8') ?>"
|
|
data-description="<?= htmlspecialchars($f['description'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
|
|
data-status="<?= htmlspecialchars($f['status'], ENT_QUOTES, 'UTF-8') ?>"
|
|
data-in-use="<?= (int)$f['deadline_count'] ?>">
|
|
|
|
<td class="fw-semibold" style="color:var(--scad-heading)">
|
|
<?= htmlspecialchars($f['name'], ENT_QUOTES, 'UTF-8') ?>
|
|
</td>
|
|
<td class="text-muted">
|
|
<?= htmlspecialchars($f['description'] ?? '—', ENT_QUOTES, 'UTF-8') ?>
|
|
</td>
|
|
<td class="text-center"><?= (int)$f['deadline_count'] ?></td>
|
|
<td class="text-center"><?= (int)$f['open_count'] ?></td>
|
|
<td class="text-center">
|
|
<div class="d-inline-flex gap-1">
|
|
<button class="btn-action btn-action-edit btn-edit" title="Modifica">
|
|
<i class="fa-solid fa-pen"></i>
|
|
</button>
|
|
<button class="btn-action btn-action-delete btn-delete" title="Elimina">
|
|
<i class="fa-solid fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<?php include('../../include/footer.php'); ?>
|
|
</div>
|
|
|
|
<div class="modal fade" id="functionModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="functionModalTitle">Nuova Funzione</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Chiudi"></button>
|
|
</div>
|
|
|
|
<form id="functionForm">
|
|
<div class="modal-body">
|
|
<input type="hidden" id="functionId" name="id" value="">
|
|
|
|
<div class="mb-3">
|
|
<label for="functionName" class="form-label fw-semibold">Nome <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="functionName" name="name" maxlength="255" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="functionDescription" class="form-label fw-semibold">Descrizione</label>
|
|
<textarea class="form-control" id="functionDescription" name="description" rows="3"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Annulla</button>
|
|
<button type="submit" class="btn btn-scad-primary">Salva</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include('../../jsinclude.php'); ?>
|
|
|
|
<script>
|
|
$(function() {
|
|
function openModal(data) {
|
|
const isEdit = !!data;
|
|
|
|
$('#functionModalTitle').text(isEdit ? 'Modifica Funzione' : 'Nuova Funzione');
|
|
$('#functionId').val(isEdit ? data.id : '');
|
|
$('#functionName').val(isEdit ? data.name : '');
|
|
$('#functionDescription').val(isEdit ? data.description : '');
|
|
|
|
new bootstrap.Modal('#functionModal').show();
|
|
}
|
|
|
|
$('#btnAddFunction').on('click', function() {
|
|
openModal(null);
|
|
});
|
|
|
|
$('#functionsList').on('click', '.btn-edit', function() {
|
|
const $row = $(this).closest('[data-id]');
|
|
|
|
openModal({
|
|
id: $row.data('id'),
|
|
name: $row.data('name'),
|
|
description: $row.data('description')
|
|
});
|
|
});
|
|
|
|
$('#functionsList').on('click', '.btn-delete', function() {
|
|
const $row = $(this).closest('[data-id]');
|
|
const inUse = parseInt($row.data('in-use') || 0, 10);
|
|
const name = $row.data('name');
|
|
|
|
if (inUse > 0) {
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Impossibile eliminare',
|
|
text: `La funzione "${name}" è utilizzata in ${inUse} scadenz${inUse === 1 ? 'a' : 'e'}.`
|
|
});
|
|
return;
|
|
}
|
|
|
|
Swal.fire({
|
|
title: `Eliminare "${name}"?`,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Elimina',
|
|
cancelButtonText: 'Annulla',
|
|
confirmButtonColor: '#dc3545'
|
|
}).then(function(result) {
|
|
if (!result.isConfirmed) return;
|
|
|
|
$.post('scadenzario/functions/ajax/delete_function.php', {
|
|
id: $row.data('id')
|
|
})
|
|
.done(function(res) {
|
|
if (res.success) {
|
|
location.reload();
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Errore',
|
|
text: res.message
|
|
});
|
|
}
|
|
})
|
|
.fail(function() {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Errore di rete'
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
$('#functionForm').on('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const payload = {
|
|
id: $('#functionId').val(),
|
|
name: $('#functionName').val().trim(),
|
|
description: $('#functionDescription').val().trim()
|
|
};
|
|
|
|
if (!payload.name) {
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Nome obbligatorio'
|
|
});
|
|
return;
|
|
}
|
|
|
|
$.post('scadenzario/functions/ajax/save_function.php', payload)
|
|
.done(function(res) {
|
|
if (res.success) {
|
|
location.reload();
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Errore',
|
|
text: res.message
|
|
});
|
|
}
|
|
})
|
|
.fail(function() {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Errore di rete'
|
|
});
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|