#!/home/rebelsky/perl/bin/perl
#This script prints a web page that asks the client to confirm that they 
#wish to delete this annotation.  If they say yes, the annotation is 
#deleted.  If they say no or cancel, that annotation and its reply tree 
#are redisplayed.
#(POD documentation at end)

##################
# Package Begins #
##################
#package declaration
package Delete;
use Exporter();
@ISA = (Exporter);
@EXPORT = qw(delete_execute);

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

###########################################################################
# delete_execute #
###########################################################################
# This subroutine takes in the user information returned by ravel and sends
# the client a response containing a web page asking for confirmation for
# deleting an annotation. 
# ARGUMENTS: The user 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 delete_execute
  {
    #read arguements
    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;                      #the original query string
    my $file;                       #the annotation file to be deleted
    my $url;                        #url of the page the annotation is on
    my $lasttime;                   #lasttime the user accessed this page
    my $response;                   #the response to send the client
    my $response_object;            #the client response object
    local(*fields);                 #a hash to store the annotation data in

    #parse the query string
    $query = $client_request->url;
    $query =~ /\?(.*)/i;
    $query = $1;

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

    #get the data from the annotation using AFile->readFile
    readFile(*fields,$file);

    #remove extra spaces from ends of author name
    $fields{'author'} =~ s/^(\s)*//i;
    $fields{'author'} =~ s/(\s)*$//i;

    #print out confirmation
    $response = <<"EOF"; 
<html>
<meta name=\"Ravel\" content=\"disallow: .*?-.*?-.*?-.*?\$\">
<head>
<title>Delete<\/title>
<\/head>
<body bgcolor=\"white\">
<center><h1>Delete?<\/h1><\/center>
Are you sure you want to delete the annotation below?
<br>
<br>
<b>Title:<\/b> $fields{'title'}
<br>
<b>Annotation:<\/b>$fields{'annotation'}
<br>
<br>
<form>
<input type=\"button\" name=\"yes\" value=\"Delete\" onClick=document.location=\"http://ravel/Annotation/delete_annotation.cgi?$file\&$url\&$lasttime\">
<input type=\"button\" name=\"cancel\" value=\"Cancel\" onClick=document.location=\"http://ravel/Annotation/annotation.cgi?$file\&$url\&$lasttime\">
<\/form>
<\/body>
<\/html>
EOF

    #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 delete_execute

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

=head1 ID

=over 4

=item Package

Delete.pm (Previously known as delete.cgi)

=item Author

Rachel Heck

=item Description

This script prints a web page that asks the client to confirm that they 
wish to delete this annotation.  If they say yes, the annotation is 
deleted.  If they say no or cancel, that annotation and its reply tree are 
redisplayed.

=back

=head1 Subroutines

=over 4

=item delete_execute

This subroutine takes in the user information returned by ravel and sends 
the client a response containing a web page asking for confirmation for 
deleting an annotation. 

=back

=head1 History

=over 4

=item [9 July 1999]

The script works and is completely commented.

=item [12 July 1999]

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

=item [13 July 1999]

It now displays the annotation when it asks for confirmation to delete it.

=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 [30 July 1999]

If the user chooses to not delete the annotation, that annotation is 
redisplayed along with the whole reply tree instead of the base annotation 
and the reply tree.

=item [4 August 1999]

Turned the script (delete.cgi) into a package (Delete.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 delete_execute is working and is fully commented.

=back

=cut

