update documents with icon style
This commit is contained in:
@@ -1,22 +1,13 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Recupera l'id utente loggato
|
||||
$iduserlogin = $_SESSION['iduserlogin'];
|
||||
|
||||
// Recupera l'id della casa dall'URL
|
||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
|
||||
// Recupera lo slug dalla richiesta
|
||||
$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal';
|
||||
|
||||
// Recupera il parametro showOnlyRequired
|
||||
$showOnlyRequired = isset($_GET['showOnlyRequired']) && $_GET['showOnlyRequired'] === 'true';
|
||||
$sectionId = isset($_GET['sectionId']) ? $_GET['sectionId'] : null;
|
||||
|
||||
// Recupera i dettagli della casa (per verifica accesso)
|
||||
$queryHome = $conn->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;
|
||||
|
||||
Reference in New Issue
Block a user