Quote:
Originally Posted by Paul M
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'
|
Very helpful, thank you very much. You gave me just enough information to enable me to find the tutorials I needed, so I'm off to give it a go ....
[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:
// Add or remove user from Org Members secondary usergroup (12)
// according to Org Pwd value (filed5) in user's profile
global $vbulletin;
if ($vbulletin->userinfo[field5] == $vbphrase[org_member_password]) // Correct pwd in profile
{
if ($vbulletin->userinfo[membergroupids] == '') // if no membergroupids already set, set to 12
{
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids='12'
WHERE userid=$vbulletin->userinfo[userid]
");
}
elseif ((strpos($vbulletin->userinfo[membergroupids], '12'))=== false) // else if group 12 not found
// add 12 to list
{
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids=concat_ws(',', $vbulletin->userinfo[membergroupids], '12')
WHERE userid=$vbulletin->userinfo[userid]
");
}
}
else // Correct pwd NOT in profile
{
if ((strpos($vbulletin->userinfo[membergroupids], '12')) > 0) // if listed in usergroup 12
{
if ($vbulletin->userinfo[membergroupids] == '12') // 12 only usergroup listed
// blank out membergroupids
{
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids=''
WHERE (userid=$vbulletin->userinfo[userid])
");
}
else // 12 is one of several
{
if ((strpos($vbulletin->userinfo[membergroupids], ',12')) > 0) // if not first in list
// remove ,12
{
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids=replace($vbulletin->userinfo[membergroupids], ',12', '')
WHERE (userid=$vbulletin->userinfo[userid])
");
}
else // must be first in list
// remove 12,
{
$updatefields = $vbulletin->db->query("
UPDATE user
SET membergroupids=replace($vbulletin->userinfo[membergroupids], '12,', '')
WHERE (userid=$vbulletin->userinfo[userid])
");
}
}
}
}
Hooked to global_start as suggested above by Andreas. Generates SQL error when logging in or out that stops execution. At least it doesn't seem to farge the database.
Message received in email when password matches and trying to add user to group 12:
Quote:
Invalid SQL:
UPDATE user
SET membergroupids=concat_ws(',', Array[membergroupids], '12')
WHERE userid=Array[userid];
MySQL Error : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '[membergroupids], '12')
WHERE userid=Array[useri
Error Number : 1064
|
Message received in email when password doesn't match and trying to remove user from group 12:
Quote:
Invalid SQL:
UPDATE user
SET membergroupids=replace(Array[membergroupids], ',12', '')
WHERE (userid=Array[userid]);
MySQL Error : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '[membergroupids], ',12', '')
WHERE (use
Error Number : 1064
|
So it appears the password check, at least, is working. Looks to my novice, untrained eye that it is trying to pass the entire [membergroups] and [userid] arrays instead of the specific value for the user.
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?