A Crystal Bank for your users
create file called crystalbank.php
place this in the file
<?php
include "globals.php";
print "<h3>Crystal Bank Bank</h3>";
if($ir['crystalbank']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;
case "withdraw":
withdraw();
break;
default:
index();
break;
}
}
else
{
if(isset($_GET['buy']))
{
if($ir['crystals']>5000)
{
print "Congratulations, you bought a Crystal bank account for 5000 Crystals Coins!
<a href='goldbank.php'>Start using my account</a>";
$db->query("UPDATE users SET crystals=crystals-5000,crystalbank=0 WHERE userid=$userid");
}
else
{
print "You do not have enough Money to open an account.
<a href='explore.php'>Back to town...</a>";
}
}
else
{
print "Open a crystal bank account today, just 5000 Crystals coins!
<a href='crystalbank.php?buy'> Yes, sign me up!</a>";
}
}
function index()
{
global $db, $ir,$c,$userid,$h;
print "\n<b>You currently have {$ir['crystalbank']} crystals in the bank.</b>
<table width='75%' cellspacing=1 class='table'> <tr> <td width='50%'><b>Deposit Crystals</b>
<form action='crystalbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['crystals']}' />
<input type='submit' value='Deposit' /></form></td> <td>
<b>Withdraw crystals</b>
There is no fee on withdrawals.<form action='crystalbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['crystalbank']}' />
<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['crystals'])
{
print "You do not have enough crystals to deposite in the bank bank.";
}
else
{
$gain=$_POST['deposit']-$fee;
$ir['crystal']+=$gain;
$db->query("UPDATE users SET crystalbank=crystalbank+$gain, crystals=crystals-{$_POST['deposit']} where userid=$userid");
print "You hand over {$_POST['deposit']} to be deposited,
$gain is added to your account.
<b>You now have {$ir['crystalbank']} in the bank.</b>
<a href='crystalbank.php'> Back</a>";
}
}
function withdraw()
{
global $db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((int) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['crystalbank'])
{
print "You do not have enough crystals to withdraw from the bank.";
}
else
{
$gain=$_POST['withdraw'];
$ir['crystalbank']-=$gain;
$db->query("UPDATE users SET crystalbank=crystalbank-$gain, crystals=crystals+$gain where userid=$userid");
print "You ask to withdraw $gain,
the banking lady grudgingly hands it over.
<b>You now have {$ir['crystalbank']} in the bank.</b>
<a href='crystalbank.php'> Back</a>";
}
}
$h->endpage();
?>
Add to your database
crystalbank int 11 default 0