PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wwwfiles/details.php

https://github.com/annulen/MolDB
PHP | 320 lines | 260 code | 37 blank | 23 comment | 91 complexity | b53878f116e4e65b0de47fa4d1050beb MD5 | raw file
  1. <?php
  2. // details.php Norbert Haider, University of Vienna, 2006-2010
  3. // part of MolDB5R last change: 2010-06-11
  4. $myname = $_SERVER['PHP_SELF'];
  5. require_once("functions.php");
  6. // read UID and password from an include file (which should
  7. // be stored _outside_ the web server's document_root directory
  8. // somewhere in the include path of PHP!!!!!!!!!!!!!)
  9. include("moldb5conf.php"); // contains $uid and $pw of a proxy user
  10. // with read-only access to the moldb database;
  11. // contains $bitmapURLdir (location of .png files);
  12. // the conf file must have valid PHP start and end tags!
  13. //$configfile = "moldb5conf.php"; // just an alternative to "include" for
  14. // plain-text conf files
  15. //$conf = `cat $configfile`; # read content of configuration file
  16. //eval($conf); # and treat as valid PHP statements
  17. if (config_quickcheck() > 0) { die(); }
  18. $user = $ro_user; # from configuration file
  19. $password = $ro_password;
  20. if ($user == "") {
  21. die("no username specified!\n");
  22. }
  23. if (!isset($sitename) || ($sitename == "")) {
  24. $sitename = "MolDB demo";
  25. }
  26. ?>
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  28. <html>
  29. <head>
  30. <link href="moldb.css" rel="stylesheet" type="text/css">
  31. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  32. <meta name="author" content="N. Haider">
  33. <title><?php echo "$sitename"; ?>: compound details</title>
  34. </head>
  35. <body>
  36. <?php
  37. $mol_id = $_REQUEST['mol'];
  38. $rxn_id = $_REQUEST['rxn'];
  39. $db_id = $_REQUEST['db'];
  40. $link = mysql_pconnect($hostname,"$ro_user", "$ro_password")
  41. or die("Could not connect to database server!");
  42. mysql_select_db($database)
  43. or die("Could not select database!");
  44. if (exist_db($default_db) == FALSE) {
  45. $default_db = get_lowestdbid();
  46. }
  47. $db_id = check_db($db_id);
  48. if ($db_id < 0) {
  49. $db_id = $default_db;
  50. $db_id = check_db($db_id);
  51. if ($db_id < 0) {
  52. $db_id = get_lowestdbid();
  53. }
  54. }
  55. if ($db_id == 0) { die(); }
  56. $qstr01 = "SELECT * FROM $metatable WHERE (db_id = $db_id)";
  57. $result01 = mysql_query($qstr01)
  58. or die("Query failed (#1)!");
  59. while($line01 = mysql_fetch_array($result01)) {
  60. $db_id = $line01['db_id'];
  61. $dbtype = $line01['type'];
  62. $access = $line01['access'];
  63. $dbname = $line01['name'];
  64. $usemem = $line01['usemem'];
  65. $digits = $line01['digits'];
  66. $subdirdigits = $line01['subdirdigits'];
  67. }
  68. mysql_free_result($result01);
  69. if (!isset($digits) || (is_numeric($digits) == false)) { $digits = 8; }
  70. if (!isset($subdirdigits) || (is_numeric($subdirdigits) == false)) { $subdirdigits = 0; }
  71. if ($subdirdigits < 0) { $subdirdigits = 0; }
  72. if ($subdirdigits > ($digits - 1)) { $subdirdigits = $digits - 1; }
  73. $dbprefix = $prefix . "db" . $db_id . "_";
  74. $molstructable = $dbprefix . $molstrucsuffix;
  75. $moldatatable = $dbprefix . $moldatasuffix;
  76. $molstattable = $dbprefix . $molstatsuffix;
  77. $molcfptable = $dbprefix . $molcfpsuffix;
  78. $molfgbtable = $dbprefix . $molfgbsuffix;
  79. $pic2dtable = $dbprefix . $pic2dsuffix;
  80. $rxnstructable = $dbprefix . $rxnstrucsuffix;
  81. $rxndatatable = $dbprefix . $rxndatasuffix;
  82. if ($usemem == 'T') {
  83. $molstattable = $molstattable . $memsuffix;
  84. $molcfptable = $molcfptable . $memsuffix;
  85. }
  86. $safemol_id = escapeshellcmd($mol_id);
  87. $saferxn_id = escapeshellcmd($rxn_id);
  88. function showHit2($id) {
  89. global $bitmapURLdir;
  90. global $molstructable;
  91. global $moldatatable;
  92. global $pic2dtable;
  93. global $digits;
  94. global $subdirdigits;
  95. global $db_id;
  96. global $access;
  97. $result3 = mysql_query("SELECT mol_name FROM $moldatatable WHERE mol_id = $id")
  98. or die("Query failed! (showHit2)");
  99. while ($line3 = mysql_fetch_array($result3, MYSQL_ASSOC)) {
  100. $txt = $line3["mol_name"];
  101. }
  102. mysql_free_result($result3);
  103. echo "<table width=\"100%\">\n";
  104. echo "<tr>\n<td bgcolor=\"#EEEEEE\">\n";
  105. print "<b>$txt</b> (<a href=\"showmol.php?mol=${id}&db=${db_id}\" target=\"blank\">$id</a>)\n";
  106. echo "</td>\n</tr>\n";
  107. echo "</table>\n";
  108. if ($access >= 2) { // display an "edit" link for read/write data collections
  109. print "[<a href=\"admin/editdata.php?db=${db_id}&id=${id}&action=editdata\" target=\"admin\">edit</a>]<br />\n";
  110. }
  111. // for faster display, we should have GIF files of the 2D structures
  112. // instead of invoking the JME applet:
  113. $qstr = "SELECT status FROM $pic2dtable WHERE mol_id = $id";
  114. //echo "SQL: $qstr<br />\n";
  115. $result2 = mysql_query($qstr)
  116. or die("Query failed! (pic2d)");
  117. while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) {
  118. $status = $line2["status"];
  119. }
  120. mysql_free_result($result2);
  121. if ($status != 1) { $usebmp = false; } else { $usebmp = true; }
  122. if ((isset($bitmapURLdir)) && ($bitmapURLdir != "") && ($usebmp == true)) {
  123. while (strlen($id) < $digits) { $id = "0" . $id; }
  124. $subdir = '';
  125. if ($subdirdigits > 0) { $subdir = substr($id,0,$subdirdigits) . '/'; }
  126. print "<img src=\"${bitmapURLdir}/${db_id}/${subdir}${id}.png\" alt=\"selected structure\">\n";
  127. } else {
  128. // if no bitmaps are available, we must invoking another instance of JME
  129. // in "depict" mode for structure display of each hit
  130. $result4 = mysql_query("SELECT struc FROM $molstructable WHERE mol_id = $id") or die("Query failed!");
  131. while ($line4 = mysql_fetch_array($result4, MYSQL_ASSOC)) {
  132. $molstruc = $line4["struc"];
  133. }
  134. mysql_free_result($result4);
  135. // JME needs MDL molfiles with the "|" character instead of linebreaks
  136. $jmehitmol = strtr($molstruc,"\n","|");
  137. echo "<applet code=\"JME.class\" archive=\"JME.jar\" \n";
  138. echo "width=\"450\" height=\"300\">";
  139. echo "<param name=\"options\" value=\"depict\"> \n";
  140. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  141. echo "</applet>\n";
  142. }
  143. }
  144. function showHit2rxn($id) {
  145. global $rxnstructable;
  146. global $rxndatatable;
  147. global $db_id;
  148. global $access;
  149. $result3 = mysql_query("SELECT rxn_name FROM $rxndatatable WHERE rxn_id = $id")
  150. or die("Query failed! (showHit2rxn)");
  151. while ($line3 = mysql_fetch_array($result3, MYSQL_ASSOC)) {
  152. $txt = $line3["rxn_name"];
  153. }
  154. mysql_free_result($result3);
  155. echo "<table width=\"100%\">\n";
  156. echo "<tr>\n<td bgcolor=\"#EEEEEE\">\n";
  157. print "<b>$txt</b> (<a href=\"showmol.php?rxn=${id}&db=${db_id}\" target=\"blank\">$id</a>)\n";
  158. echo "</td>\n</tr>\n";
  159. echo "</table>\n";
  160. if ($access >= 2) { // display an "edit" link for read/write data collections
  161. print "[<a href=\"admin/editdata.php?db=${db_id}&id=${id}&action=editdata\" target=\"admin\">edit</a>]<br />\n";
  162. }
  163. // use JME in "depict" mode for reaction display
  164. $result4 = mysql_query("SELECT struc FROM $rxnstructable WHERE rxn_id = $id") or die("Query failed! (showHit2rxn)");
  165. while ($line4 = mysql_fetch_array($result4, MYSQL_ASSOC)) {
  166. $molstruc = $line4["struc"];
  167. }
  168. mysql_free_result($result4);
  169. $molstruc = strip_labels($molstruc);
  170. // JME needs MDL molfiles with the "|" character instead of linebreaks
  171. $jmehitmol = strtr($molstruc,"\n","|");
  172. echo "<applet code=\"JME.class\" archive=\"JME.jar\" \n";
  173. echo "width=\"550\" height=\"300\">";
  174. echo "<param name=\"options\" value=\"depict\"> \n";
  175. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  176. echo "</applet>\n";
  177. }
  178. function showData_old($id) {
  179. echo "<p />\n";
  180. global $moldatatable;
  181. $result4 = mysql_query("SELECT * FROM $moldatatable WHERE mol_id = $id")
  182. or die("Query failed! (showData_old)");
  183. $y = mysql_num_fields($result4);
  184. echo "<table>\n";
  185. while ($line4 = mysql_fetch_array($result4, MYSQL_BOTH)) {
  186. for ($x = 0; $x < $y; $x++) {
  187. $fieldname = mysql_field_name($result4, $x);
  188. //$fieldtype = mysql_field_type($result4, $x);
  189. if ($fieldname != "mol_name" && $fieldname != "mol_id" && $line4[$fieldname] != "") {
  190. //echo "<b>$fieldname:</b> \t$line4[$fieldname] <br />\n";
  191. echo "<tr>\n";
  192. echo " <td><b>$fieldname</b></td><td>$line4[$fieldname]</td>\n";
  193. echo "</tr>\n";
  194. }
  195. }
  196. echo "<br />\n";
  197. }
  198. echo "</table>\n";
  199. mysql_free_result($result4);
  200. }
  201. function showData($id) {
  202. echo "<p />\n";
  203. global $dbtype;
  204. global $moldatatable;
  205. global $rxndatatable;
  206. if ($dbtype == 1) {
  207. $idname = "mol_id";
  208. $namename = "mol_name";
  209. $datatable = $moldatatable;
  210. } elseif ($dbtype == 2) {
  211. $idname = "rxn_id";
  212. $namename = "rxn_name";
  213. $datatable = $rxndatatable;
  214. }
  215. //echo "<table bgcolor=\"#eeeeee\">\n";
  216. echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n";
  217. $qstr = "SHOW FULL COLUMNS FROM $datatable";
  218. $result = mysql_query($qstr)
  219. or die("Query failed! (showData)");
  220. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  221. $field = $line["Field"];
  222. $label = $field;
  223. $type = $line["Type"];
  224. $comment = $line["Comment"];
  225. if (($field != $idname) && ($field != $namename)) {
  226. $format = 1;
  227. if (strlen($comment)>4) {
  228. $pos = strpos($comment, ">>>>");
  229. if ($pos !== false) {
  230. if ($pos == 0) {
  231. $comment = str_replace(">>>>","",$comment);
  232. $acomment = explode("<",$comment);
  233. $label = $acomment[0];
  234. $nformat = $acomment[1];
  235. if ($nformat == 0) { $format = 0; }
  236. if ($nformat == 1) { $format = 1; }
  237. if ($nformat == 2) { $format = 2; }
  238. if ($nformat == 3) { $format = 3; }
  239. if ($nformat == 4) { $format = 4; }
  240. }
  241. }
  242. }
  243. $dataval = ""; //preliminary....
  244. $qstr2 = "SELECT $field FROM $datatable WHERE $idname = $id";
  245. $result2 = mysql_query($qstr2)
  246. or die("Query failed! (dataval)");
  247. $line2 = mysql_fetch_row($result2);
  248. mysql_free_result($result2);
  249. $dataval = $line2[0];
  250. if (($format > 0) && (strlen($dataval) > 0)) {
  251. if ($label != "") { $field = $label; }
  252. echo "<tr><td valign=\"top\"><b>$field</b></td>";
  253. if ($format == 1) { echo "<td valign=\"top\">$dataval</td></tr>\n"; }
  254. if ($format == 2) { echo "<td valign=\"top\"><pre>$dataval</pre></td></tr>\n"; }
  255. if ($format == 3) {
  256. $mfdata = mfreformat($dataval);
  257. echo "<td valign=\"top\">$mfdata</td></tr>\n";
  258. }
  259. if ($format == 4) {
  260. $urldata = urlreformat($dataval);
  261. echo "<td valign=\"top\">$urldata</td></tr>\n";
  262. }
  263. } // if ($format > 0)...
  264. } // if...
  265. }
  266. echo "</table>\n";
  267. mysql_free_result($result);
  268. }
  269. if (($safemol_id !='') || ($saferxn_id !='')) {
  270. print "<h2>${sitename}: details for selected entry</h2>\n";
  271. if (($dbtype == 1) && ($safemol_id !='')) {
  272. showHit2($safemol_id);
  273. showData($safemol_id);
  274. } elseif (($dbtype == 2) && ($saferxn_id !='')) {
  275. showHit2rxn($saferxn_id);
  276. showData($saferxn_id);
  277. }
  278. } else {
  279. echo "<h2>No molecule/reaction ID specified!</h2>\n";
  280. }
  281. ?>
  282. </body>
  283. </html>