SMF Shop

SMFShop => Items => Topic started by: dcd119 on September 26, 2006, 12:46:17 pm

Title: Change Member Group
Post by: dcd119 on September 26, 2006, 12:46:17 pm
I rewrote the code here to allow people to change membergroups on the forum

I called this Membergroup.php

Code: [Select]
<?php

class item_Membergroup extends itemTemplate {
    function 
getItemDetails() {
        
$this->name "Change Membergroup";
        
$this->desc "Change your Membergroup!";
        
$this->price 50000;

        
$this->require_input false;
        
$this->can_use_item true;
    }

    function 
getAddInput() {
        return 
"Membergroup: <input type='text' name='info1' value=''>";
    }

    function 
onUse() {
        global 
$db_prefix$ID_MEMBER$item_info;

        
$result db_query("UPDATE {$db_prefix}members
                            SET ID_GROUP = 
{$item_info[1]}
                            WHERE ID_MEMBER = 
{$ID_MEMBER}",
                            
__FILE____LINE__);
        return 
"Changed Member Group to {$item_info[1]}";
    }

}

?>

Title: Re: Change Member Group
Post by: TechnoDragon on September 26, 2006, 11:26:57 pm
question on this before i use it...does this allow them to change to ANY membergroup or just certain ones?

If it is any, then that is a serious security risk!
Title: Re: Change Member Group
Post by: chadk on September 27, 2006, 03:23:38 am
Nope, it looks to allow you to set which membergroup they can add themselves to when you add the item to your shop.
Title: Re: Change Member Group
Post by: Daniel15 on September 27, 2006, 08:39:01 pm
Here's an improved version of the code. This shows a dropdown box, rather than a text entry field (it's a big more user-friendly). The code used here is the same code that will be in the next SMFShop version (basically, a 'Give money to people depending on what group they're in' sort of thing)

Code: [Select]
<?php

class item_Membergroup extends itemTemplate {
    function getItemDetails() {
        $this->name "Change Membergroup";
        $this->desc "Change your Membergroup!";
        $this->price 50000;

        $this->require_input false;
        $this->can_use_item true;
    }

    function getAddInput() {
global $db_prefix;

$selectBox '<select name="info1">';

// Get all non post-based membergroups
$result db_query("SELECT ID_GROUP, groupName
FROM 
{$db_prefix}membergroups
WHERE minPosts = -1"
,
__FILE____LINE__);

// For each membergroup, add it to the list
while ($row mysql_fetch_assoc($result)) {
$selectBox .= "<option value='{$row['ID_GROUP']}'>{$row['groupName']}</option>";
}

$selectBox .= "</select>";
        return "Membergroup: ".$selectBox;
    }

    function onUse() {
        global $db_prefix$ID_MEMBER$item_info;

        $result db_query("UPDATE {$db_prefix}members
                            SET ID_GROUP = 
{$item_info[1]}
                            WHERE ID_MEMBER = 
{$ID_MEMBER}",
                            __FILE____LINE__);
        return "Changed Member Group to {$item_info[1]}";
    }

}

?>


Quote
question on this before i use it...does this allow them to change to ANY membergroup or just certain ones?
I was thinking the same thing, until I saw that the admin is prompted for the membergroup when they add the item, and not the user.

Edited by Daniel15 on 6th October 2006: Bug fix in getAddInput() function
Title: Re: Change Member Group
Post by: TechnoDragon on September 28, 2006, 02:11:46 pm
I'll have to think about this one...most of my gorups are post count, other wise it is staff
Title: Re: Change Member Group
Post by: dcd119 on September 30, 2006, 12:27:27 am
the idea is a membergroup that they can buy into, presetupup by the admin, for example they could by a forum shopper membergroup... that way they can be all happy they are part of the membergroup.

the forums that I run, the people love anything thats available..

Daniel: it took me a few hours to figure out ur coding in regards to SMF, this was my first attempt at creating something for SMF and SMFSHOP. Having to go into the database to figureout exactly what I am doing makes sense..

Thanks again for recoding my idea from your Code Daniel.

Much appreciated.

MJ
Title: Re: Change Member Group
Post by: TechnoDragon on September 30, 2006, 01:28:02 pm
the idea is a membergroup that they can buy into, presetupup by the admin, for example they could by a forum shopper membergroup... that way they can be all happy they are part of the membergroup.

the forums that I run, the people love anything thats available..

Daniel: it took me a few hours to figure out ur coding in regards to SMF, this was my first attempt at creating something for SMF and SMFSHOP. Having to go into the database to figureout exactly what I am doing makes sense..

Thanks again for recoding my idea from your Code Daniel.

Much appreciated.

MJ

Since you put it that way, i can see the benefit then
Title: Re: Change Member Group
Post by: Daniel15 on September 30, 2006, 03:15:02 pm
Quote
Daniel: it took me a few hours to figure out ur coding in regards to SMF, this was my first attempt at creating something for SMF and SMFSHOP. Having to go into the database to figureout exactly what I am doing makes sense..
Yeah, I'm not the best at coding :P
Anyways, when I started writing SMFShop, there wasn't any real coding documentation on SMF (like there is now)... I had to look through heaps of files to figure out how to get it working. Once you get the hang of it, it gets much easier.
Title: Re: Change Member Group
Post by: Daniel15 on October 06, 2006, 06:52:20 pm
I just though I'd notify everyone that I edited the item I posted above, due to a small bug in the getAddInput() function.
Title: Re: Change Member Group
Post by: PSPXavier on October 07, 2006, 04:55:52 am
I'm new to this.. Could someone please tell me how to add this item?

Sorry for my stupidity...  :-\
Title: Re: Change Member Group
Post by: Daniel15 on October 07, 2006, 02:12:54 pm
Hi,
 Basically, to use an item like this, grab the code posted above, and save it as 'Membergroup.php'. Then, upload the item to your Sources/shop/items/ directory. After doing all that, log on to your forum and go to the admin section, and click on the SMFShop 'Add An Item' link. The new item should now appear in the dropdown list :).

Is this enough, or would do you require more help (screenshots, etc.)?
Title: Re: Change Member Group
Post by: PSPXavier on October 18, 2006, 10:37:09 am
Thanks-- I think I got it.
Title: Re: Change Member Group
Post by: Maniakc on February 18, 2007, 02:09:56 am
Hey, it's PSPXavier! Wheres your Forum!? haven't talked to you in a while!
Title: Re: Change Member Group
Post by: Daniel15 on February 18, 2007, 01:44:22 pm
Oh, and by the way guys, a similar item is included in SMFShop 3.0, it's just not added by default :)
Title: Re: Change Member Group
Post by: celadore on March 07, 2007, 06:34:20 am
great item, however, when a user purchases this item his MAIN membergroup is changed.  What if we want to give this user access to ADDITIONAL membergroups.
Title: Re: Change Member Group
Post by: celadore on March 07, 2007, 07:11:31 am
Couldn't find a solution, so created one (based on this item and Buy Membergroup by Chad on this thread:
http://www.daniel15.com/forum/index.php/topic,369.0.html

Code: [Select]
<?php
//File: AddMembergroup.php
//      Item

//DATE: Mar 07, 2007
//Author Taj

class item_AddMembergroup extends itemTemplate {
    function 
getItemDetails() {
    
$this->authorName "Taj";

$this->authorWeb "http://www.hostadore.com/";

$this->authorEmail "admin@hostadore.com";

        
$this->name "Add Membergroup";
        
$this->desc "Allows you to add yourself to a membergroup!";
        
$this->price 1;

        
$this->require_input false;
        
$this->can_use_item true;
    }

    function 
getAddInput() {
global $db_prefix;

$selectBox '<select name="info1">';

// Get all non post-based membergroups
$result db_query("SELECT ID_GROUP, groupName
FROM 
{$db_prefix}membergroups
WHERE minPosts = -1"
,
__FILE____LINE__);

// For each membergroup, add it to the list
while ($row mysql_fetch_assoc($result)) {
$selectBox .= "<option value='{$row['ID_GROUP']}'>{$row['groupName']}</option>";
}

$selectBox .= "</select>";
        return 
"Membergroup: ".$selectBox;
    }
    

    function 
onUse() {
        global 
$db_prefix$ID_MEMBER$item_info;

$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'].", ".$item_info[1];
} else {
$additionalGroups['additionalGroups'] = $item_info[1];
}


echo 
$additionalGroups['additionalGroups'];          
        
$result db_query("UPDATE {$db_prefix}members SET additionalGroups = '{$additionalGroups['additionalGroups']}'
         WHERE ID_MEMBER=
{$ID_MEMBER}",__FILE____LINE__);

        return 
"You have joined new membergroup {$item_info[1]}!!";
    }
}
?>
Title: Re: Change Member Group
Post by: babylonking on March 20, 2007, 01:38:31 am
Nice Item, I have only one question which is: How can i have another item that will have No Primary Membergroup in drop down box.


Thanks !

Title: Re: Change Member Group
Post by: babylonking on March 20, 2007, 03:12:07 am
Never mind i figured out   8)
Title: Re: Change Member Group
Post by: Str8up-Nate on May 03, 2008, 10:10:47 am
hmmm would there be a way to make it so that when they bought this item for a secondary member group that it would only be for like 30 days? then they would be removed from the group?
Title: Re: Change Member Group
Post by: phantom111 on August 19, 2010, 05:45:23 am
hmmm would there be a way to make it so that when they bought this item for a secondary member group that it would only be for like 30 days? then they would be removed from the group?

refresh

Can someone do this?