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 Primary Usergroup Based on Value of Custom Profile Field Details »»
Add User to Primary Usergroup Based on Value of Custom Profile Field
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: Never Installs: 59
Uses Plugins
 
No support by the author.

This version is for the PRIMARY group. Here is the one for secondary groups:

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

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 primary user group based on that selection. This happens at the time the user activates their email account after registering.

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 User Group Based on 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')
		{
			$userdata->set('usergroupid', 10);
		}]]></phpcode>
	</plugin>
</plugins>
If, for example, you want to check the value of field6, change field5 in the XML file to field6. If you are looking for "male" instead of "yes", change
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:
$userdata->set('usergroupid', 10);
substiture your usergroupid of choice.

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.

Amy

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #52  
Old 04-19-2006, 09:22 PM
JAV-ISH JAV-ISH is offline
 
Join Date: Mar 2006
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If I use moderated public groups, the user is active in this group without moderation. Is there a workaround?
Reply With Quote
  #53  
Old 04-19-2006, 10:38 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

what do mean by moderated public group? A group where the leader must approve the members? This mod is not intended to work with such groups.
Reply With Quote
  #54  
Old 05-01-2006, 11:30 AM
sepulchres sepulchres is offline
 
Join Date: Apr 2006
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by amykhar
what do mean by moderated public group? A group where the leader must approve the members? This mod is not intended to work with such groups.
I'm also getting a parse error when I activate the account of the registered user. It seems that a lot of people are getting the same thing when using this hack. I read that Paul was having similar problems and Amy, you fixed it...But that was in the secondary one. Is there anything I can do to fix mine because it seems to be a similar problem that I am having. Cheers.

btw, I have checked all the userids and options of the custom field. I am using custom groups which are not public and emails must be verified by users. Here is the php code from the plugin...

Code:
Plugin 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 9')
        {
            $userdata->set('usergroupid', 9);

        if ($user['field5'] == 'Year 10')
        {
            $userdata->set('usergroupid', 10);

        if ($user['field5'] == 'Year 11')
        {
            $userdata->set('usergroupid', 11);

        if ($user['field5'] == 'Year 12')
        {
            $userdata->set('usergroupid', 12);
        }
Reply With Quote
  #55  
Old 05-01-2006, 12:18 PM
paulfletcher paulfletcher is offline
 
Join Date: Jan 2006
Location: USA
Posts: 106
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey. Well It was working for the secondary user-group. Although I found out that I needed one for the primary group. So Amykhar helped me out with this slight modification of the script... Works on my board (3.5.4).

PHP Code:
switch($userinfo['field5'])
{
    case 
"A":    
        
$userdata->set('usergroupid'12);
    break;
    case 
"B":
        
$userdata->set('usergroupid'13);
    break;
    case 
"C":
        
$userdata->set('usergroupid'18);
    break;

Talk to you later,
Paul F
Reply With Quote
  #56  
Old 05-01-2006, 12:19 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Because this mod requires you to change the code for it to work, you really need to be careful when making the changes. You haven't closed the braces on your first three if clauses, which is what's giving you the parse errors. I'm sorry, but I can't keep fixing these problems on an individual basis here and am referring any further issues to my premium support forum.
Reply With Quote
  #57  
Old 05-19-2006, 04:18 PM
Tory H Tory H is offline
 
Join Date: Mar 2006
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Amy,
I need this mod to read a different field (referrer) rather than profile field.

Basically the user is put into a usergroup based on what field is filled out as referrer (automatically passed from URL). Basically if they are my referral they are top dog permissions because they are somebody who I can trust, if a troll refers them then maybe they get put into a special group.

Will this work do you think?
Thx
Matt
Reply With Quote
  #58  
Old 06-16-2006, 03:10 AM
futuredood futuredood is offline
 
Join Date: Jan 2002
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by paulfletcher
Hey. Well It was working for the secondary user-group. Although I found out that I needed one for the primary group. So Amykhar helped me out with this slight modification of the script... Works on my board (3.5.4).

PHP Code:
switch($userinfo['field5'])
{
    case 
"A":    
        
$userdata->set('usergroupid'12);
    break;
    case 
"B":
        
$userdata->set('usergroupid'13);
    break;
    case 
"C":
        
$userdata->set('usergroupid'18);
    break;

Talk to you later,
Paul F
I presume this means you can let the user input the actual text in the case "X" area, correct? In that case, can you tell me where I would place this in the XML file?

I plan on having available more usergroups in the future, and would like to have the individual be able to type in the group they are entering (I'd have a link to the possibilities on the registration page).

Also, has their been any changes so that this could work all the time (for example, they can change their usergroup as they like through edit profile)? Thanks.
Reply With Quote
  #59  
Old 06-19-2006, 08:02 PM
ThePiston ThePiston is offline
 
Join Date: Jun 2006
Posts: 56
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

can someone post some working, multi-item xml code? I got mine working for multiple raio buttons with the secondary code, but i switched all of those groups to 'non-joinable custom/primary' usergroups and now I get nothing showing up when Iclick the registration email link and I can't get it to work. I've trid every combination i can think of... Ive got the right field, correct spelling and syntax, groups... i think i need to see someone's successful code for a multi-item xml file to compare. tia

this is the code i have now that does not want to work:
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'] == 'Yes'
        { 
            
$userdata->set('usergroupid'15); 
            } 
             
         else if (
$user['field5'] == 'No'
        { 
            
$userdata->set('usergroupid'17); 
            } 
             
         else if (
$user['field5'] == 'Always'
        { 
            
$userdata->set('usergroupid'19); 
            } 
             
         else if (
$user['field5'] == 'Never'
        { 
            
$userdata->set('usergroupid'20); 
            } 
I tried using all 'if's but that didn't work either... i'm not too hip on PHP, but i should be able to crack this?!
Reply With Quote
  #60  
Old 06-30-2006, 05:18 PM
JazzleBug JazzleBug is offline
 
Join Date: Feb 2004
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This installed beautifully, Amy! I'm all about automation and this cuts down on quite a bit of work for me. Thank you!
Reply With Quote
  #61  
Old 06-30-2006, 05:51 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

happy to be of service
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 03:47 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.04567 seconds
  • Memory Usage 2,339KB
  • 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
  • (5)bbcode_code
  • (3)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
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • 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