function lotto_claimTicket() { global $DB; global $MySelf; $LOTTO_MAX_PERCENT = getConfig("lottoPercent"); if (!getConfig("lotto")) { makeNotice("Your CEO disabled the Lotto module, request denied.", "warning", "Lotto Module Offline"); } // Only people with parents consent may play! if (!$MySelf->canPlayLotto()) { makeNotice("Im sorry, but you are not allowed to play Lotto. " . "Ask your CEO or a friendly Director to enable this for you.", "warning", "Unable to play :("); } // Ticket ID sane? numericCheck($_GET[ticket], 0); $ticket = $_GET[ticket]; // Get the drawing ID. $drawing = lotto_getOpenDrawing(); // Get my credits $MyStuff = $DB->getRow("SELECT lottoCredit, lottoCreditsSpent FROM users WHERE id='" . $MySelf->getID() . "'"); $Credits = $MyStuff[lottoCredit]; $CreditsSpent = $MyStuff[lottoCreditsSpent]; // Are we broke? if ($Credits < 1) { makeNotice("You can not afford the ticket, go get more credits!", "warning", "You're broke!'", "index.php?action=lotto", "[ashamed]"); } // Now check if we bust it. $myTickets = lotto_checkRatio($drawing); if ($myTickets <= 0) { makeNotice("You are already owning the maximum allowed tickets!", "warning", "Exceeded ticket ratio!", "index.php?action=lotto", "[Cancel]"); } // Deduct credit from account. $newcount = $Credits - 1; $DB->query("UPDATE users SET lottoCredit='{$newcount}' WHERE id='" . $MySelf->getID() . "' LIMIT 1"); if ($DB->affectedRows() != 1) { makeNotice("Internal Error: Problem with your bank account... :(", "error", "Internal Error", "index.php?action=lotto", "[Cancel]"); } // Add to "Spent". $spent = $CreditsSpent + 1; $DB->query("UPDATE users SET lottoCreditsSpent='{$spent}' WHERE id='" . $MySelf->getID() . "' LIMIT 1"); if ($DB->affectedRows() != 1) { makeNotice("Internal Error: Problem with your bank account... :(", "error", "Internal Error", "index.php?action=lotto", "[Cancel]"); } // Lets check that the ticket is still unclaimed. $Ticket = $DB->getCol("SELECT owner FROM lotteryTickets WHERE ticket='{$ticket}' AND drawing='{$drawing}'"); if ($Ticket[0] >= 0) { makeNotice("Im sorry, but someone else was faster that you and already claimed that ticket.", "warning", "Its gone, Jim!", "index.php?action=lotto", "[Damn!]"); } // Give him the ticket. $DB->query("UPDATE lotteryTickets SET owner='" . $MySelf->getID() . "' WHERE ticket='{$ticket}' AND drawing='{$drawing}' LIMIT 1"); if ($DB->affectedRows() == 1) { Header("Location: index.php?action=lotto"); } else { makeNotice("Internal Error: Could not grant you the ticket :(", "error", "Internal Error", "index.php?action=lotto", "[Cancel]"); } }
function lotto_playLotto() { // Globals, as usual. global $DB; global $MySelf; $LOTTO_MAX_PERCENT = getConfig("lottoPercent"); $ID = $MySelf->getID(); // is Lotto enabled at all? if (!getConfig("lotto")) { makeNotice("Your CEO disabled the Lotto module, request denied.", "warning", "Lotto Module Offline"); } // Only people with parents consent may play! if (!$MySelf->canPlayLotto()) { makeNotice("Im sorry, but you are not allowed to play Lotto. " . "Ask your CEO or a friendly Director to enable this for you.", "warning", "Unable to play :("); } // Get my credits $MyStuff = $DB->getRow("SELECT lottoCredit, lottoCreditsSpent FROM users WHERE id='" . $MySelf->getID() . "'"); $Credits = $MyStuff[lottoCredit]; $CreditsSpent = $MyStuff[lottoCreditsSpent]; // Handle empty accounts. if ($Credits < 1) { $Credits = "None"; } if ($CreditsSpent < 1) { $CreditsSpent = "None"; } // My Info Table. $MyInfo = new table(2, true); $MyInfo->addHeader(">> My lotto assets"); $MyInfo->addRow(); $MyInfo->addCol("My balance (tickets):"); $MyInfo->addCol($Credits); $MyInfo->addRow(); $MyInfo->addCol("Total spent (tickets):"); $MyInfo->addCol($CreditsSpent); $MyInfo->addHeader("Need more credits? <a href=\"index.php?action=buycredits\">Buy them here!</a>"); // Print resent pots. $MyWins = new table(4, true); $MyWins->addHeader(">> Recent jackpots"); $MyWins->addRow("#060622"); $MyWins->addCol("Drawing"); $MyWins->addCol("Winner"); $MyWins->addCol("Winning Ticket"); $MyWins->addCol("Jackpot"); $Jackpots = $DB->query("SELECT * FROM lotto WHERE isOpen='0'"); if ($Jackpots->numRows() >= 1) { while ($jp = $Jackpots->fetchRow()) { // $TotalTickets_DS = $DB->Query("SELECT ticket FROM lotteryTickets WHERE drawing='" . $woot[drawing] . "' AND owner >= '0'"); // $TotalTickets = $TotalTickets_DS->numRows(); $MyWins->addRow(); $MyWins->addCol("<a href=\"index.php?action=lotto&showdrawing=" . $jp[drawing] . "\">#" . str_pad($jp[drawing], 3, "0", STR_PAD_LEFT) . "</a>"); if ($jp[winner] == "-1") { $MyWins->addCol("<i>No one</i>"); } else { $MyWins->addCol(ucfirst(idToUsername($jp[winner]))); } $MyWins->addCol("#" . str_pad($jp[winningTicket], 3, "0", STR_PAD_LEFT)); $MyWins->addCol(number_format($jp[potSize]) . " ISK"); $GotWinners = true; } } $drawingID = lotto_getOpenDrawing(); $drawingID = $drawingID[0]; // Load the current drawing. if (!$_GET[showdrawing]) { $drawingID = lotto_getOpenDrawing(); //$drawingID = $drawingID[0]; } else { numericCheck($_GET[showdrawing], 0); $drawingID = $_GET[showdrawing]; } // jackpot! WOOT! $Jackpot = $DB->getCol("SELECT value FROM config WHERE name='jackpot' LIMIT 1"); if ($drawingID != is_null()) { $currentBuyin = $DB->getCol("SELECT COUNT(*) FROM lotteryTickets WHERE drawing=" . $drawingID . " AND owner >=0"); $totalJackpot = $Jackpot[0] + $currentBuyin[0] * 1000000; } $MyWins->addHeader("The current jackpot is at " . number_format($totalJackpot, 2) . " ISK."); // $MyWins->addHeader("Please contact your lotto officer to claim your prize."); // Only do this if we have an open drawing, doh! if ($drawingID != is_null()) { $TICKETS = $DB->query("SELECT * FROM lotteryTickets WHERE drawing = '{$drawingID}' ORDER BY ticket"); $allowedTickets = lotto_checkRatio($drawingID); // Table header $drawing = new table(2, true); $drawing->addHeader(">> Drawing #{$drawingID}"); // 1=left side, 0=right side. $side = 1; while ($ticket = $TICKETS->fetchRow()) { $ticketCount++; // If we are on the left side, open up a new table row. if ($side == 1) { $drawing->addRow(); } // Ticket owned already? if ($ticket[owner] == -1) { if ($Credits >= 1 && $allowedTickets > 0) { $drawing->addCol("<a href=\"index.php?action=claimTicket&drawing={$max}&ticket=" . $ticket[ticket] . "\">#" . str_pad($ticket[ticket], 4, "0", STR_PAD_LEFT) . "</a> (unclaimed)"); } else { $drawing->addCol("#" . str_pad($ticket[ticket], 4, "0", STR_PAD_LEFT) . " (unclaimed)"); } } elseif ($ticket[owner] >= 0) { // Increase the chances counter. if ($ticket[owner] == $ID) { $chances++; } if ($ticket[isWinner]) { $drawing->addCol("#" . str_pad($ticket[ticket], 4, "0", STR_PAD_LEFT) . " (" . idToUsername($ticket[owner]) . ") <font color=\"#00ff00\"><b>WINNER!</b></font>"); } else { $drawing->addCol("#" . str_pad($ticket[ticket], 4, "0", STR_PAD_LEFT) . " (" . idToUsername($ticket[owner]) . ")"); } } else { if ($ticket[isWinner]) { $drawing->addCol("#" . str_pad($ticket[ticket], 4, "0", STR_PAD_LEFT) . " (locked) <font color=\"#00ff00\"><b>WINNER!</b></font>"); } else { $drawing->addCol("#" . str_pad($ticket[ticket], 4, "0", STR_PAD_LEFT) . " (locked)"); } } // Toggle sides. $side = 1 - $side; $AreTickets = true; } // My Chances $winningChance = number_format(100 / ($ticketCount / $chances), 3) . "%"; // Even the odds ;) if ($side == 0) { $drawing->addCol("---"); } if ($allowedTickets > 0) { $drawing->addHeader("Click on a ticket to buy it, up to {$allowedTickets} more ({$LOTTO_MAX_PERCENT}%). Your chances of winning are: {$winningChance}"); } else { $drawing->addHeader("You exceeded the maximum allowed tickets ({$LOTTO_MAX_PERCENT}%). Your chances of winning are: {$winningChance}"); } } // HTML goodness. $html = "<h2>Play Lotto</h2>"; $html .= $MyInfo->flush() . "<br>"; if ($GotWinners) { $html .= $MyWins->flush() . "<br>"; } // only include ticket table if we have tickets. if ($AreTickets) { $html .= $drawing->flush(); } // return the page. return $html; }