#!/usr/bin/perl
package FormatdictyBase_base;
use strict;
use vars qw (@ISA @EXPORT_OK);
use Exporter;

@ISA = ('Exporter');
@EXPORT_OK = qw( PrintPageTop BeginHTML Banner SmallLogo PageHeading Help PrintBannerPageTop FooterReturnEmail PrintSmallLogoPageTop Divider75 Divider75br Divider50 Divider35 Divider35br ToolBar Copyright ButtonBar Email);

# Author : Gail Binkley
# Date   : January 18 2000

# This package includes a number of graphics routines for sdev/dictyBase databases
# For example printing the database banner etc.
#
#
# updated by Shuai Weng at March 2003. -- 
#          -- to get rid of the hard-coded html tags, path and urls
#
#

use CGI qw/:all/;

# use File::Basename; ## for the dirname function
# use lib dirname($ENV{DOCUMENT_ROOT})."/lib/dictyBase/Objects";

use lib "/usr/local/dicty/www_dictybase/db/lib/dictyBase/Objects";
use ConfigURLdictyBase;
use ConfigPathdictyBase;

our $configUrl = ConfigURLdictyBase->new;
our $configPath = ConfigPathdictyBase->new;
our $database = "dictyBase";
our $dblink = $configUrl->dblink($database);

##############################################################################
sub PrintPageTop {
##############################################################################
# this subroutine simply prints out the top of the sub pages, including
# the tool bar.  In addition to the database, it takes a page header as 
# an argument and optionally a help file. 

    my $database = shift;
    my $title = shift;
    my $helpfile = shift;
    my $help2 = shift;

    print &ToolBar;	
    &PrintTitleWithHelp($database, $title, $helpfile, $help2);
 
}

##############################################################################
sub PrintTitleWithHelp{
##############################################################################
# this subroutine simply prints out the top of the sub pages.  In addition
# to the database, it takes a page header as an argument, and optionall a
# help file.  The page prints out with the logo left-justified, heading 
# centered, and help right-justified

    my $database = shift;
    my $title = shift;
    my $helpfile = shift;
    my $help2 = shift;
    
    my $help;
    if ($helpfile) {
        $help = &Help($helpfile, $database, $help2);
    }

    print table({-width=>'100%',
		 -border=>'0',
		 -cellspacing=>'0',
		 -cellpadding=>'0'},
		Tr(td({-width=>'10%'}, br).
		   td({-width=>'80%',
		       -align=>'center',
		       -valign=>'middle'},
		      h1($title)).
		   td({-width=>'10%',
		       -valign=>'middle',
		       -align=>'right'},
		      $help)));

}


##############################################################################
sub ToolBar {
##############################################################################

    my $newUrl;

    my $gifFile = $configPath->breadStem."html/html/images/NewUpdate.gif";

    if (-e "$gifFile") {

	$newUrl = " ".img({-src=>$configUrl->breadServerRoot."images/NewUpdate.gif"});
	
    }
	
    return table({-border=>"0",
	     -width=>"100%",
	     -cellpadding=>"2",
	     -cellspacing=>"0"},
	    Tr(td({-colspan=>"4"},
		  hr({-width=>"100%"}))).
	    Tr(td({-valign=>"middle",
		   -align=>"right"},
		  a({-href=>$configUrl->breadServerRoot},
		    img({-src=>$configUrl->breadServerRoot."images/dictylogo.png",
			 -alt=>"dictyBase",
			 -border=>"0"}))).
	       th({-nowrap=>'1',
		   -valign=>"middle"},
		  "Quick Search:").
	       td({-align=>"left",
		   -valign=>"middle"},
		  start_form({-method=>"post",
			      -action=>$configUrl->dictyBaseCGIRoot."dictyBase/search/quickSearch"}).
		  textfield(-name=>'query',
			    -size=>'13').
		  submit(-name=>'Submit',
			 -value=>'Submit').
		  end_form).
	       th({-align=>"left",
		   -valign=>"middle"},
		  a({-href=>$configUrl->breadServerRoot."sitemap.html"}, 
		    "Site Map")." | ".
		  a({-href=>$configUrl->breadServerRoot."HelpContents.shtml"}, "Help")." | ".
		  a({-href=>$configUrl->breadServerRoot."SearchContents.shtml"},
		    "Full Search")." | ".
		  a({-href=>$configUrl->breadServerRoot},
		    "Home".$newUrl))).
	    Tr(td({-colspan=>"4",
		   -align=>"left"},
		  table({-border=>"0",
			 -width=>"100%",
			 -cellpadding=>"1",
			 -cellspacing=>"0"},
			Tr({-bgcolor=>"#b7d8e4",
			    -align=>"center"},
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->breadServerRoot."ComContents.shtml"}, "Community Info"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->breadServerRoot."SubmitContents.shtml"}, "Submit Data"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->DictyosteliumServerRoot."cgi-bin/blast.pl"}, "BLAST"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->DictyosteliumServerRoot."cgi-bin/dictyBase/web-primer"}, "Primers"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->DictyosteliumServerRoot."cgi-bin/dictyBase/PATMATCH/nph-patmatch"}, "PatMatch"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->dictyBaseCGIRoot."dictyBase/seqTools"}, "Gene/Seq Resources"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->breadServerRoot."Vl-Dictyostelium.shtml"}, "Virtual Library"))).
			   td(font({-size=>"-1"},
				   a({-href=>$configUrl->dictyBaseCGIRoot."dictyBase/suggestion"}, "Contact dictyBase"))))))).
	    Tr(td({-colspan=>"4"}, 
		  hr({-width=>"100%"}))));

}

##############################################################################
sub FooterReturnEmail {
##############################################################################

    my $formNm = "suggestion";

    return table({-width=>'100%'},
		 Tr(td({-align=>'left',
			-valign=>'top'},
		       a({-href=>$configUrl->breadServerRoot},
			 img({-src=>$configUrl->breadServerRoot.'images/arrow.small.up.gif',
                              -border=>0}).
			     "Return to dictyBase")).
		    td({-align=>'right',
			-valign=>'bottom'},
		       start_form(-action=>$configUrl->dictyBaseCGIRoot.'dictyBase/suggestion',
				  -name=>$formNm,
				  -target=>"infowin"). 
		       hidden(-name=>'script_name',
			      -value=>$ENV{'SCRIPT_NAME'}).
		       hidden(-name=>'server_name',
			      -value=>$ENV{'SERVER_NAME'}).
		       hidden(-name=>'query_string',
			      -value=>$ENV{'QUERY_STRING'}).
		       a({-href=>"javascript:document.$formNm.submit()"},
			 "Send a Message to the dictyBase Curators".
			 img({-src=>$configUrl->breadServerRoot.'images/mail.gif',
			      -border=>0})).end_form)));
		       


}


##############################################################################
sub Banner {
##############################################################################
# this subroutine simply returns a string.  Call it using print &Banner to 
# print the Database Banner centered.  Keeping $database parameter to be 
# consistent with FormatSMD.pm, but it is not necessary here. 

    my $database = lc(shift);

    my $url = $configUrl->breadServerRoot."Dictyostelium";


    return center(a({-href=>$url}, 
		    img({-src=>$configUrl->breadServerRoot.'images/dictyBase-home.gif',
			 -alt=>"dictyBase"}))),br;
}

##############################################################################
sub SmallLogo {
##############################################################################
# this subroutine simply returns a string.  Call it using print &SmallLogo
# to print a small logo left-justified. Keeping $database parameter to be 
# consistent with FormatSMD.pm, but it is not necessary here.

    my $database = lc(shift);

    my $url = $configUrl->breadServerRoot."Dictyostelium";

    return a({-href=>$url}, 
	     img({-src=>$configUrl->breadServerRoot."images/dictylogo.png",
		  -align=>'LEFT',
		  -valign=>'MIDDLE',
		  -border=>'0',
		  -alt=>'dictyBase'}));

}

##############################################################################
sub BeginHTML{
##############################################################################
# This subroutine simply uses the CGI routine start_html to BeginHTML,
# using whatever title was passed in, and the MDEV color as the
# background color.  Whilst simple, this means that the color need only
# be stored in one place, rather thatn have to be changed everywhere.

    my $database = lc(shift);

    my $title = shift || "dictyBase";

    my $JScript = shift;

    my $color;

    if ($database eq "dictyBase"){

	$color = "ffffff";

    } else {

	$color = "ffffff";

    }

    print start_html(-"title"=>$title,
		     -"bgcolor"=>$color,
		     -"script"=>$JScript);

}

##############################################################################
sub PageHeading{
##############################################################################
# This subroutine returns a string to print an HTML H1 header centered

    my $heading = shift;

    return h1({-align=>'CENTER',
	       -valign=>'MIDDLE'}, $heading);

}

##############################################################################
sub Help{
##############################################################################
# This subroutine returns a string, which prints out the help graphic
# button aligned to the right hand side, and will use whatever is
# passed in as the link, or by default will link to the specs page.

    my $helpfile = shift;
    my $database = uc(shift);
    my $goTut = shift;

    my $url;
    if ($helpfile =~ /\/staff\/dictyBase\/help\/(.+)$/) {
	$url = $configUrl->breadServerRoot."staff/dictyBase/help/$1";
    }
    elsif ($helpfile =~ /^http:/ && $helpfile !~ /html/i) {
	$url = $helpfile;
    }
    else {
	$helpfile =~ s/^.+\/([^\/]+)$/$1/;
    	$url = $configUrl->breadServerRoot."help/$helpfile";
    }
    my $goTutHelp = br;;
    if ($goTut) {
	$goTutHelp .= a({-href=>$configUrl->breadServerRoot."help/gotutorial.html"},
			img({-src=>$configUrl->dictyBaseImages."GOT.gif",
			     -align=>'RIGHT',
			     -valign=>'MIDDLE',
			     -border=>'0'}));
    }
    
    return table(Tr(td(a({-href=>$url},
		       img({-src=>$configUrl->dictyBaseImages."help.png",
			    -align=>'RIGHT',
			    -valign=>'MIDDLE',
			    -alt=>'Help',
			    -border=>'0'})))).
		 Tr(td($goTutHelp)));

}

##############################################################################
sub PrintBannerPageTop{
##############################################################################
# this subroutine simply prints out the top of the main page.  I only put
# the function in because these same 3 lines often appear in a row.  One
# place to have them is nicer! Help was removed since this is the routine
# for the main page banner.

    my $database = shift;

    &BeginHTML($database);
    
    print &Banner($database);

    print &Divider75br;    
}

##############################################################################
sub PrintSmallLogoPageTop{
##############################################################################
# this subroutine simply prints out the top of the sub pages.  In addition
# to the database, it takes a page header as an argument, and optionall a
# help file.  The page prints out with the logo left-justified, heading 
# centered, and help right-justified

    my $database = shift;
    my $title = shift;
    my $helpfile = shift;
    my $help2 = shift;

    &BeginHTML($database, $title);
    
    my $help;
    if ($helpfile) {
        $help = &Help($helpfile, $database, $help2);
    }
    
    print table({-width=>"100%",
		 -border=>"0",
		 -cellspacing=>"0",
		 -cellpadding=>"0"},
		Tr(td({-width=>'40',
		       -align=>"LEFT",
		       -valign=>"MIDDLE"},
		      &SmallLogo($database)).
		   td({-width=>'500',
		       -valign=>"MIDDLE"},
		      &PageHeading($title)).
		   td({-width=>'40',
		       -valign=>"MIDDLE",
		       -align=>"RIGHT"}, $help)));

}

##############################################################################
sub Divider75 {
##############################################################################
# Small dividing line 75% width of page

    return "<hr size=\"2\" width=\"75%\">\n";

}

##############################################################################
sub Divider75br {
##############################################################################
# Small dividing line 75% width of page, with <br> before and after 

    return "<br><hr size=\"2\" width=\"75%\"><br>\n";

}

##############################################################################
sub Divider50 {
##############################################################################
# Small dividing line 50% width of page

    return "<hr size=\"2\" width=\"50%\">\n";

}

##############################################################################
sub Divider35 {
##############################################################################
# Small dividing line 35% width of page

    return "<hr size=\"2\" width=\"35%\">\n";
}

##############################################################################
sub Divider35br {
##############################################################################
# Small dividing line 35% width of page, with <br> before and after 

    return "<br><hr size=\"2\" width=\"35%\"><br>\n";
}

##############################################################################
sub Copyright{
##############################################################################
# return copyright message

    return font({-size=>-2},
		"dictyBase<sup>tm</sup> pages Database Copyright &#169 1997-2002 The Board of Trustees of Leland Stanford Junior University. Permission to use the information contained in this database was given by the researchers/institutes who contributed or published the information. Users of the database are solely responsible for compliance with any copyright restrictions, including those applying to the author abstracts. Documents from this server are provided \"AS-IS\" without any warranty, expressed or implied.");
    
}

#####################################################################
1;
#####################################################################




