Guest User

Untitled

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