Save this as AddMembergroup.php under shop items.
I wanted to allow users to purchase additional membergroups. The only solutions I found were the ChangeMembergroup in default SMF 3.0 and the BuyMembergroup by Chad (which didn;t work for me). So I used both these to create a AddMembergroup item (I have only been using SMFShop for 20 minutes, but it appears to work for me).
What the Buyer gets: The member who uses this item will have himself ADDED to the 1 membergroup for which the item was set-up for. It will leave his primary membergroup unchanged. The user does NOT get to choose which membergroup he wants to be added to NOR is he assigned to a random one.
<?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]}!!";
}
}
?>