PDA

View Full Version : AUTOJOIN - Auto-entry in membergroup via field in profile


makaiguy
03-31-2006, 10:00 PM
Here's a little something to give back to this community that has been of such help to me.

With this plugin, you can have a user entered into or removed from a secondary usergroup according to several types of controls that can be placed in the user's profile via custom fields. This acts only on SECONDARY usergroups and will not affect the user's PRIMARY usergroup.

At each login, the plugin will check for the appropriate setting in the user's profile, then add or remove the user from the specified membergroup as appropriate. Note that this does not act instantaneously upon entry of the data in the profile, but requires a new login for this to take effect. [Starting with vB 3.6.4 (maybe earlier, I didn't install anything between 3.5.4 and 3.6.4) this will take effect with one or two page reloads.]

Controls currently available:1) Password for single usergroup
2) Yes/No choice for single usergroup via radio button
3) Choose one of several usergroups via radio buttons
4) Choose any of several usergroups via multiple checkboxes
Note that you may write your own additional controls and use the two included functions to do the actual insertion into, and removal from, the target usergroups.

Tested with vB 3.5.4, 3.6.4, 3.6.7-PL1, 3.8.7PL3 only.

Full instructions are in the downloadable text file autojoin.txt.

Update log:
1.00 - Initial release
1.01 - Sorts output membergroups numerically plus a few other small changes
1.02 - Rewritten using defined functions for adding to, and removing from, memberbgroups. This should make it easier to follow the logic and to adapt the code for other situations (e.g.checkboxes or radio buttons instead of text profile fields)
1.03 - InGroup() and OutGroup() functions rewritten to make them more useful when dealing with other situations than the somewhat restricted application of entry/exit of specific membergroup via stored password.
1.03.1 - Additional tweaking of InGroup() and OutGroup() functions. Tested extensively and seem to be working as intended. Tested examples of using via radio buttons instead of text field added.
1.04 - Added protection against doing anything re user's current PRIMARY usergroup in secondary usergroup list. Functions renamed to IntoGroup() and OutOfGroup().
19 April 2006 - all code moved from this thread into the downloadable text file.
1.05 - Added control for using multiple checkboxes to choose any of several usergroups.
22 May 2007 - tested with vB 3.6.7-PL1
24 Sep 2012 - tested with vB 3.8.7-PL3

makaiguy
04-02-2006, 03:14 AM
[Post reserved fur future use. Control code that was previously here has been moved into the downloadable text file.]

nasser71
04-02-2006, 11:54 AM
1st to install and say thanks m8

Murty
04-08-2006, 10:50 PM
I dont understand how this works sorry?

makaiguy
04-11-2006, 04:02 AM
I dont understand how this works sorry?

The user, by entering the required password in a custom field in his profile, will place himself into a specific user group. If he doesn't have the correct password in this field, it will make sure he is NOT in the usergroup.

This process is run each time the user logs in.

Is that what you're asking?

To make this work, you have to create a custom field in the profile where this password can be entered.

You also need to create a custom $vbphrase that houses the required password value.

GamerzWorld
04-11-2006, 08:34 AM
Is it possible to enter them into the moderation of a private usergroup? I would love this but I need to know that the group leader can moderate these users

makaiguy
04-11-2006, 11:21 PM
Is it possible to enter them into the moderation of a private usergroup? I would love this but I need to know that the group leader can moderate these users

If I understand the question...

This just adds the user to the usergroup, the same as if you checked the box for that forum after pulling up his record in the admincp. Whether this usergroup and/or forum require moderation is unaffected by this.

trigon
04-11-2006, 11:58 PM
can i use this to divorce the guys from the girls in my board??

bada_bing
04-12-2006, 12:43 AM
What if you want to kick a specific user out of the usergroup and he knows the password to get back in?

makaiguy
04-12-2006, 03:51 AM
What if you want to kick a specific user out of the usergroup and he knows the password to get back in?

Change the password and tell everybody but him ??

If that is a concern, I don't think this plugin will work for you.

If usergroup membership is used only for forum access purposes, you can lock him out of certain forums via access masks.

makaiguy
04-12-2006, 03:56 AM
can i use this to divorce the guys from the girls in my board??

I assume you have two membergroups and want to put the user in one and remove from the other depending on their choice in their profile. I guess you could use this as a framework, but it would take some additional coding.

A wouldn't think a password text field is the best way to do this. As long as you're going to be modifying code anyway, a radio button would make more sense.

x_5
04-12-2006, 05:08 AM
thanxxxxxxxxxxx

makaiguy
04-12-2006, 02:51 PM
Code revised to version 1.02 - see first post in thread.

Rewritten using defined functions for adding to, and removing from, memberbgroups. This should make it easier to follow the logic and to make it easier for you to adapt the code for other situations (e.g. checkboxes or radio buttons instead of text profile fields).

GamerzWorld
04-12-2006, 03:59 PM
If I understand the question...

This just adds the user to the usergroup, the same as if you checked the box for that forum after pulling up his record in the admincp. Whether this usergroup and/or forum require moderation is unaffected by this.

Yes but as I am saying, I have several groups not moderated by an admin but by a user. Instead of just having to enter a password and automatically being joined, is it possible that they go into the default vbulletin moderation que in which the admin of the group has to accept there application before they can see it

So say for an example a clan called BobsArmy. Is it possible that BobsArmy can have a password, but once the user enters the password instead of being automatically joined into the BobsArmy usergroup he is added automatically to the application process which is found in the group membership page, allowing a second check by the group leader

makaiguy
04-12-2006, 05:12 PM
Instead of just having to enter a password and automatically being joined, is it possible that they go into the default vbulletin moderation que in which the admin of the group has to accept there application before they can see it

Since I don't use that feature, I can't give you a definitive answer. But my GUESS is it will work exactly the same as if you went into the user's profile via the AdminCP and added him to the forum. If that throws him into the moderation queue then this hack should too, I'd think. If that bypasses the moderation queue, then I'd expect this hack would do the same.

Perhaps someone more familiar with that feature can give a more authoritative answer.

But in that case, as long as it requires moderator intervention anyhow, how would this be an improvement over the standard application process? The whole idea here was to eliminate moderator involvement.

makaiguy
04-12-2006, 05:20 PM
I assume you have two membergroups and want to put the user in one and remove from the other depending on their choice in their profile. I guess you could use this as a framework, but it would take some additional coding.

A wouldn't think a password text field is the best way to do this. As long as you're going to be modifying code anyway, a radio button would make more sense.

I've thrown together some code modifications to do this via radio buttons. See the second post (https://vborg.vbsupport.ru/showpost.php?p=939560&postcount=2) in this thread. Again, these modifications are UNTESTED so use at your own risk. [Code no longer in this post - see the download file]

trigon
04-13-2006, 03:41 AM
Understand i right, that for my problem i only modify this codes:// Add or remove user from secondary usergroups
// according to radio button choice in user's profile
// (Choice of one of several forums)

global $vbulletin;

// Enter values in the strings below for your forum
// custom field containing your radio button
$field = 'fieldX'
// membergroup number associated with FIRST radio button choice
$mg[0] = 'XX';
// membergroup number associated with SECOND radio button choice
$mg[1] = 'YY';
// add additional radio button choices as needed

// Derive additional needed variables
$userid = ($vbulletin->userinfo['userid']); // userid of user
$mgarr = explode(',' , (''.$vbulletin->userinfo['membergroupids'])); // current membergroups as array

// Do the work
foreach ($mg as $value)
{
$iii = 0
{
if ($field == pow(2,$iii))
{
InGroup($mgarr, $mg[$iii], $userid);
}
else
{
OutGroup($mgarr, $mg[$iii], $userid);
}
$iii++
}
}

GamerzWorld
04-13-2006, 07:30 AM
Since I don't use that feature, I can't give you a definitive answer. But my GUESS is it will work exactly the same as if you went into the user's profile via the AdminCP and added him to the forum. If that throws him into the moderation queue then this hack should too, I'd think. If that bypasses the moderation queue, then I'd expect this hack would do the same.

Perhaps someone more familiar with that feature can give a more authoritative answer.

But in that case, as long as it requires moderator intervention anyhow, how would this be an improvement over the standard application process? The whole idea here was to eliminate moderator involvement.

Well the problem is that if the password is cracked then spies can easily gain access. My intention was to change password into Group, which would then allow users to apply for their clans group while registering without having to go to the group membership page and click apply. If you go to the admincp then you can simply tick the box and there in but I want them to go to the group leader for moderation before this ;)

makaiguy
04-14-2006, 01:30 AM
Understand i right, that for my problem i only modify this codes:

Edit your info into the code and use it to REPLACE the portion of the original code ABOVE the functions. (In other words, add the functions from the original post to the end of the above code.)

BUT, I'm now trying to get this running on a test system, and there are some syntax errors that I'm working on correcting. (I warned you that this was untested code.) Please check back later.

trigon
04-14-2006, 03:19 AM
Edit your info into the code and use it to REPLACE the portion of the original code ABOVE the functions. (In other words, add the functions from the original post to the end of the above code.)

BUT, I'm now trying to get this running on a test system, and there are some syntax errors that I'm working on correcting. (I warned you that this was untested code.) Please check back later.
Here some information for you: i want to check if the user has in "field5" "women", then move him to usergroup "20". If he has "men", let him in this group.
Maybe you can wrote me a plugin, cause its to confusing for me what here is written, sorry.

makaiguy
04-14-2006, 05:58 AM
I've updated to version 1.03. When trying to adapt for situations other than the narrow password-in-custom-field control, some modifications were necessary, as the 1.02 code did not deal well with situations where no radio button choice had yet been made by the user.

Code in first post reflects latest version 1.03.

See also the second post which has been updated with working code to use radio buttons in custom profile field to allow user to select one of several usergroups.

All Code now included in download file.

makaiguy
04-14-2006, 06:03 AM
i want to check if the user has in "field5" "women", then move him to usergroup "20". If he has "men", let him in this group.
Maybe you can wrote me a plugin, cause its to confusing for me what here is written, sorry.

See the second post. The revised code there fits your situation exactly. Set up your custom field in the profile as a single choice radio button, with the two 'options' being 'men' and 'women'.

makaiguy
04-14-2006, 03:27 PM
Version 1.03.1 now in place. See first and second posts in thread.

makaiguy
04-16-2006, 11:12 PM
Version 1.04 is now in place. It adds a check to prevent modifying the user's PRIMARY usergroup.

trigon
04-18-2006, 11:35 PM
If i activate the plugin, then this error comes: Fatal error: Call to undefined function: outgroup() in /home/********l/public_html/forum/global.php(349) : eval()'d code on line 86

If i deactivate, everything looks good.
Btw, the plugin doesnt work for me, maybe you can take a look on it:
I have three fields, one for women (written in german/turkish)
one for men, and one for "no i dont want to give this info", also in german/turkish. The only with a new usergroup is the first (groupid 20)

makaiguy
04-19-2006, 03:35 AM
If i activate the plugin, then this error comes: Fatal error: Call to undefined function: outgroup() in /home/********l/public_html/forum/global.php(349) : eval()'d code on line 86

If i deactivate, everything looks good.
Btw, the plugin doesnt work for me, maybe you can take a look on it:
I have three fields, one for women (written in german/turkish)
one for men, and one for "no i dont want to give this info", also in german/turkish. The only with a new usergroup is the first (groupid 20)

Sorry, this is my fault. In 1.04 I changed the function names but failed to update to the new names in the code that called them. Replace the 'Do the work' section with:


// Do the work
// Proceed only if there is a user choice
if ($fieldval != '')
{
if($ug[0] != '')
{
$iii = 0;
// Check user choice against possible options
foreach ($choice_text as $value)
{
// If we have a match, add to usergroups
if ($fieldval == $choice_text[$iii])
{
$ugarr = IntoGroup($ugarr, $ug[$iii], $userid);
}
// If we have no match, remove from usergroups
else
{
$ugarr = OutOfGroup($ugarr, $ug[$iii], $userid);
}
$iii++;
}
}
}



I've edited all three scripts in the first and second posts in the thread with this correction.

Also note that you have a problem with the third option you entered. That should be
// THIRD radio button option
// Text shown in radio button for option
$choice_text[2] = 'keine Angabe/Bilgi yok';
// Associated usergroup number
$ug[2] = '2';

trigon
04-19-2006, 10:16 PM
Ok, now it works, any hint to make it for the primary usergroup? Cause i want to move the primary usergroup, not the secondary ones.

makaiguy
04-19-2006, 10:25 PM
All code has been removed from the first two posts in this thread. The latest versions of everything will always be located in the downloadable text file.

makaiguy
04-19-2006, 10:46 PM
Ok, now it works, any hint to make it for the primary usergroup? Cause i want to move the primary usergroup, not the secondary ones.

In AdminCP, when you try to add a person into a secondary usergroup which also happens to be their current primary usergroup it won't let you, so I wrote that same restriction into the code for this plugin.

If you want to change only the primary usergroup, your query needs to update usergroupid instead of membergroupids. Also, since there can only be one primary usergroup, it is a simpler operation because you just reset usergroupid to the new value and don't have to worry about leaving any other primary usergroups alone.

This is untested, but it ought to be at least close to what you need:
// Place user in/out of selected single PRIMARY
// usergroup, according to selection made in profile, via
// custom radio button field. ver 1.04

// ************** UNTESTED CODE ****************

// Enter values in the strings below for your forum
// custom field containing your radio button
$radio_field = 'fieldX';
// FIRST radio button option
// Text shown in radio button for option
$choice_text[0] = 'Choice1';
// Associated usergroup number
$ug[0] = 'XX';
// SECOND radio button option
// Text shown in radio button for option
$choice_text[1] = 'Choice2';
// Associated usergroup number
$ug[1] = 'YY';
// add additional radio button choices as needed

// You don't need to enter anything below here
// Derive additional needed variables
$userid = ($vbulletin->userinfo['userid']);
$pgrp = $vbulletin->userinfo['usergroupid']));
$new_pgrp = $pgrp;
$fieldval = $vbulletin->userinfo[$radio_field];

// Do the work
// Proceed only if there is a user choice
if ($fieldval != '')
{
if($ug[0] != '')
{
$iii = 0;
// Check user choice against possible options
foreach ($choice_text as $value)
{
// If we have a match, set as new primary usergroup
if ($fieldval == $choice_text[$iii])
{
$new_pgrp = $ug[$iii];
}
$iii++;
}
}
// if new group different than current group
if ($new_gprp != $pgrp)
{
// Put updated usergroup into database
$updatefields = $vbulletin->db->query("
UPDATE user
SET usergroupid='$new_gprp'
WHERE userid=$usrid
");
}
}

The Chief
04-19-2006, 10:54 PM
screen shots?

makaiguy
04-19-2006, 11:02 PM
screen shots?

There are no screen shots because nothing is displayed onscreen. It just sets the user's secondary usergroups when he logs on, according to whatever you have set up.

trigon
04-20-2006, 12:05 AM
In AdminCP, when you try to add a person into a secondary usergroup which also happens to be their current primary usergroup it won't let you, so I wrote that same restriction into the code for this plugin.

If you want to change only the primary usergroup, your query needs to update usergroupid instead of membergroupids. Also, since there can only be one primary usergroup, it is a simpler operation because you just reset usergroupid to the new value and don't have to worry about leaving any other primary usergroups alone.

This is untested, but it ought to be at least close to what you need:
// Place user in/out of selected single PRIMARY
// usergroup, according to selection made in profile, via
// custom radio button field. ver 1.04

// ************** UNTESTED CODE ****************

// Enter values in the strings below for your forum
// custom field containing your radio button
$radio_field = 'fieldX';
// FIRST radio button option
// Text shown in radio button for option
$choice_text[0] = 'Choice1';
// Associated usergroup number
$ug[0] = 'XX';
// SECOND radio button option
// Text shown in radio button for option
$choice_text[1] = 'Choice2';
// Associated usergroup number
$ug[1] = 'YY';
// add additional radio button choices as needed

// You don't need to enter anything below here
// Derive additional needed variables
$userid = ($vbulletin->userinfo['userid']);
$pgrp = $vbulletin->userinfo['usergroupid']));
$new_pgrp = $pgrp;
$fieldval = $vbulletin->userinfo[$radio_field];

// Do the work
// Proceed only if there is a user choice
if ($fieldval != '')
{
if($ug[0] != '')
{
$iii = 0;
// Check user choice against possible options
foreach ($choice_text as $value)
{
// If we have a match, set as new primary usergroup
if ($fieldval == $choice_text[$iii])
{
$new_pgrp = $ug[$iii];
}
$iii++;
}
}
// if new group different than current group
if ($new_gprp != $pgrp)
{
// Put updated usergroup into database
$updatefields = $vbulletin->db->query("
UPDATE user
SET usergroupid='$new_gprp'
WHERE userid=$usrid
");
}
}


So i must only use this one? or must i something replace from the old one?
(the values i must change, that i have understand ;))

makaiguy
04-20-2006, 12:09 AM
So i must only use this one? or must i something replace from the old one?
(the values i must change, that i have understand ;))

That one only. Edit in your values, and add the third radio button values as before.

trigon
04-20-2006, 02:48 AM
thx, m8, installed it, now i must wait until my girls log in :D

makaiguy
04-20-2006, 02:50 AM
thx, m8, installed it, now i must wait until my girls log in :D

You don't have a fake account to test stuff like this on?

trigon
04-20-2006, 02:57 AM
tried with a fake account, but it doesnt go. take a look at the code plz:
// Place user in/out of selected single PRIMARY
// usergroup, according to selection made in profile, via
// custom radio button field. ver 1.04

// ************** UNTESTED CODE ****************

// Enter values in the strings below for your forum
// custom field containing your radio button
$radio_field = 'field5';
// FIRST radio button option
// Text shown in radio button for option
$choice_text[0] = 'Weiblich/Bayan';
// Associated usergroup number
$ug[0] = '20';
// SECOND radio button option
// Text shown in radio button for option
$choice_text[1] = 'Männlich/Erkek';
// Associated usergroup number
$ug[1] = '2';
// THIRD radio button option
// Text shown in radio button for option
$choice_text[2] = 'keine Angabe/Bilgi yok';
// Associated usergroup number
$ug[2] = '2';
// add additional radio button choices as needed

// You don't need to enter anything below here
// Derive additional needed variables
$userid = ($vbulletin->userinfo['userid']);
$pgrp = $vbulletin->userinfo['usergroupid']));
$new_pgrp = $pgrp;
$fieldval = $vbulletin->userinfo[$radio_field];

// Do the work
// Proceed only if there is a user choice
if ($fieldval != '')
{
if($ug[0] != '')
{
$iii = 0;
// Check user choice against possible options
foreach ($choice_text as $value)
{
// If we have a match, set as new primary usergroup
if ($fieldval == $choice_text[$iii])
{
$new_pgrp = $ug[$iii];
}
$iii++;
}
}
// if new group different than current group
if ($new_gprp != $pgrp)
{
// Put updated usergroup into database
$updatefields = $vbulletin->db->query("
UPDATE user
SET usergroupid='$new_gprp'
WHERE userid=$usrid
");
}
}

makaiguy
04-20-2006, 04:26 AM
tried with a fake account, but it doesnt go. take a look at the code plz:


We've derailed this topic long enough. Taking this to PM.

SHalliday
06-04-2006, 10:52 PM
This seems like an awesome hack. So far however I have not been able to get it to work like what I need. After spending the entire day trying different variations I finally decided to ask the experts and post here.

I want members to be able to select one or more public groups to join. I first tried using a multiple-selection checkbox and after not being able to get that to work I setup 7 different single radio button fields and created a different single radio button plugin for each field. That did not work either.

My question is --> Will this work with a multiple-selection checkbox?

I want to create a multiple-selection checkbox and allow members to check off the groups they would like to be a member of. Those that are not checked off, I would like them to be removed from. Can this hack be used to accomplish this?

Appreciate any help and/or assistance you can provide.

Thank you.

makaiguy
06-06-2006, 02:38 AM
My question is --> Will this work with a multiple-selection checkbox?

Sure. It just requires a custom control to interract with the multiple-selection checkbox field. I'm in the middle of sketching it out now. Will be back in a day or two (or sooner if all goes exceptionally well and nothing blows up on my own bbs in the meanwhile).

SHalliday
06-06-2006, 03:09 AM
Thank you very much. Looking forward to your custom control script for multiple-selection checkbox field.

makaiguy
06-06-2006, 03:29 AM
Amazing. It worked right out of the box with no debugging at all. Must have held my mouth just right while coding, or something. Anyhow, here's what to use as the control in place of the ones in the downloadable autojoin.txt file:

// Add or remove user from secondary usergroup
// according checkboxes selected in user's profile
// Ver 1.4

global $vbulletin;

// Enter values in the strings below for your forum
// number of the custom field containing your checkboxes
$boxes_field = 'fieldX';
// Usergroup number for FIRST checkbox option
$ug[0] = 'X';
// Usergroup number for SECOND checkbox option
$ug[1] = 'Y';
// add additional checkbox options as needed

// You need make no changes below here

// Derive additional needed variables
// userid of user
$userid = ($vbulletin->userinfo['userid']);
// current usergroups as array
$ugarr = explode(',' , (''.$vbulletin->userinfo['membergroupids']));
// boxes selected
if ($vbulletin->userinfo[$boxes_field] == '')
{
$fieldval = 0;
}
else
{
$fieldval = $vbulletin->userinfo[$boxes_field];
}

// Do the work
$iii = 0;
foreach ($ug as $value)
{
if ($fieldval & pow(2, $iii))
{
$ugarr = IntoGroup($ugarr, $ug[$iii], $userid);
}
else
{
$ugarr = OutOfGroup($ugarr, $ug[$iii], $userid);
}
$iii++;
}


.. then just add in the code for the two functions as in the downloaded autojoin.txt file.

I'll get this added to the autojoin.txt file real soon now ...

[Edit:] Has now been added to the downloadable autojoin.txt file, as version 1.05.

cavyspirit
08-26-2006, 04:01 PM
I really need this in 3.6. First attempt isn't working.

makaiguy
08-31-2006, 10:03 PM
I really need this in 3.6. First attempt isn't working.

I haven't updated my board to 3.6 yet. But since this hack is very important to my board's operation, you can be sure I'll be updating it to work with 3.6 in the near future.

cavyspirit
11-12-2006, 10:29 PM
I now need to make this work on the regular Birthday field.

I want one secondary user group assigned if the member is under 16 and another secondary user group assigned if the member is under 21. Is this possible? Can someone suggest the code change?

Thanks

RFViet
11-14-2006, 01:49 PM
screen shots?

The same question !!

makaiguy
11-14-2006, 10:35 PM
The same question !!

The same answer: There are no screen shots because nothing is displayed onscreen. It just sets the user's secondary usergroups when he logs on, according to whatever you have set up.

Cocko
11-15-2006, 06:30 PM
any product scripts .xml out for 3.6x ?

makaiguy
12-07-2006, 01:31 PM
I've finally started playing with getting my board updated to 3.6 (3.6.4, actually).

AutoJoin has continued to work for me without modification to the original 3.5.4 installation.

salata
12-08-2006, 01:42 AM
can you have them not enter the password at every login in? basically have them choose what usergroup they belong to at registration, I.E. if i had separate sections for men and women

makaiguy
12-08-2006, 01:57 AM
can you have them not enter the password at every login in? basically have them choose what usergroup they belong to at registration, I.E. if i had separate sections for men and women

The idea of this addon is that you create a special field in their profile. They enter the required value in this field in the profile one time, and on every subsequent login it checks for the required value in that profile field, and puts them into or out of the specified secondary user group.

[Edited to add] Code is provided to do this via several different formats for the custom profile field. You may do it as:
Password for single usergroup (alternative to password-protected forum where user must enter password for every session - this way they only enter into their profile one time. Set your forum persmissions to only admit members of the specified usergroup.)
Yes/No choice for single usergroup via radio button
Choose one of several usergroups via radio buttons
Choose any of several usergroups via multiple checkboxes

makaiguy
12-08-2006, 04:08 PM
See also this somewhat similar add-on:
https://vborg.vbsupport.ru/showthread.php?t=82993

Had I known of its existence I probably wouldn't have created this one.

everd
12-08-2006, 05:54 PM
makaiguy, Your hack worked perfect for me, we are using your code with a single choice menu to pick a home state, we run a jeep wrangler forum, and are using your hack to allow us to do local and regional forums based upon this choice.. regardless of another hack being out there. Thanks a Ton, Don

makaiguy
05-23-2007, 12:08 AM
Just updated my test board to vB 3.6.7-PL1. Original code from 3.5.4 continues to work as desired.

If you've installed this plugin, please don't forget to click the Installed link in the first post.

Mum
05-29-2007, 07:21 AM
Please help me urgently, i added your details in and now i can't access my forum AT ALL. How can i turn it off? I can't access my admin panel or anything. Please help.

I went to vB AdminCP, go to Plugin System > Add New Plugin.

Under Hook Location, scroll down to select 'global_start'.

In the 'Plugin PHP Code' field, copy/paste your edited control
script from Part I.

// Place user in/out of single usergroup
// according to yes/no selection made in profile, via
// custom radio button field. ver 1.04

// Enter values in the strings below for your forum
// custom field containing your radio button
$radio_field = 'field10';
// Text returned for 'yes' choice
$join = 'Female';
// Usergroup to enter/exit
$ug = '33';
// You don't need to enter anything below here.

// Derive additional needed variables
// userid of user
$userid = ($vbulletin->userinfo['userid']);
// current usergroups as array
$ugarr = explode(',' , (''.$vbulletin->userinfo['membergroupids']));
// current radio button setting
$fieldval = $vbulletin->userinfo[$radio_field];

// Do the work
// Proceed only if there is a user choice
if ($fieldval != '')
{
// If yes, add to usergroups
if ($fieldval == $join)
{
$ugarr = IntoGroup($ugarr, $ug, $userid);
}
// Else no, remove from usergroups
else
{
$ugarr = OutOfGroup($ugarr, $ug, $userid);
}
}
// End of Control Code


// Define functions used in plug-in
// ***************** Function IntoGroup() **************

Function IntoGroup($ugarr, $ugnum, $usrid)
{
global $vbulletin;
// only proceed if not trying to put into current primary usergroup
if ($ugnum != $vbulletin->userinfo['usergroupid'])
{
// check for empty usergroup array
if($ugarr[0] == '')
{
// set veriables
$uglist = $ugnum;
$ugarr[0] = $ugnum;
$doit = true;
}
// usergroup array not empty
else
{
// If not in usergroup already
if(!in_array($ugnum, $ugarr))
{
$doit = true;
// add group to end of array
array_push($ugarr, $ugnum);
// sort numerically
sort($ugarr, SORT_NUMERIC);
// if only one group in array
if (count($ugarr) == 1)
{
// simple group list string with no commas
$uglist = $ugnum;
}
// else more groups in array than one
else
{
// group list string with comma delimiters
$uglist = implode(',' , $ugarr); // convert array to string
}
}
}
if ($doit)
{
// Put updated usergroup list into database
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids='$uglist'
WHERE userid=$usrid
");
}
}
return $ugarr;
}

// ***************** Function OutOfGroup() **************
Function OutOfGroup($ugarr, $ugnum, $usrid)
{
global $vbulletin;
// only proceed if not trying to remove from current primary usergroup
if ($ugnum != $vbulletin->userinfo['usergroupid'])
{
// Proceed only if usergroup array not empty
if($ugarr[0] != '')
{
// Check for target usergroup in existing array
if(in_array($ugnum, $ugarr))
{
// Rebuild array without target usergroup
$iii = 0;
foreach ($ugarr as $value)
{
if ($value != $ugnum)
{
$new_gparr[$iii] = $value;
$iii++;
}
}
$ugarr = $new_gparr;
if (count($ugarr) == 0)
{
$uglist = '';
}
else
{
$uglist = implode(',' , $new_gparr);
}
// Put updated usergroup list into database
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids='$uglist'
WHERE userid=$usrid
");
}
}
}
return $ugarr;
}
// End of function code

makaiguy
05-29-2007, 10:36 PM
Please help me urgently, i added your details in and now i can't access my forum AT ALL. How can i turn it off? I can't access my admin panel or anything. Please help.
Mum - nobody else has reported anything like this.

See this post for information on how to completely disable the hook system so that no plugins will run. If your ONLY problem is with a plugin installation, this should allow you to access your AdminCP:
http://www.vbulletin.com/forum/showthread.php?t=196688

dooch
06-07-2007, 03:34 PM
This mod is excellent and works a charm. I've added it to my clan website.

I've set it to appear in the "edit profile" as 2 radio buttons however.... what I would really like is a custom page showing two images/buttons. When clicking on one it will add you to that usergroup.

Is that possible?

THANKS

D

makaiguy
06-07-2007, 08:21 PM
This mod is excellent and works a charm. I've added it to my clan website.

I've set it to appear in the "edit profile" as 2 radio buttons however.... what I would really like is a custom page showing two images/buttons. When clicking on one it will add you to that usergroup.

Is that possible?

THANKS

D
Not possible as written, but you could create a php page and adapt the code, I suppose. Would be an interesting project for somebody. You could use the two subroutines from this mod to move people into and out of the usergroups, but you'd have to write your own code to handle the choice made by the user.

Here's a tutorial on creating vB-based php pages:
https://vborg.vbsupport.ru/showthread.php?t=62164

makaiguy
09-24-2012, 11:30 PM
We're in the middle of finally updating vB from 3.6.4 to 3.8.7-PL3 (long, long overdue). Although I'm having some difficulty getting some of my other tweaks to work, I'm pleased to announce that this mod continues to perform as written.