SMF Shop
SMFShop => Items => Topic started 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
<?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]}";
}
}
?>
-
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!
-
Nope, it looks to allow you to set which membergroup they can add themselves to when you add the item to your shop.
-
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)
<?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]}";
}
}
?>
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
-
I'll have to think about this one...most of my gorups are post count, other wise it is staff
-
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
-
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
-
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.
-
I just though I'd notify everyone that I edited the item I posted above, due to a small bug in the getAddInput() function.
-
I'm new to this.. Could someone please tell me how to add this item?
Sorry for my stupidity... :-\
-
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.)?
-
Thanks-- I think I got it.
-
Hey, it's PSPXavier! Wheres your Forum!? haven't talked to you in a while!
-
Oh, and by the way guys, a similar item is included in SMFShop 3.0, it's just not added by default :)
-
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.
-
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
<?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]}!!";
}
}
?>
-
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 !
-
Never mind i figured out 8)
-
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?
-
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?