// First take care that the entry is correct or return the errors!
//------------------------------------------------------------------------------------------------------
//In case someone is using the old NameCache parameter
if (strlen($_REQUEST['NameCache'])>0)
{
$paraname="NameCache";
}
else if (strlen($_REQUEST['taxon'])>0)
{
$paraname="taxon";
} else {
$paraname="name";
}
// Allow multiples items to be search
$arg=str_replace($paraname."=",$paraname."[]=",$_SERVER['QUERY_STRING']);
parse_str( $arg, $_REQUEST_NAME_ARRAY );
$errorcode=0;
$sql_or="";
foreach ($_REQUEST_NAME_ARRAY[$paraname] as $name){
//Add * to the end if not existing
if (substr($name,strlen($name)-(1))!="*"){
$name=$name."*";
}
//replace characters
$name=str_replace("*","%",$name);
$name=str_replace("+"," ",$name);
$name=str_replace("'","''",$name);
$sql_or=$sql_or."(Name.NameCache LIKE '".$name."') OR ";
//Error handling
if ((strpos($name,"%") ? strpos($name,"%")+1 : 0)>0 && strlen($name)<4)
{
$errorcode=1;
}
if ((strpos($name,"%%") ? strpos($name,"%%")+1 : 0)>0)
{
$errorcode=2;
}
if (substr($name,0,1)=="%" && substr($name,3,1)=="%")
{
$errorcode=3;
}
if (strlen($name)<3)
{
$errorcode=4;
}
}
if (strlen($sql_or)<4){
$errorcode=1;
} else {
//Delete the latest OR in the sql_or
$sql_or=substr($sql_or,0,strlen($sql_or)-3);
}
//-------- Here start the error handling ---------------
if ($errorcode==1)
{
?>
Input error 1. Please enter at least three letters with a wildcard
Return
} else if ($errorcode==2)
{
?>
Input error 2. Please do not enter successive wildcards
Return
} else if ($errorcode==3)
{
?>
Input error 3. Please enter at least three letters between wildcards
Return
} else if ($errorcode==4)
{
?>
Input error 4. Please enter at least three letters
Return
} else if ($strName=="What did you do in Berlin?"){
// This sentence is just for testing
print "Erasmus in Berlin 2002/2003. Viel Spass!!";
} else {
//There was no problems in the input --------
//The SQL statement changes depending a Reference is selected or not.
if ($_REQUEST['RefId']!=""){
// if a reference is selected take his name from the database
$SQL="SELECT Refcache FROM reference WHERE RefId=".$_REQUEST['RefId'];
echo " ".$SQL;
$rs=mssql_query($SQL, $dbcon);
$Rname_ref=mssql_fetch_array($rs);
$name_ref=$Rname_ref["RefCache"];
$rs=null;
// the real query
$SQL=$SQL."SELECT DISTINCT Name.NameCache AS Name FROM Name INNER JOIN PTaxon ON Name.NameId = PTaxon.PTNameFk WHERE (".$sql_or.") AND PTRefFk=".$_REQUEST['RefId']." ORDER BY Name.NameCache";
}
else
{
$SQL=$SQL."SELECT DISTINCT Name.NameCache AS Name FROM Name INNER JOIN PTaxon ON Name.NameId = PTaxon.PTNameFk WHERE ".$sql_or." ORDER BY Name.NameCache";
}
echo " ".$SQL;
$rs=mssql_query($SQL, $dbcon);
?>
echo mssql_num_rows($rs);?> names found. Click on name for details.
if ($_REQUEST['RefId']!="")
{
?>
Search restricted to: echo $name_ref;?>
} ?>
//end of the error in the input handled
} ?>
|
|