Guest User

Untitled

a guest
Feb 15th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.33 KB | None | 0 0
  1. <?php
  2. include('./includes/connections.php');
  3. include('./includes/brain_file.php');
  4. include('./includes/style_top.php');
  5.  
  6. echo "<center><main>Lottery</main>";
  7.  
  8. if($pl['my_jail'] > time() || $pl['my_hosp'] > time()) {
  9.     echo "Sorry this page is not viewable while in jail or hospital!<hr width='750px'/>";
  10. }
  11. if($lottoconfig['pagedisable'] == 'Yes' && $pl['playerid'] != 1) {
  12.         echo "<span style='color:red'>Sorry but admin has disbaled the lottery system.</span>";
  13.         exit;
  14. }
  15.  
  16. $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : '';
  17. switch($_GET['action']) {
  18.         case 'buy': buy_tickets(); break;
  19.         default: lotto(); break;
  20. }
  21.  
  22. function lotto() {
  23.     global $pl,$set,$lottoconfig;
  24.         $count = mysql_query("SELECT `user` FROM `lottery_players`");
  25.         $amt = mysql_num_rows($count);
  26.         echo "
  27.        <img src='http://4e7221.medialib.glogster.com/media/89879e031a5dbed8d1bf0e877ee49cb2a02e02f15f87bde3408ccfcc30c163b1/dollar-sign.png' width='200px' height='100px' /><br /><br />
  28.        <span>Welcome to the lottery</span>
  29.        <span>Each ticket costs <strong>$".number_format($lottoconfig['ticketprice'])."</strong></span><br />
  30.        <span>Maximum of <strong>".number_format($lottoconfig['maxtickets'])."</strong> tickets per person</span>
  31.        <hr width='75%' align='center'>
  32.        <strong>Loto Info</strong><br /><br />
  33.        <span>Jackpot: $".number_format($lottoconfig['ticketprice'] * $amt)."</span><br />
  34.        <span>Tickets Purchased: ".number_format($amt)."</span><br />
  35.        <span>Your Tickets: ".number_format($pl['tickets'])."</span><br /><br />
  36.        <form method='post' action='lottery.php?action=buy'>
  37.             Buy Tickets: <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='2' />
  38.                <button style='background: #BCC6CC; width: 100px; padding: 5px;'>Buy</button>
  39.        </form>";
  40.         if($pl['playerid'] == 1) {
  41.         if(isset($_POST['updatesettings'])) {
  42.                     $_POST['tp'] = isset($_POST['tp']) && ctype_digit($_POST['tp']) ? abs(intval($_POST['tp'])) : 0;
  43.                         $_POST['mut'] = isset($_POST['mut']) && ctype_digit($_POST['mut']) ? abs(intval($_POST['mut'])) : 0;
  44.                    
  45.                         if(empty($_POST['tp']) || empty($_POST['mut'])) {
  46.                             echo "You have missed a required field.";
  47.                             include('./includes/style_bottom.php');
  48.                             exit;
  49.                         }
  50.                         $check = mysql_query("SELECT `ticketprice`,`maxtickets` FROM `lottery_config`");
  51.                         if(mysql_num_rows($check))
  52.                             mysql_query("UPDATE `lottery_config` SET `ticketprice` = {$_POST['tp']}, `maxtickets` = {$_POST['mut']}");
  53.                         else
  54.                             mysql_query("INSERT INTO `lottery_config` VALUES('{$_POST['tp']}','{$_POST['mut']}')");
  55.                         echo "Info has been updated.";
  56.                 }
  57.                 else if(isset($_GET['disable'])) {
  58.                     if($lottoconfig['pagedisable'] == 'Yes') {
  59.                             mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'No' WHERE `pagedisable` = 'Yes'");
  60.                             echo "You have enabled the page again users can access the lottery.";
  61.                         }
  62.                         else {
  63.                             mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'Yes' WHERE `pagedisable` = 'No'");
  64.                             echo "You have disabled the page users can't access the lottery.";
  65.                         }
  66.                 }
  67.                 else {
  68.                     echo "<br /><br /><hr width='50%' align='center'>
  69.                         <h3>Lottery Admin Panel</h3>
  70.                         <p>Fill out the form below to create / update the price and max tickets.</p><br />
  71.                         <form method='post'>
  72.                             Cost Per Ticket: $<input type='text' name='tp' value='1' /><br /><br />
  73.                             Max Tickets Per User: <input type='text' name='mut' value='1' /><br /><br />
  74.                             <input type='submit' name='updatesettings' value='Update Lottery Settings' />
  75.                         </form><br /><br />
  76.                         <a href='lottery.php?disable'>[Turn On/Off Lottery Page]</a>";
  77.                 }
  78.     }
  79.         echo "</div>";
  80.         include ('./includes/style_bottom.php');
  81. }
  82.  
  83. function buy_tickets() {
  84.     global $pl,$lottoconfig;
  85.         $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : 0;
  86.         if(empty($_POST['amount'])) {
  87.             echo "Invalid Format.";
  88.         include ('./includes/style_bottom.php');
  89.             exit;
  90.         }
  91.         $deficit = $lottoconfig['maxtickets'] - $pl['tickets'];
  92.         if($pl['tickets'] + $_POST['amount'] > $lottoconfig['maxtickets']) {
  93.             echo "The max tickets is ".number_format($lottoconfig['maxtickets']).".
  94.             This means you can only buy ".number_format($lottoconfig['maxtickets'] - $pl['tickets'])." more ticket".($deficit == 1 ? '' : 's');
  95.         include ('./includes/style_bottom.php');
  96.             exit;
  97.         }
  98.         if($_POST['amount'] > $lottoconfig['maxtickets']) {
  99.             echo "You can't purchase this amount of tickets..";
  100.             include ('./includes/style_bottom.php');
  101.             exit;
  102.         }
  103.         if($pl['wallet'] < $lottoconfig['ticketprice'] * $_POST['amount']) {
  104.             echo "You don't have enough you need ".number_format($lottoconfig['ticketprice'] * $_POST['amount'] - $pl['wallet']) ." more.";
  105.         include ('./includes/style_bottom.php');
  106.             exit;
  107.         }
  108.         if($pl['wallet'] >= $lottoconfig['ticketprice'] * $_POST['amount'] && $_POST['amount'] <= $lottoconfig['maxtickets']) {  
  109.             $pl['wallet'] -= $lottoconfig['ticketprice'] * $_POST['amount'];
  110.             $pl['tickets'] += $_POST['amount'];
  111.             for($i = 1; $i <= $_POST['amount']; $i++)
  112.                     mysql_query("INSERT INTO `lottery_players` VALUES('{$pl['playerid']}',1)");
  113.             mysql_query("UPDATE `members` SET `wallet` = {$pl['wallet']}, `tickets` = {$pl['tickets']} WHERE `playerid` = ".$pl['playerid']);
  114.             echo "You have purchased ".number_format($_POST['amount'])." tickets for $".number_format($lottoconfig['ticketprice'] * $_POST['amount']);
  115.         }
  116.     include ('./includes/style_bottom.php');
  117. }
Advertisement
Add Comment
Please, Sign In to add comment