Quote:
Originally Posted by bananalive
PHP Code:
$shuserid = $vbulletin->db->query_first(" SELECT userid FROM ". TABLE_PREFIX ."user WHERE username = '" . $db->escape_string($qo['shuser']) . "' ");
|
Good stuff Banana, thank you. I got it working!

I am using a custom question which selects a user from usergroup 2; reference name = shuser.
PHP Code:
$answer .= '<select name="'.$formbit[id].'">';
$members = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "user
WHERE usergroupid = 2
ORDER BY username ASC");
while($row = $db->fetch_array($members)) {
$answer .= '<option value="'.$row[username].'"';
if ($row[username] == $thisanswer) {
$answer .= 'selected="selected"';
}
$answer .= '>'.$row[username].'</option>';
}
$answer .= '</select>';
Then, here is the code I am using to move a user to a new usergroup:
PHP Code:
$shuserid = $vbulletin->db->query_first("
SELECT userid
FROM ". TABLE_PREFIX ."user
WHERE username = '" . $db->escape_string($qo['shuser']) . "'
");
//print_r($shuserid['userid']);
if ($complete) {
$userinfo=fetch_userinfo($shuserid[userid]);
//**Replace 18 with choosen usergroupid you want to add them to**//
$user['usergroupid'] = 18;
if (empty($user['usergroupid'])) {
$user['usergroupid'] = 2;
}
$getusergroupid = iif($userinfo['displaygroupid'] != $userinfo['usergroupid'], $userinfo['displaygroupid'], $user['usergroupid']);
$user_usergroup =& $vbulletin->usergroupcache["$user[usergroupid]"];
$display_usergroup =& $vbulletin->usergroupcache["$getusergroupid"];
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($userinfo);
$userdata->set('usergroupid', $user['usergroupid']);
$userdata->set_usertitle(
$user['customtitle'] ? $user['usertitle'] : '',
false,
$display_usergroup,
($user_usergroup['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canusecustomtitle']) ? true : false,
($user_usergroup['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['cancontrolpanel']) ? true : false
);
require_once(DIR . '/includes/functions_ranks.php');
if ($user['userid'] == $vbulletin->userinfo['userid']) {
$vbulletin->userinfo['usergroupid'] = $user['usergroupid'];
$vbulletin->userinfo['displaygroupid'] = $user['usergroupid'];
}
$userdata->save();
}