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.

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