#function generate_record dbase_id table_id
#query select DatabaseName, ApplicationName from `database` where DatabaseID=?dbase_id?
#query select Subject, TableName, Title, Header, Link, Checks, Session, IDfield, ScreenWidth, ScreenHeight, ListOrderByField, ListOrderByAscDec from `tables` where TableID=?table_id?
#print '<?php\n'
#print '$sql->QueryItem(\"SELECT '
#set first=true
#record select fieldID, `Record`, FieldName, `Type`, DisplayName, DisplayLength, SessionVar, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and SessionVar='' and FieldName<>'' order by `order`
#if not first
#print ', '
#end
#if LookupDisplayField=''
#print TableName ^ '.' ^ FieldName ^ ' as F' ^ fieldID
#else
#if LookupTable=''
#print queryvars TableName LookupDisplayField fieldID 1
#else
#print queryvars ('T' ^ fieldID) LookupDisplayField fieldID 1
#end
#end
#set first=false
#end
#print ' FROM `' ^ TableName ^ '`\n'
#record select fieldID, `Add`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and LookupTable<>'' and LookupDisplayField<>'' and Record<>'none' order by `order`
#print 'LEFT JOIN `' ^ LookupTable ^ '` AS T' ^ fieldID ^ ' ON ' ^ TableName ^ '.' ^ FieldName ^ '=T' ^ fieldID ^ '.' ^ LookupIDField ^ '\n'
#end
#query select FieldName as IDfieldName, SessionVar from `fields` where SessionVar<>'' and TableID=?table_id? and FieldName=?IDfield? rows nrrec
#if nrrec>0
#print 'WHERE ' ^ IDfieldName ^ ' = \'$' ^ SessionVar ^ '\'\n'
#end
#print 'ORDER BY `' ^ ListOrderByField ^ '` ' ^ ListOrderByAscDec
#print ' LIMIT 1\");\n'
#set expr=''
#set sesvars=''
#set IDintern=''
#record select fieldID, `Record`, Name, FieldName, `Type`, DisplayName, DisplayLength, SessionVar, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? order by `order`
#if FieldName=IDfield
#set IDintern=Name
#end
#if SessionVar<>''
#set sesvars=sesvars ^ '&' ^ SessionVar ^ '=$' ^ SessionVar
#else
#if LookupDisplayField=''
#if Type='date'
#print 'preg_match (\'/^(\d+)-0?(\d+)-0?(\d+)$/\', $sql->data[\'F' ^ fieldID ^ '\'], $matches);\n'
#print '$' ^ Name ^ ' = \"$matches[3]/$matches[2]/$matches[1]\";\n'
#else
#print '$' ^ Name ^ ' = $sql->data[\'F' ^ fieldID ^ '\'];\n'
#end
#else
#set getvars=''
#set expr=fieldreplace LookupDisplayField fieldID
#print getvars
#print '$' ^ Name ^ ' = \"' ^ expr ^'\";\n'
#end
#end
#end
#set first=true
#set list=new_thing 'temp' 'root' ('system'['root']) ''
#set fnr=1
#set lnr=1
#set rnr=1
#record select FieldID, `Record` from `fields` where TableID=?table_id? and `Record`<>'none' order by `order`
#if Record='front'
#set elm=new_thing 'temp' ('00F'^string_of_int fnr) list FieldID
#set fnr=fnr+1
#end
#if Record='left' or Record=''
#set elm=new_thing 'temp' (string_of_dec 2 lnr^'L') list FieldID
#set lnr=lnr+1
#end
#if Record='right'
#set elm=new_thing 'temp' (string_of_dec 2 rnr^'R') list FieldID
#set rnr=rnr+1
#end
#end
#set last=''
<relas thing="list" type="'temp'" rela="elm" sort="name">
#query select `Record`, `Name`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and FieldID=?elm.descr?
#if Record='front'
#if last=''
#print 'echo (\'<table class=record>\');\n'
#end
#print 'echo (\"<tr>'
#print '<td colspan=4>$' ^ Name ^ '</td>\n'
#print '</tr>\");\n'
#set last='front'
#end
#if Record='left' or Record=''
#if last=''
#print 'echo (\'<table class=record>\');\n'
#end
#if last='front'
#print 'echo (\'</table><table class=record>\');\n'
#end
#if last='left'
#print 'echo (\"</tr>\");\n'
#end
#print 'echo (\"<tr>'
#print '<th>' ^ DisplayName ^ '</th>\n'
#print '<td>$' ^ Name ^ '</td>\");\n'
#set last='left'
#end
#if Record='right'
#if last<>'left'
#print 'echo (\"<tr><td></td><td></td>\");\n'
#end
#print 'echo (\"<th>' ^ DisplayName ^ '</th>\n'
#print '<td>$' ^ Name ^ '</td>\n'
#print '</tr>\");\n'
#set last='rigth'
#end
#set first=false
</relas>
#do remove 'temp'['root']
#do execute
#if last='left'
#print 'echo (\"</tr>\");\n'
#end
#print 'echo (\'</table>\');\n'
#print '?>\n'
#if not first
#if IDintern=''
#print '<p><input type=button value=\"Edit ' ^ Title ^ '\" onClick=\"javascript: window.open(\'edit' ^ Subject ^ '.php\',\'\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\'); return false;\">\n'
#else
#print '<p><input type=button value=\"Edit ' ^ Title ^ '\" onClick=\"javascript: window.open(\'edit' ^ Subject ^ '.php?' ^ IDintern ^'=<?php echo $' ^ IDintern ^ '; ?>\',\'\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\'); return false;\">\n'
#end
#end
#end
#function rights_record dbase_id table_id
#query select DatabaseName, ApplicationName from `database` where DatabaseID=?dbase_id?
#query select Subject, TableName, Title, Header, Link, Checks, Session, IDfield, ScreenWidth, ScreenHeight, ListOrderByField, ListOrderByAscDec from `tables` where TableID=?table_id?
#set first=true
#set list=new_thing 'temp' 'root' ('system'['root']) ''
#set fnr=1
#set lnr=1
#set rnr=1
#record select FieldID, `Record` from `fields` where TableID=?table_id? and `Record`<>'none' order by `order`
#if Record='front'
#set elm=new_thing 'temp' ('00F'^string_of_int fnr) list FieldID
#set fnr=fnr+1
#end
#if Record='left' or Record=''
#set elm=new_thing 'temp' (string_of_dec 2 lnr^'L') list FieldID
#set lnr=lnr+1
#end
#if Record='right'
#set elm=new_thing 'temp' (string_of_dec 2 rnr^'R') list FieldID
#set rnr=rnr+1
#end
#end
#set last=''
<relas thing="list" type="'temp'" rela="elm" sort="name">
#query select `fieldID`, `Record`, `Name`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and FieldID=?elm.descr?
#if Record='front'
#if last=''
#print '<table class=record>\n'
#end
#print '<tr>'
#print '<td>' ^ Name ^ ' '
#print field_rights_link fieldID 'hide'
#print '</td>\n'
#print '</tr>\n'
#set last='front'
#end
#if Record='left' or Record=''
#if last=''
#print '<table class=record>'
#end
#if last='front'
#print '</table><table class=record>'
#end
#if last='left'
#print '</tr>\n'
#end
#print '<tr>'
#print '<th>' ^ DisplayName ^ '</th>\n'
#print '<td>'
#print field_rights_link fieldID 'hide'
#print '</td>\n'
#set last='left'
#end
#if Record='right'
#if last<>'left'
#print '<tr><td></td><td></td>\n'
#end
#print '<th>' ^ DisplayName ^ '</th>\n'
#print '<td>'
#print field_rights_link fieldID 'hide'
#print '</td>\n'
#print '</tr>\n'
#set last='rigth'
#end
#set first=false
</relas>
#do remove 'temp'['root']
#do execute
#if last='left'
#print '</tr>\n'
#end
#if last<>''
#print '</table>\n'
#end
#if not first
#print '<p><input type=button value=\"Edit ' ^ Title ^ '\" onClick=\"javascript: window.open(\'edit' ^ Subject ^ '.php\',\'\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\'); return false;\">\n'
#end
#end