<?php include 'template_sup.php' ?>
<?php include 'Connections/conn.php' ?>
<? 
//First check if the database has the Selectable attribute in the references to only select those references.
//--------------------------------------------------------------------------------------------------------------------------
$SQL="SELECT sysobjects.name AS Exp1 FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id WHERE (sysobjects.name LIKE 'Reference') AND (syscolumns.name LIKE N'Selectable')";
echo "<br>".$SQL;
$rs=mssql_query($SQL, $dbcon);
if (mssql_num_rows($rs)>0) {
  $SelectableColExist=true;
} else {
  $SelectableColExist=false;
} 


//I create a different SQL depending if the Visible column exist or not in the database
if ($SelectableColExist==true){
  $SQL="SELECT RefCache, RefId FROM dbo.Reference WHERE  (Selectable = 1)";
} else {
  $SQL="SELECT DISTINCT RefCache, RefId FROM dbo.Reference INNER JOIN dbo.PTaxon ON Reference.RefId = PTaxon.PTRefFk";
} 
//--------------------------------------------------------------------------------------------------------------------------
//Select all the available sources to present into the Reference box
echo "<br>".$SQL;
$rs=mssql_query($SQL, $dbcon);
?>

                <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
                  <TBODY>
                    <TR>
                      <TD vAlign=center width=5><IMG
                  height=19 alt=""
                  src="images/woodsDayLink.gif" width=17
                  border=0> </TD>
                      <TD noWrap><B>Search!</B></TD>
                      <TD width="100%"> <HR SIZE=1> </TD>
                    </TR>
                  </TBODY>
                </TABLE>
                <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
                  <TBODY>
                    <TR>
                      <TD width=1>&nbsp;</TD>
                      <TD width="100%">
                        <TABLE cellPadding=1 width="100%">
                          <TBODY>
                            <TR>
                              <TD vAlign=top> <p> Fill in the empty field in order
                                  to query the database for a specific name. Use
                                  the asterisk (*) as a wild card (e.g. Abi* will
                                  find all names starting with Abi, Abies alba
                                  * will find the names of subspecies etc. of
                                  Abies alba, *aaa* will find all names containing
                                  triple a, and Ab*ba will find Abies alba etc.).
                                  The input must contain at least three letters.
                                  The search is only on the name itself, so please
                                  do not include authorship or year of publication.
                                </p>
                                <p>Search for a botanical name like "Luzula*":</p>
                                <form name="form1" method="get" action="results.php">
                                  <table width="68%" border="1" align="center" cellpadding="4" cellspacing="3" bordercolor="#666666" bgcolor="#F5F5F5" style="border-collapse: collapse">
                                    <tr>
                                      <td width="23%"><strong>Name:</strong></td>
                                      <td width="77%"> <div align="left">
                                          <input name="name" type="text" id="name" style="BORDER-RIGHT: #ffffff 1px groove; BORDER-TOP: #ffffff 1px groove; FONT: 10px Verdana,Geneva,sans-serif; BORDER-LEFT: #ffffff 1px groove;  COLOR: #000000; BORDER-BOTTOM: #ffffff 1px groove; HEIGHT: 17px; BACKGROUND-COLOR: #DBE3CD" size="50">
                                        </div></td>
                                    </tr>
                                    <tr>
                                      <td><strong>Select Source:</strong></td>
                                      <td><div align="left">
                                          <select name="RefId" id="RefId" style="BORDER-RIGHT: #ffffff 1px groove; BORDER-TOP: #ffffff 1px groove; FONT: 10px Verdana,Geneva,sans-serif; BORDER-LEFT: #ffffff 1px groove;  COLOR: #000000; BORDER-BOTTOM: #ffffff 1px groove; HEIGHT: 17px; BACKGROUND-COLOR: #DBE3CD">
                                          <option value="" SELECTED>----- All Sources -----</option>
<? 
  While ($Rsources=mssql_fetch_array($rs)){
?>
	<option value="<?   echo $Rsources['RefId'] ?>">
<?   if (strlen($Rsources["RefCache"])>60)
    {
   	   echo (substr($Rsources["RefCache"],0,60)." ...");
    } else {
   	   echo $Rsources['RefCache'];
    } 
?>
	</option>
<? 
} 
?>

                                          </select>
                                        </div></td>
                                    </tr>
                                    <tr>
                                      <td colspan="2"><input type="submit" name="Submit" value="Query" style="FONT: 12px Verdana,Geneva,sans-serif;"></td>
                                    </tr>
                                  </table>
                                  <p align="center">&nbsp; </p>
                                </form>
                                <p>N.B.: Do not include taxonomic authors. <br>
                                </p>
                                <p>&nbsp; </p>
                                <FONT class=small color=gray
                        size=-1>&nbsp;
                                </FONT></TD>
                              <TD vAlign=top noWrap
              align=right></TD>
                            </TR>
                          </TBODY>
                        </TABLE></TD>
                    </TR>
                  </TBODY>
                </TABLE>

<?php include 'template_inf.php' ?>