pub_search.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. /*
  3. *
  4. */
  5. function tripal_pub_search_page() {
  6. global $pager_total, $pager_total_items;
  7. $pager_id = 0;
  8. $limit = 25;
  9. // generate the search form
  10. $form = drupal_get_form('tripal_pub_search_form');
  11. $output = drupal_render($form);
  12. // retrieve any results
  13. if (array_key_exists('tripal_pub_search_form', $_SESSION) and
  14. $_SESSION['tripal_pub_search_form']['perform_search']) {
  15. $num_criteria = $_SESSION['tripal_pub_search_form']['num_criteria'];
  16. $from_year = $_SESSION['tripal_pub_search_form']['from_year'];
  17. $to_year = $_SESSION['tripal_pub_search_form']['to_year'];
  18. $search_array = array();
  19. $search_array['num_criteria'] = $num_criteria;
  20. $search_array['from_year'] = $from_year;
  21. $search_array['to_year'] = $to_year;
  22. for ($i = 0; $i <= $num_criteria; $i++) {
  23. $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['search_terms'];
  24. $search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['scope'];
  25. $search_array['criteria'][$i]['mode'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['mode'];
  26. $search_array['criteria'][$i]['operation'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['operation'];
  27. }
  28. // get the list of publications from the remote database using the search criteria.
  29. $pubs = tripal_pub_get_search_results($search_array, $limit, $pager_id);
  30. // generate the pager
  31. $page = isset($_GET['page']) ? $_GET['page'] : '0';
  32. $total_records = $_SESSION['chado_pager'][0]['total_records'];
  33. $total_pages = (int) ($total_records / $limit) + 1;
  34. // generate the pager
  35. pager_default_initialize($total_records, $limit);
  36. $pager = array(
  37. 'tags' => array(),
  38. 'element' => 0,
  39. 'parameters' => array(),
  40. 'quantity' => $limit,
  41. );
  42. $pager = theme_pager($pager);
  43. // iterate through the results and construct the table displaying the publications
  44. $rows = array();
  45. $i = $page * $limit + 1;
  46. foreach ($pubs as $pub) {
  47. // get the citation for this publication
  48. $values = array(
  49. 'pub_id' => $pub->pub_id,
  50. 'type_id' => array(
  51. 'name' => 'Citation',
  52. ),
  53. );
  54. $citation_rec = tripal_core_generate_chado_var('pubprop', $values);
  55. $citation_rec = tripal_core_expand_chado_vars($citation_rec, 'field', 'pubprop.value');
  56. // if we have the citation then use it, otherwise, just use the title
  57. $title = htmlspecialchars($pub->title);
  58. $result = $title;
  59. if ($pub->nid) {
  60. $result = l($title ,'node/' . $pub->nid, array('attributes' => array('target' => '_blank')));
  61. }
  62. if ($citation_rec->value) {
  63. $citation = htmlspecialchars($citation_rec->value);
  64. $result .= '<br>' . $citation;
  65. }
  66. $rows[] = array(
  67. number_format($i) . ".",
  68. $pub->pyear,
  69. $result
  70. );
  71. $i++;
  72. }
  73. $headers = array('', 'Year', 'Publication');
  74. $table = theme('table', $headers, $rows);
  75. // join all to form the results
  76. $output .= "<br><p><b>Found " . number_format($total_records) .
  77. ". Page " . ($page + 1) . " of $total_pages. " .
  78. " Results</b></br>" . $table . '</p>' . $pager;
  79. }
  80. return $output;
  81. }
  82. /**
  83. * Purpose: Provides the form to search pubmed
  84. *
  85. * @ingroup tripal_pub
  86. */
  87. function tripal_pub_search_form($form, &$form_state) {
  88. // Default values can come in the following ways:
  89. //
  90. // 1) as elements of the $pub_importer object. This occurs when editing an existing importer
  91. // 2) in the $form_state['values'] array which occurs on a failed validation or
  92. // ajax callbacks from non submit form elements
  93. // 3) in the $form_state['input'] array which occurs on ajax callbacks from submit
  94. // form elements and the form is being rebuilt
  95. //
  96. // Set the default values. If the pub_import_id isn't already defined by the form values
  97. // and one is provided then look it up in the database
  98. $criteria = NULL;
  99. $num_criteria = 2;
  100. $from_year = '';
  101. $to_year = '';
  102. // if the session has variables then use those. This should only happen when
  103. // the 'Test Criteria' button is clicked.
  104. if (array_key_exists('tripal_pub_search_form', $_SESSION)) {
  105. $num_criteria = $_SESSION['tripal_pub_search_form']['num_criteria'] ? $_SESSION['tripal_pub_search_form']['num_criteria'] : $num_criteria;
  106. $from_year = $_SESSION['tripal_pub_search_form']['from_year'] ? $_SESSION['tripal_pub_search_form']['from_year'] : '';
  107. $to_year = $_SESSION['tripal_pub_search_form']['to_year'] ? $_SESSION['tripal_pub_search_form']['to_year'] : '';
  108. }
  109. if (array_key_exists('values', $form_state)) {
  110. $num_criteria = $form_state['values']['num_criteria'] ? $form_state['values']['num_criteria'] : $num_criteria;
  111. $from_year = $form_state['values']['from_year'] ? $form_state['values']['from_year'] : $from_year;
  112. $to_year = $form_state['values']['to_year'] ? $form_state['values']['to_year'] : $to_year;
  113. }
  114. if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
  115. $num_criteria = $form_state['input']['num_criteria'] ? $form_state['input']['num_criteria'] : $num_criteria;
  116. $from_year = $form_state['input']['from_year'] ? $form_state['input']['from_year'] : $from_year;
  117. $to_year = $form_state['input']['to_year'] ? $form_state['input']['to_year'] : $to_year;
  118. }
  119. if (array_key_exists('triggering_element', $form_state) and
  120. $form_state['triggering_element']['#name'] == 'add') {
  121. $num_criteria++;
  122. }
  123. if (array_key_exists('triggering_element', $form_state) and
  124. $form_state['triggering_element']['#name'] == 'remove') {
  125. $num_criteria--;
  126. }
  127. $form['num_criteria']= array(
  128. '#type' => 'hidden',
  129. '#default_value' => $num_criteria,
  130. );
  131. $form['instructions'] = array(
  132. '#markup' => t('To search for publications enter keywords in the text boxes below.
  133. You can limit your search by selecting the field in the dropdown box. Click the
  134. add and remove buttons to add additional fields for searching. '),
  135. );
  136. // get publication properties list
  137. $properties = array();
  138. $properties[] = 'Any Field';
  139. $sql = "
  140. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  141. FROM {cvtermpath} CVTP
  142. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  143. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  144. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  145. WHERE CV.name = 'tripal_pub' and
  146. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  147. NOT CVTS.is_obsolete = 1
  148. ORDER BY CVTS.name ASC
  149. ";
  150. $allowed_fields = variable_get('tripal_pub_allowed_search_fields', array());
  151. $prop_types = chado_query($sql);
  152. foreach ($prop_types as $prop) {
  153. if(array_key_exists($prop->cvterm_id, $allowed_fields) and $allowed_fields[$prop->cvterm_id] > 0) {
  154. $properties[$prop->cvterm_id] = $prop->name;
  155. }
  156. }
  157. for($i = 1; $i <= $num_criteria; $i++) {
  158. $search_terms = '';
  159. $scope = '';
  160. $operation = '';
  161. $mode = '';
  162. // first populate defaults using any values in the SESSION variable
  163. if (array_key_exists('tripal_pub_search_form', $_SESSION)) {
  164. $search_terms = $_SESSION['tripal_pub_search_form']['criteria'][$i]['search_terms'] ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['search_terms'] : $search_terms;
  165. $scope = $_SESSION['tripal_pub_search_form']['criteria'][$i]['scope'] ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['scope'] : $scope;
  166. $mode = $_SESSION['tripal_pub_search_form']['criteria'][$i]['mode'] ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['mode'] : $mode;
  167. $operation = $_SESSION['tripal_pub_search_form']['criteria'][$i]['operation'] ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['operation'] : $operation;
  168. }
  169. if (array_key_exists('values', $form_state)) {
  170. $search_terms = array_key_exists("search_terms-$i", $form_state['values']) ? $form_state['values']["search_terms-$i"] : $search_terms;
  171. $scope = array_key_exists("scope-$i", $form_state['values']) ? $form_state['values']["scope-$i"] : $scope;
  172. $mode = array_key_exists("mode-$i", $form_state['values']) ? $form_state['values']["mode-$i"] : $mode;
  173. $operation = array_key_exists("operation-$i", $form_state['values']) ? $form_state['values']["operation-$i"] : $operation;
  174. }
  175. if (array_key_exists('input', $form_state)) {
  176. $search_terms = array_key_exists("search_terms-$i", $form_state['input']) ? $form_state['input']["search_terms-$i"] : $search_terms;
  177. $scope = array_key_exists("scope-$i", $form_state['input']) ? $form_state['input']["scope-$i"] : $scope;
  178. $mode = array_key_exists("mode-$i", $form_state['input']) ? $form_state['input']["mode-$i"] : $mode;
  179. $operation = array_key_exists("operation-$i", $form_state['input']) ? $form_state['input']["operation-$i"] : $operation;
  180. }
  181. // default to searching the title and abstract
  182. if (!$scope) {
  183. $scope = 'abstract';
  184. }
  185. $form['criteria'][$i]["search_terms-$i"] = array(
  186. '#type' => 'textfield',
  187. '#default_value' => $search_terms,
  188. '#required' => FALSE,
  189. );
  190. $form['criteria'][$i]["scope-$i"] = array(
  191. '#type' => 'select',
  192. '#options' => $properties,
  193. '#default_value' => $scope,
  194. '#attributes' => array('class' => array('tripal-pub-search-form-scope-select')),
  195. );
  196. /*
  197. $form['criteria'][$i]["mode-$i"] = array(
  198. '#type' => 'select',
  199. '#options' => array(
  200. 'Contains' => 'Contains',
  201. 'Starts With' => 'Starts With',
  202. 'Ends With' => 'Ends With',
  203. 'Exactly' => 'Exactly'),
  204. '#default_value' => $mode,
  205. );*/
  206. if ($i > 1) {
  207. $form['criteria'][$i]["operation-$i"] = array(
  208. '#type' => 'select',
  209. '#options' => array(
  210. 'AND' => 'AND',
  211. 'OR' => 'OR',
  212. 'NOT' => 'NOT'),
  213. '#default_value' => $operation,
  214. );
  215. }
  216. if ($i == $num_criteria) {
  217. if($i > 1) {
  218. $form['criteria'][$i]["remove-$i"] = array(
  219. '#type' => 'button',
  220. '#name' => 'remove',
  221. '#value' => t('Remove'),
  222. '#ajax' => array(
  223. 'callback' => "tripal_pubs_search_form_ajax_update",
  224. 'wrapper' => 'tripal-pub-search-form-criteria',
  225. 'effect' => 'fade',
  226. 'method' => 'replace',
  227. 'prevent' => 'click'
  228. ),
  229. // When this button is clicked, the form will be validated and submitted.
  230. // Therefore, we set custom submit and validate functions to override the
  231. // default form submit. In the validate function we set the form_state
  232. // to rebuild the form so the submit function never actually gets called,
  233. // but we need it or Drupal will run the default validate anyway.
  234. // we also set #limit_validation_errors to empty so fields that
  235. // are required that don't have values won't generate warnings.
  236. '#submit' => array('tripal_pub_search_form_ajax_button_submit'),
  237. '#validate' => array('tripal_pub_search_form_ajax_button_validate'),
  238. '#limit_validation_errors' => array(),
  239. );
  240. }
  241. $form['criteria'][$i]["add-$i"] = array(
  242. '#type' => 'button',
  243. '#name' => 'add',
  244. '#value' => t('Add'),
  245. '#ajax' => array(
  246. 'callback' => "tripal_pubs_search_form_ajax_update",
  247. 'wrapper' => 'tripal-pub-search-form-criteria',
  248. 'effect' => 'fade',
  249. 'method' => 'replace',
  250. 'prevent' => 'click'
  251. ),
  252. // When this button is clicked, the form will be validated and submitted.
  253. // Therefore, we set custom submit and validate functions to override the
  254. // default form submit. In the validate function we set the form_state
  255. // to rebuild the form so the submit function never actually gets called,
  256. // but we need it or Drupal will run the default validate anyway.
  257. // we also set #limit_validation_errors to empty so fields that
  258. // are required that don't have values won't generate warnings.
  259. '#submit' => array('tripal_pub_search_form_ajax_button_submit'),
  260. '#validate' => array('tripal_pub_search_form_ajax_button_validate'),
  261. '#limit_validation_errors' => array(),
  262. );
  263. }
  264. }
  265. $form['criteria']["date"] = array(
  266. '#type' => 'select',
  267. '#options' => array('Years' => 'Years'),
  268. '#attributes' => array('class' => array('tripal-pub-search-form-scope-select')),
  269. );
  270. $form['criteria']["from_year"] = array(
  271. '#type' => 'textfield',
  272. '#default_value' => $from_year,
  273. '#required' => FALSE,
  274. '#title' => 'from',
  275. '#size' => 4,
  276. '#maxlength' => 4,
  277. );
  278. $form['criteria']["to_year"] = array(
  279. '#type' => 'textfield',
  280. '#default_value' => $to_year,
  281. '#required' => FALSE,
  282. '#title' => 'to',
  283. '#size' => 4,
  284. '#maxlength' => 4,
  285. );
  286. $form['search'] = array(
  287. '#type' => 'submit',
  288. '#value' => t('Search'),
  289. );
  290. $form['reset'] = array(
  291. '#type' => 'submit',
  292. '#value' => t('Reset'),
  293. );
  294. $form['criteria']['#theme'] = 'tripal_pub_search_setup_form_elements';
  295. return $form;
  296. }
  297. /**
  298. * This function is used to rebuild the form if an ajax call is made vai a button.
  299. * The button causes the form to be submitted. We don't want this so we override
  300. * the validate and submit routines on the form button. Therefore, this function
  301. * only needs to tell Drupal to rebuild the form
  302. */
  303. function tripal_pub_search_form_ajax_button_submit() {
  304. $form_state['rebuild'] = TRUE;
  305. }
  306. /**
  307. * This function is just a dummy to override the default form submit on ajax calls for buttons
  308. */
  309. function tripal_pub_search_form_ajax_button_validate() {
  310. // do nothing
  311. }
  312. /**
  313. *
  314. */
  315. function tripal_pub_search_form_validate($form, &$form_state) {
  316. $num_criteria = $form_state['values']['num_criteria'];
  317. $from_year = $form_state['values']['from_year'];
  318. $to_year = $form_state['values']['to_year'];
  319. $op = $form_state['values']['op'];
  320. // no need to vlaidate on a reset
  321. if ($op == 'Reset') {
  322. return;
  323. }
  324. if($from_year and !$to_year) {
  325. form_set_error('to_year', 'Please provide a 4-digit year.');
  326. }
  327. if(!$from_year and $to_year) {
  328. form_set_error('from_year', 'Please provide a 4-digit year.');
  329. }
  330. if($from_year and !preg_match('/\d\d\d\d/' , $from_year)) {
  331. form_set_error('from_year', 'Please provide a 4-digit year.');
  332. }
  333. if($to_year and !preg_match('/\d\d\d\d/' , $to_year)) {
  334. form_set_error('to_year', 'Please provide a 4-digit year.');
  335. }
  336. }
  337. /**
  338. *
  339. */
  340. function tripal_pub_search_form_submit($form, &$form_state) {
  341. $num_criteria = $form_state['values']['num_criteria'];
  342. $from_year = $form_state['values']['from_year'];
  343. $to_year = $form_state['values']['to_year'];
  344. $op = $form_state['values']['op'];
  345. // set the session variables
  346. if($op == 'Search') {
  347. $_SESSION['tripal_pub_search_form']['num_criteria'] = $num_criteria;
  348. unset($_SESSION['tripal_pub_search_form']['criteria']);
  349. for ($i = 0; $i <= $num_criteria; $i++) {
  350. $search_terms = '';
  351. $scope = '';
  352. $mode = 'Contains';
  353. $operation = '';
  354. if (array_key_exists("search_terms-$i", $form_state['values'])) {
  355. $search_terms = trim($form_state['values']["search_terms-$i"]);
  356. }
  357. if (array_key_exists("scope-$i", $form_state['values'])) {
  358. $scope = $form_state['values']["scope-$i"];
  359. }
  360. if (array_key_exists("operation-$i", $form_state['values'])) {
  361. $operation = $form_state['values']["operation-$i"];
  362. }
  363. //$mode = $form_state['values']["mode-$i"];
  364. $_SESSION['tripal_pub_search_form']['criteria'][$i] = array(
  365. 'search_terms' => $search_terms,
  366. 'scope' => $scope,
  367. 'mode' => $mode,
  368. 'operation' => $operation
  369. );
  370. }
  371. $_SESSION['tripal_pub_search_form']['from_year'] = $from_year;
  372. $_SESSION['tripal_pub_search_form']['to_year'] = $to_year;
  373. $_SESSION['tripal_pub_search_form']['perform_search'] = 1;
  374. }
  375. if($op == 'Reset') {
  376. unset($_SESSION['tripal_pub_search_form']);
  377. }
  378. }
  379. /*
  380. * AHAH callback
  381. */
  382. function tripal_pub_search_page_update_criteria($action, $i) {
  383. $status = TRUE;
  384. // prepare and render the form
  385. $form = tripal_core_ahah_prepare_form();
  386. $data = theme('tripal_pub_search_form', $form);
  387. // bind javascript events to the new objects that will be returned
  388. // so that AHAH enabled elements will work.
  389. $settings = tripal_core_ahah_bind_events();
  390. // return the updated JSON
  391. drupal_json(
  392. array(
  393. 'status' => $status,
  394. 'data' => $data,
  395. 'settings' => $settings,
  396. )
  397. );
  398. }
  399. /*
  400. *
  401. */
  402. function tripal_pub_get_search_results($search_array, $limit, $pager_id) {
  403. // build the SQL based on the criteria provided by the user
  404. $select = "SELECT DISTINCT P.*, CP.nid ";
  405. $from = "FROM {pub} P
  406. LEFT JOIN public.chado_pub CP on P.pub_id = CP.pub_id
  407. INNER JOIN {cvterm} CVT on CVT.cvterm_id = P.type_id
  408. ";
  409. $where = "WHERE (NOT P.title = 'null') "; // always exclude the dummy pub
  410. $order = "ORDER BY P.pyear DESC, P.title ASC";
  411. $args = array(); // arguments for where clause
  412. $join = 0;
  413. $num_criteria = $search_array['num_criteria'];
  414. $from_year = $search_array['from_year'];
  415. $to_year = $search_array['to_year'];
  416. for ($i = 1; $i <= $num_criteria; $i++) {
  417. $value = $search_array['criteria'][$i]['search_terms'];
  418. $type_id = $search_array['criteria'][$i]['scope'];
  419. $mode = $search_array['criteria'][$i]['mode'];
  420. $op = $search_array['criteria'][$i]['operation'];
  421. // skip criteria with no values
  422. if(!$value) {
  423. continue;
  424. }
  425. // to prevent SQL injection make sure our operator is
  426. // what we expect
  427. if ($op and $op != "AND" and $op != "OR" and $op != 'NOT') {
  428. $op = 'AND';
  429. }
  430. if ($op == 'NOT') {
  431. $op = 'AND NOT';
  432. }
  433. if (!$op) {
  434. $op = 'AND';
  435. }
  436. $action = "= lower('%s')";
  437. if($mode == 'Contains') {
  438. $action = 'LIKE lower(\'%%' . ":crit$i" . '%%\')';
  439. }
  440. if($mode == 'Starts With') {
  441. $action = '= lower(\'%%' . ":crit$i" . '\')';
  442. }
  443. if($mode == 'Ends With') {
  444. $action = '= lower(\'' . ":crit$i" . '%%\')';
  445. }
  446. // get the scope type
  447. $values = array('cvterm_id' => $type_id);
  448. $cvterm = tripal_core_chado_select('cvterm', array('name'), $values);
  449. $type_name = '';
  450. if (count($cvterm) > 0) {
  451. $type_name = $cvterm[0]->name;
  452. }
  453. if ($type_name == 'Title') {
  454. $where .= " $op (lower(P.title) $action) ";
  455. $args[":crit$i"] = $value;
  456. }
  457. elseif ($type_name == 'Year') {
  458. $where .= " $op (lower(P.pyear) $action) ";
  459. $args[":crit$i"] = $value;
  460. }
  461. elseif ($type_name == 'Volume') {
  462. $where .= " $op (lower(P.volume) $action) ";
  463. $args[":crit$i"] = $value;
  464. }
  465. elseif ($type_name == 'Issue') {
  466. $where .= " $op (lower(P.issue) $action)";
  467. $args[":crit$i"] = $value;
  468. }
  469. elseif ($type_name == 'Journal Name') {
  470. $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = :crit$i ";
  471. $where .= " $op ((lower(P.series_name) $action and CVT.name = 'Journal Article') OR
  472. (lower(PP$i.value) $action)) ";
  473. $args[":crit$i"] = $type_id;
  474. }
  475. elseif ($type_name == 'Conference Name') {
  476. $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = :crit$i ";
  477. $where .= " $op ((lower(P.series_name) $action and CVT.name = 'Conference Proceedings') OR
  478. (lower(PP$i.value) $action)) ";
  479. $args[":crit$i"] = $type_id;
  480. }
  481. elseif ($type_name == 'Publication Type') {
  482. $where .= " $op (lower(CVT.name) $action)";
  483. $args[":crit$i"] = $value;
  484. }
  485. elseif ($type_id == 0) { //'Any Field'
  486. $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id ";
  487. $where .= " $op (lower(PP$i.value) $action OR
  488. lower(P.title) $action OR
  489. lower(P.volumetitle) $action OR
  490. lower(P.publisher) $action OR
  491. lower(P.uniquename) $action OR
  492. lower(P.pubplace) $action OR
  493. lower(P.miniref) $action OR
  494. lower(P.series_name) $action) ";
  495. $args[":crit$i"] = $value;
  496. }
  497. // for all other properties
  498. else {
  499. $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = :crit$i ";
  500. $where .= " $op (lower(PP$i.value) $action) ";
  501. $args[":crit$i"] = $type_id;
  502. }
  503. }
  504. if($from_year and $to_year) {
  505. $where .= " AND (P.pyear ~ '....' AND to_number(P.pyear,'9999') >= :from$i AND to_number(P.pyear,'9999') <= :to$i) ";
  506. $args[":from$i"] = $from_year;
  507. $args[":to$i"] = $to_year;
  508. }
  509. $sql = "$select $from $where $order";
  510. $count = "SELECT count(*) FROM ($select $from $where $order) as t1";
  511. return chado_pager_query($sql, $args, $limit, $pager_id, $count);
  512. }
  513. /**
  514. *
  515. */
  516. function tripal_pubs_search_form_ajax_update($form, $form_state) {
  517. return $form['criteria'];
  518. }
  519. /**
  520. *
  521. * @param unknown $form
  522. */
  523. function theme_tripal_pub_search_setup_form_elements($variables) {
  524. $form = $variables['form'];
  525. $rows = array();
  526. // put each criteria element in a single table row
  527. foreach ($form as $i => $element) {
  528. if(is_numeric($i)) {
  529. $rows[] = array(
  530. drupal_render($element["operation-$i"]),
  531. drupal_render($element["scope-$i"]),
  532. //drupal_render($element["mode-$i"]) .
  533. drupal_render($element["search_terms-$i"]),
  534. array(
  535. 'data' => drupal_render($element["add-$i"]) . drupal_render($element["remove-$i"]),
  536. 'nowrap' => 'nowrap',
  537. ),
  538. );
  539. }
  540. }
  541. // add in the from_year and to_year elements as the final row of the table
  542. $rows[] = array(
  543. '&nbsp;',
  544. drupal_render($form['date']),
  545. array(
  546. 'data' =>
  547. "<div id=\"pub-search-form-dates-row\">
  548. <div id=\"pub-search-form-dates\"> ".
  549. drupal_render($form['from_year']) .
  550. drupal_render($form['to_year']) . "
  551. </div>
  552. </div>
  553. ",
  554. ),
  555. ''
  556. );
  557. $headers = array();
  558. $table = array(
  559. 'header' => $headers,
  560. 'rows' => $rows,
  561. 'attributes' => array('id' => 'tripal-pub-search-form-table', 'border' => '0'),
  562. 'sticky' => TRUE,
  563. 'caption' => '',
  564. 'colgroups' => array(),
  565. 'empty' => '',
  566. );
  567. $results = '<div id="tripal-pub-search-form-criteria">';
  568. $results .= theme_table($table);
  569. $results .= '</div>';
  570. return $results;
  571. }