use LSE::Database::Connection ;
use CGI ;
use strict ;
use warnings ;
my $q = new CGI ;
print $q->header ;
my @table_cols = ('jobid', 'priority','annot_type','qid') ;
my $foreign_key = { jobid => 'link' } ;
my $table_name = 'jobs' ;
print "
\n" ;
print "\n";
print "LSE Annotators List\n";
print "";
foreach my $col (@table_cols) {
print "| $col | " ;
}
print "
\n";
my $dbh = getConnection() ;
eval
{
#Check to make sure th e current user has the right priveleges
my $current_user = $dbh->quote($ENV{REMOTE_USER}) ;
my $sth = $dbh->prepare("select * from users where userid = $current_user") ;
$sth->execute ;
my $current_user_info = $sth->fetchrow_hashref ;
#If not an administrator don't allow to view page
if ($current_user_info->{gid} ne 'admin')
{
print "Error: you aren't authorized to view this page" ;
exit ;
}
#Begin ordinary work for the list
my $cmd = "select * from $table_name " ;
if (defined $q->param('sort')) {
my $sortval = $q->param('sort');
$cmd = "$cmd order by $sortval" ;
#if the sort parameter is defined, then check to see
#if the reverse parameter is defined
if (defined $q->param('reverse') &&
$q->param('reverse') eq 'true' ) {
$cmd = "$cmd desc" ;
}
#include this print for degubing purposes
#print $cmd ;
}
my $sth = $dbh->prepare($cmd) ;
$sth->execute;
while ( my $row = $sth->fetchrow_hashref )
{
#create an empty anonymous hash
print "\n" ;
foreach my $col (@table_cols) {
#display information in table form.
if ( defined $row->{$col}) {
#start data element
print "\t| " ;
if ( defined $foreign_key->{col} ) {
print "\t{col}>" ;
print "$row->{col}" ;
print "" ;
}
else {
print "$row->{col}" ;
}
#end data element
print " | \n" ;
}
else {
print "\t | \n" ;
}
}
print "
\n" ;
} #end while
print "
" ;
} #end eval