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); } //start of buy page if ($_REQUEST['action'] == "buy") { if (!isset($_REQUEST['item'])) { message_die(GENERAL_MESSAGE, 'No Item Chosen!'); } $template->set_filenames(array( 'body' => 'shop_body.tpl') ); if ( !$userdata['session_logged_in'] ) { $redirect = 'shop.'.$phpEx.'&action=buy&item='.$_REQUEST['item']; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } //make sure item exists $sql = "select * from nuke_shopitems where id='{$_REQUEST['item']}'"; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_error()); } $row = mysql_fetch_array($result); if (!isset($row['shop'])) { message_die(GENERAL_MESSAGE, 'Fatal Error: no such item exists!'); } elseif ($row['stock'] < 1) { message_die(GENERAL_MESSAGE, 'Item is out of stock!'); } $checkshop = addslashes($row['shop']); $sql = "select * from nuke_shops where shopname='$checkshop' and shoptype!='special' and shoptype!='admin_only'"; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error'); } if (mysql_num_rows($result) < 1) { message_die(GENERAL_MESSAGE, 'That item is in a protected shop!'); } //end check on item exists // //check currency & if has item if ($board_config['multibuys'] == "off") { if (substr_count($userdata['user_items'],"ß".$row['name']."Þ") > 0) { message_die(GENERAL_MESSAGE, 'You already own one of those!'); } } if ((substr_count($userdata['user_items'],"ß") >= $board_config['shop_invlimit']) && ($board_config['shop_invlimit'] != 0)) { message_die(GENERAL_MESSAGE, 'Your inventory is full, sell back some items if you want to buy more.'); } if ($userdata[$cash_field] < $row['cost']) { message_die(GENERAL_MESSAGE, "You don't have enough ".$board_config['points_name']." to purchase this!"); } //end of check for currency and is has item // //start of table updates $leftamount = round($userdata[$cash_field] - $row['cost']); $useritems = $userdata['user_items']."ß".$row['name']."Þ"; $newstock = --$row['stock']; $newsold = ++$row['sold']; $sql="update " . USERS_TABLE . " set ".$cash_field."='$leftamount', user_items='$useritems' where username='{$userdata['username']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: updating user information'); } $sql="update nuke_shopitems set stock='$newstock', sold='$newsold' where id='{$_REQUEST['item']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_error()); } $useritemamount = substr_count($userdata['user_items'],"ß".$row['name']."Þ") +1; //end of table updates // //start of echoes $shopaction = 'You have bought a '.ucwords($row['name']).' for '.$row['cost'].' '.$board_config['points_name'].' leaving you with '.$leftamount.' '.$board_config['points_name'].'.
'; $shopinforow = 'IconItem NameDescriptionStockCostOwned'; if (file_exists("shop/images/".$row['name'].".jpg")) { $itemfilext = "jpg"; } else { $itemfilext = "gif"; } $shopitems = ''.$row['name'].''.ucwords($row['name']).''.ucfirst($row['ldesc']).''.$row['stock'].''.$row['cost'].''.$useritemamount.''; $title = "Buy ".$row['name']; $page_title = "Buy ".$row['name']; $shoptablerows = 6; $srow = mysql_fetch_array($result); $shoplocation = ' -> Shop List -> '.ucwords($row['shop']).' Inventory -> '.ucwords($row['name']).' Information -> Buy '.ucwords($row['name']).''; // start of personal information $personal = 'Your Inventory'.$userdata[$cash_field].' '.$board_config['points_name'].''; if (strlen($userdata['user_specmsg']) > 2) { $personal .= ''.$userdata['user_specmsg'].''; $personal .= 'Clear Messages'; } //end of personal information $template->assign_vars(array( 'SHOPPERSONAL' => $personal, 'SHOPLOCATION' => $shoplocation, 'SHOPACTION' => $shopaction, 'L_SHOP_TITLE' => $title, 'SHOPTABLEROWS' => $shoptablerows, 'SHOPLIST' => $shopitems, 'SHOPINFOROW' => $shopinforow, )); $template->assign_block_vars('', array()); } //start of sell page elseif ($_REQUEST['action'] == "sell") { if (!isset($_REQUEST['item'])) { message_die(GENERAL_MESSAGE, 'Fatal Error: no item chosen!'); } $template->set_filenames(array( 'body' => 'shop_body.tpl') ); if ( !$userdata['session_logged_in'] ) { $redirect = 'shop.'.$phpEx.'&action=sell&item='.$_REQUEST['item']; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } //make sure item exists $sql = "select * from nuke_shopitems where id='{$_REQUEST['item']}'"; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_error()); } $row = mysql_fetch_array($result); if (mysql_num_rows($result) < 1) { message_die(GENERAL_MESSAGE, 'Fatal Error: no such item exists!'); } $sql = "select * from nuke_shops where shopname='".addslashes($row['shop'])."' and shoptype!='special' and shoptype!='admin_only'"; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: '.mysql_error()); } if (mysql_num_rows($result) < 1) { message_die(GENERAL_MESSAGE, 'Item cannot be sold to a protected shop!'); } //end check on item exists // // //check for item if (substr_count($userdata['user_items'],"ß".$row['name']."Þ") < 1) { message_die(GENERAL_MESSAGE, "You can't sell something you don't own!"); } //end of check for item // //start of table updates $plusamount = round($row['cost'] / 100 * $board_config['sellrate']); $leftamount = $userdata[$cash_field] + $plusamount; $useritems = substr_replace($userdata['user_items'], "", strpos($userdata['user_items'], "ß".$row['name']."Þ"), strlen("ß".$row['name']."Þ")); $newstock = ++$row['stock']; $newsold = --$row['sold']; $sql="update " . USERS_TABLE . " set ".$cash_field."='$leftamount', user_items='$useritems' where username='{$userdata['username']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: updating user information'); } $sql="update nuke_shopitems set stock='$newstock', sold='$newsold' where name='{$row['name']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error: updating item information'); } //end of table updates // //start of echoes $useritemamount = substr_count($userdata['user_items'],"ß".$row['name']."Þ") -1; $shopaction = 'You have sold a '.ucwords($row['name']).' for '.$plusamount.' '.$board_config['points_name'].' which gives you '.$leftamount.' '.$board_config['points_name'].'.
'; $shopinforow = 'IconItem NameDescriptionStockCostOwned'; if (file_exists("shop/images/".$row['name'].".jpg")) { $itemfilext = "jpg"; } else { $itemfilext = "gif"; } $shopitems = ''.$row['name'].''.ucwords($row['name']).''.ucfirst($row['ldesc']).''.$row['stock'].''.$row['cost'].''.$useritemamount.''; $title = "Sell ".$row['name']; $page_title = "Sell ".$row['name']; $shoptablerows = 6; $srow = mysql_fetch_array($result); $shoplocation = ' -> Shop List -> '.ucwords($row['shop']).' Inventory -> '.ucwords($row['name']).' Information -> Sell '.ucwords($row['name']).''; // start of personal information $personal = 'Your Inventory'.$userdata[$cash_field].' '.$board_config['points_name'].''; if (strlen($userdata['user_specmsg']) > 2) { $personal .= ''.$userdata['user_specmsg'].''; $personal .= 'Clear Messages'; } //end of personal information $template->assign_vars(array( 'SHOPPERSONAL' => $personal, 'SHOPLOCATION' => $shoplocation, 'SHOPACTION' => $shopaction, 'L_SHOP_TITLE' => $title, 'SHOPTABLEROWS' => $shoptablerows, 'SHOPLIST' => $shopitems, 'SHOPINFOROW' => $shopinforow, )); $template->assign_block_vars('', array()); } else { message_die(GENERAL_MESSAGE, 'This is not a valid command!'); } // // Start output of page // include('includes/page_header.' . $phpEx); // // Generate the page // $template->pparse('body'); include('includes/page_tail.' . $phpEx); ?>