summaryrefslogtreecommitdiff
path: root/httemplate/browse/generic.cgi
blob: 9ac0f2391dd989edb771ee24179c4ca6924f79f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<%

use FS::Record qw(qsearch dbdef);
use DBIx::DBSchema;
use DBIx::DBSchema::Table;

my $error;
my $p2 = popurl(2);
my ($table) = $cgi->keywords;
my $dbdef = dbdef or die "Cannot fetch dbdef!";
my $dbdef_table = $dbdef->table($table) or die "Cannot fetch schema for $table";

my $pkey = $dbdef_table->primary_key or die "Cannot fetch pkey for $table";
print header("Browse $table", menubar('Main Menu'   => $p));

my @rec = qsearch($table, {});
my @col = $dbdef_table->columns;

if ($cgi->param('error')) { %>
   <FONT SIZE="+1" COLOR="#ff0000">Error: <%=$cgi->param('error')%></FONT>
   <BR><BR>
<% } 
%>
<A HREF="<%=$p2%>edit/<%=$table%>.cgi"><I>Add a new <%=$table%></I></A><BR><BR>

<%=table()%>
<TH>
<% foreach (grep { $_ ne $pkey } @col) {
  %><TD><%=$_%></TD>
  <% } %>
</TH>
<% foreach $rec (sort {$a->getfield($pkey) cmp $b->getfield($pkey) } @rec) { 
  %>
  <TR>
    <TD>
      <A HREF="<%=$p2%>edit/<%=$table%>.cgi?<%=$rec->getfield($pkey)%>">
      <%=$rec->getfield($pkey)%></A> </TD> <%
  foreach $col (grep { $_ ne $pkey } @col)  { %>
    <TD><%=$rec->getfield($col)%></TD> <% } %>
  </A>
  </TR>
<% } %>
</TABLE>
</BODY>
</HTML>