PageRenderTime 65ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wwwfiles/admin/editdata.php

https://github.com/annulen/MolDB
PHP | 2749 lines | 2429 code | 191 blank | 129 comment | 442 complexity | ca2d3d8ecb2b91b928e09ce230c18800 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // admin/editdata.php Norbert Haider, University of Vienna, 2009-2010
  3. // part of MolDB5R last change: 2010-06-14
  4. $myname = $_SERVER['PHP_SELF'];
  5. @include("moldb5conf.php"); // if moldb5conf.php is in the PHP include path
  6. @include("../moldb5conf.php"); // if moldb5conf.php is where it should *not* be...
  7. require_once("../functions.php");
  8. require_once("../rxnfunct.php");
  9. require_once("dbfunct.php");
  10. $debug = 1; // 0: remain silent, higher values: be more verbose
  11. // odd numbers: output as HTML comments,
  12. // even numbers: output as clear-text messages
  13. if (config_quickcheck() > 0) { die(); }
  14. if (!isset($sitename) || ($sitename == "")) {
  15. $sitename = "MolDB5R demo";
  16. }
  17. $db_id = $_REQUEST['db'];
  18. $datatype = $_REQUEST['datatype'];
  19. $action = $_REQUEST['action'];
  20. $smiles = $_POST['smiles'];
  21. $jme = $_POST['jme'];
  22. $mol = $_POST['mol'];
  23. $ostype = getostype();
  24. $link = mysql_pconnect($hostname,"$rw_user", "$rw_password")
  25. or die("Could not connect to database server!");
  26. mysql_select_db($database)
  27. or die("Could not select database!");
  28. $db_id = check_db($db_id);
  29. if ($db_id < 0) {
  30. $db_id = $default_db;
  31. $db_id = check_db_all($db_id);
  32. if ($db_id < 0) {
  33. $db_id = get_lowestdbid();
  34. }
  35. }
  36. $mydb = get_dbproperties($db_id);
  37. $dbtype = $mydb['type'];
  38. if (($dbtype == 1) && ($datatype != 1)) { $datatype = 1; }
  39. if (($dbtype == 2) && ($datatype != 2)) { $datatype = 2; }
  40. $ip = $_SERVER['REMOTE_ADDR'];
  41. $trusted = is_trustedIP($ip);
  42. if ($trusted == false) {
  43. $trusted = is_db_trustedIP($db_id,$ip); // try if IP is trusted for this db
  44. }
  45. ?>
  46. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  47. <html>
  48. <head>
  49. <link href="../moldb.css" rel="stylesheet" type="text/css">
  50. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  51. <meta name="author" content="Norbert Haider, University of Vienna">
  52. <title><?php echo "$sitename (administration page)"; ?></title>
  53. </head>
  54. <body>
  55. <?php
  56. echo "<!-- MolDB5R, OS type $ostype --!>\n";
  57. echo "<h1>$sitename: data input/editing</h1>\n";
  58. echo "On this page, you can add new MolDB5R entries and erase or edit existing ones.<br />\n";
  59. echo "<hr />\n";
  60. echo "<small>selected data collection: $db_id</small><p />\n";
  61. $dbprefix = $prefix . "db" . $db_id . "_";
  62. $moldatatable = $dbprefix . $moldatasuffix;
  63. $molfgbtable = $dbprefix . $molfgbsuffix;
  64. $molstattable = $dbprefix . $molstatsuffix;
  65. $molstructable = $dbprefix . $molstrucsuffix;
  66. $molcfptable = $dbprefix . $molcfpsuffix;
  67. $pic2dtable = $dbprefix . $pic2dsuffix;
  68. $rxnstructable = $dbprefix . $rxnstrucsuffix;
  69. $rxndatatable = $dbprefix . $rxndatasuffix;
  70. $rxnfgbtable = $dbprefix . $rxnfgbsuffix;
  71. $rxncfptable = $dbprefix . $rxncfpsuffix;
  72. $mydb = get_dbproperties($db_id);
  73. $db = $mydb['db_id'];
  74. $access = $mydb['access'];
  75. $usemem = $mydb['usemem'];
  76. $dbtype = $mydb['type'];
  77. if ($dbtype == 1) {
  78. $structable = $molstructable;
  79. $idname = "mol_id";
  80. $namename = "mol_name";
  81. } elseif ($dbtype == 2) {
  82. $structable = $rxnstructable;
  83. $idname = "rxn_id";
  84. $namename = "rxn_name";
  85. }
  86. if (($access < 2) && ($trusted == FALSE)) {
  87. echo "Your client IP is not authorized to perform the requested operation!<br />\n";
  88. //echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  89. echo "</body></html>\n";
  90. die();
  91. }
  92. if ($action == "addstruc1") {
  93. if ($dbtype == 1) { $what = "structure"; } elseif ($dbtype == 2) { $what = "reaction"; }
  94. echo "<h3>Add a new $what to data collection $db_id</h3>\n";
  95. echo "<table>\n<tr>\n<td valign=\"top\">\n";
  96. if ($dbtype == 1) {
  97. echo "<small>draw the molecule in the applet window....</small><br />\n";
  98. echo "<applet name=\"JME\" code=\"JME.class\" \n";
  99. echo "archive=\"../JME.jar\" width=\"350\" height=\"290\">\n";
  100. echo "<param name=\"jme\" value=\"$jme\">\n";
  101. //echo "<param name=\"options\" value=\"xbutton, query, hydrogens\">\n";
  102. echo "<param name=\"options\" value=\"xbutton, hydrogens, multipart\">\n";
  103. echo "You have to enable Java in your browser.\n";
  104. echo "</applet>\n";
  105. } elseif ($dbtype == 2) {
  106. echo "<small>draw the reaction in the applet window....</small><br />\n";
  107. echo "<applet name='JME' code='JME.class' \n";
  108. echo "archive='../JME.jar' width=450 height=288>\n";
  109. if (strlen($jme) > 0) {
  110. echo "<param name=\"jme\" value=\"$jme\">\n";
  111. }
  112. echo "<param name=\"options\" value=\"xbutton, hydrogens, reaction, multipart\">\n";
  113. echo "You have to enable Java in your browser.\n";
  114. echo "</applet>\n";
  115. }
  116. ?>
  117. <script>
  118. function check_ss() {
  119. var smiles = document.JME.smiles();
  120. var jme = document.JME.jmeFile();
  121. var mol = document.JME.molFile();
  122. if (smiles.length < 1) {
  123. alert("No molecule!");
  124. }
  125. else {
  126. document.form.smiles.value = smiles;
  127. document.form.jme.value = jme;
  128. document.form.mol.value = mol;
  129. document.form.submit();
  130. }
  131. }
  132. </script>
  133. <p />
  134. <form name="form" action="<?php echo $myname; ?>" method="post">
  135. <input type="button" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Submit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" onClick="check_ss()">
  136. <input type="hidden" name="smiles">
  137. <input type="hidden" name="jme">
  138. <input type="hidden" name="mol">
  139. <input type="hidden" name="action" value="addstruc2">
  140. <input type="hidden" name="db" value="<?php echo "$db_id";?>">
  141. </form>
  142. <?php
  143. echo "</td>\n<td valign=\"top\">\n";
  144. if ($dbtype == 1) {
  145. echo "<small>...or paste it in MDL (V2000) molfile format into the text window</small><br />\n";
  146. } elseif ($dbtype == 2) {
  147. echo "<small>...or paste it in MDL (V2000) rxnfile format into the text window</small><br />\n";
  148. }
  149. echo "<form name=\"form2\" action=\"$myname\" method=\"post\">\n";
  150. echo "<textarea name=\"mol\" cols=\"70\" rows=\"17\"></textarea>\n";
  151. echo "<input type=\"hidden\" name=\"action\" value=\"addstruc2\">\n";
  152. echo "<input type=\"hidden\" name=\"db\" value=\"$db_id\"><p />\n";
  153. echo "<input type=\"Submit\" name=\"select\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Submit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\">\n";
  154. echo "</form>\n";
  155. echo "</td></tr>\n</table>\n";
  156. echo "<p /><a href=\"$myname?db=$db_id\">Continue without saving</a>\n";
  157. echo "</body></html>\n";
  158. die();
  159. }
  160. if ($action == "addstruc2") {
  161. if ($dbtype == 1) {
  162. $what = "structure";
  163. $reserved_mol_id = get_next_mol_id($db_id);
  164. } elseif ($dbtype == 2) {
  165. $what = "reaction";
  166. $reserved_mol_id = get_next_rxn_id($db_id);
  167. }
  168. // find out the next available mol_id
  169. // get next available mol_id
  170. // check if we got a valid molfile (either from JME or from the text area)
  171. if (is_validmol($mol) == FALSE) {
  172. echo "<h3>ERROR: this is not a valid input MDL (V2000) molfile!</h3>\n";
  173. echo "<pre>$safemol </pre>\n";
  174. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  175. echo "</body></html>\n";
  176. die();
  177. }
  178. // if in reaction mode, check if we have the rxn file header (if not, add it)
  179. if ($dbtype == 2) {
  180. if (strpos($mol, '$RXN') === FALSE) {
  181. $mol = "\$RXN\n\n\n\n 0 1\n\$MOL\n" . $mol;
  182. }
  183. }
  184. echo "<h3>Do you really want to add this $what to data collection $db_id?</h3>\n";
  185. // JME needs MDL molfiles with the "|" character instead of linebreaks
  186. $jmehitmol = strtr($mol,"\n","|");
  187. echo "<applet name=\"JME\" code=\"JME.class\" archive=\"../JME.jar\" \n";
  188. if ($dbtype == 1) {
  189. echo "width=\"250\" height=\"220\">";
  190. } elseif ($dbtype == 2) {
  191. echo "width=\"450\" height=\"220\">";
  192. }
  193. echo "<param name=\"options\" value=\"depict\"> \n";
  194. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  195. echo "</applet>\n";
  196. ?>
  197. <script>
  198. function submit1_ss() {
  199. var smiles = document.JME.smiles();
  200. var jme = document.JME.jmeFile();
  201. var mol = document.JME.molFile();
  202. if (smiles.length < 1) {
  203. alert("No molecule!");
  204. }
  205. else {
  206. document.addstruc1.smiles.value = smiles;
  207. document.addstruc1.jme.value = jme;
  208. document.addstruc1.mol.value = mol;
  209. document.addstruc1.submit();
  210. }
  211. }
  212. </script>
  213. <script>
  214. function submit2_ss() {
  215. var smiles = document.JME.smiles();
  216. var jme = document.JME.jmeFile();
  217. var mol = document.JME.molFile();
  218. if (smiles.length < 1) {
  219. alert("No molecule!");
  220. }
  221. else {
  222. document.addstruc2.smiles.value = smiles;
  223. document.addstruc2.jme.value = jme;
  224. document.addstruc2.mol.value = mol;
  225. document.addstruc2.submit();
  226. }
  227. }
  228. </script>
  229. <?php
  230. echo "<form name=\"addstruc1\" action=\"$myname\" method=\"post\">\n";
  231. echo "<input type=\"hidden\" name=\"action\" value=\"addstruc3\">\n";
  232. echo "<input type=\"hidden\" name=\"db\" value=\"$db_id\">\n";
  233. echo "<input type=\"hidden\" name=\"nextid\" value=\"$reserved_mol_id\">\n";
  234. echo "<input type=\"hidden\" name=\"mol\" value=\"$mol\">\n";
  235. echo "<input type=\"hidden\" name=\"jme\" value=\"$jme\">\n";
  236. echo "<input type=\"hidden\" name=\"smiles\" value=\"$smiles\">\n";
  237. // echo "<input type=\"Submit\" name=\"select\" value=\"&nbsp;Yes, add new structure!\">\n";
  238. echo "<input type=\"button\" value=\"&nbsp;Yes, add new structure!\" onClick=\"submit1_ss()\">\n";
  239. echo "</form><p />\n";
  240. echo "<form name=\"addstruc2\" action=\"$myname\" method=\"post\">\n";
  241. echo "<input type=\"hidden\" name=\"action\" value=\"addstruc1\">\n";
  242. echo "<input type=\"hidden\" name=\"db\" value=\"$db_id\">\n";
  243. echo "<input type=\"hidden\" name=\"mol\" value=\"$mol\">\n";
  244. echo "<input type=\"hidden\" name=\"jme\" value=\"$jme\">\n";
  245. echo "<input type=\"hidden\" name=\"smiles\" value=\"$smiles\">\n";
  246. // echo "<input type=\"Submit\" name=\"select\" value=\"&nbsp;No, edit again\">\n";
  247. echo "<input type=\"button\" value=\"&nbsp;No, edit again\" onClick=\"submit2_ss()\">\n";
  248. echo "</form><p />\n";
  249. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  250. echo "</body></html>\n";
  251. die();
  252. }
  253. if (($action == "addstruc3") && ($dbtype == 1)) { // structure input
  254. $errorcount = 0;
  255. $proposed_mol_id = $_POST['nextid'];
  256. if ($use_cmmmsrv == 'y') {
  257. /* create a TCP/IP socket */
  258. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  259. if ($socket < 0) {
  260. //echo "socket_create() failed.\nreason: " . socket_strerror ($socket) . "\n";
  261. echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol --!>\n";
  262. $use_cmmmsrv = "n";
  263. }
  264. $sockresult = socket_connect ($socket, $cmmmsrv_addr, $cmmmsrv_port);
  265. if ($sockresult < 0) {
  266. //echo "socket_connect() failed.\nreason: ($sockresult) " . socket_strerror($sockresult) . "\n";
  267. echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol --!>\n";
  268. $use_cmmmsrv = "n";
  269. }
  270. }
  271. if ($use_cmmmsrv == 'y') {
  272. $a = socket_read($socket, 250, PHP_NORMAL_READ);
  273. //echo "$a\n";
  274. $pos = strpos($a,"READY");
  275. if ($pos === false) {
  276. echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol --!>\n";
  277. $use_cmmmsrv = "n";
  278. }
  279. $pos = 0;
  280. }
  281. // remove CR if present (IE, Mozilla et al.) and add it again (for Opera)
  282. $mol = str_replace("\r\n","\n",$mol);
  283. $mol = str_replace("\n","\r\n",$mol);
  284. //$safemol = escapeshellcmd($mol);
  285. $safemol = str_replace(";"," ",$mol);
  286. $safemol = str_replace("\""," ",$safemol);
  287. $safemol = str_replace("\'"," ",$safemol);
  288. $safemol = str_replace("\´"," ",$safemol);
  289. $safemol = str_replace("\`"," ",$safemol);
  290. $safemol = str_replace("\|"," ",$safemol);
  291. // first, tweak the molfile (if enabled in config file)
  292. if ($tweakmolfiles == "y") {
  293. if ($use_cmmmsrv == 'y') {
  294. $safemol = filterthroughcmmm($safemol,"#### checkmol:m");
  295. } else {
  296. if ($ostype == 1) {$safemol = filterthroughcmd($safemol,"$CHECKMOL -m - "); }
  297. if ($ostype == 2) {$safemol = filterthroughcmd2($safemol,"$CHECKMOL -m - "); }
  298. }
  299. }
  300. // check if we (still) have a valid MDL molfile
  301. if (is_validmol($safemol) == FALSE) {
  302. echo "<h3>ERROR: this is not a valid input MDL (V2000) molfile!</h3>\n";
  303. echo "<pre>$safemol </pre>\n";
  304. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  305. echo "</body></html>\n";
  306. die();
  307. }
  308. // next step: get the molecular statistics of the input structure
  309. // by piping it through the checkmol program
  310. //echo "adding this structure:\<br />\n<pre>$safemol</pre>\n";
  311. // get next available mol_id
  312. $result = mysql_query("SELECT COUNT(mol_id) AS molcount FROM $molstructable")
  313. or die("Query failed! (1c3)");
  314. $line = mysql_fetch_row($result);
  315. mysql_free_result($result);
  316. $molcount = $line[0];
  317. if ($molcount == 0) {
  318. $next_mol_id = 1;
  319. } else {
  320. $result = mysql_query("SELECT MAX(mol_id) AS molcount FROM $molstructable")
  321. or die("Query failed! (1c4)");
  322. $line = mysql_fetch_row($result);
  323. mysql_free_result($result);
  324. $molcount = $line[0];
  325. $next_mol_id = $molcount + 1;
  326. }
  327. if ($proposed_mol_id != $next_mol_id) {
  328. echo "This entry exists already!<br />\n";
  329. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  330. echo "</body></html>\n";
  331. die();
  332. }
  333. // add structure to molstruc
  334. $qstr = "INSERT INTO $molstructable (`mol_id`, `struc`) VALUES ($next_mol_id, \"$safemol\" )";
  335. if ($debug > 0) { debug_output("adding structure as no. $next_mol_id to data collection $db_id <br />\n"); }
  336. $result = mysql_query($qstr);
  337. $err = 0;
  338. $err = mysql_errno();
  339. if ($err != 0) {
  340. echo "<br />Action failed (#1/$err: " . mysql_error() . ")<br />\n";
  341. $errorcount++;
  342. } #else { echo "."; }
  343. if ($use_cmmmsrv == 'y') {
  344. $chkresult = filterthroughcmmm("$safemol", "#### checkmol:aXbH");
  345. } else {
  346. if ($ostype == 1) { $chkresult = filterthroughcmd("$safemol", "$CHECKMOL -aXbH - "); }
  347. if ($ostype == 2) {
  348. $safemol = str_replace("\n","\r\n",$safemol);
  349. $chkresult = filterthroughcmd2("$safemol", "$CHECKMOL -aXbH - ");
  350. }
  351. }
  352. #echo "<pre>$chkresult</pre>\n";
  353. if (strlen($chkresult) < 2) {
  354. echo "no response from checkmol (maybe a server configuration problem?)\n</body></html>\n";
  355. exit;
  356. }
  357. $cr = explode("\n", $chkresult);
  358. $molstat = trim($cr[0]);
  359. $molfgb = trim($cr[1]);
  360. $molfgb = str_replace(";",",",$molfgb);
  361. $molhfp = trim($cr[2]);
  362. $molhfp = str_replace(";",",",$molhfp);
  363. $qstr = "INSERT INTO $molstattable VALUES ( $next_mol_id,$molstat )";
  364. $result = mysql_query($qstr);
  365. $err = 0;
  366. $err = mysql_errno();
  367. if ($err != 0) {
  368. echo "<br />Action failed (#2/$err: " . mysql_error() . ")<br />\n";
  369. $errorcount++;
  370. } #else { echo "."; }
  371. $qstr = "INSERT INTO $molfgbtable VALUES ($next_mol_id,$molfgb )";
  372. $result = mysql_query($qstr);
  373. $err = 0;
  374. $err = mysql_errno();
  375. if ($err != 0) {
  376. echo "<br />Action failed (#3/$err: " . mysql_error() . ")<br />\n";
  377. $errorcount++;
  378. } #else { echo "."; }
  379. // get the fingerprint dictionary
  380. $fpdefqstr = "SELECT fp_id, fpdef FROM $fpdeftable;";
  381. $fpdefresult = mysql_query($fpdefqstr)
  382. or die("Could not get fingerprint definition!");
  383. $i = -1;
  384. $n_dict = 0;
  385. $fpdef = array();
  386. while ($fpdefline = mysql_fetch_array($fpdefresult, MYSQL_ASSOC)) {
  387. $i++;
  388. $n_dict++;
  389. $fpdef[$i] = $fpdefline["fpdef"];
  390. }
  391. mysql_free_result($fpdefresult);
  392. //create the dictionary-based fingerprints
  393. $moldfp = "";
  394. for ($k = 0; $k < $n_dict; $k++) {
  395. $dict = $fpdef[$k];
  396. if ($ostype == 1) { $cand = $safemol . "\n" . '$$$$' ."\n" . $dict; }
  397. if ($ostype == 2) {
  398. $dict = str_replace("\r","",$dict);
  399. $dict = str_replace("\n","\r\n",$dict);
  400. $cand = $safemol . "\r\n" . '$$$$' ."\r\n" . $dict;
  401. }
  402. if ($use_cmmmsrv == 'y') {
  403. $dfpstr = filterthroughcmmm($cand,"#### MATCHMOL:F");
  404. } else {
  405. $cand = str_replace("\$","\\\$",$cand);
  406. if ($ostype == 1) { $dfpstr = filterthroughcmd($cand,"$MATCHMOL -F - "); }
  407. if ($ostype == 2) { $dfpstr = filterthroughcmd2($cand,"$MATCHMOL -F - "); }
  408. }
  409. $dfpstr = trim($dfpstr);
  410. if ($k > 0) { $moldfp .= ","; }
  411. $moldfp .= " " . $dfpstr;
  412. } // for..
  413. //now insert dictionary-based and hash-based fingerprints into molcfptable
  414. $qstr = "INSERT INTO $molcfptable VALUES ($next_mol_id, $moldfp, $molhfp )";
  415. //echo "$qstr<br />\n";
  416. //echo "adding combined fingerprints for no. $next_mol_id to table $molcfptable.... ";
  417. $result = mysql_query($qstr);
  418. $err = 0;
  419. $err = mysql_errno();
  420. if ($err != 0) {
  421. echo "<br />Action failed (#4i/$err: " . mysql_error() . ")<br />\n";
  422. $errorcount++;
  423. } #else { echo "."; }
  424. // add new record to pic2dtable
  425. $qstr = "INSERT INTO $pic2dtable VALUES ($next_mol_id, \"1\", \"3\" )"; // 0 = does not exist, 1 = OK, 2 = OK, but do not show, 3 = to be created/updated, 4 = to be deleted
  426. //echo "$qstr<br />\n";
  427. //echo "adding 2D depiction information for no. $next_mol_id to table $pic2dtable.... ";
  428. $result = mysql_query($qstr);
  429. $err = 0;
  430. $err = mysql_errno();
  431. if ($err != 0) {
  432. echo "<br />Action failed (#5/$err: " . mysql_error() . ")<br />\n";
  433. $errorcount++;
  434. } #else { echo "."; }
  435. // add new record to moldatatable
  436. $qstr = "INSERT INTO $moldatatable (`mol_id`) VALUES (\"$next_mol_id\")";
  437. //echo "$qstr<br />\n";
  438. //echo "adding mol data for no. $next_mol_id to table $moldatatable.... ";
  439. $result = mysql_query($qstr);
  440. $err = 0;
  441. $err = mysql_errno();
  442. if ($err != 0) {
  443. echo "<br />Action failed (#6/$err: " . mysql_error() . ")<br />\n";
  444. $errorcount++;
  445. } #else { echo "."; }
  446. // MySQL syntax for table description, including comments:
  447. // SHOW FULL COLUMNS FROM db3_pic2d;
  448. // MySQL syntax for changing just a comment:
  449. // ALTER TABLE `db3_pic2d` CHANGE `status` `status` TINYINT( 4 ) NOT NULL DEFAULT '0'
  450. // COMMENT '0 = does not exist, 1 = OK, 2 = OK, but do not show, 3 = to be created/updated, 4 = to be deleted, 5 = in progress'
  451. // finished.....
  452. if ($use_cmmmsrv == 'y') {
  453. socket_write($socket,'#### bye');
  454. socket_close($socket);
  455. }
  456. // for now, disable use of memory-based tables
  457. set_memstatus_dirty($db_id);
  458. if ($debug > 0) { debug_output("Finished with $errorcount errors.<br />\n"); }
  459. if ($err == 0) {
  460. // JME needs MDL molfiles with the "|" character instead of linebreaks
  461. $jmehitmol = strtr($safemol,"\n","|");
  462. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  463. echo "width=\"250\" height=\"120\">";
  464. echo "<param name=\"options\" value=\"depict\"> \n";
  465. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  466. echo "</applet>\n";
  467. echo "<p />\n";
  468. mk_dataeditform($next_mol_id,1);
  469. } else {
  470. echo "something went wrong....<br />\n";
  471. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  472. }
  473. echo "</body></html>\n";
  474. die();
  475. } // action=addstruc3
  476. if (($action == "addstruc3") && ($dbtype == 2)) { // reaction input
  477. $errorcount = 0;
  478. $proposed_rxn_id = $_POST['nextid'];
  479. if (strpos($mol,"\$RXN") === FALSE) {
  480. echo "this is not a valid reaction file!\n";
  481. echo "</body></html>\n";
  482. die();
  483. }
  484. $errorcount = 0;
  485. $proposed_rxn_id = $_POST['nextid'];
  486. if ($use_cmmmsrv == 'y') {
  487. /* create a TCP/IP socket */
  488. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  489. if ($socket < 0) {
  490. //echo "socket_create() failed.\nreason: " . socket_strerror ($socket) . "\n";
  491. echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol --!>\n";
  492. $use_cmmmsrv = "n";
  493. }
  494. $sockresult = socket_connect ($socket, $cmmmsrv_addr, $cmmmsrv_port);
  495. if ($sockresult < 0) {
  496. //echo "socket_connect() failed.\nreason: ($sockresult) " . socket_strerror($sockresult) . "\n";
  497. echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol --!>\n";
  498. $use_cmmmsrv = "n";
  499. }
  500. }
  501. if ($use_cmmmsrv == 'y') {
  502. $a = socket_read($socket, 250, PHP_NORMAL_READ);
  503. //echo "$a\n";
  504. $pos = strpos($a,"READY");
  505. if ($pos === false) {
  506. echo "<!-- could not connect to cmmmsrv - reverting to checkmol/matchmol --!>\n";
  507. $use_cmmmsrv = "n";
  508. }
  509. $pos = 0;
  510. }
  511. // remove CR if present (IE, Mozilla et al.) and add it again (for Opera)
  512. $mol = str_replace("\r\n","\n",$mol);
  513. $mol = str_replace("\n","\r\n",$mol);
  514. //$saferxn = escapeshellcmd($mol);
  515. $saferxn = str_replace(";"," ",$mol);
  516. $saferxn = str_replace("\""," ",$saferxn);
  517. $saferxn = str_replace("\'"," ",$saferxn);
  518. $saferxn = str_replace("\´"," ",$saferxn);
  519. $saferxn = str_replace("\`"," ",$saferxn);
  520. $saferxn = str_replace("\|"," ",$saferxn);
  521. $rxndescr = analyze_rxnfile($saferxn);
  522. $nrmol = get_nrmol($rxndescr);
  523. $npmol = get_npmol($rxndescr);
  524. //echo "there are $nrmol reactants and $npmol products<br>\n";
  525. if (($nrmol == 0) || ($npmol == 0)) {
  526. echo "incomplete reaction file!\n";
  527. echo "</body></html>\n";
  528. die();
  529. }
  530. $allmol = array();
  531. $rmol = array();
  532. $pmol = array();
  533. $label_list = array();
  534. $map_list = array();
  535. $n_labels = 0;
  536. $n_maps = 0;
  537. $mapstr = "";
  538. echo "<pre>\n";
  539. $allmol = explode("\$MOL\r\n",$saferxn);
  540. $header = $allmol[0];
  541. // get the fingerprint dictionary
  542. $fpdefqstr = "SELECT fp_id, fpdef FROM $fpdeftable;";
  543. $fpdefresult = mysql_query($fpdefqstr)
  544. or die("Could not get fingerprint definition!");
  545. $i = -1;
  546. $n_dict = 0;
  547. $fpdef = array();
  548. while ($fpdefline = mysql_fetch_array($fpdefresult, MYSQL_ASSOC)) {
  549. $i++;
  550. $n_dict++;
  551. $fpdef[$i] = $fpdefline["fpdef"];
  552. }
  553. mysql_free_result($fpdefresult);
  554. // get next available rxn_id
  555. $result = mysql_query("SELECT COUNT(rxn_id) AS molcount FROM $rxnstructable")
  556. or die("Query failed! (1c3a)");
  557. $line = mysql_fetch_row($result);
  558. mysql_free_result($result);
  559. $rxncount = $line[0];
  560. if ($rxncount == 0) {
  561. $next_rxn_id = 1;
  562. } else {
  563. $result = mysql_query("SELECT MAX(rxn_id) AS molcount FROM $rxnstructable")
  564. or die("Query failed! (1c4a)");
  565. $line = mysql_fetch_row($result);
  566. mysql_free_result($result);
  567. $rxncount = $line[0];
  568. $next_rxn_id = $rxncount + 1;
  569. }
  570. if ($proposed_rxn_id != $next_rxn_id) {
  571. echo "This entry exists already!<br />\n";
  572. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  573. echo "</body></html>\n";
  574. die();
  575. }
  576. $mapstr = get_maps($saferxn);
  577. if ($nrmol > 0) {
  578. $moldfpsum = "";
  579. $molhfpsum = "";
  580. $molfgbsum = "";
  581. for ($i = 0; $i < $nrmol; $i++) {
  582. $rmol[$i] = $allmol[($i+1)];
  583. $mnum = $i + 1;
  584. //echo "processing reactant no. $mnum ...";
  585. $labels = get_atomlabels($rmol[$i]);
  586. $mid = "r" . $mnum;
  587. if (strlen($labels) > 0) {
  588. add_labels($mid,$labels);
  589. }
  590. $safemol = $rmol[$i];
  591. // now tweak each molecule
  592. if ($tweakmolfiles == "y") {
  593. if ($use_cmmmsrv == 'y') {
  594. $safemol = filterthroughcmmm($safemol,"#### checkmol:m");
  595. } else {
  596. if ($ostype == 1) { $safemol = filterthroughcmd($safemol,"$CHECKMOL -m - "); }
  597. if ($ostype == 2) {
  598. $safemol = filterthroughcmd2($safemol,"$CHECKMOL -m - ");
  599. $safemol = str_replace("\n","\r\n",$safemol);
  600. }
  601. }
  602. $rmol[$i] = $safemol;
  603. } // end tweakmolefiles = y
  604. //create the dictionary-based fingerprints
  605. $moldfp = "";
  606. for ($k = 0; $k < $n_dict; $k++) {
  607. $dict = $fpdef[$k];
  608. if ($ostype == 1) { $cand = $safemol . "\n" . '$$$$' ."\n" . $dict; }
  609. if ($ostype == 2) {
  610. $dict = str_replace("\r","",$dict);
  611. $dict = str_replace("\n","\r\n",$dict);
  612. $cand = $safemol . "\r\n" . '$$$$' ."\r\n" . $dict;
  613. }
  614. if ($use_cmmmsrv == 'y') {
  615. $dfpstr = filterthroughcmmm($cand,"#### MATCHMOL:F");
  616. } else {
  617. $cand = str_replace("\$","\\\$",$cand);
  618. if ($ostype == 1) { $dfpstr = filterthroughcmd($cand,"$MATCHMOL -F - "); }
  619. if ($ostype == 2) { $dfpstr = filterthroughcmd2($cand,"$MATCHMOL -F - "); }
  620. }
  621. $dfpstr = trim($dfpstr);
  622. if ($k > 0) { $moldfp .= ","; }
  623. $moldfp .= $dfpstr;
  624. //echo "dictionary-based fingerprints for reactant $i + dictionary $k\n$dfpstr\n";
  625. } // for..
  626. //echo "moldfp: $moldfp\n";
  627. $moldfpsum = add_molfp($moldfpsum,$moldfp);
  628. // create the hash-based fingerprints
  629. if ($use_cmmmsrv == 'y') {
  630. $chkresult = filterthroughcmmm($safemol,"#### checkmol:bH");
  631. } else {
  632. if ($ostype == 1) {$chkresult = filterthroughcmd($safemol,"$CHECKMOL -bH - "); }
  633. if ($ostype == 2) {$chkresult = filterthroughcmd2($safemol,"$CHECKMOL -bH - "); }
  634. }
  635. if (strlen($chkresult) < 2) {
  636. echo "no response from checkmol (maybe a server configuration problem?)\n</body></html>\n";
  637. exit;
  638. }
  639. $cr = explode("\n", $chkresult);
  640. $molfgb = trim($cr[0]);
  641. $fgbarr = explode(";",$molfgb); // cut off the n1bits value
  642. $molfgb = $fgbarr[0];
  643. $molhfp = trim($cr[1]);
  644. $hfparr = explode(";",$molhfp); // cut off the n1bits value
  645. $molhfp = $hfparr[0];
  646. //echo "molhfp: $molhfp\n";
  647. $molhfpsum = add_molfp($molhfpsum,$molhfp);
  648. $molfgbsum = add_molfp($molfgbsum,$molfgb);
  649. } // end for ($i = 0; $i < $nrmol; $i++) ...
  650. //echo "added moldfp: $moldfpsum\n";
  651. //echo "added molhfp: $molhfpsum\n";
  652. // insert combined reaction fingerprints for reactant(s)
  653. $qstr = "INSERT INTO $rxncfptable VALUES ($next_rxn_id,'R',$moldfpsum,$molhfpsum,0)";
  654. //echo "adding combined fingerprints for no. $next_rxn_id to table $rxncfptable.... ";
  655. $result = mysql_query($qstr);
  656. $err = 0;
  657. $err = mysql_errno();
  658. if ($err != 0) {
  659. echo "<br />Action failed (#4a/$err: " . mysql_error() . ")<br />\n";
  660. $errorcount++;
  661. } // else { echo "done\n"; }
  662. // insert combined functional group bitstring for reactant(s)
  663. $qstr = "INSERT INTO $rxnfgbtable VALUES ($next_rxn_id,'R',$molfgbsum,0)";
  664. //echo "adding combined reactant functional group codes for no. $next_rxn_id to table $rxncfptable.... ";
  665. $result = mysql_query($qstr);
  666. $err = 0;
  667. $err = mysql_errno();
  668. if ($err != 0) {
  669. echo "<br />Action failed (#4b/$err: " . mysql_error() . ")<br />\n";
  670. $errorcount++;
  671. } // else { echo "done\n"; }
  672. }
  673. if ($npmol > 0) {
  674. $moldfpsum = "";
  675. $molhfpsum = "";
  676. $molfgbsum = "";
  677. for ($i = 0; $i < $npmol; $i++) {
  678. $pmol[$i] = $allmol[($i+1+$nrmol)];
  679. $mnum = $i + 1;
  680. //echo "processing product no. $mnum ...";
  681. $labels = get_atomlabels($pmol[$i]);
  682. $mid = "p" . $mnum;
  683. if (strlen($labels) > 0) {
  684. add_labels($mid,$labels);
  685. }
  686. $safemol = $pmol[$i];
  687. // tweak the molfile
  688. if ($tweakmolfiles == "y") {
  689. if ($use_cmmmsrv == 'y') {
  690. $safemol = filterthroughcmmm($safemol,"#### checkmol:m");
  691. } else {
  692. if ($ostype == 1) { $safemol = filterthroughcmd($safemol,"$CHECKMOL -m - "); }
  693. if ($ostype == 2) {
  694. $safemol = filterthroughcmd2($safemol,"$CHECKMOL -m - ");
  695. $safemol = str_replace("\n","\r\n",$safemol);
  696. }
  697. }
  698. $pmol[$i] = $safemol;
  699. } // end tweakmolefiles = y
  700. //create the dictionary-based fingerprints
  701. $moldfp = "";
  702. for ($k = 0; $k < $n_dict; $k++) {
  703. $dict = $fpdef[$k];
  704. if ($ostype == 1) { $cand = $safemol . "\n" . '$$$$' ."\n" . $dict; }
  705. if ($ostype == 2) {
  706. $dict = str_replace("\r","",$dict);
  707. $dict = str_replace("\n","\r\n",$dict);
  708. $cand = $safemol . "\r\n" . '$$$$' ."\r\n" . $dict;
  709. }
  710. if ($use_cmmmsrv == 'y') {
  711. $dfpstr = filterthroughcmmm($cand,"#### MATCHMOL:F");
  712. } else {
  713. $cand = str_replace("\$","\\\$",$cand);
  714. if ($ostype == 1) { $dfpstr = filterthroughcmd($cand,"$MATCHMOL -F - "); }
  715. if ($ostype == 2) { $dfpstr = filterthroughcmd2($cand,"$MATCHMOL -F - "); }
  716. }
  717. $dfpstr = trim($dfpstr);
  718. if ($k > 0) { $moldfp .= ","; }
  719. $moldfp .= $dfpstr;
  720. //echo "dictionary-based fingerprints for product $i + dictionary $k\n$dfpstr\n";
  721. } // for..
  722. //echo "moldfp: $moldfp\n";
  723. $moldfpsum = add_molfp($moldfpsum,$moldfp);
  724. // create the hash-based fingerprints
  725. if ($use_cmmmsrv == 'y') {
  726. $chkresult = filterthroughcmmm($safemol,"#### checkmol:bH");
  727. } else {
  728. if ($ostype == 1) {$chkresult = filterthroughcmd($safemol,"$CHECKMOL -bH - "); }
  729. if ($ostype == 2) {$chkresult = filterthroughcmd2($safemol,"$CHECKMOL -bH - "); }
  730. }
  731. if (strlen($chkresult) < 2) {
  732. echo "no response from checkmol (maybe a server configuration problem?)\n</body></html>\n";
  733. exit;
  734. }
  735. $cr = explode("\n", $chkresult);
  736. $molfgb = trim($cr[0]);
  737. $fgbarr = explode(";",$molfgb); // cut off the n1bits value
  738. $molfgb = $fgbarr[0];
  739. $molhfp = trim($cr[1]);
  740. $hfparr = explode(";",$molhfp); // cut off the n1bits value
  741. $molhfp = $hfparr[0];
  742. //echo "molhfp: $molhfp\n";
  743. $molhfpsum = add_molfp($molhfpsum,$molhfp);
  744. $molfgbsum = add_molfp($molfgbsum,$molfgb);
  745. } // end for ($i = 0; $i < $npmol; $i++) ...
  746. //echo "added moldfp: $moldfpsum\n";
  747. //echo "added molhfp: $molhfpsum\n";
  748. // insert combined reaction fingerprints for product(s)
  749. $qstr = "INSERT INTO $rxncfptable VALUES ($next_rxn_id,'P',$moldfpsum,$molhfpsum,0)";
  750. //echo "adding combined fingerprints for no. $next_rxn_id to table $rxncfptable.... ";
  751. $result = mysql_query($qstr);
  752. $err = 0;
  753. $err = mysql_errno();
  754. if ($err != 0) {
  755. echo "<br />Action failed (#4c/$err: " . mysql_error() . ")<br />\n";
  756. $errorcount++;
  757. } // else { echo "done"; }
  758. // insert combined functional group bitstring for product(s)
  759. $qstr = "INSERT INTO $rxnfgbtable VALUES ($next_rxn_id,'P',$molfgbsum,0)";
  760. //echo "adding combined product functional group codes for no. $next_rxn_id to table $rxncfptable.... ";
  761. $result = mysql_query($qstr);
  762. $err = 0;
  763. $err = mysql_errno();
  764. if ($err != 0) {
  765. echo "<br />Action failed (#4d/$err: " . mysql_error() . ")<br />\n";
  766. $errorcount++;
  767. } // else { echo "done\n"; }
  768. }
  769. // re-apply the reaction maps after tweaking (checkmol strips the atom labels)
  770. if ($tweakmolfiles == "y") {
  771. $saferxn = $header;
  772. for ($nm = 0; $nm < $nrmol; $nm++) {
  773. $saferxn .= "\$MOL\r\n" . $rmol[$nm];
  774. }
  775. for ($nm = 0; $nm < $npmol; $nm++) {
  776. $saferxn .= "\$MOL\r\n" . $pmol[$nm];
  777. }
  778. $saferxn = apply_maps($saferxn,$mapstr);
  779. }
  780. $qstr = "INSERT INTO $rxnstructable (`rxn_id`, `struc`, `map`) VALUES ($next_rxn_id, \"$saferxn\", \"$mapstr\" )";
  781. //echo "adding reaction as no. $next_rxn_id to data collection $db_id ...";
  782. //echo "<pre>$qstr</pre>\n";
  783. $result = mysql_query($qstr);
  784. $err = 0;
  785. $err = mysql_errno();
  786. if ($err != 0) {
  787. echo "<br />Action failed (#1/$err: " . mysql_error() . ")<br />\n";
  788. $errorcount++;
  789. } // else { echo "done\n"; }
  790. // add new record to rxndatatable
  791. $qstr = "INSERT INTO $rxndatatable (`rxn_id`) VALUES (\"$next_rxn_id\")";
  792. //echo "adding reaction data for no. $next_rxn_id ...";
  793. $result = mysql_query($qstr);
  794. $err = 0;
  795. $err = mysql_errno();
  796. if ($err != 0) {
  797. echo "<br />Action failed (#6/$err: " . mysql_error() . ")<br />\n";
  798. $errorcount++;
  799. } // else { echo "done\n"; }
  800. echo "</pre>\n";
  801. if ($debug > 0) { debug_output("Action finished with $errorcount errors.<br />\n"); }
  802. if ($err == 0) {
  803. // JME needs MDL molfiles with the "|" character instead of linebreaks
  804. $jmehitmol = strtr($saferxn,"\n","|");
  805. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  806. echo "width=\"250\" height=\"120\">";
  807. echo "<param name=\"options\" value=\"depict\"> \n";
  808. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  809. echo "</applet>\n";
  810. echo "<p />\n";
  811. mk_dataeditform($next_rxn_id,2);
  812. } else {
  813. echo "something went wrong....<br />\n";
  814. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  815. }
  816. echo "</body></html>\n";
  817. die();
  818. }
  819. if ($action == "savedata") {
  820. global $db_id;
  821. global $datatype;
  822. global $moldatatable;
  823. global $rxndatatable;
  824. $item_id = $_POST["id"];
  825. if ($datatype == 2) {
  826. $idname = "rxn_id";
  827. $datatable = $rxndatatable;
  828. } else {
  829. $idname = "mol_id";
  830. $datatable = $moldatatable;
  831. }
  832. echo "<h3>Saving data for entry no. $item_id in data collection $db_id</h3>\n";
  833. echo "<table bgcolor=\"#eeeeee\">\n";
  834. echo "<tr align=\"left\"><th>Field:</th><th>Value:</th></tr>\n";
  835. $i = 0;
  836. $qstr = "SHOW FULL COLUMNS FROM $datatable";
  837. $result = mysql_query($qstr)
  838. or die("Query failed! (savedata)");
  839. $updstr = "UPDATE $datatable SET ";
  840. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  841. $field = $line["Field"];
  842. $type = $line["Type"];
  843. $comment = $line["Comment"];
  844. if ($field != $idname) {
  845. $i++;
  846. $newval = ""; //preliminary....
  847. $f = "f" . $i;
  848. $newval = $_POST[$f];
  849. echo "<tr><td>$field</td><td>$newval</td></tr>\n";
  850. if ($i > 1) { $updstr .= ","; }
  851. $updstr .= " $field = \"$newval\"";
  852. } // if...
  853. } // while
  854. $updstr .= " WHERE $idname = $item_id";
  855. echo "</table>\n";
  856. $result = mysql_query($updstr)
  857. or die("Save data failed!");
  858. echo "<h3>Done.</h3>\n";
  859. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  860. echo "</body></html>\n";
  861. die();
  862. } // action = savedata
  863. if ($action == "duplcopy") {
  864. $item_id = $_REQUEST["id"];
  865. if ($datatype == 2) {
  866. $idname = "rxn_id";
  867. $datatable = $rxndatatable;
  868. $structable = $rxnstructable;
  869. $dtstr = "RD";
  870. $what = "reaction";
  871. } else {
  872. $idname = "mol_id";
  873. $datatable = $moldatatable;
  874. $structable = $molstructable;
  875. $dtstr = "SD";
  876. $what = "structure";
  877. }
  878. // sanity checks...
  879. if (!is_numeric($item_id)) {
  880. echo "invalid input!</body></html>";
  881. } else {
  882. $qstr = "SELECT COUNT($idname) AS itemcount FROM $structable WHERE $idname = $item_id";
  883. $result = mysql_query($qstr) or die("Query failed! (struc 1)");
  884. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  885. $itemcount = $line["itemcount"];
  886. }
  887. mysql_free_result($result);
  888. if ($itemcount < 1) {
  889. echo "<h2>Entry no. $item_id in data collection $db_id ($dtstr)</h2>\n<hr />\n";
  890. echo "This entry does not exist!<br />\n";
  891. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  892. echo "</body></html>\n";
  893. die();
  894. }
  895. echo "<h2>Entry no. $item_id in data collection $db_id ($dtstr)</h2>\n<hr />\n";
  896. $molstruc = ""; // can be MOL or RXN
  897. $qstr = "SELECT struc FROM $structable WHERE $idname = $item_id";
  898. $result = mysql_query($qstr) or die("Query failed! (struc 2)");
  899. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  900. $molstruc = $line["struc"];
  901. }
  902. mysql_free_result($result);
  903. if ($molstruc == "") {
  904. echo "empty structure<br />\n";
  905. } else {
  906. // JME needs MDL molfiles with the "|" character instead of linebreaks
  907. $jmehitmol = strtr($molstruc,"\n","|");
  908. if ($datatype == 1) {
  909. $what1 = "Structure:";
  910. $what2 = "structure";
  911. $jmewidth = 250;
  912. } elseif ($datatype == 2) {
  913. $what1 = "Reaction:";
  914. $what2 = "reaction";
  915. $jmewidth = 450;
  916. }
  917. echo "<h3>$what1</h3>\n";
  918. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  919. echo "width=\"$jmewidth\" height=\"120\">";
  920. echo "<param name=\"options\" value=\"depict\"> \n";
  921. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  922. echo "</applet>\n";
  923. }
  924. echo "<p />\n";
  925. // show data fields
  926. $result4 = mysql_query("SELECT * FROM $datatable WHERE $idname = $item_id")
  927. or die("Query failed! (duplcopy)");
  928. $y = mysql_num_fields($result4);
  929. echo "<table bgcolor=\"#eeeeee\">\n";
  930. while ($line4 = mysql_fetch_array($result4, MYSQL_BOTH)) {
  931. for ($x = 0; $x < $y; $x++) {
  932. $fieldname = mysql_field_name($result4, $x);
  933. //$fieldtype = mysql_field_type($result4, $x);
  934. if (($fieldname != $idname) && ($line4[$fieldname] != "")) {
  935. //echo "<b>$fieldname:</b> \t$line4[$fieldname] <br />\n";
  936. echo "<tr>\n";
  937. echo " <td><b>$fieldname</b></td><td>$line4[$fieldname]</td>\n";
  938. echo "</tr>\n";
  939. }
  940. }
  941. echo "<br />\n";
  942. }
  943. echo "</table>\n";
  944. echo "<p />\n<hr />\n";
  945. // and now the buttons for duplicate and copy
  946. echo "<form name=\"edform1\" action=\"$myname\" method=post>\n";
  947. echo "<input type=\"hidden\" name=\"action\" value=\"duplicate\">\n";
  948. echo "<input type=\"hidden\" name=\"db\" value=\"$db_id\">\n";
  949. echo "<input type=\"hidden\" name=\"datatype\" value=\"$datatype\">\n";
  950. echo "<input type=\"hidden\" name=\"id\" value=\"$item_id\">\n";
  951. echo "<input type=\"Submit\" name=\"select\" value=\"Duplicate\"> this $what + all data fields in current data collection ($db_id)\n";
  952. echo "</form><p />\n";
  953. // now, get number of available data collections
  954. $db_list = array();
  955. $n_db = 0;
  956. $qstr5 = "SELECT db_id FROM $metatable WHERE (type = $datatype) AND (db_id != $db_id) ORDER BY db_id";
  957. $result5 = mysql_query($qstr5)
  958. or die("Query failed! (duplcopy 2)");
  959. while ($line5 = mysql_fetch_array($result5, MYSQL_BOTH)) {
  960. $db_list[$n_db] = $line5["db_id"];
  961. $n_db++;
  962. }
  963. if ($n_db > 0) {
  964. echo "<form name=\"edform1\" action=\"$myname\" method=post>\n";
  965. echo "<input type=\"hidden\" name=\"action\" value=\"copy\">\n";
  966. echo "<input type=\"hidden\" name=\"sourcedb\" value=\"$db_id\">\n";
  967. echo "<input type=\"hidden\" name=\"datatype\" value=\"$datatype\">\n";
  968. echo "<input type=\"hidden\" name=\"id\" value=\"$item_id\">\n";
  969. echo "<input type=\"Submit\" name=\"select\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Copy&nbsp;&nbsp;&nbsp;\"> this $what + name to data collection ";
  970. echo "<select size=\"1\" name=\"db\">\n";
  971. for ($i = 0; $i < $n_db; $i++) {
  972. $db = $db_list[$i];
  973. echo "<option value=\"$db\"";
  974. //if ($db == $db_id) { echo " selected"; }
  975. echo ">$db</option>\n";
  976. }
  977. echo "</select>\n";
  978. echo "</form><p />\n";
  979. } else { echo "no other data collections available for copying..."; }
  980. } // end if is_numeric(item_id)
  981. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  982. echo "</body></html>\n";
  983. die();
  984. }
  985. if (($action == "editdata") || ($action == "duplicate") || ($action == "copy")) {
  986. $item_id = $_REQUEST["id"];
  987. $sourcedb_id = $db_id;
  988. $targetdb_id = $db_id;
  989. if ($datatype == 2) {
  990. $idname = "rxn_id";
  991. $datatable = $rxndatatable;
  992. $datasuffix = $rxndatasuffix;
  993. $structable = $rxnstructable;
  994. $strucsuffix = $rxnstrucsuffix;
  995. $dtstr = "RD";
  996. } else {
  997. $idname = "mol_id";
  998. $datatable = $moldatatable;
  999. $datasuffix = $moldatasuffix;
  1000. $structable = $molstructable;
  1001. $strucsuffix = $molstrucsuffix;
  1002. $dtstr = "SD";
  1003. }
  1004. // sanity checks...
  1005. if (!is_numeric($item_id)) {
  1006. echo "invalid input!</body></html>";
  1007. } else {
  1008. if ($action == "copy") {
  1009. $sourcedb_id = $_REQUEST['sourcedb'];
  1010. $db_id = $sourcedb_id;
  1011. //echo "db_id: $db_id<br>sourcedb_id: $sourcedb_id<br>targetdb_id: $targetdb_id<br>";
  1012. }
  1013. $structable = $prefix . "db" . $db_id . "_" . $strucsuffix;
  1014. $qstr = "SELECT COUNT($idname) AS itemcount FROM $structable WHERE $idname = $item_id";
  1015. $result = mysql_query($qstr) or die("Query failed! (struc 1)");
  1016. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1017. $itemcount = $line["itemcount"];
  1018. }
  1019. mysql_free_result($result);
  1020. if ($itemcount < 1) {
  1021. echo "<h2>Entry no. $item_id in data collection $db_id ($dtstr)</h2>\n<hr />\n";
  1022. echo "This entry does not exist!<br />\n";
  1023. $db_id = $targetdb_id;
  1024. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  1025. echo "</body></html>\n";
  1026. die();
  1027. }
  1028. if ($action == "duplicate") {
  1029. if ($datatype == 1) {
  1030. $new_item_id = copy_mol($db_id,$item_id,$db_id);
  1031. $item_id = $new_item_id;
  1032. } elseif ($datatype == 2) {
  1033. $new_item_id = copy_rxn($db_id,$item_id,$db_id);
  1034. $item_id = $new_item_id;
  1035. }
  1036. }
  1037. if ($action == "copy") {
  1038. if ($datatype == 1) {
  1039. $new_item_id = copy_mol($db_id,$item_id,$targetdb_id);
  1040. if ($new_item_id > 0) {
  1041. $item_id = $new_item_id;
  1042. $db_id = $targetdb_id;
  1043. }
  1044. } elseif ($datatype == 2) {
  1045. $new_item_id = copy_rxn($db_id,$item_id,$targetdb_id);
  1046. if ($new_item_id > 0) {
  1047. $item_id = $new_item_id;
  1048. $db_id = $targetdb_id;
  1049. }
  1050. }
  1051. $structable = $prefix . "db" . $db_id . "_" . $strucsuffix;
  1052. }
  1053. echo "<h2>Entry no. $item_id in data collection $db_id ($dtstr)</h2>\n<hr />\n";
  1054. $molstruc = ""; // can be MOL or RXN
  1055. $qstr = "SELECT struc FROM $structable WHERE $idname = $item_id";
  1056. $result = mysql_query($qstr) or die("Query failed! (struc 2)");
  1057. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1058. $molstruc = $line["struc"];
  1059. }
  1060. mysql_free_result($result);
  1061. if ($molstruc == "") {
  1062. echo "empty structure<br />\n";
  1063. } else {
  1064. // JME needs MDL molfiles with the "|" character instead of linebreaks
  1065. $jmehitmol = strtr($molstruc,"\n","|");
  1066. if ($datatype == 1) {
  1067. $what1 = "Structure:";
  1068. $what2 = "structure";
  1069. $jmewidth = 250;
  1070. } elseif ($datatype == 2) {
  1071. $what1 = "Reaction:";
  1072. $what2 = "reaction";
  1073. $jmewidth = 450;
  1074. }
  1075. echo "<h3>$what1</h3>\n";
  1076. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  1077. echo "width=\"$jmewidth\" height=\"120\">";
  1078. echo "<param name=\"options\" value=\"depict\"> \n";
  1079. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  1080. echo "</applet>\n";
  1081. }
  1082. echo "<form name=\"strucform\" action=\"$myname\" method=\"post\">\n";
  1083. echo "<input type=\"hidden\" name=\"action\" value=\"editstruc\">\n";
  1084. echo "<input type=\"hidden\" name=\"db\" value=\"$db_id\">\n";
  1085. echo "<input type=\"hidden\" name=\"datatype\" value=\"$datatype\">\n";
  1086. echo "<input type=\"hidden\" name=\"id\" value=\"$item_id\">\n";
  1087. echo "<input type=\"Submit\" name=\"select\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Edit $what2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\">\n";
  1088. echo "</form>";
  1089. if ($datatype == 2) {
  1090. echo "<form name=\"strucform\" action=\"$myname\" method=\"post\">\n";
  1091. echo "<input type=\"hidden\" name=\"action\" value=\"extract\">\n";
  1092. echo "<input type=\"hidden\" name=\"db\" value=\"$db_id\">\n";
  1093. echo "<input type=\"hidden\" name=\"datatype\" value=\"$datatype\">\n";
  1094. echo "<input type=\"hidden\" name=\"id\" value=\"$item_id\">\n";
  1095. echo "<input type=\"Submit\" name=\"select\" value=\"Extract molecules\">\n";
  1096. echo "</form>";
  1097. }
  1098. if ($datatype == 1) {
  1099. echo "&nbsp;&nbsp;<small><a href=\"../showmol.php?mol=${item_id}&db=${db_id}&mode=txt\"";
  1100. echo " target=\"blank\">display molfile</a></small><p />\n";
  1101. } elseif ($datatype == 2) {
  1102. echo "&nbsp;&nbsp;<small><a href=\"../showmol.php?rxn=${item_id}&db=${db_id}&mode=txt\"";
  1103. echo " target=\"blank\">display rxnfile</a></small><p />\n";
  1104. }
  1105. echo "<p />\n<hr />\n";
  1106. mk_dataeditform($item_id,$datatype);
  1107. }
  1108. echo "<p /><a href=\"$myname?db=$sourcedb_id\">Continue without saving</a>\n";
  1109. echo "</body></html>\n";
  1110. die();
  1111. }
  1112. if (($action == "extract") && ($datatype == 2)) {
  1113. $item_id = $_REQUEST["id"];
  1114. $idname = "rxn_id";
  1115. $datatable = $rxndatatable;
  1116. $structable = $rxnstructable;
  1117. $dtstr = "RD";
  1118. // sanity checks...
  1119. if (!is_numeric($item_id)) {
  1120. echo "invalid input!</body></html>";
  1121. } else {
  1122. $qstr = "SELECT COUNT($idname) AS itemcount FROM $structable WHERE $idname = $item_id";
  1123. $result = mysql_query($qstr) or die("Query failed! (extract 1)");
  1124. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1125. $itemcount = $line["itemcount"];
  1126. }
  1127. mysql_free_result($result);
  1128. if ($itemcount < 1) {
  1129. echo "<h2>Entry no. $item_id in data collection $db_id ($dtstr)</h2>\n<hr />\n";
  1130. echo "This entry does not exist!<br />\n";
  1131. echo "<p /><a href=\"$myname?db=$db_id\">Continue</a>\n";
  1132. echo "</body></html>\n";
  1133. die();
  1134. }
  1135. echo "<h2>Entry no. $item_id in data collection $db_id ($dtstr)</h2>\n<hr />\n";
  1136. $molstruc = ""; // can be MOL or RXN
  1137. $qstr = "SELECT struc FROM $structable WHERE $idname = $item_id";
  1138. $result = mysql_query($qstr) or die("Query failed! (extract 2)");
  1139. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1140. $rxnstruc = $line["struc"];
  1141. }
  1142. mysql_free_result($result);
  1143. if ($rxnstruc == "") {
  1144. echo "empty reaction<br />\n";
  1145. } else {
  1146. // JME needs MDL molfiles with the "|" character instead of linebreaks
  1147. $jmehitmol = strtr($rxnstruc,"\n","|");
  1148. $what1 = "Reaction:";
  1149. $what2 = "reaction";
  1150. $jmewidth = 450;
  1151. echo "<h3>$what1</h3>\n";
  1152. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  1153. echo "width=\"$jmewidth\" height=\"120\">";
  1154. echo "<param name=\"options\" value=\"depict\"> \n";
  1155. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  1156. echo "</applet>\n";
  1157. }
  1158. echo "<hr />\n";
  1159. // get a list of all structure databases
  1160. $db_list = array();
  1161. $result1 = mysql_query("SELECT db_id FROM $metatable WHERE (type = 1) ORDER BY db_id")
  1162. or die("Query failed! (extract 3)");
  1163. $ndb = mysql_num_rows($result1);
  1164. $i = 0;
  1165. while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
  1166. $db = $line["db_id"];
  1167. $db_list[$i] = $db;
  1168. $i++;
  1169. }
  1170. mysql_free_result($result1);
  1171. // now split the rxnfile into pieces
  1172. $rxnstruc = str_replace("\n","\r\n",$rxnstruc);
  1173. $rxnstruc = str_replace("\r\r\n","\r\n",$rxnstruc);
  1174. $rxnstruc = strip_labels($rxnstruc);
  1175. $rxndescr = analyze_rxnfile($rxnstruc);
  1176. $nrmol = get_nrmol($rxndescr);
  1177. $npmol = get_npmol($rxndescr);
  1178. $allmol = array();
  1179. $allmol = explode("\$MOL\r\n",$rxnstruc);
  1180. $header = $allmol[0];
  1181. if ($nrmol > 0) {
  1182. echo "<h3>Reactants:</h3>\n";
  1183. for ($i = 0; $i < $nrmol; $i++) {
  1184. $rmol[$i] = $allmol[($i+1)];
  1185. $mnum = $i + 1;
  1186. echo " reactant no. $mnum<br>\n";
  1187. $jmehitmol = strtr($rmol[$i],"\n","|");
  1188. echo "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"100%\">\n";
  1189. echo "<tr align=\"left\">\n";
  1190. echo "<td width=\"20%\">\n";
  1191. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  1192. echo "width=\"250\" height=\"120\">";
  1193. echo "<param name=\"options\" value=\"depict\"> \n";
  1194. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  1195. echo "</applet>\n";
  1196. echo "</td>\n<td align=\"left\">\n";
  1197. echo "<br />\n";
  1198. if ($ndb > 0) {
  1199. echo "<form name=\"searchform\" action=\"../moldbsss.php\" method=\"post\">\n";
  1200. echo "<input type=\"hidden\" name=\"mode\" value=\"1\">\n";
  1201. echo "<input type=\"hidden\" name=\"mol\" value=\"$rmol[$i]\">\n";
  1202. //echo "<input type=\"hidden\" name=\"db\" value=\"2\">\n";
  1203. echo "<input type=\"Submit\" name=\"select\" value=\"Search\"> in data collection ";
  1204. echo "<select size=\"1\" name=\"db\">\n";
  1205. $j = 0;
  1206. foreach ($db_list as $db) {
  1207. echo "<option value=\"$db\"";
  1208. if ($j == 0) { echo " selected"; }
  1209. echo "> $db </option>\n";
  1210. $j++;
  1211. }
  1212. echo "</select>\n";
  1213. echo "</form>\n";
  1214. //echo "<pre>$rmol[$i]</pre>";
  1215. echo "<form name=\"copyform\" action=\"$myname\" method=\"post\">\n";
  1216. echo "<input type=\"hidden\" name=\"action\" value=\"addstruc2\">\n";
  1217. echo "<input type=\"hidden\" name=\"mol\" value=\"$rmol[$i]\">\n";
  1218. //echo "<input type=\"hidden\" name=\"db\" value=\"2\">\n";
  1219. echo "<input type=\"Submit\" name=\"select\" value=\"&nbsp;&nbsp;Copy&nbsp;&nbsp;\"> to data collection ";
  1220. echo "<select size=\"1\" name=\"db\">\n";
  1221. $i = 0;
  1222. foreach ($db_list as $db) {
  1223. echo "<option value=\"$db\"";
  1224. if ($i == 0) { echo " selected"; }
  1225. echo "> $db </option>\n";
  1226. $i++;
  1227. }
  1228. echo "</select>\n";
  1229. echo "</form><br /></td>";
  1230. } // end if ndb > 0
  1231. echo "</tr>\n</table>\n";
  1232. }
  1233. echo "<hr />\n";
  1234. } // end if nrmol > 0
  1235. if ($npmol > 0) {
  1236. echo "<h3>Products:</h3>\n";
  1237. for ($i = 0; $i < $npmol; $i++) {
  1238. $pmol[$i] = $allmol[($i+1+$nrmol)];
  1239. $mnum = $i + 1;
  1240. echo " product no. $mnum<br>\n";
  1241. $jmehitmol = strtr($pmol[$i],"\n","|");
  1242. echo "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"100%\">\n";
  1243. echo "<tr align=\"left\">\n";
  1244. echo "<td width=\"20%\">\n";
  1245. echo "<applet code=\"JME.class\" archive=\"../JME.jar\" \n";
  1246. echo "width=\"250\" height=\"120\">";
  1247. echo "<param name=\"options\" value=\"depict\"> \n";
  1248. echo "<param name=\"mol\" value=\"$jmehitmol\">\n";
  1249. echo "</applet>\n";
  1250. echo "</td>\n<td align=\"left\">\n";
  1251. echo "<br />\n";
  1252. if ($ndb > 0) {
  1253. echo "<form name=\"searchform\" action=\"../moldbsss.php\" method=\"post\">\n";
  1254. echo "<input type=\"hidden\" name=\"mode\" value=\"1\">\n";
  1255. echo "<input type=\"hidden\" name=\"mol\" value=\"$pmol[$i]\">\n";
  1256. //echo "<input type=\"hidden\" name=\"db\" value=\"2\">\…

Large files files are truncated, but you can click here to view the full file