diff --git a/Layout/default/ConstructionConsent/Consentform.pdf.php b/Layout/default/ConstructionConsent/Consentform.pdf.php index 3d8b68c47..699d2241e 100644 --- a/Layout/default/ConstructionConsent/Consentform.pdf.php +++ b/Layout/default/ConstructionConsent/Consentform.pdf.php @@ -1,8 +1,9 @@ consent */ ?> @@ -254,7 +255,7 @@

Wir bedanken uns schon jetzt herzlich für Ihre Unterstützung bei diesem wichtigen Projekt!

-

Für Fragen oder weitere Informationen stehen wir Ihnen gerne unter project->phone?> oder per E-Mail an project->email?> zur Verfügung.

+

Für Fragen oder weitere Informationen stehen wir Ihnen gerne unter consent->project->phone?> oder per E-Mail an consent->project->email?> zur Verfügung.

Mit freundlichen Grüßen

@@ -313,7 +314,7 @@
  • eine Mitbenutzung von Anlagen, Leitungen oder sonstigen Einrichtungen nach § 60 – 64 nicht möglich oder nicht tunlich ist.
  • -

    Die BB beabsichtigt für das Projekt name?> in Ausübung dieses Rechtes auf dem(n) Grundstück(en)

    +

    Die BB beabsichtigt für das Projekt consent->name?> in Ausübung dieses Rechtes auf dem(n) Grundstück(en)

    @@ -323,10 +324,10 @@ - - - - + + + + @@ -334,13 +335,13 @@ - + - + - + @@ -353,7 +354,7 @@
    usage_pipe_on_plot) ? "☒" : "☐"?>consent->usage_pipe_on_plot) ? "☒" : "☐"?> Verlegung von Rohren und Lichtwellenleitern am Grundstück
    usage_pipe_in_building) ? "☒" : "☐"?>consent->usage_pipe_in_building) ? "☒" : "☐"?> Verlegung von Rohren und Lichtwellenleitern in den darauf befindlichen Gebäuden
    usage_manhole) ? "☒" : "☐"?>consent->usage_manhole) ? "☒" : "☐"?> Errichtung eines Schachtes/einer Kabelmontagegrube und/oder eines LWL-Verteilschrankes/einer LWL-Abschlussbox.
    - +
    usage_owner) ? "☒" : "☐"?>consent->usage_owner) ? "☒" : "☐"?> Die Nutzung der Liegenschaft seitens BB dient der Eigenversorgung der GE und/oder dessen Nutzer(in) und wird dieser entgeltlos zugestimmt.
    @@ -412,8 +413,8 @@

    Übersichtsplan / Planskizze

    - file && $consent->file->file_id && $consent->file->file->fileExists()): ?> - + consent->file && $owner->consent->file->file_id && $owner->consent->file->file->fileExists()): ?> +
    diff --git a/Layout/default/ConstructionConsent/Index.php b/Layout/default/ConstructionConsent/Index.php index fb2768f29..4f04678b9 100644 --- a/Layout/default/ConstructionConsent/Index.php +++ b/Layout/default/ConstructionConsent/Index.php @@ -146,6 +146,10 @@ $pagination_entity_name = "Zustimmungserklärungen"; 1, "filter" => ["project_id" => (is_array($filter) && array_key_exists("project_id", $filter) ? $filter["project_id"] : "")]])?>"> Filter zurücksetzen + +
    + $filter])?>"> Zustimmungserklärungen herunterladen +
    @@ -321,6 +325,7 @@ $pagination_entity_name = "Zustimmungserklärungen"; Objektadresse GST-Nr. Einlagezahl + Anzahl Eigentümer Anfragestatus Anfrageresultat @@ -343,6 +348,18 @@ $pagination_entity_name = "Zustimmungserklärungen"; gst?> ez?> + + + + owners !== null) { + $owners = $item->owners; + $owner_count = count($owners); + ?> + + + + status) ? __($item->status,"consent") : ""?> log->debug($e->getTraceAsString()); } + return true; } - public function createConsentFormPdf(ConstructionConsentOwner $owner = null) : ?string { - if($owner) { - $owners = [$owner]; - } else { - if(!is_array($this->getProperty("owners")) || !count($this->getProperty("owners"))) { - return null; - } - $owners = $this->owners; - } - - $pdf_vars = [ - "consent" => $this, - "owners" => $owners - ]; - - $footer_text = $this->footer_text; - $footer_font = $this->footer_font; - $footer_size = $this->footer_size; - - $pdf = new PdfForm("ConstructionConsent/Consentform.pdf", $pdf_vars); - - //$wkOpts = "--footer-center '$footer_text' --footer-font-name '$footer_font' --footer-font-size '$footer_size'"; - $wkOpts = "--footer-html '".$_SERVER["HTTP_HOST"].MFFANCYBASEURL."/assets/pdf/ConstructionConsent/Consentform.footer.html' --margin-bottom 15mm --margin-top 10mm"; - $filename = $pdf->render($wkOpts); - - if(!file_exists($filename) || !is_file($filename)) { + public function createConsentFormPdf(array $owners): ?string + { + if (empty($owners)) { return null; } - return $filename; + $pdf = new PdfForm("ConstructionConsent/Consentform.pdf", [ + 'consent' => $this, + 'owners' => $owners + ]); + + $footerFile = BASEDIR . "/public/assets/pdf/ConstructionConsent/Consentform.footer.html"; + + $wkOpts = sprintf( + "--footer-html '%s' --margin-bottom 15mm --margin-top 10mm --margin-bottom 15mm --margin-top 10mm", + $footerFile + ); + + $filename = $pdf->render($wkOpts); + return @is_file($filename) ? $filename : null; } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index 43c1c079d..2bd0e5d8b 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -140,45 +140,69 @@ class ConstructionConsentController extends mfBaseController { $this->addAction(); } - protected function download() { - //var_dump($r->get());exit; + protected function generatePdf(array $owners, ConstructionConsent $consent): ?string + { + if (empty($owners)) return null; + + $this->layout()->setTemplate("ConstructionConsent/Consentform.pdf"); + $this->layout()->set("ressourcePathPrefix", MFFANCYBASEURL); + $this->layout()->set("owners", $owners); + $this->layout()->set("consent", $consent); + + return $consent->createConsentFormPdf($owners); // Might need adjustment for multiple + } + + protected function downloadAction() + { $owner_id = $this->request->owner_id; - if (!is_numeric($owner_id) || $owner_id < 1) { + + if (!is_numeric($owner_id) || $owner_id < 1 || !($owner = new ConstructionConsentOwner($owner_id))->id) { $this->layout()->setFlash("Besitzer nicht gefunden", "error"); $this->redirect("ConstructionConsent"); } - $owner = new ConstructionConsentOwner($owner_id); - if (!$owner->id) { - $this->layout()->setFlash("Besitzer nicht gefunden", "error"); - $this->redirect("ConstructionConsent"); - } - - $cc = $owner->consent; - if(!$cc) { + if (!($cc = $owner->consent)) { $this->layout()->setFlash("Zustimmungserklärung nicht gefunden.", "error"); $this->redirect("ConstructionConsent"); } - $this->layout()->setTemplate("ConstructionConsent/Consentform.pdf"); - $this->layout()->set("ressourcePathPrefix", MFFANCYBASEURL); - $this->layout()->set("owners", [$owner]); - $this->layout()->set("consent", $cc); - //return true; - - $filename = $cc->createConsentFormPdf($owner); - if(!$filename) { - $this->layout()->setFlash("Beim Erstellen des PDFs ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error"); + if (!($filename = $this->generatePdf([$owner], $cc))) { + $this->layout()->setFlash("PDF-Erstellung fehlgeschlagen", "error"); $this->redirect("ConstructionConsent", "View", ["id" => $cc->id]); } - header('Content-Type: application/octet-stream'); - header('Content-disposition: attachment; filename="Zustimmungserklärung-'.$cc->id.'-'.$owner_id.'.pdf"'); - header('Content-Transfer-Encoding: binary'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Content-Type: ' . mime_content_type($filename)); - header("Content-Length: " . filesize($filename)); + $this->sendPdfResponse($filename, "Zustimmungserklärung-{$cc->id}-{$owner_id}.pdf"); + } + protected function downloadMultipleAction() + { + // Reuse index filter logic + $filter = $this->getPreparedFilter($this->request->filter); + + $owners = []; + foreach (ConstructionConsent::search($filter, []) as $consent) { + $owners = array_merge($owners, $consent->owners ?: []); + } + + if (empty($owners)) { + $this->layout()->setFlash("Keine Besitzer gefunden", "error"); + $this->redirect("ConstructionConsent"); + } + + // Use first consent as base - might need adjustment for your use case + if (!($filename = $this->generatePdf($owners, $owners[0]->consent))) { + $this->layout()->setFlash("PDF-Erstellung fehlgeschlagen", "error"); + $this->redirect("ConstructionConsent"); + } + + $this->sendPdfResponse($filename, "Zustimmungserklärungen-".date('Y-m-d').".pdf"); + } + + private function sendPdfResponse(string $filename, string $downloadName): void + { + header('Content-Type: ' . mime_content_type($filename)); + header('Content-disposition: attachment; filename="' . $downloadName . '"'); + header('Content-Length: ' . filesize($filename)); readfile($filename); exit; }