<script>
tb = parent.AfianHandler['allTabs']['<?echo 
$_GET['tabid'];?>'];
<?
if ($_SESSION['username'] == "admin") {

/* no item selected */
if ($_POST['itemlist'] == "") {
	iframeAlert($lang->get("Empty user list."));
	echo "parent.AdmUsersEndAction(tb);</script>";
	exit();
}

/* checking input */
$split = explode("|", $str->fromHTML($_POST['itemlist']));
for ($i = 0 ; $i < sizeof($split) ; $i++) {
	if ($split[$i] != "") {
		$items[] = $split[$i];
	}
}



$sys['temp']['gid'] = $str->fromHTML($_GET['togid']);
$sys['temp']['groupname'] = $auth->gid2name($sys['temp']['gid']);


if (!$auth->getGroupInfo($sys['temp']['gid'])) {
	iframeAlert($lang->get("Destination group does not exist anymore."));
	echo "parent.AdmUsersEndAction(tb);</script>";
	exit();
}


foreach ($items as $uid) {
		$sys['temp']['uid'] = $uid;
		$userInfo = $auth->getUserInfoById($sys['temp']['uid']);
		$sys['temp']['username'] = $userInfo['username'];
		if ($sys['temp']['uid'] != "1") {
			if ($userInfo['gid'] == $sys['temp']['gid']) {
				$iframeAlertMsg[] = $lang->get("User \"%1\" is already in group \"%2\".", array($sys['temp']['username'], $sys['temp']['groupname']));
			} else {
				if ($auth->transferUser($sys['temp']['uid'], $sys['temp']['gid'])) {
					$log->act("0", "user transfer", "".$sys['temp']['username']." (".$sys['temp']['uid'].") TO ".$sys['temp']['groupname']." (".$sys['temp']['gid'].")");
					$iframeAlertMsg[] = "<span class=\"nowrap\">">$lang->get("User \"%1\" transfered to group \"%2\"", array($sys['temp']['username'], $sys['temp']['groupname']))."</span>";
					?>
				if (tb != undefined) {
				tb.removeItem('<?echo $str->safeJS($uid);?>');
				}
					<?
				} else {
					$log->act("1", "user transfer", "".$sys['temp']['username']." (".$sys['temp']['uid'].") TO ".$sys['temp']['groupname']." (".$sys['temp']['gid'].") - ".$auth->error."");
					$iframeAlertMsg[] = $lang->get("Failed to transfer user \"%1\" to group \"%2\".", array($sys['temp']['username'], $sys['temp']['groupname']));
				}
			}
		} else {
			$iframeAlertMsg[] = $lang->get("You cannot transfer user \"admin\".");
		}
		
	}


}
?>

parent.AdmUsersEndAction(tb);
<?iframeAlert($iframeAlertMsg);?>
</script>