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.

456 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
  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. #var_dump($thtml);
  158. #die;
  159. // <p>WMDE Ansprechpartner: $_POST[wmdecontact]</p>
  160. // Telefon: $_POST[phone]
  161. // Print text using writeHTMLCell()
  162. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  163. // ---------------------------------------------------------
  164. $tn = tempnam("/tmp","kaform");
  165. // Close and output PDF document
  166. // This method has several options, check the source code
  167. // documentation for more information.
  168. $pdf->Output($tn, 'F');
  169. return $tn;
  170. }
  171. function mkSnippedPdf($key){
  172. $pageLayout = array(210,70);
  173. // create new PDF document
  174. # $pdf = new kaformPDF(
  175. # PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
  176. # true, 'UTF-8', false);
  177. $pdf = new kaformPDF(
  178. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  179. true, 'UTF-8', false);
  180. $pdf->AddPage('L');
  181. $pos = array_search($key,array_keys($_POST['desc']))+1;
  182. // echo "<br>Make Snipped for $key -> $pos<br>";
  183. # $mydesk = $_POST[desc][$key];
  184. #
  185. $amount = $_POST['amount'][$key];
  186. $desc = $_POST['desc'][$key];
  187. $am = floatval(str_replace(",",".",$amount));
  188. $am = str_replace(".",",",sprintf("%.2f",$am));
  189. $html =
  190. <<<EOD
  191. <h1>Position $pos</h1>
  192. <p>$desc</p><br>
  193. <p>$am EUR</p><br>
  194. EOD;
  195. // Print text using writeHTMLCell()
  196. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  197. $tn = tempnam("/tmp","kaform");
  198. // Close and output PDF document
  199. // This method has several options, check the source code
  200. // documentation for more information.
  201. $pdf->Output("$tn", 'F');
  202. return $tn;
  203. }
  204. //var_dump($_POST);
  205. function convert($row) {
  206. $r = array();
  207. foreach ($_SESSION['files'] as $filename => $file){
  208. if ($file['row'] != $row)
  209. continue;
  210. $tn = tempnam("/tmp","kaform");
  211. file_put_contents("$tn",$file['content']);
  212. array_push($r,"$tn");
  213. }
  214. return $r;
  215. }
  216. function calcSum(){
  217. $sum =0;
  218. if (!isset($_POST['amount'])) {
  219. echo "wrong parameters";
  220. die;
  221. }
  222. foreach ($_POST['amount'] as $val){
  223. // var_dump($val);
  224. $sum += floatval(str_replace(",",".",$val));
  225. }
  226. $sum -= get_adv();
  227. return str_replace(".",",",sprintf("%0.2f",$sum));
  228. }
  229. function mkTable(){
  230. $html = "<br>&nbsp;<br><table>";
  231. $pos = 1;
  232. $sum =0;
  233. if (!isset($_POST['amount'])) {
  234. echo "wrong parameters";
  235. die;
  236. }
  237. foreach ($_POST['amount'] as $key=>$val){
  238. $html .='<tr>';
  239. $html .= "<td>$pos</td>";
  240. $html .= "<td>".$_POST['date'][$key]."</td>";
  241. $html .= "<td>".$_POST['desc'][$key]."</td>";
  242. $am = floatval(str_replace(",",".",$val));
  243. $am = str_replace(".",",",sprintf("%.2f",$am));
  244. $html .= '<td align="right">'.$am." ".$_POST['currency'][$key]. "</td>";
  245. $html .="</tr>";
  246. $sum += floatval(str_replace(",",".",$val));
  247. $pos ++;
  248. }
  249. $adv = get_adv();
  250. if ($adv) {
  251. $html .= "<tr>";
  252. $html .= '<td colspan="3">';
  253. $html .= "Bereits erhaltener Vorschuss:";
  254. $html .= '</td>';
  255. $html .= '<td align="right">';
  256. $html .= sprintf("-%0.2f",$adv)." EUR";
  257. $html .= '</td>';
  258. $html .= "</tr>";
  259. }
  260. $html .= '<tr>';
  261. $html .= '<td colspan="3">';
  262. $html .= "<b>Summe:</b>";
  263. $html .= '</td>';
  264. $html .= '<td align="right">';
  265. $html .= "<b>".calcSum()." EUR</b>";
  266. $html .= '</td>';
  267. $html .= '</tr>';
  268. $html .= "</table>";
  269. # $html .="<br>&nbsp;<br>";
  270. # $html .="<b>Summe: ".calcSum()."</b>";
  271. return $html;
  272. // return str_replace(".",",",sprintf("%0.2f",$sum));
  273. // return sprintf("%.2f",$sum);
  274. }
  275. $pdfs = array();
  276. // Applicatoin starts here
  277. //
  278. $p = mkFrontPDF();
  279. $file = $p;
  280. #header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  281. #header('Content-Length: ' . filesize($file));
  282. #readfile($file);
  283. #var_dump($p);
  284. #die();
  285. #echo "Making Fromt PDF<BR>";
  286. #echo "Did Making Fromt PDF<BR>";
  287. array_push($pdfs,$p);
  288. //var_dump($pdfs);
  289. foreach ($_POST['desc'] as $key => $val) {
  290. // echo "DREESK KEY VAL $key --> $val<br>";
  291. $p = mkSnippedPDF($key);
  292. array_push($pdfs,$p);
  293. $pr = convert($key);
  294. $pdfs = array_merge($pdfs,$pr);
  295. }
  296. //var_dump($pdfs);
  297. //
  298. $resultnam = tempnam("/tmp","karesult");
  299. $cmd = "$CONVERT_CMD";
  300. foreach ($pdfs as $filename){
  301. $cmd .= " $filename";
  302. }
  303. $cmd .= " cat output $resultnam.pdf";
  304. exec ($cmd);
  305. #var_dump($_POST);
  306. $file = "$resultnam.pdf";
  307. if ($_POST['sendmail']=='yes'){
  308. $subj = "Kostenerstattungsantrag ueber".calcSum()." EUR";
  309. $mail = new PHPMailer\PHPMailer\PHPMailer();
  310. $mail->SMTPOptions = array(
  311. 'ssl' => array(
  312. 'verify_peer' => false,
  313. 'verify_peer_name' => false,
  314. 'allow_self_signed' => true
  315. )
  316. );
  317. $mail->IsSMTP();
  318. $mail->setFrom($mailFrom);
  319. $mail->Subject = $subj;
  320. $mail->Body = "Kostenerstattungsantrag ...";
  321. $mail->AddAddress($mailDest);
  322. $mail->AddAttachment( $file , 'antrag.pdf' );
  323. $mail->Host = $mailHost; // Specify main and backup server
  324. $mail->Port = $mailPort; // Set the SMTP port
  325. $mail->SMTPAuth = $mailSMTPAuth;
  326. $mail->Username = $mailUsername;
  327. $mail->Password = $mailPassword;
  328. $mail->SMTPSecure = $mailSMTPSecure; // Enable encryption, 'ssl' also accepted
  329. $rc = $mail->send();
  330. if (!$rc) {
  331. echo 'Mailer Error: ' . $mail->ErrorInfo;
  332. }
  333. echo "Dein Antrag wurde versendet.<BR>";
  334. echo '<a href="ka.php">
  335. Weiteren Antrag auf Kostenerstattung stellen</a><BR>';
  336. die;
  337. }
  338. $file = "$resultnam.pdf";
  339. header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  340. header('Content-Length: ' . filesize($file));
  341. readfile($file);