getMessage(), "\n
"; } //Primary SQL Statement $statement = $pdo->prepare("SELECT zf_bap_orders.*,zbs.name as zbs_name,zbc.code as zbc_code, zbc.discount_price as zbc_discount FROM zf_bap_orders JOIN zf_bap_events zbs on zf_bap_orders.event_id = zbs.event_id LEFT JOIN zf_bap_coupons zbc on zf_bap_orders.coupon_id = zbc.coupon_id WHERE zf_bap_orders.code = :code AND zf_bap_orders.status_id = :status_id"); //Bind parameters $statement->bindParam("code", $_GET["code"]); // "Auth" 2 $expected_status = 2; // 2 equals "is paid" $statement->bindParam("status_id", $expected_status); //Only show, if ticket is paid //Execute Statement and fetch Data $statement->execute(); $row2 = $statement->fetch(); if(!($row2["order_id"]>0)){ die('Fehler! Ticket ist ungültig.'); } //PDF Library $mpdf = new Mpdf(); $mpdf->allow_charset_conversion = true; //Get Payment methode using ternary operator $zahlung = $row2["paypal_token"] != "" ? "Paypal" : "Barzahlung"; //Looks like shit, but works :D (PHP Serialized Class -> JSON -> PHP stdClass -> PHP Object) $seats = json_decode(json_encode(unserialize($row2["places"], ['allowed_classes' => false])), true); //Convert object to HTML List $seat_html = ""; $is_vip = false; $vip_price = 0; foreach ($seats as $seat) { if($seat["place_name"]!="VIP"){ $seat_html .= $seat["place_name"] . " (" . $seat["place_price"] . "€), "; // results in e.g. 'Reihe 1, Platz 2 (5€)' }else{ $is_vip=true; $vip_price=$seat["place_price"]; } } //Generate Coupon Badge $rabatt = ($row2["coupon_id"]!=0) ? $row2["zbc_code"] . ' (-' . $row2["zbc_discount"].'€)' : "-"; //Build HTML Site, which will be converted into a PDF $data = ' Zauberflöte - Ticketbuchung Logo

Ihre Zauberflöte - Tickets

Ticket-Nummer ' . $row2["order_id"] . "_" . $row2["code"] . '
Zusätze ' . ($is_vip ? "VIP (".$vip_price."€)" : "-") . '
Name ' . sonderzeichen($row2["first_name"]) . " " . sonderzeichen($row2["last_name"]) . '
Bestelldatum ' . $row2["date"] . '
Rabattcode ' . $rabatt . '
Kontakt ' . (($row2["paypal_token"] != "") ? ($row2["email"] . " /  " . $row2["phone"]) : "-") . '
Vorstellung ' . $row2["zbs_name"] . '
Platz ' . $seat_html . '
Zahlung ' . $zahlung . '
Finaler Preis ' . $row2["total_price"] . '€
QR Code '; //Convert from HTML try { $mpdf->WriteHTML(mb_convert_encoding($data, 'UTF-8', 'UTF-8')); } catch (MpdfException $ex) { echo 'Exception abgefangen: ', $ex->getMessage(), "\n
"; die(); } //Print to Webpage try { $mpdf->Output(); } catch (MpdfException $ex) { echo 'Exception abgefangen: ', $ex->getMessage(), "\n
"; } function sonderzeichen($string): string { $res = $string; $res = str_replace("ä", "ae", $res); $res = str_replace("ü", "ue", $res); $res = str_replace("ö", "oe", $res); $res = str_replace("Ä", "Ae", $res); $res = str_replace("Ü", "Ue", $res); $res = str_replace("Ö", "Oe", $res); return str_replace("ß", "ss", $res); }