<?php

function list#primaryfield##records#($#primarykey#=null){
	if (!isset($#primarykey#)) $#primarykey#=GETVAL('#primarykey#');
	
	global $db;
	
	$query="select * from #bridgetable#,#lookuptable# 
		where #bridgetable#.#primarykey#=$#primarykey# and #bridgetable#.#lookupkey#=#lookuptable#.#lookupkey#
	 	order by #sortquery#";
	 	
	 $rs=sql_query($query,$db);
	 
	 ?>
	 <div class="stable">
	 <table class="subtable">
	 <tr>
	 	<td><b>#c_record#</b></td>
#iterator-fieldlist-tableheader#
	 </tr>
	 <?
	 
	 while ($myrow=sql_fetch_array($rs)){
	 	$#lookupkey#=$myrow['#lookupkey#'];
	 	$#bridgekey#=$myrow['#bridgekey#'];
#iterator-fieldlist-myrow#	 	
	 	$#dispfield#=$myrow['#dispfield#'];
	 	$title="$#dispfield#"; //change if necessary
	 	$dbtitle=htmlspecialchars(noapos(htmlspecialchars($title)));
	 ?>
	 <tr>
	 	<td valign="top">
	 		<a href=# onclick="ajxjs(self.show#record#,'#records#.js');show#record#(<?echo $#lookupkey#?>,'<?echo $dbtitle;?>');return false;">
	 		<u><?echo htmlspecialchars($title);?></u>
	 		</a>
	 	</td>
#iterator-fieldlist-tablerow#	 	
	 	<td valign="top">
	 		<a href=# onclick="del#primaryfield##record#(<?echo $#bridgekey#?>,<?echo $#primarykey#;?>,<?echo $#lookupkey#;?>,'<?emitgskey('del#primaryfield##record#_'.$#lookupkey#);?>');return false;">
	 		<img src="imgs/t.gif" class="img-del">
	 		</a>
	 	</td>
	 </tr>
	 <?	
	 }//while	
	 ?>
	 
	 <tr>
	 	<td valign="center">
			 <input class="inpshort" id="#primaryfield##records#_#lookupkey#_<?echo $#primarykey#;?>"  
				onfocus="lookupentity(this,'#record#','#c_records#');" onkeyup="_lookupentity(this,'#record#','#c_records#');">
				
			<span id="#primaryfield##records#_#lookupkey#_<?echo $#primarykey#;?>_val2"></span>
			<?makelookup('#primaryfield##records#_#lookupkey#_'.$#primarykey#);?>
	 	</td>
#iterator-fieldlist-tableinsert#	 	
	 	<td valign="center">
	 		<button onclick="ajxjs(self.add#primaryfield#,'#records#.js');add#primaryfield##record#(<?echo $#primarykey#;?>,'<?emitgskey('add#primaryfield##record#_'.$#primarykey#);?>');">Add #c_record#</button>
	 	</td>
	 </tr>
	 
	 </table>
	 </div>
	 <?
	
}