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.

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