Guest User

Untitled

a guest
Feb 15th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.40 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 COUNT(`user`) FROM `lottery_players` AS `players`");
  25.         $amt = mysql_fetch_row($count);
  26.         echo "
  27.            <img src='http://4e7221.medialib.glogster.com/media/89879e031a5dbed8d1bf0e877ee49cb2a02e02f15f87bde3408ccfcc30c163b1/dollar-sign.png'
  28.                width='200px' height='100px' /><br /><br />
  29.            <span>Welcome to the lottery</span>
  30.            <span>Each ticket costs <strong>".number_format($lottoconfig['ticketprice'])."</strong></span><br />
  31.            <span>Maximum of <strong>".number_format($lottoconfig['maxtickets'])."</strong> tickets per person</span>
  32.            <hr width='75%' align='center'>
  33.            <strong>Loto Info</strong><br /><br />
  34.            <span>Jackpot: ".number_format($lottoconfig['ticketprice'] * $amt['players'])."</span><br />
  35.            <span>Tickets Purchased: ".number_format($amt['players'])."</span><br />
  36.            <span>Your Tickets: ".number_format($pl['tickets'])."</span><br /><br />
  37.            <form method='post' action='lottery.php?action=buy'>
  38.                Buy Tickets: <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='2' />
  39.                <button style='background: #BCC6CC; width: 100px; padding: 5px;'>Buy</button>
  40.            </form>";
  41.             if($pl['playerid'] == 1)
  42.             {
  43.                 if(isset($_POST['updatesettings']))
  44.                 {
  45.                     $_POST['tp'] = isset($_POST['tp']) && ctype_digit($_POST['tp']) ? abs(intval($_POST['tp'])) : 0;
  46.                     $_POST['mut'] = isset($_POST['mut']) && ctype_digit($_POST['mut']) ? abs(intval($_POST['mut'])) : 0;
  47.                    
  48.                     if(empty($_POST['tp']) || empty($_POST['mut']))
  49.                     {
  50.                         echo "You have missed a required field.";
  51.                        
  52.                         exit;
  53.                     }
  54.                    
  55.                     $check = mysql_query("SELECT `ticketprice`,`maxtickets` FROM `lottery_config`");
  56.                     if(mysql_num_rows($check))
  57.                         mysql_query("UPDATE `lottery_config` SET `ticketprice` = {$_POST['tp']}, `maxtickets` = {$_POST['mut']}");
  58.                     else
  59.                         mysql_query("INSERT INTO `lottery_config` VALUES('{$_POST['tp']}','{$_POST['mut']}')");
  60.                     echo "Info has been updated.";
  61.                 }
  62.                 else if(isset($_GET['disable']))
  63.                 {
  64.                     $select = mysql_query("SELECT `pagedisable` FROM `lottery_config`");
  65.                     if(mysql_fetch_single($select) == 'Yes')
  66.                     {
  67.                         mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'No' WHERE `pagedisable` = 'Yes'");
  68.                         echo "You have enabled the page again users can access the lottery.";
  69.                     }
  70.                     else
  71.                     {
  72.                         mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'Yes' WHERE `pagedisable` = 'No'");
  73.                         echo "You have disabled the page users can't access the lottery.";
  74.                     }
  75.                 }
  76.                 else
  77.                 {
  78.                     echo "<br /><br /><hr width='50%' align='center'>
  79.                    <h3>Lottery Admin Panel</h3>
  80.                    <p>Fill out the form below to create / update the price and max tickets.</p><br />
  81.                    <form method='post'>
  82.                        Cost Per Ticket: $<input type='text' name='tp' value='1' /><br /><br />
  83.                        Max Tickets Per User: <input type='text' name='mut' value='1' /><br /><br />
  84.                        <input type='submit' name='updatesettings' value='Update Lottery Settings' />
  85.                    </form><br /><br />
  86.                    <a href='lottery.php?disable'>[Turn On/Off Lottery Page]</a>";
  87.                 }
  88.             }
  89.         echo "</div>";
  90.  
  91. }
  92.  
  93. function buy_tickets()
  94. {
  95.     global $pl,$lottoconfig;
  96.     $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : 0;
  97.     if(empty($_POST['amount']))
  98.     {
  99.         echo "Invalid Format.";
  100.    
  101.         exit;
  102.     }
  103.     $deficit = $lottoconfig['maxtickets'] - $pl['tickets'];
  104.     if($pl['tickets'] + $_POST['amount'] > $lottoconfig['maxtickets'])
  105.     {
  106.         echo "The max tickets is ".number_format($lottoconfig['maxtickets']).".
  107.        This means you can only buy ".number_format($lottoconfig['maxtickets'] - $pl['tickets'])." more ticket".($deficit == 1 ? '' : 's');
  108.  
  109.         exit;
  110.     }
  111.     if($_POST['amount'] > $lottoconfig['maxtickets'])
  112.     {
  113.         echo "You can't purchase this amount of tickets..";
  114.        
  115.         exit;
  116.     }
  117.     if($pl['wallet'] < $lottoconfig['ticketprice'] * $_POST['amount'])
  118.     {
  119.         echo "You don't have enough you need ".number_format($lottoconfig['ticketprice'] * $_POST['amount'] - $pl['wallet']) ." more.";
  120.    
  121.         exit;
  122.     }
  123.     if($pl['wallet'] >= $lottoconfig['ticketprice'] * $_POST['amount'] && $_POST['amount'] <= $lottoconfig['maxtickets'])
  124.     {  
  125.         $pl['wallet'] -= $lottoconfig['ticketprice'] * $_POST['amount'];
  126.         $pl['tickets'] += $_POST['amount'];
  127.         for($i = 1; $i <= $_POST['amount']; $i++)
  128.             mysql_query("INSERT INTO `lottery_players` VALUES('{$pl['userid']}')");
  129.         mysql_query("UPDATE `members` SET `wallet` = {$pl['wallet']}, `tickets` = {$pl['tickets']} WHERE `userid` = {$pl['playerid']}");
  130.         echo "You have purchased ".number_format($_POST['amount'], '')." tickets for ".number_format($lottoconfig['ticketprice'] * $_POST['amount']);
  131.     }
  132. exit();
  133. }
Advertisement
Add Comment
Please, Sign In to add comment