#function generate_list project table_id link part
#query select name as application from `project` where project=?project?
#query select name as tablename, `sql` as tablesql, title as tabletitle, `where`, id_field, width as tablewidth, height as tableheight from `table` where `table`=?table_id?
#set orderfield='0'
#query select `field` as orderfield, `name` as ordername from `field` where `table`=?table_id? and `Type`='ordering'
#print '<?php\n'
#print 'if ($_GET[order'^table_id^']<>\'\') {\n'
#print ' $sql->QueryItem(\"DELETE FROM user_selection WHERE user=$user_ID and field=\'sort_' ^table_id^ '\'\");\n'
#print ' $sql->QueryItem(\"INSERT INTO user_selection VALUES (\'$user_ID\', \'sort_' ^table_id^ '\',\'$_GET[order'^table_id^']\'\");\n'
#print '}\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 ($_GET[full_'^table_id^']==\'Fullpage\') {\n'
#print ' $_SESSION[fullpage_' ^ table_id ^ ']=\'f\';\n'
#print '}\n'
#print 'if ($_GET[full_'^table_id^']==\'Pages\') {\n'
#print ' $_SESSION[fullpage_' ^ table_id ^ ']=\'\';\n'
#print '}\n'
#print 'if ($filter'^table_id^'!=\'\')\n'
#print '{\n'
#print '$qfilter'^table_id^' = quote(\'%\'.$filter'^table_id^'.\'%\');\n'
#set tests=''
#record select field.sql as fieldsql, SessionVar from `field` where `table`=?table_id? and SessionVar<>'' and field.name<>?id_field? and field.name<>'' AND link_table='' order by `order`
#set tests=tests ^ ' AND `' ^ tablesql ^ '`.`' ^ fieldsql ^ '`=\'$' ^ SessionVar ^ '\''
#end
#if where <> ''
#set tests=tests ^ ' AND ' ^ where
#end
#print '$query = (\"\n'
#print 'FROM `' ^ tablesql ^ '`\n'
#record select field, `Add`, field.sql as fieldsql, `Type`, title, width, height, link_table, link_field, link_display from `field` where `table`=?table_id? and List='true' and link_table<>'' and link_display<>'' order by `order`
#print 'LEFT JOIN `' ^ link_table ^ '` AS T' ^ field ^ ' ON ' ^ tablesql ^ '.' ^ fieldsql ^ '=T' ^ field ^ '.' ^ link_field ^ '\n'
#end
#set first=true
#record select field, `Add`, field.sql as fieldsql, `Type`, title, width, height, link_table, link_field, link_display from `field` where `table`=?table_id? and (`Type`='varchar' or `Type`='int') and List='true' order by `order`
#if link_table='' or link_display=''
#if first
#set first=false
#print 'WHERE (' ^ (if link_table='' then tablesql else 'T' ^ field) ^ '.`' ^ fieldsql ^ '` LIKE $qfilter'^table_id^'\n'
#else
#print 'OR ' ^ (if link_table='' then tablesql else 'T' ^ field) ^ '.`' ^ fieldsql ^ '` LIKE $qfilter'^table_id^'\n'
#end
#else
#if first
#set first=false
#print 'WHERE (' ^ multiply ('T' ^ field) link_display (' LIKE $qfilter'^table_id^'\n')
#else
#print 'OR ' ^ multiply ('T' ^ field) link_display (' 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 `' ^ tablesql ^ '`\n'
#record select field, `Add`, field.sql as fieldsql, `Type`, title, width, height, link_table, link_field, link_display from `field` where `table`=?table_id? and List='true' and link_table<>'' and link_display<>'' order by `order`
#print 'LEFT JOIN `' ^ link_table ^ '` AS T' ^ field ^ ' ON ' ^ tablesql ^ '.' ^ fieldsql ^ '=T' ^ field ^ '.' ^ link_field ^ '\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 '$sortorder=$sql->QueryItem(\"SELECT value FROM user_selection WHERE user=$user_ID and field=\'sort_' ^table_id^ '\'\");\n'
#print 'if ($lastorder==\'\') {$fromrec=20*$page;} else {\n'
#set first=true
#record select table_order, name from table_order where `table`=?table_id? order by `order`
#if first
#print 'if ($sortorder==\'\' || $sortorder==\'' ^ table_order ^ '\') {\n'
#set first=false
#else
#print 'if ($sortorder==\'' ^ table_order ^ '\') {\n'
#end
#print ' $sql->QueryItem(\"SELECT COUNT(*) AS fromrec$query AND CONCAT('
#set first2=true
#record select table.sql as tsql, field.sql as fsql from table_ofield inner join `field` on field.field=table_ofield.field inner join `table` on field.table=table.table where table_order=?table_order? order by table_ofield.order
#if first2
#set first2=false
#else
#print ',\'/\','
#end
#print tsql ^ '.' ^ fsql
#end
#print ') < $lastorder\");\n'
#print '}\n'
#end
#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 field, `Record`, field.sql as fieldsql, `Type`, title, width, SessionVar, height, link_table, link_field, link_display from `field` where `table`=?table_id? and (List='true' or (SessionVar<>'' and link_table='')) and field.sql<>'' order by `order`
#if not first
#print ', '
#end
#if link_display=''
#print tablesql ^ '.' ^ fieldsql ^ ' as F' ^ field
#else
#if SessionVar<>''
#print tablesql ^ '.' ^ fieldsql ^ ' as F' ^ field ^ ', '
#end
#print queryvars ('T' ^ field) link_display field 1
#end
#set first=false
#end
#print '$query\".\n'
#set first=true
#record select table_order, name from table_order where `table`=?table_id? order by `order`
#if first
#print ' (($sortorder==\'\' || $sortorder==\'' ^ table_order ^ '\')?\"'
#set first=false
#else
#print '\":\'\').\n'
#print ' (($sortorder==\'' ^ table_order ^ '\')?\"'
#end
#set first2=true
#record select field as ofield from table_ofield where table_order=?table_order? order by table_ofield.order
#if first2
#set first2=false
#print ' ORDER BY '
#else
#print ','
#end
#print ofield
#end
#end
#if not first
#print ' \":\'\').'
#end
#print '($_SESSION[fullpage_'^table_id^']==\'\'?\"LIMIT $fromrec, 20\":\'\'));\n'
#print 'if (' ^ check_off part 'nofilter' ^ ') {\n'
#print 'echo \"<form action=\\\"\\\" method=get name=Filter'^table_id^'>\";\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 ' if ($_SESSION[fullpage_'^table_id^']==\'\') {\n'
#print ' echo \"Page: \";\n'
#print ' echo \"<select name=\\\"page'^table_id^'\\\" OnChange=\\\"Filter'^table_id^'.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 ' echo \"<input type=submit name=full_'^table_id^' value=\\\"Fullpage\\\">\";\n'
#print ' } else {\n'
#print ' echo \"<input type=submit name=full_'^table_id^' value=\\\"Pages\\\">\";\n'
#print ' }\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'
#query select count(*) as orderings from table_order where `table`=?table_id?
#if orderings>'1'
#print 'echo \"<select name=\\\"order' ^ table_id ^ '\\\" OnChange=\\\"Filer'^table_id^'.submit();\\\">\\n\";\n'
#record select table_order, name from table_order order by `order`
#print 'echo \"<option value=' ^ table_order ^'\".($sortorder==\'' ^ table_order ^'\'?\" selected\":\'\').\">' ^ name ^ '</option>\\n\";\n'
#end
#print 'echo \"</select>\\n\";\n'
#end
#set sesvars=''
#record select field, `List`, field.sql as fieldsql, `Type`, title, SessionVar, height, width, link_table, link_field, link_display from `field` where `table`=?table_id? and field.sql<>'' order by `order`
#if SessionVar<>''
#if sesvars<>''
#set sesvars=sesvars ^ '&'
#end
#set sesvars=sesvars ^ SessionVar ^ '=$' ^ fieldsql
#end
#end
#query select count(*) as fields from `field` where `table`=?table_id? and Record <>'none' and `Add`='true' and title<>''
#if fields>'0'
#print 'echo \"<input type=button value=\\\"Add ' ^ tabletitle ^ '\\\" onClick=\\\"javascript: window.open(\'add' ^ tablename ^ '.php?' ^ sesvars ^ '\',\'\',\'width=' ^ tablewidth ^ ',height=' ^ tableheight ^ ',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`, field.sql as fieldsql, `Type`, title, width * 7 as width, height, link_table, link_field, link_display from `field` where `table`=?table_id? and List='true' order by `order`
#print '<th width=' ^ width ^ 'px>' ^ title ^ '</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 field, `List`, name as internname, field.sql as fieldsql, `Type`, title, width, SessionVar, height, link_table, link_field, link_display from `field` where `table`=?table_id? and field.sql<>'' order by `order`
#if SessionVar<>''
#if fieldsql=id_field
#print ' $' ^ id_field ^ ' = $sql->data[\'F' ^ field ^ '\'];\n'
#end
#end
#if List='true'
#if link_display='' or Type='enum'
#if Type='date'
#print ' preg_match (\'/^(\d+)-0?(\d+)-0?(\d+)$/\', $sql->data[\'F' ^ field ^ '\'], $matches);\n'
#print ' $' ^ internname ^ ' = htmlspecialchars(\"$matches[3]/$matches[2]/$matches[1]\");\n'
#else
#print ' $' ^ internname ^ ' = htmlspecialchars($sql->data[\'F' ^ field ^ '\']);\n'
#end
#else
#if SessionVar<>''
#print ' $' ^ internname ^ ' = htmlspecialchars($sql->data[\'F' ^ field ^ '\']);\n'
#end
#set getvars=''
#set expr=fieldreplace link_display field
#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' ^ tablename ^ '.php?' ^ sesvars ^ '\',\'wijzigen\',\'width=' ^ tablewidth ^ ',height=' ^ tableheight ^ ',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' ^ tablename ^ '.php?' ^ ordername ^ '=$' ^ ordername ^ '\',\'add\',\'width=' ^ tablewidth ^ ',height=' ^ tableheight ^ ',location=no,menubar=no,scrollbars=yes,status=no,resizable=yes\'); no_bubble(event);\\"><b>Add</b></td>\n'
#end
#record select `List`, field.sql as fieldsql, name as internname, `Type`, title, width, height, link_table, link_field, link_display from `field` where field.`table`=?table_id? and List='true' order by `order`
#print '<td>$' ^ internname^ (if link_display<>'' then '_lup' else '') ^ '</td>\n'
#end
#print '</tr>\");\n'
#print '}\n'
#print '?>\n'
#print '</table>\n'
#end
#function rights_list project table_id link part
#query select name as application from `project` where project=?project?
#query select name as tablename, `sql` as tablesql, title as tabletitle, id_field, width as tablewidth, height as tableheight from `table` where `table`=?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`, field.sql as fieldsql, `Type`, title, width * 7 as width, height, link_table, link_field, link_display from `field` where field.`table`=?table_id? and List='true' order by `order`
#print '<th width=' ^ width ^ 'px>' ^ title ^ '</th>\n'
#end
#print '</tr>\n'
#print '<tr>\n'
#record select field, `List`, field.sql as fieldsql, `Type`, title, width, height, link_table, link_field, link_display from `field` where field.`table`=?table_id? and List='true' order by `order`
#print '<td>'
#print field_rights_link field 'hide'
#print '</td>\n'
#end
#print '</tr>\n'
#if link=''
#print '<tr onMouseOver=\"ChangeColor(this)\" onMouseOut=\"ChangeColorBack(this)\" onClick=\"window.open(\'rightsedit' ^ tablename ^ '.php\',\'wijzigen\',\'width=' ^ tablewidth ^ ',height=' ^ tableheight ^ ',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 field, `List`, field.sql as fieldsql, `Type`, title, width, height, link_table, link_field, link_display from `field` where field.`table`=?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