#!/usr/bin/perl
#
######################################################################
#
#   Program for keyword search of survey constructs
#
#   Mike Morrow, 26 June 1998
#
#   Modified: P. Newsted, June 30, 1998
#
######################################################################

use CGI;

$db = "/acs3b/newsted/public_html/constructs.htm";

$q = new CGI;

# Collect the parameters
$key1 = $q->param('key1');
$key2 = $q->param('key2');
$boolean = $q->param('boolean');

print($q->header);
print($q->start_html(-title=>'Searching for Surveys',
		     -xbase=>'http://www.acs.ucalgary.ca/~newsted/',
		     -BGCOLOR=>'white'));

if (!open(DB,"<$db"))
{
    print("Could not open database: $db\n");
    exit(1);
}
else
{
    print('<h2 align=left>Search Results:</h2>');
    print('Please click on any result to see the 
           full citation. A red check mark, 
           <IMG SRC="check2.gif" width=18 height=18> , 
           indicates an available instrument.<P>
           Responses in "quotes" are article
           titles that contain the search term(s);  
           these articles have employed a survey. <HR><P>');
    $hit = 0;
    if ($boolean eq 'and')
    {
	while (<DB>)
	{   
	    if ((/<BR>.*$key1.*$/i) && (/<BR>.*$key2.*$/i))
	    {
		$hit = 1;
		print;
	    }
	}
    }
    elsif ($boolean eq 'or')
    {
	while (<DB>)
	{
	    if ((/<BR>.*$key1.*$/i) || (/<BR>.*$key2.*$/i))
	    {
		$hit = 1;
		print;
	    }
	}
    }
    else
    {
	print("bogus boolean: $boolean\n");
    }

    if ($hit == 0)
    {
	print("<p>No matches found for: <tt>$key1 $boolean $key2</tt>\n");
    }
    close(DB);
}

print($q->end_html);
exit(0);

__END__
