pub_importers.inc 23 KB

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