summaryrefslogtreecommitdiff
path: root/dopdf.php
diff options
context:
space:
mode:
Diffstat (limited to 'dopdf.php')
-rw-r--r--dopdf.php202
1 files changed, 202 insertions, 0 deletions
diff --git a/dopdf.php b/dopdf.php
new file mode 100644
index 0000000..ca254dc
--- /dev/null
+++ b/dopdf.php
@@ -0,0 +1,202 @@
+<?php
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+?>
+<?php
+/* vim: set ts=4 sw=4 et : */
+
+require_once __DIR__ . "/check_auth.php";
+require_once __DIR__ . "/../includes/common.php";
+
+require_once __DIR__ . '/vendor/autoload.php';
+
+require_once __DIR__ . "/twig.php";
+require_once __DIR__ . "/lookup.php";
+
+session_write_close();
+
+$puid = "invalid";
+if (isset($_SESSION['uid'])) {
+ $puid = $_SESSION['uid'];
+}
+
+if (isset($_GET['id']) && ($_SESSION['admin'] || $_SESSION['commissioner'])) {
+ $puid = $_GET['id'];
+}
+
+if (isset($_POST['uid']) && ($_SESSION['admin'] || $_SESSION['commissioner'])) {
+ $puid = $_POST['uid'];
+}
+
+if (isset($_POST['ruid']) && $_SESSION['admin']) {
+ $puid = $_POST['ruid'];
+}
+
+if (isset($_SESSION['commissioner']) && !isset($_SESSION['admin'])) {
+ if (!uidInCommission($puid, $_SESSION['commissioner'])) {
+ header("HTTP/1.0 404 Not Found");
+ exit(0);
+ }
+}
+
+$force = false;
+if (isset($doFull) && $doFull) {
+ if (isset($_GET['force']) && $_GET['force'])
+ $force = true;
+} else {
+ $doFull = false;
+}
+
+if ($puid == 'invalid' && $puid == '') {
+ $mysqli->close();
+ exit(0);
+}
+
+$data = [
+ 'organisation' => $_POST['organisation'],
+ 'anrede' => $_POST['anrede'],
+ 'anrede_briefkopf' => $_POST['anrede_briefkopf'],
+ 'titel' => $_POST['titel'],
+ 'vorname' => $_POST['vorname'],
+ 'nachname' => $_POST['nachname'],
+ 'strasse' => $_POST['strasse'],
+ 'adresszusatz' => $_POST['adresszusatz'],
+ 'plz' => $_POST['plz'],
+ 'ort' => $_POST['ort'],
+ 'betreff' => $_POST['subject'],
+ 'text' => $_POST['html'],
+ 'datum' => $_POST['date'],
+ 'data' => $_POST['data'],
+ 'fn' => $_POST['fn']
+];
+
+define('NUMERAL_SIGN', 'minus');
+define('NUMERAL_HUNDREDS_SUFFIX', 'hundert');
+define('NUMERAL_INFIX', 'und');
+
+$lNumeral = array('null', 'ein', 'zwei', 'drei', 'vier',
+ 'fünf', 'sechs', 'sieben', 'acht', 'neun',
+ 'zehn', 'elf', 'zwölf', 'dreizehn', 'vierzehn',
+ 'fünfzehn', 'sechzehn', 'siebzehn', 'achtzehn', 'neunzehn');
+
+$lTenner = array('', '', 'zwanzig', 'dreißig', 'vierzig',
+ 'fünfzig', 'sechzig', 'siebzig', 'achtzig', 'neunzig');
+
+$lGroupSuffix = array(array('s', ''),
+ array('tausend ', 'tausend '),
+ array('e Million ', ' Millionen '),
+ array('e Milliarde ', ' Milliarden '),
+ array('e Billion ', ' Billionen '),
+ array('e Billiarde ', ' Billiarden '),
+ array('e Trillion ', ' Trillionen '));
+
+function num2text($pNumber)
+{
+ global $lNumeral;
+ if ($pNumber == 0) {
+ return $lNumeral[0];
+ } elseif ($pNumber < 0) {
+ return NUMERAL_SIGN . ' ' . num2text_group(abs($pNumber));
+ } else {
+ return num2text_group($pNumber);
+ }
+}
+
+function num2text_group($pNumber, $pGroupLevel = 0)
+{
+ global $lNumeral, $lTenner, $lGroupSuffix;
+ if ($pNumber == 0) {
+ return '';
+ }
+ $lGroupNumber = $pNumber % 1000;
+ if ($lGroupNumber == 1) {
+ $lResult = $lNumeral[1] . $lGroupSuffix[$pGroupLevel][0];
+ } elseif ($lGroupNumber > 1) {
+ $lResult = '';
+ $lFirstDigit = floor($lGroupNumber / 100);
+ if ($lFirstDigit > 0) {
+ $lResult .= $lNumeral[$lFirstDigit] . NUMERAL_HUNDREDS_SUFFIX;
+ }
+ $lLastDigits = $lGroupNumber % 100;
+ $lSecondDigit = floor($lLastDigits / 10);
+ $lThirdDigit = $lLastDigits % 10;
+ if ($lLastDigits == 1) {
+ $lResult .= $lNumeral[1] . 's';
+ } elseif ($lLastDigits > 1 && $lLastDigits < 20) {
+ $lResult .= $lNumeral[$lLastDigits];
+ } elseif ($lLastDigits >= 20) {
+ if ($lThirdDigit > 0) {
+ $lResult .= $lNumeral[$lThirdDigit] . NUMERAL_INFIX;
+ }
+ $lResult .= $lTenner[$lSecondDigit];
+ }
+ $lResult .= $lGroupSuffix[$pGroupLevel][1];
+ }
+ return num2text_group(floor($pNumber / 1000), $pGroupLevel + 1) . $lResult;
+}
+
+try {
+ $ddata = json_decode($_POST['data']);
+ $data['data'] = $ddata;
+ $data['betrag'] = number_format($ddata->Betrag, 2, ",", ".");
+ $data['betrag_bs'] = num2text($ddata->Betrag) . ' Euro';
+ $data['betrag_datum'] = explode('-', $ddata->Geldeingang)[2] . '.' . explode('-', $ddata->Geldeingang)[1] . '.' . explode('-', $ddata->Geldeingang)[0];
+} catch (Exception $e) {
+ ;
+}
+
+$template = $_POST['template'];
+$template = 'hsrw.twig';
+
+$html = $twig->render($template, $data);
+
+$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
+$fontDirs = $defaultConfig['fontDir'];
+
+$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
+$fontData = $defaultFontConfig['fontdata'];
+
+$mpdf = new Mpdf\Mpdf([
+ 'tempDir' => __DIR__ . '/tmp',
+ 'format' => 'A4',
+]);
+
+//$mpdf->SetImportUse();
+$mpdf->useActiveForms = true;
+if (!strstr($template, 'zahlung')) {
+ $mpdf->SetProtection(array('print'));
+}
+$mpdf->WriteHTML($html);
+$mysqli->close();
+
+if (isset($_GET['test'])) {
+ header("Content-Type: application/pdf");
+ $mpdf->Output();
+ exit(0);
+}
+
+$fn = $_POST['fn'];
+
+mkdir("/var/www/uploads/" . $puid . "_");
+$file = "/var/www/uploads/" . $puid . "_/" . $fn . ".pdf";
+$mpdf->Output($file, \Mpdf\Output\Destination::FILE);
+
+if (isset($_GET['save'])) {
+ echo "1";
+ exit(0);
+}
+
+header("Content-Type: application/pdf");
+readfile($file);
+exit(0);
+
+?>