You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

506 lines
11 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. session_start();
  3. if ($_GET['lst']=='1'){
  4. $file = "Antrag.pdf";
  5. header('Content-Disposition: attachment; filename="'. $file . '"');
  6. header('Content-Length: ' . strlen($_SESSION['lst']));
  7. echo $_SESSION['lst'];
  8. die;
  9. }
  10. ?>
  11. <html>
  12. <head>
  13. <title>Kostenerstattungsforumlar</title>
  14. <meta charset="utf-8">
  15. <meta name="viewport" content="width=device-width, initial-scale=1">
  16. <!-- Kube CSS -->
  17. <link rel="stylesheet" href="css/kube.min.css">
  18. <link rel="stylesheet" href="addons/kube-addons.min.css" />
  19. <link rel="stylesheet" href="master.css" />
  20. </head>
  21. <body>
  22. <?php
  23. error_log("SUBMIT\n");
  24. require "config.php";
  25. require "PHPMailer/PHPMailer.php";
  26. require "PHPMailer/SMTP.php";
  27. require "PHPMailer/Exception.php";
  28. #$CONVERT_CMD = "/usr/bin/pdftk";
  29. require_once('TCPDF/tcpdf.php');
  30. class kaformPDF extends TCPDF {
  31. //Page header
  32. public function Header() {
  33. }
  34. // Logo
  35. // $image_file = K_PATH_IMAGES.'logo_example.jpg';
  36. // $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
  37. // // Set font
  38. // $this->SetFont('helvetica', 'B', 20);
  39. // // Title
  40. // $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
  41. // }
  42. // Page footer
  43. public function Footer() {
  44. }
  45. // Position at 15 mm from bottom
  46. // $this->SetY(-15);
  47. // Set font
  48. // $this->SetFont('helvetica', 'I', 8);
  49. // Page number
  50. // $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
  51. // }
  52. // }
  53. //
  54. };
  55. function get_adv()
  56. {
  57. $aval = $_POST['advance'];
  58. if (!$aval)
  59. $aval = "0";
  60. $advance = floatval(str_replace(",",".",$aval));
  61. if ($advance < 0 )
  62. $advance = -$advance;
  63. return $advance;
  64. }
  65. function mkFrontPDF(){
  66. $comments = str_replace("\n","<BR>",$_POST['comments']);
  67. $bankaddress = str_replace("\n","<BR>",$_POST['n_bankaddress']);
  68. $address = str_replace("\n","<BR>",$_POST['n_address']);
  69. $account_owner = $_POST['owner'];
  70. if (!$account_owner) $account_owner = $_POST['realname'];
  71. # $aval = $_POST['advance'];
  72. # $advance = floatval(str_replace(",",".",$aval));
  73. $aw = $_POST;
  74. switch ($_POST['banktype']){
  75. case "bank-eu":
  76. $aw = "EU-Bank&uuml;berweisung";
  77. $aw_details = "
  78. Kontoinhaber: $account_owner<br>
  79. IBAN: $_POST[iban]<br>
  80. BIC: $_POST[bic]<br>
  81. Anmerkungen:<br> $comments<br>
  82. ";
  83. break;
  84. case "bank-noneu":
  85. $aw = "Non-EU-Bank&uuml;berweisung";
  86. $aw_details = "
  87. Kontoinhaber: $account_owner<br>
  88. Kontonummer: $_POST[n_iban]<br>
  89. BIC/SWIFT: $_POST[n_bic]<br>
  90. Bank: $_POST[n_ankname]<br><br>
  91. Bankanschrift:<br>$bankaddress<br><br>
  92. Anschrift des Empf&auml;ngers:<br>$address<br><br>
  93. Verwendungszweck:<br> $_POST[n_purpose]<br>
  94. Anmerkungen:<br> $comments<br>
  95. ";
  96. break;
  97. case "bank-paypal":
  98. $aw = "PayPal";
  99. $aw_details = "PayPal Account:";
  100. }
  101. $thtml = mkTable();
  102. // create new PDF document
  103. $pdf = new kaformPDF(
  104. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  105. true, 'UTF-8', false);
  106. // set document information
  107. /* $pdf->SetCreator(PDF_CREATOR);
  108. $pdf->SetAuthor('Nicola Asuni');
  109. $pdf->SetTitle('TCPDF Example 001');
  110. $pdf->SetSubject('TCPDF Tutorial');
  111. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  112. */
  113. // set default header data
  114. // $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,
  115. // PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING,
  116. // array(0,64,255), array(0,64,128));
  117. // $pdf->setFooterData(array(0,64,0), array(0,64,128));
  118. // set header and footer fonts
  119. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  120. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  121. // set default monospaced font
  122. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  123. // set margins
  124. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  125. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  126. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  127. // set auto page breaks
  128. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  129. // set image scale factor
  130. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  131. // set some language-dependent strings (optional)
  132. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  133. require_once(dirname(__FILE__).'/lang/eng.php');
  134. $pdf->setLanguageArray($l);
  135. }
  136. // ---------------------------------------------------------
  137. // set default font subsetting mode
  138. $pdf->setFontSubsetting(true);
  139. // Set font
  140. // dejavusans is a UTF-8 Unicode font, if you only need to
  141. // print standard ASCII chars, you can use core fonts like
  142. // helvetica or times to reduce file size.
  143. $pdf->SetFont('dejavusans', '', 14, '', true);
  144. // Add a page
  145. // This method has several options, check the source code
  146. // documentation for more information.
  147. $pdf->AddPage('P');
  148. // set text shadow effect
  149. $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2,
  150. 'depth_h'=>0.2, 'color'=>array(196,196,196),
  151. 'opacity'=>1, 'blend_mode'=>'Normal'));
  152. // calculate the overall summary
  153. $sum = calcSum();
  154. // Set some content to print
  155. $html =
  156. <<<EOD
  157. <h1>Kostenerstattungsantrag &uuml;ber $sum $_POST[currency]</h1>
  158. <p><b>Projekt: $_POST[project]</b></p>
  159. <hr>
  160. <p>
  161. &nbsp;
  162. <br>
  163. <!-- Nickname: $_POST[nickname]<br> -->
  164. Name: $_POST[realname]<br>
  165. Telefon: $_POST[phone]<br>
  166. E-Mail: $_POST[email]<br>
  167. Ansprechpartner: $_POST[wmdecontact]<br>
  168. </p>
  169. <hr>
  170. <br>
  171. <p>
  172. Auszahlungsweg: $aw<br>
  173. $aw_details
  174. </p>
  175. <hr>
  176. $thtml
  177. EOD;
  178. // Print text using writeHTMLCell()
  179. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  180. // ---------------------------------------------------------
  181. $tn = tempnam("/tmp","kaform");
  182. // Close and output PDF document
  183. // This method has several options, check the source code
  184. // documentation for more information.
  185. $pdf->Output($tn, 'F');
  186. return $tn;
  187. }
  188. function mkSnippedPdf($key){
  189. $pageLayout = array(210,70);
  190. // create new PDF document
  191. # $pdf = new kaformPDF(
  192. # PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
  193. # true, 'UTF-8', false);
  194. $pdf = new kaformPDF(
  195. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  196. true, 'UTF-8', false);
  197. $pdf->AddPage('L');
  198. $pos = array_search($key,array_keys($_POST['desc']))+1;
  199. // echo "<br>Make Snipped for $key -> $pos<br>";
  200. # $mydesk = $_POST[desc][$key];
  201. #
  202. $amount = $_POST['amount'][$key];
  203. $desc = $_POST['desc'][$key];
  204. $am = floatval(str_replace(",",".",$amount));
  205. $am = str_replace(".",",",sprintf("%.2f",$am));
  206. $html =
  207. <<<EOD
  208. <h1>Position $pos</h1>
  209. <p>$desc</p><br>
  210. <p>$am $_POST[currency]</p><br>
  211. EOD;
  212. // Print text using writeHTMLCell()
  213. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  214. $tn = tempnam("/tmp","kaform");
  215. // Close and output PDF document
  216. // This method has several options, check the source code
  217. // documentation for more information.
  218. $pdf->Output("$tn", 'F');
  219. return $tn;
  220. }
  221. //var_dump($_POST);
  222. function convert($row) {
  223. $r = array();
  224. foreach ($_SESSION['files'] as $filename => $file){
  225. if ($file['row'] != $row)
  226. continue;
  227. $tn = tempnam("/tmp","kaform");
  228. file_put_contents("$tn",$file['content']);
  229. array_push($r,"$tn");
  230. }
  231. return $r;
  232. }
  233. function calcSum(){
  234. $sum =0;
  235. if (!isset($_POST['amount'])) {
  236. echo "wrong parameters";
  237. die;
  238. }
  239. foreach ($_POST['amount'] as $val){
  240. // var_dump($val);
  241. $sum += floatval(str_replace(",",".",$val));
  242. }
  243. $sum -= get_adv();
  244. return str_replace(".",",",sprintf("%0.2f",$sum));
  245. }
  246. function mkTable(){
  247. $html = "<br>&nbsp;<br><table>";
  248. $pos = 1;
  249. $sum =0;
  250. if (!isset($_POST['amount'])) {
  251. echo "wrong parameters";
  252. die;
  253. }
  254. foreach ($_POST['amount'] as $key=>$val){
  255. $html .='<tr>';
  256. $html .= "<td>$pos</td>";
  257. $html .= "<td>".$_POST['date'][$key]."</td>";
  258. $html .= "<td>".$_POST['desc'][$key]."</td>";
  259. $am = floatval(str_replace(",",".",$val));
  260. $am = str_replace(".",",",sprintf("%.2f",$am));
  261. $html .= '<td align="right">'.$am." ".$_POST['currency']. "</td>";
  262. $html .="</tr>";
  263. $sum += floatval(str_replace(",",".",$val));
  264. $pos ++;
  265. }
  266. $adv = get_adv();
  267. if ($adv) {
  268. $html .= "<tr>";
  269. $html .= '<td colspan="3">';
  270. $html .= "Bereits erhaltener Vorschuss:";
  271. $html .= '</td>';
  272. $html .= '<td align="right">';
  273. $html .= sprintf("-%0.2f",$adv)." ".$_POST['currency'];
  274. $html .= '</td>';
  275. $html .= "</tr>";
  276. }
  277. $html .= '<tr>';
  278. $html .= '<td colspan="3">';
  279. $html .= "<b>Summe:</b>";
  280. $html .= '</td>';
  281. $html .= '<td align="right">';
  282. $html .= "<b>".calcSum()." ".$_POST['currency']."</b>";
  283. $html .= '</td>';
  284. $html .= '</tr>';
  285. $html .= "</table>";
  286. # $html .="<br>&nbsp;<br>";
  287. # $html .="<b>Summe: ".calcSum()."</b>";
  288. return $html;
  289. // return str_replace(".",",",sprintf("%0.2f",$sum));
  290. // return sprintf("%.2f",$sum);
  291. }
  292. $pdfs = array();
  293. error_log("Making Front PDF");
  294. //
  295. // Applicatoin starts here
  296. //
  297. $p = mkFrontPDF();
  298. $file = $p;
  299. #header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  300. #header('Content-Length: ' . filesize($file));
  301. #readfile($file);
  302. array_push($pdfs,$p);
  303. foreach ($_POST['desc'] as $key => $val) {
  304. // echo "DREESK KEY VAL $key --> $val<br>";
  305. $p = mkSnippedPDF($key);
  306. array_push($pdfs,$p);
  307. $pr = convert($key);
  308. $pdfs = array_merge($pdfs,$pr);
  309. }
  310. //var_dump($pdfs);
  311. //
  312. $resultnam = tempnam("/tmp","karesult");
  313. $cmd = "$PDFTK_CMD";
  314. foreach ($pdfs as $filename){
  315. $cmd .= " $filename";
  316. }
  317. $cmd .= " cat output $resultnam.pdf";
  318. error_log("EXEC CMD $cmd");
  319. exec ($cmd);
  320. $file = "$resultnam.pdf";
  321. if ($_POST['sendmail']=='yes'){
  322. $subj = "Kostenerstattungsantrag ueber".calcSum()." ".$_POST['currency'];
  323. $mail = new PHPMailer\PHPMailer\PHPMailer();
  324. $mail->SMTPOptions = array(
  325. 'ssl' => array(
  326. 'verify_peer' => false,
  327. 'verify_peer_name' => false,
  328. 'allow_self_signed' => true
  329. )
  330. );
  331. $mail->IsSMTP();
  332. $mail->setFrom($mailFrom);
  333. $mail->Subject = $subj;
  334. $mail->Body = "Kostenerstattungsantrag ...";
  335. $mail->AddAddress($mailDest);
  336. if ($mailDestCC) {
  337. $mail->AddCC($mailDestCC);
  338. }
  339. $mail->AddAttachment( $file , 'antrag.pdf' );
  340. $mail->Host = $mailHost; // Specify main and backup server
  341. $mail->Port = $mailPort; // Set the SMTP port
  342. $mail->SMTPAuth = $mailSMTPAuth;
  343. $mail->Username = $mailUsername;
  344. $mail->Password = $mailPassword;
  345. $mail->SMTPSecure = $mailSMTPSecure; // Enable encryption, 'ssl' also accepted
  346. $rc = $mail->send();
  347. if (!$rc) {
  348. echo 'Mailer Error: ' . $mail->ErrorInfo;
  349. die;
  350. }
  351. echo "Dein Antrag wurde versendet.<BR>";
  352. ?>
  353. <!-- <div class="is-col">
  354. <button type="button" onclick="downloadDocument(false);"
  355. class="button is-orange"><?=_("Kopie des Antrags herunterladen")?></button>
  356. </div> -->
  357. <?php
  358. echo '<a href="./submit.php?lst=1" target="_blank">Kopie des Antrags herunterladen</a>';
  359. echo "<br>";
  360. echo '<a href="./">
  361. Weiteren Antrag auf Kostenerstattung stellen</a><BR>';
  362. $_SESSION['lst']=file_get_contents("$resultnam.pdf");
  363. session_write_close();
  364. die;
  365. }
  366. $file = "$resultnam.pdf";
  367. header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  368. header('Content-Length: ' . filesize($file));
  369. readfile($file);
  370. ?>
  371. <script src="js/kube.min.js"></script>
  372. <script src="addons/upload/kube.upload.min.js"></script>
  373. <script src="addons/kube-addons.min.js"></script>
  374. <script src="kaform.js"></script>
  375. <script src="iban.js/iban.js"></script>
  376. </body>
  377. </html>