<?php
require('includes/settings.php');
require('includes/mysql_connect.php');
require('includes/funcs.php');
$p_bonus_code = sanitize($_POST['bonus-code']);


if ($p_bonus_code == $g_TestCode)
{
	echo "valid";
	exit();
}


if ($p_bonus_code == null || !preg_match('/^[A-Z]{3}\d{3}$/', $p_bonus_code))
{
	echo "fail";
	exit();
}

$check_code_sql = "SELECT intBonusCodeID from ".$g_KioskBonusCodesTableName." where strBonusCode = '$p_bonus_code' and ynUsed = 'N'";
$check_code_result = getFromDatabase($check_code_sql);
if(mysqli_num_rows($check_code_result) != 1)
{
	echo "fail";
	exit();
}

echo "valid";

?>
