I have a script here, and it all works fairly well except updating the usergroup.
PHP Code:
function extend_user($username, $extTime)
{
global $vbulletin;
$extUserInfo = $vbulletin->db->query_first("SELECT usergroupid, userid FROM " . TABLE_PREFIX . "user WHERE `username`='{$vbulletin->GPC['username']}' LIMIT 1");
if(empty($extUserInfo))
{
return "Error: There's no such user \"$username\"!!";
}
$extSubInfo = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "subscriptionlog WHERE `userid`={$extUserInfo['userid']} ORDER BY `expirydate` DESC");
if(empty($extSubInfo))
{
return "Error: The user \"$username\" has no subscriptions!!";
}
$extSubscription = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "subscription WHERE `subscriptionid` = {$extSubInfo['subscriptionid']}");
if(empty($extSubscription))
{
return "Error: Invalid subscription data!";
}
$newTime = $extSubInfo['expirydate'] + $extTime;
if($newTime < time()) {
return "Error: The new time [" . date("d M Y", $newTime) . "] is less than current time [" . date("d M Y") . "]";
}
$extAdd = $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "subscriptionlog SET `status`='1', `expirydate`='$newTime' WHERE `userid`={$extUserInfo['userid']} AND `expirydate`='{$extSubInfo['expirydate']}'");
if(!$extAdd)
{
return "Error: Unable to extend user \"$username\", unknown SQL Error!";
}
// Set this only AFTER we set their *valid* time.
if($extUserInfo['usergroupid'] != $extSubscription['nusergroupid']) {
$groupChange = $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET `usergroupid`='{$extSubscription['nusergroupid']}' WHERE `userid`='{$extUserInfo['userid']}'");
if(!$groupChange)
{
return "Error: Unable to update user \"$username\" usergroup, contact admin!";
}
}
return null;
}
The function is meant to add time to a subscription, and it all works very well except when I change their usergroup using the "user" table, it does not seem to update their display on the forum. Wondering if anyone knows a solution.