pub_importers.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. /**
  3. * A function to render a listing of all publication importers
  4. *
  5. * @ingroup tripal_pub
  6. */
  7. function tripal_pub_importers_list() {
  8. // clear out the session variable when we view the list.
  9. unset($_SESSION['tripal_pub_import']);
  10. $header = array('', 'Importer Name', 'Database', 'Search String', 'Disabled', 'Create Contact', '');
  11. $rows = array();
  12. $importers = db_query("SELECT * FROM {tripal_pub_import} ORDER BY name");
  13. while ($importer = db_fetch_object($importers)) {
  14. $criteria = unserialize($importer->criteria);
  15. $num_criteria = $criteria['num_criteria'];
  16. $criteria_str = '';
  17. for ($i = 1; $i <= $num_criteria; $i++) {
  18. $search_terms = $criteria['criteria'][$i]['search_terms'];
  19. $scope = $criteria['criteria'][$i]['scope'];
  20. $is_phrase = $criteria['criteria'][$i]['is_phrase'];
  21. $operation = $criteria['criteria'][$i]['operation'];
  22. $criteria_str .= "$operation ($scope: $search_terms) ";
  23. }
  24. $rows[] = array(
  25. l(t('Edit/Test'), "admin/tripal/tripal_pub/import/edit/$importer->pub_import_id"),
  26. $importer->name,
  27. $criteria['remote_db'],
  28. $criteria_str,
  29. $importer->disabled ? 'Yes' : 'No',
  30. $importer->do_contact ? 'Yes' : 'No',
  31. l(t('Delete'), "admin/tripal/tripal_pub/import/delete/$importer->pub_import_id"),
  32. );
  33. }
  34. $rows[] = array(
  35. 'data' => array(
  36. array('data' => l(t('Create a new publication importer.'), "admin/tripal/tripal_pub/import/new"),
  37. 'colspan' => 7),
  38. )
  39. );
  40. $page = theme('table', $header, $rows);
  41. return $page;
  42. }
  43. /*
  44. *
  45. */
  46. function tripal_pub_importer_setup($action = 'new', $pub_import_id = NULL) {
  47. global $pager_total, $pager_total_items;
  48. $pager_id = 0;
  49. $limit = 20;
  50. // generate the search form
  51. $form = drupal_get_form('tripal_pub_importer_setup_form', $pub_import_id, $action);
  52. $output = l("Return to publication importers list", "admin/tripal/tripal_pub/import_list");
  53. $output .= $form;
  54. // retrieve any results
  55. $remote_db = $_SESSION['tripal_pub_import']['remote_db'];
  56. $num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
  57. $days = $_SESSION['tripal_pub_import']['days'];
  58. $search_array = array();
  59. $search_array['remote_db'] = $remote_db;
  60. $search_array['num_criteria'] = $num_criteria;
  61. $search_array['days'] = $days;
  62. for ($i = 1; $i <= $num_criteria; $i++) {
  63. $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'];
  64. $search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_import']['criteria'][$i]['scope'];
  65. $search_array['criteria'][$i]['is_phrase'] = $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'];
  66. $search_array['criteria'][$i]['operation'] = $_SESSION['tripal_pub_import']['criteria'][$i]['operation'];
  67. }
  68. if ($_SESSION['tripal_pub_import']['perform_search']) {
  69. // get the list of publications from the remote database using the search criteria.
  70. $pubs = tripal_pub_get_remote_search_results($remote_db, $search_array, $limit, $pager_id);
  71. //dpm($pubs);
  72. // generate the pager
  73. $total_pages = $pager_total[$pager_id];
  74. $total_items = $pager_total_items[$pager_id];
  75. $page = isset($_GET['page']) ? $_GET['page'] : '0';
  76. $pager = theme('pager');
  77. // iterate through the results and construct the table displaying the publications
  78. $rows = array();
  79. $i = $page * $limit + 1;
  80. if (count($pubs) > 0) {
  81. foreach ($pubs as $pub) {
  82. $citation = htmlspecialchars($pub['Citation']);
  83. $raw_link = '';
  84. if($pub['Publication Dbxref']) {
  85. $raw_link = l('raw', 'admin/tripal/tripal_pub/import/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
  86. }
  87. $rows[] = array(
  88. number_format($i),
  89. $citation,
  90. $raw_link,
  91. );
  92. $i++;
  93. }
  94. }
  95. $headers = array('', 'Publication', '');
  96. $table = theme('table', $headers, $rows);
  97. // join all to form the results
  98. $output .= "<br><p><b>Found " . number_format($total_items) .
  99. ". Page " . ($page + 1) . " of $total_pages. " .
  100. " Results</b></br>" . $table . '</p>' . $pager;
  101. }
  102. return $output;
  103. }
  104. /*
  105. *
  106. */
  107. function theme_tripal_pub_importer_setup_form($form) {
  108. $rows = array();
  109. foreach ($form['criteria'] as $i => $element) {
  110. if(is_numeric($i)) {
  111. $rows[] = array(
  112. drupal_render($element["operation-$i"]),
  113. drupal_render($element["scope-$i"]),
  114. drupal_render($element["search_terms-$i"]),
  115. drupal_render($element["is_phrase-$i"]),
  116. drupal_render($element["add-$i"]) . drupal_render($element["remove-$i"]),
  117. );
  118. }
  119. }
  120. $headers = array('Operation','Scope', 'Search Terms', '','');
  121. $markup = '';
  122. $markup .= '<div>' . drupal_render($form['remote_db']) . '</div>';
  123. $markup .= '<div id="pub-search-form-row1">';
  124. $markup .= ' <div id="pub-search-form-col1">' . drupal_render($form['loader_name']) . '</div>';
  125. $markup .= ' <div id="pub-search-form-col3">' . drupal_render($form['days']) . '</div>';
  126. $markup .= '</div>';
  127. $markup .= '<div id="pub-search-form-row2">' . drupal_render($form['disabled']) . '</div>';
  128. $markup .= '<div id="pub-search-form-row3">' . drupal_render($form['do_contact']) . '</div>';
  129. $markup .= theme('table', $headers, $rows, array('id' => 'tripal-pub-importer-table'));
  130. $form['criteria'] = array(
  131. '#type' => 'markup',
  132. '#value' => $markup,
  133. '#weight' => -10,
  134. );
  135. return drupal_render($form);
  136. }
  137. /**
  138. * Purpose: Provides the form to search pubmed
  139. *
  140. * @ingroup tripal_pub
  141. */
  142. function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NULL, $action = 'new') {
  143. tripal_core_ahah_init_form();
  144. // Set the default values. If the pub_import_id isn't already defined by the form values
  145. // and one is provided then look it up in the database
  146. $criteria = NULL;
  147. if ($action == "edit" and !$form_state['values']) {
  148. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = %d";
  149. $importer = db_fetch_object(db_query($sql, $pub_import_id));
  150. $criteria = unserialize($importer->criteria);
  151. $remote_db = $criteria['remote_db'];
  152. $days = $criteria['days'];
  153. $disabled = $criteria['disabled'];
  154. $do_contact = $criteria['do_contact'];
  155. $num_criteria = $criteria['num_criteria'];
  156. $loader_name = $criteria['loader_name'];
  157. }
  158. // if we're here because the form was posted then load from the session variable (we lost the form state)
  159. $num_criteria = isset($_SESSION['tripal_pub_import']['num_criteria']) ? $_SESSION['tripal_pub_import']['num_criteria'] : $num_criteria;
  160. $loader_name = isset($_SESSION['tripal_pub_import']['loader_name']) ? $_SESSION['tripal_pub_import']['loader_name'] : $loader_name;
  161. $remote_db = isset($_SESSION['tripal_pub_import']['remote_db']) ? $_SESSION['tripal_pub_import']['remote_db'] : $remote_db;
  162. $disabled = isset($_SESSION['tripal_pub_import']['disabled']) ? $_SESSION['tripal_pub_import']['disabled'] : $disabled;
  163. $do_contact = isset($_SESSION['tripal_pub_import']['do_contact']) ? $_SESSION['tripal_pub_import']['do_contact'] : $do_contact;
  164. $days = isset($_SESSION['tripal_pub_import']['days']) ? $_SESSION['tripal_pub_import']['days'] : $days;
  165. // If the form_state has variables then use those. This happens when an error occurs on the form or the
  166. // form is resbumitted using AJAX
  167. if ($form_state['values']) {
  168. $num_criteria = $form_state['values']['num_criteria'] ? $form_state['values']['num_criteria'] : $num_criteria;
  169. $loader_name = $form_state['values']['loader_name'] ? $form_state['values']['loader_name'] : $loader_name;
  170. $remote_db = $form_state['values']['remote_db'] ? $form_state['values']['remote_db'] : $remote_db;
  171. $disabled = $form_state['values']['disabled'] ? $form_state['values']['disabled'] : $disabled;
  172. $do_contact = $form_state['values']['do_contact'] ? $form_state['values']['do_contact'] : $do_contact;
  173. $days = $form_state['values']['days'] ? $form_state['values']['days'] : $days;
  174. }
  175. // check if the pub_import_id in the session variable is not the same as the one we've been provided
  176. // if so, then clear the session variable
  177. if ($pub_import_id and $pub_import_id != $_SESSION['tripal_pub_import']['pub_import_id']) {
  178. unset($_SESSION['tripal_pub_import']);
  179. }
  180. // change the number of criteria based on form_state post data.
  181. if (!$num_criteria) {
  182. $num_criteria = 1;
  183. }
  184. if($form_state['post']["add-$num_criteria"]) {
  185. $num_criteria++;
  186. }
  187. if($form_state['post']["remove-$num_criteria"]) {
  188. $num_criteria--;
  189. }
  190. $form['pub_import_id'] = array(
  191. '#type' => 'hidden',
  192. '#value' => $pub_import_id,
  193. '#required' => TRUE,
  194. );
  195. $form['action'] = array(
  196. '#type' => 'hidden',
  197. '#value' => $action,
  198. '#required' => TRUE,
  199. );
  200. $form['loader_name'] = array(
  201. '#type' => 'textfield',
  202. '#title' => t('Loader Name'),
  203. '#description' => t('Please provide a name for this loader setup..'),
  204. '#default_value' => $loader_name,
  205. '#required' => TRUE,
  206. );
  207. $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
  208. $remote_dbs = array();
  209. $values = array(
  210. 'name' => $supported_dbs,
  211. );
  212. $dbs = tripal_core_chado_select('db', array('*'), $values);
  213. foreach ($dbs as $index => $db) {
  214. $remote_dbs[$db->name] = $db->description;
  215. };
  216. // use PubMed as the default
  217. if (!$remote_db) {
  218. $remote_db = 'PMID';
  219. }
  220. $form['remote_db'] = array(
  221. '#title' => t('Remote Database'),
  222. '#type' => 'select',
  223. '#options' => $remote_dbs,
  224. '#default_value' => $remote_db,
  225. '#ahah' => array(
  226. 'path' => "admin/tripal/tripal_pub/import/changedb",
  227. 'wrapper' => 'tripal-pub-importer-setup-form',
  228. 'event' => 'click',
  229. 'method' => 'replace',
  230. ),
  231. );
  232. $form['num_criteria']= array(
  233. '#type' => 'hidden',
  234. '#default_value' => $num_criteria,
  235. );
  236. $form['pub_import_id']= array(
  237. '#type' => 'hidden',
  238. '#default_value' => $pub_import_id,
  239. );
  240. $form['days'] = array(
  241. '#type' => 'textfield',
  242. '#title' => t('Days since record modified'),
  243. '#description' => t('Limit the search to include pubs that have been added no more than this many days before today.'),
  244. '#default_value' => $days,
  245. '#size' => 5,
  246. );
  247. $form['disabled'] = array(
  248. '#type' => 'checkbox',
  249. '#title' => t('Disabled'),
  250. '#description' => t('Check to disable this importer.'),
  251. '#default_value' => $disabled,
  252. );
  253. $form['do_contact'] = array(
  254. '#type' => 'checkbox',
  255. '#title' => t('Create Contact'),
  256. '#description' => t('Check to create an entry in the contact table for each author of a matching publication during import. This allows storage of
  257. additional information such as affilation, etc. Otherwise, only authors names are retrieved.'),
  258. '#default_value' => $do_contact,
  259. );
  260. // choices array
  261. $scope_choices = array(
  262. 'any' => 'Any Field',
  263. 'abstract' => 'Abstract',
  264. 'author' => 'Author',
  265. 'id' => 'Accession',
  266. 'title' => 'Title',
  267. 'journal' => 'Journal Name'
  268. );
  269. $first_op_choices = array(
  270. '' => '',
  271. 'NOT' => 'NOT'
  272. );
  273. $op_choices = array(
  274. 'AND' => 'AND',
  275. 'OR' => 'OR',
  276. 'NOT' => 'NOT'
  277. );
  278. for($i = 1; $i <= $num_criteria; $i++) {
  279. // if we have criteria supplied from the database then use that as the initial defaults
  280. if ($criteria) {
  281. $search_terms = $criteria['criteria'][$i]['search_terms'];
  282. $scope = $criteria['criteria'][$i]['scope'];
  283. $is_phrase = $criteria['criteria'][$i]['is_phrase'];
  284. $operation = $criteria['criteria'][$i]['operation'];
  285. }
  286. // if we're here because the form was posted then load from the session variable (we lost the form state)
  287. $search_terms = isset($_SESSION['tripal_pub_import']['criteria'][$i]['search_terms']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'] : $search_terms;
  288. $scope = isset($_SESSION['tripal_pub_import']['criteria'][$i]['scope']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['scope'] : $scope;
  289. $is_phrase = isset($_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'] : $is_phrase;
  290. $operation = isset($_SESSION['tripal_pub_import']['criteria'][$i]['operation']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['operation'] : $operation;
  291. // If the form_state has variables then use those. This happens when an error occurs on the form or the
  292. // form is resbumitted using AJAX
  293. if ($form_state['values']) {
  294. $search_terms = $form_state['values']["search_terms-$i"];
  295. $scope = $form_state['values']["scope-$i"];
  296. $is_phrase = $form_state['values']["is_phrase-$i"];
  297. $operation = $form_state['values']["operation-$i"];
  298. }
  299. $form['criteria'][$i]["search_terms-$i"] = array(
  300. '#type' => 'textfield',
  301. '#description' => t('Please provide a list of words for searching. You may use
  302. conjunctions such as "AND" or "OR" to separate words if they are expected in
  303. the same scope. Uncheck the "Is Phrase" checkbox to use conjunctions'),
  304. '#default_value' => $search_terms,
  305. '#required' => TRUE,
  306. );
  307. $form['criteria'][$i]["scope-$i"] = array(
  308. '#type' => 'select',
  309. '#description' => t('Please select the fields to search for this term.'),
  310. '#options' => $scope_choices,
  311. '#default_value' => $scope,
  312. );
  313. $form['criteria'][$i]["is_phrase-$i"] = array(
  314. '#type' => 'checkbox',
  315. '#title' => t('Is Phrase?'),
  316. '#default_value' => $is_phrase,
  317. );
  318. if ($i == 1) {
  319. /*
  320. $form['criteria'][$i]["operation-$i"] = array(
  321. '#type' => 'select',
  322. '#options' => $first_op_choices,
  323. '#default_value' => $operation,
  324. );*/
  325. }
  326. if ($i > 1) {
  327. $form['criteria'][$i]["operation-$i"] = array(
  328. '#type' => 'select',
  329. '#options' => $op_choices,
  330. '#default_value' => $operation,
  331. );
  332. }
  333. if ($i == $num_criteria) {
  334. if($i > 1) {
  335. $form['criteria'][$i]["remove-$i"] = array(
  336. '#type' => 'image_button',
  337. '#value' => t('Remove'),
  338. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  339. '#ahah' => array(
  340. 'path' => "admin/tripal/tripal_pub/import/criteria/minus/$i",
  341. 'wrapper' => 'tripal-pub-importer-setup-form',
  342. 'event' => 'click',
  343. 'method' => 'replace',
  344. ),
  345. '#attributes' => array('onClick' => 'return false;'),
  346. );
  347. }
  348. $form['criteria'][$i]["add-$i"] = array(
  349. '#type' => 'image_button',
  350. '#value' => t('Add'),
  351. '#src' => drupal_get_path('theme', 'tripal') . '/images/add.png',
  352. '#ahah' => array(
  353. 'path' => "admin/tripal/tripal_pub/import/criteria/add/$i",
  354. 'wrapper' => 'tripal-pub-importer-setup-form',
  355. 'event' => 'click',
  356. 'method' => 'replace',
  357. ),
  358. '#attributes' => array('onClick' => 'return false;'),
  359. );
  360. }
  361. }
  362. $form['test'] = array(
  363. '#type' => 'submit',
  364. '#value' => t('Test Importer'),
  365. );
  366. $form['save'] = array(
  367. '#type' => 'submit',
  368. '#value' => t('Save Importer'),
  369. );
  370. /*
  371. $form['import'] = array(
  372. '#type' => 'submit',
  373. '#value' => t('Save & Import Now'),
  374. );*/
  375. $form['delete'] = array(
  376. '#type' => 'submit',
  377. '#value' => t('Delete Importer'),
  378. );
  379. // allow the selected remote database to make changes to the form if needed
  380. $callback = "tripal_pub_remote_alter_form_$remote_db";
  381. call_user_func($callback, &$form, $form_state);
  382. return $form;
  383. }
  384. /**
  385. *
  386. */
  387. function tripal_pub_importer_setup_form_validate($form, &$form_state) {
  388. $num_criteria = $form_state['values']['num_criteria'];
  389. $remote_db = $form_state['values']["remote_db"];
  390. $days = trim($form_state['values']["days"]);
  391. $disabled = $form_state['values']["disabled"];
  392. $do_contact = $form_state['values']["do_contact"];
  393. $loader_name = trim($form_state['values']["loader_name"]);
  394. for ($i = 1; $i <= $num_criteria; $i++) {
  395. $search_terms = trim($form_state['values']["search_terms-$i"]);
  396. $scope = $form_state['values']["scope-$i"];
  397. $is_phrase = $form_state['values']["is_phrase-$i"];
  398. $operation = $form_state['values']["operation-$i"];
  399. }
  400. if ($days and !is_numeric($days) or preg_match('/\./', $days)) {
  401. form_set_error("days", "Please enter a numeric, non decimal value, for the number of days.");
  402. }
  403. // allow the selected remote database to validate any changes to the form if needed
  404. $callback = "tripal_pub_remote_validate_form_$remote_db";
  405. call_user_func($callback, &$form, $form_state);
  406. }
  407. /**
  408. *
  409. */
  410. function tripal_pub_importer_setup_form_submit($form, &$form_state) {
  411. $pub_import_id = $form_state['values']['pub_import_id'];
  412. $num_criteria = $form_state['values']['num_criteria'];
  413. $remote_db = $form_state['values']["remote_db"];
  414. $days = trim($form_state['values']["days"]);
  415. $loader_name = trim($form_state['values']["loader_name"]);
  416. $disabled = $form_state['values']["disabled"];
  417. $do_contact = $form_state['values']["do_contact"];
  418. // set the session variables
  419. $_SESSION['tripal_pub_import']['remote_db'] = $remote_db;
  420. $_SESSION['tripal_pub_import']['days'] = $days;
  421. $_SESSION['tripal_pub_import']['num_criteria'] = $num_criteria;
  422. $_SESSION['tripal_pub_import']['loader_name'] = $loader_name;
  423. $_SESSION['tripal_pub_import']['disabled'] = $disabled;
  424. $_SESSION['tripal_pub_import']['do_contact'] = $do_contact;
  425. $_SESSION['tripal_pub_import']['pub_import_id'] = $pub_import_id;
  426. unset($_SESSION['tripal_pub_import']['criteria']);
  427. for ($i = 1; $i <= $num_criteria; $i++) {
  428. $search_terms = trim($form_state['values']["search_terms-$i"]);
  429. $scope = $form_state['values']["scope-$i"];
  430. $is_phrase = $form_state['values']["is_phrase-$i"];
  431. $operation = $form_state['values']["operation-$i"];
  432. $_SESSION['tripal_pub_import']['criteria'][$i] = array(
  433. 'search_terms' => $search_terms,
  434. 'scope' => $scope,
  435. 'is_phrase' => $is_phrase,
  436. 'operation' => $operation
  437. );
  438. }
  439. // now perform the appropriate action for the button clicked
  440. if ($form_state['values']['op'] == 'Test Importer') {
  441. $_SESSION['tripal_pub_import']['perform_search'] = 1;
  442. }
  443. if ($form_state['values']['op'] == 'Save Importer' or
  444. $form_state['values']['op'] == 'Save & Import Now') {
  445. $record = array(
  446. 'name' => $loader_name,
  447. 'criteria' => serialize($_SESSION['tripal_pub_import']),
  448. 'disabled' => $disabled,
  449. 'do_contact' => $do_contact
  450. );
  451. // first check to see if this pub_import_id is already present. If so,
  452. // do an update rather than an insert
  453. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = %d";
  454. $importer = db_fetch_object(db_query($sql, $pub_import_id));
  455. if($importer) {
  456. // do the update
  457. $record['pub_import_id'] = $pub_import_id;
  458. if(drupal_write_record('tripal_pub_import', $record, 'pub_import_id')){
  459. unset($_SESSION['tripal_pub_import']);
  460. drupal_set_message('Publication import settings updated.');
  461. drupal_goto('admin/tripal/tripal_pub/import_list');
  462. }
  463. else {
  464. drupal_set_message('Could not update publication import settings.', 'error');
  465. }
  466. }
  467. else {
  468. // do the insert
  469. if(drupal_write_record('tripal_pub_import', $record)){
  470. unset($_SESSION['tripal_pub_import']);
  471. drupal_set_message('Publication import settings saved.');
  472. // if the user wants to do the import now then do it (may time out
  473. // for long jobs)
  474. if ($form_state['values']['op'] == 'Save & Import Now') {
  475. tripal_pub_import_publications($record['pub_import_id']);
  476. }
  477. drupal_goto('admin/tripal/tripal_pub/import_list');
  478. }
  479. else {
  480. drupal_set_message('Could not save publication import settings.', 'error');
  481. }
  482. }
  483. }
  484. if ($form_state['values']['op'] == 'Delete Importer') {
  485. $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = %d";
  486. $success = db_query($sql, $pub_import_id);
  487. if ($success) {
  488. drupal_set_message('Publication importer deleted.');
  489. drupal_goto('admin/tripal/tripal_pub/import_list');
  490. }
  491. else {
  492. drupal_set_message('Could not delete publication importer.', 'error');
  493. }
  494. }
  495. }
  496. /*
  497. *
  498. */
  499. function tripal_pub_importer_delete($pub_import_id) {
  500. $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = %d";
  501. $success = db_query($sql, $pub_import_id);
  502. if ($success) {
  503. drupal_set_message('Publication importer deleted.');
  504. drupal_goto('admin/tripal/tripal_pub/import_list');
  505. }
  506. else {
  507. drupal_set_message('Could not delete publication importer.', 'error');
  508. }
  509. }
  510. /*
  511. * AHAH callback
  512. */
  513. function tripal_pub_importer_setup_page_update_remotedb() {
  514. $status = TRUE;
  515. // prepare and render the form
  516. $form = tripal_core_ahah_prepare_form();
  517. $data = theme('tripal_pub_importer_setup_form', $form);
  518. // bind javascript events to the new objects that will be returned
  519. // so that AHAH enabled elements will work.
  520. $settings = tripal_core_ahah_bind_events();
  521. // return the updated JSON
  522. drupal_json(
  523. array(
  524. 'status' => $status,
  525. 'data' => $data,
  526. 'settings' => $settings,
  527. )
  528. );
  529. }
  530. /*
  531. * AHAH callback
  532. */
  533. function tripal_pub_importer_setup_page_update_criteria($action, $i) {
  534. $status = TRUE;
  535. // prepare and render the form
  536. $form = tripal_core_ahah_prepare_form();
  537. $data = theme('tripal_pub_importer_setup_form', $form);
  538. // bind javascript events to the new objects that will be returned
  539. // so that AHAH enabled elements will work.
  540. $settings = tripal_core_ahah_bind_events();
  541. // return the updated JSON
  542. drupal_json(
  543. array(
  544. 'status' => $status,
  545. 'data' => $data,
  546. 'settings' => $settings,
  547. )
  548. );
  549. }