SMF Shop
SMFShop => Items => Topic started by: Basil Beard 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:
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
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
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:
<a href='$scripturl?action=shop;do=invother'>{$txt['shop_invother']}</a><br />
and insert
<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.
$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.
-
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.
-
Thanks =). Btw, I realised that I forot to include the message in the PM. Thus you might want to change the:
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
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);
-
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
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 ?
-
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.
-
Ok i will try again from scratch and see what happens. I will let you know how i get on O0
-
Is there even a line 1928 in Shop.php? :S I don't remember my code getting *that* big :P
-
Good point. I have added a couple of things to my shop.php and its just over 1000 lines. Very strange tazpot o_0
-
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.
-
I use Dreamweaver at the moment (which isn't free, unfortunately), but I used to use ConTEXT (http://context.cx), as it was recommended to me by [Unknown] (former SMF lead developer). You could try it if you want.
-
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
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.
<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
-
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
-
Ahhh! I see
} 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
}
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
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.
-
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
Fatal error: Call to undefined function: sendpm() in /home/sitename/public_html/smf/Sources/shop/Shop.php on line 1026
Which is this line
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?
-
That error means that the function 'sendpm' doesn't exist... What is sendpm, exactly? And where is it defined?
-
Oh silly me. Thats right. I had already included all the stuff for the sendpm function for prior coding I had done and then forgotten about it :-P.
Just like with the send pm items, all you need to do is add
global $sourcedir;
require_once($sourcedir . '/Subs-Post.php');
at the top of your shop.php file below the <?php line.
Sorry about that :P
-
:D Thanks basil i will try it now. O0
Update : Just the ticket all works fine now. Once again Thanks guy's 8)
-
ok...made all of the edits...shop loads, but when i send the item to someone i get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = '82'' at line 3
File: /home/www/forum.technodragon.net/Sources/shop/Shop.php
Line: 1007
what do i need to edit to fix this?
-
Can you post the section of code around line 1007 and tell us which line it is. :)
-
Sure, here ya go:
else {
$result = db_query("UPDATE {$db_prefix}shop_inventory
SET ownerid = $newowner
WHERE id = '{$_POST['giftid']}'", __FILE__, __LINE__); <---- Line 1007
$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'
-
I think Basil has put an extra exclamation mark after giftidso you have
this
WHERE id = '{$_POST['giftid']}'", __FILE__, __LINE__);
and need this
WHERE id = '{$_POST['giftid']}", __FILE__, __LINE__);
but save you origional and test this before deleting it :)
-
Didn't work...it seems to be trying to create a new id that does not exist. 82 is not a user id that exists...only goes to 81 right now
-
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'
Thought I had adressed this already. That change should hopefully fix it. 82 is the id number of the item, not a person.
-
ok...figured out a problem with this (it works nearly perfectly). However, if a member has a diferent display name than their login then it errors out because that member does not exist. Example: member has a login of booger, but display is snot...when you lookup a member to send it to it shows snot, when you send the item, it thinks the member doesn't exist because there is no member name of snot, only booger. Where is the code do i need to change this. When i put the member name in the box it sends without a problem.
-
Yeah. I know. My guess is to change that you would need to change the memberName line to whatever the display name is called in the database.
-
this may sound like an innane question...but what line does the change need to be done to?
-
Never mind...found the line, made the change, works perfectly!
-
hi
technodragon can u share that bit of code with us? thanks :D
also i have a question for basil.... how come it shows my name as "Clucky" after I send an item? lol
is there someway to how my normal username rather than clucky ?
-
Find this bit of code and change the bold piece to realName:
);
$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']);
}
for the clucky name part look for this:
$pmfrom = array(
'id' => '1',
'name' => 'Clucky',
'username' => 'Clucky'
just change the name to whatever you like.
-
wow thanks - would u believe it i was JUSt posting a PM to u on SMF arcade where u are currently online as I type this lol
i just came to check which thread it was and viola a reply
thank u so much :D
-
Any time!
P.S> Are you stalking me? ;D
-
I am getting this error, after reading through this entire thread and making changes mentioned along the way.
Parse error: syntax error, unexpected T_ELSEIF in /home/mamma/public_html/ndmcommunity/Sources/shop/Shop.php on line 967
This is the line
elseif($_GET['do'] = "senditems") {
Can someone help?
-
Ok now it's telling me that line 967 is
$row = mysql_fetch_array($result, MYSQL_ASSOC);
-
sounds like the file got corrupted during upload to your server...try uploading it again to see what happens
-
I did, I have done so several time's. It's not working =(
-
can you post the full page code for us to look at? it might help to understand where the error is. O0
-
Here is the link to the whole file
http://h1.ripway.com/xmetalmamax/Shop.php
-
that's not what he meant...he meant copy the code out of your file and paste it here in the post
-
Uh, it exceeds the allowed max characters.... :buck2:
-
And if you're asking for the shop code... it is the same thing taken from this thread... on the 1st page.... about a few post down, not the first post, but th eone that was supposedly corrected =/
-
then zip up the file and attach it to your post...the link tries to actually load the page
-
How's this?
-
Try this and see if it works for ya.
-
*sigh* It's giving me the same error. Screw it.
-
Check to see that you have the shop mod installed correctyl of the right version...the reason i say that, is that file works flawlessly on my shop...
-
If you like, you can paste large chunks of code at http://pastebin.dansoftaustralia.net/ (which is great for debugging, you can change someone's code, and get a DIFF showing what you've changed :D)
-
Thank you Daniel. I posted it on that... The error is still on line 967. So, what do I do after I put the code in this debugging thing?
-
I don't know how much more clear I can make this. I have re-done everything from the begginning, read this post more times than I should have. And it is telling me that THIS line 967 IS the problem. It never changes
elseif($_GET['do'] == "senditems") {
That is line 967, according to conTEXT AND the link that Daniel provided me with.
This is the error that it's giving me
Parse error: syntax error, unexpected T_ELSEIF in /home/angel25/public_html/ndmcommunity/Sources/shop/Shop.php on line 967
Every time, all the time. Re doing the code, didn't work. There is something wrong with that line!
-
hvymtalmama, please try this version of the code, and see if it solves your problem: http://pastebin.dansoftaustralia.net/35.dsa
-
Thanks for replying Daniel, but I don't need it now. I have decided that SMF is not for me. And to switch software. The staff at the SMF website, are worthless. And there are more problems with the software than I need to deal with .
-
This functionality is built into the latest SMFShop release (SMFShop 2.2, Build 10) :)