Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.48 KB | None | 0 0
  1. <?
  2. require("_game-header.php");
  3.  
  4.  
  5.  
  6. $totaltickets = mysql_query("SELECT SUM(ticket) FROM raffle_tickets");
  7. $row = mysql_fetch_assoc($totaltickets, MYSQL_ASSOC);
  8. $totaltickets =  $row["SUM(ticket)"];
  9.  
  10. echo $totaltickets ."<br>";
  11.  
  12. $usertickets = mysql_query("SELECT ticket FROM raffle_tickets WHERE owner='$accinfo[uniqueid]'");
  13. $row = mysql_fetch_assoc($usertickets, MYSQL_ASSOC);
  14. $usertickets = $row["ticket"];
  15.  
  16. echo $usertickets;
  17.  
  18. // Let's figure out the users win chance.
  19.  
  20. if($usertickets > 0)
  21. {
  22.     $winchance = ($usertickets / $totaltickets * 100);
  23.     $winchance = number_format($winchance,2);
  24.  
  25. }
  26.  
  27. // The user doesn't have tickets, let's tell them.
  28. else
  29. {
  30.     $winchance = "0.00";
  31. }
  32.  
  33.     $totalpot = $totaltickets * $_rafflecost;
  34.     $totalpot = number_format($totalpot);
  35.  
  36. if($action == "")
  37. {
  38.  
  39.     $q=mysql_query("SELECT field, data FROM settings WHERE field='rafflewinner' or field='rafflewinning' or field='raffleticket'");
  40.     while($r=mysql_fetch_array($q))
  41.     {
  42.         if($r['field']=="rafflewinner")
  43.         {
  44.             $q2=mysql_query("SELECT uniqueid, username FROM user_maininfo WHERE uniqueid='{$r['data']}'");
  45.             $winner=mysql_fetch_array($q2);
  46.         }
  47.         elseif($r['field']=="rafflewinning"){$totalpot=$r['data'];}
  48.         else{$winningticket=$r['data'];}
  49.  
  50.     }
  51. }
  52.  
  53. //echo "<br><center>
  54. //Last Week's Winner is Lottery Ticket Number <b><font color=yellow>$winner</font></b>!!!<br>The lucky owner of this ticket was none other than <b><a href=game-viewuser.php?idname=$winner[uniqueid]>$winner[username]</a></b> who received ".number_format($totalpot)." gold!!!
  55. echo "<br><center><table border=1 cellspacing=0 cellpadding=5><tr></center>";
  56. echo "<td><center><b>Total Lottery Tickets<td><center><b>Total Pot This Week<td><center><b>Your Tickets This Week<td><center><b>Your Chance of Winning";
  57. echo "<tr><td><center>$totaltickets Tickets<td><center>$totalpot Gold<td><center>$usertickets Tickets<td><center>$winchance%";
  58. echo "</table><br><br></center>";
  59. echo "<b>Raffle Organiser:</b> The Lottery of the Realm is a draw that occurs on a <u>Sunday Evening at 9pm GMT (Server Time)</u>. Out of all the tickets, there will be <b>one</b> winner that is lucky enough to take home the whole pot! Minus a small fee of course.<br><br><b>Raffle Organiser:</b> You can buy tickets here from myself for a mere <b>$_rafflecost gold</b> each, and bear in mind the more you have, the better chance you have to win. So how many do you want to buy from me today?";
  60.  
  61. echo "<br><br><center><form action=lottery.php method=post><input type=hidden name=action value=buy2>";
  62. echo "<table border=1 cellspacing=0 cellpadding=5><tr>";
  63. echo "<td><center><b>Buy Tickets:<td><center><input type=text name=amount size=5>";
  64. echo "<tr><td colspan=2><center><input type=submit value='Buy Lottery Tickets'></table></form><br><br>";
  65.  
  66. // If number isn't a positive amount to purchase tickets. Throw Error!
  67.  
  68. if($action == "buy2") {
  69.     echo "buy 2 check";
  70.  
  71.     $totalprice = $amount * $_rafflecost;
  72.     if (isset($amount) && $amount < 1 && is_numeric($amount) && (ctype_digit($amount) != true)) {
  73.         echo "<br><center><font color=red><b>Error:</b></font> You need to enter a whole positive amount to purchase tickets.<br>";
  74.         echo "<br>[<a href=lottery.php>Back to Raffle Shop</a>]";
  75.     }
  76.  
  77.  
  78.     if ($action == "buy2") {
  79.         echo "buy check";
  80.         $totalprice = $amount * $_rafflecost;
  81.  
  82.         if ($amount == 0) ;
  83.         {
  84.             echo "<br><center><font color=red><b>Error:</b></font> You need to enter a whole positive amount to purchase tickets.<br>";
  85.             echo "<br>[<a href=lottery.php>Back to Raffle Shop</a>]";
  86.         }
  87.  
  88.         if ($amount > 1) {
  89.             $ticket = "tickets";
  90.         } elseif ($amount == 1) {
  91.             $ticket = "ticket";
  92.  
  93.             echo "<br><center><b>Lottery Organiser:</b> So you want to buy <b>$amount</b> lottery $ticket at the price of $_rafflecost gold each, which totals <b>" . number_format($totalprice) . "</b> gold?";
  94.             echo "<br><br><table border=1 cellspacing=0 cellpadding=5><tr>";
  95.             echo "<td colspan=2><center><input type=submit value='Buy Tickets'></table></form>";
  96.         }
  97.  
  98.         if ($accwealth[gold] < $totalprice) {
  99.             echo "<br><center><font color=red><b>Error:</b></font> You don't have the funds available to buy this many tickets.<br>";
  100.             echo "<br>[<a href=lottery.php>Back to Raffle Shop</a>]";
  101.             include("_game-footer.php");
  102.             exit;
  103.         }
  104.  
  105.         if ($amount > 1) {
  106.             $ticket = "tickets";
  107.         } elseif ($amount == 1) {
  108.             $ticket = "ticket";
  109.         }
  110.  
  111.         echo "<br><center><font color=yellow><b>Success:</b></font> You have bought <b>$amount</b> $ticket for the cost of <b>$totalprice</b>. Your new lottery ticket numbers have been added to this weeks draw.";
  112.     }
  113. }
  114.  
  115.     $newtickets = $ticketamount;
  116.     mysql_query("INSERT INTO player_log (type,time,user,detail) VALUES ('Raffle-Buy','$fulltime','$accinfo[uniqueid]','Bought $amount lottery tickets for a cost of $totalprice gold.')");
  117.  
  118.     mysql_query("INSERT INTO raffle_tickets (ticket,owner) VALUES ('$ticketamount','$accinfo[uniqueid]') LIMIT 1");
  119.  
  120.  
  121.     $totalprice = mysql_real_escape_string($totalprice);
  122.     mysql_query("UPDATE user_economy SET gold=gold-$totalprice WHERE uniqueid='$accinfo[uniqueid]' LIMIT 1");
  123.     echo "<br><br>[<a href=game-raffle.php>Back to Raffle Shop</a>]<br><br>";
  124.  
  125.  
  126.  
  127.  
  128. include("_game-footer.php");
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement