EOD; $nav = "" //."Quick Search | " ."Advanced Search" //."Settings" ."

" ."
"; $searchform = <<
Product Name (Partials acceptable)
C.A.S Number
Catalog ID


EOD; $footer = << EOD; if($action == "" || $action == "advsearch") { echo $header; echo $nav; echo $searchform; } //advance search else if($action == "advance"){ echo $header; echo $nav; echo $searchform; $sql = "SELECT * FROM mol "; if (get_magic_quotes_gpc()) { $q = stripslashes($q); } $str = mysql_real_escape_string(trim($q)); if($str==''){ $query = ""; $query_desc = " all in catalog"; } else { if ($method=='catid'){ $query = "WHERE mol_id='$str'"; $query_desc = " Catalog Number is '$str'"; } else if($method=='casno'){ $query = "WHERE cas_no LIKE '%".$str."%'"; $query_desc = "C.A.S. Number contains '$str'"; } else if($method=='formula'){ $query = "WHERE structure LIKE '%".$str."%'"; $query_desc = "Chemical Formula contains '$str'"; } else if($method=='pname'){ $query = "WHERE structure_name LIKE '%".$str."%'"; $query_desc = "Product Name contains '$str'"; } } $sql .= $query; $result = mysql_query($sql); if (!$result) { $errmsg = 'Invalid query: ' . mysql_error() . "\n"; $errmsg .= 'Whole query: ' . $sql; echo $footer; exit; } if (!($limit)){ $limit = 20;// Default results per-page. } if (!($page)){ $page = 0; // Default page value. } $numrows = mysql_num_rows($result); if ($numrows == 0){ // bah, modify the "Not Found" error for your needs. echo "
No results found matching your query - $query_desc
"; echo $footer; mysql_free_result($result); exit; } $pages = intval($numrows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($numrows%$limit) { $pages++; // has remainder so add one page } // Current page number. $current = ceil($page/$limit) + 1; if (($pages < 1) || ($pages == 0)) { // If $pages is less than one or equal to 0, total pages is 1. $total = 1; } else { // Else total pages is $pages value. $total = $pages; } $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { //If not last results page, last result equals $page plus $limit. $last = $page + $limit; } else{ // If last results page, last result equals total number of results. $last = $numrows; } ?> \n"; while ($data = mysql_fetch_array($result)) { $viewlink = "$PHP_SELF?action=viewcat&catid=".$data['mol_id']; echo "" .""; } echo "\n\n"; echo "
Search Results for
Results - of Page of
Results per-page: 5 | 10 | 20 | 50
 
StructureIDProduct NameC.A.S. Number
"; showmol($data['mol_id'],$thumbwidth,$thumbheight); echo "".$data['mol_id']."".$data['structure_name']."".$data['cas_no']."
 
\n"; // Don't show 'previous' link if current page is first page. if ($page != 0) { $back_page = $page - $limit; echo " Previous\n"; } // loop through each page and give link to it. for ($i=1; $i <= $pages; $i++) { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("$i \n");// If current page don't give link, just text. } else { echo " $i\n"; } } // If last page don't give next link. if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { $next_page = $page + $limit; echo " Next\n"; } echo "
\n"; echo $footer; mysql_free_result($result); } //view item else if($action == "viewcat"){ echo $header; echo $nav; $catid = escapeshellcmd($catid); $catid = mysql_real_escape_string(trim($catid)); $sql = "SELECT * FROM mol WHERE mol_id='$catid'"; $result = mysql_query($sql); if (!$result) { $errmsg = 'Invalid query: ' . mysql_error() . "\n"; $errmsg .= 'Whole query: ' . $sql; debug($errmsg); } $data = mysql_fetch_array($result); mysql_free_result($result); $funcgroups = array('aminoacids','aminoalcohols','biotin','boronic','glycidols','indoles','isocyanates','pyrrolidines','wittigs'); foreach($funcgroups as $table) { $sql = "SELECT catno FROM $table WHERE catno=".$catid; $result = mysql_query($sql); if($result){ if(mysql_num_rows($result)>0){ $funcgr[]=$table; } mysql_free_result($result); } } ?>
C.A.S Number
Catalog ID
Product Name
Functional Group
" target=blank>download molfile
Back
Settings"; echo $footer; } //render image from database else if ($action=="showimg"){ $sql="SELECT structure FROM mol WHERE mol_id = ".$catid; $result = mysql_query($sql); if ($result) { $data = mysql_fetch_array($result); if($data[0]){ header('Content-type: image/jpeg'); echo $data[0]; } mysql_free_result($result); } } //down mol file from database else if ($action=="downmol"){ $catid = escapeshellcmd($catid); $sql="SELECT structure FROM mol WHERE mol_id = ".$catid; $result = mysql_query($sql); if ($result) { $data = mysql_fetch_array($result); if($data[0]){ header("Content-Type: chemical/x-mdl-molfile"); header("Content-Disposition: filename=$catid.mol"); echo "$data[0]"; } mysql_free_result($result); } } mysql_close(); function showmol($catid,$width=250,$height=120){ $catid = escapeshellcmd($catid); $sql="SELECT structure FROM mol WHERE mol_id = ".$catid; $result = mysql_query($sql); if ($result) { $data = mysql_fetch_array($result); if($data[0]){ //header('Content-type: text/plain'); //echo $data[0]; // JME needs MDL molfiles with the "|" character instead of linebreaks $jmehitmol = strtr($data[0],"\r\n","|"); echo ""; echo " \n"; echo "\n"; echo "\n"; } mysql_free_result($result); } } function set_variables_after_query($selection) { // set variables in the caller's environment from a database query // by James Thornton, http://jamesthornton.com $row = mysql_fetch_row($selection); foreach($row as $i => $value) { $column = mysql_field_name($selection,$i); $retarry["$column"] = $value; echo print_r($retarry,true); } } function debug($string) { print "".$string."
"; } ?>