From 254fc65859e22e1794478ab30761e07dc0cbd6b3 Mon Sep 17 00:00:00 2001
From: Claudio
Date: Thu, 6 Mar 2025 10:49:00 +0100
Subject: [PATCH] fixed shared docs
---
public/userportal/documents-home-shared.php | 835 +++++++++---------
.../documents-home-sharedbck060325.php | 599 +++++++++++++
public/userportal/get-shared-documents.php | 74 ++
3 files changed, 1078 insertions(+), 430 deletions(-)
create mode 100644 public/userportal/documents-home-sharedbck060325.php
create mode 100644 public/userportal/get-shared-documents.php
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()) {
- Documenti della Casa
+ Documenti Condivisi della Casa
@@ -119,118 +62,31 @@ while ($row = $queryPages->fetch_assoc()) {
-
-
-
-
-
+
+
@@ -290,124 +179,40 @@ while ($row = $queryPages->fetch_assoc()) {
-
-
-
Documenti per la Casa:
-
Indirizzo:
+
+
+
Documenti Condivisi 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 Documento
-
Data Caricamento
-
Azioni
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Nessun documento caricato
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -415,183 +220,353 @@ while ($row = $queryPages->fetch_assoc()) {
-
+
-
-
+
+
+
+
+ // Carica tutti i documenti e le sezioni condivise per la ricerca
+ let allDocuments = [];
+ query("
+ SELECT d.document_id, d.document_name, p.slug, s.section_name
+ FROM documents d
+ LEFT JOIN sections s ON d.idsections = s.idsections
+ LEFT JOIN pages p ON d.page_id = p.idpages
+ WHERE d.idsections IN (" . implode(',', array_map('intval', $sharedSections)) . ")
+ ORDER BY s.section_name, d.document_name
+ ");
+ while ($doc = $allDocumentsQuery->fetch_assoc()) {
+ echo "allDocuments.push({
+ id: '{$doc['document_id']}',
+ name: '" . addslashes(htmlspecialchars($doc['document_name'])) . "',
+ section: '" . addslashes(htmlspecialchars($doc['section_name'])) . "',
+ slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "'
+ });\n";
+ }
+ ?>
-
-
+
+
+
+
+
+
+
+
+
+
+
+
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 Documento
+
Data Caricamento
+
Azioni
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Nessun documento caricato
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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;
+}
+?>
+
+
+
+
+
+