SMF Shop
SMFShop => Items => Topic started by: chadk on October 22, 2006, 11:23:33 pm
-
Save as Sources\shop\items\BuyMembergroup.php
Look for :
/////////////NOTICE change the following ID or your item will fail.
$shophistoryID=98;//Set this to 0 if you don't have a shop history forum
and edit the 98 to your own shop history forum ID, if you don't use this feature, edit it to 0.
Enjoy.
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: BuyMembergroup.php
// Item
//VERSION: 1.0 (Build 1)
//DATE: Oct 22, 2006
//Author Chad
class item_BuyMembergroup extends itemTemplate {
function getItemDetails() {
$this->authorName = "Chad";
$this->authorWeb = "http://www.aviary.info/";
$this->authorEmail = "generalchad@gmail.com";
$this->name = "Buy Membergroup";
$this->desc = "Allows you to buy your way into a membergroup!";
$this->price = 250;
$this->require_input = false;
$this->can_use_item = true;
}
function getAddInput() {
global $db_prefix, $item_info;
$result = db_query("SELECT groupName
FROM {$db_prefix}membergroups", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$groups.=("<OPTION id='x{$i}' value='{$row[0]}'>{$row[0]}");
$i++;
}
return "Which Membergroup ID do you want to grant users access to?: <SELECT name='info1'>{$groups}</SELECT>";
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info, $user, $sourcedir;
/////////////NOTICE change the following ID or your item will fail.
$shophistoryID=98;//Set this to 0 if you don't have a shop history forum
//Begin Shop history
if ($shophistoryID) {
require_once($sourcedir . '/Subs-Post.php');
$topicOptions['board'] = $shophistoryID; //SHOP history forum
$topicOptions['id']=0; //NEW topic
$msgOptions['subject'] = "I just bought my way into the {$item_info[1]} membergroup!"; //Subject
$msgOptions['body'] = "Yep!";
$posterOptions['id']=$ID_MEMBER; //Current user's ID
createPost(&$msgOptions, &$topicOptions, &$posterOptions); //create the post using the SMF posting function
}
//End Shop history
$groupID=mysql_fetch_array(db_query("SELECT `ID_GROUP` FROM {$db_prefix}membergroups WHERE groupName = '{$item_info[1]}'", __FILE__, __LINE__),MYSQL_ASSOC);
$additionalGroups = mysql_fetch_array(db_query("SELECT `additionalGroups` FROM {$db_prefix}members WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__),MYSQL_ASSOC);
if($additionalGroups['additionalGroups']) {
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].", ".$groupID['ID_GROUP'];
} else {
$additionalGroups['additionalGroups'] = $groupID['ID_GROUP'];
}
echo $groupID['ID_GROUP'].":";
echo $additionalGroups['additionalGroups'];
$result = db_query("UPDATE {$db_prefix}members SET additionalGroups = '{$additionalGroups['additionalGroups']}'
WHERE ID_MEMBER={$ID_MEMBER}",__FILE__, __LINE__);
return "You're in the new group, {$item_info[1]}!!";
}
}
?>
-
Hi, really thanks for this.. actually i am letting my user buy a limited time access to a certain user group..
i dun think it is possible to set a time limit for the membergroup change, can i bother you to help me code it such that whenever someone uses this item, it send a pm to me so i know the date they used the item afterwhich i can decide when to remove the usergroup manually..
-
Ok very new here, how do I add this, and where do I add this code???? Thanks for any help!
-
You need to place the code into a file called BuyMembergroup.php, and upload it to the Sources/shop/items directory.
-
Hi, really thanks for this.. actually i am letting my user buy a limited time access to a certain user group..
i dun think it is possible to set a time limit for the membergroup change, can i bother you to help me code it such that whenever someone uses this item, it send a pm to me so i know the date they used the item afterwhich i can decide when to remove the usergroup manually..
I'm not good at coding so maybe anyone could look what could be done about chinatown's idea?
Ofcourse it would be better if time limit could be set when adding an item (for hour, for day, month, year) ::)
-
One more thing..
when I go to "Edit/delete...item" I get this on top of the page:
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/xxx/public_html/forum/Sources/shop/items/BuyMembergroup.php on line 62
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/xxx/public_html/forum/Sources/shop/items/BuyMembergroup.php on line 62
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/xxx/public_html/forum/Sources/shop/items/BuyMembergroup.php on line 62
Any idea?
P.S. Line 62 createPost(&$msgOptions, &$topicOptions, &$posterOptions); //create the post using the SMF posting function
By the way - SMF 1.1.1
-
http://custom.simplemachines.org/mods/index.php?mod=413
This modification will add the ability to charge users a subscription to join a membergroup for a defined period of time.
But this mod uses paypal
is it possible to rewrite it so it uses SMFShop credits?
Thanx ;)
-
I want to create an item : leave Membergroup
how to change this querie to do that?
$groupID=mysql_fetch_array(db_query("SELECT `ID_GROUP` FROM {$db_prefix}membergroups WHERE groupName = '{$item_info[1]}'", __FILE__, __LINE__),MYSQL_ASSOC);
$additionalGroups = mysql_fetch_array(db_query("SELECT `additionalGroups` FROM {$db_prefix}members WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__),MYSQL_ASSOC);
if($additionalGroups['additionalGroups']) {
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].", ".$groupID['ID_GROUP'];
} else {
$additionalGroups['additionalGroups'] = $groupID['ID_GROUP'];
}
echo $groupID['ID_GROUP'].":";
echo $additionalGroups['additionalGroups'];
$result = db_query("UPDATE {$db_prefix}members SET additionalGroups = '{$additionalGroups['additionalGroups']}'
WHERE ID_MEMBER={$ID_MEMBER}",__FILE__, __LINE__);
Thanks
-
$request = db_query("
SELECT ID_MEMBER, additionalGroups
FROM {$db_prefix}members
WHERE FIND_IN_SET($item_info[1], additionalGroups)
AND ID_MEMBER={$ID_MEMBER}",__FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
$tempGroup = array_flip(explode(',', $row['additionalGroups']));
unset($tempGroup[$item_info[1]]);
$tempGroup = implode(',', array_flip($tempGroup));
// Do the update for this member - this may be slow for lots of people... but how many you really do at once?
db_query("
UPDATE {$db_prefix}members
SET additionalGroups = '$tempGroup'
WHERE ID_MEMBER = $row[ID_MEMBER]
LIMIT 1", __FILE__, __LINE__);
}
mysql_free_result($request);
My code didn't work :-(
Unknown column 'groupName' in 'where clause'
File /public_html/smf/Sources/shop/items/LeaveMembergroup.php
Line: 71 WHERE FIND_IN_SET($item_info[1], additionalGroups)
AND ID_MEMBER={$ID_MEMBER}",__FILE__, __LINE__);
Thanks for your help
-
Bump
no one can help me?
-
actually I wrote a version of this already here: http://www.daniel15.com/forum/index.php/topic,316.0.html
the recoded post by daniel15 is the one that you want to download..
feel free to use or expand on the code from there.
MJ
-
thanks but your item change the Primary Membergroup, actually I want to change only the Additional Membergroups, chadk item's do that, what I need now is a item to do the reverse witch allow members to leave an additional Membergroup
-
O found a little bug on the original code
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].", ".$groupID['ID_GROUP'];
should be
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].",".$groupID['ID_GROUP'];