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.

273 lines
7.2 KiB

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. $account_owner = $_POST[owner];
  34. if (!$account_owner) $account_owner = $_POST[realname];
  35. switch ($_POST[bank]){
  36. case "EU":
  37. $aw = "EU-Bank&uuml;berweisung";
  38. $aw_details = "
  39. Kontoinhaber: $account_owner<br>
  40. ";
  41. break;
  42. case "NonEU":
  43. $aw = "Non-EU-Bank&uuml;berweisung";
  44. break;
  45. }
  46. // create new PDF document
  47. $pdf = new kaformPDF(
  48. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  49. true, 'UTF-8', false);
  50. // set document information
  51. /* $pdf->SetCreator(PDF_CREATOR);
  52. $pdf->SetAuthor('Nicola Asuni');
  53. $pdf->SetTitle('TCPDF Example 001');
  54. $pdf->SetSubject('TCPDF Tutorial');
  55. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  56. */
  57. // set default header data
  58. // $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,
  59. // PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING,
  60. // array(0,64,255), array(0,64,128));
  61. // $pdf->setFooterData(array(0,64,0), array(0,64,128));
  62. // set header and footer fonts
  63. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  64. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  65. // set default monospaced font
  66. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  67. // set margins
  68. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  69. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  70. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  71. // set auto page breaks
  72. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  73. // set image scale factor
  74. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  75. // set some language-dependent strings (optional)
  76. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  77. require_once(dirname(__FILE__).'/lang/eng.php');
  78. $pdf->setLanguageArray($l);
  79. }
  80. // ---------------------------------------------------------
  81. // set default font subsetting mode
  82. $pdf->setFontSubsetting(true);
  83. // Set font
  84. // dejavusans is a UTF-8 Unicode font, if you only need to
  85. // print standard ASCII chars, you can use core fonts like
  86. // helvetica or times to reduce file size.
  87. $pdf->SetFont('dejavusans', '', 14, '', true);
  88. // Add a page
  89. // This method has several options, check the source code
  90. // documentation for more information.
  91. $pdf->AddPage('P');
  92. // set text shadow effect
  93. $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2,
  94. 'depth_h'=>0.2, 'color'=>array(196,196,196),
  95. 'opacity'=>1, 'blend_mode'=>'Normal'));
  96. // calculate the overall summary
  97. $sum = calcSum();
  98. // Set some content to print
  99. $html =
  100. <<<EOD
  101. <h1>Kostenerstattungsantrag &uuml;ber $sum EUR</h1>
  102. <p><b>Projekt: $_POST[project]</b></p>
  103. <p>WMDE Ansprechpartner: $_POST[wmdecontact]</p>
  104. <hr>
  105. <p>
  106. &nbsp;
  107. <br>
  108. Name: $_POST[realname]<br>
  109. E-Mail: $_POST[email]<br>
  110. Telefon: $_POST[phone]
  111. </p>
  112. <hr>
  113. <br>
  114. <p>
  115. Auszahlungsweg: $aw<br>
  116. $aw_details
  117. </p>
  118. EOD;
  119. // Print text using writeHTMLCell()
  120. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  121. // ---------------------------------------------------------
  122. $tn = tempnam("/tmp","kaform");
  123. // Close and output PDF document
  124. // This method has several options, check the source code
  125. // documentation for more information.
  126. $pdf->Output($tn, 'F');
  127. return $tn;
  128. }
  129. function mkSnippedPdf($key){
  130. $pageLayout = array(210,70);
  131. // create new PDF document
  132. # $pdf = new kaformPDF(
  133. # PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
  134. # true, 'UTF-8', false);
  135. $pdf = new kaformPDF(
  136. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  137. true, 'UTF-8', false);
  138. $pdf->AddPage('L');
  139. $pos = array_search($key,array_keys($_POST['desc']))+1;
  140. echo "<br>Make Snipped for $key -> $pos<br>";
  141. # $mydesk = $_POST[desc][$key];
  142. #
  143. $amount = $_POST['amount'][$key];
  144. $desc = $_POST['desc'][$key];
  145. $html =
  146. <<<EOD
  147. <h1>Posi. $pos</h1>
  148. <p>$desc</p><br>
  149. <p>$amount EUR</p><br>
  150. EOD;
  151. // Print text using writeHTMLCell()
  152. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  153. $tn = tempnam("/tmp","kaform");
  154. // Close and output PDF document
  155. // This method has several options, check the source code
  156. // documentation for more information.
  157. $pdf->Output("$tn", 'F');
  158. return $tn;
  159. }
  160. //var_dump($_POST);
  161. function convert($row) {
  162. $r = array();
  163. foreach ($_SESSION['files'] as $filename => $file){
  164. if ($file['row'] != $row)
  165. continue;
  166. $tn = tempnam("/tmp","kaform");
  167. file_put_contents("$tn",$file['content']);
  168. array_push($r,"$tn");
  169. }
  170. return $r;
  171. }
  172. function calcSum(){
  173. $sum =0;
  174. if (!isset($_POST['amount'])) {
  175. echo "wrong parameters";
  176. die;
  177. }
  178. foreach ($_POST['amount'] as $val){
  179. var_dump($val);
  180. $sum += floatval(str_replace(",",".",$val));
  181. }
  182. return $sum;
  183. }
  184. $pdfs = array();
  185. // Applicatoin starts here
  186. $p = mkFrontPDF();
  187. array_push($pdfs,$p);
  188. foreach ($_POST['desc'] as $key => $val) {
  189. echo "DREESK KEY VAL $key --> $val<br>";
  190. $p = mkSnippedPDF($key);
  191. array_push($pdfs,$p);
  192. $pr = convert($key);
  193. $pdfs = array_merge($pdfs,$pr);
  194. }
  195. var_dump($pdfs);
  196. $cmd = "$CONVERT_CMD";
  197. foreach ($pdfs as $filename){
  198. $cmd .= " $filename";
  199. }
  200. $cmd .= " cat output /tmp/result.pdf";
  201. exec ($cmd);
  202. echo "CMD: $cmd<br>";