remote_search.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. *
  4. */
  5. function tripal_pub_remote_search_page() {
  6. global $pager_total;
  7. // generate the search form
  8. $form = drupal_get_form('tripal_pub_remote_search_form');
  9. // retrieve any results
  10. $remote_db = $_SESSION['tripal_pub_search_criteria']['remote_db'];
  11. $search_terms = $_SESSION['tripal_pub_search_criteria']['search_terms'];
  12. $results = tripal_pub_get_remote_search_results($remote_db, $search_terms, 10, 0);
  13. // iterate through the results and construct the table displaying the publications
  14. if (count($results) > 0) {
  15. }
  16. // generate the pager
  17. $total_items = $pager_total[0];
  18. $pager = theme('pager');
  19. // join all to form the final page
  20. $output = $form . "<p><b>Found " . number_format($total_items) . " Results</b></br>" . $table . '</p>' . $pager;
  21. return $output;
  22. }
  23. /*
  24. *
  25. */
  26. function tripal_pub_get_remote_search_results($remote_db, $search_terms, $num_to_retrieve, $pager_id) {
  27. $results = array();
  28. $callback = 'tripal_pub_remote_search_' . strtolower($remote_db);
  29. if (function_exists($callback) and $search_terms) {
  30. $results = call_user_func($callback, $search_terms, $num_to_retrieve, $pager_id);
  31. }
  32. return $results;
  33. }
  34. /**
  35. * Purpose: Provides the form to search pubmed
  36. *
  37. * @ingroup tripal_pub
  38. */
  39. function tripal_pub_remote_search_form(&$form_state = NULL) {
  40. $remote_db = $_SESSION['tripal_pub_search_criteria']['remote_db'];
  41. $search_terms = $_SESSION['tripal_pub_search_criteria']['search_terms'];
  42. $remote_dbs = array('Pubmed' => 'Pubmed');
  43. $form['remote_db'] = array(
  44. '#title' => t('Remote Publication Database'),
  45. '#type' => 'select',
  46. '#options' => $remote_dbs,
  47. '#default_value' => $remote_db,
  48. );
  49. $form['search_terms']= array(
  50. '#type' => 'textfield',
  51. '#title' => t('Search Terms'),
  52. '#description' => t('Please provide a list of words, separated by spaces for searching'),
  53. '#default_value' => $search_terms,
  54. );
  55. $form['submit'] = array(
  56. '#type' => 'submit',
  57. '#value' => t('Submit'),
  58. '#executes_submit_callback' => TRUE,
  59. );
  60. return $form;
  61. }
  62. /**
  63. *
  64. */
  65. function tripal_pub_remote_search_form_validate($form, &$form_state) {
  66. $remote_db = $form_state['values']['remote_db'];
  67. $search_terms = $form_state['values']['search_terms'];
  68. }
  69. /**
  70. *
  71. */
  72. function tripal_pub_remote_search_form_submit($form, &$form_state) {
  73. $remote_db = $form_state['values']['remote_db'];
  74. $search_terms = $form_state['values']['search_terms'];
  75. // store the search settings in a session variable. Then when the page
  76. // is refreshed these values will be available for the page to
  77. // generate results.
  78. if ($op == 'Reset') {
  79. unset($_SESSION['tripal_pub_search_criteria']);
  80. unset($form_state['values']);
  81. }
  82. else {
  83. $_SESSION['tripal_pub_search_criteria'] = array(
  84. 'remote_db' => $remote_db,
  85. 'search_terms' => $search_terms,
  86. );
  87. }
  88. }