SMFShop > Items

Item Transfers.

(1/11) > >>

Basil Beard:
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:


--- Code: ---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');

    }
--- End code ---

this should go right before the

--- Code: ---     else {
        die("What do I do with {$_GET['do']}? HUH????");
    }
}


function formatMoney($money) {
    global $modSettings;

    $money = (int) $money;
    return $modSettings['shopCurrencyPrefix'].$money.$modSettings['shopCurrencySuffix'];
}
?>

--- End code ---
Which ends the file.

Next, open shop.tempelate.php and insert

--- Code: ---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();
}

--- End code ---
Right before the ?> that ends the file.

You also need to find this line of code:

--- Code: --- <a href='$scripturl?action=shop;do=invother'>{$txt['shop_invother']}</a><br />

--- End code ---
and insert

--- Code: --- <a href='$scripturl?action=shop;do=senditems'>{$txt['shop_senditems']}</a><br />

--- End code ---

After it.

Lastly, open shop.english.php and insert these four lines pretty much anywhere in the file.

--- Code: ---$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";

--- End code ---

Save/upload everything, and you should be able to transfer items from account to account without using the trade center.

 

Daniel15:
Thanks Basil Beard! That was actually one of the features planned for the next version of SMFShop. Maybe I'll use some of your code for it.

Basil Beard:
Thanks =). Btw, I realised that I forot to include the message in the PM. Thus you might want to change the:


--- Code: ---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);

--- End code ---

to

--- Code: ---sendpm($pmto, 'You have been sent an item!', "{$target} has sent you an {$name}. Isn't that nice of them? They have attached the following message: [quote] {$_POST['message']} [/quote] [i]You do not need to reply to this automated message[/i]", 0, $pmfrom);
--- End code ---

tazpot:
Maybe im daft but i can't seem to find either  shop.template.php  or  shop.english.php  ???


Modify.....Silly me i found them    themes/default/shop.template.php   it's late at night and my brain hurts. ;D

But after editing the code i had this white page with this error when opening the shop

--- Code: ---Parse error: syntax error, unexpected T_ELSEIF in /home/site_name/public_html/smf/Sources/shop/Shop.php on line 1928
--- End code ---

 :)the benefits of backing things up pay's off again :) but have you any ideas guy's ?

Basil Beard:
that was after editing the code?

I donno, probably a mistake in copying it over or something. Best thing to do would be to get rid of it, or to show someone that potion(the stuff around line1928) of your code.

Navigation

[0] Message Index

[#] Next page

Go to full version