<?php

function list#records#(){
	global $db; 
	$mode=GETSTR('mode');
	$key=GETSTR('key');
	
	$page=isset($_GET['page'])?$_GET['page']+0:0;
	
	if ($mode!='embed'){

?>
<div class="section">
<div class="listbar">
	<form class="listsearch" onsubmit="_inline_lookup#record#(gid('#record#key'));return false;">
	<div class="listsearch_">
		<input id="#record#key" class="img-mg" onkeyup="_inline_lookup#record#(this);">
	</div>
	<input type="image" src="imgs/mg.gif" class="searchsubmit" value=".">
	</form>

	<div style="padding-top:10px;">
	<a class="recadder" onclick="addtab('#record#_new','<?tr('list_#record#_add_tab');?>','new#record#');"> <img src="imgs/t.gif" class="img-addrec" width="18" height="18"><?tr('list_#record#_add');?></a>
	</div>
</div>

<div id="#record#list">
<?		
	}

	$query="select * from #tablename# ";
	
	$soundex=GETSTR('soundex')+0;
	$sxsearch='';
	if ($soundex&&$key!='') $sxsearch=" or concat(soundex(#dispfield#),'') like concat(soundex('$key'),'%') ";
	
	if ($key!='') $query.=" where (#searchquery# $sxsearch) ";
	$rs=sql_query($query,$db);
	$count=sql_affected_rows($db,$rs);
	
	$perpage=20;
	$maxpage=ceil($count/$perpage)-1;
	if ($maxpage<0) $maxpage=0;
	if ($page<0) $page=0;
	if ($page>$maxpage) $page=$maxpage;
	$start=$perpage*$page;

	if ($maxpage>0){
?>
<div style="font-size:12px;padding:10px 0;">
<?echo $page+1;?> of <?echo $maxpage+1;?>
&nbsp;
<a href=# onclick="ajxpgn('#record#list',document.appsettings.codepage+'?cmd=slv_#fviewindex#&key='+encodeHTML(gid('#record#key').value)+'&page=<?echo $page-1;?>&mode=embed');return false;">&laquo; Prev</a>
|
<a href=# onclick="ajxpgn('#record#list',document.appsettings.codepage+'?cmd=slv_#fviewindex#&key='+encodeHTML(gid('#record#key').value)+'&page=<?echo $page+1;?>&mode=embed');return false;">Next &raquo;</a>
</div>
<?		
	}
	
	$query.=" order by #sortquery# limit $start,$perpage";	
	
	$rs=sql_query($query,$db);
	
	while ($myrow=sql_fetch_array($rs)){
		$#primarykey#=$myrow['#primarykey#'];
		$#dispfield#=$myrow['#dispfield#'];
		
		$#record#title="$#dispfield#"; //change this if needed
		
		$db#record#title=noapos(htmlspecialchars($#record#title));
?>
<div class="listitem"><a onclick="show#record#(<?echo $#primarykey#;?>,'<?echo $db#record#title;?>');"><?echo $#record#title;?></a></div>
<?		
	}//while
	
	if ($mode!='embed'){
?>
</div>
</div>

<script>
gid('tooltitle').innerHTML='<a><?tr('icon_#records#');?></a>';
ajxjs(self.show#record#,'#records#.js');
</script>
<?	
	}//embed mode

}
