#! /usr/bin/perl -w #use strict; use CGI::Ajax; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use DBI; $cgi = new CGI; my $Show_Form = sub { my $dBopts=["primates", "rodents", "ungulates", "carnivores"]; my @html =($cgi->header(-type=>"text/javascript" -src=>"binding.js"), $cgi->start_html(-title=>'GDET Intro Page'), $cgi->center($cgi->h3("GMPD Data Entry Tool Introduction")),$cgi->p, $cgi->h3("Please select a database"), $cgi->startform(-name=>'Select1', -method=>'POST'), "User Name :", $cgi->textfield(-name=>'user', -id=>"user"), "Password :", $cgi->password_field(-name=>'password', -id=>"password"), "Database :", $cgi->popup_menu(-id=>"Database", -name=>"Database", -value=>$dBopts, -width=>'1'), ##First AJAX trick here, this works $cgi->button(-name=>"SelectdB", -value=>"SelectdB", -onClick=>"connectdB( ['Database', 'user', 'password'], ['div3', 'extref', 'extloc', 'exthost', 'extpara']); return true;"),$cgi->p); $html=join("\n", @html); my @boxhtml=($cgi->h4("Connection status:"), $cgi->div({-id=>"div3"}), $cgi->end_div(-id=>"div3")); my $boxhtml=join("\n", @boxhtml); $html .= $boxhtml; my $loccellhtml=join("\n", ($cgi->div({-id=>'extloc', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'extloc'}))); my $refcellhtml=join("\n", ($cgi->div({-id=>'extref', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'extref'}))); my $hostcellhtml=join("\n", ($cgi->div({-id=>'exthost', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'extref'}))); my $paracellhtml=join("\n", ($cgi->div({-id=>'extpara', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'extref'}))); my @formhtml=($cgi->startform(-name=>'Select1', -method=>'POST'), $cgi->table({-border=>"2"}, $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$cgi->h4("Host Reported Name")]), $cgi->td([$cgi->center($cgi->submit(-name=>'NewHostTax', -value=>"New Host\n Taxonomy", -onClick=>"document.fork1.action='GDETNewLoc.cgi';"))], -colspan=>1), $cgi->td([$hostcellhtml], -colspan=>2, -align=>"center")), $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$cgi->h4("Parasite Reported Name")]), $cgi->td([$cgi->center($cgi->submit(-name=>'NewParaTax', -value=>"New Parasite\n Taxonomy", -onClick=>"document.fork1.action='GDETNewRef.cgi';"))], -colspan=>1), $cgi->td([$paracellhtml], -colspan=>2, -align=>"center")), $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$cgi->h4("Location Name")]), $cgi->td([$cgi->center($cgi->submit(-name=>'NewLocation', -value=>'New Location', -onClick=>"document.fork1.action='GDETNewLoc.cgi';"))], -colspan=>1), $cgi->td([$loccellhtml], -colspan=>2, -align=>"center")), $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$cgi->h4("Citation")]), $cgi->td([$cgi->center($cgi->submit(-name=>'NewReference', -value=>'New Reference', -onClick=>"document.fork1.action='GDETNewRef.cgi';"))], -colspan=>1), $cgi->td([$refcellhtml], -colspan=>2, -align=>"center"))), $cgi->submit(-name=>'GDETNewMAIN.cgi', -value=>"Enter MAIN\n record", -onClick=>"document.cookie = 'gotopage=GDETNewMAIN.cgi';document.Select1.action='storecookies.cgi'; return true;"), $cgi->endform); my $hostdatahtml=join("\n", ($cgi->div({-id=>'hostdata', -style=>'width: 350px; height: 100px;'}), $cgi->end_div({-id=>'hostdata'}))); my $paradatahtml=join("\n", ($cgi->div({-id=>'paradata', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'paradata'}))); my $locdatahtml=join("\n", ($cgi->div({-id=>'locdata', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'locdata'}))); my $refdatahtml=join("\n", ($cgi->div({-id=>'refdata', -style=>'width: 350px; height: 20px; overflow: auto'}), $cgi->end_div({-id=>'refdata'}))); my @displaytable=($cgi->table({-border=>"2"}, $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$hostdatahtml], -colspan=>2, -align=>"center")), $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$paradatahtml], -colspan=>2, -align=>"center")), $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$locdatahtml], -colspan=>2, -align=>"center")), $cgi->Tr({-align=>"LEFT",-valign=>"Center"}, $cgi->td([$refdatahtml], -colspan=>2, -align=>"center")))); my $metatable=$cgi->table({-border=>'0'}, $cgi->Tr({-align=>"LEFT",-valign=>"Top"}, $cgi->td([@formhtml]), $cgi->td([@displaytable]))); #my $formhtml=join("\n", @formhtml); #$html .= $formhtml; $html .= $metatable; my $extradiv=join("\n", ($cgi->div({-id=>'extra', -style=>'width: 350px; height: 100px; overflow: auto;'}), $cgi->end_div({-id=>'extra'}))); $html .= $extradiv; $html .= $cgi->end_html; return ($html); }; my $showhostdata=sub { $hostreptname=shift; #$hostreptname=$cgi->param("Hosts"); $dB=shift; $user=shift; $password=shift; $dBprefix="Ung" if($dB eq "ungulates"); $dBprefix="Sqrl" if($dB eq "rodents"); $dBprefix="Carn" if($dB eq "carnivores"); $dBprefix="Prim" if($dB eq "primates"); $tablename="$dBprefix" . "HostTax"; $connectstring=join(":", "DBI", "mysql", $dB, "128.192.18.43:3306"); %dBattr = ( PrintError => 0, RaiseError => 0 ); $dbh = DBI->connect($connectstring, $user, $password, \%dBattr) or die; my $qtdhostreptname=$dbh->quote($hostreptname); my $query="SELECT HostCorrectedName FROM $tablename WHERE HostReportedName=$qtdhostreptname"; $sth=$dbh->prepare($query); $sth->execute; $hostcortname=@{$sth->fetch}[0]; my $qtdhostcortname=$dbh->quote($hostcortname); my $query2="SELECT HostAuthority, TaxOrder, Family, Notes FROM $tablename WHERE HostReportedName=$qtdhostcortname AND HostCorrectedName=$qtdhostcortname"; $sth=$dbh->prepare($query2); $sth->execute; @hostcortdata=@{$sth->fetch}; @listdata=(("Corrected Name:" . "\t$hostcortname"), ("Host Authority: " . "\t$hostcortdata[0]"), ("Host Order:" . "\t$hostcortdata[1]"), ("Host Family:" . "\t$hostcortdata[2]"), ("Notes:" . "\t$hostcortdata[3]")); $dbh->disconnect; return($cgi->scrolling_list("showhostdata", \@listdata), $hostreptname); }; my $connectdB=sub { my $dB=shift; my $user=shift; my $password=shift; my %tables = ("References" => Citation, "Locations" => LocationName, "ParasiteTax" => ParasiteReportedName, "HostTax" => HostReportedName ); # my $dBprefix; $dBprefix="Ung" if($dB eq "ungulates"); $dBprefix="Sqrl" if($dB eq "rodents"); $dBprefix="Carn" if($dB eq "carnivores"); $dBprefix="Prim" if($dB eq "primates"); $connectstring=join(":", "DBI", "mysql", $dB, "128.192.18.43:3306"); %dBattr = ( PrintError => 0, RaiseError => 0 ); $dbh = DBI->connect($connectstring, $user, $password, \%dBattr) or die; foreach $table (keys %tables) { $tablename="$dBprefix" . "$table"; $searchstr=$tables{$table}; $query="SELECT DISTINCT $searchstr FROM $tablename"; #$html=$cgi->h5($query); $sth=$dbh->prepare($query) or $html=$cgi->h4($dbh->errstr()); $sth->execute() or $html=$cgi->h4($sth->errstr()); while(@row = $sth->fetchrow_array) { for $i (0..($sth->{NUM_OF_FIELDS}-1)) { push(@returnrows, $row[$i]); } } unshift(@returnrows, ""); $$table=[@returnrows]; undef @returnrows; } $html=$cgi->h6("connected to $dB as $user"); $extantrefs=$cgi->popup_menu(-name=>"References", -value=>$References, -width=>"200"); $extantlocs=$cgi->popup_menu(-name=>"Locations", -value=>$Locations, -width=>"200"); ##Second AJAX trick here, works in IE $extanthosts=$cgi->popup_menu(-name=>"Hosts", -value=>$HostTax, id=>"Hosts", -onChange=>"showhostdata(['Hosts', 'Database', 'user', 'password'], ['hostdata', 'extra']); return true;"), $extantparas=$cgi->popup_menu(-name=>"Parasites", -value=>$ParasiteTax, -width=>"200"); #print $cgi->redirect(-location=>"GDETNewMAIN.cgi"); return($html, $extantrefs, $extantlocs, $extanthosts, $extantparas); }; my $pjx = CGI::Ajax->new(connectdB => $connectdB, showhostdata => $showhostdata); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($cgi,$Show_Form);