From 9399e5b54aae74383fd6d08d001893cd555f9289 Mon Sep 17 00:00:00 2001 From: Claudio Date: Wed, 21 May 2025 13:57:39 +0200 Subject: [PATCH] update documents with icon style --- public/userportal/get-documents.php | 27 +- public/userportal/get-sections.php | 51 + public/userportal/tabs/documenti.php | 649 ++++++------- .../userportal/tabs/documenti_condropdown.php | 875 ++++++++++++++++++ 4 files changed, 1267 insertions(+), 335 deletions(-) create mode 100644 public/userportal/get-sections.php create mode 100644 public/userportal/tabs/documenti_condropdown.php diff --git a/public/userportal/get-documents.php b/public/userportal/get-documents.php index 7e0b52b..0a89618 100644 --- a/public/userportal/get-documents.php +++ b/public/userportal/get-documents.php @@ -1,22 +1,13 @@ prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?"); $queryHome->bind_param('ii', $idhome, $iduserlogin); $queryHome->execute(); @@ -28,7 +19,6 @@ if (!$homeData) { 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(); @@ -42,7 +32,6 @@ if (!$pageData) { $page_id = $pageData['idpages']; -// Recupera i documenti associati al `page_id`, con le sezioni $sql = " SELECT d.*, s.section_name AS section_name FROM documents d @@ -52,10 +41,17 @@ $sql = " if ($showOnlyRequired) { $sql .= " AND d.is_required = 1"; } +if ($sectionId) { + $sql .= " AND md5(s.section_name) = ?"; +} $sql .= " ORDER BY s.section_name, d.document_name"; $queryDocuments = $conn->prepare($sql); -$queryDocuments->bind_param('i', $page_id); +if ($sectionId) { + $queryDocuments->bind_param('is', $page_id, $sectionId); +} else { + $queryDocuments->bind_param('i', $page_id); +} $queryDocuments->execute(); $resultDocuments = $queryDocuments->get_result(); @@ -65,7 +61,6 @@ while ($row = $resultDocuments->fetch_assoc()) { $documents[$sectionName][] = $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(); @@ -76,7 +71,6 @@ 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'] ?? ''), @@ -84,9 +78,6 @@ $response = [ '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/get-sections.php b/public/userportal/get-sections.php new file mode 100644 index 0000000..c51c33e --- /dev/null +++ b/public/userportal/get-sections.php @@ -0,0 +1,51 @@ +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'])); +} + +$queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?"); +$queryPageId->bind_param('s', $slug); +$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']; + +$querySections = $conn->prepare(" + SELECT DISTINCT s.section_name + FROM documents d + LEFT JOIN sections s ON d.idsections = s.idsections + WHERE d.page_id = ? + ORDER BY s.section_name +"); +$querySections->bind_param('i', $page_id); +$querySections->execute(); +$resultSections = $querySections->get_result(); + +$sections = []; +while ($row = $resultSections->fetch_assoc()) { + $sections[] = $row; +} + +header('Content-Type: application/json'); +echo json_encode(['sections' => $sections]); +exit; diff --git a/public/userportal/tabs/documenti.php b/public/userportal/tabs/documenti.php index 3af7e25..4e4d5ce 100644 --- a/public/userportal/tabs/documenti.php +++ b/public/userportal/tabs/documenti.php @@ -4,7 +4,6 @@ if (!isset($idhome) || $idhome <= 0) { die("Errore: ID immobile non valido."); } - // Recupera i dettagli della casa $stmt = $pdo->prepare("SELECT name, address, zip, city, country FROM home WHERE idhome = ? AND iduser = ?"); $stmt->execute([$idhome, $iduserlogin]); @@ -37,39 +36,69 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal'; + + -
+
- -
-
+ +
+
+ query("SELECT * FROM pages ORDER BY namepages"); + $pages = $stmt->fetchAll(PDO::FETCH_ASSOC); + foreach ($pages as $index => $page) { + $slug = htmlspecialchars($page['slug']); + $name = ucfirst(htmlspecialchars($page['namepages'])); + $iconClass = getCategoryIcon($index); + echo "
+ +
{$name}
+
"; + } + ?> +
+ +
+ + +
+
+ +
+
+ + + +
+ +
- -
- - -
- -
- - - -
+
+ +
-
@@ -77,173 +106,6 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
\ No newline at end of file