<?
$title = "Select users";
//template header
require_once($sys['root']."/system/templates/popup/header.inc");
?>

<script language="JavaScript1.2" type="text/javascript" src="?file=share.js&sharename=<?echo urlencode($_GET['object'])?>">
	</script>

<table cellspacing="0" cellpadding="0" border="0" style="width:100%;height:100%;background-color:#F2F2F2">
<tr>
    <td background="images/popup/top-bg.gif" height="26">&nbsp;</td>
</tr>

<tr>
    <td style="padding:10px;" valign="top">
<!-- Popup Contents -->
<script>
atime = false;
function filterUsers() {
	if (atime) {
	window.clearTimeout(atime);
	}
	atime = window.setTimeout('goFilter()', 1000);
}

function goFilter() {
	document.filterForm.submit();
	document.getElementById('loading_msg').style.visibility='visible';
}
</script>
<form name="filterForm" method="post" action="?file=share_select_users_list" target="hidden_iframe">
<table width="100%" align="center">
<tr>
<td><?$lang->display("Filter by group");?></td>
<td><b><?$lang->display("Users");?></b></td>
<td align="right" style="padding-right:22px;"><span id="loading_msg" class="comment" style="visibility:hidden"><?$lang->display("Loading user list...");?></span></td>
</tr>
<tr>
	<td comment="Groups">
<div style="border:1px solid silver;width:213px;height:150px;overflow:auto;background-color:white;">
<table>
<?
$rs = $db->query("SELECT name, id FROM ".$settings->config['groups_tablename']." ".((($options['view_others'] != "-") && ($options['view_others'] != "+"))?"WHERE name='".$str->safeSQL($options['view_others'])."'":"")."");
while (!$rs->EOF) {


$userCount = $db->GetOne("SELECT COUNT(*) 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']."' 
AND groups.id = '".$rs->fields['id']."' ORDER BY interauth.username
");

if ($userCount > 0) {
?>
<tr>
<td><input name="gids[]" type="checkbox" value="<?echo $rs->fields['id'];?>" onclick="filterUsers()" id="group_<?echo $rs->fields['id'];?>"><label for="group_<?echo $rs->fields['id'];?>"><?echo $rs->fields['name'];?></label> <span class="comment">(<?echo $userCount; echo ($userCount > 1)?$lang->get(" users"):$lang->get(" user")?>)</span></td>
</tr>
<?
}

	$rs->MoveNext();
}
?>
</table>
</div>
	</td>
	<td comment="Users" valign="top" colspan="2">
<div style="border:1px solid silver;width:213px;height:110px;overflow:auto;background-color:white;" id="users_list">
<div style="font-size:10px;padding:10px"><?$lang->display("Choose a group to select users from.");?></div></div>
<br>
<?$lang->display("Filter by name:");?> <input type="text" onkeyup="filterUsers()" name="namefilter">
	</td>
</tr>
</table>
</form>



	</td>
</tr>

<tr>
    <td align="center" height="20">
<table border="0" cellspacing="3" cellpadding="1" style="position:relative;top:18px;z-index:1">
<tr>
	<td><?
$tpl->btn(
$lang->get("Add selected users"), 
"addUsers()"
)
?></td>
	<td><?
$tpl->btn(
$lang->get("Close"), 
"self.close();window.close()"
)
?></td>
</tr>
</table>
	</td>
</tr>
<tr>
	<td>
<!-- END Popup Contents -->
	</td>
</tr>
<tr>
    <td background="images/popup/bottom-bg.gif" height="46">&nbsp;</td>
</tr>
</table>
<script>
function loadHTML(str) {
document.getElementById('users_list').innerHTML = str;
}
</script>
<div style="position:absolute;overflow:hidden;width:1px;height:1px;top:-999px;left:-999px;z-index:-99;">
<iframe id="hidden_iframe" name="hidden_iframe"></iframe>
</div>
<?
//template footer
require_once($sys['root']."/system/templates/popup/footer.inc");
?>