<TITLE>Leptospira Search Results</TITLE>

<!
includeFile("body.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;
$maxitems=(int)$maxitems;

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

$srch_lept="";
$srch_auth="";
$srch_mesh="";
$srch_addr="";

$max=3;
$upit="maxitems=" + (char)$maxitems;
$rr=0;
while($rr<$max) {
   $cu=$co[$rr];
   $upit=$upit + "&co=" + $cu;
   if ($cu!="") {
      $cu=" " + $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;
   if ($srch!="") {
      $ll="%";
      if ($how=="=") {
         $ll="";
         }
      if ($sel==0) {
         $srch_addr=$srch_addr + $cu + "AD " +  $how + " '" + $ll + $srchh + $ll + "'";
         $srch_mesh=$srch_mesh + $cu + "MH " +  $how + " '" + $ll + $srchh + $ll + "'";
         $srch_lept=$srch_lept + $cu + "(TI " + $how + " '" + $ll + $srchh + $ll + "' OR SO " + $how + " '" + $ll + $srch + $ll + "')";
         }
      if ($sel==1) {
         $srch_lept=$srch_lept + $cu + "TI " + $how + " '" + $ll + $srchh + $ll + "'";           
         }
      if ($sel==3) {
         $srch_mesh=$srch_mesh + $cu + "MH " + $how + " '" + $ll + $srch + $ll + "'";
         }
      }
   $rr=$rr + 1;
   }

echo("Search:<BR>\n");
echo("$upit<BR>\n");
echo("Search string:<BR>\n");
printf("Database MESH: %s<BR>\n", $srch_mesh);
printf("Database ADDR: %s<BR>\n", $srch_addr);
printf("Database AUTH: %s<BR>\n", $srch_auth);
printf("Database LEPT: %s<BR>\n", $srch_lept);

echo("<HR><FORM>\n");
echo("To retrieve individual references for display on your screen, simply click on a highlighted link,");
echo("or you can select references that you like (like this");
echo("<INPUT NAME=\"test\" TYPE=\"checkbox\" CHECKED>");
echo(") and than click to \"Retrieve Selected References\" button");
echo("</FORM><HR>\n");


/*- ---------------------------------------------------------------------- -*/
/*- Open connection to database and SELECT data from tables		   -*/
/*- ---------------------------------------------------------------------- -*/
        $sock = msqlConnect("localhost");
        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("");
           }

        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')")<0) {
           printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
           fatal("");
           } 

exit(0);

/*- ---------------------------------------------------------------------- -*/
/*- Connected to mSQL server, now try to send SELECT query to database     -*/
/*- ---------------------------------------------------------------------- -*/

echo("<FORM ACTION=\"listall.msql\">");
echo("<CENTER><TABLE WIDTH=550 COLSPAN=3 BORDER=0>\n");

if ($srch_lept!="") {
   if (msqlQuery($sock, "select DISTINCT UI, TI, DP from leptospira where $srch_lept")<0) {
      printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
      fatal("");
      } 

   $res=msqlStoreResult();
   $row=msqlFetchRow($res);

if (#$row > 0) {
   while(#$row>0 && $maxitems>$n) {
      $n = $n + 1;
      echo("<TR><TD WIDTH=20>$n.</TD><TD WIDTH=20><INPUT VALUE=\"$row[0]\" NAME=\"selected\" TYPE=\"checkbox\"></TD>\n");


      if (msqlQuery($sock, "select AU from author where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 
      $pa=msqlStoreResult();
      $str=msqlFetchRow($pa);
      msqlFreeResult($pa);

      printf("<TD><A HREF=\"listall.msql?selected=%s\">", $row[0]);
      echo("$str[0], $row[1]");
      echo("</A><BR>\n");
      echo("</TD></TR>\n");

      $row=msqlFetchRow($res);    
   }

} 
msqlFreeResult($res);

}

if ($srch_addr!="") {
   if (msqlQuery($sock, "select DISTINCT UI from address where $srch_addr")<0) {
      printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
      fatal("");
      } 

   $res=msqlStoreResult();
   $row=msqlFetchRow($res);

if (#$row > 0) {
   while(#$row>0 && $maxitems>$n) {
      $n = $n + 1;
      echo("<TR><TD WIDTH=20>$n.</TD><TD WIDTH=20><INPUT VALUE=\"$row[0]\" NAME=\"selected\" TYPE=\"checkbox\"></TD>\n");

      if (msqlQuery($sock, "select DISTINCT TI, DP from leptospira where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 

      $lpt=msqlStoreResult();
      $lept=msqlFetchRow($lpt);
      msqlFreeResult($lpt);

      if (msqlQuery($sock, "select AU from author where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 
      $pa=msqlStoreResult();
      $str=msqlFetchRow($pa);
      msqlFreeResult($pa);

      printf("<TD><A HREF=\"listall.msql?selected=%s\">", $row[0]);
      echo("$str[0], $lept[0]");
      echo("</A><BR>\n");
      echo("</TD></TR>\n");

      $row=msqlFetchRow($res);    
   }
}
msqlFreeResult($res);

}

if ($srch_auth!="" ) {
   if (msqlQuery($sock, "select DISTINCT UI from author where $srch_auth")<0) {
      printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
      fatal("");
      } 

   $res=msqlStoreResult();
   $row=msqlFetchRow($res);

if (#$row > 0) {
   while(#$row>0 && $maxitems>$n) {
      $n = $n + 1;
      echo("<TR><TD WIDTH=20>$n.</TD><TD WIDTH=20><INPUT VALUE=\"$row[0]\" NAME=\"selected\" TYPE=\"checkbox\"></TD>\n");

      if (msqlQuery($sock, "select TI, DP from leptospira where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 

      $ltpt=msqlStoreResult();
      $lpt=msqlFetchRow($ltpt);
      msqlFreeResult($ltpt);

      if (msqlQuery($sock, "select AU from author where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 
      $pa=msqlStoreResult();
      $str=msqlFetchRow($pa);
      msqlFreeResult($pa);

      printf("<TD><A HREF=\"listall.msql?selected=%s\">", $row[0]);
      echo("$str[0], $lpt[0]");
      echo("</A><BR>\n");
      echo("</TD></TR>\n");
      $row=msqlFetchRow($res);    
   }
}
msqlFreeResult($res);

}

if ($srch_mesh!="" ) {
   if (msqlQuery($sock, "select DISTINCT UI from mash_heading where $srch_mesh")<0) {
      printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
      fatal("");
      } 

   $res=msqlStoreResult();
   $row=msqlFetchRow($res);

if (#$row > 0) {
   while(#$row>0 && $maxitems>$n) {
      $n = $n + 1;
      echo("<TR><TD WIDTH=20>$n.</TD><TD WIDTH=20><INPUT VALUE=\"$row[0]\" NAME=\"selected\" TYPE=\"checkbox\"></TD>\n");

      if (msqlQuery($sock, "select DISTINCT TI, DP from leptospira where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 

      $lpt=msqlStoreResult();
      $lept=msqlFetchRow($lpt);
      msqlFreeResult($lpt);


      if (msqlQuery($sock, "select AU from author where UI=$row[0]")<0) {
         printf("<BR><BR><BR><CENTER><TABLE><TR><TD><B><FONT SIZE=3>%s</FONT></TD></TR></TABLE>\n", $ERRMSG);
         fatal("");
         } 
      $pa=msqlStoreResult();
      $str=msqlFetchRow($pa);
      msqlFreeResult($pa);

      printf("<TD><A HREF=\"listall.msql?selected=%s\">", $row[0]);
      echo("$str[0], $lept[0]");
      echo("</A><BR>\n");
      echo("</TD></TR>\n");

      $row=msqlFetchRow($res);    
   }
}

msqlFreeResult($res);
}

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

if ($n == 0) {
   echo("Sorry, can not find any matching data.<BR>\n");
} else {
   echo("<HR>\n");
   echo("<INPUT TYPE=\"submit\" VALUE=\"Retrieve Selected References\">\n");
   echo("<INPUT TYPE=\"reset\" VALUE=\"Clear Selections\">\n");
   echo("<HR>\n");
   echo("</FORM>\n");
}


>

</BODY>
</HTML>

</BODY>
