#!/usr/local/bin/perl ($cmd,@param) = split(/\,/,$ENV{QUERY_STRING}); $testdir = 'c:/www/siteman/client/nyucfp/website/cfp20001'; $livedir = '/usr/local/ns-home/cfpweb'; $basehref = "http://$ENV{SERVER_NAME}$ENV{SCRIPT_NAME}"; $basehref =~ s/cgi\-bin\/[\x00-\xff]+//; $basehref =~ s/[\/]+$/\//; $out = "ADVANCED SEARCH

\n"; if ($cmd eq 'search') { read(STDIN,$buffer,$ENV{CONTENT_LENGTH}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $form{$name} = $value; } if ($form{allscps}) { $out .= " Please wait while we access the main site search... "; } else { if ($form{area} eq 'ALL') { $q1 = ".html"; $q2 = ".html"; } elsif ($form{area} =~ /^[A-Z]/) { $q1 = "cour$form{area}"; $q2 = "$form{area}.html"; } else { $q1 = $form{area}; $q2 = $form{area}; } opendir(FDIR,$testdir) || opendir(FDIR,$livedir) || die("can't open directory for search!"); @files = readdir(FDIR); $hits = 1; @words = split(/ /,$form{keywords}); foreach $file (@files) { if (($file =~ $q1) || ($file =~ $q2)) { if (open(FILE,"$testdir/$file") || open(FILE,"$livedir/$file")) { $foundit = 0; while ($nextline = ) { if ($nextline =~ //i) { $title = $nextline; } if ($form{phrase} eq 'yes') { if ($nextline =~ /$form{keywords}/i) { $foundit = 1; } } else { foreach $word (@words) { if ($nextline =~ /$word/i) { $foundit = 1; } } } } close FILE; if ($foundit) { $title =~ s/<title>//i; $title =~ s/<\/title>//i; $out .= "<b>$hits.</b> <a href=\"$file\">$title</a><br><br>\n"; $hits++; } } } } if ($hits == 1) { $out .= "Sorry, no pages were found containing you search string.\n"; } } } elsif ($cmd eq '') { $out .= " <script> document.forms[0].method = 'POST'; document.forms[0].action = '$basehref"."cgi-bin/advsearch.pl?search'; </script> <table border=\"0\" cellpadding=\"0\" cellspacing=\"5\"> <tr> <td><span class=\"name\">Keyword(s):</span></td> <td><input name=\"keywords\" size=\"20\"></td> </tr> <tr> <td><span class=\"name\">Area:</span></td> <td> <select name=\"area\"> <option value=\"ALL\" selected>All of CFP <option value=\"B\">Book <option value=\"D\">Digital <option value=\"M\">Magazine <option value=\"alumni\">Alumni <option value=\"certificate\">Certificates <option value=\"cour\">Courses <option value=\"facinfo\">Faculty <option value=\"interview\">Interviews </select> </td> </tr> <tr> <td colspan=\"2\"><input type=\"checkbox\" name=\"phrase\" value=\"yes\"><span class=\"name\">Search Keywords as Phrase</span></td> </tr> <tr> <td colspan=\"2\"><input type=\"checkbox\" name=\"allscps\" value=\"1\"><span class=\"name\">Search Entire SCPS Site</span></td> </tr> <tr> <td><input type=\"reset\" value=\" Clear \"></td> <td><input type=\"submit\" value=\" Search \"></td> </tr> </table> "; } if (open(FILE,"$testdir/Resources.html") || open(FILE,"$livedir/Resources.html")) { while ($nextline = <FILE>) { $content .= $nextline; } close FILE; } else {die ("Cannot read index file!!!\n");} $titlebase = "<title>NYU Center for Publishing Advanced Search<\/title> <base href=\"$basehref\"> "; $content =~ s/gl\.gif/gas\.gif/gi; $content =~ s/glink\.gif/geye\.gif/gi; $content =~ s/geyeoff\.gif/geyeon\.gif/gi; $content =~ s/glinkson\.gif/glinksoff\.gif/gi; $beforelink = "glinkson.src = 'images/glinksoff.gif'"; $afterlink = "glinkson.src = 'images/glinkson.gif';"; $content =~ s/$beforelink/$afterlink/; $content =~ s/gadvaoff\.gif/gadvaon\.gif/gi; $content =~ s/location=\'/location=\'$basehref/g; $content =~ s/<title>[\x00-\xff]*<\/title>/$titlebase/i; $content =~ s/(<!--BEGIN_PAGE_TEXT-->)[\x00-\xff]*(<!--END_PAGE_TEXT-->)/$out/; print "content-type: text/html $content ";