update documenti obbligatori
This commit is contained in:
parent
1da7ee5208
commit
6749663730
@ -13,6 +13,9 @@ $idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
// Recupera lo slug dalla richiesta
|
||||
$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal';
|
||||
|
||||
// Recupera il parametro showOnlyRequired
|
||||
$showOnlyRequired = isset($_GET['showOnlyRequired']) && $_GET['showOnlyRequired'] === 'true';
|
||||
|
||||
// Recupera i dettagli della casa (per verifica accesso)
|
||||
$queryHome = $conn->prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?");
|
||||
$queryHome->bind_param('ii', $idhome, $iduserlogin);
|
||||
@ -40,20 +43,26 @@ if (!$pageData) {
|
||||
$page_id = $pageData['idpages'];
|
||||
|
||||
// Recupera i documenti associati al `page_id`, con le sezioni
|
||||
$queryDocuments = $conn->prepare("
|
||||
$sql = "
|
||||
SELECT d.*, s.section_name AS section_name
|
||||
FROM documents d
|
||||
LEFT JOIN sections s ON d.idsections = s.idsections
|
||||
WHERE d.page_id = ?
|
||||
ORDER BY s.section_name, d.document_name
|
||||
");
|
||||
";
|
||||
if ($showOnlyRequired) {
|
||||
$sql .= " AND d.is_required = 1";
|
||||
}
|
||||
$sql .= " ORDER BY s.section_name, d.document_name";
|
||||
|
||||
$queryDocuments = $conn->prepare($sql);
|
||||
$queryDocuments->bind_param('i', $page_id);
|
||||
$queryDocuments->execute();
|
||||
$resultDocuments = $queryDocuments->get_result();
|
||||
|
||||
$documents = [];
|
||||
while ($row = $resultDocuments->fetch_assoc()) {
|
||||
$documents[$row['section_name']][] = $row;
|
||||
$sectionName = $row['section_name'] ?: 'Senza sezione';
|
||||
$documents[$sectionName][] = $row;
|
||||
}
|
||||
|
||||
// Recupera i documenti già caricati per questa casa
|
||||
|
||||
@ -37,22 +37,35 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-12 col-md-6 text-center text-md-start">
|
||||
<label for="pageSelectDropdown" class="fw-bold d-block mb-2">Seleziona Categoria:</label>
|
||||
<select id="pageSelectDropdown" class="form-control w-100 w-md-auto">
|
||||
<?php foreach ($pages as $page) { ?>
|
||||
<option value="<?php echo htmlspecialchars($page['slug']); ?>"
|
||||
<?php echo ($docpage === $page['slug']) ? 'selected' : ''; ?>>
|
||||
<?php echo ucfirst(htmlspecialchars($page['namepages'])); ?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-12 col-md-6 text-center text-md-end mt-3 mt-md-0">
|
||||
<div class="input-group w-100 w-md-75 mx-auto mx-md-0">
|
||||
<input type="text" id="documentSearch" class="form-control" placeholder="Cerca sezione o documento..." autocomplete="off">
|
||||
<div id="searchResults" class="list-group dropdown-menu show" style="position: absolute; width: 100%; max-height: 200px; overflow-y: auto; z-index: 1000; display: none;"></div>
|
||||
<!-- Sezione filtri -->
|
||||
<div class="filter-section mb-4 p-3 bg-light rounded shadow-sm">
|
||||
<div class="row align-items-center">
|
||||
<!-- Checkbox "Mostra solo obbligatori" -->
|
||||
<div class="col-12 col-md-3 mb-2 mb-md-0">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="showOnlyRequired">
|
||||
<label class="form-check-label" for="showOnlyRequired">
|
||||
<i class="fas fa-filter me-1"></i> Solo obbligatori
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Dropdown "Seleziona Categoria" -->
|
||||
<div class="col-12 col-md-4 mb-2 mb-md-0">
|
||||
<label for="pageSelectDropdown" class="form-label mb-1 fw-bold">Categoria:</label>
|
||||
<select id="pageSelectDropdown" class="form-control w-100">
|
||||
<?php foreach ($pages as $page) { ?>
|
||||
<option value="<?php echo htmlspecialchars($page['slug']); ?>"
|
||||
<?php echo ($docpage === $page['slug']) ? 'selected' : ''; ?>>
|
||||
<?php echo ucfirst(htmlspecialchars($page['namepages'])); ?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Campo di ricerca -->
|
||||
<div class="col-12 col-md-5 mb-2 mb-md-0 position-relative">
|
||||
<label for="documentSearch" class="form-label mb-1 fw-bold">Cerca:</label>
|
||||
<input type="text" id="documentSearch" class="form-control w-100" placeholder="Sezione o documento..." autocomplete="off">
|
||||
<div id="searchResults" class="list-group dropdown-menu show w-100" style="position: absolute; max-height: 200px; overflow-y: auto; z-index: 1000; display: none;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -230,6 +243,107 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Stile per la sezione filtri */
|
||||
.filter-section {
|
||||
background-color: #f8f9fa;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 10px;
|
||||
padding: 15px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
/* Stile per il checkbox */
|
||||
.form-check.form-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.form-check-input {
|
||||
width: 2em;
|
||||
height: 1em;
|
||||
margin-right: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.form-check-input:checked {
|
||||
background-color: #007bff;
|
||||
border-color: #007bff;
|
||||
}
|
||||
|
||||
.form-check-label {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-check-label i {
|
||||
color: #007bff;
|
||||
font-size: 1rem;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.form-check-label:hover {
|
||||
color: #0056b3;
|
||||
}
|
||||
|
||||
/* Stile per le etichette dei filtri */
|
||||
.form-label {
|
||||
font-size: 0.9rem;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
/* Stile per il dropdown e il campo di ricerca */
|
||||
.form-control {
|
||||
border-radius: 6px;
|
||||
font-size: 0.95rem;
|
||||
padding: 8px 12px;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #007bff;
|
||||
box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
|
||||
}
|
||||
|
||||
/* Stile per i risultati della ricerca */
|
||||
#searchResults {
|
||||
border-radius: 6px;
|
||||
border: 1px solid #ddd;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
#searchResults .list-group-item {
|
||||
font-size: 0.9rem;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
#searchResults .list-group-item:hover {
|
||||
background-color: #f1f3f5;
|
||||
}
|
||||
|
||||
/* Responsive: impila i filtri su schermi piccoli */
|
||||
@media (max-width: 767.98px) {
|
||||
.filter-section {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.form-check.form-switch {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@ -252,6 +366,12 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
loadDocuments(slug);
|
||||
});
|
||||
|
||||
// Gestione del checkbox "Mostra solo obbligatori"
|
||||
$("#showOnlyRequired").on("change", function() {
|
||||
const slug = $("#pageSelectDropdown").val();
|
||||
loadDocuments(slug);
|
||||
});
|
||||
|
||||
// Carica tutti i documenti e le sezioni da tutte le pagine per la ricerca
|
||||
let allDocuments = [];
|
||||
<?php
|
||||
@ -320,12 +440,15 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
});
|
||||
|
||||
function loadDocuments(slug, targetSectionId = null) {
|
||||
const showOnlyRequired = $("#showOnlyRequired").is(":checked");
|
||||
|
||||
$.ajax({
|
||||
url: 'get-documents.php',
|
||||
method: 'GET',
|
||||
data: {
|
||||
slug: slug,
|
||||
idhome: idhome
|
||||
idhome: idhome,
|
||||
showOnlyRequired: showOnlyRequired // Passa il filtro al backend
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
@ -404,27 +527,29 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
${(loadedDocuments[document.document_id] || []).length > 0 ? `
|
||||
<table class="table table-bordered document-list-table" id="table-${document.document_id}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome Documento</th>
|
||||
<th>Data Caricamento</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${loadedDocuments[document.document_id].map(doc => `
|
||||
<div class="loaded-documents-section" id="loaded-documents-${document.document_id}">
|
||||
${(loadedDocuments[document.document_id] || []).length > 0 ? `
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
<table class="table table-bordered document-list-table" id="table-${document.document_id}">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><a href="homedocuments/${doc.filename}" target="_blank">${doc.filename}</a></td>
|
||||
<td>${doc.created_at}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${doc.id}" data-file="${doc.filename}">Elimina</button></td>
|
||||
<th>Nome Documento</th>
|
||||
<th>Data Caricamento</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
` : '<p class="text-muted">Nessun documento caricato</p>'}
|
||||
</thead>
|
||||
<tbody>
|
||||
${loadedDocuments[document.document_id].map(doc => `
|
||||
<tr>
|
||||
<td><a href="homedocuments/${doc.filename}" target="_blank">${doc.filename}</a></td>
|
||||
<td>${doc.created_at}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${doc.id}" data-file="${doc.filename}">Elimina</button></td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
@ -471,38 +596,39 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
dictDefaultMessage: "Trascina qui i file o clicca per caricarli",
|
||||
dictRemoveFile: "Rimuovi",
|
||||
previewTemplate: `
|
||||
<div class="dz-preview dz-file-preview">
|
||||
<div class="dz-image"><img data-dz-thumbnail /></div>
|
||||
<div class="dz-details">
|
||||
<div class="dz-filename"><span data-dz-name></span></div>
|
||||
<div class="dz-size"><span data-dz-size></span></div>
|
||||
</div>
|
||||
<div class="dz-progress">
|
||||
<span class="dz-upload" data-dz-uploadprogress></span>
|
||||
</div>
|
||||
<div class="dz-error-message"><span data-dz-errormessage></span></div>
|
||||
<div class="dz-success-mark">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
</div>
|
||||
<div class="dz-error-mark">
|
||||
<i class="fas fa-times-circle"></i>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
<div class="dz-preview dz-file-preview">
|
||||
<div class="dz-image"><img data-dz-thumbnail /></div>
|
||||
<div class="dz-details">
|
||||
<div class="dz-filename"><span data-dz-name></span></div>
|
||||
<div class="dz-size"><span data-dz-size></span></div>
|
||||
</div>
|
||||
<div class="dz-progress">
|
||||
<span class="dz-upload" data-dz-uploadprogress></span>
|
||||
</div>
|
||||
<div class="dz-error-message"><span data-dz-errormessage></span></div>
|
||||
<div class="dz-success-mark">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
</div>
|
||||
<div class="dz-error-mark">
|
||||
<i class="fas fa-times-circle"></i>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
init: function() {
|
||||
this.on("success", function(file, response) {
|
||||
try {
|
||||
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||
|
||||
if (parsedResponse.success) {
|
||||
let tableId = `#table-${document.document_id} tbody`;
|
||||
let row = `
|
||||
<tr>
|
||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||
<td>${parsedResponse.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||
</tr>`;
|
||||
$(tableId).append(row);
|
||||
// Usa document.document_id invece di parsedResponse.documentId
|
||||
updateDocumentTable(document.document_id, parsedResponse);
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Caricamento completato",
|
||||
text: "Il documento è stato caricato con successo.",
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
@ -518,6 +644,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
text: "Risposta dal server non valida.",
|
||||
});
|
||||
}
|
||||
this.removeFile(file);
|
||||
});
|
||||
|
||||
this.on("error", function(file, errorMessage) {
|
||||
@ -563,6 +690,8 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
const documentId = $(this).data("id");
|
||||
const fileName = $(this).data("file");
|
||||
const $row = $(this).closest("tr");
|
||||
const $table = $row.closest("table");
|
||||
const $section = $table.closest('.loaded-documents-section');
|
||||
|
||||
Swal.fire({
|
||||
title: "Sei sicuro?",
|
||||
@ -588,6 +717,10 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
|
||||
if (parsedResponse.success) {
|
||||
$row.remove();
|
||||
// Controlla se la tabella è vuota
|
||||
if ($table.find("tbody tr").length === 0) {
|
||||
$section.empty(); // Rimuove la tabella e il titolo
|
||||
}
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Eliminato",
|
||||
@ -623,6 +756,56 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
});
|
||||
});
|
||||
|
||||
// Funzione per aggiornare dinamicamente la tabella dei documenti
|
||||
function updateDocumentTable(documentId, parsedResponse) {
|
||||
console.log('Aggiornamento tabella per documentId:', documentId, 'con risposta:', parsedResponse); // Debug
|
||||
const sectionId = `#loaded-documents-${documentId}`;
|
||||
const $section = $(sectionId);
|
||||
|
||||
if (!$section.length) {
|
||||
console.error('Sezione non trovata per documentId:', documentId);
|
||||
return;
|
||||
}
|
||||
|
||||
let $table = $section.find(`#table-${documentId}`);
|
||||
if ($table.length === 0) {
|
||||
// Se la tabella non esiste, crea la sezione e la tabella
|
||||
console.log('Creazione nuova tabella per documentId:', documentId);
|
||||
const tableHtml = `
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
<table class="table table-bordered document-list-table" id="table-${documentId}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome Documento</th>
|
||||
<th>Data Caricamento</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||
<td>${parsedResponse.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
$section.html(tableHtml);
|
||||
console.log('Tabella creata:', $section.html()); // Debug
|
||||
} else {
|
||||
// Se la tabella esiste, aggiungi la nuova riga
|
||||
console.log('Aggiunta riga alla tabella esistente per documentId:', documentId);
|
||||
const row = `
|
||||
<tr>
|
||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||
<td>${parsedResponse.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||
</tr>`;
|
||||
$table.find("tbody").append(row);
|
||||
console.log('Riga aggiunta:', row); // Debug
|
||||
}
|
||||
}
|
||||
|
||||
// Funzione per caricare un file dalla fotocamera
|
||||
window.uploadFromCamera = function(input, documentId) {
|
||||
if (input.files && input.files[0]) {
|
||||
@ -642,14 +825,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||
|
||||
if (parsedResponse.success) {
|
||||
let tableId = `#table-${documentId} tbody`;
|
||||
let row = `
|
||||
<tr>
|
||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||
<td>${parsedResponse.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||
</tr>`;
|
||||
$(tableId).append(row);
|
||||
// Aggiorna dinamicamente la tabella
|
||||
updateDocumentTable(documentId, parsedResponse);
|
||||
// Mostra un messaggio di successo
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Caricamento completato",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user