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
  #112  
Old 05-24-2008, 09:04 AM
Conner85 Conner85 is offline
 
Join Date: Jan 2008
Posts: 129
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Someone needs to update this for 3.7 Gold. It's causing registration errors for my users.
Reply With Quote
  #113  
Old 05-27-2008, 01:55 AM
oz_girl's Avatar
oz_girl oz_girl is offline
 
Join Date: Mar 2008
Location: Australia
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is perfect for my forums but is this 3.7 Gold compatible?
Reply With Quote
  #114  
Old 05-28-2008, 09:02 AM
oz_girl's Avatar
oz_girl oz_girl is offline
 
Join Date: Mar 2008
Location: Australia
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone using this successfully on 3.7 gold or 3.7.1??
Reply With Quote
  #115  
Old 06-07-2008, 12:40 AM
jpapadpapa jpapadpapa is offline
 
Join Date: Feb 2008
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I, too, really need this for 3.7.1!
Reply With Quote
  #116  
Old 09-04-2008, 05:42 PM
steven s's Avatar
steven s steven s is offline
 
Join Date: Aug 2004
Location: Greenville, SC
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by oz_girl View Post
Anyone using this successfully on 3.7 gold or 3.7.1??
Quote:
Originally Posted by jpapadpapa View Post
I, too, really need this for 3.7.1!
Just installed it on v3.7.3.

THANKS!
This is the answer I've been looking for.
It will automatically ban my spammers.

Edit: Also works on 3.7.4 p1
Reply With Quote
  #117  
Old 11-02-2008, 11:29 AM
steven s's Avatar
steven s steven s is offline
 
Join Date: Aug 2004
Location: Greenville, SC
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is an old one but I love it.
Spammers usually enter the same number into my location profile field.
Bam, automatic ban. Just banned two more.
They have gotten past answering questions which I'm sure stops a few, and this mod is just another measure.
Reply With Quote
  #118  
Old 12-23-2008, 07:40 PM
YESS YESS is offline
 
Join Date: Nov 2008
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you Amy this is exactly what my client needed to perfect their forums.

Now all I need to do is learn how to do something like this with a cron job so that users who are already registered can choose something in their profile to 'upgrade' their account and set their primary usergroup.
Reply With Quote
  #119  
Old 12-23-2008, 11:22 PM
YESS YESS is offline
 
Join Date: Nov 2008
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There we go, I went ahead and wrote a Scheduled Task that every 10 minutes would check for anybody in the primary group 'Registered users' with the custom profile field9 set to 'Yes' and move them to usergroup 9, and vice versa. Sorry in advance for unclean code and please don't hate.

Place the code in the box below in a .php script in your /includes/cron folder and create a new scheduled task pointing to that script.

Replace 'field9' with the field you want to check. Replace 'Yes' and 'No' with the values of your field9 option.

Replace 'New member' and 'Introductory grower/distributor' with your chosen user titles.

Replace the usergroup numbers 2(Registered member) and 9(Custom usergroup) on the MySQL queries with the numbers of the usergroups you want to migrate to and from.

Sorry I can't go into more detail, sort of in a hurry to get this job done for my client. I don't recommend attempting this if you are not comfortable editing SQL queries.

Be sure to test this out on your forums using the 'Run now' option from the Scheduled Tasks section of the control panel, if you have messed up the syntax at all the control panel should return an error and send a copy of the error to the board owner via email.

I recommend backing up your databases before trying this out just in case you do something wrong, I don't hold any responsibility for lost or corrupt data in your database.

P.S. I recommend putting a notice in your custom usergroup description letting the user know that it can take up to 10 minutes for the changes to take effect to avoid confusion. (Or whatever interval you set your scheduled task job to.)

PHP Code:
<?php
error_reporting
(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db))
{
    exit;
}

$tmpA $vbulletin->db->query_read("
SELECT user.userid,user.usergroupid,user.username 
FROM `user`,`userfield` AS field 
WHERE user.usergroupid = 2 
AND user.userid=field.userid 
AND field.field9='Yes'
"
);

while (
$tmpU $vbulletin->db->fetch_array($tmpA))
{
    
$vbulletin->db->query_write("
        UPDATE " 
TABLE_PREFIX "user
        SET usergroupid = 9, usertitle='Introductory grower/distributer' 
        WHERE userid = " 
$tmpU['userid']);
}




$tmpA $vbulletin->db->query_read("
SELECT user.userid,user.usergroupid,user.username 
FROM `user`,`userfield` AS field 
WHERE user.usergroupid = 9 
AND user.userid=field.userid 
AND field.field9='No'
"
);

while (
$tmpU $vbulletin->db->fetch_array($tmpA))
{
    
$vbulletin->db->query_write("
        UPDATE " 
TABLE_PREFIX "user
        SET usergroupid = 2, usertitle='New member' 
        WHERE userid = " 
$tmpU['userid']);
}
?>
Reply With Quote
  #120  
Old 01-21-2009, 02:44 PM
forexforum forexforum is offline
 
Join Date: Sep 2008
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi there,

Does it work on the latest vB 3.8? I need this. Thank you all.
Reply With Quote
  #121  
Old 03-29-2009, 05:09 PM
amjadz4's Avatar
amjadz4 amjadz4 is offline
 
Join Date: Aug 2007
Posts: 245
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i need this for the latest vb too!! can you please update it!!
thanks!
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:21 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.14755 seconds
  • Memory Usage 2,328KB
  • 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
  • (4)bbcode_code
  • (1)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
  • (3)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (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