#Working copy is located at www.swosu.ed/util/directry.htm
#!/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("<HEAD>\n");
print("<TITLE>Results</TITLE></HEAD>\n");
print("<BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\">\n");
print("<center>\n");
print("<img src=\"/images/swbanner.jpg\" usemap=\"#header\" border=\"0
+\" ALT=\"SWOSU\">\n");
print("</center>\n");
&GET_STATE_INFO;
print "<center>\n";
print "<H1>Faculty/Staff Directory Look Up</H1>\n";
print "</center>\n";
print "<P>Enter Search Keys</P>\n";
print "<FORM METHOD=POST ACTION=/cgi-perl/swosufac.pl>\n";
print "<INPUT TYPE=\x22text\x22 NAME=\x22keys\x22 SIZE=40 ";
print "VALUE=\x22", $keys, "\x22>\n";
print "<INPUT TYPE=\x22submit\x22 Name=\x22submit\x22 Value =\x22Searc
+h\x22>\n";
print "</FORM>\n";
if ( $keys eq "")
{
print "<HR>";
print "<B>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.)</B>";
print "<P>";
print "The Name field will be searched.<P>";
}
else
{
print "<HR>";
print "<B>Search Results</B>";
print "<TABLE BORDER>\n";
print "<TH ALIGN=\x22center\x22>Name</TH>\n";
print "<TH ALIGN=\x22center\x22>Office</TH>\n";
print "<TH ALIGN=\x22center\x22>Phone Number</TH>\n";
print "<TH ALIGN=\x22center\x22>Title</TH>\n";
print "<TH ALIGN=\x22center\x22>Email Address</TH>\n";
print "<TH ALIGN=\x22center\x22>HomePage</TH><TR>\n";
&SEARCH_FOR_MATCH($keys);
print "</TABLE>\n";
}
print "<P>";
print "<hr>\n";
print "<I>Please send comments or suggestions to <A HREF=\"mailto:webm
+aster\@swosu.edu\">Webmaster</a></i>\n";
print "<p>\n";
print "<font size=\"1\">Southwestern Oklahoma State University<br>\n";
print "100 Campus Drive<br>\n";
print "Weatherford, OK 73096<br>\n";
print "<p>\n";
print "<MAP NAME=\"header\">\n";
print "<AREA SHAPE=RECT COORDS=\"234,39,358,58\" HREF=\"/index.htm\" A
+LT=\"SWOSU Home\">\n";
print "<AREA SHAPE=RECT COORDS=\"362,37,417,61\" HREF=\"/util/search.h
+tm\" ALT=\"Search SWOSU\">\n";
print "<AREA SHAPE=RECT COORDS=\"418,39,478,59\" HREF=\"/sitemap.htm\"
+ ALT=\"SWOSU Site Map\">\n";
print "<AREA SHAPE=RECT COORDS=\"483,38,599,61\" HREF=\"/util/directry
+.htm\" ALT=\"Campus Directory\">\n";
print "<AREA SHAPE=\"default\" NOHREF=\"NOHREF\">\n";
print "</MAP>\n";
print("</BODY>\n");
print("</HTML>\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(<MYFILE>)
{
$in_line = $_;
($name, $office, $phone_num, $title,$email,$hmpg ) = split(/~/,$in_l
+ine);
if ($email ne "")
{
$email="<a href=\"mailto:" . $email . "\@swosu.edu\" >" . $email . "
+\@swosu.edu </a>";
}
if ($hmpg ne "")
{
$hmpg="<a href=\"\/perl\/disclaim.pl\?\/\~" . $hmpg . "\/\">" . $hmp
+g . "</a>";
}
$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 "<TD ALIGN=\x22left\x22>", $name, "</TD>\n";
print "<TD ALIGN=\x22left\x22>", $office, "</TD>\n";
print "<TD ALIGN=\x22left\x22>", $phone_num, "</TD>\n";
print "<TD ALIGN=\x22left\x22>", $title, "</TD>\n";
print "<TD ALIGN=\x22left\x22>", $email, "</TD>\n";
print "<TD ALIGN=\x22left\x22>", $hmpg, "</TD>\n";
print "<TR>\n";
}
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.