Author Topic: Change Member Group  (Read 15251 times)

Offline dcd119

Change Member Group
« 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]}";
    }

}

?>


Offline TechnoDragon

Re: Change Member Group
« Reply #1 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!
Don't tell me to get into shape...I have a shape...It is round!


Offline chadk

Re: Change Member Group
« Reply #2 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.
« Last Edit: September 27, 2006, 03:25:11 am by chadk »

Offline Daniel15

Re: Change Member Group
« Reply #3 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
« Last Edit: October 06, 2006, 06:51:28 pm by daniel15 »

Offline TechnoDragon

Re: Change Member Group
« Reply #4 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
Don't tell me to get into shape...I have a shape...It is round!


Offline dcd119

Re: Change Member Group
« Reply #5 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

Offline TechnoDragon

Re: Change Member Group
« Reply #6 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
Don't tell me to get into shape...I have a shape...It is round!


Offline Daniel15

Re: Change Member Group
« Reply #7 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.

Offline Daniel15

Re: Change Member Group
« Reply #8 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.

Offline PSPXavier

Re: Change Member Group
« Reply #9 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...  :-\

Offline Daniel15

Re: Change Member Group
« Reply #10 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.)?

Offline PSPXavier

Re: Change Member Group
« Reply #11 on: October 18, 2006, 10:37:09 am »
Thanks-- I think I got it.

Offline Maniakc

Re: Change Member Group
« Reply #12 on: February 18, 2007, 02:09:56 am »
Hey, it's PSPXavier! Wheres your Forum!? haven't talked to you in a while!

Offline Daniel15

Re: Change Member Group
« Reply #13 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 :)

Offline celadore

Re: Change Member Group
« Reply #14 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.