update icon manage home
This commit is contained in:
parent
9399e5b54a
commit
b5e9901b8e
@ -4,7 +4,8 @@ include('include/headscript.php');
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
$iduserlogin = $_SESSION['iduserlogin'];
|
||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal';
|
||||
$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal'; // Slug principale per la pagina
|
||||
$subSlug = isset($_GET['subSlug']) ? $_GET['subSlug'] : null; // Slug aggiuntivo opzionale
|
||||
$showOnlyRequired = isset($_GET['showOnlyRequired']) && $_GET['showOnlyRequired'] === 'true';
|
||||
$sectionId = isset($_GET['sectionId']) ? $_GET['sectionId'] : null;
|
||||
|
||||
@ -32,26 +33,35 @@ if (!$pageData) {
|
||||
|
||||
$page_id = $pageData['idpages'];
|
||||
|
||||
// Costruisci la query per i documenti
|
||||
$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 = ?
|
||||
";
|
||||
$params = [$page_id];
|
||||
|
||||
if ($showOnlyRequired) {
|
||||
$sql .= " AND d.is_required = 1";
|
||||
}
|
||||
|
||||
if ($sectionId) {
|
||||
$sql .= " AND md5(s.section_name) = ?";
|
||||
$params[] = $sectionId;
|
||||
}
|
||||
|
||||
// Aggiungi filtro per subSlug (assumendo che i documenti abbiano un campo slug o un riferimento)
|
||||
if ($subSlug) {
|
||||
$sql .= " AND d.slug = ?"; // Assumo che 'documents' abbia un campo 'slug' per il filtraggio
|
||||
$params[] = $subSlug;
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY s.section_name, d.document_name";
|
||||
|
||||
$queryDocuments = $conn->prepare($sql);
|
||||
if ($sectionId) {
|
||||
$queryDocuments->bind_param('is', $page_id, $sectionId);
|
||||
} else {
|
||||
$queryDocuments->bind_param('i', $page_id);
|
||||
}
|
||||
$types = str_repeat('s', count($params) - 1) . 'i'; // 's' per stringhe, 'i' per page_id
|
||||
$queryDocuments->bind_param($types, ...$params);
|
||||
$queryDocuments->execute();
|
||||
$resultDocuments = $queryDocuments->get_result();
|
||||
|
||||
|
||||
@ -107,7 +107,6 @@ $mainphoto = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphot
|
||||
margin: 0;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
/* Nome dell'immobile in bianco */
|
||||
}
|
||||
|
||||
.header-banner-overlay .property-info p {
|
||||
@ -180,10 +179,10 @@ $mainphoto = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphot
|
||||
<!-- Tab Navigation -->
|
||||
<ul class="nav nav-tabs" id="propertyTabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="details-tab" data-toggle="tab" href="#details" role="tab" aria-controls="details" aria-selected="true">Dettagli</a>
|
||||
<a class="nav-link" id="details-tab" data-toggle="tab" href="#details" role="tab" aria-controls="details" aria-selected="false">Dettagli</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="documents-tab" data-toggle="tab" href="#documents" role="tab" aria-controls="documents" aria-selected="false">Documenti</a>
|
||||
<a class="nav-link active" id="documents-tab" data-toggle="tab" href="#documents" role="tab" aria-controls="documents" aria-selected="true">Documenti</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="owners-tab" data-toggle="tab" href="#owners" role="tab" aria-controls="owners" aria-selected="false">Proprietari</a>
|
||||
@ -193,11 +192,11 @@ $mainphoto = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphot
|
||||
<!-- Tab Content -->
|
||||
<div class="tab-content" id="propertyTabsContent">
|
||||
<!-- Tab Dettagli -->
|
||||
<div class="tab-pane fade show active" id="details" role="tabpanel" aria-labelledby="details-tab">
|
||||
<div class="tab-pane fade" id="details" role="tabpanel" aria-labelledby="details-tab">
|
||||
<?php include('tabs/dettagli.php'); ?>
|
||||
</div>
|
||||
<!-- Tab Documenti -->
|
||||
<div class="tab-pane fade" id="documents" role="tabpanel" aria-labelledby="documents-tab">
|
||||
<div class="tab-pane fade show active" id="documents" role="tabpanel" aria-labelledby="documents-tab">
|
||||
<?php include('tabs/documenti.php'); ?>
|
||||
</div>
|
||||
<!-- Tab Proprietari -->
|
||||
|
||||
@ -2,67 +2,89 @@
|
||||
global $idhome, $isNew, $homeData, $namedb, $addressdb, $countrydb, $citydb, $zipdb, $commentdb, $latitudedb, $longitudedb, $fulladdressdb,
|
||||
$cadastral_municipalitydb, $cadastral_sectiondb, $cadastral_sheetdb, $cadastral_particledb, $cadastral_subdb, $cadastral_categorydb,
|
||||
$cadastral_classdb, $cadastral_surfacedb, $cadastral_renditadb;
|
||||
|
||||
require_once dirname(__DIR__) . '/class/db-functions.php';
|
||||
$dbHandler = DBHandlerSelect::getInstance();
|
||||
$pdo = $dbHandler->getConnection();
|
||||
|
||||
// Recupera i dati della casa dal database
|
||||
$stmt = $pdo->prepare("SELECT * FROM home WHERE idhome = ?");
|
||||
$stmt->execute([$idhome]);
|
||||
$homeData = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$homeData) {
|
||||
die("Errore: Casa non trovata.");
|
||||
}
|
||||
|
||||
// Popola le variabili globali con i dati recuperati
|
||||
$namedb = $homeData['name'] ?? '';
|
||||
$addressdb = $homeData['address'] ?? '';
|
||||
$countrydb = $homeData['country'] ?? '';
|
||||
$citydb = $homeData['city'] ?? '';
|
||||
$zipdb = $homeData['zip'] ?? '';
|
||||
$commentdb = $homeData['comment'] ?? '';
|
||||
$latitudedb = $homeData['latitude'] ?? '';
|
||||
$longitudedb = $homeData['longitude'] ?? '';
|
||||
$fulladdressdb = $homeData['fulladdress'] ?? '';
|
||||
$cadastral_municipalitydb = $homeData['cadastral_municipality'] ?? '';
|
||||
$cadastral_sectiondb = $homeData['cadastral_section'] ?? '';
|
||||
$cadastral_sheetdb = $homeData['cadastral_sheet'] ?? '';
|
||||
$cadastral_particledb = $homeData['cadastral_particle'] ?? '';
|
||||
$cadastral_subdb = $homeData['cadastral_sub'] ?? '';
|
||||
$cadastral_categorydb = $homeData['cadastral_category'] ?? '';
|
||||
$cadastral_classdb = $homeData['cadastral_class'] ?? '';
|
||||
$cadastral_surfacedb = $homeData['cadastral_surface'] ?? '';
|
||||
$cadastral_renditadb = $homeData['cadastral_rendita'] ?? '';
|
||||
?>
|
||||
|
||||
<style>
|
||||
/* Stile per l'overlay dello spinner */
|
||||
.loading-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 9999;
|
||||
display: none;
|
||||
/* Stile per il lucchetto */
|
||||
.lock-btn {
|
||||
font-size: 1.5rem;
|
||||
padding: 0.5rem 1rem;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.loading-overlay .spinner-custom {
|
||||
width: 4rem;
|
||||
height: 4rem;
|
||||
border: 4px solid #fff;
|
||||
border-top: 4px solid #007bff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
.lock-btn.locked {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.loading-overlay .spinner-text {
|
||||
color: #fff;
|
||||
font-size: 1.2rem;
|
||||
margin-top: 1rem;
|
||||
.lock-btn.unlocked {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
/* Flash verde per l'input */
|
||||
.input-flash {
|
||||
animation: flashGreen 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes flashGreen {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
background-color: #d4edda;
|
||||
}
|
||||
|
||||
50% {
|
||||
background-color: #d4edda;
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Stile per il messaggio di salvataggio */
|
||||
.save-flash {
|
||||
animation: flashGreen 1s ease-in-out;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="card card-body">
|
||||
<!-- Overlay dello spinner -->
|
||||
<div id="loading-overlay" class="loading-overlay">
|
||||
<div class="spinner-custom"></div>
|
||||
<div class="spinner-text">Salvataggio Dati...</div>
|
||||
</div>
|
||||
|
||||
<h4 class="card-title font-20 mt-0"><?php echo $isNew ? "Aggiungi una nuova casa" : "Modifica la tua casa"; ?></h4>
|
||||
|
||||
<!-- Tasto Salva in cima -->
|
||||
<!-- Lucchetto -->
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<button type="button" id="save-form-btn" class="btn btn-primary">
|
||||
<i class="fas fa-save"></i> Salva Modifiche
|
||||
<button type="button" id="lock-btn" class="btn lock-btn locked" data-locked="true">
|
||||
<i class="fas fa-lock"></i>
|
||||
</button>
|
||||
<div id="save-message" class="alert d-none" role="alert"></div>
|
||||
</div>
|
||||
@ -74,18 +96,18 @@ $pdo = $dbHandler->getConnection();
|
||||
<h4 class="mt-4">Dati Principali</h4>
|
||||
<div class="form-group">
|
||||
<label>Nome</label>
|
||||
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control" required>
|
||||
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control" required readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Nota</label>
|
||||
<textarea id="comment" name="comment" rows="4" class="form-control"><?php echo htmlspecialchars($commentdb); ?></textarea>
|
||||
<textarea id="comment" name="comment" rows="4" class="form-control" readonly><?php echo htmlspecialchars($commentdb); ?></textarea>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4">Indirizzo</h4>
|
||||
<div class="form-group">
|
||||
<label>Indirizzo Completo</label>
|
||||
<input type="text" value="<?php echo htmlspecialchars($fulladdressdb); ?>" id="fulladdress" name="fulladdress" class="form-control">
|
||||
<input type="text" value="<?php echo htmlspecialchars($fulladdressdb); ?>" id="fulladdress" name="fulladdress" class="form-control" readonly>
|
||||
</div>
|
||||
|
||||
<!-- Sezione Mappa e Foto -->
|
||||
@ -98,7 +120,7 @@ $pdo = $dbHandler->getConnection();
|
||||
<h5>Foto dell'immobile</h5>
|
||||
<div class="form-group">
|
||||
<label for="photo">Carica Foto</label>
|
||||
<input type="file" id="photo" name="photo" class="form-control" accept="image/*">
|
||||
<input type="file" id="photo" name="photo" class="form-control" accept="image/*" readonly disabled>
|
||||
<small class="text-muted">Carica un'unica foto, verrà sovrascritta se ne scegli un'altra.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -115,27 +137,27 @@ $pdo = $dbHandler->getConnection();
|
||||
<div class="row">
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Comune Catastale</label>
|
||||
<input type="text" id="cadastral_municipality" name="cadastral_municipality" value="<?php echo htmlspecialchars($cadastral_municipalitydb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_municipality" name="cadastral_municipality" value="<?php echo htmlspecialchars($cadastral_municipalitydb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Sezione Catastale</label>
|
||||
<input type="text" id="cadastral_section" name="cadastral_section" value="<?php echo htmlspecialchars($cadastral_sectiondb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_section" name="cadastral_section" value="<?php echo htmlspecialchars($cadastral_sectiondb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Foglio Catastale</label>
|
||||
<input type="text" id="cadastral_sheet" name="cadastral_sheet" value="<?php echo htmlspecialchars($cadastral_sheetdb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_sheet" name="cadastral_sheet" value="<?php echo htmlspecialchars($cadastral_sheetdb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Particella Catastale</label>
|
||||
<input type="text" id="cadastral_particle" name="cadastral_particle" value="<?php echo htmlspecialchars($cadastral_particledb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_particle" name="cadastral_particle" value="<?php echo htmlspecialchars($cadastral_particledb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Subalterno Catastale</label>
|
||||
<input type="text" id="cadastral_sub" name="cadastral_sub" value="<?php echo htmlspecialchars($cadastral_subdb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_sub" name="cadastral_sub" value="<?php echo htmlspecialchars($cadastral_subdb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -143,21 +165,21 @@ $pdo = $dbHandler->getConnection();
|
||||
<div class="row">
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Categoria Catastale</label>
|
||||
<input type="text" id="cadastral_category" name="cadastral_category" value="<?php echo htmlspecialchars($cadastral_categorydb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_category" name="cadastral_category" value="<?php echo htmlspecialchars($cadastral_categorydb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Classe Catastale</label>
|
||||
<input type="text" id="cadastral_class" name="cadastral_class" value="<?php echo htmlspecialchars($cadastral_classdb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_class" name="cadastral_class" value="<?php echo htmlspecialchars($cadastral_classdb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Superficie Catastale (m²)</label>
|
||||
<input type="number" step="0.01" id="cadastral_surface" name="cadastral_surface" value="<?php echo htmlspecialchars($cadastral_surfacedb); ?>" class="form-control">
|
||||
<input type="number" step="0.01" id="cadastral_surface" name="cadastral_surface" value="<?php echo htmlspecialchars($cadastral_surfacedb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Rendita Catastale (€)</label>
|
||||
<input type="text" id="cadastral_rendita" name="cadastral_rendita" value="<?php echo htmlspecialchars($cadastral_renditadb); ?>" class="form-control">
|
||||
<input type="text" id="cadastral_rendita" name="cadastral_rendita" value="<?php echo htmlspecialchars($cadastral_renditadb); ?>" class="form-control" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -176,7 +198,10 @@ $pdo = $dbHandler->getConnection();
|
||||
<div class="row">
|
||||
<div class="col-md-6 form-group">
|
||||
<label>Nazione</label>
|
||||
<input type="text" id="country" name="country" value="<?php echo htmlspecialchars($countrydb); ?>" class="form-control" readonly>
|
||||
<select id="country" name="country" class="form-control">
|
||||
<option value="<?php echo htmlspecialchars($countrydb); ?>" selected><?php echo htmlspecialchars($countrydb); ?></option>
|
||||
<!-- Aggiungi altre opzioni se necessario -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@ -195,12 +220,15 @@ $pdo = $dbHandler->getConnection();
|
||||
<script>
|
||||
// Gestione caricamento foto
|
||||
document.getElementById('photo').addEventListener('change', function(event) {
|
||||
if (document.getElementById('lock-btn').dataset.locked === 'true') {
|
||||
alert('Devi sbloccare la modifica prima di caricare una foto.');
|
||||
this.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
let file = event.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
const loadingOverlay = document.getElementById('loading-overlay');
|
||||
loadingOverlay.style.display = 'flex';
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("photo", file);
|
||||
formData.append("idhome", <?php echo $idhome; ?>);
|
||||
@ -209,11 +237,12 @@ $pdo = $dbHandler->getConnection();
|
||||
xhr.open("POST", "save-home.php", true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
loadingOverlay.style.display = 'none';
|
||||
let response = JSON.parse(xhr.responseText);
|
||||
if (response.success) {
|
||||
document.getElementById('photo-preview').src = "mainphoto/" + response.filename;
|
||||
showSaveMessage("Foto caricata con successo!", "success");
|
||||
document.getElementById('photo').value = '';
|
||||
document.getElementById('photo').classList.add('input-flash');
|
||||
} else {
|
||||
showSaveMessage("Errore nel caricamento della foto: " + response.message, "danger");
|
||||
}
|
||||
@ -225,44 +254,94 @@ $pdo = $dbHandler->getConnection();
|
||||
// Funzione per mostrare il messaggio di salvataggio
|
||||
function showSaveMessage(message, type) {
|
||||
const saveMessage = document.getElementById('save-message');
|
||||
saveMessage.className = `alert alert-${type} d-block`;
|
||||
saveMessage.className = `alert alert-${type} d-block save-flash`;
|
||||
saveMessage.textContent = message;
|
||||
setTimeout(() => {
|
||||
saveMessage.className = 'alert d-none';
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Gestione tasto Salva con spinner
|
||||
document.getElementById('save-form-btn').addEventListener('click', function() {
|
||||
const loadingOverlay = document.getElementById('loading-overlay');
|
||||
loadingOverlay.style.display = 'flex';
|
||||
this.disabled = true;
|
||||
// Gestione lucchetto e modalità modifica
|
||||
document.getElementById('lock-btn').addEventListener('click', function() {
|
||||
const isLocked = this.dataset.locked === 'true';
|
||||
|
||||
const form = document.getElementById('home-form');
|
||||
if (isLocked) {
|
||||
Swal.fire({
|
||||
title: 'Conferma',
|
||||
text: 'Vuoi procedere alla modifica dei dati?',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#28a745',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Sì, modifica',
|
||||
cancelButtonText: 'Annulla'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this.classList.remove('locked');
|
||||
this.classList.add('unlocked');
|
||||
this.innerHTML = '<i class="fas fa-lock-open"></i>';
|
||||
this.dataset.locked = 'false';
|
||||
|
||||
// Rendi i campi editabili
|
||||
document.querySelectorAll('input:not(#country), textarea').forEach(element => {
|
||||
element.removeAttribute('readonly');
|
||||
element.removeAttribute('disabled');
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: 'Conferma',
|
||||
text: 'Vuoi bloccare le modifiche e salvare i dati?',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#dc3545',
|
||||
cancelButtonColor: '#3085d6',
|
||||
confirmButtonText: 'Sì, blocca',
|
||||
cancelButtonText: 'Annulla'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this.classList.remove('unlocked');
|
||||
this.classList.add('locked');
|
||||
this.innerHTML = '<i class="fas fa-lock"></i>';
|
||||
this.dataset.locked = 'true';
|
||||
|
||||
// Rendi i campi read-only
|
||||
document.querySelectorAll('input:not(#country), textarea').forEach(element => {
|
||||
element.setAttribute('readonly', true);
|
||||
if (element.type === 'file') element.setAttribute('disabled', true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Salvataggio automatico al cambio di un campo
|
||||
const fields = [
|
||||
'name', 'comment', 'fulladdress',
|
||||
'cadastral_municipality', 'cadastral_section', 'cadastral_sheet', 'cadastral_particle', 'cadastral_sub',
|
||||
'cadastral_category', 'cadastral_class', 'cadastral_surface', 'cadastral_rendita',
|
||||
'latitude', 'longitude', 'zip', 'city', 'country', 'address'
|
||||
'latitude', 'longitude', 'zip', 'city', 'country'
|
||||
];
|
||||
|
||||
// Raccogli i dati del form
|
||||
let params = `idhome=${encodeURIComponent(<?php echo $idhome; ?>)}`;
|
||||
fields.forEach(field => {
|
||||
const value = document.getElementById(field)?.value || '';
|
||||
params += `&${field}=${encodeURIComponent(value)}`;
|
||||
const element = document.getElementById(field);
|
||||
if (element) {
|
||||
element.addEventListener('change', function() {
|
||||
if (field !== 'country' && document.getElementById('lock-btn').dataset.locked === 'true') return;
|
||||
|
||||
let params = `idhome=${encodeURIComponent(<?php echo $idhome; ?>)}`;
|
||||
fields.forEach(f => {
|
||||
const value = document.getElementById(f)?.value || '';
|
||||
params += `&${f}=${encodeURIComponent(value)}`;
|
||||
});
|
||||
|
||||
// Invia i dati tramite AJAX
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "save-home.php", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
loadingOverlay.style.display = 'none';
|
||||
document.getElementById('save-form-btn').disabled = false;
|
||||
|
||||
if (xhr.status === 200) {
|
||||
let response;
|
||||
try {
|
||||
@ -273,6 +352,7 @@ $pdo = $dbHandler->getConnection();
|
||||
}
|
||||
if (response.success) {
|
||||
showSaveMessage("Modifiche salvate con successo!", "success");
|
||||
element.classList.add('input-flash');
|
||||
} else {
|
||||
showSaveMessage("Errore durante il salvataggio: " + response.message, "danger");
|
||||
}
|
||||
@ -284,6 +364,8 @@ $pdo = $dbHandler->getConnection();
|
||||
|
||||
xhr.send(params);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Gestione mappa
|
||||
let map, marker, autocomplete;
|
||||
@ -313,9 +395,12 @@ $pdo = $dbHandler->getConnection();
|
||||
});
|
||||
|
||||
google.maps.event.addListener(marker, 'dragend', function() {
|
||||
if (document.getElementById('lock-btn').dataset.locked === 'true') return;
|
||||
|
||||
const position = marker.getPosition();
|
||||
document.getElementById('latitude').value = position.lat();
|
||||
document.getElementById('longitude').value = position.lng();
|
||||
document.getElementById('latitude').dispatchEvent(new Event('change'));
|
||||
});
|
||||
|
||||
autocomplete = new google.maps.places.Autocomplete(document.getElementById('fulladdress'), {
|
||||
@ -325,6 +410,8 @@ $pdo = $dbHandler->getConnection();
|
||||
}
|
||||
|
||||
function fillInAddress() {
|
||||
if (document.getElementById('lock-btn').dataset.locked === 'true') return;
|
||||
|
||||
const place = autocomplete.getPlace();
|
||||
if (!place.geometry) {
|
||||
console.error("Errore: Il luogo selezionato non contiene informazioni di geolocalizzazione.");
|
||||
@ -333,12 +420,8 @@ $pdo = $dbHandler->getConnection();
|
||||
|
||||
const location = place.geometry.location;
|
||||
|
||||
if (document.getElementById('latitude')) {
|
||||
document.getElementById('latitude').value = location.lat();
|
||||
}
|
||||
if (document.getElementById('longitude')) {
|
||||
document.getElementById('longitude').value = location.lng();
|
||||
}
|
||||
|
||||
const addressComponents = place.address_components;
|
||||
let zip = "",
|
||||
@ -356,20 +439,16 @@ $pdo = $dbHandler->getConnection();
|
||||
}
|
||||
});
|
||||
|
||||
if (document.getElementById('zip')) {
|
||||
document.getElementById('zip').value = zip;
|
||||
}
|
||||
if (document.getElementById('city')) {
|
||||
document.getElementById('city').value = city;
|
||||
}
|
||||
if (document.getElementById('country')) {
|
||||
document.getElementById('country').value = country;
|
||||
}
|
||||
if (document.getElementById('address')) {
|
||||
document.getElementById('address').value = address.trim();
|
||||
}
|
||||
document.getElementById('fulladdress').value = address.trim();
|
||||
|
||||
map.setCenter(location);
|
||||
marker.setPosition(location);
|
||||
document.getElementById('fulladdress').dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
// Inizializza la mappa quando il DOM è pronto
|
||||
document.addEventListener('DOMContentLoaded', initAutocomplete);
|
||||
</script>
|
||||
@ -22,6 +22,10 @@ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
// Imposta lo slug predefinito
|
||||
$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
|
||||
// Recupera tutti i tag disponibili
|
||||
$stmt = $pdo->query("SELECT tag_id, tag_name FROM tags ORDER BY tag_name");
|
||||
$allTags = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!-- Contenuto del tab Documenti -->
|
||||
@ -78,13 +82,34 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Campo di ricerca e checkbox -->
|
||||
<!-- Campo di ricerca per nome/sezione, tag e checkbox -->
|
||||
<div class="col-12">
|
||||
<div class="position-relative mt-3">
|
||||
<label for="documentSearch" class="form-label mb-1 fw-bold">Cerca:</label>
|
||||
<div class="row">
|
||||
<!-- Campo di ricerca per nome/sezione -->
|
||||
<div class="col-md-6 position-relative mt-3">
|
||||
<label for="documentSearch" class="form-label mb-1 fw-bold">Cerca per nome o sezione:</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>
|
||||
<!-- Dropdown per i tag -->
|
||||
<div class="col-md-6 position-relative mt-3">
|
||||
<label class="form-label mb-1 fw-bold">Filtra per tag:</label>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary dropdown-toggle w-100" type="button" id="tagDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Seleziona tag...
|
||||
</button>
|
||||
<div class="dropdown-menu w-100" aria-labelledby="tagDropdown">
|
||||
<?php foreach ($allTags as $tag): ?>
|
||||
<a class="dropdown-item tag-option" href="#" data-tag-id="<?php echo $tag['tag_id']; ?>" data-tag-name="<?php echo htmlspecialchars($tag['tag_name']); ?>">
|
||||
<?php echo htmlspecialchars($tag['tag_name']); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Contenitore per i badge selezionati -->
|
||||
<div id="selectedTags" class="d-flex flex-wrap gap-2 mt-2"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Checkbox -->
|
||||
<div class="form-check form-switch mt-2">
|
||||
<input class="form-check-input" type="checkbox" id="showOnlyRequired">
|
||||
@ -239,14 +264,42 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
background-color: #f1f3f5;
|
||||
}
|
||||
|
||||
/* Stile per il dropdown dei tag */
|
||||
.dropdown-menu {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.tag-option:hover {
|
||||
background-color: #f1f3f5;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Stile per i badge selezionati */
|
||||
#selectedTags .tag-badge {
|
||||
background-color: #e6f0fa;
|
||||
/* Colore chiaro per i badge selezionati */
|
||||
color: #2c3e50;
|
||||
font-size: 0.9rem;
|
||||
padding: 0.4em 0.8em;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
#selectedTags .tag-badge .remove-tag {
|
||||
font-size: 0.7rem;
|
||||
margin-left: 5px;
|
||||
cursor: pointer;
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
/* Stile per il titolo del documento */
|
||||
.document-title {
|
||||
font-weight: bold;
|
||||
/* Grassetto per maggiore risalto */
|
||||
font-size: 1.1rem;
|
||||
/* Aumenta leggermente la dimensione */
|
||||
color: #2c3e50;
|
||||
/* Colore scuro per contrasto */
|
||||
}
|
||||
|
||||
/* Stile per il preloader */
|
||||
@ -307,7 +360,11 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
|
||||
.document-title {
|
||||
font-size: 1rem;
|
||||
/* Riduci leggermente su mobile */
|
||||
}
|
||||
|
||||
.tag-badge {
|
||||
font-size: 0.8rem;
|
||||
padding: 0.3em 0.6em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -317,9 +374,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
let idhome = <?php echo $idhome; ?>;
|
||||
let currentCategory = '<?php echo $docpage; ?>';
|
||||
let currentSection = null;
|
||||
let selectedTags = []; // Array per tenere traccia dei tag selezionati
|
||||
|
||||
// Caricamento iniziale: non carichiamo documenti finché non selezioniamo una sezione
|
||||
// loadDocuments(currentCategory); // Rimuoviamo questa chiamata
|
||||
// Caricamento iniziale: non carichiamo documenti finché non selezioniamo una categoria o cerchiamo
|
||||
|
||||
// Gestione del clic sulle icone delle categorie
|
||||
$('.category-icon').on('click', function() {
|
||||
@ -331,29 +388,29 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
$('.category-icon').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
$('.section-icons-container').hide().empty();
|
||||
$('#documentSections').empty(); // Svuota i documenti quando selezioni una categoria
|
||||
$('.preloader').show(); // Mostra il preloader
|
||||
$('#documentSections').empty();
|
||||
$('.preloader').show();
|
||||
loadSections(slug);
|
||||
});
|
||||
|
||||
// Gestione del clic sulle icone delle sezioni
|
||||
$(document).on('click', '.section-icon', function() {
|
||||
const sectionId = $(this).data('section-id');
|
||||
const sectionName = $(this).find('.section-name').text(); // Recupera il nome della sezione
|
||||
const sectionName = $(this).find('.section-name').text();
|
||||
if (currentSection === sectionId) return;
|
||||
|
||||
currentSection = sectionId;
|
||||
$('.section-icon').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
$('.document-preloader').show(); // Mostra il preloader per i documenti
|
||||
loadDocuments(currentCategory, sectionId, sectionName); // Carica i documenti della sezione
|
||||
$('.document-preloader').show();
|
||||
loadDocuments(currentCategory, sectionId, sectionName);
|
||||
});
|
||||
|
||||
// Gestione del checkbox "Solo obbligatori"
|
||||
$("#showOnlyRequired").on('change', function() {
|
||||
if (currentSection) { // Carica solo se una sezione è selezionata
|
||||
if (currentSection) {
|
||||
const sectionName = $('.section-icon.active .section-name').text();
|
||||
$('.document-preloader').show(); // Mostra il preloader
|
||||
$('.document-preloader').show();
|
||||
loadDocuments(currentCategory, currentSection, sectionName);
|
||||
}
|
||||
});
|
||||
@ -369,7 +426,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
$('.preloader').hide(); // Nascondi il preloader
|
||||
$('.preloader').hide();
|
||||
if (response.error) {
|
||||
console.error(response.error);
|
||||
return;
|
||||
@ -385,7 +442,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
$('.section-icons-container').html(html).slideDown();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$('.preloader').hide(); // Nascondi il preloader in caso di errore
|
||||
$('.preloader').hide();
|
||||
console.error('Errore nel caricamento delle sezioni:', error);
|
||||
}
|
||||
});
|
||||
@ -395,23 +452,28 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
let allDocuments = [];
|
||||
<?php
|
||||
$stmt = $pdo->query("
|
||||
SELECT d.document_id, d.document_name, p.slug, s.section_name
|
||||
SELECT d.document_id, d.document_name, p.slug, s.section_name, GROUP_CONCAT(t.tag_name) AS tags
|
||||
FROM documents d
|
||||
LEFT JOIN sections s ON d.idsections = s.idsections
|
||||
LEFT JOIN pages p ON d.page_id = p.idpages
|
||||
LEFT JOIN document_tags dt ON d.document_id = dt.document_id
|
||||
LEFT JOIN tags t ON dt.tag_id = t.tag_id
|
||||
GROUP BY d.document_id, d.document_name, p.slug, s.section_name
|
||||
ORDER BY s.section_name, d.document_name
|
||||
");
|
||||
while ($doc = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$tags = $doc['tags'] ? addslashes(htmlspecialchars($doc['tags'])) : '';
|
||||
echo "allDocuments.push({
|
||||
id: '{$doc['document_id']}',
|
||||
name: '" . addslashes(htmlspecialchars($doc['document_name'])) . "',
|
||||
section: '" . addslashes(htmlspecialchars($doc['section_name'])) . "',
|
||||
slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "'
|
||||
slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "',
|
||||
tags: '{$tags}'
|
||||
});\n";
|
||||
}
|
||||
?>
|
||||
|
||||
// Gestione della ricerca dinamica
|
||||
// Gestione della ricerca dinamica per nome/sezione
|
||||
$('#documentSearch').on('input', function() {
|
||||
const searchTerm = $(this).val().toLowerCase().trim();
|
||||
$('#searchResults').empty().hide();
|
||||
@ -428,8 +490,8 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
if (results.length > 0) {
|
||||
let html = '';
|
||||
results.forEach(result => {
|
||||
html += `<a href="#" class="list-group-item list-group-item-action" data-slug="${result.slug}" data-section="${md5(result.section)}">
|
||||
${result.name} (Sezione: ${result.section})
|
||||
html += `<a href="#" class="list-group-item list-group-item-action" data-slug="${result.slug}" data-section="${md5(result.section)}" data-name="${result.name}">
|
||||
${result.name} (Sezione: ${result.section}${result.tags ? ', Tag: ' + result.tags : ''})
|
||||
</a>`;
|
||||
});
|
||||
$('#searchResults').html(html).show();
|
||||
@ -438,33 +500,69 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
e.preventDefault();
|
||||
const slug = $(this).data('slug');
|
||||
const sectionId = $(this).data('section');
|
||||
const documentName = $(this).data('name');
|
||||
|
||||
currentCategory = slug;
|
||||
currentSection = sectionId;
|
||||
$('.category-icon').removeClass('active');
|
||||
$('.category-icon[data-slug="' + slug + '"]').addClass('active');
|
||||
$('.section-icons-container').hide().empty();
|
||||
$('.preloader').show(); // Mostra il preloader durante la ricerca
|
||||
loadSections(slug);
|
||||
$('#documentSections').empty();
|
||||
$('.document-preloader').show();
|
||||
|
||||
// Carica direttamente i documenti senza passare per le sezioni
|
||||
loadDocuments(slug, sectionId, null, documentName);
|
||||
|
||||
$('#documentSearch').val('');
|
||||
$('#searchResults').hide();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Trova il nome della sezione e carica i documenti
|
||||
setTimeout(() => {
|
||||
const sectionElement = $(`.section-icon[data-section-id="${sectionId}"]`);
|
||||
if (sectionElement.length) {
|
||||
$('.section-icon').removeClass('active');
|
||||
sectionElement.addClass('active');
|
||||
const sectionName = sectionElement.find('.section-name').text();
|
||||
$('.document-preloader').show(); // Mostra il preloader
|
||||
loadDocuments(slug, sectionId, sectionName);
|
||||
}
|
||||
}, 500);
|
||||
// Gestione del dropdown dei tag
|
||||
$('.tag-option').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
const tagId = $(this).data('tag-id');
|
||||
const tagName = $(this).data('tag-name');
|
||||
|
||||
if (!selectedTags.some(t => t.id === tagId)) {
|
||||
selectedTags.push({
|
||||
id: tagId,
|
||||
name: tagName
|
||||
});
|
||||
updateSelectedTags();
|
||||
if (currentSection) {
|
||||
const sectionName = $('.section-icon.active .section-name').text();
|
||||
$('.document-preloader').show();
|
||||
loadDocuments(currentCategory, currentSection, sectionName);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Funzione per aggiornare i badge dei tag selezionati
|
||||
function updateSelectedTags() {
|
||||
$('#selectedTags').empty();
|
||||
selectedTags.forEach(tag => {
|
||||
$('#selectedTags').append(`
|
||||
<span class="tag-badge">
|
||||
${tag.name}
|
||||
<span class="remove-tag" data-tag-id="${tag.id}">×</span>
|
||||
</span>
|
||||
`);
|
||||
});
|
||||
$('.remove-tag').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
const tagId = $(this).data('tag-id');
|
||||
selectedTags = selectedTags.filter(t => t.id !== tagId);
|
||||
updateSelectedTags();
|
||||
if (currentSection) {
|
||||
const sectionName = $('.section-icon.active .section-name').text();
|
||||
$('.document-preloader').show();
|
||||
loadDocuments(currentCategory, currentSection, sectionName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Chiudi i risultati della ricerca se clicchi fuori
|
||||
$(document).on('click', function(e) {
|
||||
if (!$(e.target).closest('.input-group, #searchResults').length) {
|
||||
@ -472,8 +570,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
}
|
||||
});
|
||||
|
||||
function loadDocuments(slug, targetSectionId = null, sectionName = null) {
|
||||
function loadDocuments(slug, targetSectionId = null, sectionName = null, searchName = null) {
|
||||
const showOnlyRequired = $("#showOnlyRequired").is(":checked");
|
||||
const tagIds = selectedTags.map(t => t.id);
|
||||
|
||||
$.ajax({
|
||||
url: 'get-documents.php',
|
||||
@ -482,11 +581,13 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
slug: slug,
|
||||
idhome: idhome,
|
||||
showOnlyRequired: showOnlyRequired,
|
||||
sectionId: targetSectionId ? targetSectionId : null
|
||||
sectionId: targetSectionId ? targetSectionId : null,
|
||||
tags: tagIds.length > 0 ? tagIds.join(',') : null,
|
||||
searchName: searchName ? searchName : null
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
$('.document-preloader').hide(); // Nascondi il preloader
|
||||
$('.document-preloader').hide();
|
||||
if (response.error) {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
@ -515,7 +616,6 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
}
|
||||
sectionCount++;
|
||||
|
||||
// Usa il nome della sezione passato come parametro
|
||||
const displaySectionName = sectionName || sectionKey;
|
||||
|
||||
html += `
|
||||
@ -540,6 +640,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
<span class="document-title fw-bold">${document.document_name || 'Documento senza nome'}</span>
|
||||
${document.is_required ? '<span class="badge bg-danger ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Obbligatorio</span>' : ''}
|
||||
${document.max_documents > 0 ? `<span class="badge bg-info ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Max: ${document.max_documents}</span>` : ''}
|
||||
${document.tags ? `<span class="badge bg-secondary ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Tag: ${document.tags}</span>` : ''}
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-primary toggle-dropzone" data-target="#dropzone-${document.document_id}">
|
||||
<i class="fas fa-plus"></i>
|
||||
@ -602,9 +703,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
collapseElement.collapse('show');
|
||||
$('html, body').animate({
|
||||
scrollTop: collapseElement.offset().top - 100
|
||||
}, 500);
|
||||
}, 100);
|
||||
}
|
||||
}, 1000);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// Rinizializza Dropzone per ogni documento
|
||||
@ -877,7 +978,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||
};
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$('.document-preloader').hide(); // Nascondi il preloader in caso di errore
|
||||
$('.document-preloader').hide();
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Errore',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user