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.

508 lines
11 KiB

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