"; if ($PrintBox == "y") { print ""; //input box for the search number print "

"; //Search submit button } print ""; //Prints a hidden field with the file name in it to //be resent to this form to save the file name $SearchString = trim($SearchString); //Trims leading and ending spaces off of the search string $SearchStringLower = strtolower ($SearchString); //Get lower case search string for comparrison if ($SearchString == "") //If search number is blank print intro message { if ($PrintBox == "y") { print ("
Please enter the markings you want to research and click the submit button.

"); //stored in the data file } } elseif ( $sstrlen <= 1 && $AllowSingle == "n") //If search number is blank print intro message { if ($PrintBox == "y") { print ("
Not enough information.
"); //Print error message for short search string print ("
Please enter a search with more than 1 letter or digit.

"); } } else //If search number is not blank look it up { print (" Matches for $SearchString:

"); foreach($SNumbrs as $temp) //Searches for a match to the search string { $match = explode ("~", $temp); //Seperate the input string $match[0]=trim($match[0]); //Trim whitespace from the search string $matchLower=strtolower($match[0]); // Make all search lower case $pos = strpos ($matchLower, $SearchStringLower); //search string. if ($pos !== false ) //Compare the search string to the string from the file { $Match="y"; //If a match is found set $Match to y. //$printout = trim($RString $match[0]$match[2]); $p1 = substr($match[0],0,$pos ); //Break apart the results so search can be bolded $p2 = substr($match[0],$pos, $sstrlen); //$p2 = $p2 . " "; $p3 = substr($match[0],($pos+$sstrlen)); $printout = "$p1$p2$p3"; //print "$RString $match[0] $match[2].
"; if($match[2]=="") // Fix output so that there is not a space infront of { // the period at the end of the results if $match[2] is empty. print "$printout.
"; } else { print "$printout $match[2].
"; } //break; //Leave the search loop after a match is found. } // Comment this out for multiple matches. } if ($Match == "n"){ //If no match is found print no match message. if ($PrintBox == "y") { //print "No match was found for $SearchString."; print "None"; } } } print ""; } //Function prints a lookup input text box and a submit button, and requires 5 parameters: //1. $file - This is the data file that contains the dates and serial numbers. //2. $from - The name of the form to call when the submitt buttin is clicked. This can // be left blank and the form will recall itself. //3. $SearchString is provided when a number is provided in the text box and submit // is clicked. If blank the opening screen is printed. //4. $Case - Should be blank u or l if set to u all search input is changet to upper case. // if set to l all search input is set to lower case. If blank search input case is not is changed. //5. $RString - String to print for the results message. //If the search number is matched function prints out the results function MatchString($file, $form, $SearchString, $Case, $RString) { $Match="n"; //Switch that is set to y if a match is found. $file = trim ($file); //trim leading and trailing spaces from data file name $InFile = "data/$file"; //adds data directory path to file name. $fnl=strlen ($file); //Get length of the input file. $sstrlen = strlen ($SearchString); //Get length of the input file. $fp=fopen($InFile,'r') or die("Could not open $InFile"); // Opens data file for read. while ( ! feof($fp)) { $line=fgets($fp,1024); //Read in datafile one line at a time, stores data in the $line array $line = str_replace ("\",\"", "~", "$line"); //Replaces "," with ~ $line = str_replace ("\"", "", "$line"); //Replaces " with nothing //search, replace, subject if (trim($line)!="") //Store strings to be searched in $SNumbrs if the line is not blank { $SNumbrs[]=trim($line); //Stores each line of input in an array. } } print "
"; print ""; //input box for the search number print "

"; //Search submit button print ""; //Prints a hidden field with the file name in it to //be resent to this form to save the file name $SearchString = trim($SearchString); //Trims leading and ending spaces off of the search string if ($Case == "u") { //Changes search string to upper case is $Case is set to "u" $SearchString = strtoupper ($SearchString); } if ($Case == "l") { //Changes search string to lower case is $Case is set to "l" $SearchString = strtolower ($SearchString); } if ($SearchString == "") //If search number is blank print intro message { print ("
Please enter the markings you want to research and click the submit button.

"); //stored in the data file } else //If search number is not blank look it up { foreach($SNumbrs as $temp) //Searches for a match to the search string { $match = explode ("~", $temp); //Seperate the input string $match[0]=trim($match[0]); //Trim whitespace from the search string //$match[0]=substr($match[0], 0, $sstrlen); // Trims the match string to the same length as the //search string. if ($SearchString == $match[0] ) //Compare the search string to the string from the file { print "
$RString $SearchString = $match[2].

"; if ($match[1]!="" ) //Print additional information if the additional { //info field is not blank print "$match[1]
"; } if ($match[3]!="" ) //Print additional information if the additional { //info field is not blank print "$match[3]
"; } //if ($match[4]!="" ) //Print additional information if the additional //{ //info field is not blank //print "$match[4]
"; // } $Match="y"; //If a match is found set $Match to y. break; //Leave the search loop after a match is found } } if ($Match == "n"){ //If no match is found print no match message. print "No match was found for $SearchString."; } } print "
"; } //This function prints a select button and a model list. The function requires //three parameters: //1. a catagory the following are catagory definitions: // conversion = "c"; // hand gun = "h"; // hand gun double action = "hd"; // hand gun pocket = "hp"; // hand gun semi-auto = "hsemi"; // hand gun single action = "hs"; // long gun = "l"; // long gun bolt = "lb"; // long gun lever action = "ll"; // long gun$ pump = "lp"; // long gun semi-auto = "lsemi"; // long gun shotgun = "ls"; //2. a ModFile, which lists all modles for that brand in the following format: // file name~model~category code //mod files avaliable at this time are: // winmods.dat // milmods.dat // savmods.dat // cltmods.dat //3. a call file name, this is the file that is called when submit is pressed. // //This function sends a file name ($file) to the form that it calls. function PrintModLst($catagory, $ModFile, $CallFile) { $i=0; $fp=fopen($ModFile,'r') or die("Could not open $ModFile"); // Opens data file for read. while ( ! feof($fp)) //Read in datafile one line at a time. { $line=fgets($fp,1024); $Mods[]=$line; //Stores each line of input in an array. } print "
"; print ""; //Prints drop down box foreach($Mods as $temp) { $pieces = explode ("~", $temp); $pieces[2]=trim($pieces[2]); if ($pieces[2] == $catagory) { $i++; if ($i==1) { print ""; } else { print ""; } } } print ""; print "



"; print "
"; } //Function prints a lookup input text box and a submit button, requires 3 parameters: //1. $file - This is the data file to search it should contain the dates and serial numbers. //2. $from - The name of the form to call when the submitt buttin is clicked. // If this is blank and the form will recall itself. //3. $SearchNumber *Should be left blank* is passed to the function when a number is entered // in the text box and the submit button is clicked. // If $SearchNumber is blank the opening screen is printed. function lookup($file, $form, $SearchNumber) { $file = trim ($file); //trim leading and trailing spaces from data file name $InFile = "data/$file"; //adds data directory path to file name. $fnl=strlen ($file); //Get length of the input file. // The following section looks up the model name form the file name in the ???mods.dat file and // and prints it out in the results screen. $type = substr ($file, 0,3); if ($type == "win") { //Sets brand to Winchester. $ModFile = "mods/winmods.dat"; //adds data directory path to file name. $Brand = "Winchester"; } elseif ($type == "us_") { //Sets brand to U.S Military. $ModFile = "mods/milmods.dat"; //adds data directory path to file name. $Brand = "U.S. Military"; } elseif ($type == "brm") { //Sets brand to Mauser Pistol C-96 (Broomhandle). $ModFile = "mods/singlemod.dat"; //adds data directory path to file name. $Brand = "Mauser Pistol C-96 (Broomhandle)"; } // singlemod.dat is used if there is no modifle for this selection. elseif ($type == "mar") { //Sets brand to "Marlin". $ModFile = "mods/singlemod.dat"; //adds data directory path to file name. $Brand = "Marlin"; // singlemod.dat is used if there is no modifle for this selection. } else { //Sets brand to blank. $ModFile = "mods/singlemod.dat"; //adds data directory path to file name. $Brand = ""; //This selection should be used if a brand name is not desired. }; // singlemod.dat is used if there is no modifle for this selection. $fp=fopen($ModFile,'r') or die("Could not open $ModFile"); // Opens correct mods data file for read. while ( ! feof($fp)) //Read in datafile one line at a time. { $line=fgets($fp,1024); if ($file == substr ($line, 0,$fnl)) { $NameLine = $line; } } $Name = explode ("~", $NameLine); ///////////////////// End of brand lookup section. // The following code looks up a searial number match and prints out the results. $fp=fopen($InFile,'r') or die("Could not open $InFile"); // Opens data file for read. while ( ! feof($fp)) { $line=fgets($fp,1024); //Read in datafile one line at a time, stores data in the $line array $line = str_replace ("\",\"", "~", "$line"); //Replaces "," with ~ $line = str_replace ("\"", "", "$line"); //Replaces " with nothing if (trim($line)!="") //Store serial numbers to be searched in $SNumbrs if the line is not blank { $SNumbrs[]=trim($line); //Stores each line of input in an array. } } $size = count ($SNumbrs); //Get how many serial numbers are in the array. $size = ($size-1); //Subtract 1 because array numbers start with 0 $first = explode ("~", $SNumbrs[0]); //Store the first serial number in $first $last = explode ("~", $SNumbrs[$size]); //Store the lste serial number in $last $last[0]=trim($last[0]); //Remove leading & trailing whitspace from $last if(!is_numeric ($first[0])) //Check to see if the first item in the data file is a number. { //If not a number it means that this model was not numbered. print ("$Brand $Name[1]:


$first[3]
$first[2]
"); //Prints out information from position #4 in the data file // if the model is not numbered. } else // If the model is numbered the following matches the serial number and prints out the results. { print "
"; print ("$Brand $Name[1]:
Covering numbers: $first[0] - $last[0].

"); //Prints out first and last numbers contained in the data file. print ""; //Prints the input box for the search number. print "

"; //Prints the search submit button. print ""; //Prints a hidden field with the file name in it so it will be passed //when the form again (saves state). $SearchNumber = trim($SearchNumber); //Trims leading and ending spaces off of the search number // The following is for error testing. if ($SearchNumber == "") { print ("
Please enter a serial number and click the submit button.

"); } //If search number is blank print intro message. elseif(!is_numeric ($SearchNumber)) { print ("
The search entered contins letters please only enter numbers

"); } //Check to see if the search entered is a number if not print error message. elseif($SearchNumber < $first[0]) { print ("
The number etered is outside the range stored in our database (low)

"); } //If search number is low print error message. elseif($SearchNumber > $last[0]) { print ("
The number etered is outside the range stored in our database (high)

"); } //If search number is high print error message else //If search number passes error tests look it up { foreach($SNumbrs as $temp) //Searches for a match to the serial number or { //to see of the search number is exceeded if($match == "") //$match will be blank of the first iteration of the loop { $matchP = explode ("~", $temp); //$matchP saves data from the previous } //iteration of the loop so it can be printed when //the match is equaled or exceded. On the first //iteration of the loop $matchP will be blank, this loads //the correct information into $matchP so it will not be //blank if the serail number is matched on the first // iteration of the loop. else { //Saves information from $match for printing. $matchP = $match; }; $match = explode ("~", $temp); //Seperate the input string $match[0]=trim($match[0]); //Trim whitespace from the serial number settype($match[0], "integer"); //Set the serial number veriable to an integer if($SearchNumber != $last[0]) //Subtracts 1 from the match number unless it is tha { // last number in the file so years will not be off $match[0]=$match[0]-1; // off by one number } if ($SearchNumber <= $match[0] ) //Compare the serial number to the search number { print "
The year of manufacture for serial number $SearchNumber is $matchP[2].

"; // Print the results when $match equeals or exceeds the search number. Field 2 is the year field. if ($matchP[1]!="" ) //Print month information if the field is not blank { print "$matchP[1]
"; } if ($matchP[3]!="" ) //Print the comments field if it is not blank. { print "$matchP[3]
"; } break; //Leave the search loop after a match is found } } } print "
"; } } ?>