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.

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