cash_pay($l, $allbet); bank_add($allbet); while (true) { $map = generate_randmap(); $win = summ_map($map, $numbers); if ($win !== null and $win * $allbet < winlimit()) { break; } } $allwin = $win * $allbet; mysql_query("INSERT INTO stat_game VALUES('NULL','" . date("d.m.y") . "','" . date("H:i:s") . "','" . $l . "','" . cash_balance($l) . "','" . $allbet . "','" . $allwin . "','Stars Keno')"); if ($allwin > 0) { cash_add($l, $allwin); bank_pay($allwin); echo "&RESULT=OK" . "&NUMBERS=" . implode("|", $map) . "&PAYOUT=" . $allwin . "&BALANCE=" . cash_balance($l); } else { //include( "../../par_prog.php" ); echo "&RESULT=OK" . "&NUMBERS=" . implode("|", $map) . "&PAYOUT=0" . "&BALANCE=" . cash_balance($l); } //RESULT //BET //NUMBERS //BALANCE //PAYOUT //echo "&RESULT=OK&NUMBERS=1|2|3|4|5|6|7|8|9|10&PAYOUT=1"; break; case "MOVE": echo "&RESULT=NOT_IMPL_MOVE&BALANCE=" . cash_balance($l); break; } debug_out("end\r\n================\r\n");
<?php // configuration require "../includes/config.php"; $positions = []; $rows = query("SELECT * FROM portfolio WHERE id = ?", $_SESSION["id"]); if (!empty($rows)) { foreach ($rows as $row) { $stock = lookup($row["symbol"]); if ($stock !== false) { $positions[] = ["name" => $stock["name"], "price" => $stock["price"], "shares" => $row["shares"], "symbol" => $row["symbol"]]; } } } $balance = cash_balance(); // render portfolio render("portfolio.php", ["positions" => $positions, "balance" => $balance, "title" => "Portfolio"]);
// else render form render("buy_form.php", ["title" => "Buy Stocks"]); } else { if ($_SERVER["REQUEST_METHOD"] == "POST") { $stock = lookup($_POST["symbol"]); //validate submission if ($stock === false || empty($stock)) { apologize("Invalid symbol."); } else { if (empty($_POST["shares"])) { apologize("Please enter the number of shares."); } else { if (!preg_match("/^\\d+\$/", $_POST["shares"])) { apologize("Number of shares should be a positive integer."); } else { if (cash_balance() < $stock["price"] * $_POST["shares"]) { apologize("Inadequate funds."); } else { // capitalize symbol $_POST["symbol"] = strtoupper($_POST["symbol"]); // update portfolio query("INSERT INTO portfolio (id,symbol,shares) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)", $_SESSION["id"], $_POST["symbol"], $_POST["shares"]); // update history query("INSERT INTO history (id, transaction, symbol, shares, price) VALUES (?,?,?,?,?)", $_SESSION["id"], "BOUGHT", $_POST["symbol"], $_POST["shares"], $stock["price"]); // update cash balance query("UPDATE users SET cash = cash - ? WHERE id = ?", $stock["price"] * $_POST["shares"], $_SESSION["id"]); // email receipt $rows1 = query("SELECT * FROM history WHERE id = ?", $_SESSION["id"]); $rows2 = query("SELECT * FROM users WHERE id = ?", $_SESSION["id"]); $datetime = $rows1[0]["date/time"]; $stockname = $stock["name"];
<?php print "<h4>" . "Your current cash balance is: \$" . number_format(cash_balance(), 2) . "</h4>"; $rows = query("SELECT * FROM portfolio WHERE id = ?", $_SESSION["id"]); ?> <form action="buy.php" method="post"> <fieldset> <div class="form-group"> <input autofocus class="form-control" name="symbol" placeholder="Symbol" type="text"/> </div> <div class="form-group"> <input class="form-control" name="shares" placeholder="Shares" type="text"/> </div> <div class="form-group"> <button type="submit" class="btn btn-default">Buy</button> </div> </fieldset> </form>