Guest User

Untitled

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