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
  #112  
Old 09-24-2007, 08:10 PM
groeken groeken is offline
 
Join Date: Mar 2005
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

mhh.. then must be an error in my syntax, i think. Maybe anyone has an idea what is wrong..
the main problem is that if i had to activate more than 1 user at the same time the users will be put in the same group, allthough they had different choices for the selected field.

PHP Code:
$user $db->query_first("SELECT field8    FROM " TABLE_PREFIX "userfield WHERE userid = '" $vbulletin->userinfo['userid'] . "'");

if (
$user['field8'] == '1. Fachsemester') {
  
$membergroupids $userdata->fetch_field('membergroupids');
  if (
$membergroupids) {
      
$membergroupids $membergroupids ", 17";
    }
    else {
      
$membergroupids 17;
    }
  
$userdata->set('membergroupids'$membergroupids);        
}
elseif (
$user['field8'] == '2. Fachsemester') {
  
$membergroupids $userdata->fetch_field('membergroupids');
  if (
$membergroupids) {
      
$membergroupids $membergroupids ", 18";
      }
      else {
      
$membergroupids 18;
      }
    
$userdata->set('membergroupids'$membergroupids);        
  }
elseif (
$user['field8'] == '3. Fachsemester') {
  
$membergroupids $userdata->fetch_field('membergroupids');
    if (
$membergroupids) {
      
$membergroupids $membergroupids ", 19";
        }
        else {
          
$membergroupids 19;
        }
    
$userdata->set('membergroupids'$membergroupids);        
}
elseif (
$user['field8'] == '4. Fachsemester') {
  
$membergroupids $userdata->fetch_field('membergroupids');
    if (
$membergroupids) {
       
$membergroupids $membergroupids ", 20";
    }
    else {
      
$membergroupids 20;
    }
  
$userdata->set('membergroupids'$membergroupids);        
}
elseif (
$user['field8'] == '5. Fachsemester') {
  
$membergroupids $userdata->fetch_field('membergroupids');
    if (
$membergroupids) {
      
$membergroupids $membergroupids ", 21";
    }
    else {
    
$membergroupids 21;
  }
  
$userdata->set('membergroupids'$membergroupids);        
}
elseif (
$user['field8'] == '6. Fachsemester') {
  
$membergroupids $userdata->fetch_field('membergroupids');
    if (
$membergroupids) {
    
$membergroupids $membergroupids ", 22";
    }
    else {
     
$membergroupids 22;
    }
  
$userdata->set('membergroupids'$membergroupids);        
}
elseif (
$user['field8'] == 'Diplom oder spaeter') {
  
$membergroupids $userdata->fetch_field('membergroupids');
    if (
$membergroupids) {
     
$membergroupids $membergroupids ", 23";
    }
    else {
     
$membergroupids 23;
    }
  
$userdata->set('membergroupids'$membergroupids);        

any ideas?

groeken
Reply With Quote
  #113  
Old 04-15-2008, 04:51 AM
dcw dcw is offline
 
Join Date: Dec 2006
Location: Florida
Posts: 126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does this work for 3.7?
Reply With Quote
  #114  
Old 04-20-2008, 08:07 AM
Ramsesx's Avatar
Ramsesx Ramsesx is offline
 
Join Date: Aug 2005
Location: Southern Germany
Posts: 512
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by dcw View Post
Does this work for 3.7?
Yes it works for me on 3.7 RC1
Reply With Quote
  #115  
Old 05-15-2008, 11:58 PM
Mum Mum is offline
 
Join Date: Jun 2006
Location: New Zealand
Posts: 660
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Doesn't work for me on 3.7 gold, database error apon sign up.
Reply With Quote
  #116  
Old 06-09-2008, 09:12 PM
MG Webmaster MG Webmaster is offline
 
Join Date: Jun 2008
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So does it work on 3.7.1????
Reply With Quote
  #117  
Old 09-17-2008, 03:42 PM
biome.pat biome.pat is offline
 
Join Date: Aug 2008
Location: Toronto, ON, Canada
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey folks! I've read through this whole thread, and can't seem to find anyone with the same problem (except maybe Murty in post #63). It seems that the plugin works for most registrations, but a few users end up in the wrong category. To explain, I've got it set up so field5 is a single-selection menu where members/students pick their year of study. I have it set up so that if they pick "Year 1" from the pull-down (instead of the other options of "Year 2", "Year 3", "Year 4+", "Grad Student" or "Alumni/Other"), they're put in a special usergroup with different forum access (called "Year - 1"), while if they pick anything else, they're put in another usergroup (called "Year - Other").

Settings are like so:

Set Default: Yes, Including a First Blank
Field Required: Yes, at Registration and Profile Updating
Field Editable by User: Only at Registration
Private Field: No
Field Searchable on Members List: Yes
Show on Members List: Yes

Every few days, I've been doing a search for students who have both "Year 1" chosen in the profile field, and are in "Year - Other" usergroup. If I'd set this up correctly, there shouldn't be any users found, but there are always a few.

Any ideas? It might be important to mention that the board has a high registration volume at the beginning of the academic year, so we've had over 1000 new users in 48 days.

PHP 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'] == 'Year 1')
        {
            
$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);
        } 
Any insight would be muchly appreciated!
Reply With Quote
  #118  
Old 09-17-2008, 05:10 PM
biome.pat biome.pat is offline
 
Join Date: Aug 2008
Location: Toronto, ON, Canada
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright, so after doing 30 or so registrations is different browsers (and changing "Set Default" to "No", so that each registrant has so select the menu and choose an option (as opposed to first year's just seeing it already selected and leaving it), it seems it's an IE issues. After I changes the "Set Default" option, firefox never seems to have any problems (an it did once or twice before), but IE never puts them in the right category. They automatically end up in the usergroup indicated by the else statement (id:14 or "Year - Other"). Any ideas here folks? I'm baffled!
Reply With Quote
  #119  
Old 12-30-2008, 03:30 PM
Levo1980 Levo1980 is offline
 
Join Date: May 2006
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

sorry my english ist not the best
i have import the xml and befor i import this i have changed this like this:

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


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

		$userdata->set('membergroupids', $membergroupids);		}
But it doenst work....
I use VB 3.6.6 and on fild8 they have to select m?nnlich or weiblich (male or female), i want that all "weiblich" go to the secondary usergroup ladies which have the the ID:10.

Can somebody help me???
Reply With Quote
  #120  
Old 02-26-2009, 09:55 AM
Bellinis's Avatar
Bellinis Bellinis is offline
 
Join Date: Aug 2005
Location: Amsterdam, the Netherland
Posts: 130
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dear amykhar & others,

I'd been looking for such mod for a long time. Will this one still work for 3.8? I'm affraid not....
Is there an updated version of some similar mod?

Thanks a lot in advance!
Reply With Quote
  #121  
Old 04-07-2009, 02:22 PM
sensimilla sensimilla is offline
 
Join Date: Dec 2004
Location: Poland
Posts: 555
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Bellinis View Post
Dear amykhar & others,

I'd been looking for such mod for a long time. Will this one still work for 3.8? I'm affraid not....
Is there an updated version of some similar mod?

Thanks a lot in advance!

Same here.. I am in need of this hack.
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 04:14 PM.


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.07914 seconds
  • Memory Usage 2,365KB
  • 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
  • (7)bbcode_code
  • (2)bbcode_php
  • (2)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
  • (1)pagenav_pagelinkrel
  • (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