diff --git a/public/assets/js/as/app.js b/public/assets/js/as/app.js index 4cf43cd..dee00aa 100644 --- a/public/assets/js/as/app.js +++ b/public/assets/js/as/app.js @@ -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 () { diff --git a/public/userportal/details-home.php b/public/userportal/details-home.php new file mode 100644 index 0000000..f14bcec --- /dev/null +++ b/public/userportal/details-home.php @@ -0,0 +1,516 @@ + + +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']; +?> + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + +
+
+
+
+
+ +

+ + + +
+
+
+ + +
+
+
+
+

+ +
+
+
+ + + +
+
+
+ + +
+ +
+
Note
+ +
+
+
+ +
+ + Anteprima Foto +
+ Carica un'unica foto, verrà sovrascritta se ne scegli un'altra. +
+
+ + +
+
Indirizzo
+ + +
+
+ + +
+
Dati Catastali
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+
+
+ + + + + + + + + + +
+
+
+ +
+
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userportal/homes-list.php b/public/userportal/homes-list.php index 1acd145..b9dcaae 100644 --- a/public/userportal/homes-list.php +++ b/public/userportal/homes-list.php @@ -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(); + + + @@ -88,109 +291,212 @@ $result = $stmt->get_result();
-
- +
+ + Aggiungi Casa/Terreno + + +
-
-
-
-
-
- - - - - - - - - - - - - - - + + - - - - - - - - fetch_assoc()) { ?> +
+
+
+
+
+ +
NomeIndirizzoCittàNazioneNomi ProprietariProprietariAction
+ - - - - - - - - - - - - - - - + + + + + + - - -
- - - - Assegna Proprietario - - - - Proprietari - - - -
- - - - - - - - - - - - - - - - - - - - -
-
FotoNomeCittà / NazioneIndirizzoProprietariAction
-
+ + + + + + + + + + + + + + + fetch_assoc()) { ?> + + + + <?php echo htmlspecialchars($row['name']); ?> + + + + + + + + + , + + + + + + + +
+ Assegna Proprietario'; + } elseif ($row['total_ownership'] < 100) { + $btn_class = "btn-warning"; // Percentuale inferiore al 100% → Arancione + $btn_text = ' ' . $row['owner_count'] . ' (' . htmlspecialchars($row['total_ownership']) . '%)'; + } else { + $btn_class = "btn-success"; // Percentuale completa → Verde + $btn_text = ' ' . $row['owner_count'] . ''; + } + ?> + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+ data_seek(0); // Ripristina i dati per la griglia + while ($row = $result->fetch_assoc()) { ?> +
+
+ <?php echo htmlspecialchars($row['name']); ?> + + + + + + + + + +
+
+

+
+
+
+ +
+
+ + + + + +
+
+ + + + + + + diff --git a/public/userportal/mainphoto/2-15101febb-1740410415.png b/public/userportal/mainphoto/2-15101febb-1740410415.png new file mode 100644 index 0000000..0100404 Binary files /dev/null and b/public/userportal/mainphoto/2-15101febb-1740410415.png differ diff --git a/public/userportal/mainphoto/2-1e5e44aa1-1740410431.png b/public/userportal/mainphoto/2-1e5e44aa1-1740410431.png new file mode 100644 index 0000000..6544b0d Binary files /dev/null and b/public/userportal/mainphoto/2-1e5e44aa1-1740410431.png differ diff --git a/public/userportal/mainphoto/2-2-1740406717.png b/public/userportal/mainphoto/2-2-1740406717.png new file mode 100644 index 0000000..f5b13ca Binary files /dev/null and b/public/userportal/mainphoto/2-2-1740406717.png differ diff --git a/public/userportal/mainphoto/2-202306porticicasa05-1740410459.jpg b/public/userportal/mainphoto/2-202306porticicasa05-1740410459.jpg new file mode 100644 index 0000000..f7a17ae Binary files /dev/null and b/public/userportal/mainphoto/2-202306porticicasa05-1740410459.jpg differ diff --git a/public/userportal/mainphoto/2-202306porticicasa05-1740475641.jpg b/public/userportal/mainphoto/2-202306porticicasa05-1740475641.jpg new file mode 100644 index 0000000..f7a17ae Binary files /dev/null and b/public/userportal/mainphoto/2-202306porticicasa05-1740475641.jpg differ diff --git a/public/userportal/mainphoto/2-Immagine20241106165906-1740406948.png b/public/userportal/mainphoto/2-Immagine20241106165906-1740406948.png new file mode 100644 index 0000000..fa92ce1 Binary files /dev/null and b/public/userportal/mainphoto/2-Immagine20241106165906-1740406948.png differ diff --git a/public/userportal/mainphoto/2-ufficioorganizzato-1740410481.jpg b/public/userportal/mainphoto/2-ufficioorganizzato-1740410481.jpg new file mode 100644 index 0000000..96d0966 Binary files /dev/null and b/public/userportal/mainphoto/2-ufficioorganizzato-1740410481.jpg differ diff --git a/public/userportal/mainphoto/2-ufficioorganizzato-1740410609.jpg b/public/userportal/mainphoto/2-ufficioorganizzato-1740410609.jpg new file mode 100644 index 0000000..96d0966 Binary files /dev/null and b/public/userportal/mainphoto/2-ufficioorganizzato-1740410609.jpg differ diff --git a/public/userportal/mainphoto/noimage.jpg b/public/userportal/mainphoto/noimage.jpg new file mode 100644 index 0000000..1f724cc Binary files /dev/null and b/public/userportal/mainphoto/noimage.jpg differ diff --git a/public/userportal/mainphoto/noimage.png b/public/userportal/mainphoto/noimage.png new file mode 100644 index 0000000..3035730 Binary files /dev/null and b/public/userportal/mainphoto/noimage.png differ diff --git a/public/userportal/manage-home-old.php b/public/userportal/manage-home-old.php new file mode 100644 index 0000000..19a49e0 --- /dev/null +++ b/public/userportal/manage-home-old.php @@ -0,0 +1,354 @@ + + +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']; +?> + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + +
+
+
+
+
+ +

+ + + +
+
+
+ + +
+
+
+

+
+ + +
+ + +
+ +
+ + +
+ +

Carica Foto

+
+ + + Carica un'unica foto, verrà sovrascritta se ne scegli un'altra. +
+ + +
+ Anteprima Foto +
+ + + + +

Indirizzo Completo

+
+ + +
+ +

Geolocalizzazione

+
+ +
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userportal/manage-home.php b/public/userportal/manage-home.php index 8b66ed2..6366480 100644 --- a/public/userportal/manage-home.php +++ b/public/userportal/manage-home.php @@ -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'];
-
-

-
- +
+
+

+ +
+
+ + -
- - -
+ +
+
+
+ + +
+ +
+
Note
+ +
+
+
+ +
+ + Anteprima Foto +
+ Carica un'unica foto, verrà sovrascritta se ne scegli un'altra. +
+
-
- - -
+ +
+
Indirizzo
+ + +
+
-

Indirizzo Completo

-
- - -
+ +
+
Dati Catastali
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
-

Geolocalizzazione

-
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
-
- - -
-
- - -
-
- - -
- -
- - -
-
- - -
- - + + +
+ + + + + + + + + +
@@ -161,12 +367,14 @@ $fulladdressdb = $homeData['fulladdress']; const 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); + }); + } }); + diff --git a/public/userportal/save-home.php b/public/userportal/save-home.php index 34c059c..ca1f179 100644 --- a/public/userportal/save-home.php +++ b/public/userportal/save-home.php @@ -1,32 +1,84 @@ 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();