<?php 
require('includes/settings.php');
require('includes/mysql_connect.php');
require('includes/funcs.php');

echo "starting...";
function NotFB()
{
	do
	{
		$a1 = chr(65 + rand(0,25));
		$a2 = chr(65 + rand(0,25));
	}
	while($a1 == "F" && $a2 == "B");
	
	return $a1 . $a2;
}
echo "1...";
for ($i=0; $i < 3000 ; $i++) 
{ 
	//$code = strtoupper(substr(md5(uniqid(rand(), true)), 3, 5));
	$code = NotFB() . chr(65 + rand(0,25)) . rand(1,9) . rand(1,9) . rand(1,9);
	// check to see if already in db
	$check_sql = "SELECT intBonusCodeID from tblKioskBonusCodesParkPlace2017 where strBonusCode = '$code'";
	$check_result = getFromDatabase($check_sql);
	if (mysqli_num_rows($check_result) == 0)
	{
		$insert_sql = "INSERT into tblKioskBonusCodesParkPlace2017 (strBonusCode, intCodeType) VALUES ('$code', 1)";
		$insert_result = getFromDatabase($insert_sql);
	}
	else
	{
		$i -= 1;
	}
}
echo "2...";

for ($i=0; $i < 3000 ; $i++) 
{	// food bank type="2"
	//$code = strtoupper(substr(md5(uniqid(rand(), true)), 3, 5));
	$code = "FB" . chr(65 + rand(0,25)) . rand(1,9) . rand(1,9) . rand(1,9);
	// check to see if already in db
	$check_sql = "SELECT intBonusCodeID from tblKioskBonusCodesParkPlace2017 where strBonusCode = '$code'";
	$check_result = getFromDatabase($check_sql);
	if (mysqli_num_rows($check_result) == 0)
	{
		$insert_sql = "INSERT into tblKioskBonusCodesParkPlace2017 (strBonusCode, intCodeType) VALUES ('$code', 2)";
		$insert_result = getFromDatabase($insert_sql);
	}
	else
	{
		$i -= 1;
	}
}
echo "3...";
for ($i=0; $i < 3000 ; $i++) 
{ 
	//$code = strtoupper(substr(md5(uniqid(rand(), true)), 3, 5));
	$code = NotFB() . chr(65 + rand(0,25)) . rand(1,9) . rand(1,9) . rand(1,9);
	// check to see if already in db
	$check_sql = "SELECT intBonusCodeID from tblKioskBonusCodesParkPlace2017 where strBonusCode = '$code'";
	$check_result = getFromDatabase($check_sql);
	if (mysqli_num_rows($check_result) == 0)
	{
		$insert_sql = "INSERT into tblKioskBonusCodesParkPlace2017 (strBonusCode, intCodeType) VALUES ('$code', 3)";
		$insert_result = getFromDatabase($insert_sql);
	}
	else
	{
		$i -= 1;
	}
}
echo "DONE";
?>