#!/usr/local/bin/perl -I../../pm
 
# Copyright (c) 1996. Curtis E. Dyreson. All rights reserved.  This 
# software is covered under the general license and lack of 
# warranty as stated in the installation kit. WARNING! DANGER WILL 
# ROBINSON! USE AT YOUR OWN RISK!
 
use strict;
use CGI_Lite;
use DBMDatabase;
use Persistent::Graph;
use JumpingSpider;

my $cgi = new CGI_Lite;
 
my $ROOT = 'http://www.cs.jcu.edu.au/cgi-bin/perl/mww/script';

# Build the header
 print "Content-type: text/html", "\r\n\r\n";
 my $data = $cgi->parse_form_data();
 
# common routine to clean junk
 require "cleanWS.pm";
 
# Make security checks - none really
#require "security.pm";
 
# figure out which action to apply
 
 my $i = 0;
 my @keywords = ();
 @keywords = split("->", $$data{"query"});

 &starter(\@keywords);
 
#========================================================================
# Process the field entries
#========================================================================
sub starter {

  my ($keywords) = @_;
  my $global = new Globals();

  print "<HTML>";
  print  <<"HEAD";
  <HEAD>
  <TITLE>
  Mini World Web - James Cook University
  </TITLE>
  </HEAD>
  <BODY>
  <INPUT TYPE="hidden" NAME="hidden" VALUE="">
  <FORM METHOD="POST" ACTION="$ROOT/starter">
  Enter the next search string in the text box below.<BR>
HEAD

  print "<INPUT TYPE=\"text\" NAME=\"query\" VALUE=\"";
    print $$data{"query"};
    print "\" SIZE=60><BR>\n";

  print  <<'FORM';
  <INPUT TYPE="submit" NAME="Search" VALUE="Search">
  </FORM>
FORM

  my $result = &Query::query($keywords, 
                 $global->{'indexTable'}, 
                 $global->{'WWWReachableTable'});

  #
  # print out the graphic user interface
  #

  print "Results of search for <UL><LI>" . 
        join ("<LI>", @$keywords) . "</UL>\n";
  my $id;
  my $titleTable = $global->{'titleTable'};
  print "<OL>\n" if (scalar @$result);
  foreach $id (@$result) {
    my $url = $id->toString();
    my $t = $titleTable->retrieveTuple($id);
    my $title = "title unknown?";
    $title = $t->getValueAsString() if ($t);
    print "<li><A HREF=\"$url\">$title</A><BR> (<i>$url</i>)<BR>\n" if ($t);
    }
  print "</OL>\n" if (scalar @$result);

  print  <<'REST';
  <hr size=3 noshade>
  [<a href="http://www.cs.jcu.edu.au/~curtis/htmls/MiniWorldWeb/publications.html">Papers</a>]
  [<a href="http://www.cs.jcu.edu.au/~curtis/htmls/MiniWorldWeb/demo.html">Interactive demo</a>]
  [<a href="http://www.cs.jcu.edu.au/~curtis/htmls/MiniWorldWeb/code.html">Implementation</a>]
  [<A HREF="mailto:curtis@cs.jcu.edu.au">join mailing list</A>]
  <P>
  Curtis Dyreson &copy; 1997. All rights reserved. 
  </BODY>
  </HTML>
REST

}

sub printMeasureTables {
  print '<tr>';
    print '<td valign=top>';
    print '</td>';
  print '</tr>';
}

sub printGUI {
  print '<center><table border=3 cellpadding=5>';
  print '<tr></tr>';
  print '</table>';
  print "\n<P>\n";
    print '</td>';
}

sub printMessage {
  my ($message) = @_;
  print $message;
}  

sub convert_to_pre_html {
  my ($text) = @_;

  #$text =~ s/&/\&and;/g;
  $text =~ s/</\&lt;/g;
  $text =~ s/>/&gt;/g;
  #$text =~ s/\&/\&and;/g;
  return $text;
}
