#!/home/rebelsky/perl/bin/perl
#This script displays the reply tree using javascript.
#(POD documentation at end)

##################
# Package Begins #
##################
#package declaration
package Bottom;
use Exporter ();
@ISA = (Exporter);
@EXPORT = qw(bottom_execute);

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

###########################################################################
# bottom_execute #
###########################################################################
# This subroutine gets all the user information from ravel and then sends
# the client a response containing the correct HTML and Javascript to
# display the reply tree for a specified annotation.
# ARGUMENTS: The user's name in string form, the user information in string
# form, the 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 bottom_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
    #variables
    my $query;                  #original query string
    my $file;                   #annotation file address
    my $url;                    #url of the annotated page
    my $tree;                   #javascript line for tree creation
    my $groups;                 #the groups that the user is a member of
    my $lasttime;               #last time that the user viewed this page
    my $response;               #the response to send the client
    my $response_object;        #the client response object
    
    #parse the string of user information
    $user_info =~ /<GROUPLIST>(.*)<\/GROUPLIST>/;
    $groups = $1;
    $query = $client_request->url;
    $query =~/\?(.*)/i;
    $query = $1;
    
    #split query into parts
    $query =~ /(.*)\&(.*)\&(.*)/i;
    $file = $1;
    $url = $2;
    $lasttime = $3;
    
    #generate the javascript line for creating the tree using 
    #treeCreation->main
    $tree = tree_main($file,$url,$name,$groups,$lasttime);
    
    #if there are replies, return the tree. If not, say so
    if ($tree ne "There are no replies for this annotation.<br>")
      {
        #print the tree
        $response = <<"EOF"; 
<center><h1>Reply Tree<\/h1><\/center>
<html>
<meta name=\"Ravel\" content=\"disallow: .*?-.*?-.*?-.*?\$\">
<head>
<title>Replies<\/title>
<SCRIPT LANGUAGE=\"Javascript\" SRC=\"http://www.math.grin.edu/~rebelsky/Blazers/Annotations/Summer1999/Trees/tree.js\">
<\/SCRIPT>
<SCRIPT LANGUAGE=\"Javascript\">
$tree
<\/SCRIPT>
<\/head>
<BODY BGCOLOR=white>
<\/BODY>
<\/HTML>
EOF
      }                         #if ($tree...this annotation.<br>")
    else
      {
        #print that there are no replies
        $response = <<"EOF";
<center><h1>Reply Tree<\/h1><\/center>
<html>
<meta name=\"Ravel\" content=\"disallow: .*?-.*?-.*?-.*?\$\">
<head>
<title>Replies<\/title>
<\/head>
<BODY BGCOLOR=white>
$tree
<\/BODY>
<\/HTML>
EOF
      }                         #else
    
    #create the client response object and send a response
    $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 bottom_execute

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

=head1 ID

=over 4

=item Package

Bottom.pm (Previously known as bottom.cgi)

=item Author

Rachel Heck

=item Description

This script displays the reply tree using javascript.

=back

=head1 Subroutines

=over 4

=item bottom_execute

This subroutine gets all the user information from ravel and then sends 
the client a response containing the correct HTML and Javascript to 
display the reply tree for a specified annotation.

=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.

=item [27 July 1999]

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

=item [4 August 1999]

Changed the script (bottom.cgi) into a package (Bottom.pm) in order to use 
Proxy URL stuff. This adds protection.  All cgi calls are now Proxy URLs.  
The name, group and email information are no longer being passed to cgi 
scripts.

=item [5 August 1999]

The subroutine bottom_execute is working and is fully commented.

=back

=cut

