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.

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