We are having a problem:
wdm2005 has been helping me with a item for SA Shop.
The code for the item is to make 'buy' an additional Membergroup witch involves also additional member-related boards.
We have inserted this code , but there is a problem.
If a member choose to add a new (secundary) Membergroup, they loose all other one(s).
And that is not good
I'll explain:
Primary Membergroup: Trustee -> they see everything, except board 1 and 2 (membergroup 1 and 2)
Additional Membergroup:
- buy group 1
- buy group 2
The meaning is that they can buy both additional membergroups.
now, if they have bought group 1, and they buy group 2, they loose group 1 and visa versa.
They should be able to have multiple member groups.
What should i do to make it work for multiple Membergroups 2, 3 or more?
Here is the code: (look after "function onUse() {"
<?php
/**********************************************************************************
* SA Shop item *
***********************************************************************************
* SA Shop: Shop MOD for Simple Machines Forum *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under *
* the terms of the provided license as published by Simple Machines LLC. *
* *
* This program is distributed in the hope that it is and will be useful, but *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* See the "license.txt" file for details of the Simple Machines license. *
* The latest version of the license can always be found at *
* http://www.simplemachines.org. *
**********************************************************************************/
//File: AddMembergroup.php
// Item
if (!defined('SMF'))
die('Hacking attempt...');
class item_AddMembergroup extends itemTemplate
{
function getItemDetails()
{
$this->name = 'Add Membergroup';
$this->desc = 'Allows you to add yourself to a membergroup!';
$this->price = 5000;
$this->require_input = false;
$this->can_use_item = true;
}
function getAddInput()
{
global $smcFunc;
$selectBox = '<select name="info1">';
// Get all non post-based membergroups
$result = $smcFunc['db_query']('','
SELECT id_group, group_name
FROM {db_prefix}membergroups
WHERE min_Posts = -{int:id}',
array(
'id' => 1,
)
);
// For each membergroup, add it to the list
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$selectBox .= '<option value="' . $row['id_group'] . '">' . $row['group_name'] . '</option>';
}
$selectBox .= '</select>';
return 'Membergroup: '. $selectBox;
}
function onUse() {
global $smcFunc, $user_info, $item_info;
$additionalGroups = mysql_fetch_array(
$smcFunc['db_query']('','
SELECT additional_groups
FROM {db_prefix}members
WHERE id_member = {int:id}',
array('id' => $user_info['id'],
)
),MYSQL_ASSOC);
if($additionalGroups['additionalGroups']) {
$additionalGroups['additionalGroups'] = $additionalGroups['additionalGroups'].",".$item_info[1];
} else {
$additionalGroups['additionalGroups'] = $item_info[1];
}
echo $additionalGroups['additionalGroups'];
$result = $smcFunc['db_query']('','
UPDATE {db_prefix}members
SET additional_groups = {int:agp}
WHERE id_member= {int:id}',
array(
'id' => $user_info['id'],
'agp' => $additionalGroups['additionalGroups'],
)
);
return "You have joined an additional membergroup {$item_info[1]}!!";
}
}
?>
Thx in advance for looking into this.
Gtrs
N.