#!/usr/local/bin/perl $| = 1; ############################################################## # # Search1.cgi 1.0.4 # Based on Database_Doctor # Altered 6/2/2001 by Bob Roberds for use with # comic strip archive # at http://www.soaprope.com # Mike Carville # www.web-bazaar.com/cgi/ # carville@web-bazaar.com # # This script is made available free of charge. # Please leave my name in the header section. # You may not sell this script for any reason. # While not required, please leave the banner in the footer # in the manager script to help fund further development. # # If you are really thrilled with this script, why not help # us both out and buy a reference book from our scripts page. # We get a commission, you get knowledge, and Amazon stockholders # breathe easier for another day. <:-) # # The Database Doctor # ------------------- # The Database Doctor is a tool designed to help manage # Pipe Delimited Databases.(|) The script is designed to # add to, edit and delete, sort and prepare printouts of # databases. Many scripts, especially web stores utilize # these types of data files. # # The script is password protected, and has a user addition # form. # # Earlier versions of this script supported multiple users. # Nobody seemed to care, and it messed up a lot of people. # Out like the cat. In with the new. # # Even though this was written to manage a webstore database, # everybody seemed to want a front end to this. Display.cgi # was written to address this. The Database Doctor will still # work wonderfully to create and maintain databases for an # inventory file. With display.cgi now it becomes flexible # and can easily handle address books, directories or whatever # you can imagine. And imagination is the key. # # # A key feature of the script is that it will edit any # number of fields in a database. # # -the database you make will have as many fields # as set in the @table_names array below. # # -if you subsequently add a field to the middle you # will need to adjust your database # # -The Titles for the fields need to match the names # on the input form, and are contained within the @table_names array . # # -The input form for new items is an html form module located in html.dat. # # -The Form can be whatever you like...you can have drop down # and so forth to speed up entry. # # -The absolute key though is that the name of the fields in the form # must match the headings for the fields in the @tables_names array below. This is how # the script knows where the data is coming in from, and where to put it. # If you are missing data from an entry form you are having a matching problem # # -Don't add an opening or closing form tag to html.dat...as that is in # the script itself. # # PATH to PERL # ------------ # # The first line of every cgi script contains the path to the perl interpreter on your server. # /usr/bin/perl is standard on most, some others use /usr/local/bin/perl # If you don't know where it is, ask your host, or if you have telnet, login and type whereis perl # # FILES # ----- # # Make ABSOLUTELY sure to transfer the files in ASCII and not BINARY. BINARY breaks cgi scripts. # # In the main CGI Directory place database_doctor.cgi(755) # # Contents (permissions in ())... html.dat(666) # # DATABASE (name whatever you like)(666) # # Place login_setup.cgi and users.dat wherever you want. # Login Setup will create the encrypted password. # There is a path to adjust the users.dat location on # the first line of login_setup.cgi # # There are two logon pages included as well. Remember to changes the # paths to the scripts, and to leave the form input names alone. # One accesses the Database Doctor, the other will add users to users.dat. # # One Other Option... # By setting the $check_items variable to Y the script will verify that the # first field in the entry you are adding is unique from all the others. # Most web store scripts require a unique item id. # # ALWAYS BACK UP YOUR DATA MANUALLY!!!! # # # We of course are not responsible if this script blows # up your computer. We can, however, sell you a new one. # At the point of this writing my computer has failed to blow up. # # My personal friend and mentor Steven May contributed to this # script with the form parsing routine, and inspired the logic # behind parts of the search routine. You can see Steven's # work at http://www.blackwater-pacific.com/ # # And lastly, thanks to Joe DePasquale for the search routine I # borrowed from the linkmatic script before modifying. # # # # Improvements in version 2.0 # # -changed path structure to make installation easier # # -added the ability to use get as well as post in the display script # # -added a routine that limits the number of results from a search, and provides links to more results. # # SET THESE FILE PATHS...you can add paths if you like,but having # paths caused lots of people not to be able to set it up right...so # I gave up and took em out! $database = "fsfprs.dat"; #just the name of the file $users = "users.dat"; #change to Y if you would like the first field compared #to the other first fields in the database during preview #to insure a unique ID if you need that for a webstore $check_items = "N"; @table_fields = ("Chars","Gags","Month","Year","Cameo","Special","Strip"); $fieldmax = 6; #max index of @table_fields and @fields $fieldmonth = 2; #indices of month and year fields in @table_fields and @fields $fieldyear = 3; ################################################################################################## #####Thats that. You change below here and you mess with the guts...feel free but be careful###### $ksdropfile = "../../public_html/private/data/keenspot_dropdown.html"; $topadfile = "../../public_html/private/data/advertisement.html"; $bottomadfile = "../../public_html/private/data/bottom_ad.html"; $emaillinkfile = "../emaillink.html"; print "Content-type: text/html\n\n"; print < Soap on a Rope - Search
END_OF_HEADER splat_file($topadfile); print <

END_OF_HEADER2 splat_file($emaillinkfile); print <

END_OF_HEADER2A ############################################################## # Parse from the web form ############################################################## read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @cgiPairs = split(/&/,$buffer); foreach $cgiPair (@cgiPairs) { ($name,$value) = split(/=/,$cgiPair); $value =~ s/\+/ /g; $value =~ s/%(..)/pack("c",hex($1))/ge; $form{$name} .= "\0" if (defined($form{$name})); $form{$name} .= "$value"; } ############################################################## # Find Items and Display in Editor ############################################################## if ($form {'find'}) { $hitCount=0; if ($form{'searchtext'}) { @searchText = split(/\x20/,$form{'searchtext'}); foreach $test (@searchText) { $test =~ s/\W//g; #remove nonword characters if ($test =~ /\S{2,}/) { push (@searchKey, $test);} } # # Testing here # print @searchKey; # print %form; # end testing if (! @searchKey) { print " ERROR: No valid keywords were entered.
\n"; } else { print"\n"; print"\n"; for ($cntr=0;$cntr<=$fieldmax;$cntr++){ if ($cntr!=$fieldmonth && $cntr!=$fieldyear) { print"\n"; } } print"\n"; $count=1; open(DATABASE, "$database"); @inLine=; #Load all of the database into @inLine 5/19/2001 close(DATABASE); if ($form{'sortorder'} eq 'ntoo') # see if sorting new-to-old { @inLine=reverse(@inLine);#print("ntoo\n"); #the print ntoo is debug stuff } $inldx = 0; while ($inLine[$inldx] && $hitCount < $form{'maxresults'}) { $line=$inLine[$inldx]; if ( $form{'field'} ne "") { @fields = split (/\|/, $inLine[$inldx]); $inLine[$inldx]=$fields[$form{'field'}]; } if ($form{'searchtype'} eq "any") {$foundFlag = "N";} else {$foundFlag = "Y";} foreach $test (@searchKey) { if ($inLine[$inldx] =~ /$test/i) { if ($form{'searchtype'} eq "any") { $foundFlag = "Y"; last; } } else { if ($form{'searchtype'} eq "all") { $foundFlag = "N"; last; } } # end If InLine } # end ForEach Test if ($foundFlag eq "Y") { @fields = split(/\|/,$line); $hitCount++; print "\n"; for ($cntr=0;$cntr<=$fieldmax;$cntr++){ if ($cntr==$fieldmax) { $datestr = substr($fields[$cntr],6,2); # Extract the date value $datestr =~ s/^0//g; # Remove leading 0 if any from $datestr #print"\n"; print"\n"; } elsif ($cntr != $fieldyear && $cntr != $fieldmonth) { print"\n"; } } print"\n"; } $count++; $inldx++; } # end While InLine #close(LINK); what is this?? 5/19/2001 print "
$table_fields[$cntr]
$fields[$cntr]$fields[$fieldmonth] $datestr $fields[$fieldyear]$fields[$cntr]
\n"; print "

Your search returned $hitCount entries.

\n"; } } else # end Else StartSearch { print " ERROR: No keywords were entered.

\n"; } } ############################################################## # Display the search form ############################################################## print <

Choose any combination of Search terms to locate entries.

SEARCH by Keywords:

Search for documents containing ANY or ALL of these words or phrases.
Show results in order OLD TO NEW or NEW TO OLD.
Search only in this Field
Max. results to show

END_OF_SEARCH_FORM ############################################################## # Display the footer ############################################################## #print < # # #END_OF_FOOTER print <

END_OF_FOOTER splat_file($bottomadfile); print <

END_OF_FOOTER2 sub splat_file { my $splatline; open(MY_SPLAT_FILE,$_[0]); while ($splatline = ) { print $splatline; } close(MY_SPLAT_FILE); }