<?php
include_once(DIRNAME(__FILE__) . '/globals.php');
echo "<h3>Town Bank</h3><h4>Welcome to the Bank, Here you can deposit your cash to keep it safe from other players!</h4><br />";
if ($ir['bankmoney'] > -1) {
switch ($_GET['page']) {
case "deposit": deposit(); break;
case "withdraw": withdraw(); break;
default: index(); break;
}
} else {
if (isset($_GET['buy'])) {
if ($ir['money'] > 49999) {
echo "<b>Success:</b> You have paid <b>$50,000</b> for a bank account.<br />
Would you like to go to your bank account?<br /><br />
<a href='bank.php'>Yes</a> | <a href='explore.php'>No</a>";
$db->query("UPDATE users SET money=money-1000,bankmoney=0 WHERE userid=$userid");
} else {
echo "<b>Error:</b> You do not have enough cash to open an account!<br /><br /> > <a href='explore.php'>Back</a>";
}
} else {
echo "<b>Bank Manager:</b> Hey, <i>" . $ir['username'] . "</i>, Welcome to the Bank.<br />
Here you can deposit your cash so it doesn't get stolen by other players.<br />
To open a bank account it will cost <b>$50,000</b>, Would you like to open an account?<br /><br />
<br /><a href='bank.php?buy'>Yes please</a> | <a href='explore.php'>No thanks</a>";
}
}
function index()
{
global $db, $ir, $c, $userid, $h;
echo "You currently have <b>" . money_formatter($ir['bankmoney']) . "</b> in your bank account.<br /><br />
<table width='80%' class='table'><tr><th width='50%'>Deposit Cash</th><th>Withdraw Cash</th></tr>
<tr><td style='text-align:center;'> <br />
<form action='bank.php?page=deposit' method='post'>
<input type='text' name='deposit' value='{$ir['money']}' /><br />
<input type='submit' value='Deposit' /></form></td>
<td style='text-align:center;'> <br /><form action='bank.php?page=withdraw' method='post'>
<input type='text' name='withdraw' value='{$ir['bankmoney']}' /><br />
<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $db, $ir, $c, $userid, $h;
$_POST['deposit'] = abs((int) $_POST['deposit']);
if ($_POST['deposit'] > $ir['money']) {
echo "<b>Error:</b> You do not have enough cash to deposit that amount!<br /><br /> > <a href='bank.php'>Back</a>";
} else {
$fee = ceil($_POST['deposit'] * 100 / 100);
if ($fee > 0) {
$fee = 0;
}
$gain = $_POST['deposit'] - $fee;
$ir['bankmoney'] += $gain;
$db->query("UPDATE users SET bankmoney=bankmoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
echo "You hand over <b>" . money_formatter($_POST['deposit']) . "</b> to be added into your bank account.<br /><br />
<b>Bank Manager:</b> Okay <i>" . $ir['username'] . "</i>, The cash has been added to your bank account.<br /><br />
You now have <b>" . money_formatter($ir['bankmoney']) . "</b> in your bank account.<br /><br />
> <a href='bank.php'>Back</a>";
}
}
function withdraw()
{
global $db, $ir, $c, $userid, $h;
$_POST['withdraw'] = abs((int) $_POST['withdraw']);
if ($_POST['withdraw'] > $ir['bankmoney']) {
echo "<b>Error:</b> You do not have enough banked cash to withdraw that amount!<br /><br /> > <a href='bank.php'>Back</a>";
} else {
$gain = $_POST['withdraw'];
$ir['bankmoney'] -= $gain;
$db->query("UPDATE users SET bankmoney=bankmoney-$gain, money=money+$gain where userid=$userid");
echo "You ask for <b>\$" . $gain . "</b> to be taken from your account.<br /><br />
<b>Bank Manager:</b> Okay <i>" . $ir['username'] . "</i>, Here is your cash.<br /><br />
You now have <b>" . money_formatter($ir['bankmoney']) . "</b> in your bank account.<br /><br />
> <a href='bank.php'>Back</a>";
}
}
$h->endpage();
?>
tHEY DONT HAVAE IT IN THERE, ANY SUGGESTIONS