I do like the way you've gone with this, however could off made it shorter but using isset()
I've slighty edited you're code and removed all the die(""); as it's alot cleaner when it show's the endpage function :P
<?php
include(DIRNAME(__FILE__) . '/globals.php');
$m=$db->query("SELECT * FROM users WHERE userid=".abs(intval($_GET['pro']))."");
$r=$db->fetch_row($m);
$_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : false;
switch($_GET['action'])
{
case "accept"; accept(); break;
case "decline"; decline(); break;
case "decision"; decision(); break;
case "proposeform"; proposeform(); break;
case "proposesubmit"; proposesubmit(); break;
default: index(); break;
}
if (!in_array($_GET['action'], array('propose', 'proposesubmit', 'proposeform', 'decision', 'decline', 'accept')))
{
print "Action Not Understood!";
$h->endpage();
exit;
}
function index()
{
global $db,$ir,$c,$h,$userid;
if ($ir['married'] != 0)
{
echo "You are already married";
exit($h->endpage());
} else {
print"<h1>Proposal Center</h1>
Do you want to propose to someone?
<form action='marriage.php?action=proposeform' method='post'>
<input type='submit' class='submit' value='Yes.'>
</form>
<form action='index.php' method='get'>
<input type='submit' class='submit' value='No.'>
</form>";
}
}
function proposeform()
{
global $db,$ir,$c,$h,$userid;
if ($ir['married'] != 0)
{
echo"You are already married";
exit($h->endpage());
} else {
print"<h1>Proposal Center</h1>
<form action='marriage.php?action=proposesubmit' method='post'>
Please enter the user id of the user you want to propose to:
User ID: <input type='text' name='propose' />
Message: <input type='text' name='message' />
<input type='submit' value='Propose' /></form>";
}
}
function proposesubmit()
{
global $db,$r,$ir,$c,$h,$userid;
$m=$db->query("SELECT * FROM users WHERE userid=".abs(intval($_POST['propose']))."");
$r=$db->fetch_row($m);
if ($r['married'] != 0)
{
echo "This person is already married. Sorry. Try someone else.";
exit($h->endpage());
}
if ($ir['married'] != 0)
{
echo "You are already married";
exit($h->endpage());
}
if ($ir['userid'] == $_POST['propose'])
{
echo "You cannot marry yourself";
exit($h->endpage());
}
if ($_POST['propose'] <= 0)
{
echo"Invalid user, Try someone else.";
exit($h->endpage());
} else {
$ch=$db->query("SELECT * FROM proposals WHERE proPROPOSED=".abs(intval($_POST['propose']))."");
if ($db->num_rows($ch)!=0)
{
echo "This user already has a pending proposal, please try again later
<a href=index.php>> Back</a>";
exit($h->endpage());
} else {
$m=$db->query("SELECT * FROM users WHERE userid=".abs(intval($_POST['propose']))."");
$r=$db->fetch_row($m);
$db->query("INSERT INTO proposals VALUES('', '{$ir['userid']}', '".abs(intval($_POST['propose']))."', '".mysql_real_escape_string($_POST['message'])."')");
event_add(abs(intval($_POST['propose'])),"[url='viewuser.php?u=$userid']".htmlentities($ir['username'])." [".abs(intval($ir['userid']))."][/url] proposed to you
click [url='marriage.php?action=decision']<u>HERE</u>[/url] to make your mind up.</a> ",$c);
print"<h3>Proposal Center</h3>
You proposed to ".htmlentities($r['username'])." [".abs(intval($r['userid']))."], please wait for their decision
";
}
}
}
function decision()
{
global $ir,$db,$h,$userid;
$m=$db->query("SELECT * FROM proposals WHERE proPROPOSED=".abs(intval($ir['userid']))."");
if ($db->num_rows($m)==0)
{
echo"Nobody has proposed to you!
<a href=index.php>> Back</a>";
exit($h->endpage());
} else {
$pro=$db->fetch_row($m);
$f=$db->query("SELECT * FROM users WHERE userid=".abs(intval($pro['proPROPOSER']))."");
$r=$db->fetch_row($f);
print"<h3>Decision Center</h3>
<center><table width=90% cellspacing=1 class=table border=1 bordercolor=#636363></center><tr><td>
Proposer: [url='viewuser.php?u=".abs(intval($r[']".htmlentities($r['username'])."[/url]
</td>
<td>Message: ".htmlentities($pro['proMESSAGE'])."
</td>
<td>Decision:
[url='marriage.php?action=accept&pro=".abs(intval($pro[']<font color=green>Accept</font>[/url]
or
[url='marriage.php?action=decline&pro=".abs(intval($pro[']<font color=red>Decline</font>[/url]</td></tr></table>";
}
}
function accept()
{
global $ir,$userid,$db,$h;
if ($r['married'] != 0)
{
echo"This person is already married. Sorry. Try someone else.";
exit($h->endpage());
}
if($ir['married'] != 0)
{
print "You are already married";
$h->endpage();
exit();
}
$m=$db->query("SELECT * FROM proposals WHERE (`proID` = ".abs(intval($_GET['pro'])).") AND (`proPROPOSED` = $userid)");
if(!mysql_num_rows($m))
{
echo ('You\'ve clicked an invalid link, please report to an administrator.');
$h->endpage();
exit();
} else {
$m=$db->query("SELECT * FROM proposals WHERE proID=".abs(intval($_GET['pro']))." AND proPROPOSED=$userid");
$pro=$db->fetch_row($m);
$db->query("UPDATE `users` SET `married` =".abs(intval($pro['proPROPOSER']))." WHERE (`userid` = $userid)");
$db->query("UPDATE `users` SET `married` =".abs(intval($pro['proPROPOSED']))." WHERE (`userid` = ".abs(intval($pro['proPROPOSER'])).")");
$db->query("DELETE FROM proposals WHERE (proID=".abs(intval($pro['proID'])).")");
$mr=$db->query("SELECT * FROM `users` WHERE (`userid` =".abs(intval($pro['proPROPOSER'])).")");
$par=$db->fetch_row($mr);
event_add($par['userid'],"Your proposal for [url='viewuser.php?u=".abs(intval($ir[']".htmlentities($ir['username'])."[/url] was accepted",$c);
print "You married ".htmlentities($par['username'])." !!!
";
}
}
function decline()
{
global $ir,$userid,$db,$h;
$_GET['pro'] = isset($_GET['pro']) && is_numeric($_GET['pro']) ? abs(@intval($_GET['pro'])) : false;
if(!$_GET['pro'])
{
echo "Stop abusing our marriage system!";
exit($h->endpage());
}
$m=$db->query("SELECT * FROM proposals WHERE proID=".abs(intval($_GET['pro']))." AND proPROPOSED=$userid");
if ($db->num_rows($m) == 0)
{
print "Invalid proposal or this is not your proposal";
}
else
{
$pro=$db->fetch_row($m);
$db->query("DELETE FROM proposals WHERE proID=".abs(intval($pro['proID']))."");
$mr=$db->query("SELECT * FROM users WHERE userid=".abs(intval($pro['proPROPOSER']))."");
$par=$db->fetch_row($mr);
event_add($par['userid'],"".htmlentities($ir['username'])." [".abs(intval($ir['userid']))."] has declined your proposal",$c);
print"You declined the proposal from ".htmlentities($par['username'])."!
";
}
}
$h->endpage();
?>
I'll release a new martial system once I've finished the updates :)