#!/home/bin/ # This script generates a HTML FORM, with itself as the "ACTION" # When this script is called it checks the STDIN for data it may # be passing to itself. If there is none, it generates the FORM # plus some help text on how to use it. If it does see search # keys in STDIN ($keys) it will again print the FORM, skip the # help text, open the data file, search for matches, and print # them as a HTML table. #require("cgilib.pl"); #****************************************************************** #**************** Main Rtn *********************** #****************************************************************** print "Content-Type: text/html\n\n"; $phone="/home/docs/resources/data/swosufac.dat"; print("\n"); print("Results\n"); print("\n"); print("
\n"); print("\"SWOSU\"\n"); print("
\n"); &GET_STATE_INFO; print "
\n"; print "

Faculty/Staff Directory Look Up

\n"; print "
\n"; print "

Enter Search Keys

\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; if ( $keys eq "") { print "
"; print "Enter Search words separated by spaces, Search words will be"; print " AND'ed together (only those names that contain all the keys"; print " will be returned.)"; print "

"; print "The Name field will be searched.

"; } else { print "


"; print "Search Results"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; &SEARCH_FOR_MATCH($keys); print "
NameOfficePhone NumberTitleEmail AddressHomePage
\n"; } print "

"; print "


\n"; print "Please send comments or suggestions to Webmaster\n"; print "

\n"; print "Southwestern Oklahoma State University
\n"; print "100 Campus Drive
\n"; print "Weatherford, OK 73096
\n"; print "

\n"; print "\n"; print "\"SWOSU\n"; print "\"Search\n"; print "\"SWOSU\n"; print "\"Campus\n"; print "\n"; print "\n"; print("\n"); print("\n"); #****************************************************************** #******************** Subroutines ******************************** #****************************************************************** #****************************************************************** #**************** Get Passed data from form *********************** #****************************************************************** sub GET_STATE_INFO { %fields = (); read(STDIN, $save_string, $ENV{CONTENT_LENGTH}); # Yes- Use it @prompts = split(/&/,$save_string); foreach (@prompts) { ($tmp1, $tmp2) = split(/=/,$_); $tmp2 =~ s/\x2b/\x20/g; $tmp2 =~ s/%2C/\x2c/g; $tmp2 =~ s/%28/\x28/g; $tmp2 =~ s/%29/\x29/g; $fields{$tmp1}=$tmp2; } $keys = $fields{'keys'}; $keys = "\U$keys"; } #****************************************************************** #********** Search file for lines with all search keys ************ #****************************************************************** sub SEARCH_FOR_MATCH { @search_key = split(/\x20/,$keys); $k =0; open(MYFILE, $phone); while() { $in_line = $_; ($name, $office, $phone_num, $title,$email,$hmpg ) = split(/~/,$in_line); if ($email ne "") { $email="" . $email . "\@swosu.edu "; } if ($hmpg ne "") { $hmpg="" . $hmpg . ""; } $found = "yes"; foreach (@search_key) { $pos_out = rindex("\U$name",$_); if ($pos_out < 0) { $found = "no"; } } if ( $found eq "yes") { if ($k > 999) { next; } # limit to 999 matches $k = $k + 1; print "", $name, "\n"; print "", $office, "\n"; print "", $phone_num, "\n"; print "", $title, "\n"; print "", $email, "\n"; print "", $hmpg, "\n"; print "\n"; } } }