Location: PHPKode > projects > Trunk.net > purchasetickets.php
<?

require "include/functions.php";

$res = mysql_query("SELECT * FROM lottery_config") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
$arr_config[$arr['name']] = $arr['value'];

$endday = $arr_config['end_date'];

if (!$arr_config["enable"])
stderr("Sorry", "Lottery is disabled.");

dbconn();

loggedinorreturn();

$ticket_amount_display = $arr_config['ticket_amount'];

if ($arr_config["ticket_amount_type"] == GB)
$arr_config['ticket_amount'] = 1024 * 1024 * 1024 * $arr_config['ticket_amount'];
else if ($arr_config["ticket_amount_type"] == MB)
$arr_config['ticket_amount'] = 1024 * 1024 * $arr_config['ticket_amount'];
$size = $arr_config['ticket_amount'];

$minupload = $size; //Minimum Upload Required to Buy Ticket!

stdhead("Tickets Page");

if (get_user_class() < 0)
{
print("<h1>Sorry</h2><p>You must be Registered to request, see the <a href=faq.php><b>FAQ</b></a> for information on different user classes</p>");
die();
}

if (get_date_time() > $arr_config['end_date'])
{
print ("Sorry I cannot sell you any tickets!");
die();
}

$res = mysql_query("SELECT downloaded, uploaded FROM users WHERE id = $CURUSER[id]") or die(mysql_error());
$result = mysql_fetch_assoc($res);

$res2 = mysql_query("SELECT COUNT(id) AS tickets FROM tickets WHERE user = $CURUSER[id]") or die(mysql_error());
$result2 = mysql_fetch_assoc($res2);

$purchaseable = $arr_config['user_tickets'];
if (($result2['tickets'] + $_REQUEST['number']) > $purchaseable || $_REQUEST['number'] < 1 )
{
print("<table class=frame width=737 cellspacing=0 cellpadding=5><tr><td><table class=main width=100% cellspacing=0 cellpadding=5><tr><td class=colhead align=left>ERROR</td></tr><tr><td>The max number of tickets you can purchase is $purchaseable<br></td></tr></table></td></tr></table>");
stdfoot();
die;
}

if (($minupload * $_REQUEST['number']) > $result["uploaded"] )
{
print("<table class=frame width=737 cellspacing=0 cellpadding=5><tr><td><table class=main width=100% cellspacing=0 cellpadding=5><tr><td class=colhead align=left>ERROR</td></tr><tr><td>You do not have enough upload amount to buy a ticket<br></td></tr></table></td></tr></table>");
stdfoot();
die;
}
$upload = $result["uploaded"] - ($minupload * $_REQUEST['number']);
mysql_query("UPDATE users SET uploaded=$upload WHERE id=". $CURUSER["id"]) or die(mysql_error());
$tickets = $_REQUEST['number'];
for ($i = 0; $i < $tickets; $i++)
mysql_QUERY("INSERT INTO tickets(user) VALUES($CURUSER[id])");
$me = mysql_num_rows(mysql_query("SELECT * FROM tickets WHERE user=" . $CURUSER["id"]));
print("<br>\n");

?>
<table border=1 width=600 cellspacing=0 cellpadding=5>
<tr><td class=tabletitle width=600 align=center>iMT Lottery</td></tr>
<tr><td class=tableb align=left>
You just purchased <?= $_REQUEST["number"]; ?> ticket<? if ($_REQUEST["number"] > 1) echo "s"; ?>!<br>
Your new total is <?= $me; ?>!<br>
Your new upload total is <?= mksize($upload); ?>!<br><br>
<a href=tickets.php>Go Back</a>
</td></tr></table>

<?
print("<br>\n");

stdfoot();
die;

?>
Return current item: Trunk.net