From b63606a48c2926f6177b6a17c20648b665372c64 Mon Sep 17 00:00:00 2001 From: Claudio Date: Thu, 6 Mar 2025 14:56:57 +0100 Subject: [PATCH] added report download --- composer.json | 1 + composer.lock | 75 ++++++- public/userportal/documents-home-shared.php | 18 ++ public/userportal/download-report.php | 195 ++++++++++++++++++ .../userportal/download-shared-documents.php | 162 +++++++++++++++ public/userportal/shared-homes.php | 44 +++- 6 files changed, 491 insertions(+), 4 deletions(-) create mode 100644 public/userportal/download-report.php create mode 100644 public/userportal/download-shared-documents.php diff --git a/composer.json b/composer.json index bdb9ccc..6956948 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "phpmailer/phpmailer": "^6.9", "proengsoft/laravel-jsvalidation": "^4.0.0", "spatie/laravel-query-builder": "^5.0", + "tecnickcom/tcpdf": "^6.8", "vanguardapp/activity-log": "^5.0", "vanguardapp/announcements": "^5.0", "vanguardapp/plugins": "^5.0", diff --git a/composer.lock b/composer.lock index b67297b..1f076a1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4aa12c72336d4694139400139378d75f", + "content-hash": "36e0265c4d1a5422d60fbaef9b95eb98", "packages": [ { "name": "akaunting/laravel-setting", @@ -6189,6 +6189,79 @@ ], "time": "2023-02-24T10:42:00+00:00" }, + { + "name": "tecnickcom/tcpdf", + "version": "6.8.2", + "source": { + "type": "git", + "url": "https://github.com/tecnickcom/TCPDF.git", + "reference": "f7a781073e1645062f163e058139e2f89355d420" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/f7a781073e1645062f163e058139e2f89355d420", + "reference": "f7a781073e1645062f163e058139e2f89355d420", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=7.1.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "config", + "include", + "tcpdf.php", + "tcpdf_parser.php", + "tcpdf_import.php", + "tcpdf_barcodes_1d.php", + "tcpdf_barcodes_2d.php", + "include/tcpdf_colors.php", + "include/tcpdf_filters.php", + "include/tcpdf_font_data.php", + "include/tcpdf_fonts.php", + "include/tcpdf_images.php", + "include/tcpdf_static.php", + "include/barcodes/datamatrix.php", + "include/barcodes/pdf417.php", + "include/barcodes/qrcode.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Nicola Asuni", + "email": "info@tecnick.com", + "role": "lead" + } + ], + "description": "TCPDF is a PHP class for generating PDF documents and barcodes.", + "homepage": "http://www.tcpdf.org/", + "keywords": [ + "PDFD32000-2008", + "TCPDF", + "barcodes", + "datamatrix", + "pdf", + "pdf417", + "qrcode" + ], + "support": { + "issues": "https://github.com/tecnickcom/TCPDF/issues", + "source": "https://github.com/tecnickcom/TCPDF/tree/6.8.2" + }, + "funding": [ + { + "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_donations¤cy_code=GBP&business=paypal@tecnick.com&item_name=donation%20for%20tcpdf%20project", + "type": "custom" + } + ], + "time": "2025-01-26T14:03:12+00:00" + }, { "name": "tijsverkoyen/css-to-inline-styles", "version": "2.2.6", diff --git a/public/userportal/documents-home-shared.php b/public/userportal/documents-home-shared.php index 4f719a0..0b7288f 100644 --- a/public/userportal/documents-home-shared.php +++ b/public/userportal/documents-home-shared.php @@ -166,6 +166,21 @@ while ($row = $queryPages->fetch_assoc()) { width: 100% !important; } } + + .btn-warning { + background-color: #ffca2c; + /* Un giallo più brillante */ + border-color: #ffca2c; + color: #212529; + /* Testo scuro per contrasto */ + } + + .btn-warning:hover { + background-color: #e0b026; + /* Giallo più scuro al passaggio del mouse */ + border-color: #e0b026; + color: #212529; + } @@ -188,6 +203,9 @@ while ($row = $queryPages->fetch_assoc()) { + + Scarica Zip + diff --git a/public/userportal/download-report.php b/public/userportal/download-report.php new file mode 100644 index 0000000..ac3e880 --- /dev/null +++ b/public/userportal/download-report.php @@ -0,0 +1,195 @@ +prepare(" + SELECT sharing_type, shared_sections, iduser + FROM home_sharing + WHERE idhome = ? AND (idshareduser = ? OR shared_email = ?) AND status = 'accepted' +"); +$querySharing->bind_param('iis', $idhome, $iduserlogin, $emailuser); +$querySharing->execute(); +$sharingData = $querySharing->get_result()->fetch_assoc(); + +$queryOwner = $conn->prepare("SELECT iduser FROM home WHERE idhome = ?"); +$queryOwner->bind_param("i", $idhome); +$queryOwner->execute(); +$ownerData = $queryOwner->get_result()->fetch_assoc(); + +if (!$sharingData && $ownerData['iduser'] != $iduserlogin) { + die("Accesso negato."); +} + +// Recupera i dati della casa +$queryHome = $conn->prepare("SELECT * FROM home WHERE idhome = ?"); +$queryHome->bind_param('i', $idhome); +$queryHome->execute(); +$homeData = $queryHome->get_result()->fetch_assoc(); + +// Classe personalizzata per il PDF +class MYPDF extends TCPDF +{ + protected $homeName; // Proprietà per il nome dell'immobile + + public function __construct($homeName, $orientation, $unit, $format) + { + parent::__construct($orientation, $unit, $format); + $this->homeName = $homeName; // Imposta il nome dell'immobile + } + + public function Header() + { + $this->SetFont('helvetica', 'B', 16); + $this->SetTextColor(0, 63, 127); + $this->Cell(80, 10, 'Report Immobile', 0, 0, 'L'); + $this->SetFont('helvetica', 'B', 14); + $this->Cell(0, 10, htmlspecialchars($this->homeName), 0, 1, 'R'); + $this->SetFont('helvetica', '', 10); + $this->SetTextColor(100, 100, 100); + $this->Cell(0, 5, 'Generato il ' . date('d/m/Y H:i'), 0, 1, 'C'); + $this->Ln(5); + $this->SetLineStyle(array('width' => 0.5, 'color' => array(0, 63, 127))); + $this->Line(15, $this->GetY(), $this->getPageWidth() - 15, $this->GetY()); + } + + public function Footer() + { + $this->SetY(-15); + $this->SetFont('helvetica', 'I', 8); + $this->SetTextColor(100, 100, 100); + $this->Cell(0, 10, 'CasaDoc - Pagina ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, 0, 'C'); + } +} + +// Crea il PDF passando il nome dell'immobile +$pdf = new MYPDF($homeData['name'], PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); +$pdf->SetCreator(PDF_CREATOR); +$pdf->SetAuthor('CasaDoc'); +$pdf->SetTitle($homeData['name']); +$pdf->SetMargins(15, 35, 15); +$pdf->SetHeaderMargin(10); +$pdf->SetFooterMargin(10); +$pdf->SetAutoPageBreak(true, 25); +$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); +$pdf->AddPage(); + +// Stile generale +$pdf->SetFont('helvetica', '', 11); +$pdf->SetTextColor(0, 0, 0); + +// Sezione Informazioni Generali +$pdf->SetFillColor(240, 248, 255); +$pdf->SetDrawColor(0, 63, 127); +$pdf->SetLineWidth(0.2); +$pdf->Cell(0, 8, 'Informazioni Generali', 'B', 1, 'L', 1); +$pdf->Ln(2); + +$html = ' + + + + + + + + + + + + + +
Indirizzo:' . htmlspecialchars($homeData['fulladdress']) . '
Città:' . htmlspecialchars($homeData['city']) . ', ' . htmlspecialchars($homeData['country']) . ' ' . htmlspecialchars($homeData['zip']) . '
Note:' . (empty($homeData['comment']) ? 'Nessuna nota' : htmlspecialchars($homeData['comment'])) . '
'; +$pdf->writeHTML($html, true, false, true, false, ''); + +// Immagine +$imageFile = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphoto'] : 'assets/images/no-image.jpg'; +if (file_exists($imageFile)) { + $pdf->Ln(5); + list($width, $height) = getimagesize($imageFile); + $maxWidth = $pdf->getPageWidth() - 100; + $scale = $maxWidth / $width; + $newHeight = $height * $scale; + $pdf->Image($imageFile, 15, $pdf->GetY(), $maxWidth, $newHeight, '', '', 'T', false, 300, '', false, false, 1); + $pdf->Ln($newHeight + 5); +} + +// Mappa Google Static Maps +$latitude = $homeData['latitude'] ?: 41.9028; +$longitude = $homeData['longitude'] ?: 12.4964; +$googleMapsApiKey = 'AIzaSyADtQRKgCpJNnQCP8QvBeKDcm0TrTPpsGY'; // Sostituisci con la tua chiave API +$mapUrl = "https://maps.googleapis.com/maps/api/staticmap?center={$latitude},{$longitude}&zoom=14&size=800x500&markers=color:red|{$latitude},{$longitude}&key={$googleMapsApiKey}"; +$mapFile = sys_get_temp_dir() . '/map_' . $idhome . '.png'; + +file_put_contents($mapFile, file_get_contents($mapUrl)); +if (file_exists($mapFile)) { + $pdf->SetFillColor(240, 248, 255); + $pdf->Cell(0, 8, 'Posizione Geografica', 'B', 1, 'L', 1); + $pdf->Ln(2); + $pdf->Image($mapFile, 15, $pdf->GetY(), 100, 50, '', '', 'T', false, 300, '', false, false, 1); + $pdf->Ln(55); + unlink($mapFile); +} + +// Sezione Dati Catastali +$pdf->SetFillColor(240, 248, 255); +$pdf->Cell(0, 8, 'Dati Catastali', 'B', 1, 'L', 1); +$pdf->Ln(2); + +$html = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CampoValore
Comune Catastale' . (empty($homeData['cadastral_municipality']) ? '-' : htmlspecialchars($homeData['cadastral_municipality'])) . '
Sezione' . (empty($homeData['cadastral_section']) ? '-' : htmlspecialchars($homeData['cadastral_section'])) . '
Foglio' . (empty($homeData['cadastral_sheet']) ? '-' : htmlspecialchars($homeData['cadastral_sheet'])) . '
Particella' . (empty($homeData['cadastral_particle']) ? '-' : htmlspecialchars($homeData['cadastral_particle'])) . '
Subalterno' . (empty($homeData['cadastral_sub']) ? '-' : htmlspecialchars($homeData['cadastral_sub'])) . '
Categoria' . (empty($homeData['cadastral_category']) ? '-' : htmlspecialchars($homeData['cadastral_category'])) . '
Classe' . (empty($homeData['cadastral_class']) ? '-' : htmlspecialchars($homeData['cadastral_class'])) . '
Superficie' . (empty($homeData['cadastral_surface']) ? '-' : htmlspecialchars($homeData['cadastral_surface']) . ' mq') . '
Rendita' . (empty($homeData['cadastral_rendita']) ? '-' : '€' . htmlspecialchars($homeData['cadastral_rendita'])) . '
'; +$pdf->writeHTML($html, true, false, true, false, ''); + +// Nome del file e output +$homeNameSafe = preg_replace('/[^A-Za-z0-9\-]/', '_', $homeData['name']); +$pdfFileName = "Report_Immobile_{$homeNameSafe}_" . date('Ymd_His') . ".pdf"; +$pdf->Output($pdfFileName, 'D'); +exit; diff --git a/public/userportal/download-shared-documents.php b/public/userportal/download-shared-documents.php new file mode 100644 index 0000000..2ba8eb6 --- /dev/null +++ b/public/userportal/download-shared-documents.php @@ -0,0 +1,162 @@ +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(); +$sharingData = $querySharing->get_result()->fetch_assoc(); + +if (!$sharingData) { + die("Accesso negato o condivisione non trovata."); +} + +$sharedSections = json_decode($sharingData['shared_sections'], true); +$sharingIdUser = $sharingData['iduser']; + +// Recupera i dettagli della casa +$queryHome = $conn->prepare("SELECT * FROM home WHERE idhome = ?"); +$queryHome->bind_param('i', $idhome); +$queryHome->execute(); +$homeData = $queryHome->get_result()->fetch_assoc(); +$homeName = preg_replace('/[^A-Za-z0-9\-]/', '_', $homeData['name']); + +// Recupera i documenti caricati +$queryLoaded = $conn->prepare(" + SELECT ds.filename, ds.document_id, d.document_name, s.section_name + FROM doc_storage ds + LEFT JOIN documents d ON ds.document_id = d.document_id + LEFT JOIN sections s ON d.idsections = s.idsections + LEFT JOIN home_sharing hs ON hs.idhome = ds.idhome + WHERE ds.idhome = ? AND hs.idshareduser = ? AND hs.status = 'accepted' + AND d.idsections IN (" . implode(',', array_map('intval', $sharedSections)) . ") +"); +$queryLoaded->bind_param('ii', $idhome, $iduserlogin); +$queryLoaded->execute(); +$resultLoaded = $queryLoaded->get_result(); + +$files = []; +while ($row = $resultLoaded->fetch_assoc()) { + $files[] = [ + 'filename' => $row['filename'], + 'document_name' => $row['document_name'], + 'section_name' => $row['section_name'] + ]; +} + +// Crea il PDF del report +// ... (codice precedente fino alla creazione del PDF) ... + +class MYPDF extends TCPDF +{ + protected $homeName; + + public function __construct($homeName, $orientation, $unit, $format) + { + parent::__construct($orientation, $unit, $format); + $this->homeName = $homeName; + } + + public function Header() + { + $this->SetFont('helvetica', 'B', 16); + $this->SetTextColor(0, 63, 127); + $this->Cell(80, 10, 'Report Immobile', 0, 0, 'L'); + $this->SetFont('helvetica', 'B', 14); + $this->Cell(0, 10, htmlspecialchars($this->homeName), 0, 1, 'R'); + $this->SetFont('helvetica', '', 10); + $this->SetTextColor(100, 100, 100); + $this->Cell(0, 5, 'Generato il ' . date('d/m/Y H:i'), 0, 1, 'C'); + $this->Ln(5); + $this->SetLineStyle(array('width' => 0.5, 'color' => array(0, 63, 127))); + $this->Line(15, $this->GetY(), $this->getPageWidth() - 15, $this->GetY()); + } + + public function Footer() + { + $this->SetY(-15); + $this->SetFont('helvetica', 'I', 8); + $this->SetTextColor(100, 100, 100); + $this->Cell(0, 10, 'CasaDoc - Pagina ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, 0, 'C'); + } +} + +$pdf = new MYPDF($homeData['name'], PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); +$pdf->SetMargins(15, 35, 15); +$pdf->SetHeaderMargin(10); +$pdf->SetFooterMargin(10); +$pdf->SetAutoPageBreak(true, 25); +$pdf->AddPage(); + +// ... (resto del codice per il PDF e lo ZIP invariato) ... + +$html = '

' . htmlspecialchars($homeData['name']) . '

'; +$html .= '

Indirizzo: ' . htmlspecialchars($homeData['fulladdress']) . '

'; +$html .= '

Città: ' . htmlspecialchars($homeData['city']) . ', ' . htmlspecialchars($homeData['country']) . ' ' . htmlspecialchars($homeData['zip']) . '

'; +$html .= '

Note: ' . htmlspecialchars($homeData['comment']) . '

'; +$html .= '

Dati Catastali

'; +$html .= '

Comune Catastale: ' . htmlspecialchars($homeData['cadastral_municipality']) . '

'; +$html .= '

Sezione: ' . htmlspecialchars($homeData['cadastral_section']) . '

'; +$html .= '

Foglio: ' . htmlspecialchars($homeData['cadastral_sheet']) . '

'; +$html .= '

Particella: ' . htmlspecialchars($homeData['cadastral_particle']) . '

'; +$html .= '

Subalterno: ' . htmlspecialchars($homeData['cadastral_sub']) . '

'; +$html .= '

Categoria: ' . htmlspecialchars($homeData['cadastral_category']) . '

'; +$html .= '

Classe: ' . htmlspecialchars($homeData['cadastral_class']) . '

'; +$html .= '

Superficie: ' . htmlspecialchars($homeData['cadastral_surface']) . ' mq

'; +$html .= '

Rendita: €' . htmlspecialchars($homeData['cadastral_rendita']) . '

'; + +$pdf->writeHTML($html, true, false, true, false, ''); + +$imageFile = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphoto'] : 'assets/images/no-image.jpg'; +if (file_exists($imageFile)) { + $pdf->Image($imageFile, 15, $pdf->GetY() + 10, 100, 0, '', '', '', false, 300, '', false, false, 0); +} + +$reportFilePath = sys_get_temp_dir() . "/Report_Immobile_{$homeName}_" . date('Ymd_His') . ".pdf"; +$pdf->Output($reportFilePath, 'F'); // Salva il PDF temporaneamente + +// Crea lo ZIP +$zip = new ZipArchive(); +$zipFileName = "Documenti_Condivisi_{$homeName}_" . date('Ymd_His') . ".zip"; +$zipFilePath = sys_get_temp_dir() . '/' . $zipFileName; + +if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { + die("Errore nella creazione del file ZIP."); +} + +// Aggiungi i documenti allo ZIP +foreach ($files as $file) { + $filePath = "homedocuments/{$file['filename']}"; + if (file_exists($filePath)) { + $zip->addFile($filePath, "{$file['section_name']}/{$file['document_name']}_{$file['filename']}"); + } +} + +// Aggiungi il PDF del report +if (file_exists($reportFilePath)) { + $zip->addFile($reportFilePath, "Report_Immobile_{$homeName}.pdf"); +} + +$zip->close(); + +// Download dello ZIP +header('Content-Type: application/zip'); +header('Content-Disposition: attachment; filename="' . $zipFileName . '"'); +header('Content-Length: ' . filesize($zipFilePath)); +readfile($zipFilePath); + +// Pulizia +unlink($zipFilePath); +unlink($reportFilePath); +exit; diff --git a/public/userportal/shared-homes.php b/public/userportal/shared-homes.php index 6bfb125..1e38ec8 100644 --- a/public/userportal/shared-homes.php +++ b/public/userportal/shared-homes.php @@ -268,6 +268,19 @@ $result = $stmt->get_result(); right: 0; left: auto; } + + .dropdown-item.bg-warning { + background-color: #ffca2c; + /* Giallo brillante */ + color: #212529; + /* Testo scuro per contrasto */ + } + + .dropdown-item.bg-warning:hover { + background-color: #e0b026; + /* Giallo più scuro al passaggio del mouse */ + color: #212529; + } @@ -380,7 +393,7 @@ $result = $stmt->get_result();
  • Documenti
  • -
  • +
  • Scarica ZIP
  • @@ -425,7 +438,7 @@ $result = $stmt->get_result();