Advertisement:

Author Topic: AddMembergroup issue !!  (Read 2076 times)

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
AddMembergroup issue !!
« on: January 02, 2010, 09:16:41 PM »
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() {"
Code: [Select]
<?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.
« Last Edit: January 09, 2010, 12:35:39 PM by NeQo »

Offline

  • SMF Friend
  • SMF Legend
  • *
  • Posts: 60,725
Re: AddMembergroup issue !!
« Reply #1 on: January 02, 2010, 10:04:49 PM »
You'd probably be best asking him, actually. Most users here just don't know anything about SA Shop.
Payin' anything to roll the dice, just one more time
Some will win, some will lose, some were born to sing the blues
Oh the movie never ends
It goes on and on and on and on

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #2 on: January 03, 2010, 04:16:27 PM »
Oh, thank you very much for your meaningful answer... :-\
I wouldn't be asking here if we knew the solution.

In fact , this has nothing to do with the mod.
It was just a question so let somebody take a look and give us a little help with the $additionalGroups code.
There is something we did wrong, but don't know what.
So i thought you all know about coding, maybe somebody could help.

Many Thx

Offline

  • SMF Friend
  • SMF Legend
  • *
  • Posts: 60,725
Re: AddMembergroup issue !!
« Reply #3 on: January 03, 2010, 04:36:30 PM »
So, why are you using mysql_fetch_array, which is listed in the manual as shouldn't be being used anyway...

The reason I asked is because I still don't really understand what that's supposed to do, not to mention the fact you need to bring $smcFunc into scope, followed by calling everything through $smcFunc - never, ever using mysql_* directly.
Payin' anything to roll the dice, just one more time
Some will win, some will lose, some were born to sing the blues
Oh the movie never ends
It goes on and on and on and on

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #4 on: January 04, 2010, 01:00:31 PM »
Code: [Select]
never, ever using mysql_*Ok i see.
That is not so good then...  :-\


The meaning of this all is to let members join the forum in a basic member group, with normal boards.
With a credit system they can "buy" additional member groups.
The additional groups each have there own hidden boards.
So a user can choose the additional group randomly.
(The credit system works good and the AdditionalMembergroup is an item they can buy)
So this system works "almost" like a charm

A member can thus have the following achievable: basic status + group 1 + group 2 + group 3 + ...
The code now works as far as only 1 of the groups is added.
Basically that is good.

But when a member buys a second group, he looses the others.
And that is NOT good.
They need also to remain the previous group(s)

It is some kind of self-controlled automation of "Additional Membergroups:" in the 'Profile' page.
I really hope i gave a good explanation...

PS: it would also be ok if this works with 'Boards' instead of 'Membergroups'


Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #5 on: January 06, 2010, 12:11:29 PM »
Little bump.

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #6 on: January 08, 2010, 12:13:24 PM »
Eh... help plz!

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,509
  • Young and Foolish
    • SimplePortal
Re: AddMembergroup issue !!
« Reply #7 on: January 08, 2010, 12:34:09 PM »
Instances of $additionalGroups['additionalGroups'] should be $additionalGroups['additional_groups'] in your code, since the field name in the smf_members table is 'additional_groups' and not 'additionalGroups'.

I would suggest using addMembersToGroup() function though. It has a parameter to override permissions in SMF 2.0.

Former SMF Core Developer | My Mods | My Anime List | SimplePortal | Samanyolu Fanları

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #8 on: January 08, 2010, 06:52:36 PM »
Is that addMembersToGroup() function working for 2 RC 2.0?

Offline

  • SMF Friend
  • SMF Legend
  • *
  • Posts: 60,725
Re: AddMembergroup issue !!
« Reply #9 on: January 08, 2010, 06:54:36 PM »
Yes, it works in 2.0 RC2.
Payin' anything to roll the dice, just one more time
Some will win, some will lose, some were born to sing the blues
Oh the movie never ends
It goes on and on and on and on

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #10 on: January 09, 2010, 12:35:24 PM »
Fixed! Thanks for the support.  ;D

Offline Ascot

  • Jr. Member
  • **
  • Posts: 126
  • No soy tan noob!
Re: AddMembergroup issue !!
« Reply #11 on: May 02, 2012, 11:06:07 AM »
How could you fix the issue?
Cause member groups are replaced, not added on my code.
I need to know please. (make me happy)

Thanks in advance.

Offline Nvb

  • Semi-Newbie
  • *
  • Posts: 98
Re: AddMembergroup issue !!
« Reply #12 on: May 02, 2012, 03:50:39 PM »
This was my final code:

Code: [Select]
<?php

/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2007-01-18 19:40:57 +1100 (Thu, 18 Jan 2007)                          $ *
* $Id:: PrimaryMemberGroup.php 80 2007-01-18 08:40:57Z daniel15                 $ *
* Software by:                DanSoft Australia (http://www.dansoftaustralia.net/)*
* Copyright 2005-2007 by:     DanSoft Australia (http://www.dansoftaustralia.net/)*
* Support, News, Updates at:  http://www.dansoftaustralia.net/                    *
*                                                                                 *
* Forum software by:          Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
***********************************************************************************
* 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: AddMembergroup2.php
//      Item

if (!defined('SMF'))
   die(
'Hacking attempt...');

class 
item_AddMembergroup2 extends itemTemplate 
{
function getItemDetails() 
{
        $this->name 'Add Membergroup2';
        
$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['additional_groups']) {
   $additionalGroups['additional_groups'] = $additionalGroups['additional_groups'].",".$item_info[1];
} else {
   $additionalGroups['additional_groups'] = $item_info[1];
}   

echo $additionalGroups['additionalGroups'];          
        $result $smcFunc['db_query']('','
      UPDATE {db_prefix}members 
      SET additional_groups = {string:agp}
        WHERE id_member= {int:id}'
,
           array(
         'id' => $user_info['id'],
         'agp' => $additionalGroups['additional_groups'],
         )
      );

        return 
"Congratulations, you joined the additional mmbergroup {$item_info[1]}!!";
    }
}
?>


Offline Ascot

  • Jr. Member
  • **
  • Posts: 126
  • No soy tan noob!
Re: AddMembergroup issue !!
« Reply #13 on: May 02, 2012, 04:55:55 PM »
thank you a lot ♥