Location: PHPKode > projects > Taxonomic Search Engine > main.php
<?php

session_start();
if (!isset($_SESSION['start']) )
{
	$_SESSION['start']		= true;
}
else
{
	$_SESSION['start']	= false;
}
	

$search_string = trim($_GET['taxon_name']);

if (($search_string == '') || (!isset($search_string)))
{
	$search_string = "Apus apus";
	$_SESSION['start']	= true;
}

//$not_set = true;

$suggest_spelling = $_GET['spelling'];

header('Content-Type: text/html; charset=utf-8');



require_once("config.inc.php");
require_once("lib.xml.inc.php");
require("Net/HTTP/Client.php");
require_once("nusoap.php");
require_once("XPath.class.php");
require_once("xslt.php");


include ("agrep.php");

include("wrapper.php");
include("itis_wrapper.php");
include("funindex_wrapper.php");
include("ipni_wrapper.php");
include("ubio_wrapper.php");
include("ncbi_wrapper.php");

//include ("google.php");


if ($_SESSION['start']==false)
{
	// uncomment this to use Google spelling
	//$alternative_spelling = GoogleSpelling ($search_string);
	$alternative_spelling = "";
	
	// approximate string matching
	//agrep ('namelist.txt', $search_string, $approx_match);





// Test servers

// 1. Create wrappers
$itis = new ITISWrapper;
$fundex = new FunindexWrapper;
$ipni = new IPNIWrapper;
$ubio = new uBioWrapper;
$ncbi = new NCBIWrapper;

// 2. Test for service availability
//echo "<p/>ITIS is ", $itis->IsAlive() ? "alive" : "dead", "<br/>";
//echo "IndexFungorum is ", $fundex->IsAlive() ? "alive" : "dead", "<br/>";
//echo "IPNI is ", $ipni->IsAlive() ? "alive" : "dead", "<br/>";

//$search_string = "Monilinia fructicola";


// Build a search result
$search_result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$search_result .= "<NameSearchResults>";

// ITIS
if (1)
{
	$tmp = $itis->NameSearch($search_string,1);
	// Strip XML header
	$search_result .= preg_replace ("/<\?xml(.*?)\?>/", "", $tmp);
}

// IndexFung
//if (isset($include_IF))
if (1)
{
	$tmp = $fundex->NameSearch($search_string, EXACT, 1);
	// Strip XML header
	$search_result .= preg_replace ("/<\?xml(.*?)\?>/", "", $tmp);
}


// IPNI
if (1)
{
	$tmp = $ipni->NameSearch($search_string,1);

	// Strip XML header
	$search_result .= preg_replace ("/<\?xml(.*?)\?>/", "", $tmp);
}


// uBio
if (1)
{
	$tmp = $ubio->NameSearch($search_string,1);

	// Strip XML header
	$search_result .= preg_replace ("/<\?xml(.*?)\?>/", "", $tmp);
}

// NCBI
if (1)
{
	$tmp = $ncbi->NameSearch($search_string,1);

	// Strip XML header
	$search_result .= preg_replace ("/<\?xml(.*?)\?>/", "", $tmp);
}

$search_result .= "</NameSearchResults>";

//echo $search_result;

// Make pretty HTML report

}
?>

<html>
<head>
<title>Taxonomic Search Engine</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


<!-- Code from http://www.xs4all.nl/~peterned/csshover.html to
 add hover to elements other than <a> to IE. -->

<!--[if gte IE 5]>
	<style type="text/css">
		body {
			behavior:url("scripts/csshover.htc");
		}
	</style>
<![endif]-->

<link rel="stylesheet" href="portal.css" type="text/css" media="screen" />
<link rel="stylesheet" href="xmlverbatim.css" type="text/css" media="screen" />
</head>
<body>

<h1>Taxonomic Search Engine</h1>
<h2>Federating taxonomic databases using web services</h2>
<?php include("top.inc.php"); ?>

<!-- Begin Nedstat Basic code -->
<!-- Title: Taxonomic Search Engine -->
<!-- URL: http://darwin.zoology.gla.ac.uk/~rpage/portal/ -->
<script language="JavaScript" type="text/javascript" src="http://m1.nedstatbasic.net/basic.js">
</script>
<script language="JavaScript" type="text/javascript" >
<!--
  nedstatbasic("AC/H2g3jCxZMf+3awDPCJ3LzSyzA", 0);
// -->
</script>
<noscript>
<a target="_blank" href="http://www.nedstatbasic.net/stats?AC/H2g3jCxZMf+3awDPCJ3LzSyzA"><img
src="http://m1.nedstatbasic.net/n?id=AC/H2g3jCxZMf+3awDPCJ3LzSyzA"
border="0" width="18" height="18"
alt="Nedstat Basic - Free web site statistics
Personal homepage website counter"></a><br>
<a target="_blank" href="http://www.nedstatbasic.net/">Free counter</a>
</noscript>
<!-- End Nedstat Basic code -->


</h3>
</td>
</tr>
</table>




<!--<p><a href="html">Code documentation</a></p>-->

<script language = "JavaScript">
	function validateSearchForm (form)
	{
		// Required fields for all references
		if (form.taxon_name.value == "")
		{
			alert ("Please enter the name of a taxon.");
			form.taxon_name.focus();
			return false;
		}
		return true;
	}
</script>


<form id= "fsearch" name="search" method="GET" action="main.php" onSubmit="return validateSearchForm(this)">
  Search for
  <input name="taxon_name" type="text" id="taxon_name" size="32" value="<?php echo $search_string;?>" />
  <input type="submit" name="Submit" value="Go" /><br/>
 <input name="spelling" type ="checkbox" value="yes" <?php if ($suggest_spelling == 'yes') echo " checked"; ?> />Suggest alternative spellings?

</form>




<?php


// Alternative spelling(s)
if ($suggest_spelling == 'yes')
{
	$parameters = array(
		'search_string'=> $search_string);
	
			
	// Create SOAP client from WSDL
	$soapclient = new soapclient('http://darwin.zoology.gla.ac.uk/~rpage/portal/TSE.php#wsdl');

	$soapclient->debug_flag=true;


	$result = $soapclient->call(
		'SpellingSuggestion',
		$parameters);
		
	if (is_array($result))
	{
		// We have at least one suggestion...
					
		// Have we got the search string in the list of suggestions?
		$spellings = count($result);
		if ($spellings > 0)
		{
			if (in_array($search_string, $result))
			{
				$spellings--;
			}
			if ($spellings > 0)
			{
				echo "<p><b><font color=\"red\">Did you mean:</font></b>";
				foreach ($result as $suggestion)
				{
					if ($suggestion != $search_string)
					{
						echo "&nbsp;<a href=\"main.php?taxon_name=",
							urlencode($suggestion);
							
						if ($suggest_spelling == 'yes')
						{
							echo "&amp;spelling=yes";
						}
							
						echo  "\">$suggestion</a>";	
					}
				
				}
				echo "</p>";
			}
		}
	}
		
}



if ($_SESSION['start']==false)
{

echo "<p>Click on a result below to see full details in the lower frame</p>";

		$xslt_file = "xsl/table.xsl";
		if ($config['sabcmd'] != '')
		{
			// Transform using external sablot processor
			$xpresult = XSLT_Buffer ($search_result, $xslt_file);
		}
		else
		{
			// Use XSLT extension
			$xslt_processor = xslt_create();
			$xslt = join ("", file($xslt_file));
			$arg_buffer = array("/xml" => $search_result, "/xslt" => $xslt);
			$xp = xslt_create() or die ("Could not create XSLT processor");
			if (!($xpresult = xslt_process($xp, "arg:/xml", "arg:/xslt", NULL, $arg_buffer)))
			{
				echo "An error occurred: " . xslt_error($xp) . "(error code " . xslt_errno($xp) . ")";
			}
			xslt_free($xp);
		}		
		echo $xpresult;
		
/*		// Performance
		echo "<p></p>";
		
		$xslt_file = "xsl/performance.xsl";
		if ($config['sabcmd'] != '')
		{	
			// Transform using external sablot processor
			$xpresult = XSLT_Buffer ($search_result, $xslt_file);
		}
		else
		{
			// Use XSLT extension
			$xslt_processor = xslt_create();
			$xslt = join ("", file($xslt_file));
			$arg_buffer = array("/xml" => $search_result, "/xslt" => $xslt);
			$xp = xslt_create() or die ("Could not create XSLT processor");
			if (!($xpresult = xslt_process($xp, "arg:/xml", "arg:/xslt", NULL, $arg_buffer)))
			{
				echo "An error occurred: " . xslt_error($xp) . "(error code " . xslt_errno($xp) . ")";
			}
			xslt_free($xp);
		}		
		echo $xpresult;
*/		

}

$_SESSION['start']==false;

?>



<hr noshade/>

<!-- this is where we update the taxon info via Javascript in get.php -->
<div id="contentDiv">
</div>

</body>
</html>

Return current item: Taxonomic Search Engine