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.

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