SMF Shop

SMFShop => Items => Topic started by: chadk on October 22, 2006, 11:23:33 pm

Title: New Item: Buy Membergroup
Post 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.


Code: [Select]
<?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($resultMYSQL_ASSOC);

while (
$row mysql_fetch_array($resultMYSQL_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]}!!";
    }
}
?>
Title: Re: New Item: Buy Membergroup
Post by: chinatown on November 16, 2006, 06:59:04 pm
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..
Title: Re: New Item: Buy Membergroup
Post by: hbixler03 on December 13, 2006, 11:23:00 am
Ok very new here, how do I add this, and where do I add this code????  Thanks for any help!
Title: Re: New Item: Buy Membergroup
Post by: Daniel15 on December 13, 2006, 12:24:47 pm
You need to place the code into a file called  BuyMembergroup.php, and upload it to the Sources/shop/items directory.
Title: Re: New Item: Buy Membergroup
Post by: CRONUS on December 19, 2006, 06:43:15 pm
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)  ::)
Title: New Item: Buy Membergroup (BUG ???)
Post by: CRONUS on December 29, 2006, 04:29:00 pm
One more thing..
when I go to "Edit/delete...item" I get this on top of the page:
Quote
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
Code: [Select]
createPost(&$msgOptions, &$topicOptions, &$posterOptions); //create the post using the SMF posting function
By the way - SMF 1.1.1
Title: Re: New Item: Buy Membergroup
Post by: CRONUS on January 04, 2007, 08:52:26 pm
http://custom.simplemachines.org/mods/index.php?mod=413

Quote
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 ;)
Title: Re: New Item: Buy Membergroup
Post by: Sakuragi on January 12, 2007, 09:00:03 pm
I want to create an item : leave Membergroup
how to change this querie to do that?
Code: [Select]
$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
Title: Re: New Item: Buy Membergroup
Post by: Sakuragi on January 13, 2007, 03:41:00 am
Code: [Select]
$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
Title: Re: New Item: Buy Membergroup
Post by: Sakuragi on January 14, 2007, 06:25:23 pm
Bump
no one can help me?
Title: Re: New Item: Buy Membergroup
Post by: dcd119 on January 15, 2007, 01:22:51 pm
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
Title: Re: New Item: Buy Membergroup
Post by: Sakuragi on January 15, 2007, 07:15:24 pm
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
Title: Re: New Item: Buy Membergroup
Post by: Sakuragi on January 19, 2007, 08:30:37 am
O found a little bug on the original code
Code: [Select]
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].", ".$groupID['ID_GROUP'];
should be

Code: [Select]
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].",".$groupID['ID_GROUP'];