Documenti per la Casa:
-Indirizzo:
+Documenti Condivisi per la Casa:
+Indirizzo:
+diff --git a/public/userportal/documents-home-shared.php b/public/userportal/documents-home-shared.php index 38829de..4f719a0 100644 --- a/public/userportal/documents-home-shared.php +++ b/public/userportal/documents-home-shared.php @@ -7,13 +7,12 @@ error_reporting(E_ALL); $conn = new mysqli($servername, $username, $password, $database); // Recupera l'id utente loggato $iduserlogin = $_SESSION['iduserlogin']; -//echo $iduserlogin; // Recupera l'id della casa dall'URL $idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0; // Recupera lo sharing_type e le sezioni condivise per questa casa $querySharing = $conn->prepare(" - SELECT sharing_type, shared_sections , iduser + SELECT sharing_type, shared_sections, iduser FROM home_sharing WHERE idhome = ? AND idshareduser = ? AND status = 'accepted' "); @@ -22,19 +21,13 @@ $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']; $sharingIdUser = $sharingData['iduser']; -$sharedSections = json_decode($sharingData['shared_sections'], true); // Decodifica il JSON -?> -prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?"); @@ -43,59 +36,10 @@ $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 -} +// Imposta lo slug predefinito o usa quello passato via GET +$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal'; -// 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' +// Recupera le pagine disponibili nella tabella 'pages' $queryPages = $conn->query("SELECT * FROM pages ORDER BY namepages"); $pages = []; while ($row = $queryPages->fetch_assoc()) { @@ -103,7 +47,6 @@ while ($row = $queryPages->fetch_assoc()) { } ?> - @@ -111,7 +54,7 @@ while ($row = $queryPages->fetch_assoc()) { -
Indirizzo:
+Indirizzo:
+Indirizzo:
+diff --git a/public/userportal/documents-home-sharedbck060325.php b/public/userportal/documents-home-sharedbck060325.php new file mode 100644 index 0000000..38829de --- /dev/null +++ b/public/userportal/documents-home-sharedbck060325.php @@ -0,0 +1,599 @@ +prepare(" + SELECT sharing_type, shared_sections , iduser + 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']; +$sharingIdUser = $sharingData['iduser']; +$sharedSections = json_decode($sharingData['shared_sections'], true); // Decodifica il JSON +?> +prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?"); +$queryHome->bind_param('ii', $idhome, $sharingIdUser); +$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; +} +?> + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + +
+ +