From 5d64b2ed06037452a7bf3e61efb287867f08f710 Mon Sep 17 00:00:00 2001 From: Claudio Date: Wed, 4 Dec 2024 21:07:29 +0100 Subject: [PATCH] fixed section share --- public/userportal/documents-home-shared.php | 598 ++++++++++++++++++++ public/userportal/include/navigationbar.php | 4 +- public/userportal/include/topbar.php | 8 +- public/userportal/index.php | 2 +- public/userportal/shared-homes.php | 152 +++++ 5 files changed, 757 insertions(+), 7 deletions(-) create mode 100644 public/userportal/documents-home-shared.php create mode 100644 public/userportal/shared-homes.php diff --git a/public/userportal/documents-home-shared.php b/public/userportal/documents-home-shared.php new file mode 100644 index 0000000..7a3ac24 --- /dev/null +++ b/public/userportal/documents-home-shared.php @@ -0,0 +1,598 @@ +prepare(" + SELECT sharing_type, shared_sections + FROM home_sharing + WHERE idhome = ? AND idshareduser = ? AND status = 'accepted' +"); +$querySharing->bind_param('ii', $idhome, $iduserlogin); +$querySharing->execute(); +$resultSharing = $querySharing->get_result(); +$sharingData = $resultSharing->fetch_assoc(); + +// Se non ci sono dati, mostra errore o gestisci diversamente +if (!$sharingData) { + die("Accesso negato o condivisione non trovata."); +} + +// Ottieni i dati di condivisione +$sharingType = $sharingData['sharing_type']; +$sharedSections = json_decode($sharingData['shared_sections'], true); // Decodifica il JSON +?> +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.idsections, 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 ds.*, hs.sharing_type + FROM doc_storage ds + LEFT JOIN home_sharing hs ON hs.idhome = ds.idhome + WHERE ds.idhome = ? AND hs.idshareduser = ? AND hs.status = 'accepted' +"); +$queryLoadedDocuments->bind_param('ii', $idhome, $iduserlogin); +$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) { + // Ottieni l'id della sezione dalla prima riga di documenti (dato che `idsections` è comune ai documenti di una sezione) + $sectionId = $sectionDocuments[0]['idsections'] ?? null; + + // Verifica se la sezione corrente è condivisa + if (!in_array($sectionId, $sharedSections)) { + continue; // Salta questa sezione + } + ?> +
+ +

+ +

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

Nessun documento caricato

+ +
+ +
+
+
+ +
+ + + + +
+
+
+ +
+
+ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userportal/include/navigationbar.php b/public/userportal/include/navigationbar.php index 589c3c1..df115d3 100644 --- a/public/userportal/include/navigationbar.php +++ b/public/userportal/include/navigationbar.php @@ -20,7 +20,7 @@
  • - +
  • @@ -53,7 +53,7 @@
  • - Immobili Condivisi + Immobili Condivisi
  • diff --git a/public/userportal/include/topbar.php b/public/userportal/include/topbar.php index 97e0128..49adc56 100644 --- a/public/userportal/include/topbar.php +++ b/public/userportal/include/topbar.php @@ -29,7 +29,7 @@ $conn->close();