View Full Version : Usergroup Permissions based off Profile Options
DaPro
02-09-2010, 02:35 AM
Hi Guys,
Looking for a modification that would allow me to select a usergroup based off of a profile option.
For instance, if I had a question:
"Are you selling goods?"
And it is "Yes" or "No" values, I could specify:
If "Yes" change usergroup to X.
Would this be possible for vBulletin 4?
DaPro
02-11-2010, 04:33 PM
Sorry to do this, but is anyone willing to help with this?
DaPro
02-12-2010, 04:57 PM
So I tried to do this myself and the code isn't working. Could someone look into this for me?
I made a plugin and it's hooklocation is profile_updateprofile
$user = $db->query_first("SELECT field6 FROM " . TABLE_PREFIX . "userfield WHERE userid = " . $vbulletin->userinfo['userid'] . "");
if($user['field6'] == 'Yes' && $vbulletin->userinfo['usergroupid'] =='2') {
$userdata->set('usergroupid', 10);
} elseif($user['field6'] == 'No' && $vbulletin->userinfo['usergroupid'] =='10') {
$userdata->set('usergroupid', 2);
}Could someone help me with this?
This is for vBulletin 4.0 by the way.
White_Snake
02-12-2010, 06:06 PM
on which hook are you setting this? this code should run after the user has registered in the forum, therefore it should run depending if you are asking your users to validate their email or not and for the people who already are in there, you would need to run a script that will move them to the user group if your forum is too big, but if its small one, less than 50 users or so i suppose it can be done manually
DaPro
02-12-2010, 06:13 PM
on which hook are you setting this? this code should run after the user has registered in the forum, therefore it should run depending if you are asking your users to validate their email or not and for the people who already are in there, you would need to run a script that will move them to the user group if your forum is too big, but if its small one, less than 50 users or so i suppose it can be done manually
Sorry, I guessed you missed it in my post:
"profile_updateprofile"
That's the hook I am using. I want users to be switched after they edit their profile not after they register. Since there is no promotion system that supports being based off profile fields, I need something like that.
White_Snake
02-12-2010, 06:17 PM
okay, well, your code is requestin the db for data the vbulletin main array already contains, so, try this code and tell me if it works:
if ($vbulletin->userinfo[field6] == 'Yes' AND $vbulletin->userinfo['usergroupid'] =='2')
{
$userdata->set('usergroupid', 10);
}
elseif ($vbulletin->userinfo[field6] == 'No' AND $vbulletin->userinfo['usergroupid'] =='10')
{
$userdata->set('usergroupid', 2);
}
by the way, where did you found this $userdata->set() function? this seems to be a new trick for me
DaPro
02-12-2010, 06:25 PM
okay, well, your code is requestin the db for data the vbulletin main array already contains, so, try this code and tell me if it works:
if ($vbulletin->userinfo[field6] == 'Yes' AND $vbulletin->userinfo['usergroupid'] =='2')
{
$userdata->set('usergroupid', 10);
}
elseif ($vbulletin->userinfo[field6] == 'No' AND $vbulletin->userinfo['usergroupid'] =='10')
{
$userdata->set('usergroupid', 2);
}
by the way, where did you found this $userdata->set() function? this seems to be a new trick for me
Unfortunately it isn't working. I guess it's just not going to work like I want. That's not my code, I just slightly (very slight) modified it to do what I need it to do for my purposes. Not sure where I originally found it.
White_Snake
02-12-2010, 06:29 PM
Unfortunately it isn't working. I guess it's just not going to work like I want. That's not my code, I just slightly (very slight) modified it to do what I need it to do for my purposes. Not sure where I originally found it.
the problem might be that userdata set, im not sure either exactly how it works, the if sections are fine, the problem is the userdata, ill check around to get the exact function but before it, i have a question:
why are you trying to edit the main group and not just add your members to a sub group? it would be much easier AND most of all, you wont overwrite a mod/admin permission if said person tweaks with that button
DaPro
02-12-2010, 06:39 PM
the problem might be that userdata set, im not sure either exactly how it works, the if sections are fine, the problem is the userdata, ill check around to get the exact function but before it, i have a question:
why are you trying to edit the main group and not just add your members to a sub group? it would be much easier AND most of all, you wont overwrite a mod/admin permission if said person tweaks with that button
Will the Additional Usergroup overwrite anything in particular? Otherwise, I was just changing the usergroup because I figured that would be cleaner.
White_Snake
02-12-2010, 06:42 PM
if ($vbulletin->userinfo[field6] == 'Yes' AND $vbulletin->userinfo['usergroupid'] =='2')
{
$membergroupids = $userdata->fetch_field('membergroupids');
if ($membergroupids)
{
$membergroupids = $membergroupids . ", 10";
}
else
{
$membergroupids = 10;
}
$userdata->set('membergroupids', $membergroupids);
}
elseif ($vbulletin->userinfo[field6] == 'No' AND $vbulletin->userinfo['usergroupid'] =='10')
{
$userdata->set('usergroupid', 2);
}
this code should add the user sucessfully, but im not sure how to remove a user from a usergroup, im not sure if there is such a thing as unset, that part is out of my rookie knwoledge, but, send me a PM and lets see what can i do for you :p
--------------- Added 1266007473 at 1266007473 ---------------
Will the Additional Usergroup overwrite anything in particular? Otherwise, I was just changing the usergroup because I figured that would be cleaner.
well, it might be cleaner but, if a co-admin / moderator clicks yes/no his main permission will be overwritten, even you run the risk to get your main permission overwritten, so, dont mess with main usergroups unless you *REALLY* know what you are doing, and as well i hope you are testing this in a password protected forum away from your live one
DaPro
02-12-2010, 06:48 PM
if ($vbulletin->userinfo[field6] == 'Yes' AND $vbulletin->userinfo['usergroupid'] == '2')
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 10
WHERE userid = {$vbulletin->userinfo['userid']}
");
}
elseif ($vbulletin->userinfo[field6] == 'No' AND $vbulletin->userinfo['usergroupid'] == '10')
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 2
WHERE userid = {$vbulletin->userinfo['userid']}
");
}
I was going to try this...
But isn't that what the AND's are for in my if statements? I figured those would make sure that ONLY users who are already in the usergroup '2' can have their usergroup changed. And then if they set it to no then it would remove them and revert them to '2' only if they are already in the usergroup '10'. Does that make sense?
White_Snake
02-12-2010, 06:52 PM
if ($vbulletin->userinfo[field6] == 'Yes' AND $vbulletin->userinfo['usergroupid'] == '2')
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 10
WHERE userid = {$vbulletin->userinfo['userid']}
");
}
elseif ($vbulletin->userinfo[field6] == 'No' AND $vbulletin->userinfo['usergroupid'] == '10')
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 2
WHERE userid = {$vbulletin->userinfo['userid']}
");
}
I was going to try this...
But isn't that what the AND's are for in my if statements? I figured those would make sure that ONLY users who are already in the usergroup '2' can have their usergroup changed. And then if they set it to no then it would remove them and revert them to '2' only if they are already in the usergroup '10'. Does that make sense?
yes, that code will do exactly what you want, but as i say, you will run the risk to overwrite your and your staff main membergroup permissions, so, you must do it with secondary usergroups, and since secondary usergroups are a series of numbers, it requires another mysql structure, which is what im trying to figure out without adding extra queries
DaPro
02-12-2010, 07:00 PM
yes, that code will do exactly what you want, but as i say, you will run the risk to overwrite your and your staff main membergroup permissions, so, you must do it with secondary usergroups, and since secondary usergroups are a series of numbers, it requires another mysql structure, which is what im trying to figure out without adding extra queries
I still don't see how that could happen and that code didn't work, it doesn't like something listed in it. Is there a debugger I could see if any errors are happening?
White_Snake
02-12-2010, 07:07 PM
I still don't see how that could happen and that code didn't work, it doesn't like something listed in it. Is there a debugger I could see if any errors are happening?
i will explain you how could it happen, and about the debug, you can turn on the debug mode just in the same way it can be turned on for vbulletin 3
http://img69.imageshack.us/img69/6458/overwrite.png
your code is overwritting that part, the primary usergroup instead of just adding a new option into the aditional usergroup
DaPro
02-12-2010, 07:10 PM
Haha, I know what it's overwriting, I am not dumb. But what I am saying is THIS
AND $vbulletin->userinfo['usergroupid'] == '2'
Should stop it, because I am not using any additional usergroups, only primary usergroups for admins, staff, mods, etc. Everyone has their own PRIMARY usergroup.
White_Snake
02-12-2010, 07:17 PM
Haha, I know what it's overwriting, I am not dumb. But what I am saying is THIS
AND $vbulletin->userinfo['usergroupid'] == '2'
Should stop it, because I am not using any additional usergroups, only primary usergroups for admins, staff, mods, etc. Everyone has their own PRIMARY usergroup.
okay, lets see then, the last piece of code you posted should work, and i just spotted a error on your mysql query:
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 10
WHERE userid = {$vbulletin->userinfo['userid']}
");
should be:
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 10
WHERE userid = " . $vbulletin->userinfo['userid']. "
");
same for the other below, hope this helps :)
DaPro
02-12-2010, 07:32 PM
This crap is still not working, man I give up.
White_Snake
02-12-2010, 07:47 PM
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = '10'
WHERE userid = " . $vbulletin->userinfo['userid']. "
");
now try it that way, with the 10 in between the lines
as well try to add global $vbulletin; at the begining of the script, sometimes hooks answers in very unexpected forms, or try it in another plugin such as MEMBERINFO which should display any user profile, just for the sake to see if there is something wrong with the plugin location it happend to me once :P
DaPro
02-12-2010, 09:51 PM
That didn't help either, and I don't know how to set it to MEMBERINFO in the hook?
I decided to just scrap this, because I just realize it's not going to fully do what I want.
--------------- Added 1266074015 at 1266074015 ---------------
Okay, so I actually found this script someone made that works as a cronjob when set as a scheduled task. It worked, BUT people were having access issues once they logged in or did anything, it immediately reverted them back to the registered user usergroup.
Any idea as to why from any advanced coders on here?
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.field6='Yes'
");
while ($tmpU = $vbulletin->db->fetch_array($tmpA))
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 10
WHERE userid = " . $tmpU['userid']);
}
$tmpA = $vbulletin->db->query_read("
SELECT user.userid,user.usergroupid,user.username
FROM `user`,`userfield` AS field
WHERE user.usergroupid = 10
AND user.userid=field.userid
AND field.field6='No'
");
while ($tmpU = $vbulletin->db->fetch_array($tmpA))
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 2
WHERE userid = " . $tmpU['userid']);
}
DaPro
02-14-2010, 03:47 PM
Would anyone mind helping me out?
imedic
04-11-2011, 07:24 AM
I am also very interested in having a mod that place an user in a group coresponding to a custom field value.
Mainly If a user set at registration what is he;s job he is then asigned to secondary group that has acces to forums relevant to him. Different jobs can have same group and also same job can have more groups than automatic one (if user set it mannualy).
Registered users dont see a thing in the forum unless they are part of another group (aditional group) so I am SPAM free :) and users, after selection of aditional group see only the relevant part of the forum for them.
This should run as a cron job (some might change job at some point) AND at registration as a user just registering must enter instantly in a group so he can see something. This should not interfere with an user entering another group (as he can have 2 different jobs, one is asigned from the custom field selection, second from he;s selection in usergroups).
I am willing to pay for this mod and release it to general public. I need for both 3.8 and 4.x versions but first for 3.8. If someone wants to participate is more than welcomed.
Please contact me on private.
I see here are requests for unpaied mods, if I post my request wrongly please point me to the right place. Thanks
I see some old mods doing this: for 3.5 (https://vborg.vbsupport.ru/showthread.php?t=82993&page=7), 3.5.4 (https://vborg.vbsupport.ru/showthread.php?t=111870&page=4) (reported to work on 3.7, 3.6.4 (https://vborg.vbsupport.ru/showthread.php?t=148644&highlight=custom+profile&page=2).
If someone knows if one of this work in 3.8 is much appreciated to share.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.