Subs::Header (version 1.0)


package Subs::Header;

##############################################################################
#
# DESCRIPTION: This subroutine class produces an HTML documentation 
# DESCRIPTION: header file which will serve as a home page for a 
# DESCRIPTION: processing run.
# DESCRIPTION: The page created by this generic class is largely blank,
# DESCRIPTION: so most missions need to have their own sub-class which
# DESCRIPTION: fills in more information.
# DESCRIPTION: 
# DESCRIPTION: This class provides a number of methods which may be used
# DESCRIPTION: to format HTML, such that sub-classes
# DESCRIPTION: should not need to explicitly use any HTML tags.
# DESCRIPTION: Sub-classes could over-ride these methods to produce
# DESCRIPTION: a page in something other than HTML.
#
# HISTORY:
#
# VERSION: 1.0
#
##############################################################################

use Subs::Sub;
@ISA = ("Subs::Sub");
use strict;


#########################################
# constructor
#########################################
sub new {
    my $proto=shift;
    my $self=$proto->SUPER::new();

    $self->{DESCRIPTION}="Creating HTML header page";

    ########################
    # Header file name
    ########################
    $self->{FILE}=$self->filename()->get("header");

    ########################################
    # put some generic info in the job par 
    ########################################
    my $procscriptver=$self->procpar()->read("version");

    my $procdate= Util::Date->new()->date();

    $self->jobpar->set({procscriptver => $procscriptver,
                        procdate      => $procdate      });


    return $self;
}

#####################
# METHODS:
#####################

############################################
# first inherit init stuff and then
# generate the header file top
############################################
sub init {
    my $self  = shift;

    ###########################
    # inherit the usual stuff
    ###########################
    $self->SUPER::init();

    ##################################
    # get some info
    ##################################
    my $seq=$self->jobpar()->read("sequence");

    ###################################
    # write the top of the header page
    ###################################
    open  HEADER, ">$self->{FILE}";

    print HEADER "<HTML>\n";
    print HEADER "<HEAD>\n";
    print HEADER "<TITLE>Sequence $seq Header Page</TITLE>\n";
    print HEADER "</HEAD>\n";
    print HEADER "<BODY>\n";
    print HEADER "<CENTER><H1>Sequence $seq Header Page</H1></CENTER>\n";
    print HEADER "This page gives a basic description of this sequence\n";
    print HEADER "and references to more detailed information.\n";
    print HEADER "<P>\n";

    print HEADER "The following information is also available:\n";
    print HEADER "<UL>\n";
    print HEADER $self->link_text();
    print HEADER "</UL>\n";

    print HEADER "<HR>\n";

    close HEADER;

} # end of init method

######################################################################
# empty body - specific missions should over-ride this
# to fill in the contents of the header page.
######################################################################
sub body {
}


###################################################################
# generate the links to other pages which are found at the top of the page.
# Sub-classes should override this method to add more links.
###################################################################
sub link_text {
    my $self = shift;

    my $url;
    my $text="";
    my $filename=$self->filename();

    $url=$filename->get("fileinfo");
    $text .= "<LI><A HREF=\"$url\">A list of all files</A>\n";

    $url=$filename->get("logindex");
    $text .= "<LI><A HREF=\"$url\">The processing log index</A>\n";

    return $text;

} # end of link_text method


#######################################################################
# first put the closing HTML tags in the header page, then
# record the name of the header page in the job.par
# and finally do inherited cleanup stuff
#######################################################################
sub cleanup {
    my $self = shift;

    ##############################
    # finish the file
    ##############################
    open  HEADER, ">>$self->{FILE}";
    print HEADER "</BODY>\n";
    print HEADER "</HTML>\n";
    close HEADER;

    #############################################
    # record the name of the file in the jobpar
    #############################################
    $self->jobpar->set({header=>$self->{FILE}});

    #############################
    # do any inherited stuff
    #############################
    $self->SUPER::cleanup();

} # end of cleanup method

#######################################################
# begin a document section with the given heading
#######################################################
sub begin_section {
    my $self=shift;
    my $heading=shift;

    open  HEADER, ">>$self->{FILE}";
    print HEADER "<H2>$heading</H2>\n";
    print HEADER "<UL>\n";
    close HEADER;

}

###########################################################################
# end a document section. This doesn't actually do anything,
# but you should use it in case a subclass wanted to do something special 
# here. 
###########################################################################
sub end_section {
    my $self=shift;

    open  HEADER, ">>$self->{FILE}";
    print HEADER "</UL>\n";
    close HEADER;

}


###################################################
# begin a bulleted list
###################################################
sub begin_list {
    my $self=shift;

    open  HEADER, ">>$self->{FILE}";
    print HEADER "<UL>\n";
    close HEADER;
}

###################################################
# end a bulleted list
###################################################
sub end_list {
    my $self=shift;

    open  HEADER, ">>$self->{FILE}";
    print HEADER "</UL>\n";
    close HEADER;
}


######################################################################
# add an element to a bulleted list.
# Each item is a set of name-value pairs which will appear
# on the same line. Usually there is only one name-value pair,
# but sometimes it is useful to put two things (e.g. R.A. and Dec.)
# on the same line
######################################################################
sub item { # (name, value, name, value...)
    my $self=shift;

    ######################################
    # open the HTML file
    ######################################
    open  HEADER, ">>$self->{FILE}";
    print HEADER "<LI>";

    ##################################
    # loop over all name: value pairs
    ##################################
    my $name;
    my $data;
    while($name=shift) {
        $data=shift || "";

        print HEADER "<STRONG>$name</STRONG> $data\n";
    }

    ########################
    # close the HTML file
    ########################
    close HEADER;

} # end of item method




##################################################################
# generate a standard section giving name and address information
# for a given PI
##################################################################
sub pi_info {
    my $self = shift;
    my $prefix = shift;
    my $type   = shift;

    if(! defined $type) { $type =uc($prefix) }

    my $jobpar = $self->jobpar();

    open  HEADER, ">>$self->{FILE}";
    print HEADER "<H2>$type Principal Investigator</H2>\n";

    my $param;
    foreach $param ("piname" , "piaddr1", "piaddr2", "piaddr3", "piaddr4", 
                    "piaddr5", "piemail" ) {
   
        my $value = $jobpar->read($prefix.$param);
        if($value) {print HEADER "$value<br>\n"}
    }
    print HEADER "<P>\n";

    close HEADER;

} # end of pi_info method