change doc settingand tags

This commit is contained in:
Claudio 2025-06-05 09:33:46 +02:00
parent b5e9901b8e
commit 3e9262d6bf

View File

@ -22,6 +22,13 @@ $documents = [];
while ($row = $queryDocuments->fetch_assoc()) {
$documents[] = $row;
}
// Recupera l'elenco dei tag
$queryTags = $conn->query("SELECT tag_id, tag_name FROM tags ORDER BY tag_name ASC");
$tags = [];
while ($row = $queryTags->fetch_assoc()) {
$tags[$row['tag_id']] = $row['tag_name'];
}
?>
<!DOCTYPE html>
@ -36,8 +43,23 @@ while ($row = $queryDocuments->fetch_assoc()) {
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css">
<!-- Select2 CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
.page-content-wrapper {
padding-top: 70px;
}
.btn-block {
width: 100%;
}
.select2-container .select2-selection--multiple {
min-height: 38px;
}
</style>
</head>
<body class="fixed-left">
@ -48,7 +70,7 @@ while ($row = $queryDocuments->fetch_assoc()) {
<div class="content-page">
<div class="content">
<?php include('include/topbar.php'); ?>
<br>
<div class="page-content-wrapper">
<div class="container-fluid">
<div class="row mb-4">
@ -61,7 +83,6 @@ while ($row = $queryDocuments->fetch_assoc()) {
<button class="btn btn-outline-success btn-block shadow-sm" data-toggle="modal" data-target="#addDocumentModal">
<i class="mdi mdi-plus"></i> Aggiungi Documento
</button>
</div>
</div>
@ -79,11 +100,25 @@ while ($row = $queryDocuments->fetch_assoc()) {
<th>Sezione</th>
<th>Max Documenti</th>
<th>Obbligatorio</th>
<th>Tag</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($documents as $document) { ?>
<?php foreach ($documents as $document) {
// Prepara la query per recuperare i tag associati
$tagStmt = $conn->prepare("SELECT t.tag_id, t.tag_name FROM tags t
JOIN document_tags dt ON t.tag_id = dt.tag_id
WHERE dt.document_id = ?");
$tagStmt->bind_param("i", $document['document_id']);
$tagStmt->execute();
$tagResult = $tagStmt->get_result();
$documentTags = [];
while ($tagRow = $tagResult->fetch_assoc()) {
$documentTags[] = $tagRow['tag_name'];
}
$tagStmt->close();
?>
<tr>
<td><?php echo $document['document_id']; ?></td>
<td><?php echo htmlspecialchars($document['document_name']); ?></td>
@ -91,6 +126,7 @@ while ($row = $queryDocuments->fetch_assoc()) {
<td><?php echo htmlspecialchars($document['section_name']); ?></td>
<td><?php echo $document['max_documents']; ?></td>
<td><?php echo $document['is_required'] ? 'Sì' : 'No'; ?></td>
<td><?php echo implode(', ', $documentTags); ?></td>
<td>
<button
class="btn btn-sm btn-warning"
@ -102,15 +138,14 @@ while ($row = $queryDocuments->fetch_assoc()) {
data-section-id="<?php echo $document['idsections']; ?>"
data-max-documents="<?php echo htmlspecialchars($document['max_documents']); ?>"
data-is-required="<?php echo $document['is_required']; ?>"
data-notes="<?php echo htmlspecialchars($document['notes']); ?>">
data-notes="<?php echo htmlspecialchars($document['notes']); ?>"
data-tags="<?php echo htmlspecialchars(json_encode(array_column($documentTags, 'tag_id'))); ?>">
<i class="mdi mdi-pencil"></i>
</button>
<button class="btn btn-sm btn-danger delete-document" data-id="<?php echo $document['document_id']; ?>">
<i class="mdi mdi-delete"></i>
</button>
</td>
</tr>
<?php } ?>
@ -120,10 +155,11 @@ while ($row = $queryDocuments->fetch_assoc()) {
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modale: Modifica Documento -->
<div class="modal fade" id="editDocumentModal" tabindex="-1" role="dialog" aria-labelledby="editDocumentModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
@ -132,17 +168,14 @@ while ($row = $queryDocuments->fetch_assoc()) {
<div class="modal-header">
<h5 class="modal-title" id="editDocumentModalLabel">Modifica Documento</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- Nome Documento -->
<div class="form-group">
<label for="editDocumentName">Nome Documento</label>
<input type="text" class="form-control" id="editDocumentName" name="document_name" required>
</div>
<!-- Pagina -->
<div class="form-group">
<label for="editPageId">Pagina</label>
<select class="form-control" id="editPageId" name="page_id" required>
@ -154,8 +187,6 @@ while ($row = $queryDocuments->fetch_assoc()) {
?>
</select>
</div>
<!-- Sezione -->
<div class="form-group">
<label for="editSectionId">Sezione</label>
<select class="form-control" id="editSectionId" name="idsections">
@ -167,14 +198,10 @@ while ($row = $queryDocuments->fetch_assoc()) {
?>
</select>
</div>
<!-- Max Documenti -->
<div class="form-group">
<label for="editMaxDocuments">Max Documenti</label>
<input type="number" class="form-control" id="editMaxDocuments" name="max_documents" min="0">
</div>
<!-- Obbligatorio -->
<div class="form-group">
<label for="editIsRequired">Obbligatorio</label>
<select class="form-control" id="editIsRequired" name="is_required">
@ -182,8 +209,14 @@ while ($row = $queryDocuments->fetch_assoc()) {
<option value="1"></option>
</select>
</div>
<!-- Note -->
<div class="form-group">
<label for="editTags">Tag</label>
<select class="form-control" id="editTags" name="tags[]" multiple="multiple">
<?php foreach ($tags as $tagId => $tagName) {
echo "<option value='$tagId'>" . htmlspecialchars($tagName) . "</option>";
} ?>
</select>
</div>
<div class="form-group">
<label for="editNotes">Note</label>
<textarea class="form-control" id="editNotes" name="notes"></textarea>
@ -197,6 +230,7 @@ while ($row = $queryDocuments->fetch_assoc()) {
</div>
</div>
</div>
<!-- Modale: Aggiungi Documento -->
<div class="modal fade" id="addDocumentModal" tabindex="-1" role="dialog" aria-labelledby="addDocumentModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
@ -205,7 +239,7 @@ while ($row = $queryDocuments->fetch_assoc()) {
<div class="modal-header">
<h5 class="modal-title" id="addDocumentModalLabel">Aggiungi Documento</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
@ -246,6 +280,14 @@ while ($row = $queryDocuments->fetch_assoc()) {
<option value="1"></option>
</select>
</div>
<div class="form-group">
<label for="tags">Tag</label>
<select class="form-control" id="tags" name="tags[]" multiple="multiple">
<?php foreach ($tags as $tagId => $tagName) {
echo "<option value='$tagId'>" . htmlspecialchars($tagName) . "</option>";
} ?>
</select>
</div>
<div class="form-group">
<label for="notes">Note</label>
<textarea class="form-control" id="notes" name="notes"></textarea>
@ -263,69 +305,66 @@ while ($row = $queryDocuments->fetch_assoc()) {
<?php include('include/footer.php'); ?>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-rc.0/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('#documentsTable').DataTable();
$('#documentsTable').DataTable({
"pageLength": 10,
"language": {
"url": "//cdn.datatables.net/plug-ins/1.11.5/i18n/Italian.json"
}
});
// Inizializza Select2 per i tag
$('#tags').select2({
placeholder: "Seleziona o cerca tag",
allowClear: true,
tags: true
});
$('#editTags').select2({
placeholder: "Seleziona o cerca tag",
allowClear: true,
tags: true
});
$('#editDocumentModal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget);
// Recupera i dati dal pulsante
var documentId = button.data('id');
var documentName = button.data('name'); // Nome Documento
var documentName = button.data('name');
var pageId = button.data('page-id');
var sectionId = button.data('section-id'); // ID Sezione
var maxDocuments = button.data('max-documents'); // Max Documenti
var isRequired = button.data('is-required'); // Obbligatorio
var notes = button.data('notes'); // Note
var sectionId = button.data('section-id');
var maxDocuments = button.data('max-documents');
var isRequired = button.data('is-required');
var notes = button.data('notes');
var tags = button.data('tags') ? JSON.parse(button.data('tags')) : [];
// Debug (visualizza i dati in console)
console.log("Dati ricevuti dal pulsante:");
console.log({
console.log("Dati ricevuti dal pulsante:", {
documentId,
documentName,
pageId,
sectionId,
maxDocuments,
isRequired,
notes
notes,
tags
});
// Popola i campi del modale
$('#editDocumentId').val(documentId);
$('#editDocumentName').val(documentName); // Nome Documento
$('#editPageId').val(pageId); // Pagina
$('#editSectionId').val(sectionId); // Sezione
$('#editMaxDocuments').val(maxDocuments); // Max Documenti
$('#editIsRequired').val(isRequired); // Obbligatorio
$('#editNotes').val(notes); // Note
$('#editDocumentName').val(documentName);
$('#editPageId').val(pageId);
$('#editSectionId').val(sectionId);
$('#editMaxDocuments').val(maxDocuments);
$('#editIsRequired').val(isRequired);
$('#editNotes').val(notes);
$('#editTags').val(tags).trigger('change');
});
});
</script>
<script>
<?php if (isset($_GET['success'])) { ?>
Swal.fire({
icon: 'success',
title: 'Documento aggiunto',
text: 'Il documento è stato aggiunto con successo.',
});
<?php } elseif (isset($_GET['error'])) { ?>
Swal.fire({
icon: 'error',
title: 'Errore',
text: 'Si è verificato un errore durante l\'aggiunta del documento.',
});
<?php } ?>
</script>
<script>
$(document).ready(function() {
// Funzione di eliminazione con SweetAlert
$('.delete-document').on('click', function() {
var documentId = $(this).data('id'); // Recupera l'ID del documento
var documentId = $(this).data('id');
Swal.fire({
title: 'Sei sicuro?',
@ -338,7 +377,6 @@ while ($row = $queryDocuments->fetch_assoc()) {
cancelButtonText: 'Annulla'
}).then((result) => {
if (result.isConfirmed) {
// Esegui richiesta AJAX per eliminare
$.ajax({
url: 'delete-document.php',
type: 'POST',
@ -351,7 +389,6 @@ while ($row = $queryDocuments->fetch_assoc()) {
'Il documento è stato eliminato con successo.',
'success'
).then(() => {
// Ricarica la pagina per aggiornare la tabella
location.reload();
});
},
@ -367,10 +404,22 @@ while ($row = $queryDocuments->fetch_assoc()) {
});
});
});
<?php if (isset($_GET['success'])) { ?>
Swal.fire({
icon: 'success',
title: 'Documento aggiunto',
text: 'Il documento è stato aggiunto con successo.',
});
<?php } elseif (isset($_GET['error'])) { ?>
Swal.fire({
icon: 'error',
title: 'Errore',
text: 'Si è verificato un errore durante l\'aggiunta del documento.',
});
<?php } ?>
</script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap4.min.js"></script>