update layout

This commit is contained in:
2025-02-25 12:20:57 +01:00
parent ca0ecc1b6c
commit 80ece398c4
16 changed files with 1769 additions and 177 deletions
+282 -56
View File
@@ -37,6 +37,17 @@ $commentdb = $homeData['comment'];
$latitudedb = $homeData['latitude'];
$longitudedb = $homeData['longitude'];
$fulladdressdb = $homeData['fulladdress'];
// Campi catastali
$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_renditadbs = $homeData['cadastral_rendita'];
$cadastral_notesdb = $homeData['cadastral_notes'];
?>
@@ -94,56 +105,251 @@ $fulladdressdb = $homeData['fulladdress'];
<div class="row">
<div class="col-lg-12">
<div class="card card-body">
<h4 class="card-title font-20 mt-0"><?php echo $isNew ? "Aggiungi una nuova casa" : "Modifica la tua casa"; ?></h4>
<form id="home-form">
<input type="hidden" name="idhome" value="<?php echo $idhome; ?>">
<div class="card">
<div class="card-header bg-primary d-flex justify-content-between align-items-center">
<h4 class="mb-0 text-white"><?php echo $isNew ? "Carta d'Identità dell'Immobile" : "Dettagli dell'Immobile"; ?></h4>
<button id="edit-toggle" class="btn btn-light btn-sm">
<i class="fas fa-pencil-alt"></i> Modifica
</button>
</div>
<div class="card-body">
<form id="home-form">
<input type="hidden" name="idhome" value="<?php echo $idhome; ?>">
<div class="form-group">
<label>Nome</label>
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control" required>
</div>
<!-- Sezione Nome e Foto -->
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label>Nome Immobile</label>
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control form-field" readonly>
</div>
<!-- Sezione Note -->
<div class="form-group">
<h5 class="text-primary"><i class="fas fa-sticky-note"></i> Note</h5>
<textarea id="comment" name="comment" rows="3" class="form-control form-field" readonly><?php echo htmlspecialchars($commentdb); ?></textarea>
</div>
</div>
<div class="col-md-4 text-center">
<label>Foto dell'Immobile</label>
<div class="photo-container">
<input type="file" id="photo" name="photo" class="form-control form-field d-none" accept="image/*" disabled>
<img id="photo-preview" src="<?php echo !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphoto'] : 'assets/images/no-image.jpg'; ?>" alt="Anteprima Foto" class="img-fluid mt-2 rounded shadow" style="max-width: 200px;">
</div>
<small class="text-muted photo-hint d-none">Carica un'unica foto, verrà sovrascritta se ne scegli un'altra.</small>
</div>
</div>
<div class="form-group">
<label>Commento</label>
<textarea id="comment" name="comment" rows="4" class="form-control"><?php echo htmlspecialchars($commentdb); ?></textarea>
</div>
<!-- Sezione Indirizzo -->
<div class="border rounded p-3 mt-4">
<h5 class="text-primary"><i class="fas fa-map-marker-alt"></i> Indirizzo</h5>
<label>Indirizzo Completo</label>
<input type="text" value="<?php echo htmlspecialchars($fulladdressdb); ?>" id="fulladdress" name="fulladdress" class="form-control form-field" readonly>
<div id="map" class="mt-3" style="height: 300px;"></div>
</div>
<h4 class="mt-4">Indirizzo Completo</h4>
<div class="form-group">
<label>Indirizzo Completo</label>
<input type="text" value="<?php echo htmlspecialchars($fulladdressdb); ?>" id="fulladdress" name="fulladdress" class="form-control">
</div>
<!-- Sezione Dati Catastali -->
<div class="border rounded p-3 mt-4">
<h5 class="text-primary"><i class="fas fa-building"></i> Dati Catastali</h5>
<div class="row">
<div class="col-md-4">
<label>Comune Catastale</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_municipalitydb); ?>" id="cadastral_municipality" name="cadastral_municipality" class="form-control form-field" readonly>
</div>
<div class="col-md-4">
<label>Sezione</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_sectiondb); ?>" id="cadastral_section" name="cadastral_section" class="form-control form-field" readonly>
</div>
<div class="col-md-4">
<label>Foglio</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_sheetdb); ?>" id="cadastral_sheet" name="cadastral_sheet" class="form-control form-field" readonly>
</div>
</div>
<div class="row mt-2">
<div class="col-md-4">
<label>Particella</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_particledb); ?>" id="cadastral_particle" name="cadastral_particle" class="form-control form-field" readonly>
</div>
<div class="col-md-4">
<label>Subalterno</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_subdb); ?>" id="cadastral_sub" name="cadastral_sub" class="form-control form-field" readonly>
</div>
<div class="col-md-4">
<label>Categoria Catastale</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_categorydb); ?>" id="cadastral_category" name="cadastral_category" class="form-control form-field" readonly>
</div>
</div>
<div class="row mt-2">
<div class="col-md-4">
<label>Classe Catastale</label>
<input type="text" value="<?php echo htmlspecialchars($cadastral_classdb); ?>" id="cadastral_class" name="cadastral_class" class="form-control form-field" readonly>
</div>
<div class="col-md-4">
<label>Superficie (mq)</label>
<input type="number" step="0.01" value="<?php echo htmlspecialchars($cadastral_surfacedb); ?>" id="cadastral_surface" name="cadastral_surface" class="form-control form-field" readonly>
</div>
<div class="col-md-4">
<label>Rendita ()</label>
<input type="number" step="0.01" value="<?php echo htmlspecialchars($cadastral_renditadbs); ?>" id="cadastral_rendita" name="cadastral_rendita" class="form-control form-field" readonly>
</div>
</div>
</div>
<h4 class="mt-4">Geolocalizzazione</h4>
<div id="map"></div>
<!-- Sezione Geolocalizzazione (campi nascosti) -->
<div class="row mt-3">
<div class="col-md-6">
<input type="hidden" id="latitude" name="latitude" value="<?php echo htmlspecialchars($latitudedb); ?>">
</div>
<div class="col-md-6">
<input type="hidden" id="longitude" name="longitude" value="<?php echo htmlspecialchars($longitudedb); ?>">
</div>
<div class="col-md-4">
<input type="hidden" id="zip" name="zip" value="<?php echo htmlspecialchars($zipdb); ?>">
</div>
<div class="col-md-4">
<input type="hidden" id="city" name="city" value="<?php echo htmlspecialchars($citydb); ?>">
</div>
<div class="col-md-4">
<input type="hidden" id="country" name="country" value="<?php echo htmlspecialchars($countrydb); ?>">
</div>
</div>
<div class="form-group mt-4">
<label>CAP</label>
<input type="text" id="zip" name="zip" value="<?php echo htmlspecialchars($zipdb); ?>" class="form-control" readonly>
</div>
<div class="form-group">
<label>Città</label>
<input type="text" id="city" name="city" value="<?php echo htmlspecialchars($citydb); ?>" class="form-control" readonly>
</div>
<div class="form-group">
<label>Nazione</label>
<input type="text" id="country" name="country" value="<?php echo htmlspecialchars($countrydb); ?>" class="form-control" readonly>
</div>
<div class="form-group mt-4">
<label>Latitudine</label>
<input type="text" id="latitude" name="latitude" value="<?php echo htmlspecialchars($latitudedb); ?>" class="form-control" readonly>
</div>
<div class="form-group">
<label>Longitudine</label>
<input type="text" id="longitude" name="longitude" value="<?php echo htmlspecialchars($longitudedb); ?>" class="form-control" readonly>
</div>
</form>
<button type="submit" class="btn btn-primary mt-3 w-100 save-btn d-none"><i class="fas fa-save"></i> Salva</button>
</form>
</div>
</div>
</div>
</div>
<!-- Aggiungi il seguente script JavaScript -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const editToggleBtn = document.getElementById('edit-toggle');
const formFields = document.querySelectorAll('.form-field');
const saveBtn = document.querySelector('.save-btn');
const photoInput = document.getElementById('photo');
const photoHint = document.querySelector('.photo-hint');
// Ottieni il valore di isNew dalla pagina PHP
const isNewRecord = <?php echo $isNew ? 'true' : 'false'; ?>;
// Variabile per tenere traccia dello stato di modifica
let editMode = isNewRecord;
// Se è un nuovo record, entra automaticamente in modalità modifica
if (isNewRecord) {
// Modifica il testo del pulsante
editToggleBtn.innerHTML = '<i class="fas fa-eye"></i> Visualizza';
editToggleBtn.classList.remove('btn-light');
editToggleBtn.classList.add('btn-info');
// Abilita tutti i campi
formFields.forEach(field => {
field.readOnly = false;
field.disabled = false;
if (field.type === 'file') {
field.classList.remove('d-none');
}
});
// Mostra pulsante salva e suggerimento foto
saveBtn.classList.remove('d-none');
photoHint.classList.remove('d-none');
}
// Gestione del click sul pulsante di modifica
editToggleBtn.addEventListener('click', function() {
editMode = !editMode;
if (editMode) {
// Attiva modalità modifica
editToggleBtn.innerHTML = '<i class="fas fa-eye"></i> Visualizza';
editToggleBtn.classList.remove('btn-light');
editToggleBtn.classList.add('btn-info');
// Abilita tutti i campi
formFields.forEach(field => {
field.readOnly = false;
field.disabled = false;
if (field.type === 'file') {
field.classList.remove('d-none');
}
});
// Mostra pulsante salva e suggerimento foto
saveBtn.classList.remove('d-none');
photoHint.classList.remove('d-none');
} else {
// Torna alla modalità visualizzazione
editToggleBtn.innerHTML = '<i class="fas fa-pencil-alt"></i> Modifica';
editToggleBtn.classList.remove('btn-info');
editToggleBtn.classList.add('btn-light');
// Disabilita tutti i campi
formFields.forEach(field => {
field.readOnly = true;
field.disabled = true;
if (field.type === 'file') {
field.classList.add('d-none');
}
});
// Nascondi pulsante salva e suggerimento foto
saveBtn.classList.add('d-none');
photoHint.classList.add('d-none');
}
});
});
</script>
<script>
// Caricamento della mappa
function initMap() {
let map = new google.maps.Map(document.getElementById("map"), {
center: {
lat: 41.9028,
lng: 12.4964
}, // Roma
zoom: 14
});
let marker = new google.maps.Marker({
position: {
lat: 41.9028,
lng: 12.4964
},
map: map,
draggable: true
});
marker.addListener("dragend", function() {
let position = marker.getPosition();
document.getElementById("latitude").value = position.lat();
document.getElementById("longitude").value = position.lng();
});
}
// Cambio immagine al clic sulla foto
document.getElementById("photo-preview").addEventListener("click", function() {
document.getElementById("photo").click();
});
// Anteprima immagine selezionata
document.getElementById("photo").addEventListener("change", function(event) {
let file = event.target.files[0];
if (file) {
let reader = new FileReader();
reader.onload = function(e) {
document.getElementById("photo-preview").src = e.target.result;
};
reader.readAsDataURL(file);
}
});
</script>
<!-- Inclusione API Google Maps -->
<script src="https://maps.googleapis.com/maps/api/js?key=TUACHIAVEAPI&callback=initMap" async defer></script>
</div><!-- container -->
</div> <!-- Page content Wrapper -->
</div> <!-- content -->
@@ -161,12 +367,14 @@ $fulladdressdb = $homeData['fulladdress'];
const idhome = <?php echo $idhome; ?>;
const inputField = document.getElementById(field);
var 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) {
if (xhr.status === 200) {
inputField.classList.add("success-flash");
setTimeout(function() {
@@ -186,6 +394,7 @@ $fulladdressdb = $homeData['fulladdress'];
xhr.send(params);
}
// Funzione per la mappa e autocomplete
function initAutocomplete() {
const latitude = parseFloat(document.getElementById('latitude').value);
@@ -194,7 +403,7 @@ $fulladdressdb = $homeData['fulladdress'];
const defaultLocation = {
lat: 41.9028,
lng: 12.4964
}; // Default location: Rome
}; // Default: Roma
const location = !isNaN(latitude) && !isNaN(longitude) ? {
lat: latitude,
lng: longitude
@@ -233,6 +442,7 @@ $fulladdressdb = $homeData['fulladdress'];
// Riempie i campi dopo che un indirizzo è stato selezionato
function fillInAddress() {
const place = autocomplete.getPlace();
if (!place.geometry) {
console.error("Errore: Il luogo selezionato non contiene informazioni di geolocalizzazione.");
return;
@@ -240,7 +450,8 @@ $fulladdressdb = $homeData['fulladdress'];
const location = place.geometry.location;
// Imposta latitudine e longitudine se esistono gli elementi corrispondenti
// Controlla se gli elementi esistono prima di impostare i valori
if (document.getElementById('latitude')) {
document.getElementById('latitude').value = location.lat();
}
@@ -254,7 +465,6 @@ $fulladdressdb = $homeData['fulladdress'];
country = "",
address = "";
// Itera sui componenti dell'indirizzo per assegnare valori a CAP, città, nazione e indirizzo
addressComponents.forEach(component => {
const types = component.types;
if (types.includes("postal_code")) zip = component.long_name;
@@ -265,7 +475,6 @@ $fulladdressdb = $homeData['fulladdress'];
}
});
// Imposta i valori se esistono gli elementi corrispondenti
if (document.getElementById('zip')) {
document.getElementById('zip').value = zip;
}
@@ -278,13 +487,22 @@ $fulladdressdb = $homeData['fulladdress'];
if (document.getElementById('address')) {
document.getElementById('address').value = address.trim();
}
if (document.getElementById('fulladdress')) {
document.getElementById('fulladdress').value = place.formatted_address;
}
// Centra la mappa e sposta il marker nella nuova posizione
map.setCenter(location);
marker.setPosition(location);
// Centra la mappa e sposta il marker
if (map && marker) {
map.setCenter(location);
marker.setPosition(location);
} else {
console.error("Errore: Mappa o Marker non inizializzati correttamente.");
}
// Aggiorna i campi tramite AJAX
updateField('fulladdress', document.getElementById('fulladdress').value, {
updateField('fulladdress', place.formatted_address, {
address: address.trim(),
zip: zip,
city: city,
@@ -296,17 +514,25 @@ $fulladdressdb = $homeData['fulladdress'];
// Aggiorna i dati tramite AJAX al cambio di valore
document.getElementById('name').addEventListener('change', function() {
updateField('name', this.value);
});
// Event listener per aggiornamento automatico dei dati al cambio di valore
const fieldsToUpdate = [
'name', 'comment', 'cadastral_municipality', 'cadastral_section', 'cadastral_sheet',
'cadastral_particle', 'cadastral_sub', 'cadastral_category', 'cadastral_class',
'cadastral_surface', 'cadastral_rendita', 'cadastral_notes'
];
document.getElementById('comment').addEventListener('change', function() {
updateField('comment', this.value);
fieldsToUpdate.forEach(field => {
const inputField = document.getElementById(field);
if (inputField) {
inputField.addEventListener('change', function() {
updateField(field, this.value);
});
}
});
</script>
<!-- jQuery -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/popper.min.js"></script>