update layout
@ -1,8 +1,18 @@
|
||||
var as = {};
|
||||
|
||||
as.toggleSidebar = function () {
|
||||
$(".sidebar").toggleClass("expanded");
|
||||
$("body").toggleClass("sidebar-enable"); // Permette di aggiungere uno stato globale
|
||||
if (window.innerWidth < 992) {
|
||||
// Mobile e Tablet: La sidebar si chiude completamente
|
||||
$(".sidebar").toggleClass("expanded");
|
||||
$("body").toggleClass("sidebar-enable");
|
||||
} else {
|
||||
// Desktop: La sidebar si restringe, lasciando solo le icone
|
||||
if ($("body").hasClass("sidebar-collapsed")) {
|
||||
$("body").removeClass("sidebar-collapsed");
|
||||
} else {
|
||||
$("body").addClass("sidebar-collapsed");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
as.hideNotifications = function () {
|
||||
|
||||
516
public/userportal/details-home.php
Normal file
@ -0,0 +1,516 @@
|
||||
<?php include('include/headscript.php'); ?>
|
||||
|
||||
<?php
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Verifica se si sta aggiungendo una nuova casa o aggiornando una esistente
|
||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
$isNew = ($idhome == 0);
|
||||
|
||||
if ($isNew) {
|
||||
// Se non esiste ancora l'idhome, crea un nuovo record e ricarica la pagina con l'ID generato
|
||||
$insertQuery = $conn->prepare("INSERT INTO home (iduser) VALUES (?)");
|
||||
$insertQuery->bind_param("i", $iduserlogin);
|
||||
$insertQuery->execute();
|
||||
$idhome = $conn->insert_id; // Ottieni il nuovo idhome generato
|
||||
|
||||
// Ricarica la pagina con il nuovo idhome
|
||||
header("Location: manage-home.php?idhome=$idhome");
|
||||
exit(); // Assicurati di uscire per evitare che il codice continui
|
||||
}
|
||||
|
||||
// Se esiste già l'idhome, carica i dati della casa
|
||||
$query = $conn->prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?");
|
||||
$query->bind_param("ii", $idhome, $iduserlogin);
|
||||
$query->execute();
|
||||
$result = $query->get_result();
|
||||
$homeData = $result->fetch_assoc();
|
||||
|
||||
// Assegna i valori esistenti ai campi
|
||||
$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'];
|
||||
// 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'];
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
||||
<?php include('include/seo.php'); ?>
|
||||
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/icons.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
<style>
|
||||
#map {
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.success-flash {
|
||||
background-color: #d4edda !important;
|
||||
transition: background-color 1s ease;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
<div id="wrapper">
|
||||
<?php include('include/navigationbar.php'); ?>
|
||||
|
||||
<div class="content-page">
|
||||
<div class="content">
|
||||
<?php include('include/topbar.php'); ?>
|
||||
|
||||
<div class="page-content-wrapper">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="page-title-box d-flex justify-content-between align-items-center">
|
||||
<!-- Titolo -->
|
||||
<h4 class="page-title m-0"><?php echo $isNew ? "Aggiungi Casa" : "Modifica Casa"; ?></h4>
|
||||
|
||||
<!-- Tasto Torna indietro -->
|
||||
<button onclick="history.back()" class="btn btn-dark">
|
||||
<i class="fas fa-arrow-left"></i> Torna indietro
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<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; ?>">
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<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');
|
||||
|
||||
let editMode = false;
|
||||
|
||||
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 -->
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Google Maps API for Autocomplete and Geolocation -->
|
||||
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyADtQRKgCpJNnQCP8QvBeKDcm0TrTPpsGY&libraries=places&callback=initAutocomplete"></script>
|
||||
<script>
|
||||
let map, marker, autocomplete;
|
||||
|
||||
// Funzione per inviare i dati del campo tramite AJAX
|
||||
function updateField(field, value, additionalData = {}) {
|
||||
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() {
|
||||
inputField.classList.remove("success-flash");
|
||||
}, 1000);
|
||||
} else {
|
||||
console.error("Errore durante l'aggiornamento: " + xhr.responseText);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let params = `field=${encodeURIComponent(field)}&value=${encodeURIComponent(value)}&idhome=${idhome}`;
|
||||
for (let key in additionalData) {
|
||||
params += `&${key}=${encodeURIComponent(additionalData[key])}`;
|
||||
}
|
||||
|
||||
xhr.send(params);
|
||||
}
|
||||
|
||||
|
||||
// Funzione per la mappa e autocomplete
|
||||
function initAutocomplete() {
|
||||
const latitude = parseFloat(document.getElementById('latitude').value);
|
||||
const longitude = parseFloat(document.getElementById('longitude').value);
|
||||
|
||||
const defaultLocation = {
|
||||
lat: 41.9028,
|
||||
lng: 12.4964
|
||||
}; // Default: Roma
|
||||
const location = !isNaN(latitude) && !isNaN(longitude) ? {
|
||||
lat: latitude,
|
||||
lng: longitude
|
||||
} : defaultLocation;
|
||||
|
||||
// Inizializza la mappa
|
||||
map = new google.maps.Map(document.getElementById('map'), {
|
||||
center: location,
|
||||
zoom: 14
|
||||
});
|
||||
|
||||
// Aggiungi un marker
|
||||
marker = new google.maps.Marker({
|
||||
position: location,
|
||||
map: map,
|
||||
draggable: true
|
||||
});
|
||||
|
||||
google.maps.event.addListener(marker, 'dragend', function() {
|
||||
const position = marker.getPosition();
|
||||
document.getElementById('latitude').value = position.lat();
|
||||
document.getElementById('longitude').value = position.lng();
|
||||
|
||||
// Aggiorna latitudine e longitudine
|
||||
updateField('latitude', position.lat());
|
||||
updateField('longitude', position.lng());
|
||||
});
|
||||
|
||||
// Autocomplete per l'indirizzo
|
||||
autocomplete = new google.maps.places.Autocomplete(document.getElementById('fulladdress'), {
|
||||
types: ['geocode']
|
||||
});
|
||||
autocomplete.addListener('place_changed', fillInAddress);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
const location = place.geometry.location;
|
||||
|
||||
|
||||
// Controlla se gli elementi esistono prima di impostare i valori
|
||||
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 = "",
|
||||
city = "",
|
||||
country = "",
|
||||
address = "";
|
||||
|
||||
addressComponents.forEach(component => {
|
||||
const types = component.types;
|
||||
if (types.includes("postal_code")) zip = component.long_name;
|
||||
if (types.includes("locality")) city = component.long_name;
|
||||
if (types.includes("country")) country = component.long_name;
|
||||
if (types.includes("street_number") || types.includes("route")) {
|
||||
address += component.long_name + " ";
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
if (document.getElementById('fulladdress')) {
|
||||
document.getElementById('fulladdress').value = place.formatted_address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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', place.formatted_address, {
|
||||
address: address.trim(),
|
||||
zip: zip,
|
||||
city: city,
|
||||
country: country,
|
||||
latitude: location.lat(),
|
||||
longitude: location.lng()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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'
|
||||
];
|
||||
|
||||
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>
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -15,12 +15,14 @@ $sql = "
|
||||
h.zip,
|
||||
h.city,
|
||||
h.country,
|
||||
h.mainphoto,
|
||||
COUNT(ho.owner_id) AS owner_count,
|
||||
SUM(ho.ownership_percentage) AS total_ownership,
|
||||
GROUP_CONCAT(
|
||||
CASE
|
||||
WHEN po.owner_type = 'individual'
|
||||
THEN CONCAT(po.first_name, ' ', po.last_name)
|
||||
ELSE po.company_name
|
||||
THEN CONCAT(po.first_name, ' ', po.last_name, ' (', ho.ownership_percentage, '%)')
|
||||
ELSE CONCAT(po.company_name, ' (', ho.ownership_percentage, '%)')
|
||||
END
|
||||
SEPARATOR '\n'
|
||||
) AS owner_names
|
||||
@ -36,6 +38,7 @@ $sql = "
|
||||
h.idhome
|
||||
";
|
||||
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param('i', $iduserlogin);
|
||||
$stmt->execute();
|
||||
@ -62,6 +65,206 @@ $result = $stmt->get_result();
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/icons.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css">
|
||||
<style>
|
||||
/* Visualizza il pulsante mobile anche su desktop */
|
||||
.button-menu-mobile {
|
||||
display: inline-block !important;
|
||||
}
|
||||
|
||||
/* Nascondi il quadrato rosso con la X su desktop */
|
||||
@media (min-width: 992px) {
|
||||
.button-menu-mobile {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.button-menu-mobile i.ion-close {
|
||||
display: none;
|
||||
/* Nasconde la X rossa */
|
||||
}
|
||||
|
||||
.button-menu-mobile i.mdi-menu {
|
||||
display: inline-block;
|
||||
/* Mostra sempre le tre righe orizzontali */
|
||||
}
|
||||
}
|
||||
|
||||
/* Stile per mobile: Mantieni il comportamento originale */
|
||||
@media (max-width: 991.98px) {
|
||||
.button-menu-mobile {
|
||||
background-color: #ff5e5e;
|
||||
/* Questo è il colore rosso originale */
|
||||
border-radius: 50%;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.button-menu-mobile i.ion-close {
|
||||
display: inline-block;
|
||||
/* Mostra la X rossa */
|
||||
}
|
||||
|
||||
.button-menu-mobile i.mdi-menu {
|
||||
display: none;
|
||||
/* Nasconde le tre righe quando la barra è aperta */
|
||||
}
|
||||
}
|
||||
|
||||
/* Stili per colori professionali */
|
||||
.btn-main {
|
||||
background-color: rgb(96, 93, 175);
|
||||
/* Blu professionale */
|
||||
color: #fff;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-main:hover {
|
||||
background-color: #364fc7;
|
||||
/* Blu più scuro al passaggio */
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: rgb(21, 190, 86);
|
||||
/* Grigio tenue */
|
||||
color: #212529;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: #868e96;
|
||||
/* Grigio più scuro al passaggio */
|
||||
}
|
||||
|
||||
.btn-info-light {
|
||||
background-color: #ffd43b;
|
||||
/* Giallo professionale */
|
||||
color: #212529;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-info-light:hover {
|
||||
background-color: #fcc419;
|
||||
/* Giallo più intenso al passaggio */
|
||||
}
|
||||
|
||||
/* Uniformità altezza */
|
||||
.equal-height {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.equal-height .flex-fill {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Applica l'effetto zoom solo alle card della griglia */
|
||||
#gridView .card {
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
transition: transform 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
#gridView .card:hover {
|
||||
transform: scale(1.03);
|
||||
}
|
||||
|
||||
|
||||
.card-img-top {
|
||||
height: 180px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
/* Nasconde i tre puntini di default */
|
||||
.action-menu {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Mostra i tre puntini quando il mouse passa sul box */
|
||||
.box-home:hover .action-menu {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
/* Pulsante 3 puntini */
|
||||
.action-toggle {
|
||||
border: none;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
padding: 6px 10px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Cambia colore al passaggio del mouse */
|
||||
.action-toggle:hover {
|
||||
background: rgba(230, 230, 230, 1);
|
||||
}
|
||||
|
||||
|
||||
/* Stile per il menu delle azioni */
|
||||
.dropdown-menu {
|
||||
font-size: 14px;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.dropdown-item i {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
/* Stile per l'immagine */
|
||||
.img-thumbnail {
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
/* Spazio tra l'icona dei proprietari e il nome */
|
||||
td i.fas {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
/* Contenitore per i bottoni in alto */
|
||||
.action-container {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
/* Sposta il bottone proprietari a sinistra */
|
||||
right: 10px;
|
||||
/* Mantiene il menu azioni a destra */
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
/* Distribuisce gli elementi a sinistra e a destra */
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* Bottone proprietari a sinistra */
|
||||
.owner-btn {
|
||||
font-size: 14px;
|
||||
padding: 4px 10px;
|
||||
}
|
||||
|
||||
/* I 3 puntini restano nascosti finché il mouse non passa sopra */
|
||||
.box-home .action-menu {
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
/* Mostra i 3 puntini solo in hover */
|
||||
.box-home:hover .action-menu {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
@ -88,109 +291,212 @@ $result = $stmt->get_result();
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-12">
|
||||
<div class="float-right">
|
||||
<!-- Pulsante per aggiungere una nuova casa -->
|
||||
<a href="manage-home.php" class="btn btn-success">
|
||||
<i class="fas fa-plus"></i> Aggiungi Casa/Terreno
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-12 d-flex justify-content-start align-items-center gap-3">
|
||||
<a href="manage-home.php" class="btn btn-success">
|
||||
<i class="fas fa-plus"></i> Aggiungi Casa/Terreno
|
||||
</a>
|
||||
|
||||
<button id="toggleViewBtn" class="btn btn-info ms-2">
|
||||
<i class="fas fa-th-large"></i> Vista Griglia
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="homeTable" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<th>Indirizzo</th>
|
||||
|
||||
<th>Città</th>
|
||||
<th>Nazione</th>
|
||||
<th>Nomi Proprietari</th>
|
||||
<th>Proprietari</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<!-- Campi di input per i filtri -->
|
||||
<th><input type="text" placeholder="Cerca Nome" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Indirizzo" class="form-control form-control-sm"></th>
|
||||
<!-- table view -->
|
||||
<div id="tableView" style="display: none;">
|
||||
|
||||
<th><input type="text" placeholder="Cerca Città" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Nazione" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Proprietari" class="form-control form-control-sm"></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($row = $result->fetch_assoc()) { ?>
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
|
||||
<table id="homeTable" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($row['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['address']); ?></td>
|
||||
|
||||
<td><?php echo htmlspecialchars($row['zip']); ?> - <?php echo htmlspecialchars($row['city']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['country']); ?></td>
|
||||
<td><?php echo nl2br(htmlspecialchars($row['owner_names'])); ?></td>
|
||||
<td>
|
||||
<?php if ($row['owner_count'] == 0) { ?>
|
||||
<a href="assign-owners.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-danger btn-sm">
|
||||
<i class="fas fa-user-times"></i> Assegna Proprietario
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a href="assign-owners.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-success btn-sm">
|
||||
<i class="fas fa-user-check"></i> <?php echo htmlspecialchars($row['owner_count']); ?> Proprietari
|
||||
</a>
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="text-nowrap">
|
||||
<div class="d-flex justify-content-start align-items-center gap-2">
|
||||
<!-- Pulsante per modificare i dettagli della casa -->
|
||||
<a href="manage-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-info btn-sm me-2" title="Dettagli">
|
||||
<i class="fas fa-info-circle"></i>
|
||||
</a>
|
||||
|
||||
<!-- Pulsante per i documenti della casa -->
|
||||
<a href="documents-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-primary btn-sm me-2" title="Documenti">
|
||||
<i class="fas fa-folder-open"></i>
|
||||
</a>
|
||||
|
||||
<!-- Pulsante per condividere la casa -->
|
||||
<a href="share-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-warning btn-sm me-2" title="Condividi">
|
||||
<i class="fas fa-share-alt"></i>
|
||||
</a>
|
||||
|
||||
<!-- Pulsante per passaggio proprietà -->
|
||||
<button class="btn btn-secondary btn-sm me-2 transfer-property-btn" data-id="<?php echo $row['idhome']; ?>" title="Passaggio Proprietà">
|
||||
<i class="fas fa-exchange-alt"></i>
|
||||
</button>
|
||||
|
||||
<!-- Pulsante per eliminare la casa -->
|
||||
<button class="btn btn-danger btn-sm delete-home-btn" data-id="<?php echo $row['idhome']; ?>" title="Elimina">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
<th>Foto</th>
|
||||
<th>Nome</th>
|
||||
<th>Città / Nazione</th>
|
||||
<th>Indirizzo</th>
|
||||
<th>Proprietari</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div><!-- end table-responsive -->
|
||||
|
||||
<tr>
|
||||
<!-- Campi di input per i filtri -->
|
||||
<th></th>
|
||||
<th><input type="text" placeholder="Cerca Nome" class="form-control form-control-sm"></th>
|
||||
|
||||
<th><input type="text" placeholder="Cerca Città" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Indirizzo" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Proprietari" class="form-control form-control-sm"></th>
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($row = $result->fetch_assoc()) { ?>
|
||||
<tr>
|
||||
<!-- Thumbnail immagine -->
|
||||
<td>
|
||||
<img src="mainphoto/<?php echo htmlspecialchars($row['mainphoto'] ?? 'default.jpg'); ?>"
|
||||
class="img-thumbnail open-photo"
|
||||
style="width: 80px; height: 80px; object-fit: cover; cursor: pointer;"
|
||||
alt="<?php echo htmlspecialchars($row['name']); ?>"
|
||||
data-toggle="modal" data-target="#photoModal"
|
||||
data-src="mainphoto/<?php echo htmlspecialchars($row['mainphoto'] ?? 'default.jpg'); ?>">
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
<!-- Nome immobile -->
|
||||
<td><?php echo htmlspecialchars($row['name']); ?></td>
|
||||
|
||||
<!-- Città e Nazione -->
|
||||
<td><?php echo htmlspecialchars($row['city']); ?>, <?php echo htmlspecialchars($row['country']); ?></td>
|
||||
|
||||
<!-- Indirizzo -->
|
||||
<td><?php echo htmlspecialchars($row['address']); ?></td>
|
||||
|
||||
<!-- Proprietari + Bottone -->
|
||||
<td>
|
||||
<?php echo nl2br(htmlspecialchars($row['owner_names'])); ?>
|
||||
<br>
|
||||
<?php
|
||||
// Determina il colore del pulsante in base alla percentuale totale di possesso
|
||||
if ($row['owner_count'] == 0) {
|
||||
$btn_class = "btn-danger"; // Nessun proprietario → Rosso
|
||||
$btn_text = '<i class="fas fa-user-times"></i> Assegna Proprietario';
|
||||
} elseif ($row['total_ownership'] < 100) {
|
||||
$btn_class = "btn-warning"; // Percentuale inferiore al 100% → Arancione
|
||||
$btn_text = '<i class="fas fa-user-edit"></i> ' . $row['owner_count'] . ' (' . htmlspecialchars($row['total_ownership']) . '%)';
|
||||
} else {
|
||||
$btn_class = "btn-success"; // Percentuale completa → Verde
|
||||
$btn_text = '<i class="fas fa-user-check"></i> ' . $row['owner_count'] . '';
|
||||
}
|
||||
?>
|
||||
<a href="assign-owners.php?idhome=<?php echo $row['idhome']; ?>" class="btn <?php echo $btn_class; ?> btn-sm mt-1">
|
||||
<?php echo $btn_text; ?>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
<!-- azioni -->
|
||||
<td class="text-nowrap">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="manage-home.php?idhome=<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-info-circle"></i> Dettagli
|
||||
</a></li>
|
||||
<li><a class="dropdown-item" href="documents-home.php?idhome=<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-folder-open"></i> Documenti
|
||||
</a></li>
|
||||
<li><a class="dropdown-item" href="share-home.php?idhome=<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-share-alt"></i> Condividi
|
||||
</a></li>
|
||||
<li><a class="dropdown-item transfer-property-btn" data-id="<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-exchange-alt"></i> Passaggio Proprietà
|
||||
</a></li>
|
||||
<li><a class="dropdown-item text-danger delete-home-btn" data-id="<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-trash-alt"></i> Elimina
|
||||
</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
</tr>
|
||||
|
||||
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div><!-- end table-responsive -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- grid view -->
|
||||
|
||||
<div id="gridView" style="display: block;">
|
||||
|
||||
<div class="row">
|
||||
<?php
|
||||
$result->data_seek(0); // Ripristina i dati per la griglia
|
||||
while ($row = $result->fetch_assoc()) { ?>
|
||||
<div class="col-md-3 col-sm-6 mb-4"> <!-- 4 per riga su desktop, 2 su tablet -->
|
||||
<div class="card shadow-sm border-0 position-relative box-home">
|
||||
<img src="mainphoto/<?php echo htmlspecialchars($row['mainphoto'] ?? 'default.jpg'); ?>"
|
||||
class="card-img-top"
|
||||
alt="<?php echo htmlspecialchars($row['name']); ?>">
|
||||
|
||||
<!-- Pulsante 3 puntini -->
|
||||
<!-- Contenitore per i bottoni (Proprietari + Menu Azioni) -->
|
||||
<!-- Contenitore per i bottoni (Proprietari a sinistra + Menu Azioni a destra) -->
|
||||
<div class="action-container">
|
||||
<!-- Bottone colorato con numero proprietari (SINISTRA) -->
|
||||
<?php
|
||||
if ($row['owner_count'] == 0) {
|
||||
$btn_class = "btn-danger"; // Nessun proprietario → Rosso
|
||||
} elseif ($row['total_ownership'] < 100) {
|
||||
$btn_class = "btn-warning"; // Percentuale inferiore al 100% → Arancione
|
||||
} else {
|
||||
$btn_class = "btn-success"; // Percentuale completa → Verde
|
||||
}
|
||||
?>
|
||||
<a href="assign-owners.php?idhome=<?php echo $row['idhome']; ?>" class="btn <?php echo $btn_class; ?> btn-sm owner-btn">
|
||||
<i class="fas fa-user"></i> <?php echo htmlspecialchars($row['owner_count']); ?>
|
||||
</a>
|
||||
|
||||
<!-- Pulsante 3 puntini (DESTRA) -->
|
||||
<div class="dropdown action-menu">
|
||||
<button class="btn btn-light btn-sm action-toggle" data-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<a class="dropdown-item" href="manage-home.php?idhome=<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-info-circle"></i> Dettagli
|
||||
</a>
|
||||
<a class="dropdown-item" href="documents-home.php?idhome=<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-folder-open"></i> Documenti
|
||||
</a>
|
||||
<a class="dropdown-item" href="share-home.php?idhome=<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-share-alt"></i> Condividi
|
||||
</a>
|
||||
<a class="dropdown-item transfer-property-btn" data-id="<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-exchange-alt"></i> Passaggio Proprietà
|
||||
</a>
|
||||
<a class="dropdown-item text-danger delete-home-btn" data-id="<?php echo $row['idhome']; ?>">
|
||||
<i class="fas fa-trash-alt"></i> Elimina
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="card-body text-center">
|
||||
<h5 class="card-title"><?php echo htmlspecialchars($row['name']); ?></h5>
|
||||
<p class="card-text"><?php echo htmlspecialchars($row['address']); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<button onclick="history.back()" class="btn btn-dark">
|
||||
<i class="fas fa-arrow-left"></i> Torna indietro
|
||||
@ -207,6 +513,65 @@ $result = $stmt->get_result();
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.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>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var table = $('#homeTable').DataTable({
|
||||
responsive: true,
|
||||
autoWidth: false // Impedisce a DataTables di calcolare larghezze fisse
|
||||
});
|
||||
|
||||
// Imposta la vista predefinita sulla Grid View
|
||||
$("#tableView").hide();
|
||||
$("#gridView").show();
|
||||
$("#toggleViewBtn").html('<i class="fas fa-list"></i> Vista Elenco');
|
||||
|
||||
$("#toggleViewBtn").click(function() {
|
||||
if ($("#tableView").is(":visible")) {
|
||||
$("#tableView").hide();
|
||||
$("#gridView").show();
|
||||
$("#toggleViewBtn").html('<i class="fas fa-list"></i> Vista Elenco');
|
||||
} else {
|
||||
$("#gridView").hide();
|
||||
$("#tableView").show();
|
||||
|
||||
// **Forza il ridisegno della tabella DataTables con una correzione aggiuntiva**
|
||||
setTimeout(function() {
|
||||
table.columns.adjust().draw();
|
||||
$('#homeTable').css('width', '100%'); // Forza la larghezza al 100%
|
||||
}, 200);
|
||||
|
||||
$("#toggleViewBtn").html('<i class="fas fa-th-large"></i> Vista Griglia');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Inizializza i dropdown manualmente per evitare conflitti
|
||||
var dropdowns = document.querySelectorAll('.dropdown-toggle');
|
||||
dropdowns.forEach(function(dropdown) {
|
||||
new bootstrap.Dropdown(dropdown);
|
||||
});
|
||||
|
||||
// Chiude il menu quando un'opzione viene cliccata
|
||||
$('.dropdown-menu a').on('click', function() {
|
||||
let dropdownMenu = $(this).closest('.dropdown-menu');
|
||||
let dropdownButton = dropdownMenu.prev('.dropdown-toggle');
|
||||
let dropdownInstance = bootstrap.Dropdown.getInstance(dropdownButton[0]);
|
||||
dropdownInstance.hide();
|
||||
});
|
||||
|
||||
// Chiude il dropdown quando si clicca fuori
|
||||
$(document).on('click', function(e) {
|
||||
if (!$(e.target).closest('.dropdown').length) {
|
||||
$('.dropdown-menu.show').removeClass('show');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
@ -224,20 +589,43 @@ $result = $stmt->get_result();
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Inizializza DataTables con filtri di colonna
|
||||
var table = $('#homeTable').DataTable();
|
||||
// Gestisci l'eliminazione con SweetAlert
|
||||
$('.delete-home-btn').on('click', function() {
|
||||
var idhome = $(this).data('id'); // Ottieni l'id della casa
|
||||
Swal.fire({
|
||||
title: 'Sei sicuro?',
|
||||
text: "Questa azione eliminerà la casa e non può essere annullata.",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#d33',
|
||||
cancelButtonColor: '#3085d6',
|
||||
confirmButtonText: 'Sì, elimina',
|
||||
cancelButtonText: 'Annulla'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
// Chiude il dropdown prima di eseguire l'azione
|
||||
let dropdownMenu = $(this).closest('.dropdown-menu');
|
||||
let dropdownButton = dropdownMenu.prev('.dropdown-toggle');
|
||||
let dropdownInstance = bootstrap.Dropdown.getInstance(dropdownButton[0]);
|
||||
|
||||
// Aggiungi ricerca personalizzata in ogni colonna
|
||||
$('#homeTable thead tr:eq(1) th').each(function(i) {
|
||||
$('input', this).on('keyup change', function() {
|
||||
if (table.column(i).search() !== this.value) {
|
||||
table.column(i).search(this.value).draw();
|
||||
if (dropdownInstance) {
|
||||
dropdownInstance.hide();
|
||||
}
|
||||
});
|
||||
|
||||
// Reindirizza al file di eliminazione
|
||||
window.location.href = "delete-home.php?idhome=" + idhome;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Evita la chiusura del dropdown se si clicca dentro
|
||||
$(".dropdown-menu").click(function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
// Gestisci l'eliminazione con SweetAlert
|
||||
// Gestione dell'eliminazione con SweetAlert
|
||||
$('.delete-home-btn').on('click', function() {
|
||||
var idhome = $(this).data('id'); // Ottieni l'id della casa
|
||||
Swal.fire({
|
||||
@ -251,13 +639,13 @@ $result = $stmt->get_result();
|
||||
cancelButtonText: 'Annulla'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
// Reindirizza al file di eliminazione
|
||||
window.location.href = "delete-home.php?idhome=" + idhome;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
<?php if (isset($_GET['status']) && $_GET['status'] == 'success') { ?>
|
||||
@ -275,6 +663,51 @@ $result = $stmt->get_result();
|
||||
<?php } ?>
|
||||
});
|
||||
</script>
|
||||
<!-- jQuery -->
|
||||
|
||||
<script src="assets/js/popper.min.js"></script>
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
<script src="assets/js/modernizr.min.js"></script>
|
||||
<script src="assets/js/detect.js"></script>
|
||||
<script src="assets/js/fastclick.js"></script>
|
||||
<script src="assets/js/jquery.slimscroll.js"></script>
|
||||
<script src="assets/js/jquery.blockUI.js"></script>
|
||||
<script src="assets/js/waves.js"></script>
|
||||
<script src="assets/js/jquery.nicescroll.js"></script>
|
||||
<script src="assets/js/jquery.scrollTo.min.js"></script>
|
||||
|
||||
<script src="assets/plugins/chart.js/chart.min.js"></script>
|
||||
|
||||
<!-- App js -->
|
||||
<script src="assets/js/app.js"></script>
|
||||
|
||||
|
||||
<!-- Modal per visualizzazione dell'immagine -->
|
||||
<div class="modal fade" id="photoModal" tabindex="-1" role="dialog" aria-labelledby="photoModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="photoModalLabel">Foto Immobile</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body text-center">
|
||||
<img id="modalPhoto" src="" class="img-fluid rounded" alt="Immagine immobile">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(".open-photo").on("click", function() {
|
||||
let imgSrc = $(this).attr("data-src");
|
||||
$("#modalPhoto").attr("src", imgSrc);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
BIN
public/userportal/mainphoto/2-15101febb-1740410415.png
Normal file
|
After Width: | Height: | Size: 3.4 MiB |
BIN
public/userportal/mainphoto/2-1e5e44aa1-1740410431.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
public/userportal/mainphoto/2-2-1740406717.png
Normal file
|
After Width: | Height: | Size: 569 KiB |
BIN
public/userportal/mainphoto/2-202306porticicasa05-1740410459.jpg
Normal file
|
After Width: | Height: | Size: 297 KiB |
BIN
public/userportal/mainphoto/2-202306porticicasa05-1740475641.jpg
Normal file
|
After Width: | Height: | Size: 297 KiB |
|
After Width: | Height: | Size: 24 KiB |
BIN
public/userportal/mainphoto/2-ufficioorganizzato-1740410481.jpg
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
public/userportal/mainphoto/2-ufficioorganizzato-1740410609.jpg
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
public/userportal/mainphoto/noimage.jpg
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
public/userportal/mainphoto/noimage.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
354
public/userportal/manage-home-old.php
Normal file
@ -0,0 +1,354 @@
|
||||
<?php include('include/headscript.php'); ?>
|
||||
|
||||
<?php
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Verifica se si sta aggiungendo una nuova casa o aggiornando una esistente
|
||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
$isNew = ($idhome == 0);
|
||||
|
||||
if ($isNew) {
|
||||
// Se non esiste ancora l'idhome, crea un nuovo record e ricarica la pagina con l'ID generato
|
||||
$insertQuery = $conn->prepare("INSERT INTO home (iduser) VALUES (?)");
|
||||
$insertQuery->bind_param("i", $iduserlogin);
|
||||
$insertQuery->execute();
|
||||
$idhome = $conn->insert_id; // Ottieni il nuovo idhome generato
|
||||
|
||||
// Ricarica la pagina con il nuovo idhome
|
||||
header("Location: manage-home.php?idhome=$idhome");
|
||||
exit(); // Assicurati di uscire per evitare che il codice continui
|
||||
}
|
||||
|
||||
// Se esiste già l'idhome, carica i dati della casa
|
||||
$query = $conn->prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?");
|
||||
$query->bind_param("ii", $idhome, $iduserlogin);
|
||||
$query->execute();
|
||||
$result = $query->get_result();
|
||||
$homeData = $result->fetch_assoc();
|
||||
|
||||
// Assegna i valori esistenti ai campi
|
||||
$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'];
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
||||
<?php include('include/seo.php'); ?>
|
||||
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/icons.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
<style>
|
||||
#map {
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.success-flash {
|
||||
background-color: #d4edda !important;
|
||||
transition: background-color 1s ease;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
<div id="wrapper">
|
||||
<?php include('include/navigationbar.php'); ?>
|
||||
|
||||
<div class="content-page">
|
||||
<div class="content">
|
||||
<?php include('include/topbar.php'); ?>
|
||||
|
||||
<div class="page-content-wrapper">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="page-title-box d-flex justify-content-between align-items-center">
|
||||
<!-- Titolo -->
|
||||
<h4 class="page-title m-0"><?php echo $isNew ? "Aggiungi Casa" : "Modifica Casa"; ?></h4>
|
||||
|
||||
<!-- Tasto Torna indietro -->
|
||||
<button onclick="history.back()" class="btn btn-dark">
|
||||
<i class="fas fa-arrow-left"></i> Torna indietro
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<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="form-group">
|
||||
<label>Nome</label>
|
||||
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Nota</label>
|
||||
<textarea id="comment" name="comment" rows="4" class="form-control"><?php echo htmlspecialchars($commentdb); ?></textarea>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4">Carica Foto</h4>
|
||||
<div class="form-group">
|
||||
<label for="photo">Foto dell'immobile</label>
|
||||
<input type="file" id="photo" name="photo" class="form-control" accept="image/*">
|
||||
<small class="text-muted">Carica un'unica foto, verrà sovrascritta se ne scegli un'altra.</small>
|
||||
</div>
|
||||
|
||||
<!-- Anteprima della foto -->
|
||||
<div class="form-group">
|
||||
<img id="photo-preview" src="<?php echo !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphoto'] : 'assets/images/no-image.jpg'; ?>" alt="Anteprima Foto" style="max-width: 200px; display: block; margin-top: 10px;">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('photo').addEventListener('change', function(event) {
|
||||
let file = event.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("photo", file);
|
||||
formData.append("idhome", <?php echo $idhome; ?>);
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "save-home.php", true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
let response = JSON.parse(xhr.responseText);
|
||||
if (response.success) {
|
||||
document.getElementById('photo-preview').src = "mainphoto/" + response.filename;
|
||||
} else {
|
||||
alert("Errore nel caricamento: " + response.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
<h4 class="mt-4">Geolocalizzazione</h4>
|
||||
<div id="map"></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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- container -->
|
||||
</div> <!-- Page content Wrapper -->
|
||||
</div> <!-- content -->
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Google Maps API for Autocomplete and Geolocation -->
|
||||
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyADtQRKgCpJNnQCP8QvBeKDcm0TrTPpsGY&libraries=places&callback=initAutocomplete"></script>
|
||||
<script>
|
||||
let map, marker, autocomplete;
|
||||
|
||||
// Funzione per inviare i dati del campo tramite AJAX
|
||||
function updateField(field, value, additionalData = {}) {
|
||||
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() {
|
||||
inputField.classList.remove("success-flash");
|
||||
}, 1000);
|
||||
} else {
|
||||
console.error("Errore durante l'aggiornamento: " + xhr.responseText);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let params = `field=${encodeURIComponent(field)}&value=${encodeURIComponent(value)}&idhome=${idhome}`;
|
||||
for (let key in additionalData) {
|
||||
params += `&${key}=${encodeURIComponent(additionalData[key])}`;
|
||||
}
|
||||
|
||||
xhr.send(params);
|
||||
}
|
||||
|
||||
// Funzione per la mappa e autocomplete
|
||||
function initAutocomplete() {
|
||||
const latitude = parseFloat(document.getElementById('latitude').value);
|
||||
const longitude = parseFloat(document.getElementById('longitude').value);
|
||||
|
||||
const defaultLocation = {
|
||||
lat: 41.9028,
|
||||
lng: 12.4964
|
||||
}; // Default location: Rome
|
||||
const location = !isNaN(latitude) && !isNaN(longitude) ? {
|
||||
lat: latitude,
|
||||
lng: longitude
|
||||
} : defaultLocation;
|
||||
|
||||
// Inizializza la mappa
|
||||
map = new google.maps.Map(document.getElementById('map'), {
|
||||
center: location,
|
||||
zoom: 14
|
||||
});
|
||||
|
||||
// Aggiungi un marker
|
||||
marker = new google.maps.Marker({
|
||||
position: location,
|
||||
map: map,
|
||||
draggable: true
|
||||
});
|
||||
|
||||
google.maps.event.addListener(marker, 'dragend', function() {
|
||||
const position = marker.getPosition();
|
||||
document.getElementById('latitude').value = position.lat();
|
||||
document.getElementById('longitude').value = position.lng();
|
||||
|
||||
// Aggiorna latitudine e longitudine
|
||||
updateField('latitude', position.lat());
|
||||
updateField('longitude', position.lng());
|
||||
});
|
||||
|
||||
// Autocomplete per l'indirizzo
|
||||
autocomplete = new google.maps.places.Autocomplete(document.getElementById('fulladdress'), {
|
||||
types: ['geocode']
|
||||
});
|
||||
autocomplete.addListener('place_changed', fillInAddress);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
const location = place.geometry.location;
|
||||
|
||||
// Imposta latitudine e longitudine se esistono gli elementi corrispondenti
|
||||
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 = "",
|
||||
city = "",
|
||||
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;
|
||||
if (types.includes("locality")) city = component.long_name;
|
||||
if (types.includes("country")) country = component.long_name;
|
||||
if (types.includes("street_number") || types.includes("route")) {
|
||||
address += component.long_name + " ";
|
||||
}
|
||||
});
|
||||
|
||||
// Imposta i valori se esistono gli elementi corrispondenti
|
||||
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();
|
||||
}
|
||||
|
||||
// Centra la mappa e sposta il marker nella nuova posizione
|
||||
map.setCenter(location);
|
||||
marker.setPosition(location);
|
||||
|
||||
// Aggiorna i campi tramite AJAX
|
||||
updateField('fulladdress', document.getElementById('fulladdress').value, {
|
||||
address: address.trim(),
|
||||
zip: zip,
|
||||
city: city,
|
||||
country: country,
|
||||
latitude: location.lat(),
|
||||
longitude: location.lng()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Aggiorna i dati tramite AJAX al cambio di valore
|
||||
document.getElementById('name').addEventListener('change', function() {
|
||||
updateField('name', this.value);
|
||||
});
|
||||
|
||||
document.getElementById('comment').addEventListener('change', function() {
|
||||
updateField('comment', this.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="assets/js/jquery.min.js"></script>
|
||||
<script src="assets/js/popper.min.js"></script>
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -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>
|
||||
|
||||
@ -1,32 +1,84 @@
|
||||
<?php
|
||||
// Debug: attivare la visualizzazione degli errori
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Verifica della connessione
|
||||
if ($conn->connect_error) {
|
||||
die(json_encode(['success' => false, 'message' => "Connessione fallita: " . $conn->connect_error]));
|
||||
}
|
||||
|
||||
// Recupera i dati inviati tramite AJAX
|
||||
// Verifica se è un upload di immagine
|
||||
if (!empty($_FILES['photo']) && isset($_POST['idhome'])) {
|
||||
$idhome = intval($_POST['idhome']);
|
||||
|
||||
$uploadDir = 'mainphoto/';
|
||||
if (!file_exists($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
}
|
||||
|
||||
$file = $_FILES['photo'];
|
||||
$originalName = pathinfo($file['name'], PATHINFO_FILENAME);
|
||||
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif'];
|
||||
|
||||
if (!in_array($extension, $allowedExtensions)) {
|
||||
die(json_encode(['success' => false, 'message' => "Formato non valido. Usa JPG, PNG o GIF."]));
|
||||
}
|
||||
|
||||
$newFilename = $iduserlogin . "-" . preg_replace("/[^a-zA-Z0-9]/", "", $originalName) . "-" . time() . "." . $extension;
|
||||
$filePath = $uploadDir . $newFilename;
|
||||
|
||||
if (move_uploaded_file($file['tmp_name'], $filePath)) {
|
||||
$stmt = $conn->prepare("UPDATE home SET mainphoto = ? WHERE idhome = ?");
|
||||
$stmt->bind_param("si", $newFilename, $idhome);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
echo json_encode(['success' => true, 'filename' => $newFilename]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => "Errore nel salvataggio del file."]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
// Aggiornamento AJAX degli altri campi
|
||||
$idhome = isset($_POST['idhome']) ? intval($_POST['idhome']) : 0;
|
||||
$field = isset($_POST['field']) ? $conn->real_escape_string($_POST['field']) : '';
|
||||
$value = isset($_POST['value']) ? $conn->real_escape_string($_POST['value']) : '';
|
||||
|
||||
// Verifica che i campi siano validi
|
||||
if (empty($field) || empty($value)) {
|
||||
die(json_encode(['success' => false, 'message' => 'Dati non validi']));
|
||||
// Lista dei campi consentiti per la sicurezza
|
||||
$allowedFields = [
|
||||
'name',
|
||||
'comment',
|
||||
'fulladdress',
|
||||
'address',
|
||||
'zip',
|
||||
'city',
|
||||
'country',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'cadastral_municipality',
|
||||
'cadastral_section',
|
||||
'cadastral_sheet',
|
||||
'cadastral_particle',
|
||||
'cadastral_sub',
|
||||
'cadastral_category',
|
||||
'cadastral_class',
|
||||
'cadastral_surface',
|
||||
'cadastral_rendita',
|
||||
'cadastral_notes'
|
||||
];
|
||||
|
||||
// Se il campo non è nella lista, termina lo script per evitare SQL Injection
|
||||
if (!in_array($field, $allowedFields)) {
|
||||
die(json_encode(['success' => false, 'message' => "Campo non valido."]));
|
||||
}
|
||||
|
||||
// Gestione per fulladdress e altri campi
|
||||
// Se è l'aggiornamento dell'indirizzo completo, aggiorniamo tutti i relativi campi
|
||||
if ($field == 'fulladdress') {
|
||||
// Separazione dell'indirizzo completo nei suoi componenti (indirizzo, città, CAP, nazione)
|
||||
$address = isset($_POST['address']) ? $conn->real_escape_string($_POST['address']) : '';
|
||||
$city = isset($_POST['city']) ? $conn->real_escape_string($_POST['city']) : '';
|
||||
$zip = isset($_POST['zip']) ? $conn->real_escape_string($_POST['zip']) : '';
|
||||
@ -34,7 +86,8 @@ if ($field == 'fulladdress') {
|
||||
$latitude = isset($_POST['latitude']) ? $conn->real_escape_string($_POST['latitude']) : '';
|
||||
$longitude = isset($_POST['longitude']) ? $conn->real_escape_string($_POST['longitude']) : '';
|
||||
|
||||
// Aggiorna i campi nel database
|
||||
error_log("Aggiornamento indirizzo: fulladdress=$value, address=$address, city=$city, zip=$zip, country=$country, latitude=$latitude, longitude=$longitude, idhome=$idhome");
|
||||
|
||||
$query = "UPDATE home SET fulladdress = ?, address = ?, city = ?, zip = ?, country = ?, latitude = ?, longitude = ? WHERE idhome = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
if ($stmt === false) {
|
||||
@ -42,7 +95,7 @@ if ($field == 'fulladdress') {
|
||||
}
|
||||
$stmt->bind_param("sssssssi", $value, $address, $city, $zip, $country, $latitude, $longitude, $idhome);
|
||||
} else {
|
||||
// Aggiorna altri campi
|
||||
// Aggiornamento di qualsiasi altro campo
|
||||
$query = "UPDATE home SET $field = ? WHERE idhome = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
if ($stmt === false) {
|
||||
@ -51,11 +104,11 @@ if ($field == 'fulladdress') {
|
||||
$stmt->bind_param("si", $value, $idhome);
|
||||
}
|
||||
|
||||
// Esegui l'aggiornamento
|
||||
// Esegui la query
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['success' => true, 'message' => 'Aggiornamento riuscito']);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore durante l\'esecuzione della query: ' . $stmt->error]);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
|
||||