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.

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