Browse Source

Renamed AGRICOLA to AGL, and almost complete with that importer

spficklin 12 years ago
parent
commit
57ce94d058

+ 172 - 70
tripal_pub/includes/agricola.inc → tripal_pub/includes/importers/AGL.inc

@@ -6,7 +6,6 @@
  * 3) Add "extension=yaz.so" to php.ini
  * 4) Restart apache
  * 
- *  http://agricola.nal.usda.gov/help/z3950.html
  *  
  */
 
@@ -14,64 +13,109 @@
 /**
  *
  */
-function tripal_pub_remote_search_AGRICOLA($search_array, $num_to_retrieve, $pager_id) {
-  // get some values from the serach array
+function tripal_pub_remote_search_AGL($search_array, $num_to_retrieve, $pager_id) {
+  // 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;
   
   // Build the query by iterating through the search array values
-  $search_str = '';
-  for ($i = 0; $i <= $num_criteria; $i++) {
-    $search_terms = $search_array['criteria'][$i]['search_terms'];
+  $ccl = '';
+  for ($i = 1; $i <= $num_criteria; $i++) {
+    $search_terms = trim($search_array['criteria'][$i]['search_terms']);
     $scope = $search_array['criteria'][$i]['scope'];
+    $is_phrase = $search_array['criteria'][$i]['is_phrase'];
     $op = $search_array['criteria'][$i]['operation'];
-    // Quick Reference For Attribute Fields 
-    // (eg: "@attr 2=" refers to the Relation attribute) 
-    // 1 = Use Field
-    // 2 = Relation
-    // 3 = Position
-    // 4 = Structure
-    // 5 = Truncate
-    // 6 = Completeness
-    // The attribute set used by AGRICOLA can be found at the bottom of this page:
-    // http://agricola.nal.usda.gov/help/z3950.html  
-    // 1003 == Author
-    // 4 = Title
     if ($op) {
-      $search_str .= "$op";
+      $ccl .= " " . strtolower($op) . " ";
+    }
+    $search_terms = trim($search_terms);
+    // if this is not a phrase then make sure the AND and OR are lower-case
+    if (!$is_phrase) {
+      $search_terms = preg_replace('/ OR /', ' or ', $search_terms);
+      $search_terms = preg_replace('/ AND /', ' and ', $search_terms);
+    }
+    // else make sure the search terms are surrounded by quotes 
+    else {
+      $search_terms = "\"$search_terms\""; 
     }        
-    if($scope == 'title') {
-      $search_str = "@attr 1=4 \"$search_terms\"";
+    $ccl .= ' (';
+    if ($scope == 'title') {      
+      $ccl .= "title=($search_terms)";
     }    
-    elseif($scope == 'author') {
+    elseif ($scope == 'author') {
+      $ccl .= "author=($search_terms)";
     }    
-    elseif($scope == 'abstract') {
+    elseif ($scope == 'abstit') {
+      $ccl .= "(title=($search_terms) or abstract=($search_terms))";
     }
-    elseif($scope == 'id') {
-       
-    }    
-  }   
-  dpm($search_str); 
-         
-  $search_array['limit'] = $num_to_retrieve;
-  $search_array['search_string'] = $search_str; 
+    elseif ($scope == 'id') {
+      $search_terms = preg_replace('/AGL:([^\s]*)/', 'id=($1)', $search_terms);
+      $ccl .= $search_terms;
+    }  
+    else {
+     $ccl .= "$search_terms"; 
+    }
+    $ccl .= ') ';
+  } 
+
+  if ($days) {
+    // get the date of the day suggested
+    $past_timestamp = time() - ($days * 86400);
+    $past_date = getdate($past_timestamp); 
+    $ccl .= " and (date>=" . sprintf("%04d%02d%02d", $past_date['year'], $past_date['mon'], $past_date['mday']) . ")";
+  }
+  //$ccl = "(date=20110805220826.0)";
 
   // yaz_connect() prepares for a connection to a Z39.50 server. This function is non-blocking 
   // and does not attempt to establish a connection - it merely prepares a connect to be 
   // performed later when yaz_wait() is called.
   //$yazc = yaz_connect('agricola.nal.usda.gov:7090/voyager'); // NAL Catalog
   $yazc = yaz_connect('agricola.nal.usda.gov:7190/voyager');  // NAL Article Citation Database
-  $_SESSION['tripal_pub_AGRICOLA_query'][$search_str]['yaz_connection'] = $yazc;
-  
+    
   // use the USMARC record type.  But OPAC is also supported by Agricola
   yaz_syntax($yazc, "usmarc");
   
+  // the search query is built using CCL, we need to first
+  // configure it so it can map the attributes to defined identifiers
+  // The attribute set used by AGL can be found at the bottom of this page:
+  // http://agricola.nal.usda.gov/help/z3950.html  
+  // 
+  // More in depth details:  http://www.loc.gov/z3950/agency/bib1.html
+  //
+  // CCL Syntax: http://www.indexdata.com/yaz/doc/tools.html#CCL
+  //
+  $fields = array(
+    "title"    => "u=4",
+    "author"   => "u=1003",
+    "abstract" => "u=62",
+    "id"       => "u=12",
+    "date"     => "u=1012 r=o p=3 s=100 ", 
+  );
+  yaz_ccl_conf($yazc, $fields);
+  
+  //dpm($ccl);
+  if (!yaz_ccl_parse($yazc, $ccl, &$cclresult)) {
+    drupal_set_message('Error parsing search string: ' . $cclresult["errorstring"], "error");
+    watchdog('tripal_pub', 'Error: %errstr', array('%errstr' => $cclresult["errorstring"]), WATCHDOG_ERROR);
+    return array();
+  } 
+  $search_str = $cclresult["rpn"];    
+  
+  $search_array['search_string'] = $search_str;
+  //dpm($search_array);
+    
+  // save the YAZ connection in the session for use by other functions
+  $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'] = $yazc;
+  
   // we want to get the list of pubs using the search terms but using a Drupal style pager
-  $pubs = tripal_pager_callback('tripal_pub_AGRICOLA_range',  $num_to_retrieve, $pager_id, 
-    'tripal_pub_AGRICOLA_count', $search_array);
+  $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_AGRICOLA_query'][$search_str]['yaz_connection']);
+  unset($_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection']);
   yaz_close($yazc);  
   
   return $pubs;
@@ -81,18 +125,37 @@ function tripal_pub_remote_search_AGRICOLA($search_array, $num_to_retrieve, $pag
  * tripal_pager_callback function.  This function returns a count of
  * the dataset to be paged.
  */
-function tripal_pub_AGRICOLA_count($search_array) {
+function tripal_pub_AGL_count($search_array) {
   $search_str = $search_array['search_string'];
   $days       = $search_array['days'];
   $limit      = $search_array['limit'];
   
-  $yazc = $_SESSION['tripal_pub_AGRICOLA_query'][$search_str]['yaz_connection'];
-  yaz_search($yazc, "rpn", $search_str);  
-  yaz_wait();
+  $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);
+    $error_msg = yaz_error($yazc);
+    $additional = yaz_addinfo($yazc);
+    if ($additional != $error_msg) {
+      $error_msg .= " $additional";
+    }
+    drupal_set_message("ERROR preparing search at AGL: ($error_no) $error_msg", "error");
+    return 0;    
+  }
+  if (!yaz_wait()) {
+    $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");
+    return 0;
+  }
   
   // get the total number of results from the serach
   $count = yaz_hits($yazc);  
-  $_SESSION['tripal_pub_AGRICOLA_query'][$search_str]['Count'] = $count; 
+  $_SESSION['tripal_pub_AGL_query'][$search_str]['Count'] = $count; 
   return $count;
 }
 
@@ -101,23 +164,33 @@ function tripal_pub_AGRICOLA_count($search_array) {
  * tripal_pager_callback function.  This function returns the results
  * within the specified range
  */
-function tripal_pub_AGRICOLA_range($search_array, $start = 0, $limit = 10) {
+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_AGRICOLA_query'][$search_str]['yaz_connection'];
-  $count = $_SESSION['tripal_pub_AGRICOLA_query'][$search_str]['Count'];
+  $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); 
-  yaz_present($yazc);
-  
-  $pubs = array();   
+  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");
+    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_AGRICOLA_parse_pubxml($pub_xml);
+    $pub     = tripal_pub_AGL_parse_pubxml($pub_xml);
     $pubs[]  = $pub;     
   } 
   return $pubs;
@@ -128,7 +201,7 @@ function tripal_pub_AGRICOLA_range($search_array, $start = 0, $limit = 10) {
  * http://www.loc.gov/marc/bibliographic/bdsummary.html
  * 
  */
-function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
+function tripal_pub_AGL_parse_pubxml($pub_xml) {
   $pub = array();
   
   if (!$pub_xml) {
@@ -147,6 +220,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
       $value = $xml->value;
       switch ($tag) {
         case '001':  // control number
+          $pub['Publication Accession'] = $value;
           break;
         case '003':  // control number identifier
           break;
@@ -163,8 +237,9 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
             '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', 
             '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'
           );
-          $date1 = substr($value, 7, 4);
-          $date2 = substr($value, 11, 4);
+          $date0 = substr($value, 0, 6);  // date entered on file
+          $date1 = substr($value, 7, 4);  // year of publication
+          $date2 = substr($value, 11, 4); // month of publication
           $place = substr($value, 15, 3);
           $lang  = substr($value, 35, 3);
           if (preg_match('/\d\d\d\d/', $date1)) {
@@ -193,18 +268,35 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
         case '16':  // National Bibliographic Agency Control Number
           break;
         case '35':  // System Control Number
-          break;
+          $author = array();
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
+          foreach ($codes as $code => $value) {    
+            switch ($code) {                
+              case 'a': // System control number
+                $pub['Publication Accession'] = $value;
+                break;
+            }
+          }
         case '40':  // Cataloging Source (NR)
+          $author = array();
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
+          foreach ($codes as $code => $value) {    
+            switch ($code) {                
+              case 'a':  // original cataolging agency
+                $pub['Publication Database'] = $value;
+                break;
+            }
+          }
           break;
         case '72':  // Subject Category Code
           break;
         case '100':  // main entry-personal name
-          $author = tripal_pub_remote_search_AGRICOLA_get_author($xml, $ind1);
+          $author = tripal_pub_remote_search_AGL_get_author($xml, $ind1);
           $pub['Author List'][] = $author; 
           break;
         case '110':  // main entry-corporate nmae
           $author = array();
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {                
               case 'a': // Corporate name or jurisdiction name as entry elemen
@@ -233,7 +325,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
         case '243':  // collective uniform title
           break;
         case '245':  // title statement
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {          
             switch ($code) {                
               case 'a':
@@ -266,7 +358,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
         case '258':  // philatelic issue data
           break;
         case '260':  // publication, distribution ,etc (imprint)
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {          
             switch ($code) {                
               case 'a':
@@ -289,7 +381,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
           break;
           
         case '300':  // Address
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {          
             switch ($code) {                
               case 'a':
@@ -314,7 +406,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
         case '504':  // Bibliography, Etc. Note
           break;
         case '520':  // Summary, etc
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {                
               case 'a':
@@ -324,7 +416,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
           }
           break;
         case '650':  // Subject Added Entry-Topical Term
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {
               case 'a':
@@ -334,7 +426,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
           }          
           break;
         case '653':  // Index Term-Uncontrolled
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {
               case 'a':
@@ -344,12 +436,12 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
           }
           break;
         case '700':  // Added Entry-Personal Name
-          $author = tripal_pub_remote_search_AGRICOLA_get_author($xml, $ind1);
+          $author = tripal_pub_remote_search_AGL_get_author($xml, $ind1);
           $pub['Author List'][] = $author; 
           break;
         case '710':  // Added Entry-Corporate Name
           $author = array();
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {                
               case 'a': // Corporate name or jurisdiction name as entry elemen
@@ -363,7 +455,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
           $pub['Author List'][] = $author; 
           break;
         case '773': // host item entry
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {                
               case 't':                
@@ -417,7 +509,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
         case '852': // Location (Where is the publication held)
           break;
         case '856': // Electronic Location and Access
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           foreach ($codes as $code => $value) {    
             switch ($code) {
               case 'u':
@@ -427,13 +519,23 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
           }
           break;
         default:
-          $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+          $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
           $unhandled[$tag][] = $codes;
           break;
       }
     }
   }
-  dpm($unhandled);
+  //dpm($unhandled);
+  
+  // build the Dbxref
+  if ($pub['Publication Database'] != 'AGL') {
+    
+  }
+  if ($pub['Publication Accession'] and $pub['Publication Database']) {
+    $pub['Publication Dbxref'] = $pub['Publication Database'] . ":" . $pub['Publication Accession'];
+    unset($pub['Publication Accession']);
+    unset($pub['Publication Database']);
+  }
 
   // build the full authors list
   foreach ($pub['Author List'] as $author) {
@@ -463,7 +565,7 @@ function tripal_pub_AGRICOLA_parse_pubxml($pub_xml) {
  * 
  * 
  */
-function tripal_pub_remote_search_AGRICOLA_get_subfield($xml) {
+function tripal_pub_remote_search_AGL_get_subfield($xml) {
   $codes = array();
   while ($xml->read()) {    
     $sub_element = $xml->name;
@@ -486,9 +588,9 @@ function tripal_pub_remote_search_AGRICOLA_get_subfield($xml) {
  * 
  * 
  */
-function tripal_pub_remote_search_AGRICOLA_get_author($xml, $ind1) {
+function tripal_pub_remote_search_AGL_get_author($xml, $ind1) {
   $author = array();
-  $codes = tripal_pub_remote_search_AGRICOLA_get_subfield($xml);
+  $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
   foreach ($codes as $code => $value) {          
     switch ($code) {                
       case 'a':

+ 43 - 30
tripal_pub/includes/pubmed.inc → tripal_pub/includes/importers/PMID.inc

@@ -18,34 +18,51 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
   $days = $search_array['days'];
 
   $search_str = '';
-  for ($i = 0; $i <= $num_criteria; $i++) {
-    $search_terms = $search_array['criteria'][$i]['search_terms'];
+  for ($i = 1; $i <= $num_criteria; $i++) {
+    $search_terms = trim($search_array['criteria'][$i]['search_terms']);
     $scope = $search_array['criteria'][$i]['scope'];
+    $is_phrase = $search_array['criteria'][$i]['is_phrase'];
     $op = $search_array['criteria'][$i]['operation'];
     
     if ($op) {
       $search_str .= "$op";
-    }
+    }    
     
+    // if this is phrase make sure the search terms are surrounded by quotes
+    if ($is_phrase) {
+      $search_terms = "\"$search_terms\""; 
+    }
     $search_str .= '(';
     
-    if($scope == 'title') {
-      $search_str .= '"' . implode("+", preg_split('/\s+/', trim($search_terms))) . '"[Title]';
+    if ($scope == 'title') {
+      $search_str .= $search_terms . '[Title]';
     }    
-    elseif($scope == 'author') {
-      $search_str .= '"' . implode("+", preg_split('/\s+/', trim($search_terms))) . '"[Author]';
+    elseif ($scope == 'author') {
+      $search_str .= $search_terms . '[Author]';
     }    
-    elseif($scope == 'abstract') {
-      $search_str .= '"' . implode("+", preg_split('/\s+/', trim($search_terms))) . '"[Title/Abstract]';
+    elseif ($scope == 'abstit') {
+      $search_str .= $search_terms . '[Title/Abstract]';
     }
-    elseif($scope == 'id') {
-      $search_str .= '' . implode("+", preg_split('/\s+/', trim($search_terms))) . '[Uid]';      
+    elseif ($scope == 'id') {
+      $search_terms = preg_replace('/PMID:([^\s]*)/', 'id=($1)', $search_terms);
+      $search_str .= '(' . $search_terms . ')[Uid]';      
+    }
+    else {
+      $search_str .= $search_terms;
     }    
     $search_str .= ')'; 
   }  
+  if ($days) {
+    // get the date of the day suggested
+    $past_timestamp = time() - ($days * 86400);
+    $past_date = getdate($past_timestamp); 
+    $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;
-    
+  $search_array['search_string'] = $search_str;  
+  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_PMID_range',  $num_to_retrieve, $pager_id, 
     'tripal_pub_PMID_count', $search_array);
@@ -59,14 +76,13 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
  * the dataset to be paged.
  */
 function tripal_pub_PMID_count($search_array) {
-  $terms = $search_array['search_string'];
-  $days  = $search_array['days'];
+  $search_str = $search_array['search_string'];
   $limit = $search_array['limit'];
   
-  $results = tripal_pub_PMID_search_init($terms, $limit, $days);
-  $_SESSION['tripal_pub_PMID_query'][$terms]['Count'] = $results['Count'];
-  $_SESSION['tripal_pub_PMID_query'][$terms]['WebEnv'] = $results['WebEnv'];
-  $_SESSION['tripal_pub_PMID_query'][$terms]['QueryKey'] = $results['QueryKey'];
+  $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'];
 
@@ -78,23 +94,22 @@ function tripal_pub_PMID_count($search_array) {
  * within the specified range
  */
 function tripal_pub_PMID_range($search_array, $start = 0, $limit = 10) {
-  $terms = $search_array['search_string'];
-  $days  = $search_array['days'];
+  $search_str = $search_array['search_string'];
   $limit = $search_array['limit'];
   
-  $count = $_SESSION['tripal_pub_PMID_query'][$terms]['Count'];
+  $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'][$terms]['QueryKey'];
-  $web_env   = $_SESSION['tripal_pub_PMID_query'][$terms]['WebEnv'];
+  $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($terms, $limit, $days);
+    $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'];
@@ -119,7 +134,7 @@ function tripal_pub_PMID_range($search_array, $start = 0, $limit = 10) {
 /*
  * 
  */
-function tripal_pub_PMID_search_init($terms, $retmax, $days = 0){
+function tripal_pub_PMID_search_init($search_str, $retmax){
    
   // do a search for a single result so that we can establish a history, and get
   // the number of records. Once we have the number of records we can retrieve
@@ -128,10 +143,8 @@ function tripal_pub_PMID_search_init($terms, $retmax, $days = 0){
     "db=Pubmed" .
     "&retmax=$retmax" .
     "&usehistory=y".
-    "&term=$terms";
-  if($days) {
-    $query_url .= "&reldate=$days&datetype=edat";
-  }
+    "&term=" . urlencode($search_str);
+
   //dpm($query_url);
   $rfh = fopen($query_url, "r");
   if (!$rfh) {

+ 111 - 74
tripal_pub/includes/pub_importers.inc

@@ -5,6 +5,9 @@
  * @ingroup tripal_pub
  */
 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");    
@@ -13,9 +16,10 @@ function tripal_pub_importers_list() {
     $criteria = unserialize($importer->criteria);
     $num_criteria = $criteria['num_criteria'];
     $criteria_str = '';
-    for ($i = 0; $i <= $num_criteria; $i++) {
+    for ($i = 1; $i <= $num_criteria; $i++) {
       $search_terms = $criteria['criteria'][$i]['search_terms'];
       $scope = $criteria['criteria'][$i]['scope'];
+      $is_phrase = $criteria['criteria'][$i]['is_phrase'];
       $operation = $criteria['criteria'][$i]['operation'];
       $criteria_str .= "$operation ($scope: $search_terms) ";
     }
@@ -49,8 +53,8 @@ function tripal_pub_importer_setup($action = 'new', $pub_import_id = NULL) {
   global $pager_total, $pager_total_items;
   
   $pager_id = 0;
-  $limit = 10;
-  
+  $limit = 20;
+    
   // generate the search form 
   $form = drupal_get_form('tripal_pub_importer_setup_form',  $pub_import_id, $action);
   
@@ -58,25 +62,26 @@ function tripal_pub_importer_setup($action = 'new', $pub_import_id = NULL) {
   $output .= $form;
 
   // retrieve any results
-  $remote_db = $_SESSION['tripal_pub_search']['remote_db'];
-  $num_criteria = $_SESSION['tripal_pub_search']['num_criteria'];
-  $days = $_SESSION['tripal_pub_search']['days'];
+  $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 = 0; $i <= $num_criteria; $i++) {
-    $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_search']['criteria'][$i]['search_terms'];
-    $search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_search']['criteria'][$i]['scope'];  
-    $search_array['criteria'][$i]['operation'] = $_SESSION['tripal_pub_search']['criteria'][$i]['operation'];
+  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_search']['perform_search']) {
+  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);
+    //dpm($pubs);
     
     // generate the pager
     $total_pages = $pager_total[$pager_id];
@@ -120,18 +125,20 @@ function theme_tripal_pub_importer_setup_form($form) {
   foreach ($form['criteria'] as $i => $element) {
     if(is_numeric($i)) {
       $rows[] = array(  
-        array('data' => drupal_render($element["operation-$i"]), 'width' => '10%'),    
-        array('data' => drupal_render($element["scope-$i"]), 'width' => '10%'),
+        drupal_render($element["operation-$i"]),    
+        drupal_render($element["scope-$i"]),
         drupal_render($element["search_terms-$i"]),
-        array('data' => drupal_render($element["add-$i"]) . drupal_render($element["remove-$i"]), 'width' => '5%'),
+        drupal_render($element["is_phrase-$i"]),
+        drupal_render($element["add-$i"]) . drupal_render($element["remove-$i"]),
       );
     }
   } 
-  $headers = array('Operation','Scope', 'Search Terms', '');
-  
-  $markup  = '<div id="pub-search-form-row1">';
+  $headers = array('Operation','Scope', 'Search Terms', '','');
+
+  $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-col2">' . drupal_render($form['remote_db']) . '</div>';
   $markup .= '  <div id="pub-search-form-col3">' . drupal_render($form['days']) . '</div>';
   $markup .= '</div>';
   $markup .= '<div id="pub-search-form-row2">' . drupal_render($form['disabled']) . '</div>'; 
@@ -152,7 +159,7 @@ function theme_tripal_pub_importer_setup_form($form) {
  */
 function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NULL, $action = 'new') {
   tripal_core_ahah_init_form();
- 
+     
   // 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;
@@ -169,29 +176,36 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
     $loader_name    = $criteria['loader_name'];  
   }
 
-  // if the session has variables then use those.  This should only happen when
-  // the 'Test Criteria' button is clicked.
-  $num_criteria = $_SESSION['tripal_pub_search']['num_criteria'] ? $_SESSION['tripal_pub_search']['num_criteria'] : $num_criteria;    
-  $loader_name  = $_SESSION['tripal_pub_search']['loader_name']  ? $_SESSION['tripal_pub_search']['loader_name']  : $loader_name;
-  $remote_db    = $_SESSION['tripal_pub_search']['remote_db']    ? $_SESSION['tripal_pub_search']['remote_db']    : $remote_db;
-  $disabled     = $_SESSION['tripal_pub_search']['disabled']     ? $_SESSION['tripal_pub_search']['disabled']     : $disabled;    
-  $do_contact   = $_SESSION['tripal_pub_search']['do_contact']   ? $_SESSION['tripal_pub_search']['do_contact']   : $do_contact;
-  $days         = $_SESSION['tripal_pub_search']['days']         ? $_SESSION['tripal_pub_search']['days']         : $days;    
-  
+  // if we're here because the form was posted then load from the session variable (we lost the form state)
+  $num_criteria = isset($_SESSION['tripal_pub_import']['num_criteria']) ? $_SESSION['tripal_pub_import']['num_criteria'] : $num_criteria;    
+  $loader_name  = isset($_SESSION['tripal_pub_import']['loader_name'])  ? $_SESSION['tripal_pub_import']['loader_name']  : $loader_name;
+  $remote_db    = isset($_SESSION['tripal_pub_import']['remote_db'])    ? $_SESSION['tripal_pub_import']['remote_db']    : $remote_db;
+  $disabled     = isset($_SESSION['tripal_pub_import']['disabled'])     ? $_SESSION['tripal_pub_import']['disabled']     : $disabled;    
+  $do_contact   = isset($_SESSION['tripal_pub_import']['do_contact'])   ? $_SESSION['tripal_pub_import']['do_contact']   : $do_contact;
+  $days         = isset($_SESSION['tripal_pub_import']['days'])         ? $_SESSION['tripal_pub_import']['days']         : $days;
+      
   
   // 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
-  $num_criteria = $form_state['values']['num_criteria'] ? $form_state['values']['num_criteria'] : $num_criteria;    
-  $loader_name  = $form_state['values']['loader_name']  ? $form_state['values']['loader_name']  : $loader_name;
-  $remote_db    = $form_state['values']['remote_db']    ? $form_state['values']['remote_db']    : $remote_db;
-  $disabled     = $form_state['values']['disabled']     ? $form_state['values']['disabled']     : $disabled;
-  $do_contact   = $form_state['values']['do_contact']   ? $form_state['values']['do_contact']   : $do_contact;
-  $days         = $form_state['values']['days']         ? $form_state['values']['days']         : $days;    
+  if ($form_state['values']) {
+    $num_criteria = $form_state['values']['num_criteria'] ? $form_state['values']['num_criteria'] : $num_criteria;    
+    $loader_name  = $form_state['values']['loader_name']  ? $form_state['values']['loader_name']  : $loader_name;
+    $remote_db    = $form_state['values']['remote_db']    ? $form_state['values']['remote_db']    : $remote_db;
+    $disabled     = $form_state['values']['disabled']     ? $form_state['values']['disabled']     : $disabled;
+    $do_contact   = $form_state['values']['do_contact']   ? $form_state['values']['do_contact']   : $do_contact;
+    $days         = $form_state['values']['days']         ? $form_state['values']['days']         : $days;
+  }    
+  
+  // 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 = 0;
+    $num_criteria = 1;
   }
   if($form_state['post']["add-$num_criteria"]) {    
     $num_criteria++;
@@ -199,7 +213,7 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
   if($form_state['post']["remove-$num_criteria"]) {    
     $num_criteria--;
   }
-  
+    
   $form['pub_import_id'] = array(
     '#type'          => 'hidden',
     '#value'         => $pub_import_id,
@@ -218,11 +232,16 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
     '#default_value' => $loader_name,
     '#required'      => TRUE,
   );
-   
-  $remote_dbs = array(
-    'PMID' => 'Pubmed',
-    'AGRICOLA' => 'AGRICOLA',
+  
+  $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
+  $remote_dbs = array();
+  $values = array(
+    'name' => $supported_dbs,
   );
+  $dbs = tripal_core_chado_select('db', array('*'), $values);
+  foreach ($dbs as $index => $db) {
+    $remote_dbs[$db->name] = $db->description;
+  };
   $form['remote_db'] = array(
     '#title' => t('Remote Database'),
     '#type' => 'select',
@@ -242,7 +261,7 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
   $form['days'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Days'),
-    '#description'   => t('The number of days from today to search.'),
+    '#description'   => t('Limit the search to include pubs that have been added to the database this many days before today.'),
     '#default_value' => $days,
     '#size'          => 5,
   );
@@ -259,23 +278,28 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
        additional information such as affilation, etc. Otherwise, only authors names are retrieved.'),
     '#default_value' => $do_contact,
   );
-  
-  for($i = 0; $i <= $num_criteria; $i++) {
-    // if we have criteria supplied from the database then use that, othrewise look from the form_state or the session
+  for($i = 1; $i <= $num_criteria; $i++) {
+    
+    // if we have criteria supplied from the database then use that as the initial defaults
     if ($criteria) {
       $search_terms = $criteria['criteria'][$i]['search_terms'];
       $scope = $criteria['criteria'][$i]['scope'];
+      $is_phrase = $criteria['criteria'][$i]['is_phrase'];
       $operation = $criteria['criteria'][$i]['operation'];
     }
-    // first populate defaults using any values in the SESSION variable
-    $search_terms = $_SESSION['tripal_pub_search']['criteria'][$i]['search_terms'] ? $_SESSION['tripal_pub_search']['criteria'][$i]['search_terms'] : $search_terms;
-    $scope        = $_SESSION['tripal_pub_search']['criteria'][$i]['scope']        ? $_SESSION['tripal_pub_search']['criteria'][$i]['scope']        : $scope;
-    $operation    = $_SESSION['tripal_pub_search']['criteria'][$i]['operation']    ? $_SESSION['tripal_pub_search']['criteria'][$i]['operation']    : $operation;
-    
-    // next populate defaults using any form values
-    $search_terms = $form_state['values']["search_terms-$i"] ? $form_state['values']["search_terms-$i"] : $search_terms;
-    $scope        = $form_state['values']["scope-$i"]        ? $form_state['values']["scope-$i"]        : $scope;
-    $operation    = $form_state['values']["operation-$i"]    ? $form_state['values']["operation-$i"]    : $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 ($form_state['values']) {
+      $search_terms = $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"];
+    }
     
     // default to searching the title and abstract
     if (!$scope) {
@@ -284,7 +308,9 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
   
     $form['criteria'][$i]["search_terms-$i"] = array(
       '#type'          => 'textfield',
-      '#description'   => t('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"'),
+      '#description'   => t('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. Uncheck the "Is Phrase" checkbox to use conjunctions'),
       '#default_value' => $search_terms,
       '#required'      => TRUE,
     );
@@ -293,13 +319,20 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
       '#description'   => t('Please select the fields to search for this term.'),
       '#options'       => array(
         'any'      => 'Any Field',
+        'author'   => 'Author',
+        'id'       => 'Accession',
         'title'    => 'Title',
-        'abstract' => 'Title/Abstract',
-        'author'   => 'Author'),
+        'abstit'   => 'Title & Abstract',
+      ),
       '#default_value' => $scope,
-    );    
+    );  
+    $form['criteria'][$i]["is_phrase-$i"] = array(
+      '#type'    => 'checkbox',
+      '#title'   => t('Is Phrase?'),    
+      '#default_value' => $is_phrase,
+    );  
     
-    if ($i > 0) {
+    if ($i > 1) {
       $form['criteria'][$i]["operation-$i"] = array(
         '#type'          => 'select',
         '#options'       => array(
@@ -310,7 +343,7 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
       );
     }
     if ($i == $num_criteria) {    
-      if($i > 0) {
+      if($i > 1) {
         $form['criteria'][$i]["remove-$i"] = array(
           '#type'         => 'image_button',
           '#value'        => t('Remove'),
@@ -372,9 +405,10 @@ function tripal_pub_importer_setup_form_validate($form, &$form_state) {
   $do_contact =  $form_state['values']["do_contact"];
   $loader_name =  trim($form_state['values']["loader_name"]);
 
-  for ($i = 0; $i <= $num_criteria; $i++) {            
+  for ($i = 1; $i <= $num_criteria; $i++) {            
     $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"];
     
     if ($days and !is_numeric($days) or preg_match('/\./', $days)) {
@@ -397,34 +431,37 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
   $do_contact =  $form_state['values']["do_contact"];
 
   // set the session variables
-  $_SESSION['tripal_pub_search']['remote_db'] = $remote_db;
-  $_SESSION['tripal_pub_search']['days'] = $days;
-  $_SESSION['tripal_pub_search']['num_criteria'] = $num_criteria;
-  $_SESSION['tripal_pub_search']['loader_name'] = $loader_name;
-  $_SESSION['tripal_pub_search']['disabled'] = $disabled;
-  $_SESSION['tripal_pub_search']['do_contact'] = $do_contact;
-  unset($_SESSION['tripal_pub_search']['criteria']);
-  for ($i = 0; $i <= $num_criteria; $i++) {
+  $_SESSION['tripal_pub_import']['remote_db'] = $remote_db;
+  $_SESSION['tripal_pub_import']['days'] = $days;
+  $_SESSION['tripal_pub_import']['num_criteria'] = $num_criteria;
+  $_SESSION['tripal_pub_import']['loader_name'] = $loader_name;
+  $_SESSION['tripal_pub_import']['disabled'] = $disabled;
+  $_SESSION['tripal_pub_import']['do_contact'] = $do_contact;
+  $_SESSION['tripal_pub_import']['pub_import_id'] = $pub_import_id;
+  unset($_SESSION['tripal_pub_import']['criteria']);
+  for ($i = 1; $i <= $num_criteria; $i++) {
     $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"];
     
-    $_SESSION['tripal_pub_search']['criteria'][$i] = array(
+    $_SESSION['tripal_pub_import']['criteria'][$i] = array(
       'search_terms' => $search_terms,
       'scope' => $scope,
+      'is_phrase' => $is_phrase,
       'operation' => $operation
     );
   }
 
   // now perform the appropriate action for the button clicked
   if ($form_state['values']['op'] == 'Test Importer') {
-    $_SESSION['tripal_pub_search']['perform_search'] = 1;
+    $_SESSION['tripal_pub_import']['perform_search'] = 1;
   }
   if ($form_state['values']['op'] == 'Save Importer' or 
       $form_state['values']['op'] == 'Save & Import Now') {    
     $record = array(
       'name' => $loader_name,
-      'criteria' => serialize($_SESSION['tripal_pub_search']),
+      'criteria' => serialize($_SESSION['tripal_pub_import']),
       'disabled' => $disabled,
       'do_contact' => $do_contact
     );
@@ -436,7 +473,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
       // do the update
       $record['pub_import_id'] = $pub_import_id;
       if(drupal_write_record('tripal_pub_import', $record, 'pub_import_id')){
-        unset($_SESSION['tripal_pub_search']);
+        unset($_SESSION['tripal_pub_import']);
         drupal_set_message('Publication import settings updated.');
         drupal_goto('admin/tripal/tripal_pub/import_list');       
       }
@@ -447,7 +484,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
     else {         
       // do the insert        
       if(drupal_write_record('tripal_pub_import', $record)){
-        unset($_SESSION['tripal_pub_search']);
+        unset($_SESSION['tripal_pub_import']);
         drupal_set_message('Publication import settings saved.');        
         // if the user wants to do the import now then do it (may time out
         // for long jobs)

+ 41 - 51
tripal_pub/theme/tripal_pub_admin.tpl.php

@@ -1,64 +1,54 @@
 <br /><h3>Tripal Publication Administrative Tools Quick Links</h3>
 <ul>
-<li><?php print l('Configuration', 'admin/tripal/tripal_pub/configuration') ?></li>
+  <li><?php print l('Search for Publications', 'find/publications') ?></li>
+  <li><?php print l('Configuration', 'admin/tripal/tripal_pub/configuration') ?></li>
+  <li><?php print l('Sync Publications', 'admin/tripal/tripal_pub/sync') ?></li>
+  <li><?php print l('List of Importers', 'admin/tripal/tripal_pub/import_list') ?></li>
+  <li><?php print l('Add a New Importer', 'admin/tripal/tripal_pub/import/new') ?></li>
 </ul>
 
 <h3>Module Description:</h3>
-<p>The Tripal Publication Module provides the functionality for adding, editing, deleting and
-accessing academic publications, entered by the user.This module also allows a time limited search,
-specified by the user, which searches the PubMed extracts and saves acedemic puplications.
+<p>The Tripal Publication Module provides the functionality for adding, editing, deleting viewing and bulk 
+importing of publications.  This module additionally provides a search tool for finding publications that have
+been added to Chado database.
  </p>
 <h3>Setup Instructions:</h3>
 <ol>
-<li><p><b>Set Permissions</b>: The publication module supports the Drupal user permissions interface for
-               controlling access to publlication content and functions. These permissions include viewing,
-               creating, editing or administering of
-               publication content. The default is that only the original site administrator has these
-               permissions.  You can <a href="<?php print url('admin/user/roles') ?>">add roles</a> for classifying users,
-               <a href="<?php print url('admin/user/user') ?>">assign users to roles</a> and
-               <a href="<?php print url('admin/user/permissions') ?>">assign permissions</a> for the publication content to
-               those roles.  For a simple setup, allow anonymous users access to view publication content and
-               allow the site administrator all other permissions.</p></li>
-<li><p><b>Set Publication Type Controlled Vocabulary</b>: The select list for setting the publication 
-                type is controlled be a controlled vocabulary (cv)
-                <ul><li>Before you can add any publications you need 
-                to create/load this cv. There is a limited cv included in this module. To use it, you need to 
-                load it using the <a href="<?php print url('admin/tripal/tripal_cv/obo_loader') ?>">OBO Loader included with Tripal</a>.</li>
-                <li>After the controlled vocabulary is loaded you need to set it to be used for the publication 
-                module. To do this, go to <a href="<?php print url('admin/tripal/tripal_pub/configuration') ?>">Publication->Configuration</a>, select it in the controlled vocabulary '
-                select list and click save configuration.</p></li></ul>
-
+  <li><p><b>Set Permissions</b>: The publication module supports the Drupal user permissions interface for
+    controlling access to publication content and functions. These permissions include viewing,
+    creating, editing or administering of
+    publications. The default is that only the original site administrator has these
+    permissions.  You can <a href="<?php print url('admin/user/roles') ?>">add roles</a> for classifying users,
+    <a href="<?php print url('admin/user/user') ?>">assign users to roles</a> and
+    <a href="<?php print url('admin/user/permissions') ?>">assign permissions</a> for the publication content to
+    those roles.  For a simple setup, allow anonymous users access to view publication content and
+    allow the site administrator all other permissions.</p></li>
+  <li><p><b>Sync Publications</b>:  If you already have publications in your Chado database, or you loaded them
+    through a means other than Tripal, and you want those publications to appear on your site then you will need
+    to "sync" them with Drupal.  Use the <?php print l('sync publications', 'admin/tripal/tripal_pub/sync') ?>
+    page to sync all publications.</p></li>
+  <li><p><b>Configure the Search Behavior</b>: Before allowing site visitors to search for publications 
+   visit the <?php print l('configuration page', 'admin/tripal/tripal_pub/configuration') ?> to disable or enable
+   fields for searching.  Tripal uses its own ontology for storing publication information in Chado, and all 
+   child terms of the "Publication Details" are made available for searching. However, some of these
+   may not be desired for searching and can be disabled.</p></li>
 </ol>
 <h3>Features of this Module:</h3>
 <ul>
-<li><p><b>Configuration (Search For Academic Publications):</b>  The search capability implemented in
-  this module allows a user to search, by remote connection , the PubMEd database for articles
-  that relate to key search words, chosen by the user.The "search keys" are used to search through
-  Publication titles and when one of the key words is matched in a title, the recognized article will
-  be saved to the database.
-
-      <ul>
-
-      <li><b>Choose a Controlled Vocabulary:</b>The controlled vocabulary list is a set of terms
-
-      <li><b>Set Search Key Words:</b>The search keywords, are the user entered key terms, in which
-      the publications in the PubMed database can be recognized by. The user may enter any number
-      of search terms, as by adding more search terms, the search will limit the results to those
-      in which all of the search terms appear in the publication title.
+  <li><p><b>Add/Edit/Delete Publications</b>: Publications can be maually added <?php  l('here', 'node/add/chado-pub') ?>. 
+    Once added, publications can be modified or deleted by clicking the Edit tab at the top of a publication page.</p></li>
+  
+  <li><p><b>Publication Search Tool</b>: A <?php print l('search tool','find/publications') ?> is provided for 
+    finding publications. Unlike most default search tools for Tripal, this tool does not relies on Drupal Views</p></li>
+    
+  <li><p><b>Bulk Import of Publications</b>: Site administrators can  <?php print l('add a new publication importer', 'admin/tripal/tripal_pub/import/new') ?> 
+    which provides a set of search terms for querying a remote publication database (e.g. PubMed). Publications
+    that matche the search terms can be imported when the publication import cron command is executed.  The
+    cron command can be executed using the Drush command: drush tpubs-import.  This drush command can be added
+    as a system-wide cron (in the same way the Tripal jobs cron is implemented) to be executed on a periodic basis.
+    This will allow the site to import publications which have been newly added to remote databases and which 
+    are relative to the site.  Site administrators can <?php print l('see the list of importers', 'admin/tripal/tripal_pub/import_list') ?> 
+    and edit, disable or delete the importers.</p></li>
 
-      <li><b>Set a time search interval:</b>The search term interval represents a pre-set ammount
-      of time for the search. The time search interval must be entered in minutes. This allows
-      the module to automatically search the PubMed database in a predetermined time interval.
-    </ul>
-  </p></li>
-
-<li><b>Creating a Publication:</b>
-
-<p>To <b>Create,update/delete a given property of a publication</b>:When Creating a Publication
-  it is neccessary to enter the requried fields in the form. These are marked with an astrix and
-  if they are not entered upon completion a warning will be issued and the user is forced to fill
-  in these entries. The author field, requires a given/surname/suffix to be entered. To add the
-  author to the publication, the add author button is to be pushed. The user is able to add as
-  many authors to the publication as needed.
-  </p>
+</ul>
 

+ 8 - 2
tripal_pub/tripal_pub.install

@@ -29,16 +29,22 @@ function tripal_pub_install() {
   
   // add the custom tables
   tripal_pub_add_custom_tables();
+  
 }
 
-
+function tripal_pub_enable() {
+  // make sure we have our supported databases
+  tripal_db_add_db('PMID', 'PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed', 'http://www.ncbi.nlm.nih.gov/pubmed/', TRUE);
+  tripal_db_add_db('AGL', 'USDA National Agricultural Library', 'http://agricola.nal.usda.gov/', '', TRUE);
+  
+  variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
+}
 /**
  * Implementation of hook_uninstall().
  */
 function tripal_pub_uninstall() {
   //Remove tables
   drupal_uninstall_schema('tripal_pub');
-
 }
 
 

+ 4 - 8
tripal_pub/tripal_pub.module

@@ -5,9 +5,9 @@ require_once "includes/tripal_pub.admin.inc";
 require_once "includes/pub_sync.inc";
 require_once "includes/pub_form.inc";
 require_once "includes/pub_importers.inc";
-require_once "includes/pubmed.inc";
-require_once "includes/agricola.inc";
 require_once "includes/pub_search.inc";
+require_once "includes/importers/PMID.inc";
+require_once "includes/importers/AGL.inc";
 /**
  * @file
  *
@@ -24,11 +24,7 @@ require_once "includes/pub_search.inc";
  */
 function tripal_pub_init() {
   drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_pub.js');
-  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_pub.css');
-  
-  // this variable indicates which databases are supported by the Tripal pub module
-  // for importing
-  variable_set('tripal_pub_supported_dbs', array('PMID'));
+  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_pub.css');  
 }
 
 
@@ -716,7 +712,7 @@ function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
     // the form to the ahah callback URL. We need to set it back
     // to the normal form URL
     if ($form_state['values']['action'] == 'edit') {
-      $form['#action'] = url("admin/tripal/tripal_pub/import/edit/" . $form['pub_import_id']);
+      $form['#action'] = url("admin/tripal/tripal_pub/import/edit/" . $form_state['values']['pub_import_id']);
     } 
     if ($form_state['values']['action'] == 'new') {
       $form['#action'] = url("admin/tripal/tripal_pub/import/new");