<html>
<head>
	<title></title>
</head>

<body>
<textarea id="txtarea">
<?
if (sizeof($_POST['gids']) > 0) {

$sqlExtra = "";
for ($i = 0 ; $i < sizeof($_POST['gids']); $i++) {
	if ($i == 0) {
	$sqlExtra .= "AND ".((sizeof($_POST['gids']) > 1)?"(":"")."users.gid='".$_POST['gids'][$i]."' ";
	} else {
	$sqlExtra .= "OR users.gid='".$_POST['gids'][$i]."' ";
	}
	
	if ($i == sizeof($_POST['gids'])-1 && sizeof($_POST['gids']) > 1) {
	$sqlExtra .= ")";
	}
}

if ($_POST['namefilter']) {
	$sqlExtra .= " AND ((interauth.username like '%".$str->fromHTML($_POST['namefilter'])."%') OR (optinfo.firstname like '%".$str->fromHTML($_POST['namefilter'])."%') OR (optinfo.lastname like '%".$str->fromHTML($_POST['namefilter'])."%'))";
}



$rs = $db->query("SELECT interauth.username,interauth.id,users.gid,groups.name AS gname,optinfo.firstname,optinfo.lastname FROM ".$settings->config['interauth_tablename']." AS interauth, ".$settings->config['users_tablename']." AS users, ".$settings->config['optinfo_tablename']." as optinfo, ".$settings->config['groups_tablename']." AS groups WHERE 
interauth.id = users.id 
AND groups.id=users.gid 
AND users.shareaccess != '0' 
AND users.id = optinfo.uid 
AND groups.shareaccess != '0' 
AND users.id != '".$auth->currentUserInfo['id']."' 

".$sqlExtra."
ORDER by interauth.username
");



if ($rs->RecordCount() > 0) {
?>
<table>
<?
	while (!$rs->EOF) {
?>
<tr title="<?echo "User's group: ".$rs->fields['gname'];?>">
<td>
<input type="checkbox" name="usernames[]" value="<?echo $str->safeJS($rs->fields['username'])?>" id="user_<?echo $str->safeJS($rs->fields['id'])?>" checked><label for="user_<?echo $str->safeJS($rs->fields['id'])?>"><?echo $rs->fields['username']?></label>
</td>
<td>
<?
if ($rs->fields['firstname'] || $rs->fields['lastname']) {
	echo "<span class=\"comment\">(";
}
echo $rs->fields['firstname'];
echo " ";
echo $rs->fields['lastname'];
if ($rs->fields['firstname'] || $rs->fields['lastname']) {
	echo ")</span>";
}
?> 
</td>
</tr>
<?
	$rs->MoveNext();
	}
?>
</table>
<?
} else {
	echo "<div style=\"padding:10px;font-size:10px\">">$lang->get("No results.")."<br>".$lang->get("Try another filtering criteria.")."</div>";
}
} else {
	echo "<div style=\"padding:10px;font-size:10px\">".$lang->get("Select at least one group.")."</div>";
}
?>
</textarea>
<script>
parent.loadHTML(document.getElementById('txtarea').value);
parent.document.getElementById('loading_msg').style.visibility='hidden';
</script>
</body>
</html>
