The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Auto-entry in membergroup by field in profile - 3.5.4
Quick background:
In 3.0.7, I use the following code in phpinclude_start template. Every time a user logs on, it checks for our organization's member password entered into custom field5 in user's profile. The user is then added to or removed from a particular secondary usergroup depending on whether field5 matches the organization password stored in a custom $vbphrase. Membership in the secondary usergroup is used to control access to private forums and a couple of other things on the board. We do it this way because the password changes periodically and we wish all users to have to re-enter the current password into their profiles when the password is updated to prove they are current members and have the current password. PHP Code:
And as a secondary question, is there someplace I can relocate the code to that it would work instantly as the user updates his profile instead of waiting for his next login? |
#2
|
||||
|
||||
1. This is not a Template Modification Release
2. This Code must be ported to 3.5 code 3. phpinclude_start does not exist in 3.5, use global_start instead |
#3
|
||||
|
||||
Quote:
1. I don't understand what you're telling me here. 2. Yes, that's why I came here with the question. 3. I don't find a global_start template in 3.5.4, or a global_start.php in upload. My phpinclude_start template seems to have carried over into 3.5.4, but apparently is never called? |
#4
|
||||
|
||||
global_start is a hook, you need to create a plugin, linked to that hook.
In the code, change '$DB_site' to '$vbulletin->db' and '$bbuserinfo' to '$vbulletin->userinfo' |
#5
|
||||
|
||||
Quote:
[Edit: Additional post follows, concatenated by this board into one post. At first I thought this was a neat feature, but since this doesn't bump the thread up to the top of the list, there no reason for anyone that has already looked at it to ever see the new info. Have deleted yesterday's addition and added todays with latest code.] After several rounds of tweaking, here is the complete code as now entered into the php code window in plugin manager: PHP Code:
Message received in email when password matches and trying to add user to group 12: Quote:
Quote:
What am I missing? PHP and/or SQL syntax error I can't see? Need to declare something global? Need additional code at the beginning of the routine to initialize and populate the user info fields (but the password check DOES seemingly work so the user info fields must be available)? [Edited to add:] Removing the 'global $vbulletin;' line eliminates the SQL error, but the code does not carry through and modify the usergroup. Could this be because all the $vbulletin->whatever values are nul? |
#6
|
||||
|
||||
PHP won't read/process the bold bit properly (as it's written).
Code:
$updatefields = $vbulletin->db->query(" UPDATE user SET membergroupids='12' WHERE userid=$vbulletin->userinfo[userid] "); PHP Code:
PHP Code:
|
#7
|
||||
|
||||
Thanks Paul. I've got the userid working now, apparently, via a variable.
But I think I've got problems with correctly passing the membergroups data. Before messing around with all the logic of when I do what, I thought I'd best get the queries down pat. So here's a basic test case I'm working with right now: PHP Code:
Now, if I do this instead: PHP Code:
But if I have $new_mg = '' or $new_mg = '9,12' I get a database error: Quote:
|
#8
|
||||
|
||||
membergroupids is a string, so you would need this ;
PHP Code:
|
#9
|
||||
|
||||
Thanks again, Paul. Your latest hint got me a lot further. Finally I just created a separate display page with my routine in it. This allowed me to insert a bunch of print() functions to check variables and progress and really get this thing debugged. Seems to be working like a champ.
Here's the final code, in case it will be of use to anybody else (please see questions and concerns below): PHP Code:
Had to frog around with the str_replace() function quite a bit. Couldn't get it to work recursively on itself as PHP Code:
PHP Code:
But if my target were a single digit number, say 3, nulling out '3,' and ',3' via str_replace() could mess up some two-digit group numbers: '3,12,23,31' would become '12,21' .. or even I could have problems if, heaven forbid, we ended up with three digit membergroup numbers. So for MY use for now, this will work, but as a generic routine for others, it's still lacking. Can anybody suggest a way of dealing with removing the target group that would solve this problem? (Maybe by working with the group numbers as an array?) |
#10
|
||||
|
||||
Have rewritten to deal with membergroup numbers comprised of any number of digits. The key was, indeed, to deal with them as an array.
Tested with 3.5.4 - performance with other flavors unknown. To use you'll need: 1) A custom field in your user profile, into which the user can place the required password. 2) A custom $vbphrase in which to store the required password value Enter the appropriate values for your forum into the first three variables in the script below, then install the script via vB 3.5's Plug-in Manager. Tie to the 'global_start' hook. At each login, the script will check the user's profile for the membergroup password, then add or remove the user from the membergroup as appropriate. Note that this does not act instantaneously upon entry of the password in the profile, but requires a new login for this to take effect. PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|