vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg. (https://vborg.vbsupport.ru/showthread.php?t=82993)

amykhar 06-12-2005 10:00 PM

Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg.
 
This version is for the SECONDARY group. The one for primary groups is here:

https://vborg.vbsupport.ru/showthread.php?t=82992

As far as plugins goes, this one is an advanced plugin because you WILL need to make some tweaks to suit your needs.

What this plugin does: If you have a custom profile field, for example one for gender, it checks to see if the user has selected a specific value and then assigns them to a secondary user group based on that selection.

Instructions for installation:
A. Create your custom profile field and make a note of the field number. (Or simply make a note of the field number of an existing field.)

B. Make a note of the value you are checking for. For example, you may be looking to see if your member selected "male" in your custom gender field.

C. Make a note of the usergroup number that you want to set the user to.

D. Here you have two options:
Option 1: Edit the attached XML file before you import it to change the field number, the value that you check for and the usergroupid. In my XML file, I am checking field5 to see if the value is yes and changing the usergroup to 10.

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
        <plugin active="1" product="vbulletin">
                <title>Put User in Secondary Group Based on Custom Profile Field Value</title>
                <hookname>register_activate_process</hookname>
                <phpcode><![CDATA[// Get the value for field 5
        $user = $db->query_first("
                        SELECT field5
                        FROM " . TABLE_PREFIX . "userfield
                        WHERE userid = " . $vbulletin->userinfo['userid'] . "
                ");


                if ($user['field5'] == 'yes')
                {
                                        $membergroupids = $userdata->fetch_field('membergroupids');
                if ($membergroupids)
                {
                        $membergroupids = $membergroupids . ", 10";
                }
                else
                {
                        $membergroupids = 10;
                }

                $userdata->set('membergroupids', $membergroupids);                }]]></phpcode>
        </plugin>
</plugins>

If you are checking field10 instead of field5, change all references of field5 to field10.

Example: if you are checking your field to see if the value is male, you would change (change field number as needed):

Code:

if ($user['field5'] == 'yes')
to:

Code:

if ($user['field5'] == 'male')
And, finally, change the usergroup as appropriate. Instead of 10 in this line:
Code:

$membergroupids = $membergroupids . ", 10";
substiture your usergroupid of choice.

And in this line as well,
Code:

$membergroupids = 10;
Option 2: Import the XML file as is, open the plugin manager, and make your edits there.


NOTE: This mod works for forums that require users to verify their email address upon registration. If your forum does not require users to verify their email address, you will need to use a different hook. If I have time, I'll test that variation.
----------------
Example Gender Mod that separates users into secondary groups based on their gender. Don't forget, the values are case sensitive and the field numbers and usergroup numbers need to be changed to suit your site's setup.

Code:

// Get the value for field 20
    $gender = $vbulletin->db->query_first("SELECT * FROM userfield WHERE userid=".$vbulletin->userinfo['userid']);


                if ($gender['field20'] == 'male')
                {
                        $membergroupids = $userdata->fetch_field('membergroupids');
                        if ($membergroupids)
                        {
                                $membergroupids = $membergroupids . ", 42";
                        }
                        else
                        {
                                $membergroupids = 42;
                        }

                        $userdata->set('membergroupids', $membergroupids);               
                }
                else
                {
                        $membergroupids = $userdata->fetch_field('membergroupids');
                        if ($membergroupids)
                        {
                                $membergroupids = $membergroupids . ", 41";
                        }
                        else
                        {
                                $membergroupids = 41;
                        }

                        $userdata->set('membergroupids',$membergroupids);
        }

Amy

djr 06-13-2005 05:19 AM

Ooooooooooooh! This is so great. I'm not running vB3.5 yet, so if you could make this for vB 3.07??? Please Amy? :D (begging). If there's already a hack, I'd be much obliged with a pointer.

Cyricx 07-14-2005 02:29 PM

Would it be possible to use this code to check their and thereby age?

Like I have an 18+ forum that I use a secondary usergroup to control access to.

amykhar 07-14-2005 02:33 PM

Quote:

Originally Posted by Cyricx
Would it be possible to use this code to check their and thereby age?

Like I have an 18+ forum that I use a secondary usergroup to control access to.

Yes, you could use this basic structure. It wouldn't check the value of the userfield. It would do the math on their age.

Amy

merk 07-14-2005 10:23 PM

It would be nice if you could also hook the usercp pages so if they change an option the usergroups that were assigned at registration would also change.

Other than that, nice plugin :)

Brinnie 07-15-2005 01:07 AM

Hello,

Would you be so kind as to give an example of how this mod might be used? I am looking to do something with my usergroups (see attachment) but I don't know if I need this mod or the primary group mod.

Thanks a million. :)

Brinnie

Brinnie 07-15-2005 01:09 AM

Quote:

Originally Posted by merk
It would be nice if you could also hook the usercp pages so if they change an option the usergroups that were assigned at registration would also change.

Other than that, nice plugin :)

That's what I was just wondering.
If I install this, would my members be able to cross party lines?

amykhar 07-15-2005 01:11 AM

Quote:

Originally Posted by merk
It would be nice if you could also hook the usercp pages so if they change an option the usergroups that were assigned at registration would also change.

Other than that, nice plugin :)

I'll see what I can do.

Amy

Brinnie 07-15-2005 01:51 AM

no love 4 my question? :(

Chris M 07-15-2005 01:59 AM

Quote:

Originally Posted by Brinnie
no love 4 my question? :(

You asked it in the wrong place - Ask it in the "vBulletin Modification Questions" forum for vB 3.5.0 or the "General Modification Discussion" for 3.0.x depending on which forum you want it to run on ;)

Satan

Brinnie 07-15-2005 02:06 AM

Quote:

Originally Posted by hellsatan
You asked it in the wrong place - Ask it in the "vBulletin Modification Questions" forum for vB 3.5.0 or 3.0.x depending on which forum you want it to run on ;)

Satan

oh ok. I'm a n00b, I don't know these things.

Do I need to entitle it: " Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg."?

Chris M 07-15-2005 02:10 AM

Quote:

Originally Posted by Brinnie
oh ok. I'm a n00b, I don't know these things.

Do I need to entitle it: " Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg."?

No - Reeve of Shinra has provided one way of doing it, here

If you decide to do it that way, you will only require the use of one of the hacks by amy :)

If you decide to do it via custom code, you will need to ask ;)

Satan

Brinnie 07-15-2005 02:35 AM

Quote:

Originally Posted by hellsatan
No - Reeve of Shinra has provided one way of doing it, here

If you decide to do it that way, you will only require the use of one of the hacks by amy :)

If you decide to do it via custom code, you will need to ask ;)

Satan

Do you know which one of these hacks would be better?

Chris M 07-15-2005 02:37 AM

Quote:

Originally Posted by Brinnie
Do you know which one of these hacks would be better?

It depends whether you want the user to be moved into a different Primary Group or added to a Secondary Group :)

Satan

akanevsky 08-01-2005 08:14 PM

Nice hack. A few suggestions:

1. Make it configurable from admincp.
2. Replace

PHP Code:

if ($membergroupids)
{
$membergroupids $membergroupids ", 10";
}
else
{
$membergroupids 10;


With

PHP Code:

$membergroupids .= (!empty($membergroupids) ? ", " "") . 10


amykhar 08-01-2005 08:15 PM

1. Yes, that can be done now. When I wrote this, changes to the admincp required code edits, which I was trying to avoid.
2. I realize your way is shorter, but when I write code for here, I prefer to break things out to make it as simple to read as possible. That way, new coders get a glimpse at what is going on.

thecool 08-18-2005 10:18 PM

Is there anyway to have the user added as a primary user of the Customer field as opposed to a secondary user?

thanks

Andreas 08-18-2005 10:19 PM

Did you know that vBulletin has a nice search function? ;)
https://vborg.vbsupport.ru/showthread.php?t=82992

thecool 08-18-2005 10:44 PM

Quote:

Originally Posted by KirbyDE
Did you know that vBulletin has a nice search function? ;)
https://vborg.vbsupport.ru/showthread.php?t=82992

Didn't read it up top, browsed it and missed, thanks for the heads up.

Bad Bunny 10-02-2005 06:25 AM

Is this working for gold? Cause I can't seem to get it to work. I have field5 and Yes (is it dependent on caps?) adds to group 11. Which is pretty simple...since it's almost default.

Sovereign 10-02-2005 06:54 PM

Yay, this will work for ranksets, assigns users to rank groups (for custom rankings like Army, Star Wars etc.) Now for one without email validation...

amykhar 10-03-2005 04:54 PM

It's case sensitive and it's working on my gold site.

PennylessZ28 10-04-2005 12:06 AM

What would the use of this system be? Could I use this to say put Females in a Female Usergroup and Male in a Male group and then search for a user by sex? if that was the usergroup?

amykhar 10-04-2005 02:55 AM

I have a private forum for women and one for men. This gives my users access to those groups. You could use it for whatever floats your boat though - not just gender. You could check to see if people like peas or not. Or, you could sort people into clans at registration time. Whatever your little heart desires and is capable of coding ;)

PennylessZ28 10-04-2005 03:13 AM

Good deal, I didn't think about gender related forums. I am working on something and you just gave me an awesome idea. Thanks bro!

sensimilla 10-04-2005 05:43 AM

so it can work with only one choice..?

what if I want "male" "female" "couple" to create 3 different usergrups?

TIA

GamerzWorld 10-04-2005 07:50 AM

This hack is great what ive been looking for, however have a question. Currently i have two clans running on my board, both require validation before you get moved into the secondary usergroup. Will this hack automatically bypass this or simply add them into the que, and if it does bypass is there anyway i can make it so it simply adds them for auth by the group admin

amykhar 10-04-2005 07:28 PM

It bypasses it as written. It wouldn't be a major deal to add them to the queue instead.

Sadie Frost 10-06-2005 01:49 AM

Not working for me in RC3 - would image verification interfere with this or anything?

amykhar 10-06-2005 02:35 AM

No and it's still working on my site which has used every version up to and including gold. Check any edits you made to the plugins and ensure the fields and cases are correct.

Sadie Frost 10-06-2005 03:26 AM

Okay I tried doing this with your gender code, and I get sort of a weird result. This is what I have:

Code:

// Get the value for field 20
    $gender = $vbulletin->db->query_first("SELECT * FROM userfield WHERE userid=".$vbulletin->userinfo['userid']);


                if ($gender['field6'] == 'M')
                {
                        $membergroupids = $userdata->fetch_field('membergroupids');
                        if ($membergroupids)
                        {
                                $membergroupids = $membergroupids . ", 30";
                        }
                        else
                        {
                                $membergroupids = 30;
                        }

                        $userdata->set('membergroupids', $membergroupids);               
                }
                else
                {
                        $membergroupids = $userdata->fetch_field('membergroupids');
                        if ($membergroupids)
                        {
                                $membergroupids = $membergroupids . ", 31";
                        }
                        else
                        {
                                $membergroupids = 31;
                        }

                        $userdata->set('membergroupids',$membergroupids);
        }

So my gender field is field 6, and my choices at M or F. So I made a test user with the M setting, and it put them in usergroup 31. So unless I'm reading that wrong, that's the wrong one. Am I just totally missing something here? Any help would be appreciated :)

GamerzWorld 10-07-2005 03:46 PM

Quote:

Originally Posted by amykhar
It bypasses it as written. It wouldn't be a major deal to add them to the queue instead.

How would i do that? Many users cant find the group membership page so as i said this would be great if they could select which clan they were in and be automatically joined to que for validation

scottblumin 10-12-2005 08:37 PM

Quote:

Originally Posted by sensimilla
so it can work with only one choice..?

what if I want "male" "female" "couple" to create 3 different usergrups?

TIA


Did anyone answer this question - I have the same question. I have four usergroups based on Geography.

Thanks.

GamerzWorld 10-14-2005 11:27 AM

Quote:

Originally Posted by GamerzWorld
How would i do that? Many users cant find the group membership page so as i said this would be great if they could select which clan they were in and be automatically joined to que for validation

Any guidance :)

GrendelKhan{TSU 10-14-2005 01:06 PM

you know...before this thread...
I didn't even really get what one needed secondary user groups for. so thanks!!

now I can take that OFF my list of things to learn, and put it ON my list of things to install. :P

<<< runs in n00b shame :)

cool stuff...will be installed when I get that far. :D

GamerzWorld 10-16-2005 03:37 PM

Ok i give up, hehe

jdh 10-23-2005 02:30 PM

On thing that's really been missing in vBulletin IMHO is group-centric management (ie, select a group and then add/remove users). However, this plug-in looks like it might help me...

In my particular case, I run a private board for a youth organization with some forums that are only accessible by users in a certain training level, and other forums that are only accessible by users in a certain team. Both of these groupings are a reflection of their level and membership within the organization, as opposed to the board itself.

Normally, the level changes each year (assuming they pass), and the team membership can change fairly regularly as well.

Traditionally, I have used secondary groups for this, but as I mentioned above, that's a pain to maintain (since I can't just select the "Level 1" group and add fifteen members... Rather, I have to select each of the fifteen members manually and add them to the "Level 1" group as a secondary group).

However, the use of a custom profile field to control their membership would greatly simplify this for me, since not only would it control the group membership easily, but it would also allow me to import this information from an existing database (since I do already have it stored in a membership database).

There would be a couple of things that I would need to consider...

Firstly, I would need it to hook into somewhere else other than user registration, since the profile fields will change from time to time for existing users. I'm thinking of a hook into forumhome_start or somewhere related to login. This particular board only has about 200 users, so I'm not overly concerned about performance issues (although I'd like to avoid any glaring one). Any thoughts on a more suitable hook for this purpose?

The second problem, which is a more complex one, would be have it remove any groups for which the user is no longer. In other words, if the user is now in Level 2, they should be removed from the Level 1 group (or, put more simply, I guess they could be removed from ALL level groups and then re-added to the one that matches their profile field). The same would need to occur for the team groups (they can only be a member of one team at a time).

Any thoughts or advice on how to accomplish this would be very helpful. I don't consider myself a novice in programming, but I would like to benefit from the advice of those more experienced in working with vBulletin (especially the new 3.5 hooks system) before I attempt any of this myself...

Code Monkey 10-29-2005 04:41 AM

You might want to check if the user is already in that group.

banjolawyer 01-08-2006 04:53 PM

Would this plugin work for adding a user to more than one secondary usergroup? For example if I added a "multiple selection checkbox" custom profile field, could it add the user to 2 or 3 differnt public usergroups if the user checks 2 or 3 checkboxes?

DaveAK 02-19-2006 11:59 PM

Any one got this working when you don't have email verification? I tried using the "register_addmember_complete" hook, but this didn't work. I'm not a complete novice to PHP, but I am when it comes to vBulletin. I understand the purpose of the hooks, but I can't seem to figure out which one I need to use.


All times are GMT. The time now is 07:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01504 seconds
  • Memory Usage 1,856KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_code_printable
  • (2)bbcode_php_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete