pub_importers.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. $is_phrase = 1;
  280. // if we have criteria supplied from the database then use that as the initial defaults
  281. if ($criteria) {
  282. $search_terms = $criteria['criteria'][$i]['search_terms'];
  283. $scope = $criteria['criteria'][$i]['scope'];
  284. $is_phrase = $criteria['criteria'][$i]['is_phrase'];
  285. $operation = $criteria['criteria'][$i]['operation'];
  286. }
  287. // if we're here because the form was posted then load from the session variable (we lost the form state)
  288. $search_terms = isset($_SESSION['tripal_pub_import']['criteria'][$i]['search_terms']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'] : $search_terms;
  289. $scope = isset($_SESSION['tripal_pub_import']['criteria'][$i]['scope']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['scope'] : $scope;
  290. $is_phrase = isset($_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'] : $is_phrase;
  291. $operation = isset($_SESSION['tripal_pub_import']['criteria'][$i]['operation']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['operation'] : $operation;
  292. // If the form_state has variables then use those. This happens when an error occurs on the form or the
  293. // form is resbumitted using AJAX
  294. if ($form_state['values']) {
  295. $search_terms = $form_state['values']["search_terms-$i"];
  296. $scope = $form_state['values']["scope-$i"];
  297. $is_phrase = $form_state['values']["is_phrase-$i"];
  298. $operation = $form_state['values']["operation-$i"];
  299. }
  300. $form['criteria'][$i]["search_terms-$i"] = array(
  301. '#type' => 'textfield',
  302. '#description' => t('Please provide a list of words for searching. You may use
  303. conjunctions such as "AND" or "OR" to separate words if they are expected in
  304. the same scope, but do not mix ANDs and ORs. Uncheck the "Is Phrase" checkbox to use conjunctions'),
  305. '#default_value' => $search_terms,
  306. '#required' => TRUE,
  307. '#maxlength' => 2048,
  308. );
  309. $form['criteria'][$i]["scope-$i"] = array(
  310. '#type' => 'select',
  311. '#description' => t('Please select the fields to search for this term.'),
  312. '#options' => $scope_choices,
  313. '#default_value' => $scope,
  314. );
  315. $form['criteria'][$i]["is_phrase-$i"] = array(
  316. '#type' => 'checkbox',
  317. '#title' => t('Is Phrase?'),
  318. '#default_value' => $is_phrase,
  319. );
  320. if ($i == 1) {
  321. /*
  322. $form['criteria'][$i]["operation-$i"] = array(
  323. '#type' => 'select',
  324. '#options' => $first_op_choices,
  325. '#default_value' => $operation,
  326. );*/
  327. }
  328. if ($i > 1) {
  329. $form['criteria'][$i]["operation-$i"] = array(
  330. '#type' => 'select',
  331. '#options' => $op_choices,
  332. '#default_value' => $operation,
  333. );
  334. }
  335. if ($i == $num_criteria) {
  336. if($i > 1) {
  337. $form['criteria'][$i]["remove-$i"] = array(
  338. '#type' => 'image_button',
  339. '#value' => t('Remove'),
  340. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  341. '#ahah' => array(
  342. 'path' => "admin/tripal/tripal_pub/import/criteria/minus/$i",
  343. 'wrapper' => 'tripal-pub-importer-setup-form',
  344. 'event' => 'click',
  345. 'method' => 'replace',
  346. ),
  347. '#attributes' => array('onClick' => 'return false;'),
  348. );
  349. }
  350. $form['criteria'][$i]["add-$i"] = array(
  351. '#type' => 'image_button',
  352. '#value' => t('Add'),
  353. '#src' => drupal_get_path('theme', 'tripal') . '/images/add.png',
  354. '#ahah' => array(
  355. 'path' => "admin/tripal/tripal_pub/import/criteria/add/$i",
  356. 'wrapper' => 'tripal-pub-importer-setup-form',
  357. 'event' => 'click',
  358. 'method' => 'replace',
  359. ),
  360. '#attributes' => array('onClick' => 'return false;'),
  361. );
  362. }
  363. }
  364. $form['test'] = array(
  365. '#type' => 'submit',
  366. '#value' => t('Test Importer'),
  367. );
  368. $form['save'] = array(
  369. '#type' => 'submit',
  370. '#value' => t('Save Importer'),
  371. );
  372. /*
  373. $form['import'] = array(
  374. '#type' => 'submit',
  375. '#value' => t('Save & Import Now'),
  376. );*/
  377. $form['delete'] = array(
  378. '#type' => 'submit',
  379. '#value' => t('Delete Importer'),
  380. );
  381. // allow the selected remote database to make changes to the form if needed
  382. $callback = "tripal_pub_remote_alter_form_$remote_db";
  383. call_user_func($callback, &$form, $form_state);
  384. return $form;
  385. }
  386. /**
  387. *
  388. */
  389. function tripal_pub_importer_setup_form_validate($form, &$form_state) {
  390. $num_criteria = $form_state['values']['num_criteria'];
  391. $remote_db = $form_state['values']["remote_db"];
  392. $days = trim($form_state['values']["days"]);
  393. $disabled = $form_state['values']["disabled"];
  394. $do_contact = $form_state['values']["do_contact"];
  395. $loader_name = trim($form_state['values']["loader_name"]);
  396. for ($i = 1; $i <= $num_criteria; $i++) {
  397. $search_terms = trim($form_state['values']["search_terms-$i"]);
  398. $scope = $form_state['values']["scope-$i"];
  399. $is_phrase = $form_state['values']["is_phrase-$i"];
  400. $operation = $form_state['values']["operation-$i"];
  401. if (!$is_phrase) {
  402. if (preg_match('/and/i', $search_terms) and preg_match('/or/i', $search_terms)) {
  403. form_set_error("search_terms-$i", "You may use 'AND' or 'OR' but cannot use both. Add a new entry below with the same scope for the other conunction.");
  404. $_SESSION['tripal_pub_import']['perform_search'] = 0;
  405. }
  406. }
  407. }
  408. if ($days and !is_numeric($days) or preg_match('/\./', $days)) {
  409. form_set_error("days", "Please enter a numeric, non decimal value, for the number of days.");
  410. $_SESSION['tripal_pub_import']['perform_search'] = 0;
  411. }
  412. // allow the selected remote database to validate any changes to the form if needed
  413. $callback = "tripal_pub_remote_validate_form_$remote_db";
  414. call_user_func($callback, &$form, $form_state);
  415. }
  416. /**
  417. *
  418. */
  419. function tripal_pub_importer_setup_form_submit($form, &$form_state) {
  420. $pub_import_id = $form_state['values']['pub_import_id'];
  421. $num_criteria = $form_state['values']['num_criteria'];
  422. $remote_db = $form_state['values']["remote_db"];
  423. $days = trim($form_state['values']["days"]);
  424. $loader_name = trim($form_state['values']["loader_name"]);
  425. $disabled = $form_state['values']["disabled"];
  426. $do_contact = $form_state['values']["do_contact"];
  427. // set the session variables
  428. $_SESSION['tripal_pub_import']['remote_db'] = $remote_db;
  429. $_SESSION['tripal_pub_import']['days'] = $days;
  430. $_SESSION['tripal_pub_import']['num_criteria'] = $num_criteria;
  431. $_SESSION['tripal_pub_import']['loader_name'] = $loader_name;
  432. $_SESSION['tripal_pub_import']['disabled'] = $disabled;
  433. $_SESSION['tripal_pub_import']['do_contact'] = $do_contact;
  434. $_SESSION['tripal_pub_import']['pub_import_id'] = $pub_import_id;
  435. unset($_SESSION['tripal_pub_import']['criteria']);
  436. for ($i = 1; $i <= $num_criteria; $i++) {
  437. $search_terms = trim($form_state['values']["search_terms-$i"]);
  438. $scope = $form_state['values']["scope-$i"];
  439. $is_phrase = $form_state['values']["is_phrase-$i"];
  440. $operation = $form_state['values']["operation-$i"];
  441. $_SESSION['tripal_pub_import']['criteria'][$i] = array(
  442. 'search_terms' => $search_terms,
  443. 'scope' => $scope,
  444. 'is_phrase' => $is_phrase,
  445. 'operation' => $operation
  446. );
  447. }
  448. // now perform the appropriate action for the button clicked
  449. if ($form_state['values']['op'] == 'Test Importer') {
  450. $_SESSION['tripal_pub_import']['perform_search'] = 1;
  451. }
  452. if ($form_state['values']['op'] == 'Save Importer' or
  453. $form_state['values']['op'] == 'Save & Import Now') {
  454. $record = array(
  455. 'name' => $loader_name,
  456. 'criteria' => serialize($_SESSION['tripal_pub_import']),
  457. 'disabled' => $disabled,
  458. 'do_contact' => $do_contact
  459. );
  460. // first check to see if this pub_import_id is already present. If so,
  461. // do an update rather than an insert
  462. $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = %d";
  463. $importer = db_fetch_object(db_query($sql, $pub_import_id));
  464. if($importer) {
  465. // do the update
  466. $record['pub_import_id'] = $pub_import_id;
  467. if(drupal_write_record('tripal_pub_import', $record, 'pub_import_id')){
  468. unset($_SESSION['tripal_pub_import']);
  469. drupal_set_message('Publication import settings updated.');
  470. drupal_goto('admin/tripal/tripal_pub/import_list');
  471. }
  472. else {
  473. drupal_set_message('Could not update publication import settings.', 'error');
  474. }
  475. }
  476. else {
  477. // do the insert
  478. if(drupal_write_record('tripal_pub_import', $record)){
  479. unset($_SESSION['tripal_pub_import']);
  480. drupal_set_message('Publication import settings saved.');
  481. // if the user wants to do the import now then do it (may time out
  482. // for long jobs)
  483. if ($form_state['values']['op'] == 'Save & Import Now') {
  484. tripal_pub_import_publications($record['pub_import_id']);
  485. }
  486. drupal_goto('admin/tripal/tripal_pub/import_list');
  487. }
  488. else {
  489. drupal_set_message('Could not save publication import settings.', 'error');
  490. }
  491. }
  492. }
  493. if ($form_state['values']['op'] == 'Delete Importer') {
  494. $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = %d";
  495. $success = db_query($sql, $pub_import_id);
  496. if ($success) {
  497. drupal_set_message('Publication importer deleted.');
  498. drupal_goto('admin/tripal/tripal_pub/import_list');
  499. }
  500. else {
  501. drupal_set_message('Could not delete publication importer.', 'error');
  502. }
  503. }
  504. }
  505. /*
  506. *
  507. */
  508. function tripal_pub_importer_delete($pub_import_id) {
  509. $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = %d";
  510. $success = db_query($sql, $pub_import_id);
  511. if ($success) {
  512. drupal_set_message('Publication importer deleted.');
  513. drupal_goto('admin/tripal/tripal_pub/import_list');
  514. }
  515. else {
  516. drupal_set_message('Could not delete publication importer.', 'error');
  517. }
  518. }
  519. /*
  520. * AHAH callback
  521. */
  522. function tripal_pub_importer_setup_page_update_remotedb() {
  523. $status = TRUE;
  524. // prepare and render the form
  525. $form = tripal_core_ahah_prepare_form();
  526. $data = theme('tripal_pub_importer_setup_form', $form);
  527. // bind javascript events to the new objects that will be returned
  528. // so that AHAH enabled elements will work.
  529. $settings = tripal_core_ahah_bind_events();
  530. // return the updated JSON
  531. drupal_json(
  532. array(
  533. 'status' => $status,
  534. 'data' => $data,
  535. 'settings' => $settings,
  536. )
  537. );
  538. }
  539. /*
  540. * AHAH callback
  541. */
  542. function tripal_pub_importer_setup_page_update_criteria($action, $i) {
  543. $status = TRUE;
  544. // prepare and render the form
  545. $form = tripal_core_ahah_prepare_form();
  546. $data = theme('tripal_pub_importer_setup_form', $form);
  547. // bind javascript events to the new objects that will be returned
  548. // so that AHAH enabled elements will work.
  549. $settings = tripal_core_ahah_bind_events();
  550. // return the updated JSON
  551. drupal_json(
  552. array(
  553. 'status' => $status,
  554. 'data' => $data,
  555. 'settings' => $settings,
  556. )
  557. );
  558. }