Code Example 1:

#retrieve CGI parameters
my $returnFields=$cgiobj->param("return");
 unless ($returnFields) { $returnFields="*" }
my $queryTable=$cgiobj->param("table");
my $querySort=$cgiobj->param("sort"); 
my $querySortType=$cgiobj->param("sortType");

Code Example 2:

#parse through criteria parameters
my @allcriteria=();
my @allparams=$cgiobj->param();
foreach $param (@allparams) {
 if (($param=~/criteria_condition_(.*)/)
    ($cgiobj->param($param) ne "0")) {
  my $criterion=$1." ".$cgiobj->param($param)." ".
  if ($cgiobj->param("criteria_value_$1")) {   
    #ignore blank criteria
	push (@allcriteria,$criterion);
 (" ".$cgiobj->param("criteria_logic")." ",@allcriteria);

Code Example 3:

#mission control ... set the ball in motion
my $dbh=&openDB($DBD,$dbase,$dbuser,$dbpassword);
if ($queryTable) {
 my $sqlstatement="select $returnFields from $queryTable";
 if ($queryCriteria) {
  $sqlstatement.=" where ($queryCriteria)" }
 if ($querySort) {
  $sqlstatement.=" order by $querySort $querySortType" }
 my $sth=&sendSQL($sqlstatement,$dbh);
 print &createPage

else {
	#no table has been selected to view
	print &createPage(&resultTable($dbh));

Code Example 4:

sub openDB {
#open connection to database
my ($DBD,$dbase,$dbuser,$dbpassword)=@_;
my $dbh = DBI->connect("dbi:$DBD:$dbase",$dbuser,$dbpassword)
               || die "could not connect to database!";
return $dbh;
} #end openDB

Code Example 5:

sub sendSQL {
#send SQL query
my ($sqlstatement,$dbh)=@_;
my $sth = $dbh->prepare($sqlstatement);
$sth->execute ||
       die("Could not execute SQL statement ... maybe invalid?".
           "<br>Here is the statement that choked: $sqlstatement");
return $sth;
}#end sendSQL

Code Example 6:

sub resultTable {
#output SQL statement results into an HTML table
my $rowcount=0;
my ($dbh,$sth,$queryTable,$returnFields)=@_;
my $tableHTML="";
my $labelrow="";
my @fieldNames=();
my $fieldCount=0;

#reconstruct the query URL to pass on via hyperlinks
my $queryURLa="table=$queryTable&return=$returnFields";
if ($queryCriteria) { 
 my @allparams=$cgiobj->param();
 foreach my $param (@allparams) {
  if ($param=~/criteria/) {

Code Example 7:

sub createPage {
#insert the table into the template page
#the HTML template page must contain the comment 
#<!--FRONTEND--> where you wish GUFE's output to appear
my ($tableHTML)=@_;
#full filesystem path to template HTML page
my $templatePage="gufe.html";
my $finalPage="";
open (INFILE,"$templatePage");
my @template=<INFILE>;
close (INFILE);

return $finalPage
} #end createPage