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.

295 lines
7.8 KiB

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