Author Topic: Item Transfers.  (Read 33152 times)

Offline Basil Beard

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:

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 insert
Code: [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.

 
Arrrrr!

Offline Daniel15

Re: Item Transfers.
« Reply #1 on: April 26, 2006, 07:43:03 pm »
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.

Offline Basil Beard

Re: Item Transfers.
« Reply #2 on: April 27, 2006, 04:35:35 am »
Thanks =). Btw, I realised that I forot to include the message in the PM. Thus you might want to change the:

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

to
Code: [Select]
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);
Arrrrr!

Offline tazpot

Re: Item Transfers.
« Reply #3 on: April 27, 2006, 06:40:36 am »
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: [Select]
Parse error: syntax error, unexpected T_ELSEIF in /home/site_name/public_html/smf/Sources/shop/Shop.php on line 1928
 :)the benefits of backing things up pay's off again :) but have you any ideas guy's ?
« Last Edit: April 27, 2006, 07:07:31 am by tazpot »

Offline Basil Beard

Re: Item Transfers.
« Reply #4 on: April 28, 2006, 05:32:37 am »
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.
Arrrrr!

Offline tazpot

Re: Item Transfers.
« Reply #5 on: April 28, 2006, 08:14:07 am »
Ok i will try again from scratch and see what happens. I will let you know how i get on  O0

Offline Daniel15

Re: Item Transfers.
« Reply #6 on: April 28, 2006, 09:11:46 pm »
Is there even a line 1928 in Shop.php? :S I don't remember my code getting *that* big :P

Offline Basil Beard

Re: Item Transfers.
« Reply #7 on: April 28, 2006, 10:55:43 pm »
Good point. I have added a couple of things to my shop.php and its just over 1000 lines. Very strange tazpot o_0
Arrrrr!

Offline tazpot

Re: Item Transfers.
« Reply #8 on: April 29, 2006, 06:04:59 am »
My fault i used coffeecup direct ftp to edit the php files and it has added blank lines all over the place. That will teach me for being a smart arse.

Can you guy's recomend a nice quick php editor? something with the line numbers on the side.

Offline Daniel15

Re: Item Transfers.
« Reply #9 on: April 29, 2006, 11:59:11 am »
I use Dreamweaver at the moment (which isn't free, unfortunately), but I used to use ConTEXT, as it was recommended to me by [Unknown] (former SMF lead developer). You could try it if you want.

Offline tazpot

Re: Item Transfers.
« Reply #10 on: April 30, 2006, 02:05:41 am »
Yeah i have dreamweaver too but it takes a while to start up for little jobs so i will try  conTEXT     thanks daniel  O0

Ok i tried again but still get a white page with this error
Code: [Select]
Parse error: syntax error, unexpected T_ELSEIF in /home/sitename/public_html/smf/Sources/shop/Shop.php on line 964
Also i changed the '  into " on this line.

Code: [Select]
<a href= HERE ' HERE $scripturl?action=shop;do=senditems HERE ' HERE >{$txt['shop_senditems']}</a><br />
I don't know if it would have caused an error and i know it's not connected to that fault message but i tried it both ways anyway
« Last Edit: April 30, 2006, 03:01:08 am by tazpot »

Offline tazpot

Re: Item Transfers.
« Reply #11 on: May 03, 2006, 08:15:44 am »
 O0 Context is great ! just what i was looking for.

My problem is still there though but now it's at line 966. Is there any chance one of you could just check my code and see if you can spot the problem? i will attatch it as a txt file.  Thanks

Offline Basil Beard

Re: Item Transfers.
« Reply #12 on: May 03, 2006, 09:26:02 am »
Ahhh! I see

Code: [Select]
        } elseif ($_GET['do'] == "senditems") {
Thats line 966. If you use any good text editor, it can display line numbers. Looking at that line, as well as line 964

Code: [Select]
         }
You'll see you ended the last elseif statment twice, in effect ending the larger function. When it then can across another elseif it didn't know what to do.


Anyways, there were a few errors in my coee. Should look like

Code: [Select]
elseif($_GET['do'] == "senditems") {
        $context['linktree'][] = array(
            'url' => "$scripturl?action=shop;do=senditems",
            'name' => $txt['shop_send_money'],
        );
        $context['shop_trade_items'] = "";
        $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');

    }

Basically the .= adds stuff on. So if $dog was the string "Puppy" then $dog .= "dog" would make $dog "Puppydog". We need this to get the drop down menu to work, but I forgot to set the varaible equal to the null string before hand. While the code read fine and all that, it isn't a really good thing to do and generated an error in the logs ever time you tried to send items.
Arrrrr!

Offline tazpot

Re: Item Transfers.
« Reply #13 on: May 03, 2006, 09:50:57 am »
 O0 I see now  i will change that and try again  O0  thanks Basil

Update:  I have done that and all seemed well until i tried to send an item and had the following

Code: [Select]
Fatal error: Call to undefined function: sendpm() in /home/sitename/public_html/smf/Sources/shop/Shop.php on line 1026
Which is this line

Code: [Select]
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);
Which looks ok to me except for the $target which i don't understand?
« Last Edit: May 03, 2006, 10:18:11 am by tazpot »

Offline Daniel15

Re: Item Transfers.
« Reply #14 on: May 05, 2006, 09:28:01 pm »
That error means that the function 'sendpm' doesn't exist... What is sendpm, exactly? And where is it defined?