<commit_before><?php
	session_start();
?>
<!DOCTYPE html>
<html lang="de">
	<head>
		<meta charset="utf-8" />

		<title>SSBO Ticketing</title>
		<meta name="description" content="SSBO Ticketing System" />
		<meta name="author" content="<NAME>" />

		<!-- Favicon -->
		<link rel="shortcut icon" href="img/favicon.png" />
		
		<!-- jQuery -->
		<script src="lib/jquery-2.1.0.min.js"></script>
		
		<!-- qrcode -->
		<script src="lib/qrcode.min.js"></script>
		
		<!-- custom method to read out the URL parameters -->
		<script src="js/getParameters.js"></script>
	</head>

	<body>
		<header>
			<h1>SSBO Ticketing</h1>
		</header>
		
		<div id="demo">
			<ul>
				<li>
					<a href="?code=1911332118324935400">Unused code</a>
				</li>
				<li>
					<a href="?code=9751755374018103000">Used code</a>
				</li>
				<li>
					<a href="?code=12345">Wrong code</a>
				</li>
			</ul>
		</div>

		<div id="qrcode">
			<!-- QRCode will be placed here, if the code is valid. If not a message will be prompted to the user. -->
		</div>
		
		<?php
			// Control the code
			$code = $_GET['code'];
	
			// Open a connection to the MySQL server and select the database
			require_once 'db_info.php';
			$connection = mysql_connect($db_host, $db_username, $db_password) or die('Keine Verbindung möglich. Benutzername oder Passwort sind falsch');
			mysql_select_db($db_database) or die('Die Datenbank existiert nicht.');
	
			// Select the row with the correct user_id
			$query = "SELECT * FROM tickets WHERE code = '" . $code . "' LIMIT 1";
			$result = mysql_query($query);
	
			while ($row = mysql_fetch_object($result)) {
				$used = $row -> used;
			}
			
			if (isset($used) && $used == FALSE) {
				// Code is correct
				echo '
		<script type="text/javascript">
			// Create the QRCode
			// new QRCode(document.getElementById("qrcode"), getParam("code"));
			new QRCode(document.getElementById("qrcode"), {
				text: getParam("code"),
				width: 256,
				height: 256,
				colorDark : "#0000ff",
				colorLight : "#ffffff",
				correctLevel : QRCode.CorrectLevel.H
			})
		</script>
				';
			} elseif (isset($used) && $used == TRUE) {
				// Code has been used before
				echo '
		<script type="text/javascript">
			document.getElementById("qrcode").innerHTML = "Dieser Code wurde bereits verwendet!";
		</script>
				';
			} else {
				// Code is wrong	
				echo '
		<script type="text/javascript">
			document.getElementById("qrcode").innerHTML = "Dein Code konnte nicht in der Datenbank gefunden werden. Bitte überprüfe deine Eingaben. Wenn du glaubst, dass hier ein Fehler vorliegt, melde dich bitte beim Veranstalter.";<commit_msg>Codes are set to used when logged in<commit_after><?php
	session_start();
	
	// Test login to set codes to used
	if (isset($_POST['user']) && $_POST['user'] == "user" && isset($_POST['pass']) && $_POST['pass'] == "<PASSWORD>") {
		$_SESSION['logged_ind'] = TRUE;
	}
?>
<!DOCTYPE html>
<html lang="de">
	<head>
		<meta charset="utf-8" />

		<title>SSBO Ticketing</title>
		<meta name="description" content="SSBO Ticketing System" />
		<meta name="author" content="<NAME>" />

		<!-- Favicon -->
		<link rel="shortcut icon" href="img/favicon.png" />
		
		<!-- jQuery -->
		<script src="lib/jquery-2.1.0.min.js"></script>
		
		<!-- qrcode -->
		<script src="lib/qrcode.min.js"></script>
		
		<!-- custom method to read out the URL parameters -->
		<script src="js/getParameters.js"></script>
	</head>

	<body>
		<header>
			<h1>SSBO Ticketing</h1>
		</header>
		
		<div id="demo">
			<ul>
				<li>
					<a href="?code=1911332118324935400">Unused code</a>
				</li>
				<li>
					<a href="?code=9751755374018103000">Used code</a>
				</li>
				<li>
					<a href="?code=12345">Wrong code</a>
				</li>
			</ul>
		</div>

		<div id="qrcode">
			<!-- QRCode will be placed here, if the code is valid. If not a message will be prompted to the user. -->
		</div>
		
		<?php
			// Control the code
			$code = $_GET['code'];
	
			// Open a connection to the MySQL server and select the database
			require_once 'db_info.php';
			$connection = mysql_connect($db_host, $db_username, $db_password) or die('Keine Verbindung möglich. Benutzername oder Passwort sind falsch');
			mysql_select_db($db_database) or die('Die Datenbank existiert nicht.');
	
			// Select the row with the correct user_id
			$query = "SELECT * FROM tickets WHERE code = '" . $code . "' LIMIT 1";
			$result = mysql_query($query);
	
			while ($row = mysql_fetch_object($result)) {
				$used = $row -> used;
			}
			
			if (isset($used) && $used == FALSE) {
				if (isset($_SESSION['logged_in'])) {
					// Update the code from unused to used
					$query_update = "UPDATE tickets SET used = true WHERE code = '" . $code . "'";
					mysql_query($query_update);
				}
				
				// Code is correct
				echo '
		<script type="text/javascript">
			// Create the QRCode
			// new QRCode(document.getElementById("qrcode"), getParam("code"));
			new QRCode(document.getElementById("qrcode"), {
				text: getParam("code"),
				width: 256,
				height: 256,
				colorDark : "#0000ff",
				colorLight : "#ffffff",
				correctLevel : QRCode.CorrectLevel.H
			})
		</script>
				';
			} elseif (isset($used) && $used == TRUE) {
				// Code has been used before
				echo '
		<script type="text/javascript">
			document.getElementById("qrcode").innerHTML = "Dieser Code wurde bereits verwendet!";
		</script>
				';
			} else {
				// Code is wrong	
				echo '
		<script type="text/javascript">
			document.getElementById("qrcode").innerHTML = "Dein Code konnte nicht in der Datenbank gefunden werden. Bitte überprüfe deine Eingaben. Wenn du glaubst, dass hier ein Fehler vorliegt, melde dich bitte beim Veranstalter.";
{'fraction_non_alphanumeric': 0.16719353705655077, 'fraction_numerical': 0.02107481559536354, 'mean_word_length': 3.117859725234996, 'pattern_counts': {'":': 0, '<': 108, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1133638', 'n_tokens_mistral': 2370, 'n_tokens_neox': 1909, 'n_words': 511}