Author Topic: [ITEM] I need help making my item work the way I want it to  (Read 6198 times)

Offline brianjw

[ITEM] I need help making my item work the way I want it to
« on: November 29, 2007, 08:08:10 am »
I have made a teddy bear item based off testitem2.php, so I am using this code:
Code attached at end of post

Anyway, I am trying to make it so this teddy bear item automatically sends a pm to the member who is using the item after completing the input, and it sends to them as a guest with the guest name of the name they selected during the input. And I can choose the contents of the pm.

Code: [Select]
<?php
/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2007-01-18 19:26:55 +1100 (Thu, 18 Jan 2007)                          $ *
* $Id:: testitem2.php 79 2007-01-18 08:26:55Z daniel15                          $ *
* Software by:                DanSoft Australia (http://www.dansoftaustralia.net/)*
* Copyright 2005-2007 by:     DanSoft Australia (http://www.dansoftaustralia.net/)*
* Support, News, Updates at:  http://www.dansoftaustralia.net/                    *
*                                                                                 *
* Forum software by:          Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version of the license can always be found at                        *
* http://www.simplemachines.org.                                                  *
**********************************************************************************/

// This is just to make sure that the item is used through SMF, and people aren't accessing it directly
// Additionally, this is used elsewhere in SMF (in almost all the files)
if (!defined('SMF'))
die('Hacking attempt...');

/*
 * This is a test item that gets some input from the person using it. 
 * Most likely, you'll base your item off this one.
 * Note that all items should try to follow the SMF Coding Guidelines, available
 * from http://custom.simplemachines.org/mods/guidelines.php
 *
 * Your class should always be called item_filename, eg. if your file is 
 * myCoolItem.php then the class should be called 'item_myCoolItem'. This 
 * class should always extend itemTemplate.
 */
class item_teddy extends itemTemplate
{
// When this function is called, you should set all the item's
// variables (see inside this example)
function getItemDetails() {

// The author's name
$this->authorName 'brianjw';
// The author's email address
$this->authorEmail 'brianjw@verizon.net';
// The author's website
$this->authorWeb 'http://www.gamerzgarage.com';

// --- Values changeable from within the SMFShop admin panel ---
// The name of the item
$this->name "Teddy Bear";
// The item's description
$this->desc "Buy a Teddy Bear! You may also choose for your teddy bear to hang out in your pm box, so you can visit it.";
// The item's price
$this->price 100;

// --- Unchageable values ---
// These values can not be changed when adding the item, they are stuck on what you set them to here.

// Whether inputs are required by this item. In this case, we get some inputs,
// so set this to 'true'.
$this->require_input true;
// Set this to 'false' if the item is unusable. This is good for display
// items.
$this->can_use_item true;
}

/*
 * This function is called when the user tries to use the item.
 * If your item needs any further user input then you can get that 
 * input here (eg. if it's a "Change username" item then you have
 * to ask the user what they'd like to change their username to).
 * Any text you return will get shown to the user (DON'T ECHO STUFF).
 */
function getUseInput()
{
return '<b>Name your teddy bear:</b> <input type="text" name="teddy_name" /><br /><b>Would you like your teddy bear to hang out with you in your pm box?</b> <input type="radio" name="teddy_pm" value="So I am glad you chose for me to be placed in your pm box (pm the admin to make it work)." />Yes -- <input type="radio" name="teddy_pm" value="So you chosed for me to not be placed in your pm box, so I will be sent back to the shop where another member will take me and care for me." />No';
}

// This is where all the fun begins. This function is called when 
// the user actually uses the item. Return stuff, DON'T ECHO!
function onUse()
{
return '<b>' $_POST['teddy_name'] . ' is speaking (your teddy bear):</b><br><br>Hello, my name is ' $_POST['teddy_name'] . '!<br>I am your teddy bear and my favorite things to do are to be loved and cared for. ' $_POST['teddy_pm'] . '';
}
}

?>


Thanks in advance :),
brianjw

Offline Dark_Zero

Re: [ITEM] I need help making my item work the way I want it to
« Reply #1 on: November 30, 2007, 04:43:39 am »
i think sendpm() will do the trick for you :)

in getUseInput(),  after setting the teddy bear's name to post, (using method="post") in the $from parameter of sendpm(), use $_POST['teddy_name'] to use the teddy's name.

am i right or am i right? :D (i'm a php beginner, sorry :P )
« Last Edit: November 30, 2007, 04:58:42 am by Dark_Zero »

Offline brianjw

Re: [ITEM] I need help making my item work the way I want it to
« Reply #2 on: November 30, 2007, 06:34:17 am »
I am not smart enough to know what to do with all those functions lol. :P I don't know php a well enough.
Do you think you can post the complete code needed to do it and tell me like what to find in my code and then to add before/under or replace, lol - like the mod parser ;)?

Offline brianjw

Re: [ITEM] I need help making my item work the way I want it to
« Reply #3 on: December 03, 2007, 12:43:42 am »
bump

Offline Daniel15

Re: [ITEM] I need help making my item work the way I want it to
« Reply #4 on: December 03, 2007, 12:07:35 pm »
Hopefully this should work:
Code: [Select]
<?php
// This is just to make sure that the item is used through SMF, and people aren't accessing it directly
// Additionally, this is used elsewhere in SMF (in almost all the files)
if (!defined('SMF'))
die('Hacking attempt...');


class 
item_teddy extends itemTemplate
{
// When this function is called, you should set all the item's
// variables (see inside this example)
function getItemDetails() {

// The author's name
$this->authorName 'brianjw';
// The author's email address
$this->authorEmail 'brianjw@verizon.net';
// The author's website
$this->authorWeb 'http://www.gamerzgarage.com';

// --- Values changeable from within the SMFShop admin panel ---
// The name of the item
$this->name "Teddy Bear";
// The item's description
$this->desc "Buy a Teddy Bear! You may also choose for your teddy bear to hang out in your pm box, so you can visit it.";
// The item's price
$this->price 100;

// --- Unchageable values ---
// These values can not be changed when adding the item, they are stuck on what you set them to here.

// Whether inputs are required by this item. In this case, we get some inputs,
// so set this to 'true'.
$this->require_input true;
// Set this to 'false' if the item is unusable. This is good for display
// items.
$this->can_use_item true;
}

/*
 * This function is called when the user tries to use the item.
 * If your item needs any further user input then you can get that 
 * input here (eg. if it's a "Change username" item then you have
 * to ask the user what they'd like to change their username to).
 * Any text you return will get shown to the user (DON'T ECHO STUFF).
 */
function getUseInput()
{
return '<b>Name your teddy bear:</b> <input type="text" name="teddy_name" /><br /><b>Would you like your teddy bear to hang out with you in your pm box?</b> <input type="radio" name="teddy_pm" value="So I am glad you chose for me to be placed in your pm box (pm the admin to make it work)." />Yes -- <input type="radio" name="teddy_pm" value="So you chosed for me to not be placed in your pm box, so I will be sent back to the shop where another member will take me and care for me." />No';
}

// This is where all the fun begins. This function is called when 
// the user actually uses the item. Return stuff, DON'T ECHO!
function onUse()
{
require_once('Sources/Subs-Post.php');

// Who is sending the IM
$pmfrom = array(
'id' => 0,
'name' => $_POST['teddy_name'],
'username' => $_POST['teddy_name']
);

// Who is receiving the IM
$pmto = array(
'to' => array($context['user']['id']),
'bcc' => array()
);
// The message subject
$subject 'Subject';
// The actual message
$message $_POST['teddy_pm'];
// Send the PM
sendpm($pmto$subject$message0$pmfrom);

return '<b>' $_POST['teddy_name'] . ' is speaking (your teddy bear):</b><br><br>Hello, my name is ' $_POST['teddy_name'] . '!<br>I am your teddy bear and my favorite things to do are to be loved and cared for. ' $_POST['teddy_pm'] . '';
}
}

?>


Offline brianjw

Re: [ITEM] I need help making my item work the way I want it to
« Reply #5 on: December 04, 2007, 06:17:08 am »
I get this error when trying to use it,
Quote
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 ')
ORDER BY mem.lngfile
LIMIT 0' at line 8
File: /home/content/b/j/w/bjwilson/html/Sources/Subs-Post.php
Line: 809

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.4, while your database is at version 1.1.2. The above error might possibly go away if you execute the latest version of upgrade.php.
brianjw

Offline brianjw

Re: [ITEM] I need help making my item work the way I want it to
« Reply #6 on: December 10, 2007, 11:02:56 am »
BUMP ;)

Offline Daniel15

Re: [ITEM] I need help making my item work the way I want it to
« Reply #7 on: December 17, 2007, 04:01:20 pm »
Does that error happen no matter what value you use for "Name your teddy bear"?

At the bottom of Settings.php, right above the ?>, add this:
Code: [Select]
$db_show_debug = true;

Then, try it again. When the error occurs, it should show the whole query. Post the query here :)

Offline brianjw

Re: [ITEM] I need help making my item work the way I want it to
« Reply #8 on: December 18, 2007, 11:06:08 am »
Ok, definitely will do this tomorrow. Just reading posts for now. :)

Offline brianjw

Re: [ITEM] I need help making my item work the way I want it to
« Reply #9 on: December 27, 2007, 10:51:25 pm »
The entire error I get during this:
Quote
Database 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 ')
ORDER BY mem.lngfile
LIMIT 0' at line 8
File: /-------/Sources/Subs-Post.php
Line: 809

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.4, while your database is at version 1.1.2. The above error might possibly go away if you execute the latest version of upgrade.php.


SELECT
mem.memberName, mem.realName, mem.ID_MEMBER, mem.emailAddress, mem.lngfile, mg.maxMessages,
mem.pm_email_notify, mem.instantMessages, 0 AS ignored,
FIND_IN_SET(0, mem.buddy_list) AS is_buddy, mem.is_activated,
(mem.ID_GROUP = 1 OR FIND_IN_SET(1, mem.additionalGroups)) AS is_admin
FROM smf_members AS mem
LEFT JOIN smf_membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE mem.ID_MEMBER IN ()
ORDER BY mem.lngfile
LIMIT 0

Offline Daniel15

Re: [ITEM] I need help making my item work the way I want it to
« Reply #10 on: January 05, 2008, 01:20:50 pm »
Ohhh, I'm stupid :P
Find:
Code: [Select]
function onUse()
{
Add after:
Code: [Select]
global $context;
That should fix it :)