sql_query($sql)) ) {
message_die(GENERAL_MESSAGE, 'Cash Table Not Found');
} else {
$row = $db->sql_fetchrow($sresult);
$board_config['points_name'] = $row[0];
$db->sql_freeresult($sresult);
}
$sql="SELECT cash_dbfield FROM nuke_bbcash";
if ( !($sresult = $db->sql_query($sql)) ) {
message_die(GENERAL_MESSAGE, 'Cash Table Not Found');
} else {
$row = $db->sql_fetchrow($sresult);
$cash_field = $row[0];
$db->sql_freeresult($sresult);
}
//
//check logged in
//
if( !($userdata['session_logged_in']) )
{
header('Location: ' . append_sid("login.$phpEx?redirect=shop_actions.$phpEx?action=".$_REQUEST['action'], true));
}
//
//end check
//
//start functions
//
function userhasitem($checkusername, $checkitemname)
{
$checkinguser = get_userdata($checkusername);
if (substr_count($checkinguser['user_items'],"ß".$checkitemname."Þ") < 1) { return false; }
else { return true; }
}
function checkgold($checkusername, $checkgold)
{
$checkinguser = get_userdata($checkusername);
if ($checkinguser[$cash_field] < $checkgold) { return false; }
else { return true; }
}
function checkitemarray($checkusername, $checkitemname)
{
$arrayitems = str_replace("ß", "", $checkitemname);
$arrayitems = explode("Þ", substr($arrayitems, 0, strlen($arrayitems)-1));
$arraycount = count($arrayitems);
$checkinguser = get_userdata($checkusername);
for ($x = 0; $x < $arraycount; $x++)
{
if (substr_count($checkinguser['user_items'],"ß".$arrayitems[$x]."Þ") < 1) { return false; }
}
return true;
}
function cleartrade($clearer, $messageto, $message)
{
$sql = "update " . USERS_TABLE . " set user_trade='' where user_id='$clearer'";
if ( !(mysql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_query()); }
$sql = "select user_specmsg from " . USERS_TABLE . " where user_id='$messageto'";
if ( !($result = mysql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_query()); }
$row = mysql_fetch_array($result);
$newmessage = $row['user_specmsg'].' '.$message;
$sql = "update " . USERS_TABLE . " set user_specmsg='$newmessage' where user_id='{$row['user_id']}'";
if ( !(mysql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_query());
}
}
//end functions
$template->set_filenames(array(
'body' => 'shop_body.tpl')
);
//set useritems into variable
$itemarray = str_replace("Þ", "", $userdata['user_items']);
$itemarray = explode('ß',$itemarray);
$itemcount = count ($itemarray);
for ($xe = 0; $xe < $itemcount; $xe++)
{
if ($itemarray[$xe] != NULL) { $user_items .= ''; }
}
if (strlen($user_items) < 5) { $user_items = ''; }
if (empty($_REQUEST['action']))
{
header("Location: shop.php");
}
elseif ($_REQUEST['action'] == "give")
{
if ($board_config['shop_give'] == "off") { message_die(GENERAL_MESSAGE, "The ability to give items has been disabled!"); }
$shopaction = '
Please select an item and the person you would like to give it to.
';
$shopinforow = '';
$shoplocation = ' -> Inventory -> Give';
$title = 'Give Item';
$page_title = 'Give Item';
$shoptablerows = 2;
}
elseif ($_REQUEST['action'] == "confirmgive")
{
if ($board_config['shop_give'] == "off") { message_die(GENERAL_MESSAGE, "The ability to give items has been disabled!"); }
//check if trying to give item to self
if (strtolower($userdata['username']) == strtolower($username)) { message_die(GENERAL_MESSAGE, 'What is the point in giving your '.$itemname.' to yourself?'); }
//make sure the user exists
$otheruser = get_userdata($_REQUEST['username']);
if( !($otheruser['user_id']) ) { message_die(GENERAL_MESSAGE, 'No Such User Exists!'); }
//make sure user has item, prevents exploit
if (!(userhasitem($userdata['username'], $_REQUEST['itemname']))) { message_die(GENERAL_MESSAGE, "You don't have that item!"); }
$shoplocation = ' -> Inventory -> Give -> Confirm Trade';
$shoptablerows = 1;
$shopaction = '
Are you sure you want to give the '.$_REQUEST['itemname'].' to '.$_REQUEST['username'].'?
';
$shopinforow = '';
}
elseif ($_REQUEST['action'] == "giveitem")
{
if ($board_config['shop_give'] == "off") { message_die(GENERAL_MESSAGE, "The ability to give items has been disabled!"); }
//begin secondary checks
//check if trying to give item to self
//make sure the user exists
$otheruser = get_userdata($_REQUEST['username']);
if( !($otheruser['user_id']) ) { message_die(GENERAL_MESSAGE, 'No Such User Exists!'); }
//make sure user has item, prevents exploit
if (!(userhasitem($userdata['username'], $_REQUEST['itemname']))) { message_die(GENERAL_MESSAGE, "You don't have that item!"); }
if (strtolower($userdata['username']) == strtolower($_REQUEST['username'])) { message_die(GENERAL_MESSAGE, 'What is the point in giving your '.$_REQUEST['itemname'].' to yourself?'); }
//end secondary checks
$title = "Item Given";
$page_title = "Item Given";
//take the item away from the user
$useritems = substr_replace($userdata['user_items'], "", strpos($userdata['user_items'], "ß".$_REQUEST['itemname']."Þ"), strlen("ß".$_REQUEST['itemname']."Þ"));
$sql="update " . USERS_TABLE . " set user_items='$useritems' where username='{$userdata['username']}'";
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error.');
}
//give the item to the recipient
$useritems = $otheruser['user_items']."ß".$_REQUEST['itemname']."Þ";
//send receiver message
$usermessage = $otheruser['user_specmsg'];
$usermessage .= ' '.$userdata['username'].' has given you a '.$_REQUEST['itemname'].'!';
//update table
$sql="update " . USERS_TABLE . " set user_items='$useritems', user_specmsg='$usermessage' where username='{$_REQUEST['username']}'";
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Fatal Error Updating User Information on Give Page');
}
//tell the user that the item has been given
$shoplocation = ' -> Inventory -> Give -> Confirm Trade -> Trade Completed';
$shoptablerows = 1;
$shopaction = '
'.$_REQUEST['username'].' received the '.$_REQUEST['itemname'].'.
';
}
elseif ($_REQUEST['action'] == "trade")
{
if ($board_config['shop_trade'] == "off") { message_die(GENERAL_MESSAGE, "The ability to trade items has been disabled!"); }
if ((!(empty($_REQUEST['username']))) && ($_REQUEST['username'] != $userdata['username']))
{
$otheruser = get_userdata($_REQUEST['username']);
if (strlen($otheruser['user_trade']) > 3) { header("Location: shop_actions.php?action=trade&errormessage=User already has a trade waiting!"); exit; }
if (empty($otheruser)) { message_die(GENERAL_MESSAGE, "No such user exists!"); }
else
{
//
// Begin checks for additions and removes of each section.
//
if (!(checkitemarray($userdata['username'], $_REQUEST['tradeitems'])) && strlen($_REQUEST['tradeitems']) > 2) { message_die(GENERAL_MESSAGE, "Fatal Error: Invalid Items!"); }
if (!(checkitemarray($_REQUEST['username'], $_REQUEST['otheritems'])) && strlen($_REQUEST['otheritems']) > 2) { message_die(GENERAL_MESSAGE, "Fatal Error: Invalid Items!"); }
if (!(empty($_REQUEST['itemname'])))
{
if ((!(empty($_REQUEST['additem']))) && (userhasitem($userdata['username'], $_REQUEST['itemname'])))
{
if (substr_count($userdata['user_items'], $_REQUEST['itemname']) < (substr_count($tradeitems, $_REQUEST['itemname']) + 1)) { $errormessage .= 'You can not add more of an item than you currently own! '; }
else { $tradeitems .= 'ß'.$_REQUEST['itemname'].'Þ'; }
}
elseif ((!(empty($_REQUEST['removeitem']))) && (substr_count($_REQUEST['tradeitems'],"ß".$_REQUEST['itemname']."Þ") > 0))
{
$tradeitems = substr_replace($_REQUEST['tradeitems'], "", strpos($_REQUEST['tradeitems'], "ß".$_REQUEST['itemname']."Þ"), strlen("ß".$_REQUEST['itemname']."Þ"));
}
else { $tradeitems = $_REQUEST['tradeitems']; }
}
else { $tradeitems = $_REQUEST['tradeitems']; }
if (!(empty($_REQUEST['otheritem'])))
{
if ((!(empty($_REQUEST['additem']))) && (userhasitem($_REQUEST['username'], $_REQUEST['otheritem'])))
{
if (substr_count($otheruser['user_items'], $_REQUEST['otheritem']) < (substr_count($otheritems, $_REQUEST['otheritem']) + 1)) { $errormessage .= 'You can not add more of an item than '.$username.' currently owns! '; }
else { $otheritems .= 'ß'.$_REQUEST['otheritem'].'Þ'; }
}
elseif ((!(empty($_REQUEST['removeitem']))) && (substr_count($_REQUEST['otheritems'],"ß".$_REQUEST['otheritem']."Þ") > 0))
{
$otheritems = substr_replace($_REQUEST['otheritems'], "", strpos($_REQUEST['otheritems'], "ß".$_REQUEST['otheritem']."Þ"), strlen("ß".$_REQUEST['otheritem']."Þ"));
}
else { $otheritems = $_REQUEST['otheritems']; }
}
else { $otheritems = $_REQUEST['otheritems']; }
if (!(empty($_REQUEST['points'])))
{
if (!(empty($_REQUEST['addpoints'])) && is_numeric($_REQUEST['points']) && $_REQUEST['points'] > 0)
{
$goldamount = $_REQUEST['tradegold'] + $_REQUEST['points'];
if (!(checkgold($userdata['username'], $goldamount))) { $errormessage .= 'You cannot trade more gold than you currently have! '; }
else { $tradegold = round($goldamount); }
}
elseif (!(empty($_REQUEST['removepoints'])) && is_numeric($points) && $points > 0)
{
$goldamount = $_REQUEST['tradegold'] - $_REQUEST['points'];
if (!(checkgold($userdata['username'], $goldamount))) { $errormessage .= 'You cannot trade more gold than you currently have! '; }
elseif ($goldamount < 0) { $goldamount = 0; $errormessage .= 'You cannot set your gold into negative! '; }
else { $tradegold = round($goldamount); }
}
else { $tradegold = $_REQUEST['tradegold']; }
}
else { $tradegold = $_REQUEST['tradegold']; }
if (!(empty($_REQUEST['otherpoints'])))
{
if (!(empty($_REQUEST['addpoints'])) && is_numeric($_REQUEST['otherpoints']) && $_REQUEST['otherpoints'] > 0)
{
$goldamount = $_REQUEST['othergold'] + $_REQUEST['otherpoints'];
if (!(checkgold($_REQUEST['username'], $goldamount))) { $errormessage .= 'You cannot ask for more gold than '.$_REQUEST['username'].' currently has! '; }
else { $othergold = round($goldamount); }
}
elseif (!(empty($_REQUEST['removepoints'])) && is_numeric($_REQUEST['otherpoints']) && $_REQUEST['otherpoints'] > 0)
{
$goldamount = $_REQUEST['othergold'] - $_REQUEST['otherpoints'];
if (!(checkgold($userdata['username'], $goldamount))) { $errormessage .= 'You cannot ask for more gold than '.$_REQUEST['username'].' currently has! '; }
elseif ($goldamount < 0) { $goldamount = 0; $errormessage .= 'You cannot set your requested gold into negative! '; }
else { $othergold = round($goldamount); }
}
else { $othergold = $_REQUEST['othergold']; }
}
else { $othergold = $_REQUEST['othergold']; }
if (!is_numeric($tradegold) || $tradegold < 0 || !(checkgold($userdata['username'], $tradegold))) { $tradegold = 0; }
if (!is_numeric($othergold) || $othergold < 0 || !(checkgold($_REQUEST['username'], $othergold))) { $othergold = 0; }
$hiddenfields = '
';
//
// End checks for additions and removes of each section.
//
//
// Begin main output and calculations
// Set trade items into variable
//
if (strlen($tradeitems) < 3) { $tradingitems = "Nothing"; }
else {
$tradingitems = str_replace("Þ", ', ', str_replace("ß", "", $tradeitems));
$tradingitems = substr($tradingitems, 0, strlen($tradingitems)-2);
}
if (strlen($otheritems) < 3) { $otheritemz = "Nothing"; }
else {
$otheritemz = str_replace("Þ", ', ', str_replace("ß", "", $otheritems));
$otheritemz = substr($otheritemz, 0, strlen($otheritemz)-2);
}
$itemarray = str_replace("Þ", "", $otheruser['user_items']);
$itemarray = explode('ß',$itemarray);
$itemcount = count ($itemarray);
for ($xe = 0; $xe < $itemcount; $xe++)
{
if ($itemarray[$xe] != NULL) { $otheruser_items .= ''; }
}
if (strlen($otheruser_items) < 5) { $otheruser_items = ''; }
if (strlen($errormessage) > 3)
{
$shopaction .= '