Quote:
Originally Posted by Marco van Herwaarden
$aw2gr = $grouparr[$awardval];
What data are you trying to lookup in the $grouparr array? I have the feeling that you don't need that array at all as it seems you are trying to use the same value that is already available as $key.
|
The data that I'm checking for is the vb usergroup ID
the $grouparr is set with the key being the relevant award ID and the value is the vb usergroup ID that needs to be assigned to the user in question.
I see what you're saying though. With that in mind I now have;
PHP Code:
$arr = array (
3 => 50,
5 => 38,
6 => 50,
9 => 53,
12 => 23,
13 => 43,
14 => 43,
17 => 51,
18 => 37,
20 => 53,
21 => 53,
24 => 53,
25 => 53,
29 => 48,
31 => 40,
32 => 39,
38 => 46,
39 => 52
);
// ########################################################################
// ######################### USERGROUP UPDATES ############################
// ######################### GIVE ACCESS ############################
// ########################################################################
foreach ($arr as $key => $val)
{
echo "<br><br>Award=".$key.", Group=".$val;
// check for award and update secondary usergroup if required
$giveawards = $vbulletin->db->query_read("
SELECT award_id, userid
FROM " . TABLE_PREFIX . "award_user
WHERE award_id = $key
");
if ($vbulletin->db->num_rows($giveawards) > 0)
{
while ($giveawardsrow = $vbulletin->db->fetch_array($giveawards))
{ // for each award, check to see if they are a member of the relevant group and update accordingly
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userinfo = fetch_userinfo($giveawardsrow['userid']);
$userdm->set_existing($userinfo);
$membergroupids = $userdm->fetch_field('membergroupids');
echo "<br>Existing Groups=".$membergroupids." | ";
if ($membergroupids != "")
{
$withcomma = "," . $val;
$trailingcomma = $val . ",";
$membergroupids = str_replace("$withcomma", "", $membergroupids);
$membergroupids = str_replace("$trailingcomma", "", $membergroupids);
$membergroupids = str_replace("$val", "", $membergroupids);
if ($membergroupids != "")
{
$membergroupids = $membergroupids . $withcomma;
}
else
{
$membergroupids = $val;
}
}
else
{
$membergroupids = $val;
}
echo "UserID=".$giveawardsrow['userid']." Membergroups=".$membergroupids;
$userdm->set('membergroupids', $membergroupids);
$userdm->pre_save();
if (count($userdm->errors))
{
for ($i = 0; $i < count($userdm->errors); $i++)
{
echo "ERROR{$i}:{$userdm->errors[$i]}\n";
}
}
else
{
// If everything is OK
$userdm->save();
echo " | Account updated!";
$userdm->set_existing($userinfo);
$membergroupids = $userdm->fetch_field('membergroupids');
echo " | UserID=".$giveawardsrow['userid']." Membergroups=".$membergroupids;
}
}
$vbulletin->db->free_result($giveawardsrow);
}
}
It runs, and everything echos out perfectly to the screen. They're just not being updated! The only difference between this code and the copy, paste however many times and hardcode values, is the array.