<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 
set_magic_quotes_runtime(0);

include("oldinclude/dbcommon.php");
include("oldinclude/##@TABLE.strShortTableName s##_variables.php");
##if @BUILDER.arrLanguages.len>1##
include("oldinclude/languages.php");
##endif##


$gsqlHead="select ##@BUILDER.strUserNameField ws## ";
$gsqlFrom="from ##@BUILDER.strLoginTable ts##";
$gsqlWhere="";
$gsqlTail="";
// $gstrSQL = "##@TABLE.strSQL ls##";
$gstrSQL = gSQLWhere("");


##if @BUILDER.bCreateLoginPage##
if(!@$_SESSION["UserID"])
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}
if(!$_SESSION["IsAdmin"])
{
	echo "<p>".##message NO_PERMISSIONS##." <a href=\"login.php\">".##message BACK_TO_LOGIN##."</a></p>";
	return;
}
##endif##


include('oldlibs/Smarty.class.php');
$smarty = new Smarty();



$conn=db_connect();


//	process reqest data, fill session variables

if(!count($_POST) && !count($_GET))
{
	$sess_unset = array();
	foreach($_SESSION as $key=>$value)
		if(substr($key,0,strlen($strTableName)+1)==$strTableName."_" &&
			strpos(substr($key,strlen($strTableName)+1),"_")===false)
			$sess_unset[] = $key;
	foreach($sess_unset as $key)
		unset($_SESSION[$key]);
}

//	Before Process event
if(function_exists("BeforeProcessList"))
	BeforeProcessList($conn);

if(@$_REQUEST["a"]=="showall")
	$_SESSION[$strTableName."_search"]=0;
else if(@$_REQUEST["a"]=="search")
{
	$_SESSION[$strTableName."_searchfield"]=postvalue("SearchField");
	$_SESSION[$strTableName."_searchoption"]=postvalue("SearchOption");
	$_SESSION[$strTableName."_searchfor"]=postvalue("SearchFor");
	if(postvalue("SearchFor")!="" || postvalue("SearchOption")=='Empty')
		$_SESSION[$strTableName."_search"]=1;
	else
		$_SESSION[$strTableName."_search"]=0;
	$_SESSION[$strTableName."_pagenumber"]=1;
}
else if(@$_REQUEST["a"]=="advsearch")
{
	$_SESSION[$strTableName."_asearchnot"]=array();
	$_SESSION[$strTableName."_asearchopt"]=array();
	$_SESSION[$strTableName."_asearchfor"]=array();
	$_SESSION[$strTableName."_asearchfor2"]=array();
	$tosearch=0;
	$asearchfield = postvalue("asearchfield");
	$_SESSION[$strTableName."_asearchtype"] = postvalue("type");
	if(!$_SESSION[$strTableName."_asearchtype"])
		$_SESSION[$strTableName."_asearchtype"]="and";
	foreach($asearchfield as $field)
	{
		$gfield=GoodFieldName($field);
		$asopt=postvalue("asearchopt_".$gfield);
		$value1=postvalue("value_".$gfield);
		$type=postvalue("type_".$gfield);
		$value2=postvalue("value1_".$gfield);
		$not=postvalue("not_".$gfield);
		if($value1 || $asopt=='Empty')
		{
			$tosearch=1;
			$_SESSION[$strTableName."_asearchopt"][$field]=$asopt;
			if(!is_array($value1))
				$_SESSION[$strTableName."_asearchfor"][$field]=$value1;
			else
				$_SESSION[$strTableName."_asearchfor"][$field]=combinevalues($value1);
			$_SESSION[$strTableName."_asearchfortype"][$field]=$type;
			if($value2)
				$_SESSION[$strTableName."_asearchfor2"][$field]=$value2;
			$_SESSION[$strTableName."_asearchnot"][$field]=($not=="on");
		}
	}
	if($tosearch)
		$_SESSION[$strTableName."_search"]=2;
	else
		$_SESSION[$strTableName."_search"]=0;
	$_SESSION[$strTableName."_pagenumber"]=1;
}

##if @BUILDER.arrLanguages.len>1##
if(@$_REQUEST["language"])
	$_SESSION["language"]=@$_REQUEST["language"];
$smarty->assign("language",mlang_getcurrentlang());
##endif##

if(@$_REQUEST["orderby"])
{
	$_SESSION[$strTableName."_orderby"]=@$_REQUEST["orderby"];
	$_SESSION[$strTableName."_pagenumber"]=1;
}

if(@$_REQUEST["pagesize"])
{
	$_SESSION[$strTableName."_pagesize"]=@$_REQUEST["pagesize"];
	$_SESSION[$strTableName."_pagenumber"]=1;
}

if(@$_REQUEST["goto"])
	$_SESSION[$strTableName."_pagenumber"]=@$_REQUEST["goto"];


//	process reqest data - end

$includes="";


$includes.="<script type=\"text/javascript\" src=\"oldinclude/jquery.js\"></script>\r\n";
$includes.="<script type=\"text/javascript\" src=\"oldinclude/ajaxsuggest.js\"></script>\r\n";

$includes.="<script type=\"text/javascript\" src=\"oldinclude/jsfunctions.js\">".
"</script>\n".
"<script type=\"text/javascript\">".
"\nvar bSelected=false;".
"\nvar TEXT_FIRST = \"".##message FIRST##."\";".
"\nvar TEXT_PREVIOUS = \"".##message PREVIOUS##."\";".
"\nvar TEXT_NEXT = \"".##message NEXT##."\";".
"\nvar TEXT_LAST = \"".##message LAST##."\";".
"\nvar TEXT_PLEASE_SELECT='".jsreplace(##message PLEASE_SELECT##)."';".
"\nvar TEXT_SAVE='".jsreplace(##message SAVE##)."';".
"\nvar TEXT_CANCEL='".jsreplace(##message CANCEL##)."';".
"\nvar TEXT_INLINE_ERROR='".jsreplace(##message INLINE_ERROR##)."';".
"\nvar locale_dateformat = ".$locale_info["LOCALE_IDATE"].";".
"\nvar locale_datedelimiter = \"".$locale_info["LOCALE_SDATE"]."\";".
"\nvar bLoading=false;\r\n";

if ($useAJAX) {
	$includes.="var INLINE_EDIT_TABLE='##@TABLE.strShortTableName##_edit.php';\r\n";
	$includes.="var INLINE_ADD_TABLE='##@TABLE.strShortTableName##_add.php';\r\n";
	$includes.="var INLINE_VIEW_TABLE='##@TABLE.strShortTableName##_view.php';\r\n";
	$includes.="var SUGGEST_TABLE='##@TABLE.strShortTableName##_searchsuggest.php';\r\n";
	$includes.="var MASTER_PREVIEW_TABLE='##@TABLE.strShortTableName##_masterpreview.php';\r\n";
}
$includes.="\n</script>\n";
$includes.="<div id=\"search_suggest\"></div>";

$smarty->assign("includes",$includes);
$smarty->assign("useAJAX",$useAJAX);

$linkdata="<script language=javascript>
$('[@disptype=controltable1]').hide();
</script>";
$smarty->assign("linkdata",$linkdata);


//	process session variables
//	order by
$strOrderBy="";
$order_ind=-1;

##foreach Fields as @f filter @f.bListPage##
$smarty->assign("order_dir_##@f.strName g##","a");
##endfor##





if(postvalue("a")=="save")
{
	$useridx=0;
	foreach(postvalue("username") as $user)
	{
		$useridx++;
//	delete records which are not needed
		$sql="delete from ##@BUILDER.strUGMembers ts## where UserName='".db_addslashes($user)."'";
		if($user==$_SESSION["UserID"])
			$sql.=" and GroupID<>-1";
		db_exec($sql,$conn);
		if(count($_POST["cb_".$useridx]))
		{
			$glist="";
			foreach(@$_POST["cb_".$useridx] as $g)
			{
				if($g<0)
				{
					if($user==$_SESSION["UserID"] && $g==-1)
						continue;
					$sql="insert into ##@BUILDER.strUGMembers ts## (UserName,GroupID) values ('".htmlspecialchars($user)."',".$g.")";
					db_exec($sql,$conn);
				}
				else
				{
					if($glist!="")
						$glist.=",";
					$glist.=$g;
				}
			}
			if($glist!="")
			{
				$sql="insert into ##@BUILDER.strUGMembers ts## (UserName,GroupID) select '".htmlspecialchars($user)."',GroupID from ##@BUILDER.strUGGroups ts## where GroupID in (".$glist.")";
				db_exec($sql,$conn);
			}
		}
	}







}


if(@$_SESSION[$strTableName."_orderby"]=="D")
	$strOrderBy="Order by 1 desc";
else
	$strOrderBy="Order by 1 asc";

$sortbygroup=true;
if(!@$_SESSION[$strTableName."_orderby"] || @$_SESSION[$strTableName."_orderby"]=="A" || @$_SESSION[$strTableName."_orderby"]=="D")
	$sortbygroup=false;

//	page number
$mypage=(integer)$_SESSION[$strTableName."_pagenumber"];
if(!$mypage)
	$mypage=1;

//	page size
$PageSize=(integer)$_SESSION[$strTableName."_pagesize"];
if(!$PageSize)
	$PageSize=$gPageSize;

	$smarty->assign("rpp10_selected",($PageSize==10)?"selected":"");
	$smarty->assign("rpp20_selected",($PageSize==20)?"selected":"");
	$smarty->assign("rpp30_selected",($PageSize==30)?"selected":"");
	$smarty->assign("rpp50_selected",($PageSize==50)?"selected":"");
	$smarty->assign("rpp100_selected",($PageSize==100)?"selected":"");
	$smarty->assign("rpp500_selected",($PageSize==500)?"selected":"");

//	make sql "select" string

$strWhereClause="";


//	select groups list
$groups=array();
$groups[]=array(-1,"<Admin>");
$groupfullchecked=array();
$groupfullchecked[]=true;

$trs = db_query("select GroupID,Label from ##@BUILDER.strUGGroups ts## order by Label",$conn);
while($tdata = db_fetch_numarray($trs))
{
	$groups[]=array($tdata[0],$tdata[1]);
	$groupfullchecked[]=true;
}
//	select members list
$members=array();
$trs = db_query("select UserName,GroupID from ##@BUILDER.strUGMembers ts## order by UserName,GroupID",$conn);
while($tdata = db_fetch_numarray($trs))
{
	$members[]=array($tdata[1],$tdata[0]);
}

$smartygroups = array();
foreach($groups as $g)
{
	$smartygroups[]=array("name"=>htmlspecialchars($g[1]),
	"order_link"=>$g[0],
	"checkbox"=>"name=\"".$g[0]."\" onclick=\"var chk = this.checked; \$('input[@type=checkbox][@value\='+this.name+'][@name^=cb_]').each( function(){this.checked=chk;})\""
	);
}

//	add search params

if(@$_SESSION[$strTableName."_search"]==1)
//	 regular search
{  
	$strSearchFor=trim($_SESSION[$strTableName."_searchfor"]);
	$strSearchOption=trim($_SESSION[$strTableName."_searchoption"]);
	if(@$_SESSION[$strTableName."_searchfield"])
	{
		$strSearchField = $_SESSION[$strTableName."_searchfield"];
		if($where = StrWhere($strSearchField, $strSearchFor, $strSearchOption, ""))
			$strWhereClause = whereAdd($strWhereClause,$where);
		else
			$strWhereClause = whereAdd($strWhereClause,"1=0");
	}
	else
	{
		$strWhere = "1=0";
		##foreach Fields as @f filter @f.bSearch##
		if($where=StrWhere("##@f.strName s##", $strSearchFor, $strSearchOption, ""))
			$strWhere .= " or ".$where;
		##endfor##
		$strWhereClause = whereAdd($strWhereClause,$strWhere);
//		$strSQL = AddWhere($strSQL,$strWhere);
	}
}

$strSQL = gSQLWhere($strWhereClause);

//	order by
$strSQL.=" ".trim($strOrderBy);

//	save SQL for use in "Export" and "Printer-friendly" pages

$_SESSION[$strTableName."_sql"] = $strSQL;
$_SESSION[$strTableName."_where"] = $strWhereClause;
$_SESSION[$strTableName."_order"] = $strOrderBy;

//	select and display records
	$strSQLbak = $strSQL;
	if(function_exists("BeforeQueryList"))
		BeforeQueryList($strSQL,$strWhereClause,$strOrderBy);
//	Rebuild SQL if needed
	if($strSQL!=$strSQLbak)
	{
//	changed $strSQL - old style	
		$numrows=GetRowCount($strSQL);
	}
	else
	{
		$strSQL = gSQLWhere($strWhereClause);
		$strSQL.=" ".trim($strOrderBy);
		$numrows=gSQLRowCount($strWhereClause);
	}
	LogInfo($strSQL);

//	 Pagination:
	if(!$numrows)
	{
		$smarty->assign("rowsfound",false);
		$message=##message NO_RECORDS##;
		$smarty->assign("message",$message);
	}
	else
	{
		$smarty->assign("rowsfound",true);
		$smarty->assign("records_found",$numrows);
		$maxRecords = $numrows;
		$maxpages=ceil($maxRecords/$PageSize);
		if($mypage > $maxpages)
			$mypage = $maxpages;
		if($mypage<1) 
			$mypage=1;
		$maxrecs=$PageSize;
		$smarty->assign("page",$mypage);
		$smarty->assign("maxpages",$maxpages);

//	write pagination
$smarty->assign("pagination","<script language=\"JavaScript\">WritePagination(".$mypage.",".$maxpages.");
		function GotoPage(nPageNumber)
		{
			window.location='##@TABLE.strShortTableName##_list.php?goto='+nPageNumber;
		}
</script>");

}
if(!$sortbygroup)
{
	if($numrows)
	{
//	order by users or nothing - use LIMIT
		
##if @BUILDER.nDatabaseType==DATABASE_MySQL##
		$strSQL.=" limit ".(($mypage-1)*$PageSize).",".$PageSize;
	}
	$rs=db_query($strSQL,$conn);
##elseif @BUILDER.nDatabaseType==DATABASE_MSSQLServer##
		$strSQL = AddTop($strSQL, $mypage*$PageSize);
	}
	$rs=db_query($strSQL,$conn);
	db_pageseek($rs,$PageSize,$mypage);
##elseif @BUILDER.nDatabaseType==DATABASE_Access##
		$strSQL = AddTop($strSQL, $mypage*$PageSize);
	}
	$rs=db_query_direct($strSQL,$conn,$numrows);
	db_pageseek($rs,$PageSize,$mypage);
##elseif @BUILDER.nDatabaseType==DATABASE_Oracle##
		$strSQL = AddRowNumber($strSQL, $mypage*$PageSize);
	}
	$rs=db_query_direct($strSQL,$conn,$numrows);
	db_pageseek($rs,$PageSize,$mypage);
##elseif @BUILDER.nDatabaseType==DATABASE_PostgreSQL##
		$maxrecs=$PageSize;
		$strSQL.=" limit ".$PageSize." offset ".(($mypage-1)*$PageSize);
	}
	$rs=db_query($strSQL,$conn);
##endif##
}
else
{
	$rs=db_query($strSQL,$conn);
}

//	fill $rowinfo array
	$rowinfo = array();
	$shade=false;
	$recno=1;
	$editlink="";
	$copylink="";

	while($data=db_fetch_array($rs))
	{
		if(function_exists("BeforeProcessRowList"))
		{
			if(!BeforeProcessRowList($data))
				continue;
		}
		break;
	}

	while($data && ($sortbygroup || $recno<=$PageSize))
	{
		$row=array();
##if !@TABLE.bListVerticalLayout##
		if(!$shade)
		{
			$row["shadeclass"]='class="shade"';
			$row["shadeclassname"]="shade";
			$shade=true;
		}
		else
		{
			$row["shadeclass"]="";
			$row["shadeclassname"]="";
			$shade=false;
		}
##endif##

//	create checkboxes		
		$member_indexes=array();
		foreach($members as $idx=>$m)
		{
			if($m[1]==$data["##@BUILDER.strUserNameField s##"])
				$member_indexes[]=$idx;
		}
		$row["groups"]=array();
		$userfullchecked=true;
		foreach($groups as $idx=>$g)
		{
			$checked=false;
			$smarty_group=array();
			foreach($member_indexes as $i)
			{
				if($members[$i][0]==$g[0])
				{
					$smarty_group["checked"]="checked";
					break;
				}
			}
			if(!$smarty_group["checked"])
			{
				$userfullchecked=false;
				$groupfullchecked[$idx]=false;
			}
			$smarty_group["name"]="name=\"cb_".$recno."[]\" value=\"".$g[0]."\"";
			$smarty_group["group"]=$g[0];
			$row["groups"][]=$smarty_group;
		}
		if($userfullchecked)
			$row["usercheckbox"]="checked";
		$row["username"]=htmlspecialchars($data["##@BUILDER.strUserNameField s##"]);
		$row["user"]=$data["##@BUILDER.strUserNameField s##"];
		$row["username_hidden"]="value=\"".htmlspecialchars($data["##@BUILDER.strUserNameField s##"])."\"";
		$row["checkboxname"]="name=\"user_".htmlspecialchars($data["##@BUILDER.strUserNameField s##"])."\"";
		while($data=db_fetch_array($rs))
		{
			if(function_exists("BeforeProcessRowList"))
			{
				if(!BeforeProcessRowList($data))
					continue;
			}
			break;
		}
		$row["recno"]=$recno;
		$recno++;
			
		$rowinfo[]=$row;
	}
	
	foreach($smartygroups as $idx=>$g)
	{
		if($groupfullchecked[$idx])
			$smartygroups[$idx]["checkbox"].=" checked";
	}
	
//	sort rowinfo
if($sortbygroup)
{
	$sortgroup=substr($_SESSION[$strTableName."_orderby"],1);
	$sortorder=substr($_SESSION[$strTableName."_orderby"],0,1);
	usort($rowinfo,"sortfunc");
	
// apply pagination
	$firstindex=$PageSize*($mypage-1);
	for($i=0;$i<$firstindex;$i++)
		array_shift($rowinfo);
	if(count($rowinfo)>$PageSize)
		array_splice($rowinfo,$PageSize,count($rowinfo)-$PageSize);
	$recno=1;
	$shade=false;
	for($i=0;$i<count($rowinfo);$i++)
	{
		for($j=0;$j<count($rowinfo[$i]["groups"]);$j++)
			$rowinfo[$i]["groups"][$j]["name"]="name=\"cb_".$recno."[]\" value=\"".$rowinfo[$i]["groups"][$j]["group"]."\"";
		$recno++;
		if(!$shade)
		{
			$rowinfo[$i]["shadeclass"]='class="shade"';
			$rowinfo[$i]["shadeclassname"]="shade";
			$shade=true;
		}
		else
		{
			$rowinfo[$i]["shadeclass"]="";
			$rowinfo[$i]["shadeclassname"]="";
			$shade=false;
		}
	}
}

//		assign sort links
foreach($groups as $i=>$g)
{
	if($sortbygroup && $sortgroup==$g[0] && $sortorder=="a")
	{
		$smartygroups[$i]["order_link"]="d".$g[0];
		$smartygroups[$i]["order_img"] = "<img src=\"images/up.gif\" border=0>";
	}
	else
	{
		$smartygroups[$i]["order_link"]="a".$g[0];
		if($sortbygroup && $sortgroup==$g[0] && $sortorder=="d")
		$smartygroups[$i]["order_img"] = "<img src=\"images/down.gif\" border=0>";
	}
		
}
if($sortbygroup || @$_SESSION[$strTableName."_orderby"]!="A")
	$smarty->assign("users_orderlink","A");
else
	$smarty->assign("users_orderlink","D");
if(!$sortbygroup)
{
	if(@$_SESSION[$strTableName."_orderby"]=="A")
		$smarty->assign("users_orderimg","<img src=\"images/up.gif\" border=0>");
	else if(@$_SESSION[$strTableName."_orderby"]=="D")
		$smarty->assign("users_orderimg","<img src=\"images/down.gif\" border=0>");
}

$smarty->assign_by_ref("rowinfo",$rowinfo);
$smarty->assign_by_ref("groups",$smartygroups);


##if Fields[bSearch=1].len##
if(CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
{
	if($_SESSION[$strTableName."_search"]==1)
	{
		$onload = "onLoad=\"if(document.getElementById('SearchFor')) document.getElementById('ctlSearchFor').focus();\"";
		$smarty->assign("onload",$onload);
//	fill in search variables
	//	field selection
	##foreach Fields as @f filter @f.bSearch##
		if(@$_SESSION[$strTableName."_searchfield"]=="##@f.strName s##")
			$smarty->assign("search_##@f.strName g##","selected");
	##endfor##
	// search type selection
		if(@$_SESSION[$strTableName."_searchoption"]=="Contains")
			$smarty->assign("search_contains_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="Equals")
			$smarty->assign("search_equals_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="Starts with ...")
			$smarty->assign("search_startswith_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="More than ...")
			$smarty->assign("search_more_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="Less than ...")
			$smarty->assign("search_less_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="Equal or more than ...")
			$smarty->assign("search_equalormore_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="Equal or less than ...")
			$smarty->assign("search_equalorless_option_selected","selected");		
		if(@$_SESSION[$strTableName."_searchoption"]=="Empty")
			$smarty->assign("search_empty_option_selected","selected");		

		$smarty->assign("search_searchfor","value=\"".htmlspecialchars(@$_SESSION[$strTableName."_searchfor"])."\"");
	}
}
##endif##

##if @BUILDER.bCreateLoginPage##
$smarty->assign("userid",htmlspecialchars($_SESSION["UserID"]));
##endif##


##if GroupSecurity##
//	table selector
##foreach @BUILDER.Tables as @t filter (@t.bMenuItem || @t.arrMasterTables[strMasterTable==@TABLE.strDataSourceTable].len)##
$strPerm = GetUserPermissions("##@t.strDataSourceTable s##");
$smarty->assign("allow_##@t.strShortTableName##",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
##endfor##
##endif##

##if Fields[bSearch=1].len##
$smarty->assign("displayheader","<script language=\"JavaScript\">DisplayHeader();</script>");
##endif##

	$smarty->assign("allow_delete",false);
	$smarty->assign("allow_add",false);
	$smarty->assign("allow_edit",false);
	$smarty->assign("allow_export",false);
	$smarty->assign("allow_import",false);
	$smarty->assign("allow_search",true);
	$smarty->assign("allow_deleteorexport",false);

	$smarty->assign("display_grid",true);

##foreach @TABLE.arrMasterTables as @m filter @m.bDisplayInfo##
##if @first##
//	display master table info
$masterkeys=array();
$smarty->assign("showmasterfile","empty.htm");
##endif##
if($mastertable=="##@m.strMasterTable s##")
{
//	include proper masterlist.php code
	include("oldinclude/##@BUILDER.Tables[strDataSourceTable==@m.strMasterTable].strShortTableName##_masterlist.php");
	##foreach @m.arrDetailKeys as @mk##
	$masterkeys[]=@$_SESSION[$strTableName."_masterkey##@index##"];
	##endfor##
	DisplayMasterTableInfo("##@TABLE.strDataSourceTable s##", $masterkeys);
	$smarty->assign("showmasterfile","##@BUILDER.Tables[strDataSourceTable==@m.strMasterTable].strShortTableName##_masterlist.htm");
}
##endfor##


$strSQL=$_SESSION[$strTableName."_sql"];

$defaulturl="";
##if CreateMenu##
		$defaulturl="menu.php";
##else##
	##foreach @BUILDER.Tables as @t filter @t.bMenuItem order @t.nMenuOrder##
		##if @first##
		##if @t.bList##
		$defaulturl="##@t.strShortTableName##_list.php";
		##elseif @t.nType==titREPORT##
		$defaulturl="##@t.strShortTableName##_report.php";
		##elseif @t.nType==titCHART##
		$defaulturl="##@t.strShortTableName##_chart.php";
		##else##
		$defaulturl="##@t.strShortTableName##_add.php";
		##endif##
		##endif##
	##endfor##
##endif##			
##if !@BUILDER.Tables[bMenuItem].len##
	##if @BUILDER.Tables.bList##
		$defaulturl="##@BUILDER.Tables.strShortTableName##_list.php";
	##elseif @t.nType==titREPORT##
		$defaulturl="##@BUILDER.Tables.strShortTableName##_report.php";
	##elseif @t.nType==titCHART##
		$defaulturl="##@BUILDER.Tables.strShortTableName##_chart.php";
	##else##
		$defaulturl="##@BUILDER.Tables.strShortTableName##_add.php";
	##endif##
##endif##

$smarty->assign("url",$defaulturl);


$templatefile = "admin_members_list.htm";

$smarty->display($templatefile);

function sortfunc(&$a,&$b)
{
	global $sortgroup,$sortorder;
	$gcount=count($a["groups"]);
	for($i=0;$i<$gcount;$i++)
		if($a["groups"][$i]["group"]==$sortgroup)
			break;
	if($i==$gcount || $a["groups"][$i]["checked"]==$b["groups"][$i]["checked"])
	{
//	compare by username
		if($a["user"]==$b["user"])
			return 0;
		if($a["user"]>$b["user"])
			return 1;
		return -1;
	}
	if($sortorder=="a" && $a["groups"][$i]["checked"]=="")
		return 1;
	if($sortorder=="d" && $b["groups"][$i]["checked"]=="")
		return 1;
	return -1;
}