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.

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