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

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

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

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 $email;                  #the email address of the user
    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 =~ /<EMAIL>(.*)<\/EMAIL>/;
    $email = $1;
    $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,$email,$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"; 
Content-type:  text/html

<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";
Content-type:  text/html

<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 the package loaded correctly
return 1;
#####################
# Pod Documentation #
#####################
=pod

=head1 ID

=over 4

=item Script

bottom.cgi

=item Author

Rachel Heck

=item Description

This script displays the reply tree using javascript.

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

=back

=cut

