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.

319 lines
8.5 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
  1. <?php
  2. session_start();
  3. require "config.php";
  4. #$CONVERT_CMD = "/usr/bin/pdftk";
  5. require_once('TCPDF/tcpdf.php');
  6. class kaformPDF extends TCPDF {
  7. //Page header
  8. public function Header() {
  9. }
  10. // // Logo
  11. // $image_file = K_PATH_IMAGES.'logo_example.jpg';
  12. // $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
  13. // // Set font
  14. // $this->SetFont('helvetica', 'B', 20);
  15. // // Title
  16. // $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
  17. // }
  18. //
  19. // // Page footer
  20. public function Footer() {
  21. }
  22. // // Position at 15 mm from bottom
  23. // $this->SetY(-15);
  24. // // Set font
  25. // $this->SetFont('helvetica', 'I', 8);
  26. // // Page number
  27. // $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
  28. // }
  29. // }
  30. //
  31. };
  32. function mkFrontPDF(){
  33. $comments = str_replace("\n","<BR>",$_POST['comments']);
  34. $bankaddress = str_replace("\n","<BR>",$_POST['n_bankaddress']);
  35. $address = str_replace("\n","<BR>",$_POST['n_address']);
  36. $account_owner = $_POST['owner'];
  37. if (!$account_owner) $account_owner = $_POST['realname'];
  38. $aw = $_POST;
  39. switch ($_POST['banktype']){
  40. case "bank-eu":
  41. $aw = "EU-Bank&uuml;berweisung";
  42. $aw_details = "
  43. Kontoinhaber: $account_owner<br>
  44. IBAN: $_POST[iban]<br>
  45. BIC: $_POST[bic]<br>
  46. Bank: $_POST[bankname]<br><br>
  47. Verwendungszweck:<br> $_POST[purpose]<br>
  48. ";
  49. break;
  50. case "bank-noneu":
  51. $aw = "Non-EU-Bank&uuml;berweisung";
  52. $aw_details = "
  53. Kontoinhaber: $account_owner<br>
  54. Kontonummer: $_POST[n_iban]<br>
  55. BIC/SWIFT: $_POST[n_bic]<br>
  56. Bank: $_POST[n_ankname]<br><br>
  57. Bankanschrift:<br>$bankaddress<br><br>
  58. Anschrift des Empf&auml;ngers:<br>$address<br><br>
  59. Verwendungszweck:<br> $_POST[n_purpose]<br>
  60. Anmerkungen:<br> $comments<br>
  61. ";
  62. break;
  63. case "bank-paypal":
  64. $aw = "PayPal";
  65. $aw_details = "PayPal Account:";
  66. }
  67. // create new PDF document
  68. $pdf = new kaformPDF(
  69. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  70. true, 'UTF-8', false);
  71. // set document information
  72. /* $pdf->SetCreator(PDF_CREATOR);
  73. $pdf->SetAuthor('Nicola Asuni');
  74. $pdf->SetTitle('TCPDF Example 001');
  75. $pdf->SetSubject('TCPDF Tutorial');
  76. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  77. */
  78. // set default header data
  79. // $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,
  80. // PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING,
  81. // array(0,64,255), array(0,64,128));
  82. // $pdf->setFooterData(array(0,64,0), array(0,64,128));
  83. // set header and footer fonts
  84. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  85. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  86. // set default monospaced font
  87. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  88. // set margins
  89. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  90. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  91. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  92. // set auto page breaks
  93. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  94. // set image scale factor
  95. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  96. // set some language-dependent strings (optional)
  97. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  98. require_once(dirname(__FILE__).'/lang/eng.php');
  99. $pdf->setLanguageArray($l);
  100. }
  101. // ---------------------------------------------------------
  102. // set default font subsetting mode
  103. $pdf->setFontSubsetting(true);
  104. // Set font
  105. // dejavusans is a UTF-8 Unicode font, if you only need to
  106. // print standard ASCII chars, you can use core fonts like
  107. // helvetica or times to reduce file size.
  108. $pdf->SetFont('dejavusans', '', 14, '', true);
  109. // Add a page
  110. // This method has several options, check the source code
  111. // documentation for more information.
  112. $pdf->AddPage('P');
  113. // set text shadow effect
  114. $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2,
  115. 'depth_h'=>0.2, 'color'=>array(196,196,196),
  116. 'opacity'=>1, 'blend_mode'=>'Normal'));
  117. // calculate the overall summary
  118. $sum = calcSum();
  119. // Set some content to print
  120. $html =
  121. <<<EOD
  122. <h1>Kostenerstattungsantrag &uuml;ber $sum EUR</h1>
  123. <p><b>Projekt: $_POST[project]</b></p>
  124. <hr>
  125. <p>
  126. &nbsp;
  127. <br>
  128. Nickname: $_POST[nickname]<br>
  129. Name: $_POST[realname]<br>
  130. Telefon: $_POST[phone]<br>
  131. E-Mail: $_POST[email]<br>
  132. Ansprechpartner: $_POST[wmdecontact]<br>
  133. </p>
  134. <hr>
  135. <br>
  136. <p>
  137. Auszahlungsweg: $aw<br>
  138. $aw_details
  139. </p>
  140. EOD;
  141. // <p>WMDE Ansprechpartner: $_POST[wmdecontact]</p>
  142. // Telefon: $_POST[phone]
  143. // Print text using writeHTMLCell()
  144. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  145. // ---------------------------------------------------------
  146. $tn = tempnam("/tmp","kaform");
  147. // Close and output PDF document
  148. // This method has several options, check the source code
  149. // documentation for more information.
  150. $pdf->Output($tn, 'F');
  151. return $tn;
  152. }
  153. function mkSnippedPdf($key){
  154. $pageLayout = array(210,70);
  155. // create new PDF document
  156. # $pdf = new kaformPDF(
  157. # PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
  158. # true, 'UTF-8', false);
  159. $pdf = new kaformPDF(
  160. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  161. true, 'UTF-8', false);
  162. $pdf->AddPage('L');
  163. $pos = array_search($key,array_keys($_POST['description']))+1;
  164. // echo "<br>Make Snipped for $key -> $pos<br>";
  165. # $mydesk = $_POST[desc][$key];
  166. #
  167. $amount = $_POST['amount'][$key];
  168. $desc = $_POST['description'][$key];
  169. $html =
  170. <<<EOD
  171. <h1>Position $pos</h1>
  172. <p>$desc</p><br>
  173. <p>$amount EUR</p><br>
  174. EOD;
  175. // Print text using writeHTMLCell()
  176. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  177. $tn = tempnam("/tmp","kaform");
  178. // Close and output PDF document
  179. // This method has several options, check the source code
  180. // documentation for more information.
  181. $pdf->Output("$tn", 'F');
  182. return $tn;
  183. }
  184. //var_dump($_POST);
  185. function convert($row) {
  186. $r = array();
  187. foreach ($_SESSION['files'] as $filename => $file){
  188. if ($file['row'] != $row)
  189. continue;
  190. $tn = tempnam("/tmp","kaform");
  191. file_put_contents("$tn",$file['content']);
  192. array_push($r,"$tn");
  193. }
  194. return $r;
  195. }
  196. function calcSum(){
  197. $sum =0;
  198. if (!isset($_POST['amount'])) {
  199. echo "wrong parameters";
  200. die;
  201. }
  202. foreach ($_POST['amount'] as $val){
  203. // var_dump($val);
  204. $sum += floatval(str_replace(",",".",$val));
  205. }
  206. return $sum;
  207. }
  208. $pdfs = array();
  209. // Applicatoin starts here
  210. //
  211. $p = mkFrontPDF();
  212. $file = $p;
  213. #header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  214. #header('Content-Length: ' . filesize($file));
  215. #readfile($file);
  216. #var_dump($p);
  217. #die();
  218. #echo "Making Fromt PDF<BR>";
  219. #echo "Did Making Fromt PDF<BR>";
  220. array_push($pdfs,$p);
  221. //var_dump($pdfs);
  222. foreach ($_POST['description'] as $key => $val) {
  223. // echo "DREESK KEY VAL $key --> $val<br>";
  224. $p = mkSnippedPDF($key);
  225. array_push($pdfs,$p);
  226. $pr = convert($key);
  227. $pdfs = array_merge($pdfs,$pr);
  228. }
  229. //var_dump($pdfs);
  230. $cmd = "$CONVERT_CMD";
  231. foreach ($pdfs as $filename){
  232. $cmd .= " $filename";
  233. }
  234. $cmd .= " cat output /tmp/result.pdf";
  235. exec ($cmd);
  236. //var_dump($_POST);
  237. #echo "CMD: $cmd<br>";
  238. #die;
  239. $file = "/tmp/result.pdf";
  240. header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  241. header('Content-Length: ' . filesize($file));
  242. readfile($file);