Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.5 > vBulletin 3.5 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg. Details »»
Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg.
Version: 1.00, by amykhar amykhar is offline
Developer Last Online: Nov 2013 Show Printable Version Email this Page

Version: 3.5.0 Beta 1 Rating:
Released: 06-12-2005 Last Update: 06-12-2005 Installs: 55
Uses Plugins
 
No support by the author.

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

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.
Благодарность от:
Insta-Gator

Comments
  #62  
Old 03-19-2006, 05:01 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No. I mean members. Members can leave public groups and ask to join public groups. Combine this with my mod that pms group leaders when users make a request, and you'll have a usable interface.

I don't need my members to change groups after registration becuase except in very rare cases, I don't think their gender is going to change
Reply With Quote
  #63  
Old 03-19-2006, 06:43 PM
Sculli's Avatar
Sculli Sculli is offline
 
Join Date: Nov 2005
Posts: 91
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by amykhar
But, the choice can't be changed after the user registers. They would have to use the regular member group interface for that.
You mean as it is coded now it can't be changed? There is no reason it couldn't be changed if it was coded differently though, right?

I run an online game related message board, and users can have one of three allegiances. Depending on which allegiance they currently have, they are assigned to a usergroup that then assigns them a rank image that shows their allegiance. However, users can change their allegiance in game, and I would like them to be able to change their allegiance choice as well.

I currently use simple publically joinable usergroups. The issue with that is that a user could join multiple groups and thus display multiple allegiance rank images. Some users do, and it's annoying to me to have to hunt them down and tell them that they are misusing the allegiance option.

If I were able to make the allegiance choice a radio button choice in the profile, then they could only have one allegiance at a time, but they would need to be able to change it when they change it in game.

There ought to be a faily simple way to do that. Something along the lines of:
-radio button choice indicates user wants to be part of group A
-check whether user is part of group B already, if so, remove user from group B
-check whether user is part of group C already, if so, remove user from group C
-add user to group A
Reply With Quote
  #64  
Old 04-11-2006, 03:49 AM
Murty's Avatar
Murty Murty is offline
 
Join Date: Dec 2005
Location: South Australia
Posts: 293
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

a few months ago i was having trouble installing the "Put User in Secondary Group Based on Custom Profile Field Value" hack. Well i thought it was all sorted, but for some reason, users are still being put into any random fields(eg male or female). I have not edited any code or anything, but it has been an increasing issue (having to manually change users).

Has anyone got any thoughts?

Please help
Reply With Quote
  #65  
Old 04-26-2006, 08:38 AM
Injektilo's Avatar
Injektilo Injektilo is offline
 
Join Date: Jun 2004
Location: Cyprus
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

amykhar or even someone else...please help me out here

i have a gender field with 3 options (male,female,secret) how can i set males to have one secondary usergroup, for females another, and for those who selected ecret to remain as it is (dont get a secondary usergroup)
Reply With Quote
  #66  
Old 04-26-2006, 09:45 AM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's just ifs and elseifs to handle three groups.
Reply With Quote
  #67  
Old 05-02-2006, 08:47 AM
sepulchres sepulchres is offline
 
Join Date: Apr 2006
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is it possible to use this function based on two custom fields instead of one? If so, how would the code differ to the one above? Cheers.
Reply With Quote
  #68  
Old 05-24-2006, 12:05 AM
ronoxQ's Avatar
ronoxQ ronoxQ is offline
 
Join Date: Aug 2005
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'd just add another field to the plugin that looks for a different field.

Amy, here's my modified profile code, but it doesn't add me under a secondary usergroup. Any ideas?

Code:
// Get the value for field 5
        $user = $db->query_first("
			SELECT field5
			FROM " . TABLE_PREFIX . "userfield
			WHERE userid = " . $vbulletin->userinfo['userid'] . "
		");


		if ($user['field5'] == 'North')
		{
					$membergroupids = $userdata->fetch_field('membergroupids');
		if ($membergroupids)
		{
			$membergroupids = $membergroupids . ", 10";
		}
		else
		{
			$membergroupids = 10;
		}
$userdata->set('membergroupids', $membergroupids);		}
// Get the value for field 5
        $user = $db->query_first("
			SELECT field5
			FROM " . TABLE_PREFIX . "userfield
			WHERE userid = " . $vbulletin->userinfo['userid'] . "
		");

		if ($user['field5'] == 'South')
		{
					$membergroupids = $userdata->fetch_field('membergroupids');
		if ($membergroupids)
		{
			$membergroupids = $membergroupids . ", 11";
		}
		else
		{
			$membergroupids = 11;
		}
$userdata->set('membergroupids', $membergroupids);		}
// Get the value for field 5
        $user = $db->query_first("
			SELECT field5
			FROM " . TABLE_PREFIX . "userfield
			WHERE userid = " . $vbulletin->userinfo['userid'] . "
		");

		if ($user['field5'] == 'West')
		{
					$membergroupids = $userdata->fetch_field('membergroupids');
		if ($membergroupids)
		{
			$membergroupids = $membergroupids . ", 13";
		}
		else
		{
			$membergroupids = 13;
		}
$userdata->set('membergroupids', $membergroupids);		}
// Get the value for field 5
        $user = $db->query_first("
			SELECT field5
			FROM " . TABLE_PREFIX . "userfield
			WHERE userid = " . $vbulletin->userinfo['userid'] . "
		");


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

		$userdata->set('membergroupids', $membergroupids);		}
Reply With Quote
  #69  
Old 05-24-2006, 11:37 AM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ronoxQ, I'm going to respond via pm.
Reply With Quote
  #70  
Old 06-06-2006, 04:08 PM
ThePiston ThePiston is offline
 
Join Date: Jun 2006
Posts: 56
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've got a 5-option radio field that I can't get to work corectly.

I sort of got it to work, but with this code, it it puts new members into 2 Groups, whatever they chose and always the last Group (the else clause) listed as well (so 2 groups). Where am I going wrong?

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


        if (
$gender['field5'] == 'team1')
        {
            
$membergroupids $userdata->fetch_field('membergroupids');
            if (
$membergroupids)
            {
                
$membergroupids $membergroupids ", 9";
            }
            else
            {
                
$membergroupids 9;
            }

            
$userdata->set('membergroupids'$membergroupids);        
        }
        if (
$gender['field5'] == 'team2')
        {
            
$membergroupids $userdata->fetch_field('membergroupids');
            if (
$membergroupids)
            {
                
$membergroupids $membergroupids ", 11";
            }
            else
            {
                
$membergroupids 11;
            }

            
$userdata->set('membergroupids'$membergroupids);        
        }
        if (
$gender['field5'] == 'team3')
        {
            
$membergroupids $userdata->fetch_field('membergroupids');
            if (
$membergroupids)
            {
                
$membergroupids $membergroupids ", 10";
            }
            else
            {
                
$membergroupids 10;
            }

            
$userdata->set('membergroupids'$membergroupids);        
        }
        if (
$gender['field5'] == 'team4')
        {
            
$membergroupids $userdata->fetch_field('membergroupids');
            if (
$membergroupids)
            {
                
$membergroupids $membergroupids ", 12";
            }
            else
            {
                
$membergroupids 12;
            }

            
$userdata->set('membergroupids'$membergroupids);        
        }
        
        if (
$gender['field5'] == 'team5')
        {
            
$membergroupids $userdata->fetch_field('membergroupids');
            if (
$membergroupids)
            {
                
$membergroupids $membergroupids ", 13";
            }
            else
            {
                
$membergroupids 13;
            }

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

            
$userdata->set('membergroupids',$membergroupids);
    } 
*****EDIT**** I fixed it, I needed 'else if' and not 'if'
Reply With Quote
  #71  
Old 06-12-2006, 09:41 AM
Shoebuddy Shoebuddy is offline
 
Join Date: May 2004
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can I write this code? or use a switch statement


Code:
if ($user['field5'] == 'MIS (Summer)')
{
    $membergroupids = $userdata->fetch_field('membergroupids');
    if ($membergroupids)
    {
		$membergroupids = $membergroupids . ", 45";
     }
}

if ($user['field5'] == 'MIS (Fall)')
{
     $membergroupids = $userdata->fetch_field('membergroupids');
     if ($membergroupids)
     {
		$membergroupids = $membergroupids . ", 45";
      }

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05989 seconds
  • Memory Usage 2,359KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (8)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (1)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete