Actually, I think you can comment out this line:
//$changegroup = isset_param('group') ? $group : -1; // Group change requested?
and change
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
to
$currentgroup = get_and_set_current_group($course, $groupmode, $group);
and let me know if this solves the problem. =)
Thanks,
Yu