From 9bfa037c51af193fab6f445f4ac919061faa8d3c Mon Sep 17 00:00:00 2001 From: Claudio Date: Wed, 5 Mar 2025 11:57:26 +0100 Subject: [PATCH] update shared homes and documents section --- public/userportal/documents-home.php | 911 ++++++++++-------- .../userportal/documents-home_bck050325.php | 649 +++++++++++++ public/userportal/get-documents.php | 83 ++ public/userportal/manage-home.php | 45 +- public/userportal/shared-homes.php | 549 +++++++++-- public/userportal/shared-homes_bck.php | 197 ++++ 6 files changed, 1970 insertions(+), 464 deletions(-) create mode 100644 public/userportal/documents-home_bck050325.php create mode 100644 public/userportal/get-documents.php create mode 100644 public/userportal/shared-homes_bck.php diff --git a/public/userportal/documents-home.php b/public/userportal/documents-home.php index fa59e9a..a1a8495 100644 --- a/public/userportal/documents-home.php +++ b/public/userportal/documents-home.php @@ -21,51 +21,8 @@ $queryHome->execute(); $resultHome = $queryHome->get_result(); $homeData = $resultHome->fetch_assoc(); -if (!isset($_GET['docpage'])) { - $docpage = "legal"; // Slug predefinito -} else { - $docpage = $_GET['docpage']; // Slug passato via GET -} - -// Recupera il `page_id` corrispondente allo slug -$queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?"); -$queryPageId->bind_param('s', $docpage); -$queryPageId->execute(); -$resultPageId = $queryPageId->get_result(); -$pageData = $resultPageId->fetch_assoc(); - -if ($pageData) { - $page_id = $pageData['idpages']; // Page ID trovato -} else { - die("Errore: Pagina non valida."); // Slug non trovato -} - -// Recupera i documenti associati al `page_id`, con le sezioni -$queryDocuments = $conn->prepare(" - SELECT d.*, s.section_name AS section_name - FROM documents d - LEFT JOIN sections s ON d.idsections = s.idsections - WHERE d.page_id = ? - ORDER BY s.section_name, d.document_name -"); -$queryDocuments->bind_param('i', $page_id); -$queryDocuments->execute(); -$resultDocuments = $queryDocuments->get_result(); - -$documents = []; -while ($row = $resultDocuments->fetch_assoc()) { - $documents[$row['section_name']][] = $row; -} - -// Recupera i documenti già caricati per questa casa -$queryLoadedDocuments = $conn->prepare("SELECT * FROM doc_storage WHERE idhome = ?"); -$queryLoadedDocuments->bind_param('i', $idhome); -$queryLoadedDocuments->execute(); -$resultLoadedDocuments = $queryLoadedDocuments->get_result(); - -$loadedDocuments = []; -while ($row = $resultLoadedDocuments->fetch_assoc()) { - $loadedDocuments[$row['document_id']][] = $row; +if (!$homeData) { + die("Errore: Casa non trovata o accesso non autorizzato."); } // Recupera le pagine disponibili nella tabella 'documents' @@ -74,8 +31,10 @@ $pages = []; while ($row = $queryPages->fetch_assoc()) { $pages[] = $row; } -?> +// Imposta lo slug predefinito o usa quello passato via GET +$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal'; +?> @@ -98,9 +57,6 @@ while ($row = $queryPages->fetch_assoc()) { - - - @@ -252,6 +208,51 @@ while ($row = $queryPages->fetch_assoc()) { display: none; /* Nasconde inizialmente l'area */ } + + /* Stile per il gruppo input su desktop */ + .input-group { + max-width: 400px; + /* Limita la larghezza totale su desktop */ + margin: 0 auto; + /* Centra orizzontalmente su mobile */ + } + + #documentSearch { + border-radius: 0.25rem 0 0 0.25rem; + /* Arrotonda solo l'angolo sinistro */ + } + + /* Stile per i risultati della ricerca */ + #searchResults { + background-color: #fff; + border: 1px solid #ddd; + border-radius: 0.25rem; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); + } + + #searchResults .list-group-item { + cursor: pointer; + } + + #searchResults .list-group-item:hover { + background-color: #f8f9fa; + } + + /* Su tablet e mobile, allinea tutto al centro e separa in due righe */ + @media (max-width: 767.98px) { + .input-group { + max-width: 100%; + /* Usa tutta la larghezza su mobile */ + margin-top: 10px; + /* Spazio sopra il campo di ricerca */ + } + + #pageSelectDropdown, + #documentSearch { + width: 100% !important; + /* Usa tutta la larghezza su mobile */ + } + } @@ -278,106 +279,27 @@ while ($row = $queryPages->fetch_assoc()) {
-
+
- -
-
- - - - -
- $sectionDocuments) { ?> -
- -

- -

- -
-
- -
- -
-
- - - Obbligatorio - - 0) { ?> - Max: - -
- -
- - - -
-
-
-
- Trascina qui i documenti o clicca per caricarli -
-
-
- -
-
- - -
Documenti già caricati:
- 0) { ?> - - - - - - - - - - - - - - - - - - -
Nome DocumentoData CaricamentoAzioni
- - -

Nessun documento caricato

- - -
- -
-
+
+
+ +
- +
- - + +
@@ -385,265 +307,494 @@ while ($row = $queryPages->fetch_assoc()) { - + - - - - - - - - + - + + - - \ No newline at end of file diff --git a/public/userportal/documents-home_bck050325.php b/public/userportal/documents-home_bck050325.php new file mode 100644 index 0000000..fa59e9a --- /dev/null +++ b/public/userportal/documents-home_bck050325.php @@ -0,0 +1,649 @@ + +prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?"); +$queryHome->bind_param('ii', $idhome, $iduserlogin); +$queryHome->execute(); +$resultHome = $queryHome->get_result(); +$homeData = $resultHome->fetch_assoc(); + +if (!isset($_GET['docpage'])) { + $docpage = "legal"; // Slug predefinito +} else { + $docpage = $_GET['docpage']; // Slug passato via GET +} + +// Recupera il `page_id` corrispondente allo slug +$queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?"); +$queryPageId->bind_param('s', $docpage); +$queryPageId->execute(); +$resultPageId = $queryPageId->get_result(); +$pageData = $resultPageId->fetch_assoc(); + +if ($pageData) { + $page_id = $pageData['idpages']; // Page ID trovato +} else { + die("Errore: Pagina non valida."); // Slug non trovato +} + +// Recupera i documenti associati al `page_id`, con le sezioni +$queryDocuments = $conn->prepare(" + SELECT d.*, s.section_name AS section_name + FROM documents d + LEFT JOIN sections s ON d.idsections = s.idsections + WHERE d.page_id = ? + ORDER BY s.section_name, d.document_name +"); +$queryDocuments->bind_param('i', $page_id); +$queryDocuments->execute(); +$resultDocuments = $queryDocuments->get_result(); + +$documents = []; +while ($row = $resultDocuments->fetch_assoc()) { + $documents[$row['section_name']][] = $row; +} + +// Recupera i documenti già caricati per questa casa +$queryLoadedDocuments = $conn->prepare("SELECT * FROM doc_storage WHERE idhome = ?"); +$queryLoadedDocuments->bind_param('i', $idhome); +$queryLoadedDocuments->execute(); +$resultLoadedDocuments = $queryLoadedDocuments->get_result(); + +$loadedDocuments = []; +while ($row = $resultLoadedDocuments->fetch_assoc()) { + $loadedDocuments[$row['document_id']][] = $row; +} + +// Recupera le pagine disponibili nella tabella 'documents' +$queryPages = $conn->query("SELECT * FROM pages ORDER BY namepages"); +$pages = []; +while ($row = $queryPages->fetch_assoc()) { + $pages[] = $row; +} +?> + + + + + + + + + + Documenti della Casa + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+ +
+
+

Documenti per la Casa:

+

Indirizzo:

+
+
+ +
+
+ +
+
+ + +
+
+ + + + +
+ $sectionDocuments) { ?> +
+ +

+ +

+ +
+
+ +
+ +
+
+ + + Obbligatorio + + 0) { ?> + Max: + +
+ +
+ + + +
+
+
+
+ Trascina qui i documenti o clicca per caricarli +
+
+
+ +
+
+ + +
Documenti già caricati:
+ 0) { ?> + + + + + + + + + + + + + + + + + + +
Nome DocumentoData CaricamentoAzioni
+ + +

Nessun documento caricato

+ + +
+ +
+
+
+ +
+ + + +
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userportal/get-documents.php b/public/userportal/get-documents.php new file mode 100644 index 0000000..8d922d7 --- /dev/null +++ b/public/userportal/get-documents.php @@ -0,0 +1,83 @@ +prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?"); +$queryHome->bind_param('ii', $idhome, $iduserlogin); +$queryHome->execute(); +$resultHome = $queryHome->get_result(); +$homeData = $resultHome->fetch_assoc(); + +if (!$homeData) { + header('HTTP/1.1 400 Bad Request'); + die(json_encode(['error' => 'Casa non trovata o accesso non autorizzato'])); +} + +// Recupera il `page_id` corrispondente allo slug +$queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?"); +$queryPageId->bind_param('s', $docpage); +$queryPageId->execute(); +$resultPageId = $queryPageId->get_result(); +$pageData = $resultPageId->fetch_assoc(); + +if (!$pageData) { + header('HTTP/1.1 400 Bad Request'); + die(json_encode(['error' => 'Pagina non valida'])); +} + +$page_id = $pageData['idpages']; + +// Recupera i documenti associati al `page_id`, con le sezioni +$queryDocuments = $conn->prepare(" + SELECT d.*, s.section_name AS section_name + FROM documents d + LEFT JOIN sections s ON d.idsections = s.idsections + WHERE d.page_id = ? + ORDER BY s.section_name, d.document_name +"); +$queryDocuments->bind_param('i', $page_id); +$queryDocuments->execute(); +$resultDocuments = $queryDocuments->get_result(); + +$documents = []; +while ($row = $resultDocuments->fetch_assoc()) { + $documents[$row['section_name']][] = $row; +} + +// Recupera i documenti già caricati per questa casa +$queryLoadedDocuments = $conn->prepare("SELECT * FROM doc_storage WHERE idhome = ?"); +$queryLoadedDocuments->bind_param('i', $idhome); +$queryLoadedDocuments->execute(); +$resultLoadedDocuments = $queryLoadedDocuments->get_result(); + +$loadedDocuments = []; +while ($row = $resultLoadedDocuments->fetch_assoc()) { + $loadedDocuments[$row['document_id']][] = $row; +} + +// Prepara la risposta JSON +$response = [ + 'homeName' => $homeData['name'] ?? '', + 'homeAddress' => ($homeData['address'] ?? '') . ', ' . ($homeData['city'] ?? '') . ' ' . ($homeData['zip'] ?? ''), + 'documents' => $documents, + 'loadedDocuments' => $loadedDocuments +]; + +// Imposta l'header per indicare JSON +header('Content-Type: application/json'); + +// Evita output extra +echo json_encode($response, JSON_PRETTY_PRINT); +exit; diff --git a/public/userportal/manage-home.php b/public/userportal/manage-home.php index 8cea001..5ca671a 100644 --- a/public/userportal/manage-home.php +++ b/public/userportal/manage-home.php @@ -4,6 +4,10 @@ // Connessione al database $conn = new mysqli($servername, $username, $password, $database); +// Recupera l'id utente loggato e la sua email +$iduserlogin = $_SESSION['iduserlogin']; +$emailuser = $_SESSION['emailuser']; + // Verifica se si sta aggiungendo una nuova casa o aggiornando una esistente $idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0; $isNew = ($idhome == 0); @@ -20,9 +24,44 @@ if ($isNew) { 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); +// Determina l'iduser corretto per l'immobile, controllando sia il proprietario che le condivisioni +$ownerId = null; +$queryOwner = $conn->prepare("SELECT iduser FROM home WHERE idhome = ?"); +$queryOwner->bind_param("i", $idhome); +$queryOwner->execute(); +$resultOwner = $queryOwner->get_result(); +if ($resultOwner->num_rows > 0) { + $ownerData = $resultOwner->fetch_assoc(); + $ownerId = $ownerData['iduser']; +} + +// Verifica se l'utente ha accesso diretto (è il proprietario) o tramite condivisione +$hasAccess = false; +if ($ownerId == $iduserlogin) { + $hasAccess = true; // Utente è il proprietario +} else { + // Controlla se l'utente ha accesso tramite home_sharing + $querySharing = $conn->prepare(" + SELECT * FROM home_sharing + WHERE idhome = ? + AND (idshareduser = ? OR shared_email = ?) + AND status = 'accepted' + "); + $querySharing->bind_param("iis", $idhome, $iduserlogin, $emailuser); + $querySharing->execute(); + $resultSharing = $querySharing->get_result(); + $hasAccess = ($resultSharing->num_rows > 0); +} + +// Se l'utente non ha accesso, reindirizza o mostra un errore +if (!$hasAccess) { + header("Location: access-denied.php"); // O una pagina di errore personalizzata + exit(); +} + +// Carica i dati della casa per l'utente con accesso +$query = $conn->prepare("SELECT * FROM home WHERE idhome = ?"); +$query->bind_param("i", $idhome); $query->execute(); $result = $query->get_result(); $homeData = $result->fetch_assoc(); diff --git a/public/userportal/shared-homes.php b/public/userportal/shared-homes.php index 8513791..6bfb125 100644 --- a/public/userportal/shared-homes.php +++ b/public/userportal/shared-homes.php @@ -15,20 +15,31 @@ SELECT h.address, h.zip, h.city, - h.country, + h.country, + h.mainphoto, hs.sharing_type, hs.expiration_date, au.first_name, au.last_name, - COUNT(ho.owner_id) AS owner_count + 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, ' (', ho.ownership_percentage, '%)') + ELSE CONCAT(po.company_name, ' (', ho.ownership_percentage, '%)') + END + SEPARATOR '\n' + ) AS owner_names FROM home_sharing hs LEFT JOIN home h ON hs.idhome = h.idhome LEFT JOIN auth_users au ON hs.iduser = au.id LEFT JOIN home_owners ho ON hs.idhome = ho.home_id +LEFT JOIN property_owners po ON ho.owner_id = po.owner_id WHERE (hs.idshareduser = ? OR hs.shared_email = ?) AND hs.status = 'accepted' - GROUP BY +GROUP BY hs.idhome, h.name, h.address, @@ -65,6 +76,199 @@ $result = $stmt->get_result(); + + + + @@ -90,85 +294,171 @@ $result = $stmt->get_result(); -
-
-
-
-
- - - - - - - - - - - - - - - - fetch_assoc()) { ?> +
+
+ +
+
+ + +
NomeIndirizzoCAPCittàNazioneCondiviso daProprietariData ScadenzaAzioni
+ - - - - - - - - - - - + + + + + + + + - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FotoNomeCittà / NazioneIndirizzoProprietariCondiviso daData ScadenzaAzioni
-
+ + + + + + + + + + + + + fetch_assoc()) { ?> + + + <?php echo htmlspecialchars($row['name']); ?> + + + , + + + +
+ Assegna Proprietario'; + } elseif ($row['total_ownership'] < 100) { + $btn_class = "btn-warning"; + $btn_text = ' ' . $row['owner_count'] . ' (' . htmlspecialchars($row['total_ownership']) . '%)'; + } else { + $btn_class = "btn-success"; + $btn_text = ' ' . $row['owner_count']; + } + ?> + + + + + + + + + + + + + +
+
-
- -
+ + +
+
+ data_seek(0); // Ripristina i dati per la griglia + while ($row = $result->fetch_assoc()) { ?> + + +
+
+ +
+ +
@@ -180,14 +470,111 @@ $result = $stmt->get_result(); + + + + + + + + + + + + + + + diff --git a/public/userportal/shared-homes_bck.php b/public/userportal/shared-homes_bck.php new file mode 100644 index 0000000..8513791 --- /dev/null +++ b/public/userportal/shared-homes_bck.php @@ -0,0 +1,197 @@ + +prepare($sql); +$stmt->bind_param('is', $iduserlogin, $emailuser); +$stmt->execute(); +$result = $stmt->get_result(); +?> + + + + + + + + Immobili Condivisi + + + + + + + + + + + + + + + +
+ +
+
+ + +
+
+
+
+
+
+ +
+

Immobili Condivisi

+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + fetch_assoc()) { ?> + + + + + + + + + + + + + + + +
NomeIndirizzoCAPCittàNazioneCondiviso daProprietariData ScadenzaAzioni
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + \ No newline at end of file