#!/usr/bin/perl # This is a CGI script to do a complex search of the oanda database. # It is to be installed at /web/herald/htdocs/heraldry/OandA/oanda_complex.cgi on atensubmissions.nexiliscom.com. # Set URL for this script. $cgi_url = '/cgi-bin/heraldry/OandA/oanda_complex.cgi'; require '/web/herald/cgi-bin/heraldry/OandA/common.pl'; # Set title for form. $form_title = 'Complex Search Form'; $criteria = 5; # option settings @methods = ('', 'armory description', 'name pattern', 'record type', 'blazon pattern', 'broad name'); @sorts = ('score and name', 'score only', 'name only', 'last action date', 'blazon'); $sort = 'score and name'; # default foreach $pair (split (/\&/, $ENV{'QUERY_STRING'})) { ($left, $right) = split (/=/, $pair, 2); $left = &decode ($left); $right = &decode ($right); if ($left =~ /^w(\d+)$/) { $weight[$1] = $right if ($1 > 0 && $1 <= $criteria); } elsif ($left =~ /^m(\d+)$/) { $method[$1] = $right if ($1 > 0 && $1 <= $criteria); } elsif ($left =~ /^p(\d+)$/) { $p[$1] = $right if ($1 > 0 && $1 <= $criteria); } $arm_descs = $right if ($left eq 'a'); $era = $right if ($left eq 'd'); $gloss_links = $right if ($left eq 'g'); $limit = $right if ($left eq 'l'); $sort = $right if ($left eq 's'); } $limit = 25 if ($limit !~ /^\d+$/); &print_header (); $invalid = 0; $valid = 0; for $i (1 .. $criteria) { if ($weight[$i] !~ /^[+&]?\d+$/) { if ($method[$i] ne '') { print "

You specified an invalid weight ($weight[$i]) for criterion #$i; a weight must be a positive number.

"; $invalid++; } } else { if ($method[$i] eq '') { print "

You specified a weight ($weight[$i]) for criterion #$i without specifying a search method.

"; $invalid++; } else { $valid++; } } } if ($valid > 0 && $invalid == 0) { &connect_to_data_server (); print S 'l ', $limit; for $i (1 .. $criteria) { if ($method[$i] eq 'name pattern') { print S "e1 $weight[$i] $p[$i]"; } elsif ($method[$i] eq 'record type') { $temp = $p[$i]; s/([^\\])?/$1\\?/g; print S "e3 $weight[$i] ^($p[$i])\$"; } elsif ($method[$i] eq 'armory description') { print S "d0 $weight[$i] $p[$i]"; } elsif ($method[$i] eq 'blazon pattern') { print S "ebi $weight[$i] $p[$i]"; } elsif ($method[$i] eq 'broad name') { print S "n $weight[$i] $p[$i]"; } } print S 'EOF'; $n = &get_matches (); if ($sort eq 'score only') { $scoresort = 1; } elsif ($sort eq 'score and name') { $scoresort = 1; @matches = sort byscorename @matches; } elsif ($sort eq 'name only') { $scoresort = 0; @matches = sort byname @matches; } elsif ($sort eq 'last action date') { $scoresort = 0; @matches = sort bylastdate @matches; } elsif ($sort eq 'blazon') { $scoresort = 0; @matches = sort byblazon @matches; } } print '

There are other search forms available.'; print 'For help using this form, please refer to the hints page.'; print '

Scoring criteria:

    '; for $i (1 .. $criteria) { print '
  1. weight='; print ''; # method selector print 'method='; &select ("m$i", $method[$i], @methods); print 'pattern='; print ''; } print '
'; print '

Maximum number of items to display ->'; print ''; &display_options (); print '

Actions:

'; print ''; print '[reset the scoring criteria]'; print ''; if ($valid) { print '
'; &print_results ('the scoring criteria above', $n, $scoresort); } &print_trailer (); # end of /web/herald/htdocs/heraldry/OandA/oanda_complex.cgi