<TITLE>Leptospira Search Results</TITLE>

<!
includeFile("body.html");
includeFile("../text&html/head.html");
>

<CENTER>
<FONT SIZE=5 FACE="Arial, Helvetica" COLOR="#000099">Leptospira Home page -Lepto Library
<BR></FONT><FONT SIZE=4 COLOR="#000099" FACE="Arial, Helvetica">
(Leptospira search results:)
</FONT></CENTER>

<!

$n = 0;
$start=(int)$start;
if ($start==0) {
   $start=1;
   }
$maxitems=(int)$maxitems;

/*- ---------------------------------------------------------------------- -*/
/*- Take arguments sent by WWW client, and create valid SQL SELECT query   -*/
/*- ---------------------------------------------------------------------- -*/

$sarch="";

$max=4;
$upit="maxitems=" + (char)$maxitems + "&database=$database";
$rr=0;
while($rr<$max) {
   $cu=$co[$rr];
   $upit=$upit + "&co=" + $cu;
   $how=$like[$rr];
   $upit=$upit + "&like=" + $how;
   $srch=msqlEncode($search[$rr]);
   $upit=$upit + "&search=" + $srch;
   $sel=(int)$field[$rr];
   $upit=$upit + "&field=" + (char)$sel;
   $serch="";
   if ($srch!="") {
      $ll="%";
      if ($how=="=") {
         $ll="";
         }
      if ($sel==0) {
         $serch=$serch + "(AU " +  $how + " '" + $ll + $srch + $ll + "'";
         $serch=$serch + " OR AD " +  $how + " '" + $ll + $srch + $ll + "' OR TI " + $how + " '" + $ll + $srch + $ll + "' OR SO " + $how + " '" + $ll + $srch + $ll + "')";
         }
      if ($sel==1) {
         $serch=$serch + "TI " + $how + " '" + $ll + $srch + $ll + "'";
         }
      if ($sel==2) {
         $serch=$serch + "AB " + $how + " '" + $ll + $srch + $ll + "'";
         }
      if ($sel==3) {
         $serch=$serch + "AU " + $how + " '" + $ll + $srch + $ll + "'";
         }
      if ($sel==4) {
         $serch=$serch + "SO " + $how + " '" + $ll + $srch + $ll + "'";
         }
      }
   $rr=$rr + 1;

   if ($sarch!="") {
      if ($serch!="") {
         $serch=$cu + " " + $serch;
         }
      }
   if ($serch!="") {
      $sarch=$sarch + " " + $serch;
      }
   }

echo("<HR><FORM>\n");
echo("To retrieve individual references click on a highlighted link,");
echo("or select a group of references by clicking the checkbox. To retrieve all references simply
click on the retrieve selected references button.;");
echo("<INPUT NAME=\"test\" TYPE=\"checkbox\" CHECKED>");
echo(") and than click to \"Retrieve Selected References\" button");
echo("</FORM><HR>\n");

if ($sarch=="") {
   echo("<CENTER>You should at least specify one search field.\n");
   echo("</TD></TR></TABLE>\n");
   exit(0);
   }
else {
   $sarch="WORK=$database AND " + $sarch;
   }

/*- ---------------------------------------------------------------------- -*/
/*- Open connection to database and SELECT data from tables		   -*/
/*- ---------------------------------------------------------------------- -*/
        $sock = msqlConnect();
        if ($sock < 0) {
                printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
                fatal("");
           }
        if (msqlSelectDB($sock,"leptospira") < 0) {
                printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
                fatal("");
           }


$srch="SELECT DISTINCT UI, TI, AU, DP, SO FROM leptospira WHERE $sarch";

/*- ---------------------------------------------------------------------- -*/
/*- Connected to mSQL server, now try to send SELECT query to database     -*/
/*- ---------------------------------------------------------------------- -*/
if (msqlQuery($sock, $srch)<0) {
   printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
   fatal("");
   } 
$pap=msqlStoreResult();

$n=msqlNumRows($pap);

if ($n == 0) {
   echo("<CENTER>Sorry, can not find any matching data.</CENTER><BR>\n");
   echo("</TD></TR></TABLE>\n");
   exit(0);
}

/*
if (msqlQuery($sock, "SELECT _seq FROM upiti")<0) {
   printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
   fatal("");
   } 
$pa=msqlStoreResult();
$sq=msqlFetchRow($pa);
msqlFreeResult($pa);
$serial=$sq[0];
if (msqlQuery($sock, "INSERT INTO upiti VALUES ($serial, '$upit', $n)")<0) {
   printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
   fatal("");
   } 

if (msqlQuery($sock, "SELECT _seq FROM temp_dbs")<0) {
   printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
   fatal("");
   }
$pa=msqlStoreResult();
$sq=msqlFetchRow($pa);
msqlFreeResult($pa);
$dbs=(int)$sq[0];
if ($dbs>20) {
   $dbs=0;
   if (msqlQuery($sock, "DROP SEQUENCE FROM temp_dbs")<0) {
      printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
      fatal("");
      } 
   if (msqlQuery($sock, "CREATE SEQUENCE ON temp_dbs STEP 1 VALUE 1")<0) {
      printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
      fatal("");
      } 
   }

if (msqlQuery($sock, "UPDATE temp_dbs SET serial=$serial WHERE rbr=$dbs")<0) {
   printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
   fatal("");
   }

$tbl="dbs_" + (char)$dbs;

if (msqlQuery($sock, "DELETE FROM $tbl")<0) {
   printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
   fatal("");
   } 
*/

$all="";

echo("<FORM ACTION=\"listall.msql\" METHOD=\"POST\">");
$end=$start + $maxitems;
if ($end>$n) {
   $end=$n;
   }

echo("<CENTER>\n(References: <B>$start</B>-<B>$end</B> of <B>$n</B>)<P>\n<TABLE WIDTH=580 COLSPAN=3 BORDER=0>\n");

if ($start>1) {
   msqlDataSeek($pap, $start - 1);
   }

$data=msqlFetchRow($pap);
$nu=0; $out=0;
while(#$data>0) {
   $nn=$start + $nu;
   echo("<TR><TD VALIGN=TOP>$nn.</TD><TD WIDTH=20 VALIGN=TOP ALIGN=RIGHT><INPUT VALUE=\"$data[0]\" NAME=\"selected\" TYPE=\"checkbox\"></TD>\n");
   $all=$all + $data[0] + ",";
   printf("<TD><A HREF=\"listall.msql?selected=%s\">", $data[0]);
   echo("$data[1], $data[2]");
   echo("</A><BR>\n");
   echo("</TD></TR>\n");

   $nu=$nu + 1;
   if ($nu>=$maxitems) {
      $data="";
      }
   else {
      $data=msqlFetchRow($pap);
      if (#$data==0) {
         $out=1;
         }
      }
   }

msqlFreeResult($pap);

   echo("</TABLE><BR VALIGN=CENTER>\n");

   echo("<HR>\n");

   echo("<TABLE><TR><TD>\n");

   if ($start>1) {
      $ty=$start - $maxitems;
      echo("<A HREF=\"search.msql?start=$ty&$upit\"><IMG SRC=\"../pictures/previous.gif\" BORDER=0></A>\n");
      }
   echo("<INPUT TYPE=\"submit\" VALUE=\"Retrieve Selected References\">\n");
   echo("<INPUT TYPE=\"reset\" VALUE=\"Clear Selections\">\n");
   $start=$start + $maxitems;
   if ($out==0) {
      echo("<A HREF=\"search.msql?start=$start&$upit\"><IMG SRC=\"../pictures/next.gif\" BORDER=0></A>\n");
      }
   echo("</TD></TR></TABLE>");

   $all=chop($all);
   echo("<INPUT TYPE=\"HIDDEN\" NAME=\"all_references\" VALUE=\"$all\">\n");

   echo("</FORM>\n");

msqlClose($sock);

includeFile("../text&html/to-top1.txt");
>

</CENTER>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>
