<?php // trading.php
// part one: second hand store
function shs_in_stock($id)
{
global $db, $user;
$sql = "SELECT * FROM `U336282`.`trade_shs_items` WHERE item_id='".$id."' LIMIT 1";
$result = $db->sql_query($sql);
while ($row2 = $db->sql_fetchrow($result))
{
if ($row2['item_id'] == $id)
{
return true;
}
else
{
return false;
}
}
}
function sell_item_to_shs($id)
{
global $db, $user;
if (item_owned($id))
{
$sql = "SELECT * FROM `U336282`.`guildwars_items` WHERE id='".$id."' LIMIT 1";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$switch = $row['switch'];
$buyable = $row['sell'];
}
if (($buyable == "1") && ($switch == "0") && ($id != "14")) {
$sql = "INSERT INTO `trade_shs_items` (item_id, user_id) VALUES ('".$id."', '".$user->data['user_id']."')";
$db->sql_query($sql);
remove_item($id);
$sql = "SELECT * FROM `U336282`.`guildwars_items` WHERE id='".$id."' LIMIT 1";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$price = $row['price'];
}
add_gold($user->data['user_id'], (int)($price / 2));
if (count_shs_items >= 32)
{
$sql = "DELETE FROM `U336282`.`trade_shs_items` WHERE 1 ORDER BY `id` ASC LIMIT 1";
}
$db->sql_query($sql);
header('Location: http://vengeance-rpg.com/v/page.php?p=s ... #39;.$id.'&s');
} else {
header('Location: http://vengeance-rpg.com/v/page.php?p=e ... sell');
}
}
else {
header('Location: http://vengeance-rpg.com/v/page.php?p=e ... sell');
}
}
function buy_item_from_shs($id)
{
global $db, $user;
if (shs_in_stock($id))
{
$sql = "SELECT * FROM `U336282`.`guildwars_items` WHERE id='".$id."' LIMIT 1";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$price = $row['price'];
}
$gold = get_game_var('gold');
if ($gold >= ($price / 2))
{
$gold -= (int)($price / 2);
add_item($id);
set_game_var('gold', $gold);
header('Location: http://vengeance-rpg.com/v/page.php?p=s ... #39;.$id.'');
}
$sql = "DELETE FROM `U336282`.`trade_shs_items` WHERE item_id='".$id."' LIMIT 1";
$db->sql_query($sql);
}
}
function list_my_shs_items()
{
global $db, $user, $config, $cache;
echo "<center><b>Tat Exchange</b></center><br /><img src='http://bb.hbgames.tk/upload/shopowner_port_fishing.png' /> \"Please choose an item to sell, I'll give you what I think it's worth.\"<br /><br />";
$sql = "SELECT * FROM `U336282`.`guildwars_owneditems` WHERE user_id=".$user->data['user_id']." ";
$result = $db->sql_query($sql);
$array = array();
$i = 0;
while ($row = $db->sql_fetchrow($result))
{
$j = $row['item_id'];
$array[$i] = $j;
$i++;
}
for ($i=0; $i>count($array); $i++)
{
$array[$i] = get_item_data($array[$i]);
}
for ($i = 0; $i < count($array); $i++)
{
if ($array[$i] != "0") {
echo "<a href='http://vengeance-rpg.com/v/action.php?tatsell=".$array[$i]."' title='Price: ".ceil(get_item_cost($array[$i]) / 2)." gold'><img title=\"".$title."\" alt=\"".$title."\" src='http://www.vengeance-rpg.com/v/images/items/" . $array[$i] . ".png' /></a> "; }
}
}
function list_shs_items()
{
global $db, $user;
echo "<center><b>Tat Exchange</b></center><br /><img src='http://bb.hbgames.tk/upload/shopowner_port_fishing.png' /> \"Feel free to browse the general tish-tosh that players have sold to me.\"<br /><br />";
$sql = "SELECT * FROM `U336282`.`trade_shs_items` ORDER BY `id` ASC";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
echo "<a href='http://vengeance-rpg.com/v/action.php?tatbuy=".$row['item_id']."' title='Price: ".ceil(get_item_cost($row['item_id']) / 2)." gold'><img title=\"".$title."\" alt=\"".$title."\" src='http://www.vengeance-rpg.com/v/images/items/" . $row['item_id'] . ".png' /></a> ";
}
}
function count_shs_items()
{
global $db, $user;
$sql = "SELECT COUNT(*) AS `bcount` FROM `U336282`.`trade_shs_items`";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
return $row['bcount'];
}
}
// TRADING TRADING TRADING TRADING
function list_cache()
{
global $db, $user;
$sql = "SELECT * FROM `U336282`.`trade_cache` WHERE user_id='".$user->data['user_id']."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
echo "<a href='http://vengeance-rpg.com/v/action.php?tradeto=".$_GET['tradeto']."&tradecachedel=".$row['item_id']."' title='Remove item from trade'><img src='http://www.vengeance-rpg.com/v/images/items/" . $row['item_id'] . ".png' /></a> ";
}
}
function list_items_to_cache()
{
global $db, $user, $config, $cache;
$sql = "SELECT * FROM `U336282`.`guildwars_owneditems` WHERE user_id='".$user->data['user_id']."' ";
$result = $db->sql_query($sql);
$array = array();
$i = 0;
while ($row = $db->sql_fetchrow($result))
{
$j = $row['item_id'];
$array[$i] = $j;
$i++;
}
for ($i=0; $i>count($array); $i++)
{
$array[$i] = get_item_data($array[$i]);
}
for ($i = 0; $i < count($array); $i++)
{
if ($array[$i] != "0") {
echo "<a href='http://vengeance-rpg.com/v/action.php?tradeto=".$_GET['tradeto']."&tradecacheadd=".$array[$i]."' title='Add item to trade'><img src='http://www.vengeance-rpg.com/v/images/items/" . $array[$i] . ".png' /></a> "; }
}
}
function add_to_cache($id)
{
global $user, $db;
$count = 0;
$to_id = (int)$_GET['tradeto'];
$sql = "SELECT COUNT(*) AS counted FROM `U336282`.`trade_cache` WHERE user_id='".$id."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { $count = $row['counted']; }
if ((int)$count < 8)
{
if (item_owned($id))
{
$sql = "SELECT * FROM `U336282`.`guildwars_items` WHERE id='".$id."' LIMIT 1";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$switch = $row['switch'];
$buyable = $row['buy'];
}
if (($buyable == "1") && ($switch == "0")) {
$sql = "INSERT INTO `trade_cache` (item_id, user_id) VALUES ('".$id."', '".$user->data['user_id']."')";
$db->sql_query($sql);
remove_item($id);
}
}}
header('Location: http://vengeance-rpg.com/v/page.php?p=i ... ;.$to_id.'');
}
function item_in_cache($id)
{
global $db, $user;
$sql = "SELECT * FROM `U336282`.`trade_cache` WHERE item_id='".$id."' AND user_id='".$user->data['user_id']."' LIMIT 1";
$result = $db->sql_query($sql);
while ($row2 = $db->sql_fetchrow($result))
{
if ($row2['item_id'] == $id)
{
return true;
}
else
{
return false;
}
}
}
function take_from_cache($id)
{
global $user, $db;
$to_id = (int)$_GET['tradeto'];
if (item_in_cache($id))
{
$sql = "DELETE FROM `U336282`.`trade_cache` WHERE item_id='".$id."' AND user_id='".$user->data['user_id']."' LIMIT 1";
$db->sql_query($sql);
add_item($id);
}
header('Location: http://vengeance-rpg.com/v/page.php?p=i ... ;.$to_id.'');
}
function send_trade_request($to, $from, $gold)
{
global $user, $db;
$sql = "INSERT INTO `trade_requests` (to_id, from_id, gold) VALUES ('".$to."', '".$from."', '".$gold."')";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { $tradeid = $row['id']; }
$sql = "SELECT * FROM `trade_cache` WHERE user_id='".$user->data['user_id']."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$sql = "INSERT INTO `trade_items` (item_id, user_id, trade_id) VALUES ('".$row['item_id']."', '".$user->data['user_id']."', '".$tradeid."')";
$db->sql_query($sql);
}
// clear cache
$sql = "DELETE FROM `U336282`.`trade_cache` WHERE user_id='".$user->data['user_id']."'";
$db->sql_query($sql);
}
function deny_trade_request()
{
}
function send_trade_reply($to, $from, $gold)
{
global $user, $db;
$sql = "SELECT * FROM `trade_requests` WHERE trade_id='".$tradeid."'";
$result = $db->sql_query($sql);
$reply = 0;
while ($row = $db->sql_fetchrow($result))
{
$reply = $row['reply'];
if ($reply == 1)
{
die("Trade error: this trade has already been replied to?");
}
}
$sql = "INSERT INTO `trade_reply` (to_id, from_id, gold) VALUES ('".$to."', '".$from."', '".$gold."')";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { $tradeid = $row['id']; }
$sql = "SELECT * FROM `trade_cache` WHERE user_id='".$user->data['user_id']."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$sql = "INSERT INTO `trade_replyitems` (item_id, user_id, trade_id) VALUES ('".$row['item_id']."', '".$user->data['user_id']."', '".$tradeid."')";
$db->sql_query($sql);
}
// clear cache
$sql = "DELETE FROM `U336282`.`trade_cache` WHERE user_id='".$user->data['user_id']."'";
$db->sql_query($sql);
}
function deny_trade_reply()
{
}
function accept_trade_reply($tradeid)
{
global $db, $user;
$reply = 0;
$sql = "SELECT * FROM `trade_requests` WHERE trade_id='".$tradeid."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$reply = $row['reply'];
if ($reply == 0)
{
die("Trade error: this trade has not been replied to?");
}
$to = $row['to_id'];
$from = $row['from_id'];
add_gold($row['gold'], $to);
}
$sql = "SELECT * FROM `trade_reply` WHERE trade_id='".$tradeid."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
add_gold($row['gold'], $from);
}
$sql = "SELECT * FROM `trade_items` WHERE trade_id='".$tradeid."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
add_item($row['item_id'], $to);
}
$sql = "SELECT * FROM `trade_replyitems` WHERE trade_id='".$tradeid."'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
add_item($row['item_id'], $from);
}
$sql = "DELETE FROM `U336282`.`trade_items` WHERE trade_id='".$tradeid."'";
$db->sql_query($sql);
$sql = "DELETE FROM `U336282`.`trade_replyitems` WHERE trade_id='".$tradeid."'";
$db->sql_query($sql);
$sql = "DELETE FROM `U336282`.`trade_reply` WHERE trade_id='".$tradeid."'";
$db->sql_query($sql);
$sql = "DELETE FROM `U336282`.`trade_requests` WHERE trade_id='".$tradeid."'";
$db->sql_query($sql);
}
?>