Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('./includes/connections.php');
- include('./includes/brain_file.php');
- include('./includes/style_top.php');
- echo "<center><main>Lottery</main>";
- if($pl['my_jail'] > time() || $pl['my_hosp'] > time()) {
- echo "Sorry this page is not viewable while in jail or hospital!<hr width='750px'/>";
- }
- if($lottoconfig['pagedisable'] == 'Yes' && $pl['playerid'] != 1) {
- echo "<span style='color:red'>Sorry but admin has disbaled the lottery system.</span>";
- exit;
- }
- $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : '';
- switch($_GET['action']) {
- case 'buy': buy_tickets(); break;
- default: lotto(); break;
- }
- function lotto() {
- global $pl,$set,$lottoconfig;
- $count = mysql_query("SELECT COUNT(`user`) FROM `lottery_players` AS `players`");
- $amt = mysql_fetch_row($count);
- echo "
- <img src='http://4e7221.medialib.glogster.com/media/89879e031a5dbed8d1bf0e877ee49cb2a02e02f15f87bde3408ccfcc30c163b1/dollar-sign.png'
- width='200px' height='100px' /><br /><br />
- <span>Welcome to the lottery</span>
- <span>Each ticket costs <strong>".number_format($lottoconfig['ticketprice'])."</strong></span><br />
- <span>Maximum of <strong>".number_format($lottoconfig['maxtickets'])."</strong> tickets per person</span>
- <hr width='75%' align='center'>
- <strong>Loto Info</strong><br /><br />
- <span>Jackpot: ".number_format($lottoconfig['ticketprice'] * $amt['players'])."</span><br />
- <span>Tickets Purchased: ".number_format($amt['players'])."</span><br />
- <span>Your Tickets: ".number_format($pl['tickets'])."</span><br /><br />
- <form method='post' action='lottery.php?action=buy'>
- Buy Tickets: <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='2' />
- <button style='background: #BCC6CC; width: 100px; padding: 5px;'>Buy</button>
- </form>";
- if($pl['playerid'] == 1)
- {
- if(isset($_POST['updatesettings']))
- {
- $_POST['tp'] = isset($_POST['tp']) && ctype_digit($_POST['tp']) ? abs(intval($_POST['tp'])) : 0;
- $_POST['mut'] = isset($_POST['mut']) && ctype_digit($_POST['mut']) ? abs(intval($_POST['mut'])) : 0;
- if(empty($_POST['tp']) || empty($_POST['mut']))
- {
- echo "You have missed a required field.";
- exit;
- }
- $check = mysql_query("SELECT `ticketprice`,`maxtickets` FROM `lottery_config`");
- if(mysql_num_rows($check))
- mysql_query("UPDATE `lottery_config` SET `ticketprice` = {$_POST['tp']}, `maxtickets` = {$_POST['mut']}");
- else
- mysql_query("INSERT INTO `lottery_config` VALUES('{$_POST['tp']}','{$_POST['mut']}')");
- echo "Info has been updated.";
- }
- else if(isset($_GET['disable']))
- {
- $select = mysql_query("SELECT `pagedisable` FROM `lottery_config`");
- if(mysql_fetch_single($select) == 'Yes')
- {
- mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'No' WHERE `pagedisable` = 'Yes'");
- echo "You have enabled the page again users can access the lottery.";
- }
- else
- {
- mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'Yes' WHERE `pagedisable` = 'No'");
- echo "You have disabled the page users can't access the lottery.";
- }
- }
- else
- {
- echo "<br /><br /><hr width='50%' align='center'>
- <h3>Lottery Admin Panel</h3>
- <p>Fill out the form below to create / update the price and max tickets.</p><br />
- <form method='post'>
- Cost Per Ticket: $<input type='text' name='tp' value='1' /><br /><br />
- Max Tickets Per User: <input type='text' name='mut' value='1' /><br /><br />
- <input type='submit' name='updatesettings' value='Update Lottery Settings' />
- </form><br /><br />
- <a href='lottery.php?disable'>[Turn On/Off Lottery Page]</a>";
- }
- }
- echo "</div>";
- }
- function buy_tickets()
- {
- global $pl,$lottoconfig;
- $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : 0;
- if(empty($_POST['amount']))
- {
- echo "Invalid Format.";
- exit;
- }
- $deficit = $lottoconfig['maxtickets'] - $pl['tickets'];
- if($pl['tickets'] + $_POST['amount'] > $lottoconfig['maxtickets'])
- {
- echo "The max tickets is ".number_format($lottoconfig['maxtickets']).".
- This means you can only buy ".number_format($lottoconfig['maxtickets'] - $pl['tickets'])." more ticket".($deficit == 1 ? '' : 's');
- exit;
- }
- if($_POST['amount'] > $lottoconfig['maxtickets'])
- {
- echo "You can't purchase this amount of tickets..";
- exit;
- }
- if($pl['wallet'] < $lottoconfig['ticketprice'] * $_POST['amount'])
- {
- echo "You don't have enough you need ".number_format($lottoconfig['ticketprice'] * $_POST['amount'] - $pl['wallet']) ." more.";
- exit;
- }
- if($pl['wallet'] >= $lottoconfig['ticketprice'] * $_POST['amount'] && $_POST['amount'] <= $lottoconfig['maxtickets'])
- {
- $pl['wallet'] -= $lottoconfig['ticketprice'] * $_POST['amount'];
- $pl['tickets'] += $_POST['amount'];
- for($i = 1; $i <= $_POST['amount']; $i++)
- mysql_query("INSERT INTO `lottery_players` VALUES('{$pl['userid']}')");
- mysql_query("UPDATE `members` SET `wallet` = {$pl['wallet']}, `tickets` = {$pl['tickets']} WHERE `userid` = {$pl['playerid']}");
- echo "You have purchased ".number_format($_POST['amount'], '')." tickets for ".number_format($lottoconfig['ticketprice'] * $_POST['amount']);
- }
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment