#!/home/rebelsky/perl/bin/perl
#This cgi script creates the frame web page containing the annotation on 
#top and the reply tree on the bottom.
#(POD documentation at end)

##################
# Package Begins #
##################
#package declaration
package AnnotationFrame;
use Exporter ();
@ISA = (Exporter);
@EXPORT = qw(annotation_execute);

#import modules
use AFile;
use HTTP::Request;
use HTTP::Daemon;

###########################################################################
# annotation_execute #
###########################################################################
# This subroutine gets the data about the user and their request from
# ravel and sends a response to the client containing a framed web page
# with the annotation in the top frame and the reply tree in the bottom
# frame.
# ARGUMENTS: The user's name in string form, the user info in string form,
# a client connection in order to send the client a response, and the
# original client request.
# RETURNS: Returns 1 to show that it ran correctly.
###########################################################################
sub annotation_execute
  {
    #read arguments
    my $name = shift;           #id of the user for this request
    my $user_info = shift;      #a string with info on the user
    my $client = shift;         #client connection
    my $client_request = shift; #request from the client
    #other variables
    my $query;                  #original query string
    my $file;                   #the annotation file
    my $url;                    #the url of the annotated page
    my $lasttime;               #lasttime user viewed this page
    my $base;                   #the base annotation file
    my $dir;                    #the directory for the annotation
    my $response;               #the response to send the client
    my $respone_object;         #the client response object

    #parse the url string
    $query = $client_request->url;
    $query =~ /\?(.*)/i;
    $query = $1;
    
    #split the query into parts
    $query =~ /(.*)\&(.*)\&(.*)/i;
    $file = $1;
    $url = $2;
    $lasttime = $3;

    #get the base annotation file address
    $file =~ /(.*\/)(.*)/i;
    $dir = $1;
    $base = $2;
    if ($base !~ /\.txt$/i)
      {
        $base =~ s/(.*?)_(.*)/$1/i;
        $base = $base . ".txt";
      }#if ($base !~ /.txt/i)
    $base = $dir . $base;

    #Display the frame with annotation on top and reply tree on the bottom
    $response = <<"EOF";
<html>
<meta name=\"Ravel\" content=\"disallow: .*?-.*?-.*?-.*?\$\">
<head>
<title>Annotation<\/title>
<\/head>
<frameset rows=50%,50%>
<frame name=\"annotation\" src=\"http://ravel/Annotation/top.cgi?$file\&$url\&$lasttime\">
<frame name=\"tree\" src=\"http://ravel/Annotation/bottom.cgi?$base\&$url\&$lasttime\">
<\/frameset>
<body bgcolor\"white\">
<p>
You do not have a frames capable browser.  
Please use an alternative method of viewing the annotations.
<\/p>
<form>
<input type=\"button\" name=\"ok\" value=\"OK\" onClick=self.close()> 
<\/form>
<\/body>
<\/html>
EOF

    #create the client response and send it
    $response_object = HTTP::Response->new(200);
    $response_object->content($response);
    $client->send_response($response_object);
   
    #return the true value to show that it ran correctly
    return 1;
  }#sub annotation_execute

#return the true value to show that the package loaded correctly
return 1;
#####################
# Pod Documentation #
#####################
=pod

=head1 ID

=over 4

=item Package

AnnotationFrame.pm (Previously known as annotation.cgi)

=item Author

Rachel Heck

=item Desciption

This cgi script creates the frame web page containing the annotation on 
top and the reply tree on the bottom.

=back

=head1 Subroutines

=over 4

=item annotation_execute

This subroutine gets the data about the user and their request from ravel
and sends a response to the client containing a framed web page with the 
annotation in the top frame and the reply tree in the bottom frame.

=back

=head1 History

=over 4

=item [9 July 1999]

The script runs correctly and is fully commented

=item [12 July 1999]

Gets and passes the groups that the user is a member of.

=item [16 July 1999]

Pop-up annotation windows will not use plug-ins in the Ravel server 
anymore.  The package containing readFile is now called AFile instead of 
Annotation.

=item [27 July 1999]

The script is now getting and passing the last time that the user viewed 
the main web page.

=item [28 July 1999]

You can now send annotation any annotation file, including a reply, and it 
will display that annotation as well as the entire reply tree for the base 
annotation.

=item [4 August 1999]

Turned the script (annotation.cgi) into a package (AnnotationFrame.pm) in 
order to use Proxy URLs.  This adds security.  All cgi calls are now Proxy 
URLs.  The name, email, and groups information are no longer being passed 
to cgi scripts.

=item [5 August 1999]

The subroutine annotation_execute is working correctly and is fully 
commented.

=back

=cut

