226
Items / Item Transfers.
« on: April 26, 2006, 09:13:38 am »
I was board again. And so using my newfound knowledge of what $context does.... 3 easy steps to get item transfers working on your forum
1) Open shop.php and insert:
this should go right before the
Next, open shop.tempelate.php and insert
You also need to find this line of code:
After it.
Lastly, open shop.english.php and insert these four lines pretty much anywhere in the file.
Save/upload everything, and you should be able to transfer items from account to account without using the trade center.
1) Open shop.php and insert:
Code: [Select]
elseif($_GET['do'] == "senditems") {
$context['linktree'][] = array(
'url' => "$scripturl?action=shop;do=senditems",
'name' => $txt['shop_send_money'],
);
$result = db_query("SELECT it.name, inv.id AS ivid, inv.trading
FROM {$db_prefix}shop_inventory AS inv, {$db_prefix}shop_items AS it
WHERE inv.ownerid = {$ID_MEMBER} AND inv.itemid = it.id AND inv.trading = 0
GROUP BY it.id
ORDER BY it.name ASC ", __FILE__, __LINE__);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$context['shop_trade_items'] .= "
<option value ={$row['ivid']}>{$row['name']}</option>";
}
$context['sub_template'] = "sendItems";
loadTemplate('Shop');
} elseif($_GET['do'] == "senditems2") {
$context['linktree'][] = array(
'url' => "$scripturl?action=shop;do=senditems2",
'name' => $txt['shop_send_money'],
);
$result = db_query("SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE memberName = '{$_POST['membername']}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$newowner = $row['ID_MEMBER'];
$result = db_query("SELECT ownerid, itemid
FROM {$db_prefix}shop_inventory
WHERE id = '{$_POST['giftid']}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$itemid = $row['itemid'];
if ($row['ownerid'] !== $ID_MEMBER) {
die($txt['shop_use_others_item']);
}
else {
$result = db_query("UPDATE {$db_prefix}shop_inventory
SET ownerid = $newowner
WHERE id = '{$_POST['giftid']}'", __FILE__, __LINE__);
$context['shop_buy_message'] = "Item succesfully transfered!";
$result = db_query("SELECT name
FROM {$db_prefix}shop_items
WHERE id = {$itemid}", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$name = $row['name'];
$result = db_query("SELECT memberName
FROM {$db_prefix}members
WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$target = $row['memberName'];
$pmfrom = array(
'id' => '1',
'name' => 'Clucky',
'username' => 'Clucky'
);
$pmto = array(
'to' => array($newowner),
'bcc' => array()
);
sendpm($pmto, 'You have been sent an item!', "{$target} has sent you an {$name}. Isn't that nice of them? [i]You do not need to reply to this automated message[/i]", 0, $pmfrom);
}
$context['sub_template'] = "message";
loadTemplate('Shop');
}
this should go right before the
Code: [Select]
else {
die("What do I do with {$_GET['do']}? HUH????");
}
}
function formatMoney($money) {
global $modSettings;
$money = (int) $money;
return $modSettings['shopCurrencyPrefix'].$money.$modSettings['shopCurrencySuffix'];
}
?>
Which ends the file.Next, open shop.tempelate.php and insert
Code: [Select]
function template_sendItems() {
global $txt, $context, $modSettings, $scripturl, $settings;
shop_header();
echo <<<EOT
<table width="100%" cellpadding="5" cellspacing="0" border="0" class="tborder" style="margin-top: 1.5ex;">
<tr valign='top' class='windowbg2'>
<td style='padding-bottom: 2ex;' width='20%'>
<center><b>{$txt['shop_send_items']}</b></center><br />{$txt['shop_send_items_message']}
<form action="$scripturl?action=shop;do=senditems2" method="POST">
{$txt['shop_member_name']}: <input type="text" name="membername" size="25">
<a href="{$scripturl}?action=findmember;input=membername;quote=1;sesc={$context['session_id']}" onclick="return reqWin(this.href, 350, 400);"><img src="{$settings['images_url']}/icons/assist.gif" border="0" alt="{$txt['find_members']}" /> Find Members</a><br />
{$txt['shop_item_to_send']}:
<select name="giftid">
{$context['shop_trade_items']}
</select>
{$txt['shop_send_message_to_give']}: <textarea name="message" cols="50" rows="5"></textarea><br />
<input type="submit" value="{$txt['shop_send_items']}">
</form>
</td>
</tr>
</table>
EOT;
shop_footer();
}
Right before the ?> that ends the file. You also need to find this line of code:
Code: [Select]
<a href='$scripturl?action=shop;do=invother'>{$txt['shop_invother']}</a><br />
and insertCode: [Select]
<a href='$scripturl?action=shop;do=senditems'>{$txt['shop_senditems']}</a><br />
After it.
Lastly, open shop.english.php and insert these four lines pretty much anywhere in the file.
Code: [Select]
$txt['shop_send_items'] = "Send a item to someone";
$txt['shop_send_items_message'] = "You can use this to give an item to someone. This can also be used for item - item trades. If you wish to sell an item, please use the trade center. You cannot sell an item that you are currently trading";
$txt['shop_item_to_send'] = "Item to send:";
$txt['shop_senditems'] = "Items transfer center";
Save/upload everything, and you should be able to transfer items from account to account without using the trade center.