Files
2025-09-24 13:26:28 +02:00

79 lines
2.2 KiB
PHP

<?php
session_start();
define(ROOT, "../");
require_once('login.inc.php');
require_once(ROOT.'include/db.inc.php');
require_once(ROOT.'include/template.inc.php');
if (isset($_POST['search'])) {
search();
}
else if (isset($_POST['update'])) {
update();
}
else {
printForm();
}
#############################
function printForm() {
#############################
$t = new Template("templates/search.html");
$t->setVar("ERRORS", "");
$t->setVar("ID", "");
$t->parse();
}
#############################
function search() {
#############################
$_POST['id'] = str_replace("/", "", $_POST['id']);
$_POST['id'] = str_replace("-", "", $_POST['id']);
$query = sprintf("SELECT * FROM bruckmuehle_ticketculturecard WHERE id = %d LIMIT 1", sqlnum($_POST['id']));
$result = dbQuery($query);
if ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$t = new Template("templates/update.html");
$t->setVar("ID", $line['id']);
$t->setVar("OWNER", htmlentities($line['owner']));
$t->setVar("ADDRESS", htmlentities($line['address']));
$t->setVar("ZIP", $line['zip']);
$t->setVar("CITY", $line['city']);
$t->setVar("SPA_ENTRIES", $line['spaEntries']);
$str = sprintf("%012d", $line['id']);
$id = substr($str, 0, 5) . "/" . substr($str, 5, 2) . "/" . substr($str, 7, 2) . "/" . substr($str, 9, 3);
$t->setVar("FORMAT_ID", $id);
$opt = '';
for ($i = 1; $i <= $line['spaEntries']; $i++) {
$opt .= '<option value="' . $i . '">' . $i . '</option>';
}
$t->setVar("COUNT", $opt);
$t->parse();
}
else {
$t = new Template("templates/search.html");
$t->setVar("ERRORS", "Die Suche ergab keinen Treffer!");
$t->setVar("ID", $_POST['id']);
$t->parse();
}
}
############################
function update() {
############################
$query = sprintf("UPDATE bruckmuehle_ticketculturecard SET spaEntries = (spaEntries - %d) WHERE id = %d",
sqlnum($_POST['count']),
sqlnum($_POST['id']));
dbQuery($query);
$t = new Template("templates/done.html");
$t->setVar("COUNT", $_POST['count']);
$str = sprintf("%012d", $_POST['id']);
$id = substr($str, 0, 5) . "/" . substr($str, 5, 2) . "/" . substr($str, 7, 2) . "/" . substr($str, 9, 3);
$t->setVar("FORMAT_ID", $id);
$t->parse();
}
?>