#function generate_list dbase_id table_id link part
#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 orderfield='0'
#query select `FieldID` as orderfield, `FieldName` as ordername from `fields` where `TableID`=?table_id? and `Type`='ordering'
#print '<?php\n'
#print '$lastorder=$_SESSION[last_'^table_id^'];\n'
#print '$lastfilter'^table_id^'=$_SESSION[filter'^table_id^'];\n'
#print '$_SESSION[last_'^table_id^']=\'\';\n'
#print 'if ($_GET[filter' ^table_id^']) { $filter' ^table_id^' =$_GET[filter'^table_id^']; } else { $filter'^table_id^'=$_POST[filter'^table_id^'];}\n'
#print 'if ($_GET[page'^table_id^']) { $page=$_GET[page'^table_id^']; } else { $page=$_POST[page'^table_id^']; }\n'
#print 'if ($filter'^table_id^'!=$lastfilter'^table_id^') {\n'
#print ' $_SESSION[filter'^table_id^']=$filter'^table_id^';\n'
#print ' $page=0;\n'
#print '}\n'
#print 'if ($filter'^table_id^'!=\'\')\n'
#print '{\n'
#print '$qfilter'^table_id^' = quote(\'%\'.$filter'^table_id^'.\'%\');\n'
#set tests=''
#record select FieldName, SessionVar from `fields` where TableID=?table_id? and SessionVar<>'' and FieldName<>?IDfield? and FieldName<>'' AND LookupTable='' order by `order`
#set tests=tests ^ ' AND `' ^ TableName ^ '`.`' ^ FieldName ^ '`=\'$' ^ SessionVar ^ '\''
#end
#if Checks <> ''
#set tests=tests ^ ' AND ' ^ Checks
#end
#print '$query = (\"\n'
#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 List='true' and LookupTable<>'' and LookupDisplayField<>'' order by `order`
#print 'LEFT JOIN `' ^ LookupTable ^ '` AS T' ^ fieldID ^ ' ON ' ^ TableName ^ '.' ^ FieldName ^ '=T' ^ fieldID ^ '.' ^ LookupIDField ^ '\n'
#end
#set first=true
#record select fieldID, `Add`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and (`Type`='varchar' or `Type`='int') and List='true' order by `order`
#if LookupTable='' or LookupDisplayField=''
#if first
#set first=false
#print 'WHERE (' ^ (if LookupTable='' then TableName else 'T' ^ fieldID) ^ '.`' ^ FieldName ^ '` LIKE $qfilter'^table_id^'\n'
#else
#print 'OR ' ^ (if LookupTable='' then TableName else 'T' ^ fieldID) ^ '.`' ^ FieldName ^ '` LIKE $qfilter'^table_id^'\n'
#end
#else
#if first
#set first=false
#print 'WHERE (' ^ multiply ('T' ^ fieldID) LookupDisplayField (' LIKE $qfilter'^table_id^'\n')
#else
#print 'OR ' ^ multiply ('T' ^ fieldID) LookupDisplayField (' LIKE $qfilter'^table_id^'\n')
#end
#end
#end
#print ')' ^ tests ^ ' \n'
#print ' \");\n'
#print '}\n'
#print 'else\n'
#print '{\n'
#print '$query = (\" \n'
#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 List='true' and LookupTable<>'' and LookupDisplayField<>'' order by `order`
#print 'LEFT JOIN `' ^ LookupTable ^ '` AS T' ^ fieldID ^ ' ON ' ^ TableName ^ '.' ^ FieldName ^ '=T' ^ fieldID ^ '.' ^ LookupIDField ^ '\n'
#end
#print 'WHERE 1' ^ tests ^ '\n'
#print '\");\n'
#print '}\n'
#print '$lastrec=-1;\n'
#print '$sql->QueryItem(\"SELECT COUNT(*) AS records$query\");\n'
#print '$records=$sql->data[records];\n'
#print 'if ($lastorder==\'\') {$fromrec=20*$page;} else {\n'
#print '$sql->QueryItem(\"SELECT COUNT(*) AS fromrec$query AND `' ^ TableName ^ '`.`' ^ ListOrderByField ^ '` < $lastorder\");\n'
#print '$fromrec=$sql->data[fromrec]-10;\n'
#print 'if($fromrec<0) {$fromrec=0; }\n'
#print '$lastrec=$sql->data[fromrec]-$fromrec;\n'
#print '}\n'
#print '$sql->Query(\"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 (List='true' or (SessionVar<>'' and LookupTable='')) and FieldName<>'' order by `order`
#if not first
#print ', '
#end
#if LookupDisplayField=''
#print TableName ^ '.' ^ FieldName ^ ' as F' ^ fieldID
#else
#if SessionVar<>''
#print TableName ^ '.' ^ FieldName ^ ' as F' ^ fieldID ^ ', '
#end
#print queryvars ('T' ^ fieldID) LookupDisplayField fieldID 1
#end
#set first=false
#end
#print '$query\n'
#print 'ORDER BY `' ^ TableName ^ '`.`' ^ ListOrderByField ^ '` ' ^ ListOrderByAscDec ^ '\n'
#print 'LIMIT $fromrec, 20\");\n'
#print 'if (' ^ check_off part 'nofilter' ^ ') {\n'
#print 'echo \"<form action=\\\"\\\" method=get name=Filter>\";\n'
#print 'echo \"<p class=filter>\";\n'
#print 'echo \"Records: $records \";\n'
#print '$maxpage=(int) (($records+19)/20);\n'
#print 'if ($maxpage>1) {\n'
#print ' echo \"Page: \";\n'
#print ' echo \"<select name=\\\"page'^table_id^'\\\" OnChange=\\\"Filter.target=\'\'; Filter.action = \'\'; Filter.submit();\\\">\\n\";\n'
#print ' for ($i = 0; $i < $maxpage; $i++)\n'
#print ' {\n'
#print ' $nr=$i+1;\n'
#print ' if ($i==$page) {$sel=\" selected\";} else {$sel=\"\";}\n'
#print ' echo \"<option value=$i$sel>$nr van $maxpage</option>\\n\";\n'
#print ' }\n'
#print ' echo \"</select>\\n\";\n'
#print '}\n'
#print 'echo \"<input type=text name=\\\"filter'^table_id^'\\\" size=25 value=\\\"$filter'^table_id^'\\\">\";\n'
#print 'echo \"<input type=submit value=\\\"Search\\\">\";\n'
#set sesvars=''
#record select fieldID, `List`, FieldName, `Type`, DisplayName, DisplayLength, SessionVar, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and FieldName<>'' order by `order`
#if SessionVar<>''
#if sesvars<>''
#set sesvars=sesvars ^ '&'
#end
#set sesvars=sesvars ^ SessionVar ^ '=$' ^ SessionVar
#end
#end
#query select count(*) as fields from `fields` where TableID=?table_id? and Record <>'none' and `Add`='true' and DisplayName<>''
#if fields>'0'
#print 'echo \"<input type=button value=\\\"Add ' ^ Title ^ '\\\" onClick=\\\"javascript: window.open(\'add' ^ Subject ^ '.php?' ^ sesvars ^ '\',\'\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\'); return false;\\\">\";\n'
#end
#print 'echo \"</p>\";\n'
#print 'echo \"</form>\";\n'
#print '}\n'
#print '?>\n'
#print '<table class=list>\n'
#print '<tr>\n'
#if orderfield<>'0'
#print '<th></th>\n'
#end
#record select `List`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth*7 as ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and List='true' order by `order`
#print '<th width=' ^ ListWidth ^ 'px>' ^ DisplayName ^ '</th>\n'
#end
#print '</tr>\n'
#print '<?php\n'
#print 'for ($i = 0; $i < $sql->rows; $i++)\n'
#print '{\n'
#print ' $sql->Fetch($i);\n'
#set expr=''
#record select fieldID, `List`, Name as InternName, FieldName, `Type`, DisplayName, DisplayLength, SessionVar, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and FieldName<>'' order by `order`
#if SessionVar<>''
#if FieldName=IDfield
#print ' $' ^ IDfield ^ ' = $sql->data[\'F' ^ fieldID ^ '\'];\n'
#end
#end
#if List='true'
#if LookupDisplayField='' or Type='enum'
#if Type='date'
#print ' preg_match (\'/^(\d+)-0?(\d+)-0?(\d+)$/\', $sql->data[\'F' ^ fieldID ^ '\'], $matches);\n'
#print ' $' ^ InternName ^ ' = htmlspecialchars(\"$matches[3]/$matches[2]/$matches[1]\");\n'
#else
#print ' $' ^ InternName ^ ' = htmlspecialchars($sql->data[\'F' ^ fieldID ^ '\']);\n'
#end
#else
#if SessionVar<>''
#print ' $' ^ InternName ^ ' = htmlspecialchars($sql->data[\'F' ^ fieldID ^ '\']);\n'
#end
#set getvars=''
#set expr=fieldreplace LookupDisplayField fieldID
#print getvars
#print ' $' ^ InternName ^ '_lup = \"' ^ expr ^ '\";\n'
#end
#end
#end
#print ' if ($lastrec==$i) {$color=\"style=\\\"background-color: #aaaaff;\\\"\";} else {$color=\"\";}\n'
#print ' echo (\"\n'
#if link=''
#print '<tr $color onMouseOver=\\"ChangeColor(this)\\" onMouseOut=\\"ChangeColorBack(this)\\" onClick=\\"window.open(\'edit' ^ Subject ^ '.php?' ^ sesvars ^ '\',\'wijzigen\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\')\\">\n'
#else
#print '<tr $color onMouseOver=\\"ChangeColor(this)\\" onMouseOut=\\"ChangeColorBack(this)\\" onClick=\\"location=\'' ^ link ^ '?' ^ sesvars ^ '\'\\">\n'
#end
#if orderfield<>'0'
#print '<td onClick=\\"window.open(\'add' ^ Subject ^ '.php?' ^ ordername ^ '=$' ^ ordername ^ '\',\'add\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\'); no_bubble(event);\\"><b>Add</b></td>\n'
#end
#record select `List`, FieldName, Name as InternName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and List='true' order by `order`
#print '<td>$' ^ InternName ^ (if LookupDisplayField<>'' then '_lup' else '') ^ '</td>\n'
#end
#print '</tr>\");\n'
#print '}\n'
#print '?>\n'
#print '</table>\n'
#end
#function rights_list dbase_id table_id link part
#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 '<p class=filter>\n'
#print 'Records: #\n'
#print 'Pagina: #\n'
#print part_rights_link part 'listall'
#print part_rights_link part 'nofilter'
#print '</p>\n'
#print '<table class=list>\n'
#print '<tr>\n'
#record select `List`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth*7 as ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and List='true' order by `order`
#print '<th width=' ^ ListWidth ^ 'px>' ^ DisplayName ^ '</th>\n'
#end
#print '</tr>\n'
#print '<tr>\n'
#record select fieldID, `List`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth*7 as ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and List='true' order by `order`
#print '<td>'
#print field_rights_link fieldID 'hide'
#print '</td>\n'
#end
#print '</tr>\n'
#if link=''
#print '<tr onMouseOver=\"ChangeColor(this)\" onMouseOut=\"ChangeColorBack(this)\" onClick=\"window.open(\'rightsedit' ^ Subject ^ '.php\',\'wijzigen\',\'width=' ^ ScreenWidth ^ ',height=' ^ ScreenHeight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\')\">\n'
#else
#print '<tr onMouseOver=\"ChangeColor(this)\" onMouseOut=\"ChangeColorBack(this)\" onClick=\"location=\'rights_' ^ link ^'\'\">\n'
#end
#record select fieldID, `List`, FieldName, `Type`, DisplayName, DisplayLength, Help, areaheight, areawidth, ListWidth*7 as ListWidth, LookupTable, OrderByField, LookupIDField, LookupDisplayField from `fields` where TableID=?table_id? and List='true' order by `order`
#print '<td>data</td>\n'
#end
#print '<tr><td>'
#print part_rights_link part 'hide'
#print '</td>'
#print '<td>'
#print part_rights_link part 'noedit'
#print '</td>'
#print '<td>'
#print part_rights_link part 'noadd'
#print '</td>'
#print '</tr>'
#print '</table>\n'
#end