All pastes #936999 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-10 19:47 UTC
rendered paste body
<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm);
$h->menuarea();

switch($_GET['action'])
{
case 'borrow': borrow_money_start(); break;
case 'borrowed': borrow_money(); break;
case 'repay': repay_money_start(); break;
case 'repayed': repay_money(); break;
case 'invest': invest_money(); break;
case 'invested': invested_money(); break;
default: loanshark_main(); break;
}
function loanshark_main()
{
global $ir,$c,$userid,$h;
$maxloan=$ir['level']*2100;
echo "<h1>Loan Shark</h1><br />
You call up a friend and ask to borrow some money, but your friend doesn't have any.<br>
He does give you the number to a loan shark.<br><br>
You currently have a loan out of \${$ir['loan']}<br />
The max you can borrow is \$$maxloan<br />
- <a href='loanshark.php?action=borrow'>Take out a Loan</a><br />
- <a href='loanshark.php?action=repay'>Repay Loan</a><br />
- <a href='loanshark.php?action=invest'>Invest Money</a><br />";
}
function borrow_money_start()
{
global $ir,$c,$userid,$h;
$maxloan=$ir['level']*2100;
echo "The max amount you can borrow is \$$maxloan<br />
You currently have a loan of \${$ir['loan']}<br />
<form action='loanshark.php?action=borrowed' method='post'>
Ammount: <input type=text value='$maxloan' name=borrowed><br />
<input type=submit value='Borrow'>";
}
function borrow_money()
{
global $ir,$c,$userid,$h;
$maxloan=$ir['level']*2100;
$loan=$ir['loan'];
if ($loan == $maxloan) 
{ 
die("You have already taken out the max loan possible you must pay it back before you can borrow more.<br />
> <a href='loanshark.php?action=repay'>Repay</a>");
}
if ($_POST['borrowed'] >= $maxloan+1) 
{ 
die("You are trying to borrow more then your max loan<br />
> <a href='loanshark.php?action=borrow'>Back</a>");
}

mysql_query("UPDATE users SET loan=loan+{$_POST['borrowed']}, paytime=15 WHERE userid=$userid",$c);
mysql_query("UPDATE users SET money=money+{$_POST['borrowed']} WHERE userid=$userid",$c);
echo"You Borrowed {$_POST['borrowed']} from the loan shark<br />
> <a href='loanshark.php'>Back</a>";
}
function repay_money_start()
{
global $ir,$c,$userid,$h;
echo"You currently have a loan of \${$ir['loan']}<br />
<form action='loanshark.php?action=repayed' method='post'>
Ammount: <input type=text value='{$ir['loan']}' name=repayed><br />
<input type=submit value='Repay'>";
}
function repay_money()
{
global $ir,$c,$userid,$h;

if($ir['loan'] <= 0)
{
die("You are trying to payback more then u have to.<br />
> <a href='loanshark.php'>Back</a>");
}
if($_POST['repayed'] == $ir['loan'])
{
mysql_query("UPDATE users SET paytime=0 WHERE userid=$userid",$c);
}
mysql_query("UPDATE users SET loan=loan-{$_POST['repayed']} WHERE userid=$userid",$c);
mysql_query("UPDATE users SET money=money-{$_POST['repayed']} WHERE userid=$userid",$c);
echo"You repayed \${$_POST['repayed']} to the loan shark<br />
> <a href='loanshark.php'>Back</a>";
}
mysql_query("UPDATE users SET loan=loan-{$_POST['repayed']}, paytime=0 WHERE userid=$userid",$c);
mysql_query("UPDATE users SET money=money-{$_POST['repayed']} WHERE userid=$userid",$c);
echo"You repayed {$_POST['repayed']} to the loan shark<br />
> <a href='loanshark.php'>Back</a>";
}
function invest_money()
{
global $ir,$c,$userid,$h;
echo"Here you can invest money on the spot and watch your money sink or float its simple you state the amount you wish to invest in the box below and click Invest<br />
You have <b>{$ir['investments']}</b> daily invest statment's left<br />
<form action='loanshark.php?action=invested' method='post'>
Ammount: \$<input type=text name=invest><br />
<input type=submit value='Invest'><br />";
}
function invested_money()
{
global $ir,$c,$userid,$h;
if ($ir['investments'] < 1) 
{ 
die("You have used up all your daily investments<br />
> <a href='loanshark.php?action=invest'>Back</a>");
}
if(rand(1,100) <= 50) 
{ 
$gainedmoney=(int) rand(1,30);
print "<font color=green><b>Result: You hand over {$_POST['invest']} to the old man at the counter<br />
One week later you get a phone call its the old man he explains that your investment has payed off<br />
You invested \${$_POST['invest']} and ended up making \$$gainedmoney extra.</font></b><br />
You have <b>{$ir['investments']}</b> daily invest statment's left<br />
> <a href='loanshark.php?action=invest'>Try Again</a>"; 
mysql_query("UPDATE users SET investments=investments-1",$c);
mysql_query("UPDATE users SET money=money+$gainedmoney WHERE userid=$userid",$c); 
} 
else 
{ 
if ($ir['investments'] < 1) 
{ 
die("You have used up all your daily investments<br />
> <a href='loanshark.php?action=invest'>Back</a>");
}
$lostmoney=(int) rand(1,10);
mysql_query("UPDATE users SET money=money-$lostmoney WHERE userid=$userid", $c);
echo"<font color=red><b>Result: You invested \${$_POST['invest']} and lost \$$lostmoney out of your overall investment.<br />
One week later you get a phone call its the old man he explains that your investment has failed<br /></font></b><br />
You have <b>{$ir['investments']}</b> daily invest statment's left<br />
> <a href='loanshark.php?action=invest'>Try Again</a><br />"; 
mysql_query("UPDATE users SET investments=investments-1",$c);
}
}
$h->endpage();
?>