<?PHP /* Timing */ $intTimeBegan = time(); /*Safety Measure*/ unset($debug); /*Include User Functions*/ require("search.inc");?><!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD  HTML  4.0 Transitional//EN"  "http://www.w3.org/DTD/HTML4-loose.dtd">
<HTML lang="en-us">
<?PHP
/* This script was designed using HomeSite 4.0 on Windows NT.
** Whatever you use to edit this script, I suggest it 
** be something with full PHP3 color-syntax highlighting.
*/
?>
<HEAD>
	<TITLE>
		Simple Web Search for &quot;<?PHP print $words;?>&quot;
	</TITLE>
	<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<META name="robots" content="index,nofollow">
	<META name="description" content="Simple Web Search!">
<?php /*
	<LINK href="<?php print $strStyleName ?>" rel="stylesheet" type="text/css" title="Simple Search Style">
*/ ?>
</HEAD>
<BODY>
<h2>Simple Web Search</h2>
<div class="cool" style="text-align: center;">
	<form method="GET" action="<?php print $strSelf ?>">
		<table style="Width: 40%;" class="panel">
			<tr>
				<td style="Vertical-Align: Middle; Text-Align: Center;" colspan="2">Search for
					<input type="hidden" name="do" value="now">
					<input type="text" size="25" name="words" value="<?PHP print $words;?>">
					<?PHP 
if (isset ($strSearchSiteKey)) {
   $strSearchSiteIndex = $arySearchSiteIndices[chop($strSearchSiteKey)];
} else {
   reset ($arySearchSiteIndices);
   list( $dummy, $strSearchSiteIndex ) = each( $arySearchSiteIndices );
      if (count($arySearchSiteIndices) == 1) {
      $strSearchSiteKey = $dummy;
		}
}

// Print out available Site Indices to select field.
if (count($arySearchSiteIndices) > 1) {
   echo "<select name=\"strSearchSiteKey\">\n";
   reset ($arySearchSiteIndices);
   while (list($key,$val) = each( $arySearchSiteIndices ) ) {
      if ($strSearchSiteKey == $key) { echo "\t<option selected>".stripslashes($key)."\n"; }
      else {echo "\t<option>".stripslashes($key)."\n"; }
   }
   echo "</select>\n";
};

// Print out available Max Hits to select field.
if (count($aryMaxHits) > 1) {
   echo "<select name=\"intMaxHits\">\n";
   $m = 0;
   while($aryMaxHits[$m]) {
      if ($intMaxHits == $aryMaxHits[$m]) { echo "\t<option selected>$intMaxHits\n"; }
      else { echo "\t<option>$aryMaxHits[$m]\n"; }
      $m++ ;
   };
   echo "</select>\n";
} else { 
   $intMaxHits = $aryMaxHits[0];
};

// Make sure MaxHits is larger than returned results.
$intMaxHitsOffset = $intPageOffset + $intMaxHits;

?>
					<input type="submit" value="Find It!">
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<div style="Font-Size: 10pt; Font-Family: Verdana, Arial, Serif;">This <a
href="http://sunsite.berkeley.edu/SWISH-E/">SWISH-E
2.0</a>  based
	search will honor boolean (AND OR NOT), parentheses(), and wild-card*
	stemming queries. Examples: <em>john and doe or jane</em>, <em>john and (doe or
	jane)</em>, <em>not (john or jane) and doe</em>, <em>j* and doe</em>
					</div>
				</td>
			</tr>
			<?PHP
// Determine if we want to use [t] limiting code.
if ($intUseLimits) {
?>
			<tr>
				<td>Limit Search:
				</td>
				<td style="Vertical-Align: Middle; Text-Align: Center;">
					<?PHP

	// Lump all of the [t] delimiters together in preparation for the commandline.
	// $strLimit is, also, used to determine if a box is checked.
	If (is_array($aryLimits)){$strLimit = implode($aryLimits, "");};

	// Print out Search delimiters to checkbox fields.
	reset ($arySearchDelimiter);
	while (list($key,$val) = each($arySearchDelimiter)) {
		echo "\t\t<INPUT type=\"checkbox\" name=\"aryLimits[]\" value=\"$val\"";
		if (strstr($strLimit,$val)){
			print " checked"; }
		echo ">$key\n";
	};

	// Setup Limit code
	if ($strLimit != ""){
		$strLimitLine = "-t $strLimit";
	} else {
		$strLimitLine = "";
	};
	print "</TD></TR>\n";
}; // EndIf intUseLimits

?>
		</table>
	</form>
</div>
<?PHP 
// Why waste time and resources if they haven't performed a search?
If($do != "now") {fncPrintFooter();}; 
?><h2 class="indexed">Searching for
<q lang="UTF-7">
<?PHP print "$words";?></q>:</h2>
<?PHP
/* Added DN: Adds last updated time of index November 17, 1999 */

print "<p class=\"updated\">Index of <em>" . ereg_replace("_", " ", stripslashes($strSearchSiteKey)) ."</em> last updated on " . date("D, M jS, Y H:i:s", filemtime($strSearchSiteIndex)) . "</p>";

/* Get a list of metadata we need  */
reset ($aryMetaList);
$p = 0;
while($aryMetaList[$p]) {
	/* Grab properties from config file  */
	list ($strMetaName, $strLineHeading) = explode("|",$aryMetaList[$p]);
	/* Add it to our array  */
	$aryMetaName[] = $strMetaName;
	$p++;
};

/* Form properties line for command line  */
/* FIX THIS: It will fail miserably if we have no properties  */
$strMetaNameList = " -p " . implode($aryMetaName, " ");

/* Bug Fix JB: Parenthesis July 13, 1999
**
** $words = str_replace('\(','(',str_replace('\)',')',str_replace('\*','*',escapeshellcmd($words))));
**
**
** Bug Fix JB: Fixes parenthesis fix  July 14, 1999
** $words = '"'.str_replace('\(','(',str_replace('\)',')',str_replace('\*','*',escapeshellcmd($words).' '))).'"';
**
*/

$words = '"'.chop(str_replace('\(','(',str_replace('\)',')',str_replace('\*','*',escapeshellcmd($words).' ')))).'"';


$strCommandLine = $strSearchEngine.escapeshellcmd(" -d dq -m $intMaxHitsOffset -f $strSearchSiteIndex $strLimitLine $strMetaNameList -w ").$words;

fncDebug("CommandLine", $strCommandLine, 1);

// Must find a better error message, possibly fix the HTML as well.
Exec($strCommandLine, $aryResults, $return) or fncPrintFooter("<H3>Error performing search!</H3>\n<DL>\n\t<DT>Administrator\n\t\t<DD>Please check System-Specific variables defined at the beginning of the script.</DL>");
	// Jump out to HTML and set the table...

/************************************/
$i=0;
while(substr($aryResults[$i],0,1) == "#" || substr($aryResults[$i],0,3) == "err" && $i < 50):
	$strResultsClean = $aryResults[$i];
	// Correct for offset caused by SWISH-E Comments.
	$intPageOffsetCorrect++;
	//Explodes the Comment into an array
	$aryComment = Explode(": ", strstr($strResultsClean, " "));
		fncDebug($aryComment[0], $aryComment[1], 2);
	
	    // Print number of results
		If (trim($aryComment[0]) == "Number of hits") {
			$intNumHits = trim($aryComment[1]);
   		    if ($intNumHits > 0) {
			if ($intNumHits >= $intMaxHits) {

				//Print 0 as 1
				If($intPageOffset == 0){$intPageOffsetOne = $intPageOffset + 1;}
				Else{$intPageOffsetOne = $intPageOffset;};

				// What is the result number of the last document
				If ($intNumHits > $intMaxHitsOffset){$intPageHitsThru = $intMaxHitsOffset;}
				Else {$intPageHitsThru = $intNumHits;};

				// At which results am I looking
				echo "Displaying $intPageOffsetOne through $intPageHitsThru of $intNumHits results.<BR>\n\n";
				print "<DL class=\"result\">\n";
			} else {
				// If in the off chance it is a small result, under MaxHits.
				print "$intNumHits results found.<BR>\n\n";
				print "<DL class=\"result\">\n";
			};
		};
	};
	    // Soundex Yes or ...
		If (trim($aryComment[0]) == "Soundex Applied") {
			if (trim($aryComment[1]) == "1"){
				print"<dl><dt>Note:<dd>Resulting matches are sound-alikes according to <a href=\"http://www.nara.gov/genealogy/coding.html\">US Census SoundEx codes</a>.</dl>";
			};
		};
		// Stemming yes or ...
		If (trim($aryComment[0]) == "Stemming Applied") {
			if (trim($aryComment[1]) == "1"){
				print"<dl><dt>Note:<dd>Resulting matches are based on stems of the words in your query. A search for 'testing' will return matches for 'testing', 'tested', 'test', etc.</dl>";
			};
		};
	// Set the strBaseURL if it isn't in the config already.
	If (trim($aryComment[0]) == "Pointer"  && !isset($strBaseURL)){
		$strBaseURL = trim($aryComment[1]);
		fncDebug("URL Pointer",$strBaseURL, 3);
	};
	fncDebug("strResultsClean", $strResultsClean, 3);
	
	//	Crappy No Results "err:" handling.  Will be fixed someday, maybe...
	if(substr($strResultsClean,0,3) == "err"){
		print "<H3>No match for your search!</H3>\n";
		print "<P>\n\t<STRONG>User:</STRONG> Please try adjusting the search criteria and/or changing the words.\n</P>";
	};
	
	$i++;
endwhile;
/******************************************/	
			
$i = $intPageOffset + $intPageOffsetCorrect;
while(substr($aryResults[$i],0,1) != "#" && substr($aryResults[$i],0,3) != "err" && $aryResults[$i] != "" && $aryResults[$i] != "." && $i <= $intPageOffset + $intPageOffsetCorrect + $intMaxHits):

	$strResultsClean = $aryResults[$i];
//	if (substr($strResultsClean,0,1) != "#" && substr($strResultsClean,0,3) != "err"){
//	if (!ereg("^#.*",$strResultsClean) && !ereg("^e.*",$strResultsClean) && $i >= $intPageOffset){

		//$strResultsClean String Format:
		// <RANK> <URL> "<TITLE>" <SIZE>
	
		// Array exploded on Double-Quote ("):
		// [RANK URL :0][TITLE:1][ SIZE:2] 
		/* Take note of evil whitespace in the array values,
		** which must be trimmed later.*/
		$aryResultLine = explode("\"", $strResultsClean);
				
		// Get rank from the first field
		$intResultRank =  trim($aryResultLine[0]);
		$strResultURL = ereg_replace($strSiteRootDir, "", trim($aryResultLine[1]));

		$strResultURL = ereg_replace("/docs/", "", $strResultURL);

		$strResultTitle = trim($aryResultLine[2]);
		$intResultBytes = trim($aryResultLine[3]);

		/* Determine the name of the file  */
		$strCurrentFile = $strSiteRootDir.$strResultURL ;

		/* Get file modified date-time  */
		if (file_exists($strCurrentFile)){
			$strResultModDate = gmdate("\M\o\d\i\f\i\e\d \a\\t H:i:s, \o\\n M d, Y \G\M\T", filemtime($strCurrentFile));
		}



		print "\t<DT><A href=\"$strBaseURL$strResultURL\">$strResultTitle</A>\n";
		print "\t\t<DD>";
		fncDebug("Current File", $strCurrentFile, 4);

		$j=4;
		while($aryResultLine[$j]):
			/* Grab properties from config file  */
			list ($strMetaName, $strLineHeading) = explode("|",$aryMetaList[$j-4]);
			print $strLineHeading . $aryResultLine[$j] . "\n\t\t<DD>";
		$j++;
		endwhile;

		print "<SPAN style=\"Font-Size: 75%; Font-Weight:900;\">Score: $intResultRank, Size: $intResultBytes Bytes";

		If($strResultModDate) print ", $strResultModDate</SPAN>\n";
	$i++;
endwhile;

If ($intNumHits > 0) {print "</DL>\n";}

// Print out the Previous and Next buttons
If ($intNumHits > $intMaxHits) {
	print "<TABLE>\n<TR>\n";
	If ($intMaxHits < $intMaxHitsOffset){
		print "\t<TD>\n";
	    $intPrevVal = $intMaxHitsOffset - (2 * $intMaxHits);
		print "\t<FORM action=\"$strSelf\" method=\"POST\" name=\"frmPrev\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"do\" value=\"now\">\n";
/*
** Bug Fix JB: Parenthesis July 13, 1999
**		print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"". stripslashes($words) ."\">\n";
*/
		print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"".stripslashes(str_replace('"','',$words)) ."\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"strSearchSiteKey\" value=\"" . stripslashes($strSearchSiteKey) . "\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"intMaxHits\" value=\"$intMaxHits\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"intPageOffset\" value=\"$intPrevVal\">\n";
			// Print out Search delimiters to hidden fields.
			reset ($arySearchDelimiter);
			while (list($key,$val) = each($arySearchDelimiter)) {
				if (strstr($strLimit,$val)){print "\t\t<INPUT type=\"HIDDEN\" name=\"aryLimits[]\" value=\"$val\">\n";};
			};
		print "\t\t<INPUT type=\"SUBMIT\" name=\"prev$intMaxHits\" value=\"&lt;&lt; Previous $intMaxHits\">\n";
		print "\t</FORM>\n";
		print "\t</TD>\n";
	};

	If ($intNumHits > $intMaxHitsOffset){
	    if ( ( $intNumHits - $intPageHitsThru ) < $intMaxHits ) {
		    $intNextVal = ( $intNumHits - $intPageHitsThru );
		} else {
		    $intNextVal = $intMaxHits ;
		}
		print "\t<TD>\n";
		print "\t<FORM action=\"$strSelf\" method=\"POST\" name=\"frmNext\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"do\" value=\"now\">\n";
/* 
** Bug Fix JB: Parenthesis July 13, 1999
**		print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"". stripslashes($words) ."\">\n";
*/
		print "\t\t<INPUT type=\"HIDDEN\" name=\"words\" value=\"".stripslashes(str_replace('"','',$words)) ."\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"strSearchSiteKey\" value=\"" . stripslashes($strSearchSiteKey) . "\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"intMaxHits\" value=\"$intMaxHits\">\n";
		print "\t\t<INPUT type=\"HIDDEN\" name=\"intPageOffset\" value=\"$intMaxHitsOffset\">\n";
			// Print out Search delimiters to hidden fields.
			reset ($arySearchDelimiter);
			while (list($key,$val) = each($arySearchDelimiter)) {
				if (strstr($strLimit,$val)){print "\t\t<INPUT type=\"HIDDEN\" name=\"aryLimits[]\" value=\"$val\">\n";};
			};
		print "\t\t<INPUT type=\"SUBMIT\" name=\"next$intNextVal\" value=\"Next $intNextVal &gt;&gt;\">\n";
		print "\t</FORM>\n";
		print "\t</TD>\n";
	};
	print "\t</TR>\n</TABLE>\n";
};	
//Print the footer and exit
$intTimeComplete = time() - $intTimeBegan;
If ($intTimeComplete < 1){$intTimeComplete = "less than 1 second";}
Else {$intTimeComplete = $intTimeComplete." seconds";};
fncPrintFooter("<P>Search completed in $intTimeComplete.");
?>
