Приглашаем посетить
Simple Base Search
#!/usr/bin/perl
# SimpleBase Search v.1.0. written by Dave Palmer <dave@upstatepress.com>
# This is the script that you'll need to search SimpleBase
# Very little must be changed for this to work. Of course you will need
# the latest version of SimpleBase (version 3.0) for this to work!
#
# Right now the searching is limited to just searching by first or last
# name or by state. I intend to improve this to search just by using
# keywords. If anyone wants to improve on this, by all means, go ahead!
###########################################################################
# Define our global variable
$dbase_dir = "/usr/home/upstate/public_html/database/dbase.sdb";
###########################################################################
# Get data
read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $input);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# Translate our hash references
$action = $FORM{'action'};
$keyword = $FORM{'keyword'};
$search = $FORM{'search'};
if ($action eq "showall") { &showall; }
else {
&search; }
sub showall {
print "Content-type: text/html\n\n";
local($fname, $lname, $email, $address, $city, $state, $zip, $url);
open(FILE, "$dbase_dir") || die "I can't open that because: $!\n";
while(<FILE>) {
chop;
@all = split(/\n/);
foreach $line (@all) {
($fname, $lname, $email, $address, $city, $state, $zip, $url) = split(/&&/, $line);
print "<html><head><title>All Entries</title></head>\n";
print "<body>\n";
print "First Name: <b>$fname</b><br>\n";
print "Last Name: <b>$lname</b><br>\n";
print "E-mail: <b>$email</b><br>\n";
print "Address: <b>$address</b><br>\n";
print "City: <b>$city</b><br>\n";
print "State: <b>$state</b><br>\n";
print "Zip Code: <b>$zip</b><br>\n";
print "<a href=\"$url\">View Full Entry</a><br><br>\n";
print "</body></html>\n";
}
}
}
sub search {
print "Content-type: text/html\n\n";
# Make sure the user filled out the keyword field
&missing(keyword) unless $keyword;
open(FILE, "$dbase_dir") || die "I can't open that because: $!\n";
while(<FILE>) {
chop;
@all = split(/\n/);
foreach $line (@all) {
local($fname, $lname, $email, $address, $city, $state, $zip, $url) = split(/&&/, $line);
if ($search eq "fname" && $keyword eq "$fname") {
$match = 1;
print "<html><head><title>Matches</title></head>\n";
print "<body>\n";
print "First Name: <b>$fname</b><br>\n";
print "Last Name: <b>$lname</b><br>\n";
print "E-mail: <b>$email</b><br>\n";
print "Address: <b>$address</b><br>\n";
print "City: <b>$city</b><br>\n";
print "State: <b>$state</b><br>\n";
print "Zip Code: <b>$zip</b><br>\n";
print "<a href=\"$url\">View Full Entry</a><br><br>\n";
print "</body></html>\n";
}
if ($search eq "lname" && $keyword eq "$lname") {
$match = 1;
print "<html><head><title>Matches</title></head>\n";
print "<body>\n";
print "First Name: <b>$fname</b><br>\n";
print "Last Name: <b>$lname</b><br>\n";
print "E-mail: <b>$email</b><br>\n";
print "Address: <b>$address</b><br>\n";
print "City: <b>$city</b><br>\n";
print "State: <b>$state</b><br>\n";
print "Zip Code: <b>$zip</b><br>\n";
print "<a href=\"$url\">View Full Entry</a><br><br>\n";
print "</body></html>\n";
}
if ($search eq "state" && $keyword eq "$state") {
$match = 1;
print "<html><head><title>Matches</title></head>\n";
print "<body>\n";
print "First Name: <b>$fname</b><br>\n";
print "Last Name: <b>$lname</b><br>\n";
print "E-mail: <b>$email</b><br>\n";
print "Address: <b>$address</b><br>\n";
print "City: <b>$city</b><br>\n";
print "State: <b>$state</b><br>\n";
print "Zip Code: <b>$zip</b><br>\n";
print "<a href=\"$url\">View Full Entry</a><br><br>\n";
print "</body></html>\n";
}
}
}
if(! $match) {
print "<html><head><title>No Matches</title></head>\n";
print "<body>\n";
print "<h1>Sorry</h1>\n";
print "<p>Sorry, no matches found for: <b>$keyword</b>\n";
print "</body></html>\n";
exit;
}
}
sub missing {
local($missing) = @_;
print "Content-type: text/html\n\n";
print "<html><head><title>Sorry</title></head>\n";
print "<body>\n";
print "<h1>Sorry</h1>\n";
print "<p>You didn't fill in the <b>$keyword</b></p>\n";
print "Please go back and fill in that field!\n";
print "</body></html>\n";
exit;
}