Guest User

lottery.php

a guest
Feb 13th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.43 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' && $pl['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.     $count = mysql_query("SELECT COUNT(`user`) FROM `lottery_players`");
  24.     $amt = mysql_fetch_single($count);
  25.     echo "<h4>Lottery</h4>
  26.         <div style='background:#ececec; width: 400px; padding: 7px; border: 1px solid gray;'>
  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>".money_formatter($lottoconfig['ticketprice'])."</strong></span><br />
  31.             <span>Maximum of <strong>".money_formatter($lottoconfig['maxtickets'], '')."</strong> tickets per person</span>
  32.             <hr width='75%' align='center'>
  33.             <strong>Loto Info</strong><br /><br />
  34.             <span>Jackpot: ".money_formatter($lottoconfig['ticketprice'] * $amt)."</span><br />
  35.             <span>Tickets Purchased: ".money_formatter($amt, '')."</span><br />
  36.             <span>Your Tickets: ".money_formatter($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.     $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : 0;
  96.     if(empty($_POST['amount']))
  97.     {
  98.         echo "Invalid Format.";
  99.    
  100.         exit;
  101.     }
  102.     $deficit = $lottoconfig['maxtickets'] - $pl['tickets'];
  103.     if($pl['tickets'] + $_POST['amount'] > $lottoconfig['maxtickets'])
  104.     {
  105.         echo "The max tickets is ".number_format($lottoconfig['maxtickets']).".
  106.         This means you can only buy ".number_format($lottoconfig['maxtickets'] - $pl['tickets'])." more ticket".($deficit == 1 ? '' : 's');
  107.  
  108.         exit;
  109.     }
  110.     if($_POST['amount'] > $lottoconfig['maxtickets'])
  111.     {
  112.         echo "You can't purchase this amount of tickets..";
  113.        
  114.         exit;
  115.     }
  116.     if($pl['wallet'] < $lottoconfig['ticketprice'] * $_POST['amount'])
  117.     {
  118.         echo "You don't have enough you need ".money_formatter($lottoconfig['ticketprice'] * $_POST['amount'] - $pl['wallet']) ." more.";
  119.    
  120.         exit;
  121.     }
  122.     if($pl['wallet'] >= $lottoconfig['ticketprice'] * $_POST['amount'] && $_POST['amount'] <= $lottoconfig['maxtickets'])
  123.     {  
  124.         $pl['wallet'] -= $lottoconfig['ticketprice'] * $_POST['amount'];
  125.         $pl['tickets'] += $_POST['amount'];
  126.         for($i = 1; $i <= $_POST['amount']; $i++)
  127.             mysql_query("INSERT INTO `lottery_players` VALUES('{$pl['userid']}')");
  128.         mysql_query("UPDATE `members` SET `wallet` = {$pl['wallet']}, `tickets` = {$pl['tickets']} WHERE `userid` = {$pl['userid']}");
  129.         echo "You have purchased ".money_formatter($_POST['amount'], '')." tickets for ".money_formatter($lottoconfig['ticketprice'] * $_POST['amount']);
  130.     }
  131. exit();
  132. }
Advertisement
Add Comment
Please, Sign In to add comment