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.

415 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
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. $am = floatval(str_replace(",",".",$amount));
  186. $am = str_replace(".",",",sprintf("%.2f",$am));
  187. $html =
  188. <<<EOD
  189. <h1>Position $pos</h1>
  190. <p>$desc</p><br>
  191. <p>$am EUR</p><br>
  192. EOD;
  193. // Print text using writeHTMLCell()
  194. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  195. $tn = tempnam("/tmp","kaform");
  196. // Close and output PDF document
  197. // This method has several options, check the source code
  198. // documentation for more information.
  199. $pdf->Output("$tn", 'F');
  200. return $tn;
  201. }
  202. //var_dump($_POST);
  203. function convert($row) {
  204. $r = array();
  205. foreach ($_SESSION['files'] as $filename => $file){
  206. if ($file['row'] != $row)
  207. continue;
  208. $tn = tempnam("/tmp","kaform");
  209. file_put_contents("$tn",$file['content']);
  210. array_push($r,"$tn");
  211. }
  212. return $r;
  213. }
  214. function calcSum(){
  215. $sum =0;
  216. if (!isset($_POST['amount'])) {
  217. echo "wrong parameters";
  218. die;
  219. }
  220. foreach ($_POST['amount'] as $val){
  221. // var_dump($val);
  222. $sum += floatval(str_replace(",",".",$val));
  223. }
  224. $sum -= get_adv();
  225. return str_replace(".",",",sprintf("%0.2f",$sum));
  226. // return sprintf("%.2f",$sum);
  227. }
  228. function mkTable(){
  229. $html = "<br>&nbsp;<br><table>";
  230. $pos = 1;
  231. $sum =0;
  232. if (!isset($_POST['amount'])) {
  233. echo "wrong parameters";
  234. die;
  235. }
  236. foreach ($_POST['amount'] as $key=>$val){
  237. $html .='<tr>';
  238. $html .= "<td>$pos</td>";
  239. $html .= "<td>".$_POST['date'][$key]."</td>";
  240. $html .= "<td>".$_POST['description'][$key]."</td>";
  241. $am = floatval(str_replace(",",".",$val));
  242. $am = str_replace(".",",",sprintf("%.2f",$am));
  243. $html .= '<td align="right">'.$am." ".$_POST['currency'][$key]. "</td>";
  244. $html .="</tr>";
  245. $sum += floatval(str_replace(",",".",$val));
  246. $pos ++;
  247. }
  248. $adv = get_adv();
  249. if ($adv) {
  250. $html .= "<tr>";
  251. $html .= '<td colspan="3">';
  252. $html .= "Bereits erhaltener Vorschuss:";
  253. $html .= '</td>';
  254. $html .= '<td align="right">';
  255. $html .= sprintf("-%0.2f",$adv)." EUR";
  256. $html .= '</td>';
  257. $html .= "</tr>";
  258. }
  259. $html .= '<tr>';
  260. $html .= '<td colspan="3">';
  261. $html .= "<b>Summe:</b>";
  262. $html .= '</td>';
  263. $html .= '<td align="right">';
  264. $html .= "<b>".calcSum()." EUR</b>";
  265. $html .= '</td>';
  266. $html .= '</tr>';
  267. $html .= "</table>";
  268. # $html .="<br>&nbsp;<br>";
  269. # $html .="<b>Summe: ".calcSum()."</b>";
  270. return $html;
  271. // return str_replace(".",",",sprintf("%0.2f",$sum));
  272. // return sprintf("%.2f",$sum);
  273. }
  274. $pdfs = array();
  275. // Applicatoin starts here
  276. //
  277. $p = mkFrontPDF();
  278. $file = $p;
  279. #header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  280. #header('Content-Length: ' . filesize($file));
  281. #readfile($file);
  282. #var_dump($p);
  283. #die();
  284. #echo "Making Fromt PDF<BR>";
  285. #echo "Did Making Fromt PDF<BR>";
  286. array_push($pdfs,$p);
  287. //var_dump($pdfs);
  288. foreach ($_POST['description'] as $key => $val) {
  289. // echo "DREESK KEY VAL $key --> $val<br>";
  290. $p = mkSnippedPDF($key);
  291. array_push($pdfs,$p);
  292. $pr = convert($key);
  293. $pdfs = array_merge($pdfs,$pr);
  294. }
  295. //var_dump($pdfs);
  296. //
  297. $resultnam = tempnam("/tmp","karesult");
  298. $cmd = "$CONVERT_CMD";
  299. foreach ($pdfs as $filename){
  300. $cmd .= " $filename";
  301. }
  302. $cmd .= " cat output $resultnam.pdf";
  303. exec ($cmd);
  304. #var_dump($_POST);
  305. #echo "CMD: $cmd<br>";
  306. #die;
  307. $file = "$resultnam.pdf";
  308. header('Content-Disposition: attachment; filename="'. basename($file) . '"');
  309. header('Content-Length: ' . filesize($file));
  310. readfile($file);