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


All times are GMT. The time now is 12:24 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.01475 seconds
  • Memory Usage 1,755KB
  • 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
  • (6)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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