#!/home/rebelsky/perl/bin/perl

# Sarah Luebke
# started 06/15/99
# last modified 07/28/99

# This script is called when the search button is clicked (the search
# button is added by insert.cgi).  It takes a URL as a hidden query and
# produces a form.  The reader can either do a keyword search
# or an exact string search, depending on which radio button
# is checked.  The form then calls search.cgi to
# do the search.

#package declaration
package SearchForm;
use Exporter ();
@ISA = (Exporter);
@EXPORT = qw(printForm);

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

sub printForm 
  {
  #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;                  #the original query string
    my $url;                    #the url of the page being searched
    my $lasttime;               #the 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
    $query = $client_request->url;
    $query =~ /\?(.*)/i;
    $query = $1;
    
    #the following lines were added by Rachel Heck on 8/4/99
    #split the query string into parts
    $query =~ /(.*)\&(.*)/i;
    $url = $1;
    $lasttime = $2;
    
    #make the lasttime contain a | instead of the code %7C
    $lasttime =~ s/%7C/\|/i;
    
    # print out the form, including a hidden value to store the URL
    
    $response = <<"Print_tag";
<HTML>
<HEAD><TITLE>Search Annotations for $url</TITLE>
<meta name=\"Ravel\" content=\"disallow: .*?-.*?-.*?-.*?\$\"></HEAD>
<BODY BGCOLOR=\"WHITE\">
<H1>Search Annotations for $url</H1>
<form method=\"get\" action=\"http://ravel/Annotation/search.cgi\" NAME=\"search\">
<INPUT TYPE=\"radio\" NAME=\"type\" value=\"keyword\" CHECKED>Keyword<BR>
<INPUT TYPE=\"radio\" NAME=\"type\" value=\"exact\" >Exact String<BR>
<INPUT TYPE=\"radio\" NAME=\"type\" value=\"author\">Author<BR>
Enter search string<BR>
<TEXTAREA ROWS=5 COLS=60 NAME=\"string\"></TEXTAREA><BR><BR>
<INPUT TYPE=\"submit\" NAME=\"sendmein\" VALUE=\"Submit\">
<INPUT TYPE=\"reset\" NAME=\"reset\" VALUE=\"Reset\">
<INPUT TYPE=\"button\" name=\"close\" value=\"Close\" onClick=self.close()><BR>
<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"$url\">
<input type=\"hidden\" name=\"last_time\" value=\"$lasttime\">
</FORM>
</BODY>
</HTML>
Print_tag
    
    #create the response object and send it to the client
    $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 print_form

#return the true value to show that the package loaded correctly
return 1;

######################################################################
# Pod Documentation #
#####################

#=head1 Name

#Search_form

#=over 4

#=item printForm

#This subroutine gets a URL as a query string (the URL is appended to the call
# to search_form.cgi with an ampersand).  Print_form then prints out the HTML
# for a form that asks for a string, and whether the search should be a
# keyword or exact string search.

#=back

#=head 1 History

#=over 4

#=item [15 June 99]

#Began coding.

#=item [12 July 99]

#Rachel Heck edited the file so that it gets the name, email, and groups of 
#the client and then passes this to search.cgi

#=item [27 July 99]

#Rachel Heck edited the file so that it gets the last time that the user 
#looked at the main web page.

#=item [28 July 99]

# Added author search

#=item [4 August 1999]

#Turned the script (search_form.cgi) into a package (SearchForm.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.

#=back

#=cut

