//rep.php
//Description: Search a tab delimited file of federation representatives,
//Date: 1/18/2012
//Author: Andy Angrick
//Email: angrick1@cgiscript.net
$action= $_REQUEST["action"];
(!$action)&&(ShowForm());
($action == 'search')&&(Search());
($action == 'test')&&(Test());
function Test(){
print "This is a test";
exit();
}
function ShowForm(){
$rep = new Rep();
$rep->Name = "";
$rep->Rank = "";
$rep->WarrentNo = "";
$rep->Station = "";
$rep->Email = "";
$stationopt = getStations($rep->Station);
include("repsearch2.php");
exit();
}
function getStations($station){
$stationopt='';
if(!$fd = fopen("Rep.txt","r")){
$search_table="Error opening database
";
exit();
}
$allstations = array();
while(!feof($fd)){
$match=0;
$l = fgets($fd);
$l = trim($l);
$f = split("\t",$l);
$allstations[$f[3]]=1;
}
ksort($allstations);
foreach ($allstations as $key => $value)
{
if($key){
($key == $station)?($sel='selected'):($sel='');
$stationopt .= "";
}
}
fclose($fd);
return $stationopt;
}
function Search(){
$rep = new Rep();
$rep->Name = scrub($_REQUEST['Name']);
$rep->Rank = scrub($_REQUEST['Rank']);
$rep->WarrantNo = scrub($_REQUEST['WarrantNo']);
$rep->Station = scrub($_REQUEST['Station']);
$rep->Email = scrub($_REQUEST['Email']);
$stationopt = getStations($rep->Station);
//print_r($rep);
if(!$fd = fopen("Rep.txt","r")){
$search_table="Error opening database
";
exit();
}
while(!feof($fd)){
$match=0;
$l = fgets($fd);
chop($l);
$f = split("\t",$l);
$Name=preg_replace("/[^A-Za-z0-9 ,]/","",$f[0]);
$Rank=$f[1];
$WarrantNo=$f[2];
$Station=$f[3];
$Email=$f[4];
if($Name == 'Name'){
continue;
}
if($rep->Name){
$names = split(", *",strtoupper($Name));
//print "L:" . $names[0] ."\n";
//print "F:" . $names[1] ."\n";
$snames = split(" ",strtoupper($rep->Name));
$sname = trim($snames[1].$snames[0]);
$name = trim($names[0].$names[1]);
//print "M1:" . $sname ."-".$name."\n";
//print "M2:" . $sname ."-".$names[0]."\n";
//print "M3" . $sname ."-".$names[1]."\n";
$match=0;
if(preg_match("/".$sname."/",$name)){
$match=1;
}
if(preg_match("/".$sname."/",$names[0])){
$match=1;
}
if(preg_match("/".$sname."/",$names[1])){
$match=1;
}
if(!$match){
continue;
}
}
if($rep->Rank){
if(!preg_match("/".strtoupper($rep->Rank)."/",strtoupper($Rank))){
continue;
}
}
if($rep->WarrantNo){
if(!preg_match("/".strtoupper($rep->WarrantNo)."/",strtoupper($WarrantNo))){
continue;
}
}
if($rep->Station){
if(!preg_match("/".strtoupper($rep->Station)."/",strtoupper($Station))){
continue;
}
}
$line .= "
Search Results... | ||||
Name | Rank | Warrant No | Station |
---|