Guest User

Untitled

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