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.

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