Browse Source

Fixed merge conflict caused by added documentation to the properties api

Lacey Sanderson 11 years ago
parent
commit
1fedcda47b

+ 0 - 54
tripal_core/api/tripal_core_misc.api.inc

@@ -1,54 +0,0 @@
-<?php 
-/**
- * This function implements a pager, similar to a pager for a database query
- * using a non query.  Rather than pass a query as in pager_query function, a 
- * callback function should recieve as it's first argument an array of the 
- * argumetns passed to this function. The second argument should be the 
- * number of results to retreive, and the third argument should be the the
- * element index (same as with pager_query) function.  The callback function
- * should always return an array. If no values are available then an empty 
- * array should be returned.
- * 
- * @param $func
- *  The name of the callback function used to retrieve the results. The
- *  callback function should have three arguments: first, an array of values
- *  passed into the tripal_pager_callback; second, the start index of
- *  the paged values; third, the number of records to include.
- * @param limit
- *  The number of records to include in the paged results
- * @param element
- *  A unique integer ID if more than one pager exists on a page.  if multiple
- *  types of pagers (e.g. pager_query, chado_pager_query) are on the same
- *  page then this parameter should be unique amongst them all.
- * @param cfunc
- *  The name of the callback function used to specify the total results. The
- *  callback f unction should receive one argument: an array of values that
- *  are passed into the tripal_pager_callbck function. 
- */
-function tripal_pager_callback($func, $limit = 10, $element = 0, $cfunc) {
-  
-  global $pager_page_array, $pager_total, $pager_total_items;
-  $page = isset($_GET['page']) ? $_GET['page'] : '';
-   
-  // Substitute in query arguments.
-  $args = func_get_args();
-  $args = array_slice($args, 4);
-  // Alternative syntax for '...'
-  if (isset($args[0]) && is_array($args[0])) {
-    $args = $args[0];
-  }
-
-  // count the number of records by calling the counting callbackup function
-  $count = $cfunc($args);  
-  
-  // Convert comma-separated $page to an array, used by other functions.
-  $pager_page_array = explode(',', $page);
-
-  // We calculate the total of pages as ceil(items / limit).
-  $pager_total_items[$element] = $count;
-  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
-  $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
-  
-  // retrieve the results using the specified callback.
-  return $func($args, $pager_page_array[$element] * $limit, $limit);
-}

+ 3 - 6
tripal_core/api/tripal_core_properties.api.inc

@@ -526,20 +526,17 @@ function tripal_core_properties_form(&$form, &$form_state, $prop_table, $id_fiel
     $available_props, $id = NULL, $exclude = array(), $include = array(), $instructions = '',
     $fset_title = 'Additional Details') {
 
-  $d_removed      = array(); // lists removed properties
-  $num_new        = 0;  // the number of new rows
+  $d_removed = array(); // lists removed properties
 
   // if we are re constructing the form from a failed validation or ajax callback
   // then use the $form_state['values'] values
   if (array_key_exists('values', $form_state)) {
-    $d_removed      = $form_state['values']['removed'];
-    $num_new        = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
+    $d_removed = $form_state['values']['removed'];
   }
   // if we are re building the form from after submission (from ajax call) then
   // the values are in the $form_state['input'] array
   if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
-    $d_removed      = $form_state['input']['removed'];
-    $num_new        = $form_state['input']['num_new'] ? $form_state['input']['num_new'] : 0;
+    $d_removed = $form_state['input']['removed'];
   }
 
   $form['properties'] = array(

+ 0 - 1
tripal_core/tripal_core.module

@@ -42,7 +42,6 @@ require_once "api/tripal_core_chado_nodes.api.inc";
 require_once "api/tripal_core_custom_tables.api.inc";
 require_once "api/tripal_core_jobs.api.inc";
 require_once "api/tripal_core_mviews.api.inc";
-require_once "api/tripal_core_misc.api.inc";
 require_once "api/tripal_core_properties.api.inc";
 require_once "includes/jobs.inc";
 require_once "includes/mviews.inc";

+ 46 - 55
tripal_pub/api/tripal_pub.api.inc

@@ -36,12 +36,6 @@
  *    The number of records to retrieve.  In cases with large numbers of
  *    records to retrieve, the remote database may limit the size of each
  *    retrieval.
- * @param $pager_id
- *    Optional.  This function uses the 'tripal_pager_callback' function
- *    to page a set of results.  This is helpful when generating results to
- *    be view online.  The pager works identical to the pager_query function
- *    of drupal. Simply provide a unique integer value for this argument.  Each
- *    form on a single page should have a unique $pager_id.
  * @param $page
  *    Optional.  If this function is called where the
  *    page for the pager cannot be set using the $_GET variable, use this
@@ -53,21 +47,18 @@
  *
  * @ingroup tripal_pub_api
  */
-function tripal_pub_get_remote_search_results($remote_db, $search_array,
-$num_to_retrieve, $pager_id = 0, $page = 0) {
+function tripal_pub_get_remote_search_results($remote_db, $search_array, $num_to_retrieve, $page = 0) {
 
-  // manually set the $_GET['page'] parameter to trick the pager
-  // into giving us the requested page
-  if (is_int($page) and $page > 0) {
-    $_GET['page'] = $page;
-  }
   // now call the callback function to get the results
   $callback = "tripal_pub_remote_search_$remote_db";
-  $pubs = array();
+  $pubs =  array(
+    'total_records' => 0,
+    'search_str'    => '',
+    'pubs'          => array(),
+  );
   if (function_exists($callback)) {
-    $pubs = call_user_func($callback, $search_array, $num_to_retrieve, $pager_id);
+    $pubs = call_user_func($callback, $search_array, $num_to_retrieve, $page);
   }
-
   return $pubs;
 }
 /*
@@ -94,8 +85,8 @@ function tripal_pub_get_raw_data($dbxref) {
           'scope' => 'id',
           'operation' => '',
           'is_phrase' => 0,
-    ),
-    ),
+       ),
+      ),
     );
     $pubs = tripal_pub_get_remote_search_results($remote_db, $search, 1, 0);
 
@@ -265,7 +256,7 @@ function tripal_pub_import_publications($report_email = FALSE, $do_update = FALS
       $HTML_report .= "<b>$total new publications from importer: $importer</b><br><ol>\n";
       foreach ($report['inserted'] as $pub) {
         $item = $pub['Title'];
-        if ($pub['pub_id']) {
+        if (array_key_exists('pub_id', $pub)) {
           $item = l($pub['Title'], "$base_url/pub/" . $pub['pub_id']);
         }
         $HTML_report .= "<li>$item</li>\n";
@@ -1136,7 +1127,7 @@ function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
           FROM {cvterm} 
           WHERE name = :cvtname AND cv_id = 
             (SELECT cv_id 
-             FROM cv 
+             FROM {cv} 
              WHERE name = 'tripal_pub'
             )
          ) 
@@ -1228,35 +1219,35 @@ function tripal_pub_create_citation($pub) {
   if ($pub_type == 'Journal Article') {
     $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
   
-    if ($pub['Journal Name']) {
+    if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
     }
-    elseif ($pub['Journal Abbreviation']) {
+    elseif (array_key_exists('Journal Abbreviation', $pub)) {
       $citation .= $pub['Journal Abbreviation'] . '. ';
     }
-    elseif ($pub['Series Name']) {
+    elseif (array_key_exists('Series Name', $pub)) {
       $citation .= $pub['Series Name'] . '. ';  
     }
-    elseif ($pub['Series Abbreviation']) {
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
       $citation .= $pub['Series Abbreviation'] . '. ';
     }
-    if ($pub['Publication Date']) {
+    if (array_key_exists('Publication Date', $pub)) {
       $citation .= $pub['Publication Date'];
     }
-    elseif ($pub['Year']) {
+    elseif (array_key_exists('Year', $pub)) {
       $citation .= $pub['Year'];
     }
-    if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
       $citation .= '; ';
     }
-    if ($pub['Volume']) {
+    if (array_key_exists('Volume', $pub)) {
       $citation .= $pub['Volume'];
     }
-    if ($pub['Issue']) {
+    if (array_key_exists('Issue', $pub)) {
       $citation .= '(' . $pub['Issue'] . ')';
     }
-    if ($pub['Pages']) {
-      if($pub['Volume']) {
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
         $citation .= ':';
       }
       $citation .= $pub['Pages'];
@@ -1269,13 +1260,13 @@ function tripal_pub_create_citation($pub) {
   elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
     $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
   
-    if ($pub['Journal Name']) {
+    if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
     }
-    if ($pub['Publication Date']) {
+    if (array_key_exists('Publication Date', $pub)) {
       $citation .= $pub['Publication Date'];
     }
-    elseif ($pub['Year']) {
+    elseif (array_key_exists('Year', $pub)) {
       $citation .= $pub['Year'];
     }
     $citation .= '.';
@@ -1286,35 +1277,35 @@ function tripal_pub_create_citation($pub) {
   elseif ($pub_type == 'Letter') {
     $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
   
-    if ($pub['Journal Name']) {
+    if (array_key_exists('Journal Name', $pub)) {
       $citation .= $pub['Journal Name'] . '. ';
     }
-    elseif ($pub['Journal Abbreviation']) {
+    elseif (array_key_exists('Journal Abbreviation', $pub)) {
       $citation .= $pub['Journal Abbreviation'] . '. ';
     }
-    elseif ($pub['Series Name']) {
+    elseif (array_key_exists('Series Name', $pub)) {
       $citation .= $pub['Series Name'] . '. ';  
     }
-    elseif ($pub['Series Abbreviation']) {
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
       $citation .= $pub['Series Abbreviation'] . '. ';
     }
-    if ($pub['Publication Date']) {
+    if (array_key_exists('Publication Date', $pub)) {
       $citation .= $pub['Publication Date'];
     }
-    elseif ($pub['Year']) {
+    elseif (array_key_exists('Year', $pub)) {
       $citation .= $pub['Year'];
     }
-    if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
       $citation .= '; ';
     }
-    if ($pub['Volume']) {
+    if (array_key_exists('Volume', $pub)) {
       $citation .= $pub['Volume'];
     }
-    if ($pub['Issue']) {
+    if (array_key_exists('Issue', $pub)) {
       $citation .= '(' . $pub['Issue'] . ')';
     }
-    if ($pub['Pages']) {
-      if($pub['Volume']) {
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
         $citation .= ':';
       }
       $citation .= $pub['Pages'];
@@ -1339,32 +1330,32 @@ function tripal_pub_create_citation($pub) {
   elseif ($pub_type == 'Conference Proceedings') {
     $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
   
-    if ($pub['Conference Name']) {
+    if (array_key_exists('Conference Name', $pub)) {
       $citation .= $pub['Conference Name'] . '. ';
     }
-    elseif ($pub['Series Name']) {
+    elseif (array_key_exists('Series Name', $pub)) {
       $citation .= $pub['Series Name'] . '. ';  
     }
-    elseif ($pub['Series Abbreviation']) {
+    elseif (array_key_exists('Series Abbreviation', $pub)) {
       $citation .= $pub['Series Abbreviation'] . '. ';
     }
-    if ($pub['Publication Date']) {
+    if (array_key_exists('Publication Date', $pub)) {
       $citation .= $pub['Publication Date'];
     }
-    elseif ($pub['Year']) {
+    elseif (array_key_exists('Year', $pub)) {
       $citation .= $pub['Year'];
     }
-    if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
+    if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
       $citation .= '; ';
     }
-    if ($pub['Volume']) {
+    if (array_key_exists('Volume', $pub)) {
       $citation .= $pub['Volume'];
     }
-    if ($pub['Issue']) {
+    if (array_key_exists('Issue', $pub)) {
       $citation .= '(' . $pub['Issue'] . ')';
     }
-    if ($pub['Pages']) {
-      if($pub['Volume']) {
+    if (array_key_exists('Pages', $pub)) {
+      if (array_key_exists('Volume', $pub)) {
         $citation .= ':';
       }
       $citation .= $pub['Pages'];

+ 100 - 101
tripal_pub/includes/importers/AGL.inc

@@ -2,19 +2,17 @@
 /**
  *
  */
-function tripal_pub_remote_alter_form_AGL($form, $form_state) {
-
-  $num_criteria = $form['num_criteria']['#default_value'];
-
+function tripal_pub_remote_alter_form_AGL($form, $form_state, $num_criteria = 1) {
+  
   // So far we haven't been able to get AGL to filter results to only
   // include pubs by the XX number days in the past.  So, we will
   // change the 'days' element to be the year to query
-  $form['days']['#title'] = t('Year');
-  $form['days']['#description']  = t('Please enter a year to limit records by the year they were published, created or modified in the database.');
+  $form['themed_element']['days']['#title'] = t('Year');
+  $form['themed_element']['days']['#description']  = t('Please enter a year to limit records by the year they were published, created or modified in the database.');
 
   // The Journal Name filter doesn't seem to work, so remove it
   for($i = 1; $i <= $num_criteria; $i++) {
-    unset($form['criteria'][$i]["scope-$i"]['#options']['journal']);
+    unset($form['themed_element']['criteria'][$i]["scope-$i"]['#options']['journal']);
   }
   return $form;
 }
@@ -23,7 +21,7 @@ function tripal_pub_remote_alter_form_AGL($form, $form_state) {
  */
 function tripal_pub_remote_validate_form_AGL($form, $form_state) {
   $days =  trim($form_state['values']["days"]);
-  $num_criteria = $form['num_criteria']['#default_value'];
+  $num_criteria = $form_state['values']['num_criteria'];
 
   if ($days and !preg_match('/^\d\d\d\d$/', $days)) {
     form_set_error("days", "Please enter a four digit year.");
@@ -48,10 +46,10 @@ function tripal_pub_remote_validate_form_AGL($form, $form_state) {
 /**
  *
  */
-function tripal_pub_remote_search_AGL($search_array, $num_to_retrieve, $pager_id) {
+function tripal_pub_remote_search_AGL($search_array, $num_to_retrieve, $page) {
   // get some values from the serach array
   $num_criteria = $search_array['num_criteria'];
-  $days = $search_array['days'];
+  $days         = $search_array['days'];
 
   // set some defaults
   $search_array['limit'] = $num_to_retrieve;
@@ -328,43 +326,76 @@ function tripal_pub_remote_search_AGL($search_array, $num_to_retrieve, $pager_id
     "id"       => "u=12",
     "year"     => "u=30 r=o", 
     "journal"  => "u=1033"
+  );
+  yaz_ccl_conf($yazc, $fields);
+
+  if (!yaz_ccl_parse($yazc, $ccl, $cclresult)) {
+    drupal_set_message('Error parsing search string: ' . $cclresult["errorstring"], "error");
+    watchdog('tpub_import', 'Error: %errstr', array('%errstr' => $cclresult["errorstring"]), WATCHDOG_ERROR);
+    return array(
+      'total_records' => 0,
+      'search_str'    => '',
+      'pubs'          => array(),
     );
-    yaz_ccl_conf($yazc, $fields);
-
-    if (!yaz_ccl_parse($yazc, $ccl, $cclresult)) {
-      drupal_set_message('Error parsing search string: ' . $cclresult["errorstring"], "error");
-      watchdog('tpub_import', 'Error: %errstr', array('%errstr' => $cclresult["errorstring"]), WATCHDOG_ERROR);
-      return array();
+  }
+  $search_str = $cclresult["rpn"];
+ 
+  // get the total number of records 
+  $total_records = tripal_pub_AGL_count($yazc, $search_str);
+  
+  // get the pubs in the specified rang
+  $start = $page * $num_to_retrieve;
+  $results = tripal_pub_AGL_range($yazc, $search_str, $start, $num_to_retrieve, $total_records);
+
+  // close the connection
+  yaz_close($yazc);
+
+  return $results;
+}
+/**
+ * 
+ */
+function tripal_pub_AGL_range($yazc, $search_str, $start, $num_to_retrieve, $total_records) {
+  yaz_range($yazc, 1, $total_records);
+  if (!yaz_present($yazc)) {
+    $error_no = yaz_errno($yazc);
+    $error_msg = yaz_error($yazc);
+    $additional = yaz_addinfo($yazc);
+    if ($additional != $error_msg) {
+      $error_msg .= " $additional";
     }
-    $search_str = $cclresult["rpn"];
-
-    $search_array['search_string'] = $search_str;
-
-    // save the YAZ connection in the session for use by other functions
-    $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'] = $yazc;
-
-    //dpm($search_array);
-    // we want to get the list of pubs using the search terms but using a Drupal style pager
-    $pubs = tripal_pager_callback('tripal_pub_AGL_range',  $num_to_retrieve, $pager_id,
-    'tripal_pub_AGL_count', $search_array);
-
-    // close the connection
-    unset($_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection']);
-    yaz_close($yazc);
-
-    return $pubs;
+    drupal_set_message("ERROR waiting on search at AGL: ($error_no) $error_msg", "error");
+    watchdog('tpub_import', "ERROR waiting on search at AGL: (%error_no) %error_msg",
+    array('%error_no' => $error_no, '%error_msg' => $error_msg), WATCHDOG_ERROR);
+    return array(
+      'total_records' => $total_records,
+      'search_str'    => $search_str,
+      'pubs'          => array(),
+    );
+  }
+  if ($start + $num_to_retrieve > $total_records) {
+    $num_to_retrieve = $total_records - $start;
+  }
+  
+  $pubs = array();
+  for($i = $start; $i < $start + $num_to_retrieve; $i++) {
+    $pub_xml = yaz_record($yazc, $i + 1, 'xml; charset=marc-8,utf-8');
+    $pub     = tripal_pub_AGL_parse_pubxml($pub_xml);
+    $pubs[]  = $pub;
+  }
+  return array(
+    'total_records' => $total_records,
+    'search_str'    => $search_str,
+    'pubs'          => $pubs,
+  );
 }
 /*
  * This function is used as the callback function when used with the
  * tripal_pager_callback function.  This function returns a count of
  * the dataset to be paged.
  */
-function tripal_pub_AGL_count($search_array) {
-  $search_str = $search_array['search_string'];
-  $days       = $search_array['days'];
-  $limit      = $search_array['limit'];
+function tripal_pub_AGL_count($yazc, $search_str) {
 
-  $yazc = $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'];
   //yaz_sort($yazc, "1=31 id"); // sort by publication date descending
   if (!yaz_search($yazc, "rpn", $search_str)){
     $error_no = yaz_errno($yazc);
@@ -393,48 +424,9 @@ function tripal_pub_AGL_count($search_array) {
 
   // get the total number of results from the serach
   $count = yaz_hits($yazc);
-  $_SESSION['tripal_pub_AGL_query'][$search_str]['Count'] = $count;
   return $count;
 }
 
-/*
- * This function is used as the callback function when used with the
- * tripal_pager_callback function.  This function returns the results
- * within the specified range
- */
-function tripal_pub_AGL_range($search_array, $start = 0, $limit = 10) {
-  $pubs = array();
-
-  $search_str = $search_array['search_string'];
-  $days       = $search_array['days'];
-  $limit      = $search_array['limit'];
-
-  $yazc  = $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'];
-  $count = $_SESSION['tripal_pub_AGL_query'][$search_str]['Count'];
-  yaz_range($yazc, 1, $num_pubs);
-  if (!yaz_present($yazc)) {
-    $error_no = yaz_errno($yazc);
-    $error_msg = yaz_error($yazc);
-    $additional = yaz_addinfo($yazc);
-    if ($additional != $error_msg) {
-      $error_msg .= " $additional";
-    }
-    drupal_set_message("ERROR waiting on search at AGL: ($error_no) $error_msg", "error");
-    watchdog('tpub_import', "ERROR waiting on search at AGL: (%error_no) %error_msg",
-              array('%error_no' => $error_no, '%error_msg' => $error_msg), WATCHDOG_ERROR);
-    return $pubs;
-  }
-   
-  if ($start + $limit > $count) {
-    $limit = $count - $start;
-  }
-  for($i = $start; $i < $start + $limit; $i++) {
-    $pub_xml = yaz_record($yazc, $i + 1, 'xml; charset=marc-8,utf-8');
-    $pub     = tripal_pub_AGL_parse_pubxml($pub_xml);
-    $pubs[]  = $pub;
-  }
-  return $pubs;
-}
 
 /*
  * Description of XML format:
@@ -703,14 +695,14 @@ function tripal_pub_AGL_parse_pubxml($pub_xml) {
           $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {
             switch ($code) {
-            	case 'a':
-            		if (preg_match('/Proceedings/i', $value)) {
-            		  $pub['Series Name'] = preg_replace('/\.$/', '', $value);
-            		  $pub['Publication Type'][0] = 'Conference Proceedings';
-            		}
-            		else {
-            			$pub['Journal Name'] = preg_replace('/\.$/', '', $value);
-            		}
+              case 'a':
+                if (preg_match('/Proceedings/i', $value)) {
+                  $pub['Series Name'] = preg_replace('/\.$/', '', $value);
+                  $pub['Publication Type'][0] = 'Conference Proceedings';
+                }
+                else {
+                  $pub['Journal Name'] = preg_replace('/\.$/', '', $value);
+                }
                 break;
               case 't':
                 if (preg_match('/Proceedings/i', $value)) {
@@ -793,24 +785,31 @@ function tripal_pub_AGL_parse_pubxml($pub_xml) {
 
   // build the full authors list
   if (is_array($pub['Author List'])) {
-	  foreach ($pub['Author List'] as $author) {
-	    if ($author['valid'] == 'N') {
-	      // skip non-valid entries.  A non-valid entry should have
-	      // a corresponding corrected entry so we can saftely skip it.
-	      continue;
-	    }
-	    if ($author['Collective']) {
-	      $authors .= $author['Collective'] . ', ';
-	    }
-	    else {
-	      $authors .= $author['Surname'] . ' ' . $author['First Initials'] . ', ';
-	    }
-	  }
-	  $authors = substr($authors, 0, -2);
-	  $pub['Authors'] = $authors;
+    $authors = '';
+    foreach ($pub['Author List'] as $author) {
+      if (array_key_exists('valid', $author) and $author['valid'] == 'N') {
+        // skip non-valid entries.  A non-valid entry should have
+        // a corresponding corrected entry so we can saftely skip it.
+        continue;
+      }
+      if (array_key_exists('Collective', $author)) {
+        $authors .= $author['Collective'] . ', ';
+      }
+      else {
+        if (array_key_exists('Surname', $author)) {
+          $authors .= $author['Surname'];
+          if(array_key_exists('First Initials', $author)) {
+            $authors .= ' ' . $author['First Initials'];
+          }
+          $authors .= ', ';
+        }
+      }
+    }
+    $authors = substr($authors, 0, -2);
+    $pub['Authors'] = $authors;
   }
   else {
-    $pub['Authors'] = $pub['Author List'];	
+    $pub['Authors'] = $pub['Author List'];  
   }
 
   // build the citation

+ 46 - 84
tripal_pub/includes/importers/PMID.inc

@@ -9,13 +9,11 @@
 /**
  *
  */
-function tripal_pub_remote_alter_form_PMID($form, $form_state) {
-  $num_criteria = $form['num_criteria']['#default_value'];
-
+function tripal_pub_remote_alter_form_PMID($form, $form_state, $num_criteria = 1) {
   // PubMed doesn't have an 'Abstract' field, so we need to convert the criteria
   // from 'Abstract' to 'Title/Abstract'
   for($i = 1; $i <= $num_criteria; $i++) {
-    $form['criteria'][$i]["scope-$i"]['#options']['abstract'] = 'Abstract/Title';
+    $form['themed_element']['criteria'][$i]["scope-$i"]['#options']['abstract'] = 'Abstract/Title';
   }
 
   return $form;
@@ -24,7 +22,7 @@ function tripal_pub_remote_alter_form_PMID($form, $form_state) {
  *
  */
 function tripal_pub_remote_validate_form_PMID($form, $form_state) {
-  $num_criteria = $form['num_criteria']['#default_value'];
+  $num_criteria = $form_state['values']['num_criteria'];
 
   for ($i = 1; $i <= $num_criteria; $i++) {
     $search_terms =  trim($form_state['values']["search_terms-$i"]);
@@ -38,7 +36,7 @@ function tripal_pub_remote_validate_form_PMID($form, $form_state) {
 /**
  *
  */
-function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_id) {
+function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $page) {
 
   // convert the terms list provicded by the caller into a string with words
   // separated by a '+' symbol.
@@ -59,18 +57,18 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
 
     // if this is phrase make sure the search terms are surrounded by quotes
     if ($is_phrase) {
-      $search_str .= "(\"$search_terms\" |SCOPE|) ";
+      $search_str .= "(\"$search_terms\" |SCOPE|)";
     }
     // if this is not a phase then we want to separate each 'OR or 'AND' into a unique criteria
     else {
-    	$search_str .= "(";
-    	if (preg_match('/and/i', $search_terms)) {
-    	  $elements = preg_split('/\s+and+\s/i', $search_terms);
-    	  foreach ($elements as $element) {
+      $search_str .= "(";
+      if (preg_match('/and/i', $search_terms)) {
+        $elements = preg_split('/\s+and+\s/i', $search_terms);
+        foreach ($elements as $element) {
           $search_str .= "($element |SCOPE|) AND ";
-    	  }
-    	  $search_str = substr($search_str, 0, -5); // remove trailing 'AND '              
-    	} 
+        }
+        $search_str = substr($search_str, 0, -5); // remove trailing 'AND '              
+      } 
       elseif (preg_match('/or/i', $search_terms)) {
         $elements = preg_split('/\s+or+\s/i', $search_terms);
         foreach ($elements as $element) {
@@ -79,19 +77,19 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
         $search_str = substr($search_str, 0, -4); // remove trailing 'OR '        
       }
       else {
-      	$search_str .= "($search_terms |SCOPE|) ";
+        $search_str .= "($search_terms |SCOPE|)";
       }
-      $search_str .= ') ';
+      $search_str .= ')';
     }
 
     if ($scope == 'title') {
-    	$search_str = preg_replace('/\|SCOPE\|/', '[Title]', $search_str);
+      $search_str = preg_replace('/\|SCOPE\|/', '[Title]', $search_str);
     }
     elseif ($scope == 'author') {
-    	$search_str = preg_replace('/\|SCOPE\|/', '[Author]', $search_str);
+      $search_str = preg_replace('/\|SCOPE\|/', '[Author]', $search_str);
     }
     elseif ($scope == 'abstract') {
-    	$search_str = preg_replace('/\|SCOPE\|/', '[Title/Abstract]', $search_str);
+      $search_str = preg_replace('/\|SCOPE\|/', '[Title/Abstract]', $search_str);
     }
     elseif ($scope == 'journal') {
       $search_str = preg_replace('/\|SCOPE\|/', '[Journal]', $search_str);
@@ -111,66 +109,26 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
     $search_str .= " AND (\"" . sprintf("%04d/%02d/%02d", $past_date['year'], $past_date['mon'], $past_date['mday']) . "\"[Date - Create] : \"3000\"[Date - Create]))";
   }
 
-  $search_array['limit'] = $num_to_retrieve;
-  $search_array['search_string'] = $search_str;
-
-  //dpm($search_str);
-  unset($_SESSION['tripal_pub_PMID_query']);
-  // we want to get the list of pubs using the search terms but using a Drupal style pager
-  $pubs = tripal_pager_callback('tripal_pub_PMID_range',  $num_to_retrieve, $pager_id,
-    'tripal_pub_PMID_count', $search_array);
-
-  return $pubs;
-}
-
-/*
- * This function is used as the callback function when used with the
- * tripal_pager_callback function.  This function returns a count of
- * the dataset to be paged.
- */
-function tripal_pub_PMID_count($search_array) {
-  $search_str = $search_array['search_string'];
-  $limit = $search_array['limit'];
-
-  $results = tripal_pub_PMID_search_init($search_str, $limit);
-  $_SESSION['tripal_pub_PMID_query'][$search_str]['Count'] = $results['Count'];
-  $_SESSION['tripal_pub_PMID_query'][$search_str]['WebEnv'] = $results['WebEnv'];
-  $_SESSION['tripal_pub_PMID_query'][$search_str]['QueryKey'] = $results['QueryKey'];
-   
-  return $results['Count'];
-
-}
-
-/*
- * This function is used as the callback function when used with the
- * tripal_pager_callback function.  This function returns the results
- * within the specified range
- */
-function tripal_pub_PMID_range($search_array, $start = 0, $limit = 10) {
-  $search_str = $search_array['search_string'];
-  $limit = $search_array['limit'];
-
-  $count = $_SESSION['tripal_pub_PMID_query'][$search_str]['Count'];
-  if ($count == 0) {
-    return array();
-  }
-
-  // get the query_key and the web_env from the previous count query.
-  $query_key = $_SESSION['tripal_pub_PMID_query'][$search_str]['QueryKey'];
-  $web_env   = $_SESSION['tripal_pub_PMID_query'][$search_str]['WebEnv'];
-
-  // if this function has been called without calling the count function
-  // then we need to do the query.
-  if (!$query_key) {
-    $results = tripal_pub_PMID_search_init($search_str, $limit);
-    $_SESSION['tripal_pub_PMID_query']['WebEnv'] = $results['WebEnv'];
-    $_SESSION['tripal_pub_PMID_query']['QueryKey'] = $results['QueryKey'];
-    $query_key =  $results['QueryKey'];
-    $web_env = $results['WebEnv'];
+  // now initialize the query 
+  $results = tripal_pub_PMID_search_init($search_str, $num_to_retrieve);
+  $total_records = $results['Count'];
+  $query_key     = $results['QueryKey'];
+  $web_env       = $results['WebEnv'];
+  
+  // initialize the pager
+  $start = $page * $num_to_retrieve;
+  
+  // if we have no records then return an empty array
+  if ($total_records == 0) {
+    return array(
+      'total_records' => $total_records,
+      'search_str'    => $search_str,
+      'pubs'          => array(),
+    );
   }
-
-  // now get the list of PMIDs from the previous search
-  $pmids_txt = tripal_pub_PMID_fetch($query_key, $web_env, 'uilist', 'text', $start, $limit);
+  
+  // now get the list of PMIDs from the initialized search
+  $pmids_txt = tripal_pub_PMID_fetch($query_key, $web_env, 'uilist', 'text', $start, $num_to_retrieve);
 
   // iterate through each PMID and get the publication record. This requires a new search and new fetch
   $pmids = explode("\n", trim($pmids_txt));
@@ -181,7 +139,11 @@ function tripal_pub_PMID_range($search_array, $start = 0, $limit = 10) {
     $pub     = tripal_pub_PMID_parse_pubxml($pub_xml);
     $pubs[]  = $pub;
   }
-  return $pubs;
+  return array(
+    'total_records' => $total_records,
+    'search_str'    => $search_str,
+    'pubs'          => $pubs,
+  );
 }
 
 /*
@@ -335,7 +297,7 @@ function tripal_pub_PMID_parse_pubxml($pub_xml) {
           // just skip it.  Examples of other PMIDs are in the articles that
           // cite this one.
           $xml->read(); // get the value for this element
-          if(!$pub['Publication Dbxref']) {
+          if(!array_key_exists('Publication Dbxref', $pub)) {
             $pub['Publication Dbxref'] = 'PMID:' . $xml->value;
           }
           break;
@@ -696,9 +658,9 @@ function tripal_pub_PMID_parse_journal_issue($xml, &$pub) {
         case 'PubDate':
           $date = tripal_pub_PMID_parse_date($xml, 'PubDate');
           $year = $date['year'];
-          $month = $date['month'];
-          $day = $date['day'];
-          $medline = $date['medline'];
+          $month = array_key_exists('month', $date) ? $date['month'] : '';
+          $day = array_key_exists('day', $date) ? $date['day'] : '';
+          $medline = array_key_exists('medline', $date) ? $date['medline'] : '';
            
           $pub['Year'] = $year;
           if ($month and $day and $year) {
@@ -784,7 +746,7 @@ function tripal_pub_PMID_parse_authorlist($xml, &$pub) {
             // a corresponding corrected entry so we can saftely skip it.
             continue;
           }
-          if ($author['Collective']) {
+          if (array_key_exists('Collective', $author)) {
             $authors .= $author['Collective'] . ', ';
           }
           else {

+ 11 - 7
tripal_pub/includes/pub_citation.inc

@@ -4,22 +4,26 @@
 */
 function tripal_pub_citation_form($form_state) {
 
-  $form['create_all'] = array(
-    '#type' => 'item',
-    '#value' => t('Submit a job to create citation for the publications in chado. '),
+  $form['instructions'] = array(
+    '#markup' => '<p>Use this form to unify publication citations. Citations are created automtically when
+      importing publications but citations are set by the user when publications are added manually.  
+      Or publications added to the Chado database by tools other than the Tripal Publication Importer may 
+      not have citations set. If you are certain that all necessary information for all publications is present (e.g. 
+      authors, volume, issue, page numbers, etc.) but citations are not consistent, then you can
+      choose to update all citations for all publications using the form below. Alternatively, you
+      can update citations only for publication that do not already have one.</p>'
   );
   
   $form['options'] = array(
     '#type' => 'radios',
-    '#options' => 
-      array('all' => 'Create citation for all publications. Replace the existing citation if it exists.', 
-                'new' => 'Create citation for publication only if it does not already have one.'),
+    '#options' => array(
+      'all' => 'Create citation for all publications. Replace the existing citation if it exists.', 
+      'new' => 'Create citation for publication only if it does not already have one.'),
     '#default_value' => 'all'
   );
   
   $form['submit'] = array(
     '#type' => 'submit',
-    '#weight' => 10,
     '#value' => t('Submit')
   );
 

+ 188 - 129
tripal_pub/includes/pub_importers.inc

@@ -7,7 +7,7 @@
 function tripal_pub_importers_list() {
   // clear out the session variable when we view the list.
   unset($_SESSION['tripal_pub_import']);
-
+  
   $header = array('', 'Importer Name', 'Database', 'Search String', 'Disabled', 'Create Contact', '');
   $rows = array();
   $importers = db_query("SELECT * FROM {tripal_pub_import} ORDER BY name");
@@ -35,30 +35,35 @@ function tripal_pub_importers_list() {
     );
   }
 
-  $rows[] = array(
-    'data' => array(
-     array('data' => l(t('Create a new publication importer.'), "admin/tripal/chado/tripal_pub/import/new"),
-        'colspan' => 7),
-     )
-  );
 
   $page  = "<ul class='action-links'>";
   $page .= '  <li>' . l('New Importer', 'admin/tripal/chado/tripal_pub/import/new') . '</li>';
   $page .= '</ul>';
+  
+  $page .= '<p>' . t(
+    "A publication importer is used to create a set of search criteria that can be used
+     to query a remote database, find publications that match the specified criteria 
+     and then import those publications into the Chado database. An example use case would
+     be to peridocially add new publications to this Tripal site that have appeared in PubMed
+     in the last 30 days.  See the " . 
+     l("Pub Module help instructions", "admin/tripal/chado/tripal_pub/help") . " to learn how to 
+     set the importers to run automatically.") . '</p>';
 
   $page .= theme('table', array('header' => $header, 'rows' => $rows));
+  
   return $page;
 }
 
-/*
- *
+/**
+ * 
+ * @param  action
+ * @param $pub_import_id
+ * 
+ * 
  */
 function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL) {
-  global $pager_total, $pager_total_items;
-
-  $pager_id = 0;
-  $limit = 20;
-
+  global $base_path;
+  
   // make sure the tripal_pub and tripal_contact ontologies are loaded
   $values = array('name' => 'tripal_pub');
   $tpub_cv = tripal_core_chado_select('cv', array('cv_id'), $values);
@@ -70,6 +75,10 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
   if (count($tpub_cv) == 0) {
     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');
   }
+  
+  if(!extension_loaded ('yaz')){
+    drupal_set_message(t('<b>Note:</b> In order to create an importer using the USDA National Agricultural Library (AGL) you must install the yaz libraries. See the ') . l(t('Pub Module help page'), 'admin/tripal/chado/tripal_pub/help') . ' for assistance.  If you do not want to use AGL you can ignore this warning.', 'warning');
+  }
 
   // generate the search form
   $form = drupal_get_form('tripal_pub_importer_setup_form',  $pub_import_id, $action);
@@ -77,62 +86,100 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
   $output = l("Return to publication importers list", "admin/tripal/chado/tripal_pub/import_list");
   $output .= drupal_render($form);
 
-  /*
   // retrieve any results
-  $remote_db = $_SESSION['tripal_pub_import']['remote_db'];
-  $num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
-  $days = $_SESSION['tripal_pub_import']['days'];
-
-  $search_array = array();
-  $search_array['remote_db'] = $remote_db;
-  $search_array['num_criteria'] = $num_criteria;
-  $search_array['days'] = $days;
-  for ($i = 1; $i <= $num_criteria; $i++) {
-    $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'];
-    $search_array['criteria'][$i]['scope']        = $_SESSION['tripal_pub_import']['criteria'][$i]['scope'];
-    $search_array['criteria'][$i]['is_phrase']    = $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'];
-    $search_array['criteria'][$i]['operation']    = $_SESSION['tripal_pub_import']['criteria'][$i]['operation'];
-  }
-
-
-  if ($_SESSION['tripal_pub_import']['perform_search']) {
-    // get the list of publications from the remote database using the search criteria.
-    $pubs = tripal_pub_get_remote_search_results($remote_db, $search_array, $limit, $pager_id);
-    //dpm($pubs);
-
-    // generate the pager
-    $total_pages = $pager_total[$pager_id];
-    $total_items = $pager_total_items[$pager_id];
-    $page = isset($_GET['page']) ? $_GET['page'] : '0';
-    $pager = theme('pager');
-
-    // iterate through the results and construct the table displaying the publications
-    $rows = array();
-    $i = $page * $limit + 1;
-    if (count($pubs) > 0) {
-      foreach ($pubs as $pub) {
-        $citation = htmlspecialchars($pub['Citation']);
-        $raw_link = '';
-        if($pub['Publication Dbxref']) {
-          $raw_link = l('raw', 'admin/tripal/chado/tripal_pub/import/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
+  if (array_key_exists('tripal_pub_import', $_SESSION)) {
+    $remote_db = $_SESSION['tripal_pub_import']['remote_db'];
+    $num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
+    $days = $_SESSION['tripal_pub_import']['days'];
+  
+    $search_array = array();
+    $search_array['remote_db'] = $remote_db;
+    $search_array['num_criteria'] = $num_criteria;
+    $search_array['days'] = $days;
+    for ($i = 1; $i <= $num_criteria; $i++) {
+      $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'];
+      $search_array['criteria'][$i]['scope']        = $_SESSION['tripal_pub_import']['criteria'][$i]['scope'];
+      $search_array['criteria'][$i]['is_phrase']    = $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'];
+      $search_array['criteria'][$i]['operation']    = $_SESSION['tripal_pub_import']['criteria'][$i]['operation'];
+    }
+  
+    // if the form has been submitted with the 'test' button then get the results
+    if ($_SESSION['tripal_pub_import']['perform_search']) {
+      
+      $limit = 25;
+      
+      // get the list of publications from the remote database using the search criteria.
+      $page = isset($_GET['page']) ? $_GET['page'] : '0';
+      $results = tripal_pub_get_remote_search_results($remote_db, $search_array, $limit, $page);
+      $total_records = $results['total_records'];
+      $search_str    = $results['search_str'];
+      $pubs          = $results['pubs'];
+      
+      // iterate through the results and construct the table displaying the publications
+      $rows = array();
+      $i = $page * $limit + 1;
+      if (count($pubs) > 0) {
+        foreach ($pubs as $pub) {
+          $citation = htmlspecialchars($pub['Citation']);
+          $raw_link = '';
+          if($pub['Publication Dbxref']) {
+            $raw_link = l('raw', 'admin/tripal/chado/tripal_pub/import/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
+          }
+          $rows[] = array(
+            number_format($i),
+            $citation,
+            $raw_link,
+          );
+          $i++;
         }
+      }
+      
+      if (count($rows) == 0) {
         $rows[] = array(
-        number_format($i),
-        $citation,
-        $raw_link,
+          array(
+            'data' => 'No results found',
+            'colspan' => 3,
+          ),
         );
-        $i++;
       }
+      
+      $headers = array('', 'Publication', 'Raw Results');
+      $table = array(
+        'header' => $headers,
+        'rows' => $rows,
+        'attributes' => array(
+          'id' => 'tripal_pub-importer-test',
+        ),
+        'sticky' => FALSE,
+        'caption' => '',
+        'colgroups' => array(),
+        'empty' => '',
+      );
+      // once we have our table array structure defined, we call Drupal's theme_table()
+      // function to generate the table.
+      $table = theme_table($table);
+      
+      // generate the pager
+      pager_default_initialize($total_records, $limit);
+      $pager = array(
+        'tags' => array(),
+        'element' => 0,
+        'parameters' => array(),
+        'quantity' => $limit,
+      );
+      $pager = theme_pager($pager);
+      
+      // because this is an ajax callback, the theme_pager will set the URL to be
+      // "system/ajax", so we need to reset that
+      $pager = str_replace($base_path . "system/ajax", "", $pager) ;
+      
+      // join all to form the results
+      $total_pages = (int) ($total_records / $limit) + 1;
+      $page = isset($_GET['page']) ? $_GET['page'] : '0';
+      $output .= "$pager<br><b>Found " . number_format($total_records) . " publications. Page " . ($page + 1) . " of $total_pages.</b> " .
+      "<br>$remote_db Search String: $search_str $table<br>$pager";
     }
-    $headers = array('', 'Publication', '');
-    $table = theme('table', array('header' => $headers, 'rows' => $rows));
-
-    // join all to form the results
-    $output .= "<br><p><b>Found " . number_format($total_items) .
-      ". Page " . ($page + 1) . " of $total_pages. " .
-      " Results</b></br>" . $table . '</p>' . $pager;
   }
-  */
   return $output;
 }
 
@@ -142,6 +189,7 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
  * @ingroup tripal_pub
  */
 function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_id = NULL, $action = 'new') {
+
   // Default values can come in the following ways:
   //
   // 1) as elements of the $pub_importer object.  This occurs when editing an existing importer 
@@ -151,8 +199,7 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
   //    form elements and the form is being rebuilt
   //
   // set form field defaults
-  
-  
+    
   // Set the default values. If the pub_import_id isn't already defined by the form values
   // and one is provided then look it up in the database
   $criteria = NULL;
@@ -160,7 +207,7 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
   $days = '';
   $disabled = '';
   $do_contact = '';
-  $num_criteria = '';
+  $num_criteria = 1;
   $loader_name = '';
   
   // if this is an edit the we are pulling an import object from the database
@@ -176,6 +223,17 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
     $num_criteria   = $criteria['num_criteria'];
     $loader_name    = $criteria['loader_name'];
   }
+  
+  // if there are any session variables then use those
+  if (array_key_exists('tripal_pub_import', $_SESSION)) {
+    $remote_db    = $_SESSION['tripal_pub_import']['remote_db'];
+    $days         = $_SESSION['tripal_pub_import']['days'];
+    $disabled     = $_SESSION['tripal_pub_import']['disabled'];
+    $do_contact   = $_SESSION['tripal_pub_import']['do_contact'];
+    $num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
+    $loader_name  = $_SESSION['tripal_pub_import']['loader_name'];
+  }
+  
   // if we are re constructing the form from a failed validation or ajax callback
   // then use the $form_state['values'] values
   if (array_key_exists('values', $form_state)) {
@@ -193,45 +251,47 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
     $days         = $form_state['input']['days'];
     $disabled     = $form_state['input']['disabled'];
     $do_contact   = $form_state['input']['do_contact'];
-    $num_criteria = $form_state['input']['num_criteria'];
     $loader_name  = $form_state['input']['loader_name'];
+    
+    // because the num_criteria is a value and not a visible or hidden form
+    // element it is not part of the ['input'] array, so we need to get it from the form
+    $num_criteria = $form_state['complete form']['num_criteria']['#value'];
   }
 
-  // check if the pub_import_id in the session variable is not the same as the one we've been provided
-  // if so, then clear the session variable
-//  if ($pub_import_id and $pub_import_id != $_SESSION['tripal_pub_import']['pub_import_id']) {
-//    unset($_SESSION['tripal_pub_import']);
-//  }
-
-
-  // change the number of criteria based on form_state post data.
-  if (!$num_criteria) {
-    $num_criteria = 1;
-  }
-/*  
-  if($form_state['post']["add-$num_criteria"]) {
+  if (array_key_exists('triggering_element', $form_state) and
+  $form_state['triggering_element']['#name'] == 'add') {
     $num_criteria++;
   }
-  if($form_state['post']["remove-$num_criteria"]) {
+  if (array_key_exists('triggering_element', $form_state) and
+  $form_state['triggering_element']['#name'] == 'remove') {
     $num_criteria--;
   }
-*/
   
+  // check if the pub_import_id in the session variable is not the same as the one we've been provided
+  // if so, then clear the session variable
+  if ($pub_import_id and $pub_import_id != $_SESSION['tripal_pub_import']['pub_import_id']) {
+    unset($_SESSION['tripal_pub_import']);
+  }
+  
+  // set the values we need for later but that should not be shown on the form
+  $form['num_criteria']= array(
+    '#type'  => 'value',
+    '#value' => $num_criteria,
+  );
   $form['pub_import_id'] = array(
-    '#type'          => 'hidden',
-    '#value'         => $pub_import_id,
-    '#required'      => TRUE,
+    '#type'  => 'value',
+    '#value' => $pub_import_id,
   );
   $form['action'] = array(
-    '#type'          => 'hidden',
-    '#value'         => $action,
-    '#required'      => TRUE,
+    '#type'  => 'value',
+    '#value' => $action,
   );
 
+  // add in the elements that will be organized via a theme function
   $form['themed_element']['loader_name'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Loader Name'),
-    '#description'   => t('Please provide a name for this loader setup..'),
+    '#description'   => t('Please provide a name for this loader setup.'),
     '#default_value' => $loader_name,
     '#required'      => TRUE,
   );
@@ -261,16 +321,6 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
       'method'   => 'replace',
     ),
   );
-
-  $form['num_criteria']= array(
-    '#type'          => 'hidden',
-    '#default_value' => $num_criteria,
-  );
-  $form['pub_import_id']= array(
-    '#type'          => 'hidden',
-    '#default_value' => $pub_import_id,
-  );
-
   $form['themed_element']['days'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Days since record modified'),
@@ -295,28 +345,29 @@ function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_
   // add in the form for the criteria
   tripal_pub_importer_setup_add_criteria_fields($form, $form_state, $num_criteria, $criteria);
 
-  $form['test'] = array(
-    '#type'         => 'submit',
-    '#value'        => t('Test Importer'),
-  );
+  // add in the buttons
   $form['save'] = array(
     '#type'         => 'submit',
     '#value'        => t('Save Importer'),
   );
-  /*
-  $form['import'] = array(
+  $form['test'] = array(
     '#type'         => 'submit',
-    '#value'        => t('Save & Import Now'),
+    '#value'        => t('Test Importer'),
   );
-  */
   $form['delete'] = array(
     '#type'         => 'submit',
     '#value'        => t('Delete Importer'),
+    '#attributes'  => array('style' => 'float: right;')
+  );
+  
+  // add in the section where the test results will appear
+  $form['results'] = array(
+    '#markup' => '<div id="tripal-pub-importer-test-section"></div>',
   );
   
   // allow the selected remote database to make changes to the form if needed
   $callback = "tripal_pub_remote_alter_form_$remote_db";
-  $form = call_user_func($callback, $form, $form_state);
+  $form = call_user_func($callback, $form, $form_state, $num_criteria);
  
   $form['themed_element']['#theme'] = 'tripal_pub_importer_setup_form_elements';
   
@@ -367,15 +418,15 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
       $is_phrase    = $criteria['criteria'][$i]['is_phrase'];
       $operation    = $criteria['criteria'][$i]['operation'];
     }
+
+    // if the criteria comes the session
+    if (array_key_exists('tripal_pub_import', $_SESSION)) {
+      $search_terms = isset($_SESSION['tripal_pub_import']['criteria'][$i]['search_terms']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'] : $search_terms;
+      $scope        = isset($_SESSION['tripal_pub_import']['criteria'][$i]['scope'])        ? $_SESSION['tripal_pub_import']['criteria'][$i]['scope']        : $scope;
+      $is_phrase    = isset($_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'])    ? $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase']    : $is_phrase;
+      $operation    = isset($_SESSION['tripal_pub_import']['criteria'][$i]['operation'])    ? $_SESSION['tripal_pub_import']['criteria'][$i]['operation']    : $operation;
+    }
     
-/*    
-    // if we're here because the form was posted then load from the session variable (we lost the form state)
-    $search_terms = isset($_SESSION['tripal_pub_import']['criteria'][$i]['search_terms']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'] : $search_terms;
-    $scope        = isset($_SESSION['tripal_pub_import']['criteria'][$i]['scope'])        ? $_SESSION['tripal_pub_import']['criteria'][$i]['scope']        : $scope;
-    $is_phrase    = isset($_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'])    ? $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase']    : $is_phrase;
-    $operation    = isset($_SESSION['tripal_pub_import']['criteria'][$i]['operation'])    ? $_SESSION['tripal_pub_import']['criteria'][$i]['operation']    : $operation;
-*/
-      
     // If the form_state has variables then use those.  This happens when an error occurs on the form or the
     // form is resbumitted using AJAX
     if (array_key_exists('values', $form_state)) {
@@ -394,7 +445,7 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
       '#type'          => 'textfield',
       '#description'   => t('<span style="white-space: normal">Please provide a list of words for searching. You may use
         conjunctions such as "AND" or "OR" to separate words if they are expected in
-        the same scope, but do not mix ANDs and ORs.  Uncheck the "Is Phrase" checkbox to use conjunctions</span>'),
+        the same scope, but do not mix ANDs and ORs.  Check the "Is Phrase" checkbox to use conjunctions as part of the text to search</span>'),
       '#default_value' => $search_terms,
       '#required'      => TRUE,
       '#maxlength' => 2048,
@@ -440,8 +491,8 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
           // but we need it or Drupal will run the default validate anyway.
           // we also set #limit_validation_errors to empty so fields that
           // are required that don't have values won't generate warnings.
-          '#submit'   => array('tripal_pub_setup_form_criteria_button_submit'),
-          '#validate' => array('tripal_pub_setup_form_criteria_button_validate'),
+          '#submit'   => array('tripal_pub_setup_form_ajax_button_submit'),
+          '#validate' => array('tripal_pub_setup_form_ajax_button_validate'),
           '#limit_validation_errors' => array(),
         );
       }
@@ -463,8 +514,8 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
         // but we need it or Drupal will run the default validate anyway.
         // we also set #limit_validation_errors to empty so fields that
         // are required that don't have values won't generate warnings.
-        '#submit'   => array('tripal_pub_setup_form_criteria_button_submit'),
-        '#validate' => array('tripal_pub_setup_form_criteria_button_validate'),
+        '#submit'   => array('tripal_pub_setup_form_ajax_button_submit'),
+        '#validate' => array('tripal_pub_setup_form_ajax_button_validate'),
         '#limit_validation_errors' => array(),
       );
     }
@@ -476,13 +527,13 @@ function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $nu
  * the validate and submit routines on the form button. Therefore, this function
  * only needs to tell Drupal to rebuild the form
  */
-function  tripal_pub_setup_form_criteria_button_validate($form, &$form_state){
+function  tripal_pub_setup_form_ajax_button_validate($form, &$form_state){
   $form_state['rebuild'] = TRUE;
 }
 /**
  * This function is just a dummy to override the default form submit on ajax calls for buttons
  */
-function tripal_pub_setup_form_criteria_button_submit($form, &$form_state){
+function tripal_pub_setup_form_ajax_button_submit($form, &$form_state){
   // do nothing
 }
 /**
@@ -500,7 +551,10 @@ function tripal_pub_importer_setup_form_validate($form, &$form_state) {
     $search_terms =  trim($form_state['values']["search_terms-$i"]);
     $scope =  $form_state['values']["scope-$i"];
     $is_phrase =  $form_state['values']["is_phrase-$i"];
-    $operation =  $form_state['values']["operation-$i"];
+    $operation = '';
+    if($i > 1) {      
+      $operation =  $form_state['values']["operation-$i"];
+    }
 
     if (!$is_phrase) {
       if (preg_match('/and/i', $search_terms) and preg_match('/or/i', $search_terms)) {
@@ -545,7 +599,10 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
     $search_terms =  trim($form_state['values']["search_terms-$i"]);
     $scope =  $form_state['values']["scope-$i"];
     $is_phrase =  $form_state['values']["is_phrase-$i"];
-    $operation =  $form_state['values']["operation-$i"];
+    $operation = '';
+    if ($i > 1) {
+      $operation =  $form_state['values']["operation-$i"];
+    }
 
     $_SESSION['tripal_pub_import']['criteria'][$i] = array(
       'search_terms' => $search_terms,
@@ -629,10 +686,12 @@ function theme_tripal_pub_importer_setup_form_elements($variables) {
 
   // first render the fields at the top of the form
   $markup  = '';
-  $markup .= '<div>' . drupal_render($form['remote_db']) . '</div>';
-  $markup .= '<div id="pub-search-form-row1">';
-  $markup .= '  <div id="pub-search-form-col1">' . drupal_render($form['loader_name']) . '</div>';
-  $markup .= '  <div id="pub-search-form-col3">' . drupal_render($form['days']) . '</div>';
+  $markup .= '<div id="pub-search-form-row0">';
+  $markup .= '  <div id="pub-search-form-row0-col1" style="float: left">' . drupal_render($form['remote_db']) . '</div>';
+  $markup .= '  <div id="pub-search-form-row0-col2" style="float: left; margin-left: 10px">' . drupal_render($form['loader_name']) . '</div>';
+  $markup .= '</div>';
+  $markup .= '<div id="pub-search-form-row1" style="clear:both">';
+  $markup .= '  <div id="pub-search-form-row1-col1">' . drupal_render($form['days']) . '</div>';
   $markup .= '</div>';
   $markup .= '<div id="pub-search-form-row2">' . drupal_render($form['disabled']) . '</div>';
   $markup .= '<div id="pub-search-form-row3">' . drupal_render($form['do_contact']) . '</div>';

+ 23 - 14
tripal_pub/tripal_pub.module

@@ -53,7 +53,7 @@ function tripal_pub_node_info() {
 /**
  * Tripal-Publication-Menu
  *
- * Implemets hook_menu(): Adds menu items for the tripal_pub module menu. This section
+ * Implements hook_menu(): Adds menu items for the tripal_pub module menu. This section
  * gives the outline for the main menu of the Tripal-Publication module
  *
  * @return
@@ -117,6 +117,16 @@ function tripal_pub_menu() {
     'weight' => 2
   );
 
+  $items['admin/tripal/chado/tripal_pub/citation'] = array(
+    'title' => 'Citations',
+    'description' => 'Update publication citations',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_pub_citation_form'),
+    'access arguments' => array('administer tripal pubs'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 1
+  );
+  
   $items['admin/tripal/chado/tripal_pub/import_list'] = array(
     'title' => t('Importers'),
     'description' => t('List all publication importers'),
@@ -125,12 +135,20 @@ function tripal_pub_menu() {
     'type' => MENU_LOCAL_TASK,
     'weight' => 0
   );
-
+  
+  // add a second link for the importer on the data loaders page
+  $items['admin/tripal/loaders/pub_import'] = array(
+    'title' => 'Publications Importers',
+    'description' => 'Create importers that can periodically import publications from remote online publication databases.',
+    'page callback' => 'tripal_pub_importers_list',
+    'access arguments' => array('administer tripal pubs'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  
   $items['admin/tripal/chado/tripal_pub/import/new'] = array(
     'title' => t('Add an Importer'),
     'description' => t('Add a new publication importer.'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_pub_importer_setup_form'),
+    'page callback' => 'tripal_pub_importer_setup_page',
     'access arguments' => array('administer tripal pubs'),
     'type ' => MENU_CALLBACK,
   );
@@ -144,7 +162,7 @@ function tripal_pub_menu() {
 
   $items['admin/tripal/chado/tripal_pub/import/edit/%'] = array(
     'page callback' => 'tripal_pub_importer_setup_page',
-    'page arguments' => array(4, 5),
+    'page arguments' => array(5, 6),
     'access arguments' => array('administer tripal pubs'),
     'type ' => MENU_CALLBACK,
   );
@@ -186,15 +204,6 @@ function tripal_pub_menu() {
     'type ' => MENU_CALLBACK,
   );
 
-  $items['admin/tripal/chado/tripal_pub/citation'] = array(
-      'title' => ' Create Citations',
-      'description' => 'Create citations in Chado with Drupal',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_pub_citation_form'),
-      'access arguments' => array('administer tripal pubs'),
-      'type' => MENU_CALLBACK,
-  );
-
   return $items;
 }
 

+ 2 - 2
tripal_pub/tripal_pub.views_default.inc

@@ -85,8 +85,8 @@ function tripal_pub_defaultview_admin_publications() {
     'path-1' => 'node/add/tripal-pub',
   );
   $handler->display->display_options['header']['action_links_area']['link-2'] = array(
-    'label-2' => 'Add Citation',
-    'path-2' => 'admin/tripal/chado/tripal_pub/citation',
+    'label-2' => '',
+    'path-2' => '',
   );
   $handler->display->display_options['header']['action_links_area']['link-3'] = array(
     'label-3' => '',