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.

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