zauberfloete-ticket-pdf-exp.../ticket-check.php

144 lines
4.5 KiB
PHP
Raw Normal View History

2022-05-03 10:31:25 +02:00
<?php
//Database & secrets
include "config.php";
if(empty($_GET["code"])){
die('Fehler! Bitte überprüfen Sie den Link!');
}
//access var from config.php
global $CONFIG;
//Establish Database Connection using PHP Data Objects
try {
$pdo = new PDO('mysql:host=' . $CONFIG["database"]["server"] . ';dbname=' . $CONFIG["database"]["dbname"], $CONFIG["database"]["user"], $CONFIG["database"]["password"]);
} catch (PDOException $ex) {
echo 'Exception abgefangen: ', $ex->getMessage(), "\n<br/>";
}
//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
2022-05-03 10:31:25 +02:00
FROM zf_bap_orders
2022-05-03 12:34:39 +02:00
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");
2022-05-03 10:31:25 +02:00
//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.');
}
//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"])), true);
//Convert object to HTML List
$seat_html = "";
foreach ($seats as $seat) {
$seat_html .= $seat["place_name"] . " (" . $seat["place_price"] . "€), "; // results in e.g. 'Reihe 1, Platz 2 (5€)'
}
2022-05-03 12:34:39 +02:00
//Generate Coupon Badge
$rabatt = ($row2["coupon_id"]!=0) ? $row2["zbc_code"] . ' (-' . $row2["zbc_discount"].'€)' : "-";
2022-05-03 12:34:39 +02:00
2022-05-04 10:27:20 +02:00
$zusatz = "";
//converting [1,2,3] to (1,2,3) => sql syntax
$ids = str_replace("[","(",$row2["additional_ids"]);
$ids = str_replace("]",")",$ids);
//Get all used additional services
$statement_additional = $pdo->prepare("SELECT * from zf_bap_additional WHERE additional_id IN ".$ids);
//Execute Statement and fetch Data
$statement_additional->execute();
$row_additional = $statement_additional->fetchAll();
foreach ($row_additional as $item){
$zusatz .= $item["name"]." (".$item["price_eur"]."€)";
if(count($row_additional)>1){
$zusatz .= "<br/>";
}
}
2022-05-03 10:31:25 +02:00
echo '<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Zauberflöte - Ticketbuchung</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<style>
body{
margin: 50px;
}
.td_desc{
padding-right: 10px;
width: 30vw;
2022-05-04 07:04:07 +02:00
font-weight: bold;
2022-05-03 10:31:25 +02:00
}
</style>
</head>
<body class="container">
<h1>Ticket: '.$row2["order_id"] . "_" . $row2["code"].'</h1>
<table>
<tr>
<td class="td_desc">Name</td>
<td>' . $row2["first_name"] . "&nbsp;" . $row2["last_name"] . '</td>
</tr>
2022-05-04 10:27:20 +02:00
<tr>
<td class="td_desc">Zusätze</td>
<td>' . $zusatz . '</td>
</tr>
2022-05-03 10:31:25 +02:00
<tr>
<td class="td_desc">Bestelldatum</td>
<td>' . $row2["date"] . '</td>
</tr>
<tr>
<td class="td_desc">Vorstellung</td>
<td>' . $row2["zbs_name"] . '</td>
</tr>
2022-05-03 12:34:39 +02:00
<tr>
<td class="td_desc">Rabattcode</td>
<td>' . $rabatt . '</td>
</tr>
2022-05-03 10:31:25 +02:00
<tr>
<td class="td_desc">Platz</td>
<td>' . $seat_html . '</td>
</tr>
<tr>
<td class="td_desc">Zahlung</td>
<td>' . $zahlung . '</td>
</tr>
2022-05-03 12:34:39 +02:00
<tr>
<td class="td_desc">Finaler Preis</td>
<td>' . $row2["total_price"] . '</td>
</tr>
2022-05-03 10:31:25 +02:00
</table>
</body>
</html>';