#!perl use LSE::Database::Connection; use LSE::Config; use CGI; use strict; use warnings; my $q = new CGI; print $q->header; my $dbh = getConnection(); #Check to make sure the 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 ; } # Deactivate - delete input types if($q->param('action') and $q->param('action') eq 'Deactivate') { my $s_atype = $dbh->quote($q->param('atype')); my $sinput = $q->param('sinput_table'); my $dinput = $q->param('dinput_table'); # This shouldn't happen unless they're mucking with CGI by hand if($s_atype eq 'null' or !$sinput or !$dinput) { print "

Invalid form parameters

\n"; exit; } else { $dbh->do("delete from $sinput where type = $s_atype"); $dbh->do("delete from $dinput where type = $s_atype"); } } # Activate - insert new type and its input if($q->param('action') and $q->param('action') eq 'Activate') { my $aclass = $q->param('aclass'); my $sinput = ''; my $dinput = ''; my $types = ''; if($aclass = 'sentence') { $sinput = 'annotation_input'; $dinput = 'sentence_annotation_document_input'; $types = 'annotation_types'; } elsif ($aclass = 'doc') { $sinput = 'document_annotation_input'; $dinput = 'document_annotation_sentence_input'; $types = 'document_annotation_types'; } else { print "

Invalid form parameters

\n"; exit; } my $s_atype = $dbh->quote($q->param('atype')); $dbh->begin_work; if($q->param('addnew')) { my $s_desc = $dbh->quote($q->param('desc')); $dbh->do("INSERT INTO $types (type, description) VALUES ($s_atype, $s_desc)"); } foreach my $input ($q->param('sentence_input')) { my $s_input = $dbh->quote($input); $dbh->do("INSERT INTO $sinput (type, input) VALUES ($s_atype, $s_input)"); } foreach my $input ($q->param('document_input')) { my $s_input = $dbh->quote($input); $dbh->do("INSERT INTO $dinput (type, input) VALUES ($s_atype, $s_input)"); } $dbh->commit; } our (%config, $s_types, $d_types); my $config = getAnnotConfig(); local %config = %{$config}; # These aren't real annotation types, so don't complain that they aren't # configured in the database delete $config{general}; delete $config{collection}; delete $config{database}; delete $config{job_priority}; $s_types = $dbh->selectall_arrayref("select type from annotation_types order by type"); $d_types = $dbh->selectall_arrayref("select type from document_annotation_types order by type"); # Display sentence annotation types print "

Sentence Annotation Types

\n"; dumpAnnotationTypes("annotation_types","annotation_input","sentence_annotation_document_input"); # Display document annotation types print "

Document Annotation Types

\n"; dumpAnnotationTypes("document_annotation_types","document_annotation_sentence_input","document_annotation_input"); # Display annotation types mentioned in config file but not in database print "

New Annotation Types

\n"; foreach my $atype (keys(%config)) { print "

$atype

\n"; delete $config{$atype}; print qq(
); print qq(Description:
); print qq(); print qq(); print qq(Choose annotation class:); print qq(Document); print qq(Sentence); print qq(

); print qq(

Select sentence inputs:

); print qq(); print qq(
); print qq(

Select document inputs:

); print qq(); print qq(
); print qq(

); print qq(
\n); } sub dumpAnnotationTypes { our %config, $s_types, $d_types; # Tables listing annotation types, sentence input, document input my ($types,$sinput,$dinput) = @_; my $dbh = getConnection(); my $sth = $dbh->prepare("select * from $types order by type"); $sth->execute(); while(my $row = $sth->fetchrow_hashref) { my $atype = $row->{type}; print qq(

$atype

\n); print "

$row->{description}

\n"; print qq(
); print qq(); print qq(); print qq(); print qq(); my $sentence_input = $dbh->selectall_arrayref("select input from $sinput where type = '$atype'"); my $doc_input = $dbh->selectall_arrayref("select input from $dinput where type = '$atype'"); # Show the sentence input types for this annotation print "

Sentence Input: "; if(@$sentence_input) { print "

\n"; } else { print "None\n"; # If there's no document inputs either and the annotation type is # configured in the config file, allow selection of input types if(!@$doc_input and $config{$atype}) { print qq(

Select sentence inputs:

); print qq(); } } # Show the document annotation types for this annotation print "

Document Input: "; if(@$doc_input) { print "

\n"; } else { print "None\n"; # If there's no sentence input either and the annotation type is # configured in the config file, allow selection of input types if(!@$sentence_input and $config{$atype}) { print qq(

Select document inputs:

); print qq(); } } print "

Configuration Settings: "; if($config{$atype}) { print "

\n"; } else { print qq(not configured\n); } if(@$sentence_input or @$doc_input) { print qq(); delete $config{$atype}; } elsif($config{$atype}) { print qq(

); delete $config{$atype}; } print qq(
); } }