Переглянути джерело

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Lacey Sanderson 10 роки тому
батько
коміт
ebd00f389d
79 змінених файлів з 1588 додано та 916 видалено
  1. 13 1
      tripal_analysis/includes/tripal_analysis.chado_node.inc
  2. 4 1
      tripal_analysis/tripal_analysis.module
  3. 54 44
      tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc
  4. 43 4
      tripal_bulk_loader/includes/tripal_bulk_loader.chado_node.inc
  5. 3 3
      tripal_bulk_loader/includes/tripal_bulk_loader.constants.inc
  6. 2 2
      tripal_bulk_loader/includes/tripal_bulk_loader.loader.inc
  7. 0 67
      tripal_bulk_loader/theme/node--tripal-bulk-loader.tpl.php
  8. 0 0
      tripal_bulk_loader/theme/templates/tripal_bulk_loader_admin.tpl.php
  9. 166 0
      tripal_bulk_loader/theme/templates/tripal_bulk_loader_base.tpl.php
  10. 104 0
      tripal_bulk_loader/theme/templates/tripal_bulk_loader_fields.tpl.php
  11. 0 0
      tripal_bulk_loader/theme/templates/tripal_bulk_loader_modify_template_base_form.tpl.php
  12. 9 0
      tripal_bulk_loader/theme/templates/tripal_bulk_loader_teaser.tpl.php
  13. 0 79
      tripal_bulk_loader/theme/tripal_bulk_loader_template.tpl.php
  14. 28 9
      tripal_bulk_loader/tripal_bulk_loader.module
  15. 16 0
      tripal_contact/includes/tripal_contact.chado_node.inc
  16. 1 1
      tripal_contact/tripal_contact.module
  17. 2 2
      tripal_core/api/tripal_core.DEPRECATED.inc
  18. 1 1
      tripal_core/api/tripal_core.chado_nodes.api.inc
  19. 1 1
      tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc
  20. 4 2
      tripal_core/api/tripal_core.chado_nodes.properties.api.inc
  21. 1 1
      tripal_core/api/tripal_core.chado_nodes.relationships.api.inc
  22. 65 27
      tripal_core/api/tripal_core.chado_nodes.title_and_path.inc
  23. 2 4
      tripal_core/api/tripal_core.chado_query.api.inc
  24. 3 1
      tripal_core/api/tripal_core.chado_schema.api.inc
  25. 4 4
      tripal_core/includes/tripal_core.chado_install.inc
  26. 1 1
      tripal_core/theme/css/tripal.css
  27. 11 9
      tripal_core/theme/templates/node--chado-generic.tpl.php
  28. 92 45
      tripal_core/tripal_core.install
  29. 198 83
      tripal_core/tripal_core.module
  30. 3 3
      tripal_cv/api/tripal_cv.DEPRECATED.inc
  31. 5 5
      tripal_cv/api/tripal_cv.api.inc
  32. 1 1
      tripal_cv/includes/tripal_cv.admin.inc
  33. 1 1
      tripal_cv/includes/tripal_cv.cv_form.inc
  34. 4 4
      tripal_cv/includes/tripal_cv.obo_loader.inc
  35. 1 1
      tripal_cv/includes/tripal_cv.trees.inc
  36. 1 1
      tripal_db/includes/tripal_db.admin.inc
  37. 19 9
      tripal_example/includes/tripal_example.chado_node.inc
  38. 1 1
      tripal_example/theme/templates/tripal_example_teaser.tpl.php
  39. 2 2
      tripal_example/tripal_example.install
  40. 2 2
      tripal_example/tripal_example.module
  41. 0 62
      tripal_feature/api/tripal_feature.DEPRECATED.inc
  42. 313 107
      tripal_feature/api/tripal_feature.api.inc
  43. 1 1
      tripal_feature/includes/tripal_feature.admin.inc
  44. 15 0
      tripal_feature/includes/tripal_feature.chado_node.inc
  45. 48 64
      tripal_feature/includes/tripal_feature.fasta_loader.inc
  46. 30 6
      tripal_feature/includes/tripal_feature.gff_loader.inc
  47. 15 100
      tripal_feature/includes/tripal_feature.seq_extract.inc
  48. 28 16
      tripal_feature/theme/templates/tripal_feature_sequence.tpl.php
  49. 0 1
      tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php
  50. 14 12
      tripal_feature/theme/tripal_feature.theme.inc
  51. 34 18
      tripal_feature/tripal_feature.drush.inc
  52. 29 23
      tripal_feature/tripal_feature.install
  53. 5 1
      tripal_feature/tripal_feature.module
  54. 12 0
      tripal_featuremap/includes/tripal_featuremap.chado_node.inc
  55. 1 1
      tripal_featuremap/tripal_featuremap.module
  56. 3 3
      tripal_genetic/tripal_genetic.module
  57. 12 0
      tripal_library/includes/tripal_library.chado_node.inc
  58. 1 1
      tripal_library/tripal_library.module
  59. 2 2
      tripal_natural_diversity/tripal_natural_diversity.module
  60. 12 0
      tripal_organism/includes/tripal_organism.chado_node.inc
  61. 7 4
      tripal_organism/tripal_organism.module
  62. 1 1
      tripal_organism/tripal_organism.views_default.inc
  63. 3 3
      tripal_phenotype/tripal_phenotype.module
  64. 1 1
      tripal_project/includes/tripal_project.admin.inc
  65. 13 1
      tripal_project/includes/tripal_project.chado_node.inc
  66. 1 0
      tripal_project/tripal_project.info
  67. 4 4
      tripal_project/tripal_project.module
  68. 2 2
      tripal_project/tripal_project.views_default.inc
  69. 28 6
      tripal_pub/includes/tripal_pub.chado_node.inc
  70. 1 1
      tripal_pub/includes/tripal_pub.pub_citation.inc
  71. 3 1
      tripal_pub/includes/tripal_pub.pub_importers.inc
  72. 1 1
      tripal_pub/includes/tripal_pub.pub_search.inc
  73. 3 3
      tripal_pub/tripal_pub.module
  74. 1 1
      tripal_stock/includes/tripal_stock.admin.inc
  75. 16 0
      tripal_stock/includes/tripal_stock.chado_node.inc
  76. 10 1
      tripal_stock/tripal_stock.module
  77. 47 43
      tripal_views/includes/tripal_views_integration_UI.inc
  78. 1 1
      tripal_views/includes/tripal_views_integration_port.inc
  79. 2 2
      tripal_views/theme/tripal_views_search_biological_content.tpl.php

+ 13 - 1
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -724,7 +724,13 @@ function tripal_analysis_node_insert($node) {
 
   switch ($node->type) {
     case 'chado_analysis':
-
+      
+      // build the analysis variable
+      $analysis_id = chado_get_id_from_nid('analysis', $node->nid);      
+      $values = array('analysis_id' => $analysis_id);
+      $analysis = chado_generate_var('analysis', $values);
+      $node->analysis = $analysis;
+      
       // Now get the title
       $node->title = chado_get_node_title($node);
 
@@ -742,6 +748,12 @@ function tripal_analysis_node_update($node) {
 
   switch ($node->type) {
     case 'chado_analysis':
+      
+      // build the analysis variable
+      $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
+      $values = array('analysis_id' => $analysis_id);
+      $analysis = chado_generate_var('analysis', $values);
+      $node->analysis = $analysis;
 
       // Now get the title
       $node->title = chado_get_node_title($node);

+ 4 - 1
tripal_analysis/tripal_analysis.module

@@ -139,7 +139,7 @@ function tripal_analysis_permission() {
       'title' => t('Edit Analyses'),
       'description' => t('Allow users to edit analysis pages.'),
     ),
-    'adminster tripal analysis' => array(
+    'administer tripal analysis' => array(
       'title' => t('Administer Analyses'),
       'description' => t('Allow users to administer all analyses.'),
     ),
@@ -262,6 +262,9 @@ function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
   // turn of preview button for insert/updates
   if ($form_id == "chado_analysis_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
+    
+    //remove the body field
+    unset($form['body']);
   }
 }
 

+ 54 - 44
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -39,6 +39,7 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
 
       $template_id = $form_state['storage']['template_id'];
 
+      // add the template and template name to the $form_state['storage'] array
       $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
       $result = db_query($sql, array(':template' => $template_id))->fetchObject();
       $form_state['storage']['template'] = unserialize($result->template_array);
@@ -47,10 +48,13 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
       }
       $form_state['storage']['template_name'] = $result->name;
 
+      // build the recrod2priority entry for the $form_state['storage'] array. This simply
+      // maps the records to their respective orders (priorities).
       $form_state['storage']['record2priority'] = array();
       foreach ($form_state['storage']['template'] as $priority => $record_array) {
         if (!is_array($record_array)) {
-          continue; }
+          continue; 
+        }
         $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
       }
     }
@@ -197,12 +201,15 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
     '#tree' => TRUE,
   );
 
-  if (isset($form_state['storage']['template'])) {
+  if (array_key_exists('template', $form_state['storage'])) {
 
     // List Current Fields -------------------------------------------------------------
     $num_fields=0;
+    
+    // pre-create the URLs for dealing with records & fields. We will substitute values as needed
     $record_href_template = 'admin/tripal/loaders/bulk/template/%template/%action/%priority';
-    $field_href_template = 'admin/tripal/loaders/bulk/template/%template/%action/%priority/%field';
+    $field_href_template  = 'admin/tripal/loaders/bulk/template/%template/%action/%priority/%field';
+    
     foreach ($form_state['storage']['template'] as $priority => $table_array) {
       if (!is_array($table_array)) {
       continue; }
@@ -299,12 +306,12 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
           ),
           'submit-edit_record' => array(
             '#type' => 'link',
-            '#href' => str_replace(array('%template','%priority','%action'), array($path_template_id, $path_priority,'edit_record'), $record_href_template),
+            '#href' => str_replace(array('%template', '%priority', '%action'), array($path_template_id, $path_priority,'edit_record'), $record_href_template),
             '#title' => 'Edit',
           ),
           'submit-delete_record' => array(
             '#type' => 'link',
-            '#href' => str_replace(array('%template','%priority','%action'), array($path_template_id, $path_priority,'delete_record'), $record_href_template),
+            '#href' => str_replace(array('%template', '%priority', '%action'), array($path_template_id, $path_priority,'delete_record'), $record_href_template),
             '#options' => array(
               'query' => array(
                 'record_name' => $table_array['record_id'],
@@ -316,7 +323,7 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
           ),
           'submit-duplicate_record' => array(
             '#type' => 'link',
-            '#href' => str_replace(array('%template','%priority','%action'), array($path_template_id, $path_priority,'duplicate_record'), $record_href_template),
+            '#href' => str_replace(array('%template', '%priority', '%action'), array($path_template_id, $path_priority, 'duplicate_record'), $record_href_template),
             '#options' => array(
               'query' => array(
                 'record_name' => $table_array['record_id'],
@@ -328,7 +335,7 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
           ),
           'submit-add_field' => array(
             '#type' => 'link',
-            '#href' => str_replace(array('%template','%priority','%action'), array($path_template_id, $path_priority,'add_field'), $record_href_template),
+            '#href' => str_replace(array('%template', '%priority', '%action'), array($path_template_id, $path_priority, 'add_field'), $record_href_template),
             '#title' => 'Add Field',
           ),
         );
@@ -411,12 +418,12 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
             ),
             'edit_submit' => array(
               '#type' => 'link',
-              '#href' => str_replace(array('%template','%priority', '%field', '%action'), array($path_template_id, $path_priority, $path_field_index, 'edit_field'), $field_href_template),
+              '#href' => str_replace(array('%template', '%priority', '%field', '%action'), array($path_template_id, $path_priority, $path_field_index, 'edit_field'), $field_href_template),
               '#title' => "Edit",
             ),
             'delete_submit' => array(
               '#type' => 'link',
-              '#href' => str_replace(array('%template','%priority', '%field', '%action'), array($path_template_id, $path_priority, $path_field_index,'delete_field'), $field_href_template),
+              '#href' => str_replace(array('%template', '%priority', '%field', '%action'), array($path_template_id, $path_priority, $path_field_index,'delete_field'), $field_href_template),
               '#options' => array(
                 'query' => array(
                   'record_name' => $table_array['record_id'],
@@ -490,6 +497,7 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
       $form_state['storage']['template'] = unserialize($result->template_array);
       $form_state['storage']['template_name'] = $result->name;
 
+      // rebuild the record2priority for the $form_state['storage'] array
       $form_state['storage']['record2priority'] = array();
       foreach ($form_state['storage']['template'] as $priority => $record_array) {
         if (!is_array($record_array)) {
@@ -499,7 +507,7 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
       }
 
       $form_state['rebuild'] = FALSE;
-      $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$form_state['storage']['template_id'].'/edit';
+      $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/' . $form_state['storage']['template_id'] . '/edit';
     break;
 
     case 'Create Template':
@@ -570,7 +578,7 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_delete_template_base_form($form, $form_state) {
+function tripal_bulk_loader_delete_template_base_form($form, &$form_state) {
   $form = array();
 
   // set the breadcrumb
@@ -671,7 +679,7 @@ function tripal_bulk_loader_delete_template_base_form_submit($form, &$form_state
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_import_template_form($form, $form_state) {
+function tripal_bulk_loader_import_template_form($form, &$form_state) {
   $form = array();
 
   // set the breadcrumb
@@ -752,7 +760,7 @@ function tripal_bulk_loader_import_template_form_submit($form, &$form_state) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_export_template_form($form, $form_state) {
+function tripal_bulk_loader_export_template_form($form, &$form_state) {
 
   // set the breadcrumb
   $breadcrumb = array();
@@ -816,7 +824,7 @@ function tripal_bulk_loader_export_template_form($form, $form_state) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_edit_template_record_form($form, $form_state) {
+function tripal_bulk_loader_edit_template_record_form($form, &$form_state) {
   $form['#cache'] = TRUE; // Make sure the form is cached.
 
   // get args from path
@@ -847,12 +855,13 @@ function tripal_bulk_loader_edit_template_record_form($form, $form_state) {
   // Pre-process values/defaults ---------------------------
 
   // If this is the first load of the form (no form state) we need to initialize some variables
-  if (!isset($form_state['storage']['template'])) {
+  if (!array_key_exists('template', $form_state['storage'])) {
     $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
     $template = db_query($sql, array(':template' => $template_id))->fetchObject();
     $form_state['storage']['template_array'] = unserialize($template->template_array);
     $form_state['storage']['template'] = $template;
 
+    // rebuild the record2priority array in the $form_state['storage'] array
     $form_state['storage']['record2priority'] = array();
     foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
       if (!is_array($record_array)) {
@@ -866,7 +875,7 @@ function tripal_bulk_loader_edit_template_record_form($form, $form_state) {
   else {
     $template = $form_state['storage']['template'];
   }
-
+  
   // Tables and default table
   $tables = chado_get_table_names(TRUE);
   if (isset($form_state['values']['chado_table'])) {
@@ -1051,7 +1060,7 @@ function tripal_bulk_loader_edit_template_record_form($form, $form_state) {
 
   $form['edit_record']['submit-edit_record'] = array(
       '#type' => 'submit',
-      '#value' => 'Edit Record'
+      '#value' => 'Save Record'
   );
 
   $form['edit_record']['submit-cancel'] = array(
@@ -1069,10 +1078,10 @@ function tripal_bulk_loader_edit_template_record_form($form, $form_state) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_edit_template_record_form_validate($form, $form_state) {
+function tripal_bulk_loader_edit_template_record_form_validate($form, &$form_state) {
 
   // Don't worry about validation when Cancel button is clicked
-  if ($form_state['clicked_button']['#value'] == 'Edit Record') {
+  if ($form_state['clicked_button']['#value'] == 'Save Record') {
     $is_unique = tripal_bulk_loader_is_record_name_unique(
       $form_state['values']['record_name'],
       $form_state['values']['template_id'],
@@ -1100,7 +1109,7 @@ function tripal_bulk_loader_edit_template_record_form_validate($form, $form_stat
  */
 function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state) {
 
-  if ($form_state['values']['op'] ==  'Edit Record') {
+  if ($form_state['values']['op'] ==  'Save Record') {
 
     $template = $form_state['storage']['template_array'];
     $original_record_name = $template[ $form_state['storage']['original_priority'] ]['record_id'];
@@ -1423,7 +1432,7 @@ function tripal_bulk_loader_duplicate_template_record_form_submit($form, &$form_
  */
 function tripal_bulk_loader_template_field_form_default_values($mode, &$form_state) {
   $v = array();
-
+  
   // mode can be 'create' or 'edit'
   $v['mode'] = $mode;
 
@@ -1432,7 +1441,6 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   $form_state['storage']['template_id'] = $v['template_id'];
   $template_id = $v['template_id'];
 
-
   $v['record_id'] = (isset($form_state['build_info']['args'][2])) ? $form_state['build_info']['args'][2] : FALSE;
   $v['no_record_id'] = ($mode == 'create_record') ? TRUE : FALSE;
   $form_state['storage']['record_id'] = $v['record_id'];
@@ -1442,7 +1450,7 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   $v['no_field_index'] = (isset($form_state['build_info']['args'][3])) ? FALSE : TRUE;
   $form_state['storage']['field_index'] = $v['field_index'];
   $field_index = $v['field_index'];
-
+  
   if (!array_key_exists('values', $form_state)) {
     $form_state['values'] = array();
   }
@@ -1463,22 +1471,23 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
 
       // save the template record from the database for future use
       $form_state['storage']['template'] = $template;
-
-      // initialize the record2priority array which keeps track of the order by
-      // copying the priority information about each record from the template array
-      // into the $form_state['storage']['record2priority'] array
-      $form_state['storage']['record2priority'] = array();
-      foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
-        if (!is_array($record_array)) {
-          continue;
-        }
-        $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
-      }
     }
     else {
       $template = $form_state['storage']['template'];
     }
   }
+  
+  // initialize the record2priority array which keeps track of the order by
+  // copying the priority information about each record from the template array
+  // into the $form_state['storage']['record2priority'] array
+  $form_state['storage']['record2priority'] = array();
+  foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
+    if (!is_array($record_array)) {
+      continue;
+    }
+    $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
+  }
+  
 
   // If we are editing then get the original values
   if ($mode == 'edit' && !$v['no_field_index']) {
@@ -1507,22 +1516,22 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   switch ($v['field_type']) {
     case 'table field':
       if (!isset($form_state['values']['column_number'])) {
-        $form_state['values']['column_number'] = (isset($original_field['spreadsheet column'])) ? $original_field['spreadsheet column'] : '';
-        $form_state['values']['column_exposed'] = (isset($original_field['exposed'])) ? $original_field['exposed'] : FALSE;
+        $form_state['values']['column_number']       = (isset($original_field['spreadsheet column'])) ? $original_field['spreadsheet column'] : '';
+        $form_state['values']['column_exposed']      = (isset($original_field['exposed'])) ? $original_field['exposed'] : FALSE;
         $form_state['values']['column_exposed_desc'] = (isset($original_field['exposed_description'])) ? $original_field['exposed_description'] : FALSE;
       }
       break;
     case 'constant':
       if (!isset($form_state['values']['constant_value'])) {
-        $form_state['values']['constant_value'] = (isset($original_field['constant value'])) ? $original_field['constant value'] : '';
-        $form_state['values']['constant_exposed'] = (isset($original_field['exposed'])) ? $original_field['exposed'] : FALSE;
+        $form_state['values']['constant_value']    = (isset($original_field['constant value'])) ? $original_field['constant value'] : '';
+        $form_state['values']['constant_exposed']  = (isset($original_field['exposed'])) ? $original_field['exposed'] : FALSE;
         $form_state['values']['constant_validate'] = (isset($original_field['exposed_validate'])) ? $original_field['exposed_validate'] : FALSE;
       }
       break;
     case 'foreign key':
       if (!isset($form_state['values']['foreign_record'])) {
         $form_state['values']['foreign_record'] = (isset($original_field['foreign key'])) ? $original_field['foreign key'] : FALSE;
-        $form_state['values']['foreign_field'] = (isset($original_field['foreign field'])) ? $original_field['foreign field'] : FALSE;
+        $form_state['values']['foreign_field']  = (isset($original_field['foreign field'])) ? $original_field['foreign field'] : FALSE;
       }
       break;
   }
@@ -1765,7 +1774,7 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
 function tripal_bulk_loader_template_field_form($form, &$form_state = NULL) {
   $form['#cache'] = TRUE; // Make sure the form is cached.
 
-  // if there is no template supplied don't return rest of form
+  // if there is no template supplied don't build the form
   if (!isset($form_state['build_info']['args'][1])) {
     return $form;
   }
@@ -1847,8 +1856,9 @@ function tripal_bulk_loader_template_field_form($form, &$form_state = NULL) {
   $form['fields']['basic']['field_group']  = array(
     '#type' => 'select',
     '#title' => 'Record',
-    '#description' => 'This is used to group a set of fields together allowing '
-      .'multiple records to be inserted into the same table per line of the file',
+    '#description' => t(
+       'This is used to group a set of fields together allowing ' .
+       'multiple records to be inserted into the same table per line of the file'),
     '#options' => $values['field_group_options'],
     '#default_value' => $values['field_group'],
     '#ajax' => array(
@@ -2171,7 +2181,7 @@ function tripal_bulk_loader_template_field_form($form, &$form_state = NULL) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_template_field_form_validate($form, $form_state) {
+function tripal_bulk_loader_template_field_form_validate($form, &$form_state) {
 
   // Don't worry about validation when Cancel button is clicked
   if ($form_state['clicked_button']['#value'] == 'Save Changes') {
@@ -2347,7 +2357,7 @@ function tripal_bulk_loader_template_field_form_submit($form, &$form_state) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_delete_template_field_form($form, $form_state) {
+function tripal_bulk_loader_delete_template_field_form($form, &$form_state) {
   $form['#cache'] = TRUE; // Make sure the form is cached.
 
   // get args from path

+ 43 - 4
tripal_bulk_loader/includes/tripal_bulk_loader.chado_node.inc

@@ -243,9 +243,9 @@ function tripal_bulk_loader_insert($node) {
 
   db_insert('tripal_bulk_loader')->fields(array(
     'nid' => $node->nid,
-    'loader_name' => $node->loader_name,
+    'loader_name' => trim($node->loader_name),
     'template_id' => $node->template_id,
-    'file' => $node->file,
+    'file' => trim($node->file),
     'file_has_header' => $node->has_header,
     'job_status' => 'Initialized',
     'keep_track_inserted' => $node->keep_track_inserted
@@ -283,9 +283,9 @@ function tripal_bulk_loader_update($node) {
   // Update tripal_bulk_loader
   db_update('tripal_bulk_loader')->fields(array(
     'nid' => $node->nid,
-    'loader_name' => $node->loader_name,
+    'loader_name' => trim($node->loader_name),
     'template_id' => $node->template_id,
-    'file' => $node->file,
+    'file' => trim($node->file),
     'file_has_header' => $node->has_header,
     'keep_track_inserted' => $node->keep_track_inserted
   ))->condition('nid',$node->nid)->execute();
@@ -363,3 +363,42 @@ function tripal_bulk_loader_node_access($node, $op, $account) {
     return NODE_ACCESS_IGNORE;
   }
 }
+
+
+/**
+ * Implements hook_node_view().
+ * Acts on all content types.
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_bulk_loader_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+    case 'tripal_bulk_loader':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        
+        // we want to use the Tripal generic node template
+        $node->content['#tripal_generic_node_template'] = TRUE;
+        
+        $node->content['tripal_bulk_loader_base'] = array(
+          '#markup' => theme('tripal_bulk_loader_base', array('node' => $node)),
+          '#tripal_toc_id'    => 'base',
+          '#tripal_toc_title' => 'Overview',
+          '#tripal_template_show' => FALSE, 
+          '#weight' => -100,
+        );
+        $node->content['tripal_bulk_loader_fields'] = array(
+          '#markup' => theme('tripal_bulk_loader_fields', array('node' => $node)),
+          '#tripal_toc_id'    => 'fields',
+          '#tripal_toc_title' => 'Data Fields',
+          '#tripal_template_show' => FALSE,
+        );
+      }
+      if ($view_mode == 'teaser') {
+        $node->content['tripal_bulk_loader_teaser'] = array(
+          '#markup' => theme('tripal_bulk_loader_teaser', array('node' => $node)),
+        );
+      }
+      break;
+  }
+}

+ 3 - 3
tripal_bulk_loader/includes/tripal_bulk_loader.constants.inc

@@ -123,7 +123,7 @@ function tripal_bulk_loader_has_exposed_fields($node) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_set_constants_form($form, $form_state, $node) {
+function tripal_bulk_loader_set_constants_form($form, &$form_state, $node) {
   $form = array();
 
   $form['nid'] = array(
@@ -410,7 +410,7 @@ function tripal_bulk_loader_set_constants_form_submit($form, $form_state) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_edit_constant_set_form($form, $form_state, $node, $group_id) {
+function tripal_bulk_loader_edit_constant_set_form($form, &$form_state, $node, $group_id) {
   $form = array();
 
   $form['nid'] = array(
@@ -554,7 +554,7 @@ function tripal_bulk_loader_edit_constant_set_form_submit($form, &$form_state) {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_delete_constant_set_form($form, $form_state, $node, $group_id) {
+function tripal_bulk_loader_delete_constant_set_form($form, &$form_state, $node, $group_id) {
   $form = array();
 
   $form['nid'] = array(

+ 2 - 2
tripal_bulk_loader/includes/tripal_bulk_loader.loader.inc

@@ -15,7 +15,7 @@
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_add_loader_job_form($form, $form_state, $node) {
+function tripal_bulk_loader_add_loader_job_form($form, &$form_state, $node) {
   $form = array();
 
   // --notify--
@@ -361,7 +361,7 @@ function tripal_bulk_loader_load_data($nid, $job_id) {
       $lockmode = variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE');
       foreach ($tables as $table) {
         print "\t\t\t$lockmode for $table\n";
-        chado_query("LOCK TABLE ".$table." IN ".$lockmode." MODE");
+        chado_query("LOCK TABLE {".$table."} IN ".$lockmode." MODE");
       }
     }
 

+ 0 - 67
tripal_bulk_loader/theme/node--tripal-bulk-loader.tpl.php

@@ -1,67 +0,0 @@
-<div id="tripal_bulk_loader-base-box" class="tripal_bulk_loader-info-box tripal-info-box">
-  <div class="tripal_bulk_loader-info-box-title tripal-info-box-title">
-    <?php if ($teaser) { print l($node->title, 'node/'.$node->nid); } ?>
-  </div>
-  <div class="tripal_bulk_loader-data-block-desc tripal-data-block-desc"></div>
-
-  <table id="tripal_bulk_loader-base-table" class="tripal_bulk_loader-table tripal-table tripal-table-vert">
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Job Name</th>
-      <td><?php print $node->loader_name;?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Submitted By</th>
-      <td><span class="author"><?php //print theme('username', $node); ?></span></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Job Creation Date</th>
-      <td><?php print format_date($node->created, 'custom', "F j, Y, g:i a"); ?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Last Updated</th>
-      <td><?php print format_date($node->changed, 'custom', "F j, Y, g:i a"); ?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Template Name</th>
-      <td><?php print $node->template->name; ?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Data File</th>
-      <td><?php print $node->file;?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Job Status</th>
-      <td><?php print $node->job_status;?></td>
-    </tr>
-    <?php if (isset($node->job)) { if (isset($node->job->progress)) { ?>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Job Progress</th>
-      <td><?php print $node->job->progress . '% (' . l('view job', 'admin/tripal/tripal_jobs/view/' . $node->job_id) . ')';?></td>
-    </tr>
-    <?php }} ?>
-  </table>
-</div>
-
-<?php if (!$teaser) { ?>
-<?php print drupal_render(drupal_get_form('tripal_bulk_loader_add_loader_job_form', $node)); ?>
-
-  <?php if (!empty($node->inserted_records)) {
-    print '<h3>Loading Summary</h3>';
-    $rows = array();
-    $total = 0;
-    foreach ($node->inserted_records as $r) {
-      $row = array();
-      $row[] = $r->table_inserted_into;
-      $row[] = $r->num_inserted;
-      $rows[] = $row;
-      $total = $total + $r->num_inserted;
-    }
-    $rows[] = array('<b>TOTAL</b>','<b>'.$total.'</b>');
-    print theme('table',array('header'=>array('Chado Table', 'Number of Records Inserted'), 'rows'=>$rows));
-  } ?>
-  <br>
-
-  <?php print drupal_render(drupal_get_form('tripal_bulk_loader_set_constants_form', $node)); ?>
-
-<?php print theme('tripal_bulk_loader_template', $node->template->template_id); ?>
-<?php } ?>

+ 0 - 0
tripal_bulk_loader/theme/tripal_bulk_loader_admin.tpl.php → tripal_bulk_loader/theme/templates/tripal_bulk_loader_admin.tpl.php


+ 166 - 0
tripal_bulk_loader/theme/templates/tripal_bulk_loader_base.tpl.php

@@ -0,0 +1,166 @@
+<?php
+$node  = $variables['node']; ?>
+
+<div class="tripal_bulk_loader-data-block-desc tripal-data-block-desc"></div> <?php 
+
+// the $headers array is an array of fields to use as the colum headers. 
+// additional documentation can be found here 
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+// This table for the analysis has a vertical header (down the first column)
+// so we do not provide headers here, but specify them in the $rows array below.
+$headers = array();
+
+// the $rows array contains an array of rows where each row is an array
+// of values for each column of the table in that row.  Additional documentation
+// can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+$rows = array();
+
+// Name row
+$rows[] = array(
+  array(
+    'data' => 'Job Name',
+    'header' => TRUE,
+    'width' => '20%',
+  ),
+  $node->loader_name
+);
+// Submitted By
+$rows[] = array(
+  array(
+    'data' => 'Submitted By',
+    'header' => TRUE
+  ),
+  $node->uid
+);
+// Job Creation Date
+$rows[] = array(
+  array(
+    'data' => 'Job Creation Date',
+    'header' => TRUE
+  ),
+  format_date($node->created, 'custom', "F j, Y, g:i a")
+);
+// Last Updated
+$rows[] = array(
+  array(
+    'data' => 'Last Updated',
+    'header' => TRUE
+  ),
+  format_date($node->changed, 'custom', "F j, Y, g:i a")
+);
+// Template Name
+$rows[] = array(
+  array(
+    'data' => 'Template Name',
+    'header' => TRUE
+  ),
+  $node->template->name
+);
+// Data File
+$rows[] = array(
+  array(
+    'data' => 'Data File',
+    'header' => TRUE
+  ),
+  $node->file
+);
+// Job Status
+$rows[] = array(
+  array(
+    'data' => 'Job Status',
+    'header' => TRUE
+  ),
+  $node->job_status
+);  
+//Job Progress
+if (isset($node->job)) {
+  if (isset($node->job->progress)) { 
+    $rows[] = array(
+      array(
+        'data' => 'Job Progress',
+        'header' => TRUE
+      ),
+      $node->job->progress . '% (' . l('view job', 'admin/tripal/tripal_jobs/view/' . $node->job_id) . ')'
+    );
+  }
+} 
+
+// the $table array contains the headers and rows array as well as other
+// options for controlling the display of the table.  Additional
+// documentation can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+$table = array(
+  'header' => $headers,
+  'rows' => $rows,
+  'attributes' => array(
+    'id' => 'tripal_bulk_loader-table-base',
+    'class' => 'tripal-data-table'
+  ),
+  '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.
+print theme_table($table);
+
+
+// add the "submit" button for adding a loading job to the Tripal jobs management system
+$form = drupal_get_form('tripal_bulk_loader_add_loader_job_form', $node);
+print drupal_render($form); 
+
+
+// if we have inserted records then load the summary:
+if (!empty($node->inserted_records)) {
+ 
+  print '<h3>Loading Summary</h3>';
+  // the $headers array is an array of fields to use as the colum headers.
+  // additional documentation can be found here
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $headers = array('Chado Table', 'Number of Records Inserted');
+  
+  // the $rows array contains an array of rows where each row is an array
+  // of values for each column of the table in that row.  Additional documentation
+  // can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $rows = array();
+  $total = 0;
+  
+  foreach ($node->inserted_records as $r) {
+    $row = array();
+    $row[] = $r->table_inserted_into;
+    $row[] = $r->num_inserted;
+    $rows[] = $row;
+    $total = $total + $r->num_inserted;
+  }
+  $rows[] = array('<b>TOTAL</b>','<b>'.$total.'</b>');
+  
+  // the $table array contains the headers and rows array as well as other
+  // options for controlling the display of the table.  Additional
+  // documentation can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(),
+    '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.
+  print theme_table($table);
+} ?>
+<br> <?php
+
+// add the form for setting any constants values
+$form =  drupal_get_form('tripal_bulk_loader_set_constants_form', $node);
+print drupal_render($form); 
+
+// add in the constant details
+print theme('tripal_bulk_loader_template', array('template_id' => $node->template->template_id));

+ 104 - 0
tripal_bulk_loader/theme/templates/tripal_bulk_loader_fields.tpl.php

@@ -0,0 +1,104 @@
+<?php
+$node  = $variables['node']; 
+
+// Retrieve Template
+$template = db_select('tripal_bulk_loader_template', 't')
+  ->fields('t')
+  ->condition('template_id', $node->template->template_id, '=')
+  ->execute()
+  ->fetchObject();
+
+$template->template_array = unserialize($template->template_array);
+
+// Summarize Template
+$fields = array();
+$constants = array();
+foreach ($template->template_array as $priority => $table_array) {
+  if (!is_array($table_array)) {
+    continue;
+  }
+
+  $table = $table_array['table'];
+  $record = $table_array['record_id'];
+  foreach ($table_array['fields'] as $field) {
+    if (preg_match('/table field/', $field['type'])) {
+      $field['table'] = $table;
+      $field['record'] = $record;
+      $sheet = 0;//$field['spreadsheet sheet'];
+      $column = $field['spreadsheet column'];
+      $fields[$sheet.'-'.$column][] = $field;
+    } 
+    elseif ($field['type'] == 'constant') {
+      $field['table'] = $table;
+      $field['record'] = $record;
+      $constants[] = $field;
+    }
+  }
+} ?>
+
+<p><b>Constants</b></p> <?php 
+
+// add a table describing the constants specified in the file
+if (sizeof($constants)) { 
+  $headers = array('Record Name', 'Field Name', 'Value', 'Chado Table', 'Chado Field');
+  $rows = array(); 
+  
+  // iterate through the fields and add rows to the table
+  foreach ($constants as $field) {
+    $rows[] = array($field['record'], $field['title'], $field['constant value'], $field['table'], $field['field']);
+  }
+  
+  // theme the table
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_bulk_loader-table-constants',
+      'class' => 'tripal-data-table'
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  print theme_table($table);
+
+} 
+?>
+
+<br><p><b>Data Columns</b></p> <?php 
+
+// add a table specifying the data file columns
+if (sizeof($fields)) { 
+
+  $headers = array('Record Name', 'Field Name', 'Data File Column', 'Chado Table', 'Chado Field');
+  $rows = array();
+  
+  // iterate through the fields and add rows to the table
+  foreach ($fields as $column) {
+    foreach ($column as $field) {
+      $rows[] = array(
+        $field['record'],
+        $field['title'],
+        $field['spreadsheet column'],
+        $field['table'],
+        $field['field']
+      );
+    }
+  }
+  
+  // theme the table
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_bulk_loader-table-columns',
+      'class' => 'tripal-data-table'
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  print theme_table($table);
+}

+ 0 - 0
tripal_bulk_loader/theme/tripal_bulk_loader_modify_template_base_form.tpl.php → tripal_bulk_loader/theme/templates/tripal_bulk_loader_modify_template_base_form.tpl.php


+ 9 - 0
tripal_bulk_loader/theme/templates/tripal_bulk_loader_teaser.tpl.php

@@ -0,0 +1,9 @@
+<div class="tripal_bulk_loader-teaser tripal-teaser">
+<div class="tripal-bulk_loader-teaser-title tripal-teaser-title"><?php
+    print l($node->title, "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-bulk_loader-teaser-text tripal-teaser-text"><?php 
+    print $node->title;
+    print "... " . l("[more]", "node/$node->nid"); ?>
+  </div>
+</div> <?php 

+ 0 - 79
tripal_bulk_loader/theme/tripal_bulk_loader_template.tpl.php

@@ -1,79 +0,0 @@
-<?php
-
-  // Retrieve Template
-  $template = db_select('tripal_bulk_loader_template', 't')
-    ->fields('t')
-    ->condition('template_id', $variables['template_id'], '=')
-    ->execute()
-    ->fetchObject();
-
-  $template->template_array = unserialize($template->template_array);
-
-  // Summarize Template
-  $fields = array();
-  $constants = array();
-  foreach ($template->template_array as $priority => $table_array) {
-    if (!is_array($table_array)) {
-      continue;
-    }
-
-    $table = $table_array['table'];
-    $record = $table_array['record_id'];
-    foreach ($table_array['fields'] as $field) {
-      if (preg_match('/table field/', $field['type'])) {
-        $field['table'] = $table;
-        $field['record'] = $record;
-        $sheet = 0;//$field['spreadsheet sheet'];
-        $column = $field['spreadsheet column'];
-        $fields[$sheet.'-'.$column][] = $field;
-      } elseif ($field['type'] == 'constant') {
-        $field['table'] = $table;
-        $field['record'] = $record;
-        $constants[] = $field;
-      }
-    }
-  }
-?>
-
-<div id="tripal_bulk_loader-base-box" class="tripal_bulk_loader-info-box tripal-info-box">
-  <div class="tripal_bulk_loader-info-box-title tripal-info-box-title">Template Description</div>
-  <div class="tripal_bulk_loader-data-block-desc tripal-data-block-desc"></div>
-
-<?php if (sizeof($constants)) { ?>
-  <table id="tripal_bulk_loader-template_constant-table" class="tripal_bulk_loader-table tripal-table tripal-table-vert">
-  <caption><b>Constants</b> -These values are applied to all records in the Data File</caption>
-    <tr><th rowspan="2">Record Name</th><th rowspan="2">Field Name</th><th rowspan="2">Value</th><th colspan="2">Chado Database</th></tr>
-    <tr><th>Table</th><th>Field</th></tr>
-    <?php $row = 'even' ?>
-    <?php foreach ($constants as $field) {?>
-      <tr class="tripal_bulk_loader-table-<?php print $row; ?>-row tripal-table-<?php print $row; ?>-row">
-        <td><?php print $field['record'];?></td>
-        <td><?php print $field['title'];?></td>
-        <td><?php print $field['constant value']; ?></td>
-        <td><?php print $field['table'];?></td>
-        <td><?php print $field['field'];?></td>
-      </tr>
-      <?php $row = ($row == 'odd') ? 'even':'odd' ; ?>
-    <?php } ?>
-  </table>
-
-<?php } if (sizeof($fields)) { ?>
-  <table id="tripal_bulk_loader-template_fields-table" class="tripal_bulk_loader-table tripal-table tripal-table-vert">
-  <caption><b>Fields</b> -Below is a mapping between Data File columns and the Chado Database</caption>
-  <tr><th rowspan="2">Record Name</th><th rowspan="2">Field Name</th><th rowspan="2">Data File Column</th><th colspan="2">Chado Datbase</th></tr>
-  <tr><th>Table</th><th>Field</th></tr>
-  <?php $row = 'even' ?>
-  <?php foreach ($fields as $column) {?>
-    <?php foreach ($column as $field) {?>
-    <tr class="tripal_bulk_loader-table-<?php print $row; ?>-row tripal-table-<?php print $row; ?>-row">
-      <td><?php print $field['record'];?></td>
-      <td><?php print $field['title'];?></td>
-      <td><?php print $field['spreadsheet column'];?></td>
-      <td><?php print $field['table'];?></td>
-      <td><?php print $field['field'];?></td>
-    <tr>
-    <?php $row = ($row == 'odd') ? 'even':'odd' ; ?>
-  <?php }} ?>
-  </table>
-<?php } ?>
-</div>

+ 28 - 9
tripal_bulk_loader/tripal_bulk_loader.module

@@ -283,22 +283,31 @@ function tripal_bulk_loader_views_api() {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_theme() {
+function tripal_bulk_loader_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
   return array(
     'node__tripal_bulk_loader' => array(
-      'template' => 'node--tripal-bulk-loader',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+      'template' => 'node--chado-generic',
       'render element' => 'node',
       'base hook' => 'node',
+      'path' => "$core_path/theme/templates",
     ),
-    'tripal_bulk_loader_template' => array(
-      'variables' => array('template_id' => NULL),
-      'template' => 'tripal_bulk_loader_template',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+    'tripal_bulk_loader_base' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_bulk_loader_base',
+      'path' => "$path/theme/templates",
     ),
+    'tripal_bulk_loader_fields' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_bulk_loader_fields',
+      'path' => "$path/theme/templates",
+    ),
+    
+    // form element themes
     'tripal_bulk_loader_modify_template_base_form' => array(
       'template' => 'tripal_bulk_loader_modify_template_base_form',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+      'path' => "$path/theme/templates",
       'render element' => 'form'
     ),
     'tripal_bulk_loader_field_regex_fieldset' => array(
@@ -306,9 +315,19 @@ function tripal_bulk_loader_theme() {
       'function' => 'tripal_bulk_loader_field_regex_fieldset',
       'render element' => 'element'
     ),
+    
+    // admin theme
     'tripal_bulk_loader_admin' => array(
       'template' => 'tripal_bulk_loader_admin',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+      'path' => "$path/theme/templates",
+    ),
+    
+
+    // themed teaser
+    'tripal_bulk_loader_teaser' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_bulk_loader_teaser',
+      'path' => "$path/theme/templates",
     ),
   );
 }

+ 16 - 0
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -647,6 +647,14 @@ function tripal_contact_node_insert($node) {
   switch ($node->type) {
     case 'chado_contact':
 
+      // find the contact and add in the details
+      $contact_id = chado_get_id_from_nid('contact', $node->nid);
+     
+      // get the contact
+      $values = array('contact_id' => $contact_id);
+      $contact = chado_generate_var('contact', $values);
+      $node->contact = $contact;
+      
       // Now get the title
       $node->title = chado_get_node_title($node);
 
@@ -665,6 +673,14 @@ function tripal_contact_node_update($node) {
   switch ($node->type) {
     case 'chado_contact':
 
+      // find the contact and add in the details
+      $contact_id = chado_get_id_from_nid('contact', $node->nid);
+       
+      // get the contact
+      $values = array('contact_id' => $contact_id);
+      $contact = chado_generate_var('contact', $values);
+      $node->contact = $contact;
+      
       // Now get the title
       $node->title = chado_get_node_title($node);
 

+ 1 - 1
tripal_contact/tripal_contact.module

@@ -266,7 +266,7 @@ function tripal_contact_permission() {
       'title' => t('Edit Contacts'),
       'description' => t('Allow users to edit contact pages.'),
     ),
-    'adminster tripal contact' => array(
+    'administer tripal contact' => array(
       'title' => t('Administer Contacts'),
       'description' => t('Allow users to administer all contacts.'),
     ),

+ 2 - 2
tripal_core/api/tripal_core.DEPRECATED.inc

@@ -149,7 +149,7 @@ function chado_node_additional_dbxrefs_form_update_dbxrefs($node, $details, $ret
  *
  * @see chado_add_node_form_properties().
  */
-function chado_node_properties_form($form, $form_state, $details) {
+function chado_node_properties_form($form, &$form_state, $details) {
 
   tripal_report_error(
     'tripal_deprecated',
@@ -812,7 +812,7 @@ function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
     );
 
     //New API Function
-    return tripal_add_populate_mview($mview_id, $redirect);
+    return tripal_add_job_populate_mview($mview_id, $redirect);
   }
   if ($op == 'delete') {
     tripal_report_error(

+ 1 - 1
tripal_core/api/tripal_core.chado_nodes.api.inc

@@ -791,7 +791,7 @@ function hook_chado_node_sync_create_new_node($new_node, $record) {
  *
  * @ingroup tripal_chado_node_api
  */
-function hook_chado_node_sync_form($form, $form_state) {
+function hook_chado_node_sync_form($form, &$form_state) {
 
   // Change or add to the form array as needed
   // Any changes should be made in accordance with the Drupal Form API

+ 1 - 1
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -7,7 +7,7 @@
  * How To Use:
  * @code
 
-  function chado_example_form($form, $form_state) {
+  function chado_example_form($form, &$form_state) {
 
     // Default values for form elements can come in the following ways:
     //

+ 4 - 2
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -7,7 +7,7 @@
  * How To Use:
  * @code
 
-  function chado_example_form($form, $form_state) {
+  function chado_example_form($form, &$form_state) {
 
     // Default values for form elements can come in the following ways:
     //
@@ -541,7 +541,9 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
   if (isset($form_state['input']['property_table']['new']['type'])) {
     $new_type_id = $form_state['input']['property_table']['new']['type'];
     $new_term = tripal_get_cvterm(array('cvterm_id' => $new_type_id));
-    $type_desc = $new_term->definition;
+    if ($new_term) {
+      $type_desc = $new_term->definition;
+    }
   }
   $form['properties']['property_table']['new']['type'] = array(
     '#type' => 'select',

+ 1 - 1
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -7,7 +7,7 @@
  * How To Use:
  * @code
 
-  function chado_example_form($form, $form_state) {
+  function chado_example_form($form, &$form_state) {
 
     // Default values for form elements can come in the following ways:
     //

+ 65 - 27
tripal_core/api/tripal_core.chado_nodes.title_and_path.inc

@@ -6,13 +6,42 @@
  *
  * TITLES
  * ====================================
- * There are two steps to implement the ability to set custom titles for your node type:
- * 1) Add the "Set Page Titles" Form to your admin settings form
+ * There are two steps to implement the ability to set custom titles for the node type:
+ * 1) Add the 'chado_node_api' elements to the hook_node_info function().  These values
+ *    define the name of the base table and how to refer to nodes in singular and plural.
+ *    There are additional paramaters that can be added to the 'chado_node_api' for 
+ *    syncing nodes (see documentation for the chado_node_sync_form() function for additional
+ *    options.
  * @code
-    // If your module is using the Chado Node: Title & Path API to allow custom titles
+  function modulename_node_info() {
+    return array(
+      'chado_example' => array(
+        'name' => t('example'),
+        'base' => 'chado_example',
+        'description' => t('A Chado example is a collection of material that can be sampled and have experiments performed on it.'),
+        'has_title' => TRUE,
+        'locked' => TRUE,
+
+        // this is what differs from the regular Drupal-documented hook_node_info()
+        'chado_node_api' => array(
+          'base_table' => 'example',            // the name of the chado base table
+          'hook_prefix' => 'chado_example',     // usually the name of the node type
+          'record_type_title' => array(
+            'singular' => t('Example'),         // Singular human-readable title
+            'plural' => t('Examples')           // Plural human-readable title
+          ),
+        )
+      ),
+    );
+  }
+ * @endcode
+ * 
+ * 2) Add the "Set Page Titles" Form to the admin settings form
+ * @code
+    // If the module is using the "Chado Node: Title & Path API" to allow custom titles
     // for your node type then you need to add the configuration form for this functionality.
     $details = array(
-      'module' => 'tripal_example',       // the name of the MODULE implementing the content type
+      'module' => 'tripal_example',        // the name of the MODULE implementing the content type
       'content_type' => 'chado_example',   // the name of the content type
         // An array of options to use under "Page Titles"
         // the key should be the token and the value should be the human-readable option
@@ -32,14 +61,13 @@
     chado_add_admin_form_set_title($form, $form_state, $details);
  * @endcode
  *
- * 2) Use chado_get_node_title($node) where ever you want the title for your node. This
+ * 3) Use chado_get_node_title($node) where ever you want the title for your node. This
  *    should be done in hook_load(), hook_node_insert(), hook_node_update(). The reason you
  *    set the title in the node_action hooks, which act on all nodes, is because at that
  *    point you have the generic loaded node.
  * @code
   function tripal_example_load($nodes) {
 
-    $new_nodes = array();
     foreach ($nodes as $nid => $node) {
 
       // Add all of the custom content for your node type.
@@ -48,10 +76,8 @@
       // Now get the title
       $node->title = chado_get_node_title($node);
 
-      $new_nodes[$nid] = $node;
+      $nodes[$nid] = $node;
     }
-
-    return $new_nodes;
   }
  * @endcode
  *
@@ -79,7 +105,7 @@
  * a default format
  *
  * @param $node
- *   The node whose title you want
+ *   The node object
  *
  * @ingroup tripal_chado_node_api
  */
@@ -98,8 +124,7 @@ function chado_get_node_title($node) {
       $token_info = $tokens[$token];
       if (!empty($token_info)) {
         $value = chado_get_token_value($token_info, $node);
-
-        $title = str_replace($token,$value,$title);
+        $title = str_replace($token, $value, $title);
       }
     }
   }
@@ -294,6 +319,16 @@ function chado_add_admin_form_set_title_form_submit($form, $form_state) {
  *
  * @param $content_type
  *   The name of the content (node) type you are interested in (ie: chado_feature)
+ * @param $tokens
+ *   An array, passed by reference that is filled to include the tokens for this
+ *   node type.  Each token is an array with the following keys:
+ *    -table: the name of the chado table
+ *    -field: the name of the field in the above table
+ *    -token: the token string (ie: [stock.stock_id])
+ *    -description: a very short description of the token (displayed when tokens are listed)
+ *    -location: the location of the value in a chado node variable with each level
+ *     separated by an arrow (->) symbol. For example, the location for $node->feature->type_id->name
+ *     is feature>type_id>name
  *
  * @return
  *   A string containing tokens describing the default format for the title of nodes
@@ -303,7 +338,7 @@ function chado_node_get_title_format($content_type, &$tokens, $base_table = NULL
   $format = '';
 
   // Is there a title format set?
-  $format_record = chado_node_get_token_format('title',$content_type, array('return_record' => TRUE));
+  $format_record = chado_node_get_token_format('title', $content_type, array('return_record' => TRUE));
   if (!empty($format_record)) {
     $format = $format_record->format;
     $tokens = $format_record->tokens;
@@ -338,7 +373,7 @@ function chado_node_get_title_format($content_type, &$tokens, $base_table = NULL
     $format = chado_node_get_unique_constraint_format($base_table);
   }
 
-  // Add the format to the new system so we can use it later
+  // Add the format to table so we can use it later
   chado_node_add_token_format('title', $content_type, $format, $tokens);
 
   return $format;
@@ -612,42 +647,45 @@ function chado_node_generate_tokens($base_table, $token_prefix = FALSE, $locatio
  *     separated by an arrow (>) symbol. For example, the location for $node->feature->type_id->name
  *     is feature>type_id>name
  *  @param $node
- *   The node to get the value of the token from
+ *   The node to get the value of the token
  *
  * @return
  *   The value of the token
  */
 function chado_get_token_value($token_info, $node) {
 
-  $location = explode('>',$token_info['location']);
+  $token = $token_info['token'];
+  $table = $token_info['table'];
+  $location = explode('>', $token_info['location']);
 
   $var = $node;
   foreach ($location as $index) {
     $index = trim($index);
+
+    // if $var is an object then it is the $node object or a table
+    // that has been expanded. On a node_insert then the fields are 
     if (is_object($var)) {
-      if (isset($var->{$index})) {
-        $var = $var->{$index};
+      // check to see if the index is a member of the object. If so,
+      // then reset the $var to this value.
+      if (property_exists($var, $index)) {
+        $var = $var->$index;
       }
       else {
         // @TODO: Error Handling
       }
     }
+    // if the $var is an array then there are multiple instances of the same
+    // table in a FK relationship (e.g. relationship tables)
     elseif (is_array($var)) {
       $var = $var[$index];
     }
     else {
-      tripal_report_error(
-        'chado_node_api',
-        TRIPAL_WARNING,
+      tripal_report_error('chado_node_api', TRIPAL_WARNING,
         'Tokens: Unable to determine the value of %token. Things went awry when trying
         to access %index for the following %var',
-        array(
-          '%token' => $token,
-          '%index' => $index,
-          '%var' => print_r($var,TRUE)
-        )
+        array('%token' => $token, '%index' => $index, '%var' => print_r($var,TRUE))
       );
-      return;
+      return '';
     }
   }
   return $var;

+ 2 - 4
tripal_core/api/tripal_core.chado_query.api.inc

@@ -645,7 +645,7 @@ function chado_update_record($table, $match, $values, $options = NULL) {
   }
 
   // get the values used for updating
-  foreach ($values as $field => $value) {
+  foreach ($values as $field => &$value) {
     if (is_array($value)) {
       $foreign_options = array();
       // select the value from the foreign key relationship for this value
@@ -1298,14 +1298,12 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
 function chado_query($sql, $args = array()) {
   $is_local = $GLOBALS["chado_is_local"];
 
-
   // Args should be an array
   if (!is_array($args)) {
     tripal_report_error('tripal_core', TRIPAL_ERROR,
       'chado_query; Need to pass an array to chado_query, "%value" passed instead. Query: %query',
       array('%value' => $args, '%query' => $sql)
     );
-    $args = array($args);
     return FALSE;
   }
 
@@ -1318,7 +1316,7 @@ function chado_query($sql, $args = array()) {
     // the featureloc table has some indexes that use function that call other functions
     // and those calls do not reference a schema, therefore, any tables with featureloc
     // must automaticaly have the chado schema set as active to find
-    if(preg_match('/chado.featureloc/i', $sql)) {
+    if (preg_match('/chado.featureloc/i', $sql)) {
       $previous_db = chado_set_active('chado') ;
       $results = db_query($sql, $args);
       chado_set_active($previous_db);

+ 3 - 1
tripal_core/api/tripal_core.chado_schema.api.inc

@@ -214,7 +214,9 @@ function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
     if (!$v) {
       $version =  "1.11 or older";
     }
-    $version =  $v->value;
+    else {
+      $version =  $v->value;
+    }
   }
 
   // next get the exact Chado version that is installed

+ 4 - 4
tripal_core/includes/tripal_core.chado_install.inc

@@ -171,10 +171,6 @@ function tripal_core_install_chado($action) {
 function tripal_core_reset_chado_schema() {
 
   // drop current chado and chado-related schema
-  if (chado_dbschema_exists('chado')) {
-    print "Dropping existing 'chado' schema\n";
-    db_query("drop schema chado cascade");
-  }
   if (chado_dbschema_exists('genetic_code')) {
     print "Dropping existing 'genetic_code' schema\n";
     db_query("drop schema genetic_code cascade");
@@ -187,6 +183,10 @@ function tripal_core_reset_chado_schema() {
     print "Dropping existing 'frange' schema\n";
     db_query("drop schema frange cascade");
   }
+  if (chado_dbschema_exists('chado')) {
+    print "Dropping existing 'chado' schema\n";
+    db_query("drop schema chado cascade");
+  }
 
   // create the new chado schema
   print "Creating 'chado' schema\n";

+ 1 - 1
tripal_core/theme/css/tripal.css

@@ -154,7 +154,7 @@
  * |-----------------------------------------------|
  */
 .tripal-teaser {
-  clear_both;
+  clear: both;
   margin-bottom: 10px;
 }
 .tripal-teaser-title {

+ 11 - 9
tripal_core/theme/templates/node--chado-generic.tpl.php

@@ -21,7 +21,7 @@ else {
         var id = $(this).attr('id') + "-tripal-data-block";
         $(".tripal-data-block").hide().filter("#"+ id).fadeIn('fast');
         return false;
-      }); 
+      });
   
       // if a ?block= is specified in the URL then we want to show the
       // requested block
@@ -44,15 +44,17 @@ else {
         <td nowrap class="tripal-contents-table-td tripal-contents-table-td-toc"  align="left"><?php
         
           // print the table of contents. It's found in the content array 
-          print $content['tripal_toc']['#markup'];
+          if (array_key_exists('tripal_toc', $content)) {
+            print $content['tripal_toc']['#markup'];
           
-          // we may want to add the links portion of the contents to the sidebar
-          //print render($content['links']);
-          
-          // remove the table of contents and links so thye doent show up in the 
-          // data section when the rest of the $content array is rendered
-          unset($content['tripal_toc']);
-          unset($content['links']); ?>
+            // we may want to add the links portion of the contents to the sidebar
+            //print render($content['links']);
+            
+            // remove the table of contents and links so thye doent show up in the 
+            // data section when the rest of the $content array is rendered
+            unset($content['tripal_toc']);
+            unset($content['links']); 
+          } ?>
 
         </td>
         <td class="tripal-contents-table-td-data" align="left" width="100%"> <?php

+ 92 - 45
tripal_core/tripal_core.install

@@ -96,7 +96,11 @@ function tripal_core_get_schemas() {
   foreach ($temp as $table => $arr) {
     $schema[$table] = $arr;
   }
-  $temp = tripal_core_tripaltoken_schema();
+  $temp = tripal_core_tripal_token_schema();
+  foreach ($temp as $table => $arr) {
+    $schema[$table] = $arr;
+  }
+  $temp = tripal_core_tripal_toc_schema();
   foreach ($temp as $table => $arr) {
     $schema[$table] = $arr;
   }
@@ -348,32 +352,32 @@ function tripal_core_custom_tables_schema() {
   return $schema;
 }
 
-function tripal_core_tripaltoken_schema() {
+function tripal_core_tripal_token_schema() {
   $schema = array();
   $schema['tripal_token_formats'] = array(
     'fields' => array(
       'tripal_format_id' => array(
         'type' => 'serial',
         'unsigned' => TRUE,
-        'not NULL' => TRUE
+        'not null' => TRUE
       ),
       'content_type' => array(
         'type' => 'varchar',
         'length' => 255,
-        'not NULL' => TRUE
+        'not null' => TRUE
       ),
       'application' => array(
         'type' => 'varchar',
         'length' => 255,
-        'not NULL' => TRUE
+        'not null' => TRUE
       ),
       'format' => array(
         'type' => 'text',
-        'not NULL' => TRUE
+        'not null' => TRUE
       ),
       'tokens' => array(
         'type' => 'text',
-        'not NULL' => TRUE
+        'not null' => TRUE
       ),
     ),
     'indexes' => array(
@@ -389,6 +393,62 @@ function tripal_core_tripaltoken_schema() {
   return $schema;
 }
 
+/**
+ * 
+ * 
+ */
+function tripal_core_tripal_toc_schema() {
+  $schema = array();
+  $schema['tripal_toc'] = array(
+    'fields' => array(
+      'toc_item_id' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE
+      ),
+      'node_type' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE
+      ),
+      'key' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+      'title' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => FALSE
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => FALSE
+      ),
+      'hide' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => FALSE,
+        'default' => 0,
+      ),
+      'nid' => array(
+        'type' => 'int',
+        'not null' => FALSE,
+      )
+    ),
+    'indexes' => array(
+      'tripal_toc_idx1' => array('node_type', 'key'),
+      'tripal_toc_idx2' => array('node_type', 'key', 'nid'),
+    ),
+    'unique keys' => array(
+      'tripal_toc_uq1' => array('node_type', 'key', 'nid'),
+    ),
+    'primary key' => array('toc_item_id'),
+  );
+
+  return $schema;
+}
+
 /**
  * Adds an mview_id column to the tripal_custom_tables table and makes an assocation between the mview and the custom table
  *
@@ -463,44 +523,31 @@ function tripal_core_update_7201() {
 
 
 /**
- * Adds in tripal token formats table to handle page title and path rewrites
+ * Adds a tripal_token_formats table for custom page titles and URL paths
  */
 function tripal_core_update_7202() {
-  $schema = array();
-  $schema['tripal_token_formats'] = array(
-    'fields' => array(
-      'tripal_format_id' => array(
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not NULL' => TRUE
-      ),
-      'content_type' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not NULL' => TRUE
-      ),
-      'application' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not NULL' => TRUE
-      ),
-      'format' => array(
-        'type' => 'text',
-        'not NULL' => TRUE
-      ),
-      'tokens' => array(
-        'type' => 'text',
-        'not NULL' => TRUE
-      ),
-    ),
-    'indexes' => array(
-      'tripal_format_id' => array('tripal_format_id'),
-      'type_application' => array('content_type', 'application'),
-    ),
-    'unique keys' => array(
-      'type_application' => array('content_type', 'application'),
-    ),
-    'primary key' => array('tripal_format_id'),
-  );
-  db_create_table('tripal_token_formats', $schema['tripal_token_formats']);
+  try {
+    $schema = drupal_get_schema_unprocessed('tripal_core', 'tripal_token_formats');
+    db_create_table('tripal_token_formats', $schema);
+  }
+  catch (Exception $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not add tripal_token_formats table: '. $error);
+  }
+}
+
+/**
+ * Adds a tripal_toc table for customizing the table of contents on each Tripal page.
+ */
+function tripal_core_update_7203() {
+  try {
+    $schema = drupal_get_schema_unprocessed('tripal_core', 'tripal_toc');
+    db_create_table('tripal_toc', $schema);
+  }
+  catch (Exception $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not add tripal_toc table: '. $error);
+    
+  }
+  
 }

+ 198 - 83
tripal_core/tripal_core.module

@@ -533,12 +533,16 @@ function tripal_core_node_view_alter(&$build) {
   if ($build['#view_mode'] != 'full' OR !array_key_exists('#tripal_generic_node_template', $build)) {
     return;
   }
+  
+  $node_type = $build["#node"]->type;
+  $nid = $build["#node"]->nid;
+  
 
   $cache = cache_get("theme_registry:$theme", 'cache');
   $node = $build['#node'];
   $toc = array();
   $toc_html = '';
-
+  
   // if we are looking at a Tripal node template then we want to
   // make some changes to each block of content so that we can associate
   // a table of contents and add administrator and curator messages
@@ -548,7 +552,7 @@ function tripal_core_node_view_alter(&$build) {
     // that are wanting to provide content for this node
     $markup = array();
     foreach ($build as $key => $value) {
-
+      
       // skip the body element as the Tripal node types do not use it
       if ($key == 'body') {
         continue;
@@ -557,68 +561,178 @@ function tripal_core_node_view_alter(&$build) {
       // examine elements without a '#' prefix as these should be adding
       // contents to the page. Skip the table of contents and links as those
       // will be placed elsewhere
-      if (!preg_match('/^#/', $key) and $key != 'tripal_toc' and $key != 'links') {
-
-        //-----------------------
-        // INITIALIZE THE CONTENT VARIABLES
-        //-----------------------
-        $toc_item_title = $key;
-        $toc_item_id    = $key;
-        $toc_item_link  = '';
-
-        // get the title for the table of contents.  Tripal templates should
-        // have a '#tripal_toc_title' element in the build array
-        if (array_key_exists('#tripal_toc_title', $build[$key])) {
-          $toc_item_title = $build[$key]['#tripal_toc_title'];
-        }
-        // other elements in the $build array may just have a '#title' element,
-        if (array_key_exists('#title', $build[$key])) {
-          $toc_item_title = $build[$key]['#title'];
+      if (preg_match('/^#/', $key) or $key == 'tripal_toc' or $key == 'links') {
+        continue;
+      }
+      //kook to see if the title, position and visibilty of this element has
+      // custom settings.  First check if the node is customized then check
+      // if the node type.
+      $override_title = '';
+      $override_weight = '';
+      $override_hide = 0;
+      $toc_item_overrides = db_select('tripal_toc', 'tc')
+        ->fields('tc', array('toc_item_id', 'title', 'weight', 'hide'))
+        ->condition('node_type', $node_type)
+        ->condition('key', $key)
+        ->condition('nid', $nid)
+        ->execute()
+        ->fetchObject();
+      if ($toc_item_overrides) {
+        $override_title = $toc_item_overrides->title;
+        $override_weight = $toc_item_overrides->weight;
+        $override_hide = $toc_item_overrides->hide;
+      }
+      else {
+        
+        // get the override title, weight for the general case
+        $toc_item_overrides = db_select('tripal_toc', 'tc')
+          ->fields('tc', array('toc_item_id', 'title', 'weight', 'hide'))
+          ->condition('node_type', $node_type)
+          ->condition('key', $key)
+          ->isNull('nid')
+          ->execute()
+          ->fetchObject();
+        if ($toc_item_overrides) {
+          $override_title = $toc_item_overrides->title;
+          $override_weight = $toc_item_overrides->weight;
+          $override_hide = $toc_item_overrides->hide;
         }
-        $toc_item_title = ucwords($toc_item_title);
+      }
 
-        if (array_key_exists('#tripal_toc_id', $build[$key])) {
-          $toc_item_id = $build[$key]['#tripal_toc_id'];
+      // if the element should be hiddent then unset this key the build
+      // array continue to the next one
+      if ($override_hide == 1) {
+        unset($build[$key]);
+        continue;
+      }
+      
+      // for backwards compatibility we will handle the content type fields 
+      // named 'field_resource_blocks', 'field_resource_titles', and 'field_resource_links'
+      // these fields can be added on the Drupal content types page and were
+      // specifically recoginzed by Tripal v1.1. 
+      if ($key == "field_resource_links") {
+        // links should just appear on the sidebar as is and not open up a panel
+        foreach (element_children($build[$key]) as $index) {
+          $element = $build[$key][$index];
+          $weight = 0;
+          $parts = explode("|", $element['#markup']);
+          if (count($parts) == 2) {
+            $toc[$weight][$parts[0]] = "<div class=\"tripal_toc_list_item\">" . l($parts[0], $parts[1], array('attributes' => array('target' => '_blank'))) . "</div>";
+          }
+          else {
+            $toc[$weight][$parts[0]] = "<div class=\"tripal_toc_list_item\">" . $element['#markup'] . "</div>";
+          }
+          // remove this link from the build array as we've moved it to appear in the TOC
+          unset($build[$key]);
         }
-        $toc_item_link = "<div class=\"tripal_toc_list_item\"><a id=\"$toc_item_id\" class=\"tripal_toc_list_item_link\" href=\"?block=$toc_item_id\">$toc_item_title</a></div>";
+        continue;
+      }
+      if ($key == "field_resource_titles") {
+        // ignore these, we will use them in the field_resource_blocks if
+        // statement below
+        continue;
+      }
+      if ($key == "field_resource_blocks") {
+        foreach (element_children($build[$key]) as $index) {
+          // get the block details and the title
+          $weight = 0;
+          $markup = $build[$key][$index]["#markup"];
+          $toc_item_id = "resource-$index";
+          $toc_item_title = $build["field_resource_titles"][$index]["#markup"];
+          $updated_markup = "
+            <div id=\"$toc_item_id-tripal-data-block\" class=\"tripal-data-block\">
+              <div class=\"$toc_item_id-tripal-data-block-title tripal-data-block-title\">$toc_item_title</div>
+                $markup
+              </div>
+            </div>
+          ";
+          $build[$toc_item_id]['#markup'] = $updated_markup;
+          $build[$toc_item_id]['#weight'] = $weight;
+          $build[$toc_item_id]['#toc_handled'] = TRUE;
+          // add the entry to the TOC
+          $toc_item_link = "<div class=\"tripal_toc_list_item\"><a id=\"$toc_item_id\" class=\"tripal_toc_list_item_link\" href=\"?block=$toc_item_id\">$toc_item_title</a></div>";
+          $toc[$weight][$toc_item_title] = $toc_item_link;
+        }
+        // remove the key from the build array. We have have replaced it
+        unset($build[$key]);
+        unset($build["field_resource_titles"]);
+        continue;
+      }
+      
+      // skip any keys we may have already handled. This is the case for 
+      // the field_resource_blocks where we removed the old CCK fields
+      // and added new ones.  We don't want these new ones to be processed
+      // again by the code below.
+      if (array_key_exists('#toc_handled', $build[$key]) and $build[$key]['#toc_handled'] == TRUE) {
+        continue;
+      }
+      
+      // for all other fields we will handle in the following way 
+      //-----------------------
+      // INITIALIZE THE CONTENT VARIABLES
+      //-----------------------
+      $toc_item_title = $key;
+      $toc_item_id    = $key;
+      $toc_item_link  = '';
+
+      // get the title for the table of contents.  Tripal templates should
+      // have a '#tripal_toc_title' element in the build array
+      if (array_key_exists('#tripal_toc_title', $build[$key])) {
+        $toc_item_title = $build[$key]['#tripal_toc_title'];
+      }
+      // other elements in the $build array may just have a '#title' element,
+      if (array_key_exists('#title', $build[$key])) {
+        $toc_item_title = $build[$key]['#title'];
+      }
+      $toc_item_title = ucwords($toc_item_title);
+      
+      // now override the title if a value is set in the tripal_toc table
+      $toc_item_title = $override_title ? $override_title : $toc_item_title;
 
+      if (array_key_exists('#tripal_toc_id', $build[$key])) {
+        $toc_item_id = $build[$key]['#tripal_toc_id'];
+      }
+      $toc_item_link = "<div class=\"tripal_toc_list_item\"><a id=\"$toc_item_id\" class=\"tripal_toc_list_item_link\" href=\"?block=$toc_item_id\">$toc_item_title</a></div>";
 
-        //-----------------------
-        // GET THE MARKUP FOR EACH ELEMENT
-        //-----------------------
-        $markup = '';
 
-        // find the markup. Some fields will have a '#markup' and others, such
-        // as CCK elements may have a set of '#markup' elements organized by
-        // numerical keys.
-        if (array_key_exists('#markup', $build[$key]) and trim($build[$key]['#markup'])) {
-          $markup = $build[$key]['#markup'];
-        }
-        // For backwards copmatibility we should support the '#value' element as well.
-        elseif (array_key_exists('#value', $build[$key]) and trim($build[$key]['#value'])) {
-          $markup = $build[$key]['#markup'];
-        }
+      //-----------------------
+      // GET THE MARKUP FOR EACH ELEMENT
+      //-----------------------
+      $markup = '';
 
-        // if we have no '#markup' field then this element has not yet
-        // been rendered.  Let's render it and substitute that for markup
-        if (!$markup) {
-          $markup = trim(render($build[$key]));
-          $build[$key] = array(
-            '#markup' => $markup,
-          );
-        }
+      // find the markup. Some fields will have a '#markup' and others, such
+      // as CCK elements may have a set of '#markup' elements organized by
+      // numerical keys.
+      if (array_key_exists('#markup', $build[$key]) and trim($build[$key]['#markup'])) {
+        $markup = $build[$key]['#markup'];
+      }
+      // For backwards copmatibility we should support the '#value' element as well.
+      elseif (array_key_exists('#value', $build[$key]) and trim($build[$key]['#value'])) {
+        $markup = $build[$key]['#markup'];
+      }
 
-        // if we still don't have markup then skip this one
-        if (!$markup) {
-          continue;
-        }
+      // if we have no '#markup' field then this element has not yet
+      // been rendered.  Let's render it and substitute that for markup
+      if (!$markup) {
+        $markup = trim(render($build[$key]));
+        $build[$key] = array(
+          '#markup' => $markup,
+        );
+      }
+
+      // if we still don't have markup then skip this one
+      if (!$markup) {
+        continue;
+      }
 
-        //-----------------------
-        // FIND THE TEMPLATE PATH
-        //-----------------------
-        // get the template path so we can put it in an admin message box
-        $path = '';
-        if (array_key_exists($key, $cache->data) and array_key_exists('path', $cache->data[$key])) {
+      //-----------------------
+      // FIND THE TEMPLATE PATH
+      //-----------------------
+      // get the template path so we can put it in an admin message box
+      $path = '';
+      if (!array_key_exists('#tripal_template_show', $build[$key]) or 
+           $build[$key]['#tripal_template_show'] == TRUE) {
+        if ($cache and array_key_exists($key, $cache->data) and array_key_exists('path', $cache->data[$key])) {
 
           $path = $cache->data[$key]['path'] . '/' . $key . '.tpl.php';
 
@@ -632,36 +746,38 @@ function tripal_core_node_view_alter(&$build) {
             array('return_html' => 1)
           );
         }
+      }
 
-        //-----------------------
-        // SET THE WEIGHTS FOR THE TOC ELEMENTS
-        //-----------------------
-        // set the weight of the TOC item and add it to our $toc array
-        // for building of the TOC below
-        $weight = 0;
-        if (array_key_exists('#weight', $build[$key])) {
-          $weight = $build[$key]['#weight'];
-        }
-        $toc[$weight][$toc_item_title] = $toc_item_link;
-
-        //-----------------------
-        // CREATE THE DATA BLOCK
-        //-----------------------
-        // add a surrounding <div> box around the content
-        $updated_markup = "
-          <div id=\"$toc_item_id-tripal-data-block\" class=\"tripal-data-block\">
-            <div class=\"$toc_item_id-tripal-data-block-title tripal-data-block-title\">$toc_item_title</div>
-              $markup
-              $path
-            </div>
+      //-----------------------
+      // SET THE WEIGHTS FOR THE TOC ELEMENTS
+      //-----------------------
+      // set the weight of the TOC item and add it to our $toc array
+      // for building of the TOC below
+      $weight = 0;
+      if (array_key_exists('#weight', $build[$key])) {
+        $weight = $build[$key]['#weight'];
+      }
+      // override the weight if it's set in the tripal_toc table
+      $weight = $override_weight ? $override_weight : $weight;
+      $toc[$weight][$toc_item_title] = $toc_item_link;
+
+      //-----------------------
+      // CREATE THE DATA BLOCK
+      //-----------------------
+      // add a surrounding <div> box around the content
+      $updated_markup = "
+        <div id=\"$toc_item_id-tripal-data-block\" class=\"tripal-data-block\">
+          <div class=\"$toc_item_id-tripal-data-block-title tripal-data-block-title\">$toc_item_title</div>
+            $markup
+            $path
           </div>
-        ";
+        </div>
+      ";
 
-        $build[$key]['#markup'] = $updated_markup;
-        $build[$key]['#weight'] = $weight;
-      }
-    }
-  }
+      $build[$key]['#markup'] = $updated_markup;
+      $build[$key]['#weight'] = $weight;
+    } // end foreach ($build as $key => $value) {
+  } // end if ($build['#tripal_generic_node_template'] == TRUE) {
 
   //-----------------------
   // BUILD THE TABLE OF CONTENTS LINKS
@@ -677,7 +793,6 @@ function tripal_core_node_view_alter(&$build) {
     }
   }
   $build['tripal_toc']['#markup'] = "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\">$toc_html</div>";
-
 }
 
 /**

+ 3 - 3
tripal_cv/api/tripal_cv.DEPRECATED.inc

@@ -326,9 +326,9 @@ function tripal_cv_submit_obo_job($obo_id = NULL, $obo_name = NULL, $obo_url = N
   return tripal_submit_obo_job(
     array(
       'obo_id' => $obo_id,
-      'name' => $obo_name,
-      'url' => $obo_url,
-      'file' => $obo_file
+      'name'   => $obo_name,
+      'url'    => $obo_url,
+      'file'   => $obo_file
     )
   );
 }

+ 5 - 5
tripal_cv/api/tripal_cv.api.inc

@@ -779,9 +779,9 @@ function tripal_submit_obo_job($obo) {
 
   // Set Defaults
   $obo['obo_id'] = (isset($obo['obo_id'])) ? $obo['obo_id'] : NULL;
-  $obo['name'] = (isset($obo['name'])) ? $obo['name'] : NULL;
-  $obo['url'] = (isset($obo['url'])) ? $obo['url'] : NULL;
-  $obo['file'] = (isset($obo['file'])) ? $obo['file'] : NULL;
+  $obo['name']   = (isset($obo['name']))   ? $obo['name']   : NULL;
+  $obo['url']    = (isset($obo['url']))    ? $obo['url']    : NULL;
+  $obo['file']   = (isset($obo['file']))   ? $obo['file']   : NULL;
 
   if ($obo['obo_id']) {
     $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = :obo_id";
@@ -794,12 +794,12 @@ function tripal_submit_obo_job($obo) {
   else {
     if ($obo['url']) {
       $args = array($obo['name'], $obo['url']);
-      return tripal_add_job("Load OBO $obo_name", 'tripal_cv',
+      return tripal_add_job("Load OBO " . $obo['name'], 'tripal_cv',
         "tripal_cv_load_obo_v1_2_url", $args, $user->uid);
     }
     elseif ($obo['file']) {
       $args = array($obo['name'], $obo['file']);
-      return tripal_add_job("Load OBO $obo_name", 'tripal_cv',
+      return tripal_add_job("Load OBO " . $obo['name'], 'tripal_cv',
         "tripal_cv_load_obo_v1_2_file", $args, $user->uid);
     }
   }

+ 1 - 1
tripal_cv/includes/tripal_cv.admin.inc

@@ -48,7 +48,7 @@ function tripal_cv_admin_cv_listing() {
 /**
  *
  */
-function tripal_cv_admin_set_defaults_form($form, $form_state) {
+function tripal_cv_admin_set_defaults_form($form, &$form_state) {
 
   $form['instructions'] = array(
     '#markup' => t('Much of the data housed in Chado is typed, meaning that a ' .

+ 1 - 1
tripal_cv/includes/tripal_cv.cv_form.inc

@@ -79,7 +79,7 @@ function tripal_cv_cv_edit_form($form, &$form_state) {
  *
  * @ingroup tripal_cv
  */
-function tripal_cv_cv_add_form($form, $form_state) {
+function tripal_cv_cv_add_form($form, &$form_state) {
 
   // add in the form fields to this form
   tripal_cv_add_cv_form_fields($form, $form_state);

+ 4 - 4
tripal_cv/includes/tripal_cv.obo_loader.inc

@@ -114,10 +114,10 @@ function tripal_cv_obo_form($form, &$form_state) {
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_form_submit($form, &$form_state) {
-  $obo_id =  $form_state['values']['obo_id'];
-  $obo_name =  $form_state['values']['obo_name'];
-  $obo_url =  $form_state['values']['obo_url'];
-  $obo_file  = $form_state['values']['obo_file'];
+  $obo_id    = $form_state['values']['obo_id'];
+  $obo_name  = trim($form_state['values']['obo_name']);
+  $obo_url   = trim($form_state['values']['obo_url']);
+  $obo_file  = trim($form_state['values']['obo_file']);
 
   tripal_cv_submit_obo_job($obo_id, $obo_name, $obo_url, $obo_file);
 }

+ 1 - 1
tripal_cv/includes/tripal_cv.trees.inc

@@ -432,7 +432,7 @@ function tripal_cv_cvterm_info($cvterm_id) {
  *
  * @ingroup tripal_cv
  */
-function tripal_cv_list_form($form_state) {
+function tripal_cv_list_form($form, &$form_state) {
 
   // get a list of db from chado for user to choose
   $sql = "

+ 1 - 1
tripal_db/includes/tripal_db.admin.inc

@@ -120,7 +120,7 @@ function tripal_db_db_edit_form($form, &$form_state) {
  *
  * @ingroup tripal_db
  */
-function tripal_db_db_add_form($form, $form_state) {
+function tripal_db_db_add_form($form, &$form_state) {
 
   // add in the form fields to this form
   tripal_db_add_db_form_fields($form, $form_state);

+ 19 - 9
tripal_example/includes/tripal_example.chado_node.inc

@@ -574,12 +574,13 @@ function chado_example_load($nodes) {
     // cases it is probably best to let the end-user decide if text fields should
     // be included by using this function in the templates.
     $example = chado_expand_var($example, 'field', 'example.description');
+    
 
     // If your module is using the Chado Node: Title & Path API to allow custom titles
     // for your node type. Every time you want the title of the node, you need to use the
     // following API function:
-    $example->title = chado_get_node_title($node);
-
+    $node->title = chado_get_node_title($node);
+    
     // add the new example object to this node.
     $nodes[$nid]->example = $example;
   }
@@ -652,13 +653,16 @@ function tripal_example_node_insert($node) {
   // it in the hook_insert()
   switch ($node->type) {
     case 'chado_example':
-
-      // if we do not have an record ID for this node then get it
-      if (!property_exists($node, 'example_id')) {
-        $node->example_id = chado_get_id_from_nid('example', $node->nid);
-      }
-
-      // If your module is using the Chado Node: Title & Path API to allow custom titles
+     
+      // find the example and add in the details
+      $example_id = chado_get_id_from_nid('example', $nid);
+      
+      // build the example variable by using the chado_generate_var() function
+      $values = array('example_id' => $example_id);
+      $example = chado_generate_var('example', $values);
+      $node->example = $example;
+
+      // If your module is using the 'Chado Node: Title & Path API' to allow custom titles
       // for your node type. Every time you want the title of the node, you need to use the
       // following API function:
       $example->title = chado_get_node_title($node);
@@ -773,6 +777,12 @@ function tripal_example_node_view($node, $view_mode, $langcode) {
           '#tripal_toc_id'    => 'relationships',
           '#tripal_toc_title' => 'Relationships',
         );
+        
+        // Note: if you create a template that you do not want a user to 
+        // know where it is (discourage editing of it), you can add the following 
+        // key:  '#tripal_template_show' => FALSE. If this key/value is set
+        // the the administrator message that Tripal provides indicating
+        // where the template is housed will not be shown.
       }
       // set the content for the teaser view
       if ($view_mode == 'teaser') {

+ 1 - 1
tripal_example/theme/templates/tripal_example_teaser.tpl.php

@@ -11,4 +11,4 @@ $example  = $variables['node']->example; ?>
       print "... " . l("[more]", "node/$node->nid");
     } ?>
   </div>
-</div> <?php 
+</div>

+ 2 - 2
tripal_example/tripal_example.install

@@ -516,7 +516,7 @@ function tripal_example_add_example_dbxref_table() {
   // EXPLANATION: use the Drupal Schema API to describe the custom table. Then
   // add the table using the chado_create_custom_table() function.
 
-  $description =  array(
+  $schema =  array(
     'table' => 'example_dbxref',
     'fields' => array(
       'example_dbxref_id' => array(
@@ -615,4 +615,4 @@ function tripal_example_update_dependencies() {
   );
 
   return $dependencies;
-}
+}

+ 2 - 2
tripal_example/tripal_example.module

@@ -23,7 +23,7 @@ require('includes/tripal_example.chado_node.inc');
  * 
  * @ingroup tripal_example
  */
-function tripal_example_permisssions() {
+function tripal_example_permission() {
   
   // EXPLANATION:  here we want to setup any of the permission types
   // that this module needs.  Our exmample module creates a new
@@ -50,7 +50,7 @@ function tripal_example_permisssions() {
       'title' => t('Edit Examples'),
       'description' => t('Allow users to edit example pages.'),
     ),
-    'adminster tripal example' => array(
+    'administer tripal example' => array(
       'title' => t('Administer Examples'),
       'description' => t('Allow users to administer all examples.'),
     ),

+ 0 - 62
tripal_feature/api/tripal_feature.DEPRECATED.inc

@@ -373,46 +373,6 @@ function tripal_feature_reverse_complement($sequence) {
   return tripal_reverse_compliment_sequence($sequence);
 }
 
-/**
- * @deprecated Restructured API to make naming more readable and consistent.
- * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by tripal_get_sequence().
- *
- * @see tripal_get_sequence().
- */
-function tripal_feature_get_formatted_sequence($feature_id, $feature_name, $num_bases_per_line, $derive_from_parent, $aggregate, $output_format, $upstream, $downstream, $sub_features = array(), $relationship = '', $rel_part = '') {
-
-  tripal_report_error(
-    'tripal_deprecated',
-    TRIPAL_NOTICE,
-    "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
-    array(
-      '%old_function'=>'tripal_feature_get_formatted_sequence',
-      '%new_function' => 'tripal_get_sequence'
-    )
-  );
-
-  return tripal_get_sequence(
-    // Feature
-    array(
-      'feature_id' => $feature_id,
-      'name' => $feature_name
-    ),
-    // Options
-    array(
-      'width' => $num_bases_per_line,
-      'derive_from_parent' => $derive_from_parent,
-      'aggregate' => $aggregate,
-      'output_format' => $output_format,
-      'num_upstream' => $upstream,
-      'num_downstream' => $downstream,
-      'sub_feature_types' => $sub_features,
-      'relationship_type' => $relationship,
-      'relationship_part' => $rel_part
-    )
-  );
-}
-
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
@@ -470,25 +430,3 @@ function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
     )
   );
 }
-
-/**
- * @deprecated Restructured API to make naming more readable and consistent.
- * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by tripal_format_fasta_sequence().
- *
- * @see tripal_format_fasta_sequence().
- */
-function tripal_feature_return_fasta($feature, $desc) {
-
-  tripal_report_error(
-    'tripal_deprecated',
-    TRIPAL_NOTICE,
-    "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
-    array(
-      '%old_function'=>'tripal_feature_return_fasta',
-      '%new_function' => 'tripal_format_fasta_sequence'
-    )
-  );
-
-  return tripal_format_fasta_sequence($feature, $desc);
-}

+ 313 - 107
tripal_feature/api/tripal_feature.api.inc

@@ -45,7 +45,8 @@ function tripal_reverse_compliment_sequence($sequence) {
 }
 
 /**
- * Retrieves the sequence for a feature.
+ * Retrieves the sequences for a given feature. If a feature has multiple alignments
+ *  or multiple relationships then multiple sequences will be returned.
  *
  * @param $feature
  *   An associative array describing the feature. Valid keys include:
@@ -59,19 +60,15 @@ function tripal_reverse_compliment_sequence($sequence) {
  *   An associative array of options. Valid keys include:
  *    - width: Indicate the number of bases to use per line.  A new line will be added
  *        after the specified number of bases on each line.
+ *    - is_html: Set to '1' if  the sequence is meant to be displayed on a web page.
+ *        This will cause a <br> tag to separate lines of the FASTA sequence. 
  *    - derive_from_parent: Set to '1' if the sequence should be obtained from the parent
  *        to which this feature is aligned.
  *    - aggregate: Set to '1' if the sequence should only contain sub features, excluding
  *        intro sub feature sequence.  For example, set this option to obtain just
  *        the coding sequence of an mRNA.
- *    - output_format: The type of format.  Valid formats include 'fasta_html', 'fasta_txt' and
- *        'raw'.  The format 'fasta_txt' outputs line breaks as <br> tags and the entire
- *        return value is in a <span> tag with a fixed-width font definition.  'fasta_txt'
- *        outputs line breaks with windows format carriage returns (e.g. \r\n) with no other
- *        formatting. The raw format is simply the sequence with no FASTA formatting and no
- *        line breaks.
- *    - num_upstream: An integer specifing the number of upstream bases to include in the output
- *    - num_downstream: An integer specifying the number of downstream bases to include in the
+ *    - upstream: An integer specifing the number of upstream bases to include in the output
+ *    - downstream: An integer specifying the number of downstream bases to include in the
  *        output.
  *    - sub_feature_types: Only include sub features (or child features) of the types
  *        provided in the array
@@ -82,33 +79,39 @@ function tripal_reverse_compliment_sequence($sequence) {
  *        relationship the matched features belong
  *
  * @return
- *   an array of matching sequence formated as requested.
+ *   an array of matching sequence in the following keys for each sequence:
+ *      'types'         => an array of feature types that were used to derive the sequence (e.g. from an aggregated sequence)
+ *      'upstream'      => the number of upstream bases included in the sequence
+ *      'downstream'    => the number of downstream bases included in the sequence
+ *      'defline'       => the definintion line used to create a FASTA sequence
+ *      'residues'      => the residues
+ *      'featureloc_id' => the featureloc_id if the sequences is from an alignment
  *
  * @ingroup tripal_feature_api
  */
-function tripal_get_sequence($feature, $options) {
+function tripal_get_feature_sequences($feature, $options) {
 
   // default values for finding the feature
-  $feature_id    = array_key_exists('feature_id', $feature)     ? $feature['feature_id']     : 0;
-  $parent_id     = array_key_exists('parent_id', $feature)      ? $feature['parent_id']      : 0;
-  $featureloc_id = array_key_exists('featureloc_id', $feature)  ? $feature['featureloc_id']  : 0;
-  $feature_name  = array_key_exists('name', $feature)           ? $feature['name']           : '';
+  $feature_id         = array_key_exists('feature_id', $feature)     ? $feature['feature_id']     : 0;
+  $parent_id          = array_key_exists('parent_id', $feature)      ? $feature['parent_id']      : 0;
+  $featureloc_id      = array_key_exists('featureloc_id', $feature)  ? $feature['featureloc_id']  : 0;
+  $feature_name       = array_key_exists('name', $feature)           ? $feature['name']           : '';
 
   // default values for building the sequence
   $num_bases_per_line = array_key_exists('width', $options)              ? $options['width']              : 50;
   $derive_from_parent = array_key_exists('derive_from_parent', $options) ? $options['derive_from_parent'] : 0;
   $aggregate          = array_key_exists('aggregate', $options)          ? $options['aggregate']          : 0;
-  $output_format      = array_key_exists('output_format', $options)      ? $options['output_format']      : 'fasta_txt';
-  $upstream           = array_key_exists('num_upstream', $options)       ? $options['num_upstream']       : 0;
-  $downstream         = array_key_exists('num_downstream', $options)     ? $options['num_downstream']     : 0;
+  $upstream           = array_key_exists('upstream', $options)           ? $options['upstream']           : 0;
+  $downstream         = array_key_exists('downstream', $options)         ? $options['downstream']         : 0;
   $sub_features       = array_key_exists('sub_feature_types', $options)  ? $options['sub_feature_types']  : array();
   $relationship       = array_key_exists('relationship_type', $options)  ? $options['relationship_type']  : '';
   $rel_part           = array_key_exists('relationship_part', $options)  ? $options['relationship_part']  : '';
+  $is_html            = array_key_exists('is_html', $options)            ? $options['is_html']            : 0;
   
   // make sure the sub_features variable is an array
   if (!is_array($sub_features)) {
-    tripal_report_error('tripal_deprecated', TRIPAL_ERROR,
-      "'sub_features' option must be an array for function tripal_get_sequence().",
+    tripal_report_error('tripal_feature', TRIPAL_ERROR,
+      "'sub_features' option must be an array for function tripal_get_feature_sequences().",
       array()
     );
     return array();
@@ -121,12 +124,12 @@ function tripal_get_sequence($feature, $options) {
     if ($rel_part == "subject") {
       $sql = '
         SELECT FO.feature_id, FO.name, FO.uniquename, CVTO.name as feature_type, O.genus, O.species
-        FROM feature FS
-          INNER JOIN feature_relationship FR ON FR.subject_id   = FS.feature_id
-          INNER JOIN cvterm CVTFR            ON CVTFR.cvterm_id = FR.type_id
-          INNER JOIN feature FO              ON FO.feature_id   = FR.object_id
-          INNER JOIN cvterm CVTO             ON CVTO.cvterm_id  = FO.type_id
-          INNER JOIN organism O              ON O.organism_id   = FO.organism_id
+        FROM {feature} FS
+          INNER JOIN {feature_relationship} FR ON FR.subject_id   = FS.feature_id
+          INNER JOIN {cvterm} CVTFR            ON CVTFR.cvterm_id = FR.type_id
+          INNER JOIN {feature} FO              ON FO.feature_id   = FR.object_id
+          INNER JOIN {cvterm} CVTO             ON CVTO.cvterm_id  = FO.type_id
+          INNER JOIN {organism} O              ON O.organism_id   = FO.organism_id
         WHERE
           FS.feature_id = :feature_id AND
           CVTFR.name    = :relationship
@@ -136,12 +139,12 @@ function tripal_get_sequence($feature, $options) {
     if ($rel_part == "object") {
       $sql = '
         SELECT FS.feature_id, FS.name, FS.uniquename, CVTO.name as feature_type, O.genus, O.species
-        FROM feature FO
-          INNER JOIN feature_relationship FR ON FR.object_id    = FO.feature_id
-          INNER JOIN cvterm CVTFR            ON CVTFR.cvterm_id = FR.type_id
-          INNER JOIN feature FS              ON FS.feature_id   = FR.subject_id
-          INNER JOIN cvterm CVTO             ON CVTO.cvterm_id  = FS.type_id
-          INNER JOIN organism O              ON O.organism_id   = FS.organism_id
+        FROM {feature} FO
+          INNER JOIN {feature_relationship} FR ON FR.object_id    = FO.feature_id
+          INNER JOIN {cvterm} CVTFR            ON CVTFR.cvterm_id = FR.type_id
+          INNER JOIN {feature} FS              ON FS.feature_id   = FR.subject_id
+          INNER JOIN {cvterm} CVTO             ON CVTO.cvterm_id  = FS.type_id
+          INNER JOIN {organism} O              ON O.organism_id   = FS.organism_id
         WHERE
           FO.feature_id = :feature_id AND
           CVTFR.name    = :relationship
@@ -158,7 +161,7 @@ function tripal_get_sequence($feature, $options) {
       if ($rel_part == "object") {
         $defline = "$feature->uniquename $feature->feature_type ($feature->genus $feature->species), $relationship, $feature_name";
       }
-      return tripal_get_sequence(
+      return tripal_get_feature_sequences(
         array(
           'feature_id' => $feature->feature_id, 
           'name' => $defline,
@@ -166,9 +169,8 @@ function tripal_get_sequence($feature, $options) {
         ),
         array(
           'width' => $num_bases_per_line, 
-          'derive_from_pareht' => $derive_from_parent, 
+          'derive_from_parent' => $derive_from_parent, 
           'aggregate' => $aggregate, 
-          'output_format' => $output_format,
           'upstream' => $upstream, 
           'downstream' => $downstream, 
           'sub_features' => $sub_features, 
@@ -182,7 +184,7 @@ function tripal_get_sequence($feature, $options) {
   // cases cases where the alignment is in the reverse direction and when
   // the upstream and downstream extensions go beyond the lenght of the
   // parent sequence.
-  $sql ='
+  $parent_sql ='
     SELECT featureloc_id, srcname, srcfeature_id, strand, srctypename, typename,
       fmin, fmax, upstream, downstream, adjfmin, adjfmax,
       substring(residues from (adjfmin + 1) for (upstream + (fmax - fmin) + downstream))  as residues,
@@ -255,10 +257,10 @@ function tripal_get_sequence($feature, $options) {
   $sfsql = '
     SELECT SF.feature_id, CVT.name as type_name, SF.type_id
     FROM {feature_relationship} FR
-      INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
-      INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
-      INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
-      INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
+      INNER JOIN {feature} SF    ON SF.feature_id = FR.subject_id
+      INNER JOIN {cvterm} CVT    ON CVT.cvterm_id = SF.type_id
+      INNER JOIN {featureloc} FL ON FL.feature_id = FR.subject_id
+      INNER JOIN {feature} PF    ON PF.feature_id = FL.srcfeature_id
     WHERE FR.object_id = :feature_id and PF.feature_id = :srcfeature_id
     ORDER BY FL.fmin ASC
   ';
@@ -266,10 +268,10 @@ function tripal_get_sequence($feature, $options) {
   $fsql ='
     SELECT count(*) as num_children
     FROM {feature_relationship} FR
-      INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
-      INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
-      INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
-      INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
+      INNER JOIN {feature} SF    ON SF.feature_id = FR.subject_id
+      INNER JOIN {cvterm} CVT    ON CVT.cvterm_id = SF.type_id
+      INNER JOIN {featureloc} FL ON FL.feature_id = FR.subject_id
+      INNER JOIN {feature} PF    ON PF.feature_id = FL.srcfeature_id
     WHERE FR.object_id = :feature_id and PF.feature_id = :srcfeature_id
   ';
 
@@ -280,8 +282,7 @@ function tripal_get_sequence($feature, $options) {
   if ($derive_from_parent) {
 
     // execute the query to get the sequence from the parent
-    $parents = chado_query($sql, array(':upstream' => $upstream, ':downstream' => $downstream, ':feature_id' => $feature_id));
-
+    $parents = chado_query($parent_sql, array(':upstream' => $upstream, ':downstream' => $downstream, ':feature_id' => $feature_id));
     while ($parent = $parents->fetchObject()) {
       
       // if the user specified a particular parent and this one doesn't match then skip it
@@ -293,6 +294,7 @@ function tripal_get_sequence($feature, $options) {
         continue;
       }
       $seq = '';  // initialize the sequence for each parent
+      $notes = '';
 
       // if we are to aggregate then we will ignore the feature returned
       // by the query above and rebuild it using the sub features
@@ -300,7 +302,7 @@ function tripal_get_sequence($feature, $options) {
 
         // now get the sub features that are located on the parent.
         $children = chado_query($sfsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
-        $num_children = chado_query($fsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id))->fetchObject();
+        $num_children = chado_query($fsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id))->fetchField();
 
         // iterate through the sub features and concat their sequences. They
         // should already be in order.
@@ -311,6 +313,7 @@ function tripal_get_sequence($feature, $options) {
           // included then continue if this child is not one of those allowed
           // subfeatures
           if (count($sub_features) > 0 and !in_array($child->type_name, $sub_features)) {
+            $i++;
              continue;
           }
 
@@ -325,40 +328,44 @@ function tripal_get_sequence($feature, $options) {
             // -------------------------- ref
             //    ....---->  ---->
             //     up    1       2
-            $q = chado_query($sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
+            $q = chado_query($parent_sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
           }
           elseif ($i == 0 and $parent->strand < 0) { // reverse direction
             // -------------------------- ref
             //    ....<----  <----
             //    down  1       2
-            $q = chado_query($sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
+            $q = chado_query($parent_sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
           }
 
           // Next, if the last sub feature we need to include the downstream bases. first check if
           // the feature is in teh forward direction or the reverse
-          if ($i == $num_children->num_children - 1 and $parent->strand >= 0) {  // forward direction
+          elseif ($i == $num_children - 1 and $parent->strand >= 0) {  // forward direction
             // -------------------------- ref
             //        ---->  ---->....
             //          1       2 down
-            $q = chado_query($sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
+            $q = chado_query($parent_sql, array(':upstream' => 0, ':downstream' => $downstream, ':feature_id' => $child->feature_id));
           }
-          elseif ($i == $num_children->num_children - 1 and $parent->strand < 0) { // reverse direction
+          elseif ($i == $num_children - 1 and $parent->strand < 0) { // reverse direction
             // -------------------------- ref
             //        <----  <----....
             //          1       2  up
-            $q = chado_query($sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
+            $q = chado_query($parent_sql, array(':upstream' => $upstream, ':downstream' => 0, ':feature_id' => $child->feature_id));
           }
-
           // for internal sub features we don't want upstream or downstream bases
           else {
-            $q = chado_query($sql, array(':upstream' => 0, ':downstream' => 0, ':feature_id' => $child->feature_id));
+            $q = chado_query($parent_sql, array(':upstream' => 0, ':downstream' => 0, ':feature_id' => $child->feature_id));
           }
-
           while ($subseq = $q->fetchObject()) {
             // concatenate the sequences of all the sub features
             if ($subseq->srcfeature_id == $parent->srcfeature_id) {
               $seq .= $subseq->residues;
             }
+            if ($subseq->upstream > 0 ) { 
+              $notes .= "Includes " . $subseq->upstream . " bases upstream.  ";
+            }
+            if ($subseq->downstream > 0) {
+              $notes .= "Includes " . $subseq->downstream . " bases downstream.  ";
+            }
           }
           $i++;
         }
@@ -366,50 +373,62 @@ function tripal_get_sequence($feature, $options) {
       // if this isn't an aggregate then use the parent residues
       else {
          $seq = $parent->residues;
+         if ($parent->upstream > 0) {
+           $notes .= "Includes " . $parent->upstream . " bases upstream.  ";
+         }
+         if ($parent->downstream > 0) {
+           $notes .= "Includes " . $parent->downstream . " bases downstream.  ";
+         }
       }
 
       // get the reverse compliment if feature is on the reverse strand
       $dir = 'forward';
-      $notes = '';
+      $length = strlen($seq);
       if ($parent->strand < 0) {
         $seq = tripal_feature_reverse_complement($seq);
         $dir = 'reverse';
       }
       // now format for display
-      if ($output_format == 'fasta_html') {
-         $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
+      if ($is_html) {
+        $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
       }
-      elseif ($output_format == 'fasta_txt') {
-         $seq = wordwrap($seq, $num_bases_per_line, "\r\n", TRUE);
+      else {
+        $seq = wordwrap($seq, $num_bases_per_line, "\r\n", TRUE);
       }
       if (!$seq) {
-        if ($output_format == 'fasta_html') {
-          $notes .= "No sequence available.</br>";
-        }
-        else {
-          $notes .= "No sequence available.\r\n";
-        }
+        $notes .= "No sequence available.";
       }
-      
-      $notes = "Sequence derived from feature of type, '$parent->srctypename', of $parent->genus $parent->species: $parent->srcname:" . ($parent->adjfmin + 1) . ".." . $parent->adjfmax . " ($dir). ";
-      /*
+
       if (count($types) > 0) {
         $notes .= "Excludes all bases but those of type(s): " . implode(', ', $types) . ". " ;
       }
-      if ($parent->upstream > 0) {
-         $notes .= "Includes " . $parent->upstream . " bases upstream.  ";
-      }
-      if ($parent->downstream > 0) {
-         $notes .= "Includes " . $parent->downstream . " bases downstream.  ";
-      }      
-      */
+
+      // construct the definition line for this feature.
+      // to construct the defline we need a featureloc record, so we'll create one using
+      // the information we have
+      $featureloc = new stdClass;
+      $featureloc->feature_id = $feature;
+      $featureloc->fmin = $parent->adjfmin;
+      $featureloc->fmax = $parent->adjfmax;
+      $featureloc->strand = $parent->strand;
+      $featureloc->srcfeature_id = new stdClass;
+      $featureloc->srcfeature_id->name = $parent->srcname;
+      $featureloc->srcfeature_id->type_id = $parent->srctypename;
+      $featureloc->srcfeature_id->organism_id = new stdClass;
+      $featureloc->srcfeature_id->organism_id->genus = $parent->genus;
+      $featureloc->srcfeature_id->organism_id->species = $parent->species;
+      // get a proper feature object
+      $f = chado_generate_var('feature', array('feature_id' => $feature_id));
+      $defline = tripal_get_fasta_defline($f, $notes, $featureloc, '', $length);
+      
       $sequences[] = array(
         'types'         => $types,
         'upstream'      => $parent->upstream,
         'downstream'    => $parent->downstream,
-        'notes'         => $notes,
+        'defline'       => $defline,
         'residues'      => $seq,
         'featureloc_id' => $parent->featureloc_id,
+        'length'        => $length,
       );
     }
   }
@@ -419,19 +438,26 @@ function tripal_get_sequence($feature, $options) {
     $sql = "SELECT * FROM {feature} F WHERE feature_id = :feature_id";
     $values = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();
     $residues = $values->residues;
-    if ($output_format == 'fasta_html') {
-       $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);
+    $length = strlen($residues);
+    if ($is_html) {
+      $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);
     }
-    elseif ($output_format == 'fasta_txt') {
-       $residues = wordwrap($residues, $num_bases_per_line, "\r\n", TRUE);
+    else {
+      $residues = wordwrap($residues, $num_bases_per_line, "\r\n", TRUE);
     }
+    
+    // get the definintion line for this feature
+    $f = chado_generate_var('feature', array('feature_id' => $feature_id));
+    $defline = tripal_get_fasta_defline($f, '', NULL, '', $length);
 
+    // add to the sequence array
     $sequences[] = array(
       'types'      => $values->type,
       'upstream'   => 0,
       'downstream' => 0,
-      'notes'      => '',
+      'defline'    => $defline,
       'residues'   => $residues,
+      'length'     => $length,
     );
   }
 
@@ -439,55 +465,234 @@ function tripal_get_sequence($feature, $options) {
 }
 
 /**
- * Returns a fasta record for the passed in feature
- *
- * @param $feature
- *   A single feature object containing all the fields from the chado.feature table
- * @param $desc
- *   A string containing any additional details you want added to the definition line of
- *   the fasta record.
+ * Retreives or prints multiple sequences from features found using the options provided.
  *
- * Note: the feature accession and name separated by a | will be added
- *   before the description but on the same line
+ * @param $options
+ *   An associative array of options for selecting a feature. Valid keys include:
+ *    - org_commonname: The common name of the organism for which sequences should be retrieved
+ *    - genus: The genus of the organism for which sequences should be retrieved
+ *    - species: The species of the organism for which sequences should be retrieved
+ *    - analysis_name: The name of an analysis to which sequences belong. Only those that are
+ *        associated with the analysis will be retrieved.
+ *    - type: The type of feature (a sequence ontology term).
+ *    - feature_name: the name of the feature. Can be an array of feature names.
+ *    - feature_uname: the uniquename of the feature.  Can be an array of feature unique names.
+ *    - upstream: An integer specifing the number of upstream bases to include in the output
+ *    - downstream: An integer specifying the number of downstream bases to include in the
+ *        output.
+ *    - derive_from_parent: Set to '1' if the sequence should be obtained from the parent
+ *        to which this feature is aligned.
+ *    - aggregate: Set to '1' if the sequence should only contain sub features, excluding
+ *        intro sub feature sequence.  For example, set this option to obtain just
+ *        the coding sequence of an mRNA.
+ *    - sub_feature_types: Only include sub features (or child features) of the types
+ *        provided in the array
+ *    - relationship_type: If a relationship name is provided (e.g. sequence_of) then any
+ *        sequences that are in relationships of this type with matched sequences are also included
+ *    - relationship_part: If a relationship is provided in the preceeding argument then
+ *        the rel_part must be either 'object' or 'subject' to indicate which side of the
+ *        relationship the matched features belong
+ *    - width: Indicate the number of bases to use per line.  A new line will be added
+ *        after the specified number of bases on each line.
+ *    - is_html: Set to '1' if  the sequence is meant to be displayed on a web page.
+ *        This will cause a <br> tag to separate lines of the FASTA sequence. 
+ *    - print: Set to TRUE to print the sequences rather otherwise an array
+ *        of sequences will be returned.  
+ * @return
+ *   Returns an array of sequences unless the option 'print' is used.  If 'print is used
+ *   then nothing is returned but sequences are printed to STDOUT.  If returned, the 
+ *   sequences will be in an array with the following keys for each sequence:
+ *      'types'         => an array of feature types that were used to derive the sequence (e.g. from an aggregated sequence)
+ *      'upstream'      => the number of upstream bases included in the sequence
+ *      'downstream'    => the number of downstream bases included in the sequence
+ *      'defline'       => the definintion line used to create a FASTA sequence
+ *      'residues'      => the residues
+ *      'featureloc_id' => the featureloc_id if the sequences is from an alignment
  *
  * @ingroup tripal_feature_api
  */
-function tripal_format_fasta_sequence($feature, $desc) {
+function tripal_get_bulk_feature_sequences($options) {
+
+  // default values for building the sequence
+  $org_commonname     = array_key_exists('org_commonname', $options)     ? $options['org_commonname']    : '';
+  $genus              = array_key_exists('genus', $options)              ? $options['genus']             : '';
+  $species            = array_key_exists('species', $options)            ? $options['species']           : '';
+  $analysis_name      = array_key_exists('analysis_name', $options)      ? $options['analysis_name']     : '';
+  $type               = array_key_exists('type', $options)               ? $options['type']              : '';
+  $feature_name       = array_key_exists('feature_name', $options)       ? $options['feature_name']      : '';
+  $feature_uname      = array_key_exists('feature_uname', $options)      ? $options['feature_uname']     : '';
+  $derive_from_parent = array_key_exists('derive_from_parent', $options) ? $options['derive_from_parent'] : 0;
+  $aggregate          = array_key_exists('aggregate', $options)          ? $options['aggregate']          : 0;
+  $sub_features       = array_key_exists('sub_feature_types', $options)  ? $options['sub_feature_types']  : array();
+  $relationship       = array_key_exists('relationship_type', $options)  ? $options['relationship_type']  : '';
+  $rel_part           = array_key_exists('relationship_part', $options)  ? $options['relationship_part']  : '';
+  $num_bases_per_line = array_key_exists('width', $options)              ? $options['width']              : 50;
+  $upstream           = array_key_exists('upstream', $options)           ? $options['upstream']       : 0;
+  $downstream         = array_key_exists('downstream', $options)         ? $options['downstream']     : 0;
+  $print              = array_key_exists('print', $options)              ? $options['print']              : FALSE;
+
+  $sub_features = explode(',', $child);
 
-  $fasta  = ">" . variable_get('chado_feature_accession_prefix', 'FID') . "$feature->feature_id|$feature->name";
-  $fasta .= " $desc\n";
-  $fasta .= wordwrap($feature->residues, 50, "\n", TRUE);
-  $fasta .= "\n\n";
+  if (!$output_format) {
+    $output_format = 'fasta_txt';
+  }
 
-  return $fasta;
+  if (!$type and !$feature_name and !$genus) {
+    print "Please provide a type, feature name or genus\n";
+    return;
+  }
 
+  // get the list of features
+  $vars = array();
+  $sql  = "SELECT DISTINCT F.feature_id, F.name, F.uniquename, O.genus, O.species, CVT.name as feature_type " .
+      "FROM {feature} F " .
+      "  INNER JOIN {organism} O on O.organism_id = F.organism_id " .
+      "  INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id ";
+  if ($analysis_name) {
+    $sql .= "  INNER JOIN {analysisfeature} AF on AF.feature_id = F.feature_id " .
+        "  INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id ";
+  }
+  $sql .= "WHERE (1=1) ";
+  if ($org_commonname) {
+    $sql .= "AND O.common_name = :common_name ";
+    $vars[':common_name'] = $org_commonname;
+  }
+  if ($genus) {
+    $sql .= "AND O.genus = :genus ";
+    $vars[':genus'] = $genus;
+  }
+  if ($species) {
+    $sql .= "AND O.species = :species ";
+    $vars[':species'] = $species;
+  }
+  if ($type) {
+    $sql .= "AND CVT.name = :cvtname ";
+    $vars[':cvtname'] = $type;
+  }
+  if ($feature_name) {
+    if (is_array($feature_name)) {
+      $sql .= "AND F.name IN (";
+      foreach ($feature_name as $i => $fname) {
+        $sql .= ":fname$i, ";
+        $vars[":fname$i"] = $fname;
+      }
+      // remove the trailing comma and close the paren
+      $sql = substr($sql, 0, -2) . ")";
+    }
+    else {
+      $sql .= "AND F.name = :fname";
+      $vars[':fname'] = $feature_name;
+    }
+  }
+  if ($feature_uname) {
+    if (is_array($feature_uname)) {
+      $sql .= "AND F.uniquename IN (";
+      foreach ($feature_uname as $i => $funame) {
+        $sql .= ":funame$i, ";
+        $vars[":funame$i"] = $funame;
+      }
+      // remove the trailing comma and close the paren
+      $sql = substr($sql, 0, -2) . ")";
+    }
+    else {
+      $sql .= "AND F.uniquename = :funame";
+      $vars[':funame'] = $feature_uname;
+    }
+  }
+  if ($analysis_name) {
+    $sql .= "AND A.name = :aname";
+    $vars[':aname'] = $analysis_name;
+  }
+  $num_bases_per_line = 50;
+  $num_seqs = 0;
+  $q = chado_query($sql, $vars);
+
+
+  $sequences = array();
+  while ($feature = $q->fetchObject()) {
+
+    // get the sequences
+    $seqs = tripal_get_feature_sequences(array('feature_id' => $feature->feature_id), $options);
+
+    if ($print) {
+      foreach ($seqs as $seq) {
+        print ">" . $seq['defline'] . "\n";
+        print $seq['residues'] . "\n";
+      }
+    }
+    else {
+      $sequences = array_merge($sequences, $seqs);
+    }
+    $num_seqs++;
+  }
+  if (!$print) {
+    return $seqs;
+  }
+  elseif ($num_seqs == 0) {
+    print "No Sequences Found";
+  }
 }
 
 /**
  * Returns a definition line that can be used in a FASTA file
  * 
  * @param $feature
- *   A single feature object containing all the fields from the chado.feature table
+ *   A single feature object containing all the fields from the chado.feature table.
+ *   Best case is to provide an object generated by the chado_generate_var() function.
+ * @param $notes
+ *   Optional: additional notes to be added to the definition line
  * @param $featureloc
- *   Optional: A single featureloc object generated using chado_generate_var that
- *   contains a record from the chado.featureloc table.
+ *   Optional: a single featureloc object generated using chado_generate_var that
+ *   contains a record from the chado.featureloc table. Provide this if the
+ *   sequence was obtained by using the alignment rather than from the feature.residues
+ *   column
  * @param $type
  *   Optional: the type of sequence. By default the feature type is used.
+ * @param $length
+ *   Optional: the length of the sequence
  *   
  * @return
  *   A string of the format: uniquename|name|type|feature_id
  *   or if an alignment:  srcfeature_name:fmin..fmax[+-]; alignment of uniquename|name|type|feature_id 
  */
-function tripal_get_fasta_defline($feature, $featureloc = NULL, $type = '') {
+function tripal_get_fasta_defline($feature, $notes = '', $featureloc = NULL, $type = '', $length = 0) {
+    
+  // make sure the featureloc object has the srcfeature if not, then add it
+  if ($featureloc) {
+    if (!is_object($featureloc->srcfeature_id)) {
+      $featureloc->srcfeature_id = chado_generate_var('feature', array('feature_id' => $featureloc->srcfeature_id));
+    }
+    if (!is_object($featureloc->srcfeature_id->organism_id)) {
+      $featureloc->srcfeature_id->organism_id = chado_generate_var('organism', array('organism_id' => $featureloc->srcfeature_id->organism_id));
+    }
+  }
+  // make sure the feature object has the organism if not, then add it
+  if (!is_object($feature->organism_id)) {
+    $feature->organism_id = chado_generate_var('organism', array('organism_id' => $feature->organism_id));
+  }
   
+  // if a type is not provided then use the default type
   if (!$type) {
     $type = $feature->type_id->name;
   }
-  $defline = $feature->uniquename . "|" . $feature->name . "|" . $type . "|" . $feature->feature_id; 
+  
+  // construct the definition line
+  $defline = $feature->uniquename . " " . 
+             'ID=' . $feature->uniquename . "|" .
+             'Name=' . $feature->name . "|" . 
+             'organism=' . $feature->organism_id->genus . " " . $feature->organism_id->species .  "|" .
+             'type=' . $type . '|'; 
+  if ($length > 0) {
+    $defline .= "length=" . $length . "bp|";
+  }
   if ($featureloc) {
-    $defline = $defline . "; derived from alignment at " .tripal_get_location_string($featureloc);
+    $defline .= "location=Sequence derived from alignment at " . tripal_get_location_string($featureloc);
+    $defline .= " (" . $featureloc->srcfeature_id->organism_id->genus . " " . $featureloc->srcfeature_id->organism_id->species . ")|";
   }
-  
+  if ($notes) {
+    $defline .= "Notes=$notes|";
+  }
+  $defline = substr($defline, 0, -1); // remove the trailing |
   return $defline;
 }
 
@@ -504,7 +709,7 @@ function tripal_get_location_string($featureloc) {
   if ($featureloc->strand < 0) {
     $residues = tripal_feature_reverse_complement($residues);
   }
-  $strand = '.';
+  $strand = '';
   if ($featureloc->strand == 1) {
     $strand = '+';
   }
@@ -513,4 +718,5 @@ function tripal_get_location_string($featureloc) {
   }
   
   return $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax .  $strand;  
-}
+}
+

+ 1 - 1
tripal_feature/includes/tripal_feature.admin.inc

@@ -96,7 +96,7 @@ function tripal_feature_admin() {
       'simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering '.
       'future data that may be added.  If you include the Chado table name, genus, species, type '.
       'and uniquename you are guaranteed to have a unique URL. For example feature/[genus]/[species]/[type]/[uniquename]'),
-    '#size' => 150,
+    '#size' => 75,
     '#default_value' => variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]'),
   );
 

+ 15 - 0
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -774,6 +774,13 @@ function tripal_feature_node_insert($node) {
   switch ($node->type) {
     case 'chado_feature':
 
+      $feature_id = chado_get_id_from_nid('feature', $node->nid);
+      
+      // build the feature variable
+      $values = array('feature_id' => $feature_id);
+      $feature = chado_generate_var('feature', $values);
+      $node->feature = $feature;
+      
       // on an insert we need to add the feature_id to the node object
       // so that the tripal_feature_get_feature_url function can set the URL properly
       $node->feature_id = chado_get_id_from_nid('feature', $node->nid);
@@ -804,6 +811,14 @@ function tripal_feature_node_update($node) {
   // add items to other nodes, build index and search results
   switch ($node->type) {
     case 'chado_feature':
+      
+      $feature_id = chado_get_id_from_nid('feature', $node->nid);
+      
+      // build the feature variable
+      $values = array('feature_id' => $feature_id);
+      $feature = chado_generate_var('feature', $values);
+      $node->feature = $feature;
+      
       // remove any previous alias
       db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
 

+ 48 - 64
tripal_feature/includes/tripal_feature.fasta_loader.inc

@@ -442,6 +442,10 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
   $re_subject, $parent_type, $method, $uid, $analysis_id,
   $match_type, $job = NULL) {
 
+  // open the temporary loading file
+  $tmp_file = tempnam(sys_get_temp_dir(), 'tripal_fasta_');
+  $fh = fopen($tmp_file, 'wb');
+    
   $transaction = db_transaction();
   print "\nNOTE: Loading of this GFF file is performed using a database transaction. \n" .
        "If the load fails or is terminated prematurely then the entire set of \n" .
@@ -449,11 +453,13 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
   try {
 
     // first get the type for this sequence
-    $cvtermsql = "SELECT CVT.cvterm_id
-                 FROM {cvterm} CVT
-                    INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
-                    LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
-                 WHERE cv.name = :cvname and (CVT.name = :name or CVTS.synonym = :synonym)";
+    $cvtermsql = "
+      SELECT CVT.cvterm_id
+      FROM {cvterm} CVT
+        INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+        LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
+      WHERE cv.name = :cvname and (CVT.name = :name or CVTS.synonym = :synonym)
+    ";
     $cvterm = chado_query($cvtermsql, array(':cvname' => 'sequence', ':name' => $type, ':synonym' => $type))->fetchObject();
     if (!$cvterm) {
       tripal_report_error("T_fasta_loader", TRIPAL_ERROR, "Cannot find the term type: '%type'", array('%type' => $type));
@@ -511,7 +517,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
         // if we have a feature name then we are starting a new sequence
         // so lets handle the previous one before moving on
         if ($name or $uname) {
-          tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id,
+          tripal_feature_fasta_loader_handle_feature($fh, $name, $uname, $db_id,
             $accession, $subject, $rel_type, $parent_type, $analysis_id, $organism_id, $cvterm,
             $source, $residues, $method, $re_name, $match_type, $parentcvterm, $relcvterm);
           $residues = '';
@@ -602,7 +608,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
     }
   
     // now load the last sequence in the file
-    tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id,
+    tripal_feature_fasta_loader_handle_feature($fh, $name, $uname, $db_id,
       $accession, $subject, $rel_type, $parent_type, $analysis_id, $organism_id, $cvterm,
       $source, $residues, $method, $re_name, $match_type, $parentcvterm, $relcvterm);
   }
@@ -612,15 +618,19 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
     watchdog_exception('T_fasta_loader', $e);
     print "FAILED: Rolling back database changes...\n";
   }
-  
+  close($fh);
   print "\nDone\n";
 }
 
 /**
  * A helper function for tripal_feature_load_fasta() to load a single feature
  *
+ * @param $fh
+ *   The file handle where the temporary loading file is stored
  * @param $name
+ *   The name of the feature to insert/update
  * @param $uname
+ *   The uniquename of the feature to insert/udpate
  * @param $db_id
  * @param $accession
  * @param $parent
@@ -639,9 +649,9 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
  *
  * @ingroup fasta_loader
  */
-function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $accession,
+function tripal_feature_fasta_loader_handle_feature($fh, $name, $uname, $db_id, $accession,
   $parent, $rel_type, $parent_type, $analysis_id, $organism_id, $cvterm,
-  $source, $residues, $method, $re_name, $match_type, $parentcvterm, $relcvterm) {
+  $source, &$residues, $method, $re_name, $match_type, $parentcvterm, $relcvterm) {
 
   // check to see if this feature already exists if the match_type is 'Name'
   if (strcmp($match_type, 'Name')==0) {
@@ -650,8 +660,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'name' => $name,
       'type_id' => $cvterm->cvterm_id,
     );
-    $options = array('statement_name' => 'sel_feature_ornaty');
-    $results = chado_select_record('feature', array('feature_id'), $values, $options);
+    $results = chado_select_record('feature', array('feature_id'), $values);
     if (count($results) > 1) {
       tripal_report_error('T_fasta_loader', "Multiple features exist with the name '%name' of type
                '%type' for the organism.  skipping", array('%name' => $name, '%type' => $type));
@@ -669,8 +678,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'type_id' => $cvterm->cvterm_id,
     );
 
-    $options = array('statement_name' => 'sel_feature_oruqty');
-    $results = chado_select_record('feature', array('feature_id'), $values, $options);
+    $results = chado_select_record('feature', array('feature_id'), $values);
     if (count($results) > 1) {
       tripal_report_error('T_fasta_loader', "Multiple features exist with the name '%name' of type
                '%type' for the organism.  skipping", array('%name' => $name, '%type' => $type));
@@ -691,6 +699,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
   // if we don't have a feature and we're doing an insert then do the insert
   $inserted = 0;
   if (!$feature and (strcmp($method, 'Insert only')==0 or strcmp($method, 'Insert and update')==0)) {
+    print "!feature && (Insert only || Insert and update)\n\n";
     // if we have a unique name but not a name then set them to be the same and vice versa
     if (!$uname) {
       $uname = $name;
@@ -704,15 +713,12 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'organism_id' => $organism_id,
       'name' => $name,
       'uniquename' => $uname,
-      'residues' => $residues,
+      'residues' => &$residues,
       'seqlen' => drupal_strlen($residues),
       'md5checksum' => md5($residues),
       'type_id' => $cvterm->cvterm_id,
-      'is_analysis' => 'FALSE',
-      'is_obsolete' => 'FALSE',
     );
-    $options = array('statement_name' => 'ins_feature_all');
-    $success = chado_insert_record('feature', $values, $options);
+    $success = chado_insert_record('feature', $values);
     if (!$success) {
       tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to insert feature '%name (%uname)'",
         array('%name' => $name, '%uname' => $numane));
@@ -725,8 +731,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'uniquename' => $uname,
       'type_id' => $cvterm->cvterm_id,
     );
-    $options = array('statement_name' => 'sel_feature_oruqty');
-    $results = chado_select_record('feature', array('feature_id'), $values, $options);
+    $results = chado_select_record('feature', array('feature_id'), $values);
     if (count($results) == 1) {
        $inserted = 1;
        $feature = $results[0];
@@ -747,6 +752,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
 
   // if we do have a feature and this is an update then proceed with the update
   if ($feature and !$inserted and (strcmp($method, 'Update only')==0 or strcmp($method, 'Insert and update')==0)) {
+    print "feature && !inserted and (Update only || Insert and update)\n\n";
     // if the user wants to match on the Name field
     if (strcmp($match_type, 'Name')==0) {
       // if we're matching on the name but do not have a unique name then we don't want to update the uniquename.
@@ -759,8 +765,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
           'uniquename' => $uname,
           'type_id' => $cvterm->cvterm_id,
         );
-        $options = array('statement_name' => 'sel_feature_oruqty');
-        $results = chado_select_record('feature', array('feature_id'), $values, $options);
+        $results = chado_select_record('feature', array('feature_id'), $values);
         if (count($results) > 0) {
           tripal_report_error('T_fasta_loader', "Cannot update the feature '%name' with a uniquename of '%uname' and type of '%type' as it
             conflicts with an existing feature with the same uniquename and type.",
@@ -771,38 +776,32 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
         // the changes to the uniquename don't conflict so proceed with the update
         $values = array(
           'uniquename' => $uname,
-          'residues' => $residues,
+          'residues' => &$residues,
           'seqlen' => drupal_strlen($residues),
           'md5checksum' => md5($residues),
-          'is_analysis' => 'false',
-          'is_obsolete' => 'false',
         );
         $match = array(
           'name' => $name,
           'organism_id' => $organism_id,
           'type_id' => $cvterm->cvterm_id,
         );
-        $options = array('statement_name' => 'upd_feature_resemdisis_naorty_un');
       }
       // if we do not have a new unique name then don't change the existing uniquename field
       else {
         $values = array(
-          'residues' => $residues,
+          'residues' => &$residues,
           'seqlen' => drupal_strlen($residues),
           'md5checksum' => md5($residues),
-          'is_analysis' => 'false',
-          'is_obsolete' => 'false',
         );
         $match = array(
           'name' => $name,
           'organism_id' => $organism_id,
           'type_id' => $cvterm->cvterm_id,
         );
-        $options = array('statement_name' => 'upd_feature_unresemdisis_naorty');
       }
 
       // perform the update
-      $success = chado_update_record('feature', $match, $values, $options);
+      $success = chado_update_record('feature', $match, $values);
       if (!$success) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR,
           "Failed to update feature '%name' ('%name')",
@@ -816,36 +815,30 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       if ($name) {
         $values = array(
           'name' => $name,
-          'residues' => $residues,
-          'seqlen' => drupal_strlen($residues),
-          'md5checksum' => md5($residues),
-          'is_analysis' => 'false',
-          'is_obsolete' => 'false',
+           'residues' => &$residues,
+           'seqlen' => drupal_strlen($residues),
+           'md5checksum' => md5($residues),
         );
         $match = array(
           'uniquename' => $uname,
           'organism_id' => $organism_id,
           'type_id' => $cvterm->cvterm_id,
         );
-        $options = array('statement_name' => 'upd_feature_resemdisis_unorty_na');
       }
       // if we have a unique name then update it after matching by the name
       else {
         $values = array(
-          'residues' => $residues,
-          'seqlen' => drupal_strlen($residues),
-          'md5checksum' => md5($residues),
-          'is_analysis' => 'false',
-          'is_obsolete' => 'false',
+           'residues' => &$residues,
+           'seqlen' => drupal_strlen($residues),
+           'md5checksum' => md5($residues),
         );
         $match = array(
           'uniquename' => $uname,
           'organism_id' => $organism_id,
           'type_id' => $cvterm->cvterm_id,
         );
-        $options = array('statement_name' => 'upd_feature_naresemdisis_unorty');
       }
-      $success = chado_update_record('feature', $match, $values, $options);
+      $success = chado_update_record('feature', $match, $values);
       if (!$success) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to update feature '%name' ('%name')",
           array('%name' => $name, '%uiname' => $uname));
@@ -861,11 +854,9 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'analysis_id' => $analysis_id,
       'feature_id' => $feature->feature_id,
     );
-    $sel_options = array('statement_name' => 'sel_analysisfeature_anfe');
-    $results = chado_select_record('analysisfeature', array('analysisfeature_id'), $values, $sel_options);
+    $results = chado_select_record('analysisfeature', array('analysisfeature_id'), $values);
     if (count($results) == 0) {
-      $ins_options = array('statement_name' => 'ins_analysisfeature_anfe');
-      $success = chado_insert_record('analysisfeature', $values, $ins_options);
+      $success = chado_insert_record('analysisfeature', $values);
       if (!$success) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to associate analysis and feature '%name' ('%name')",
           array('%name' => $name, '%uname' => $uname));
@@ -881,18 +872,16 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'db_id' => $db_id,
       'accession' => $accession
     );
-    $sel_options = array('statement_name' => 'sel_dbxref_dbac');
-    $results = chado_select_record('dbxref', array('dbxref_id'), $values, $sel_options);
+    $results = chado_select_record('dbxref', array('dbxref_id'), $values);
     // if the accession doesn't exist then add it
     if (count($results) == 0) {
-      $ins_options = array('statement_name' => 'ins_dbxref_dbac');
-      $results = chado_insert_record('dbxref', $values, $ins_options);
+      $results = chado_insert_record('dbxref', $values);
       if (!$results) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to add database accession '%accession'",
           array('%accession' => $accession));
         return 0;
       }
-      $results = chado_select_record('dbxref', array('dbxref_id'), $values, $sel_options);
+      $results = chado_select_record('dbxref', array('dbxref_id'), $values);
       if (count($results) == 1) {
         $dbxref = $results[0];
       }
@@ -911,11 +900,9 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'feature_id' => $feature->feature_id,
       'dbxref_id' => $dbxref->dbxref_id
     );
-    $sel_options = array('statement_name' => 'sel_featuredbxref_fedb');
-    $results = chado_select_record('feature_dbxref', array('feature_dbxref_id'), $values, $sel_options);
+    $results = chado_select_record('feature_dbxref', array('feature_dbxref_id'), $values);
     if (count($results) == 0) {
-      $ins_options = array('statement_name' => 'ins_featuredbxref_fedb');
-      $success = chado_insert_record('feature_dbxref', $values, $ins_options);
+      $success = chado_insert_record('feature_dbxref', $values);
       if (!$success) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to add associate database accession '%accession' with feature",
           array('%accession' => $accession));
@@ -931,8 +918,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'uniquename' => $parent,
       'type_id' => $parentcvterm->cvterm_id,
     );
-    $options = array('statement_name' => 'sel_feature_oruqty');
-    $results = chado_select_record('feature', array('feature_id'), $values, $options);
+    $results = chado_select_record('feature', array('feature_id'), $values);
     if (count($results) != 1) {
       tripal_report_error('T_fasta_loader', "Cannot find a unique fature for the parent '%parent' of type
                '%type' for the feature.", array('%parent' => $parent, '%type' => $parent_type));
@@ -946,11 +932,9 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'object_id' => $parent_feature->feature_id,
       'type_id' => $relcvterm->cvterm_id,
     );
-    $sel_options = array('statement_name' => 'sel_featurerelationship_suojty');
-    $results = chado_select_record('feature_relationship', array('feature_relationship_id'), $values, $sel_options);
+    $results = chado_select_record('feature_relationship', array('feature_relationship_id'), $values);
     if (count($results) == 0) {
-      $ins_options = array('statement_name' => 'ins_featurerelationship_suojty');
-      $success = chado_insert_record('feature_relationship', $values, $ins_options);
+      $success = chado_insert_record('feature_relationship', $values);
       if (!$success) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to add associate database accession '%accession' with feature",
           array('%accession' => $accession));

+ 30 - 6
tripal_feature/includes/tripal_feature.gff_loader.inc

@@ -974,17 +974,41 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
  */
 function tripal_feature_load_gff3_derives_from($feature, $subject, $organism) {
 
-  // get the subject type
+  // get the subject. If the subject is not in the tripal_gff_temp table
+  // then look for the subject in the feature table using the unique name.
+  // if it is not unique then we can provide an error
   $values = array(
     'organism_id' => $organism->organism_id,
     'uniquename' => $subject,
   );
-  $result = chado_select_record('tripal_gff_temp', array('type_name'), $values);
-  if (count($result) == 0) {
-    tripal_report_error("T_gff3_loader", TRIPAL_WARNING, "Cannot find subject type for feature in 'derives_from' relationship: %subject", array('%subject' => $subject));
-     return '';
+  $result = tripal_core_chado_select('tripal_gff_temp', array('type_name'), $values);
+  $type_id = array();
+  if (count($result) > 0) {
+    $type_id = array(
+      'name' => $result[0]->type_name,
+      'cv_id' => array(
+        'name' => 'sequence'
+      ),
+    );
+  }
+  
+  // if we don't have a subject type then look for the feature in the feature table
+  if (empty($type_id)) {
+    $result = tripal_core_chado_select('feature', array('type_id'), $values);
+    if (count($result) > 1) {
+      watchdog("T_gff3_loader", "Cannot find subject type for feature,'%subject' , in 'derives_from' relationship. Multiple matching features exist with this uniquename.", 
+        array('%subject' => $subject), WATCHDOG_WARNING);
+      return '';
+    }
+    else if (count($result) == 0) {
+      watchdog("T_gff3_loader", "Cannot find subject type for feature,'%subject' , in 'derives_from' relationship.",
+        array('%subject' => $subject), WATCHDOG_WARNING);
+      return '';
+    }
+    else {
+      $type_id = $result->type_id;
+    }
   }
-  $subject_type = $result[0]->type_name;
 
   // get the subject feature
   $match = array(

+ 15 - 100
tripal_feature/includes/tripal_feature.seq_extract.inc

@@ -34,9 +34,20 @@ function tripal_feature_seq_extract_page() {
       drupal_add_http_header('Content-Disposition: attachment; filename="sequences.fasta.txt"');
     }
 
-    tripal_feature_seq_extract_get_features(NULL, $genus, $species, $analysis,
-      $ftype, $fnames['items_array'], $upstream, $downstream, $format, $use_parent, $aggregate,
-      $agg_types);
+    tripal_get_bulk_feature_sequences(array(
+      'genus' => $genus, 
+      'species' => $species, 
+      'analysis_name' => $analysis,
+      'type' => $ftype, 
+      'feature_name' => $fnames['items_array'], 
+      'upstream' => $upstream, 
+      'downstream' => $downstream, 
+      'print' => 1,
+      'output_format' => $format, 
+      'derive_from_parent' => $use_parent, 
+      'aggregate' => $aggregate,
+      'sub_feature_types' => $agg_types
+    ));
 
     return;
   }
@@ -62,7 +73,7 @@ function tripal_feature_seq_extract_page() {
  *
  * @ingroup tripal_feature
  */
-function theme_tripal_feature_seq_extract_form($form) {
+function theme_tripal_feature_seq_extract_form($form, &$form_state) {
   $rows = array(
     0 => array(
       array('data' => drupal_render($form['description']), 'colspan' => 3),
@@ -462,99 +473,3 @@ function tripal_feature_seq_extract_form_submit($form, &$form_state) {
     unset($_SESSION['tripal_feature_seq_extract']);
   }
 }
-
-/**
- * Actually extract the sequences
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_seq_extract_get_features($org_commonname, $genus, $species, $analysis_name,
-  $type, $feature_name, $upstream, $downstream, $output_format, $derive_from_parent, $aggregate,
-  $child, $relationship, $rel_part) {
-
-  $sub_features = explode(',', $child);
-
-  if (!$output_format) {
-    $output_format = 'fasta_txt';
-  }
-
-  if (!$type and !$feature_name and !$genus) {
-    print "Please provide a type, feature name or genus\n";
-     return;
-  }
-
-  // get the list of features
-  $vars = array();
-  $sql  = "SELECT DISTINCT F.feature_id, F.name, F.uniquename, O.genus, O.species, CVT.name as feature_type " .
-          "FROM {feature} F " .
-          "  INNER JOIN {organism} O on O.organism_id = F.organism_id " .
-          "  INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id ";
-  if ($analysis_name) {
-     $sql .= "  INNER JOIN {analysisfeature} AF on AF.feature_id = F.feature_id " .
-             "  INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id ";
-  }
-  $sql .= "WHERE (1=1) ";
-  if ($org_commonname) {
-    $sql .= "AND O.common_name = :common_name ";
-    $vars[':common_name'] = $org_commonname;
-  }
-  if ($genus) {
-    $sql .= "AND O.genus = :genus ";
-    $vars[':genus'] = $genus;
-  }
-  if ($species) {
-    $sql .= "AND O.species = :species ";
-    $vars[':species'] = $species;
-  }
-  if ($type) {
-    $sql .= "AND CVT.name = ':cvtname ";
-    $vars[':cvtname'] = $type;
-  }
-  if ($feature_name) {
-    if (is_array($feature_name)) {
-      $sql .= "AND F.name IN (";
-      foreach ($feature_name as $i => $fname) {
-        $sql .= ":fname$i, ";
-        $vars[":fname$i"] = $fname;
-      }
-      // remove the trailing comma and close the paren
-      $sql = substr($sql, 0, -2) . ")";
-    }
-    else {
-      $sql .= "AND F.name = :fname";
-      $vars[':fname'] = $feature_name;
-    }
-  }
-  if ($analysis_name) {
-    $sql .= "AND A.name = :aname";
-    $vars[':aname'] = $analysis_name;
-  }
-  $num_bases_per_line = 50;
-  $num_seqs = 0;
-  $q = chado_query($sql, $vars);
-
-  while ($feature = $q->fetchObject()) {
-
-    $feature_id = $feature->feature_id;
-
-    // build the header for each FASTA entry
-    if ($feature->uniquename == $feature->name) {
-      $feature_name = "$feature->uniquename $feature->feature_type ($feature->genus $feature->species)";
-    }
-    else {
-      $feature_name = "$feature->uniquename $feature->name $feature->feature_type ($feature->genus $feature->species)";
-    }
-
-    // generate the sequence
-    $sequence = tripal_feature_get_formatted_sequence($feature_id, $feature_name,
-      $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
-      $upstream, $downstream, $sub_features, $relationship, $rel_part);
-
-    // print the sequence
-    print $sequence;
-    $num_seqs++;
-  }
-  if ($num_seqs == 0) {
-    print "No Sequences Found";
-  }
-}

+ 28 - 16
tripal_feature/theme/templates/tripal_feature_sequence.tpl.php

@@ -9,9 +9,11 @@
  *
  */
 
-
 $feature = $variables['node']->feature;
 
+// number of bases per line in FASTA format
+$num_bases = 50; 
+
 // we don't want to get the sequence for traditionally large types. They are
 // too big,  bog down the web browser, take longer to load and it's not
 // reasonable to print them on a page.
@@ -43,8 +45,8 @@ if ($residues or count($featureloc_sequences) > 0) {
     $sequences_html .= '<div id="residues" class="tripal_feature-sequence-item">';
     $sequences_html .= '<p><b>' . $feature->type_id->name . ' sequence</b></p>';
     $sequences_html .= '<pre class="tripal_feature-sequence">';
-    $sequences_html .= '>' . tripal_get_fasta_defline($feature) . "\n";
-    $sequences_html .= preg_replace("/(.{50})/","\\1<br>",$feature->residues);
+    $sequences_html .= '>' . tripal_get_fasta_defline($feature, '', NULL, '', strlen($feature->residues)) . "\n";
+    $sequences_html .= wordwrap($feature->residues, $num_bases, "<br>", TRUE);
     $sequences_html .= '</pre>';
     $sequences_html .= '<a href="#sequences-top">back to top</a>';
     $sequences_html .= '</div>';
@@ -74,8 +76,8 @@ if ($residues or count($featureloc_sequences) > 0) {
             $sequences_html .= '<div id="protein-' . $protein->feature_id . '" class="tripal_feature-sequence-item">';
             $sequences_html .= '<p><b>protein sequence of ' . $protein->name . '</b></p>';
             $sequences_html .= '<pre class="tripal_feature-sequence">';
-            $sequences_html .= '>' . tripal_get_fasta_defline($protein) . "\n";
-            $sequences_html .= preg_replace("/(.{50})/","\\1<br>", $protein->residues);
+            $sequences_html .= '>' . tripal_get_fasta_defline($protein, '', NULL, '', strlen($protein->residues)) . "\n";
+            $sequences_html .= wordwrap($protein->residues, $num_bases, "<br>", TRUE);
             $sequences_html .= '</pre>';
             $sequences_html .= '<a href="#sequences-top">back to top</a>';
             $sequences_html .= '</div>';
@@ -95,6 +97,7 @@ if ($residues or count($featureloc_sequences) > 0) {
         
         // add any other sequences that are related through a relationship
         // and that have values in the 'residues' column
+        
       }
     }
   }
@@ -107,7 +110,7 @@ if ($residues or count($featureloc_sequences) > 0) {
     $sequences_html .= '<div id="coding_sequence" class="tripal_feature-sequence-item">';
     $sequences_html .= '<p><b>coding sequence</b></p>';
     $sequences_html .= '<pre class="tripal_feature-sequence">';
-    $sequences_html .= $coding_seq;
+    $sequences_html .= wordwrap($coding_seq, $num_bases, "<br>", TRUE);
     $sequences_html .= '</pre>';
     $sequences_html .= '<a href="#sequences-top">back to top</a>';
     $sequences_html .= '</div>';
@@ -147,7 +150,7 @@ if ($residues or count($featureloc_sequences) > 0) {
     }
     
     // check to see if this alignment has any CDS. If so, generate a CDS sequence
-    $cds_sequence = tripal_get_sequence(
+    $cds_sequence = tripal_get_feature_sequences(
         array(
           'feature_id' => $feature->feature_id,
           'parent_id' => $attrs['featureloc']->srcfeature_id->feature_id,
@@ -155,22 +158,25 @@ if ($residues or count($featureloc_sequences) > 0) {
           'featureloc_id' => $attrs['featureloc']->featureloc_id,
         ),
         array(
-          'width' => 50,  // FASTA sequence should have 50 chars per line
+          'width' => $num_bases,  // FASTA sequence should have $num_bases chars per line
           'derive_from_parent' => 1, // CDS are in parent-child relationships so we want to use the sequence from the parent
           'aggregate' => 1, // we want to combine all CDS for this feature into a single sequence
-          'output_format' => 'fasta_txt', // we just want plain text, we'll format it here.
           'sub_feature_types' => array('CDS'), // we're looking for CDS features
-          ''
+          'is_html' => 1
         )
     );
     if (count($cds_sequence) > 0) {
+      // the tripal_get_feature_sequences() function can return multiple sequences
+      // if a feature is aligned to multiple places. In the case of CDSs we expect
+      // that one mRNA is only aligned to a single location on the assembly so we
+      // can access the CDS sequence with index 0.
       if ($cds_sequence[0]['residues']) {
         $list_items[] = '<a href="#coding_' . $attrs['id'] . '">coding sequnece from alignment at  ' . $attrs['location'] . "</a>";
         $sequences_html .= '<a name="ccoding_' . $attrs['id'] . '"></a>';
         $sequences_html .= '<div id="coding_' . $attrs['id'] . '" class="tripal_feature-sequence-item">';
         $sequences_html .= '<p><b>Coding sequence (CDS) from alignment at  ' . $attrs['location'] . '</b></p>';
         $sequences_html .= '<pre class="tripal_feature-sequence">';
-        $sequences_html .= '>' . tripal_get_fasta_defline($feature, $attrs['featureloc'], 'CDS') . "\n";
+        $sequences_html .= '>' . tripal_get_fasta_defline($feature, '', $attrs['featureloc'], 'CDS', $cds_sequence[0]['length']) . "<br>";
         $sequences_html .= $cds_sequence[0]['residues'];
         $sequences_html .= '</pre>';
         $sequences_html .= '<a href="#sequences-top">back to top</a>';
@@ -197,15 +203,21 @@ if ($residues or count($featureloc_sequences) > 0) {
   ));
 
   $message = 'Administrators, sequences will appear on this page if:
+    <br><br><b>For any feature type:</b>
     <ul>
       <li>This feature has residues stored in the "residues" field of the feature table of Chado.</li>
-      <li>This feature has a protein feature associated via the "feature_relationship" table of Chado with a
-          relationship of type "derives from" and the protein feature has residues.</li>
-      <li>This feature has one or more CDS features associated via the "feature_relationship" table of Chado with a
-          relationship of type "part of". If the CDS features have residues then those will be concatenated
-          and presented as a sequence.</li>
       <li>This feature is aligned to another feature (e.g. scaffold, or chromosome). In this case, the
           sequence underlying the alignment will be shown.</li>
+    </ul>
+    <br><b>For gene models:</b>
+    <ul>
+      <li>This feature has a "polypeptide" (protein) feature associated via the "feature_relationship" table of Chado with a
+          relationship of type "derives from" and the protein feature has residues. Typically, a protein
+          is associated with an mRNA feature and protein sequences will appear on the mRNA page.</li>
+      <li>This feature has one or more CDS features associated via the "feature_relationship" table of Chado with a
+          relationship of type "part of". If the CDS features have residues then those will be concatenated
+          and presented as a sequence. Typically, CDSs are associated with an mRNA feature and CDS sequences 
+          will appear on the mRNA page.</li>
       <li>This feature is aligned to another feature (e.g. scaffold, or chromosome) and this feature has
           one or more CDS features associated.  The CDS sequenes underlying the alignment will be
           shown.</li>

+ 0 - 1
tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php

@@ -136,7 +136,6 @@ else {  ?>
     You can specify the feature types
     that should appear in this browser or remove it from the list of resources by navigating to the " . 
     l("Tripal feature settings page", "admin/tripal/chado/tripal_feature/configuration", array('attributes' => array('target' => '_blank')))  . "
-    </p>
     The feature browser will not appear to site visitors unless features are present. ",
     TRIPAL_INFO,
     array('return_html' => 1));

+ 14 - 12
tripal_feature/theme/tripal_feature.theme.inc

@@ -168,7 +168,7 @@ function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
         $strand = '-';
       }
       $floc_sequences[$src]['location'] = tripal_get_location_string($featureloc);
-      $floc_sequences[$src]['defline'] = tripal_get_fasta_defline($featureloc->feature_id, $featureloc);
+      $floc_sequences[$src]['defline'] = tripal_get_fasta_defline($featureloc->feature_id, '', $featureloc, '', strlen($residues));
       $floc_sequences[$src]['featureloc'] = $featureloc;
       $floc_sequences[$src]['formatted_seq'] =  tripal_feature_color_sequence($residues, $parts, $floc_sequences[$src]['defline']);
     }
@@ -389,7 +389,7 @@ function tripal_feature_color_sequence($sequence, $parts, $defline) {
   // set the background color of the rows based on the type
   $pos = 0;
   $newseq .= "<pre class=\"tripal_feature-sequence\">";
-  $newseq .= ">$defline\n";
+  $newseq .= ">$defline<br>";
 
   // iterate through the parts. They should be in order.
   $starts   = array(); // an array holding all of the children starting locations
@@ -737,23 +737,25 @@ function tripal_feature_load_organism_feature_counts($organism) {
   // iterate through the types
   $types = array();
   while ($type = $org_features->fetchObject()) {
-  $types[$type->feature_type] = $type;
-  // if we don't have an order this means we didn't go through the loop
-  // above to set the names, so do that now
-  if (!$is_custom) {
-  $names[] = $type->feature_type;
-  $order[] = $type->feature_type;
-  }
+    $types[$type->feature_type] = $type;
+    // if we don't have an order this means we didn't go through the loop
+    // above to set the names, so do that now
+    if (!$is_custom) {
+      $names[] = $type->feature_type;
+      $order[] = $type->feature_type;
+    }
   }
 
   // now reorder the types
   $ordered_types = array();
   foreach ($order as $type) {
-  $ordered_types[] = $types[$type];
+    if (array_key_exists($type, $types)) {
+      $ordered_types[] = $types[$type];
+    }
   }
   return array(
-  'types' => $ordered_types,
-      'names' => $names
+    'types' => $ordered_types,
+    'names' => $names
   );
 }
 

+ 34 - 18
tripal_feature/tripal_feature.drush.inc

@@ -40,12 +40,12 @@ function tripal_feature_drush_command() {
       'name'     => dt('The name of the feature to retrieve.'),
       'up'       => dt('An integer value specifying the number of upstream bases to include.'),
       'down'     => dt('An integer value specifying the number of downstream bases to incldue.'),
-      'out'      => dt('The output format. Valid options are "fasta_html", "fasta_txt" and raw.'),
       'parent'   => dt('Set this argument to 1 to retrieve the sequence from the parent in an alignment rather than the residues column of the feature itself.'),
       'agg'      => dt('Set this argument to 1 to aggregate sub features into a single sequence.  This is useful, for example, for obtaining CDS sequence from an mRNA'),
-      'child'    => dt('Set this argument to the sequence ontology term for the children to aggregate.  This is useful in the case where a gene has exons as well as CDSs and UTRs.  You may sepcify as many feature types as desired by separating each with a single comma (no spaces).'),
+      'child'    => dt('Set this argument to the exact sequence ontology term for the children to aggregate.  This is useful in the case where a gene has exons as well as CDSs and UTRs.  You may sepcify as many feature types as desired by separating each with a single comma (no spaces). Term matching is case-sensitive.'),
       'relationship'  => dt('Retreives the sequence of any feature in the specified relationship with the matched features.'),
       'rel_part' => dt('If a relationship is provided, then this will be "subject" or "object" indicating the side of the relationship for the matched features. If the matched features are the "object" then the "subject" features will have their sequences included in the output (and vice versa).'),
+      'width'    => dt('The number of nucleotides per row (defaults to 50).')
     ),
     'examples' => array(
       'Standard example' => 'drush tripal-current-job',
@@ -72,29 +72,45 @@ function tripal_feature_drush_command() {
  */
 function drush_tripal_feature_tripal_get_sequence() {
 
-  $org_commonname = drush_get_option('org');
-  $genus = drush_get_option('genus');
-  $species = drush_get_option('species');
-  $analysis_name = drush_get_option('analysis');
-  $type = drush_get_option('type');
-  $feature_name = drush_get_option('name');
-  $upstream = drush_get_option('up');
-  $downstream = drush_get_option('down');
-  $output_format = drush_get_option('out');
+  $org_commonname     = drush_get_option('org');
+  $genus              = drush_get_option('genus');
+  $species            = drush_get_option('species');
+  $analysis_name      = drush_get_option('analysis');
+  $type               = drush_get_option('type');
+  $feature_name       = drush_get_option('name');
+  $upstream           = drush_get_option('up')   ? drush_get_option('up') : 0;
+  $downstream         = drush_get_option('down') ? drush_get_option('down') : 0;
   $derive_from_parent = drush_get_option('parent');
-  $aggregate = drush_get_option('agg');
-  $child = drush_get_option('child');
-  $relationship = drush_get_option('relationship');
-  $rel_part = drush_get_option('rel_part');
+  $aggregate          = drush_get_option('agg');
+  $child              = drush_get_option('child');
+  $relationship       = drush_get_option('relationship');
+  $rel_part           = drush_get_option('rel_part');
+  $width              = drush_get_option('width') ? drush_get_option('width') : 50;
 
   if ($relationship and !$rel_part) {
     print "Please specify both 'relationship' and a 'rel_part' arguments. Both must be used together\n";
     return;
   }
 
-  tripal_feature_seq_extract_get_features($org_commonname, $genus, $species, $analysis_name,
-    $type, $feature_name, $upstream, $downstream, $output_format, $derive_from_parent,
-    $aggregate, $child, $relationship, $rel_part);
+  $options = array(
+    'org_commonname' => $org_commonname,
+    'genus' => $genus,
+    'species' => $species,
+    'analysis_name' => $analysis_name,
+    'type' => $type,
+    'feature_name' => $feature_name,
+    'upstream' => $upstream,
+    'downstream' => $downstream,
+    'derive_from_parent' => $derive_from_parent,
+    'aggregate' => $aggregate,
+    'sub_feature_types' => explode(',', $child),
+    'relationship_type' => $relationship,
+    'relationship_part' => $rel_part,
+    'print' => TRUE,
+    'width' => $width
+  );
+  
+  tripal_get_bulk_feature_sequences($options);
 }
 
 /**

+ 29 - 23
tripal_feature/tripal_feature.install

@@ -380,30 +380,36 @@ function tripal_feature_update_dependencies() {
  */
 function tripal_feature_update_7201() {
 
-  // there is a bug in the Tripal v2.0-alpha release that didn't add the
-  // materialized view schema to the mviews table.
-  // get the schema for the materialized view from the custom_tables table
-  // as there is a copy there, but only if the schema is missing from the
-  // materialized view table
-  $view_name = 'organism_feature_count';
-  $schema = db_select('tripal_mviews', 'tm')
-    ->fields('tm', array('mv_schema'))
-    ->condition('name', $view_name)
-    ->execute()
-    ->fetchField();
-  if (!$schema or $schema == 'Array') {
-    $schema = db_select('tripal_custom_tables', 'tct')
-      ->fields('tct', array('schema'))
-      ->condition('table_name', $view_name)
+  try {
+    // there is a bug in the Tripal v2.0-alpha release that didn't add the
+    // materialized view schema to the mviews table.
+    // get the schema for the materialized view from the custom_tables table
+    // as there is a copy there, but only if the schema is missing from the
+    // materialized view table
+    $view_name = 'organism_feature_count';
+    $schema = db_select('tripal_mviews', 'tm')
+      ->fields('tm', array('mv_schema'))
+      ->condition('name', $view_name)
       ->execute()
       ->fetchField();
-    $schema_str = var_export(unserialize($schema), TRUE);
-    $schema_str = preg_replace('/=>\s+\n\s+array/', '=> array', $schema_str);
-    db_update('tripal_mviews')
-      ->fields(array(
-      'mv_schema' => $schema_str
-      ))
-      ->condition('name', $view_name)
-      ->execute();
+    if (!$schema or $schema == 'Array') {
+      $schema = db_select('tripal_custom_tables', 'tct')
+        ->fields('tct', array('schema'))
+        ->condition('table_name', $view_name)
+        ->execute()
+        ->fetchField();
+      $schema_str = var_export(unserialize($schema), TRUE);
+      $schema_str = preg_replace('/=>\s+\n\s+array/', '=> array', $schema_str);
+      db_update('tripal_mviews')
+        ->fields(array(
+        'mv_schema' => $schema_str
+        ))
+        ->condition('name', $view_name)
+        ->execute();
+    }
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to complete update' . $error);
   }
 }

+ 5 - 1
tripal_feature/tripal_feature.module

@@ -93,7 +93,7 @@ function tripal_feature_permission() {
       'title' => t('Edit Features'),
       'description' => t('Allow users to edit feature pages.'),
     ),
-    'adminster tripal feature' => array(
+    'administer tripal feature' => array(
       'title' => t('Administer Features'),
       'description' => t('Allow users to administer all features.'),
     ),
@@ -302,6 +302,7 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_feature_relationships',
       'path' => "$path/theme/templates",
     ),
+    // help template
     'tripal_feature_help' => array(
       'template' => 'tripal_feature_help',
       'variables' =>  array(NULL),
@@ -601,5 +602,8 @@ function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
   // turn off preview button for insert/updates
   if ($form_id == "chado_feature_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
+    
+    //remove the body field
+    unset($form['body']);
   }
 }

+ 12 - 0
tripal_featuremap/includes/tripal_featuremap.chado_node.inc

@@ -551,6 +551,12 @@ function tripal_featuremap_node_insert($node) {
 
   switch ($node->type) {
     case 'chado_featuremap':
+      
+      // get the feature details from chado
+      $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);      
+      $values = array('featuremap_id' => $featuremap_id);
+      $featuremap = chado_generate_var('featuremap', $values);
+      $node->featuremap = $featuremap;
 
       // Now get the title
       $node->title = chado_get_node_title($node);
@@ -570,6 +576,12 @@ function tripal_featuremap_node_update($node) {
   switch ($node->type) {
     case 'chado_featuremap':
 
+      // get the feature details from chado
+      $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);
+      $values = array('featuremap_id' => $featuremap_id);
+      $featuremap = chado_generate_var('featuremap', $values);
+      $node->featuremap = $featuremap;
+      
       // Now get the title
       $node->title = chado_get_node_title($node);
 

+ 1 - 1
tripal_featuremap/tripal_featuremap.module

@@ -71,7 +71,7 @@ function tripal_featuremap_permission() {
       'title' => t('Edit Maps'),
       'description' => t('Allow users to edit map pages.'),
     ),
-    'adminster tripal featuremap' => array(
+    'administer tripal featuremap' => array(
       'title' => t('Administer Maps'),
       'description' => t('Allow users to administer all maps.'),
     ),

+ 3 - 3
tripal_genetic/tripal_genetic.module

@@ -27,7 +27,7 @@ require_once 'includes/tripal_genetic.admin.inc';
  */
 function tripal_genetic_permission() {
   return array(
-    'adminster tripal genetic' => array(
+    'administer tripal genetic' => array(
       'title' => t('Administer Genetic Module'),
       'description' => t('Allow users to administer the genetic module.'),
     ),
@@ -51,7 +51,7 @@ function tripal_genetic_menu() {
    'title' => 'Genetics',
    'description' => 'Genetic data including Genotypes.',
    'page callback' => 'tripal_genetic_admin_genetics_listing',
-   'access arguments' => array('adminster tripal genetic'),
+   'access arguments' => array('administer tripal genetic'),
    'type' => MENU_NORMAL_ITEM,
   );
 
@@ -60,7 +60,7 @@ function tripal_genetic_menu() {
    'description' => "A description of the Tripal genetic module including a short description of it's usage.",
    'page callback' => 'theme',
    'page arguments' => array('tripal_genetic_help'),
-   'access arguments' => array('adminster tripal genetic'),
+   'access arguments' => array('administer tripal genetic'),
    'type' => MENU_LOCAL_TASK,
   );
 

+ 12 - 0
tripal_library/includes/tripal_library.chado_node.inc

@@ -592,6 +592,12 @@ function tripal_library_node_insert($node) {
 
   switch ($node->type) {
     case 'chado_library':
+      
+      $library_id = chado_get_id_from_nid('library', $node->nid);
+      $values = array('library_id' => $library_id);
+      $library = chado_generate_var('library', $values);
+      $library = chado_expand_var($library, 'field', 'library.uniquename');
+      $node->library = $library;
 
       // Now get the title
       $node->title = chado_get_node_title($node);
@@ -610,6 +616,12 @@ function tripal_library_node_update($node) {
 
   switch ($node->type) {
     case 'chado_library':
+      
+      $library_id = chado_get_id_from_nid('library', $node->nid);
+      $values = array('library_id' => $library_id);
+      $library = chado_generate_var('library', $values);
+      $library = chado_expand_var($library, 'field', 'library.uniquename');
+      $node->library = $library;
 
       // Now get the title
       $node->title = chado_get_node_title($node);

+ 1 - 1
tripal_library/tripal_library.module

@@ -46,7 +46,7 @@ function tripal_library_permission() {
       'title' => t('Edit Libraries'),
       'description' => t('Allow users to edit library pages.'),
     ),
-    'adminster tripal library' => array(
+    'administer tripal library' => array(
       'title' => t('Administer Libraries'),
       'description' => t('Allow users to administer all libraries.'),
     ),

+ 2 - 2
tripal_natural_diversity/tripal_natural_diversity.module

@@ -27,7 +27,7 @@ require_once 'includes/tripal_natural_diversity.admin.inc';
  */
 function tripal_natural_diversity_permission() {
   return array(
-    'adminster tripal nd' => array(
+    'administer tripal nd' => array(
       'title' => t('Administer Natural Diversity Module'),
       'description' => t('Allow users to administer the natural diversity module.'),
     ),
@@ -51,7 +51,7 @@ function tripal_natural_diversity_menu() {
    'title' => 'Natural Diversity Experiments',
    'description' => 'Experiments relating to natural diversity such as genotype and phenotype experiments.',
    'page callback' => 'tripal_natural_diversity_admin_natdiv_view',
-   'access arguments' => array('adminster tripal nd'),
+   'access arguments' => array('administer tripal nd'),
    'type' => MENU_NORMAL_ITEM,
   );
 

+ 12 - 0
tripal_organism/includes/tripal_organism.chado_node.inc

@@ -579,6 +579,12 @@ function tripal_organism_node_insert($node) {
 
   switch ($node->type) {
     case 'chado_organism':
+      
+      // find the organism and add in the details
+      $organism_id = chado_get_id_from_nid('organism', $node->nid);
+      $values = array('organism_id' => $organism_id);
+      $organism = chado_generate_var('organism', $values);
+      $node->organism = $organism;
 
       // Now get the title
       $node->title = chado_get_node_title($node);
@@ -597,6 +603,12 @@ function tripal_organism_node_update($node) {
 
   switch ($node->type) {
     case 'chado_organism':
+      
+      // find the organism and add in the details
+      $organism_id = chado_get_id_from_nid('organism', $node->nid);
+      $values = array('organism_id' => $organism_id);
+      $organism = chado_generate_var('organism', $values);
+      $node->organism = $organism;
 
       // Now get the title
       $node->title = chado_get_node_title($node);

+ 7 - 4
tripal_organism/tripal_organism.module

@@ -72,7 +72,7 @@ function tripal_organism_menu() {
     'title' => 'Organisms',
     'description' => 'Any living biological entity, such as an animal, plant, fungus, or bacterium.',
     'page callback' => 'tripal_organism_admin_organism_view',
-    'access arguments' => array('adminster tripal organism'),
+    'access arguments' => array('administer tripal organism'),
     'type' => MENU_NORMAL_ITEM,
   );
 
@@ -81,7 +81,7 @@ function tripal_organism_menu() {
     'description' => "A description of the Tripal Organism module including a short description of it's usage.",
     'page callback' => 'theme',
     'page arguments' => array('tripal_organism_help'),
-    'access arguments' => array('adminster tripal organism'),
+    'access arguments' => array('administer tripal organism'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 10
   );
@@ -91,7 +91,7 @@ function tripal_organism_menu() {
     'description' => 'Manage integration of Chado organisms including associated features',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_organism_admin'),
-    'access arguments' => array('adminster tripal organism'),
+    'access arguments' => array('administer tripal organism'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 5
   );
@@ -221,7 +221,7 @@ function tripal_organism_permission() {
       'title' => t('Edit Organisms'),
       'description' => t('Allow users to edit organism pages.'),
     ),
-    'adminster tripal organism' => array(
+    'administer tripal organism' => array(
       'title' => t('Administer Organisms'),
       'description' => t('Allow users to administer all organisms.'),
     ),
@@ -272,5 +272,8 @@ function tripal_organism_form_alter(&$form, &$form_state, $form_id) {
   // turn of preview button for insert/updates
   if ($form_id == "chado_organism_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
+    
+    //remove the body field
+    unset($form['body']);
   }
 }

+ 1 - 1
tripal_organism/tripal_organism.views_default.inc

@@ -221,7 +221,7 @@ function tripal_organism_admin_defaultview_organisms() {
   $handler->display->display_options['title'] = 'Organisms';
   $handler->display->display_options['use_more_always'] = FALSE;
   $handler->display->display_options['access']['type'] = 'perm';
-  $handler->display->display_options['access']['perm'] = 'adminster tripal organism';
+  $handler->display->display_options['access']['perm'] = 'administer tripal organism';
   $handler->display->display_options['cache']['type'] = 'none';
   $handler->display->display_options['query']['type'] = 'views_query';
   $handler->display->display_options['exposed_form']['type'] = 'basic';

+ 3 - 3
tripal_phenotype/tripal_phenotype.module

@@ -22,7 +22,7 @@
  */
 function tripal_phenotype_permission() {
   return array(
-    'adminster tripal phenotype' => array(
+    'administer tripal phenotype' => array(
       'title' => t('Administer Phenotype Module'),
       'description' => t('Allow users to administer the phenotype module.'),
     ),
@@ -46,7 +46,7 @@ function tripal_phenotype_menu() {
    'title' => 'Phenotypes',
    'description' => 'A controlled sentence describing observable effects of non-wild type function.',
    'page callback' => 'tripal_phenotype_admin_phenotypes_listing',
-   'access arguments' => array('adminster tripal phenotype'),
+   'access arguments' => array('administer tripal phenotype'),
    'type' => MENU_NORMAL_ITEM,
   );
 
@@ -55,7 +55,7 @@ function tripal_phenotype_menu() {
    'description' => "A description of the Tripal phenotype module including a short description of it's usage.",
    'page callback' => 'theme',
    'page arguments' => array('tripal_phenotype_help'),
-   'access arguments' => array('adminster tripal phenotype'),
+   'access arguments' => array('administer tripal phenotype'),
    'type' => MENU_LOCAL_TASK,
   );
 

+ 1 - 1
tripal_project/includes/tripal_project.admin.inc

@@ -95,7 +95,7 @@ function tripal_project_admin($form, $form_state) {
       'simply save this setup. <b>Important</b>: be sure that whatever you choose will '.
       'always be unique even considering future data that may be added.  If you include '.
       'the Chado table name and id you are guaranteed to have a unique URL. For example project/[id]'),
-    '#size' => 150,
+    '#size' => 75,
     '#default_value' => variable_get('chado_project_url_string', '/project/[id]'),
   );
 

+ 13 - 1
tripal_project/includes/tripal_project.chado_node.inc

@@ -524,13 +524,19 @@ function tripal_project_node_insert($node) {
   // know the project_id in the presave
   switch ($node->type) {
     case 'chado_project':
+      
+      // get the feature details from chado
+      $project_id = chado_get_id_from_nid('project', $node->nid);
+      $values = array('project_id' => $project_id);
+      $project = chado_generate_var('project', $values);
+      $nodes->project = $project;
 
       // Now get the title
       $node->title = chado_get_node_title($node);
       
       // on an insert we need to add the project_id to the node object
       // so that the tripal_project_get_project_url function can set the URL properly
-      $node->project_id = chado_get_id_from_nid('project', $node->nid);
+      $node->project_id = $project_id;
 
       // remove any previous alias
       db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));
@@ -555,6 +561,12 @@ function tripal_project_node_update($node) {
   switch ($node->type) {
     case 'chado_project':
 
+      // get the feature details from chado
+      $project_id = chado_get_id_from_nid('project', $node->nid);
+      $values = array('project_id' => $project_id);
+      $project = chado_generate_var('project', $values);
+      $nodes->project = $project;
+      
       // Now get the title
       $node->title = chado_get_node_title($node);
       

+ 1 - 0
tripal_project/tripal_project.info

@@ -9,3 +9,4 @@ configure = admin/tripal/chado/tripal_project
 dependencies[] = tripal_core
 dependencies[] = tripal_views
 dependencies[] = tripal_cv
+dependencies[] = tripal_contact

+ 4 - 4
tripal_project/tripal_project.module

@@ -44,7 +44,7 @@ function tripal_project_menu() {
     'title' => 'Projects',
     'description' => ('A project. Can be used for grouping data such as with the natural diversity module data.'),
     'page callback' => 'tripal_project_admin_project_view',
-    'access arguments' => array('adminster tripal project'),
+    'access arguments' => array('administer tripal project'),
     'type' => MENU_NORMAL_ITEM
   );
 
@@ -53,7 +53,7 @@ function tripal_project_menu() {
     'description' => ("Basic Description of Tripal Project Module Functionality."),
     'page callback' => 'theme',
     'page arguments' => array('tripal_project_help'),
-    'access arguments' => array('adminster tripal project'),
+    'access arguments' => array('administer tripal project'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 6
   );
@@ -62,7 +62,7 @@ function tripal_project_menu() {
     'title' => 'Settings',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_project_admin'),
-    'access arguments' => array('adminster tripal project'),
+    'access arguments' => array('administer tripal project'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 4
   );
@@ -142,7 +142,7 @@ function tripal_project_permission() {
       'title' => t('Edit Projects'),
       'description' => t('Allow users to edit project pages.'),
     ),
-    'adminster tripal project' => array(
+    'administer tripal project' => array(
       'title' => t('Administer Projects'),
       'description' => t('Allow users to administer all projects.'),
     ),

+ 2 - 2
tripal_project/tripal_project.views_default.inc

@@ -91,8 +91,8 @@ function tripal_project_defaultview_admin_projects() {
   $handler = $view->new_display('default', 'Master', 'default');
   $handler->display->display_options['title'] = 'Projects';
   $handler->display->display_options['use_more_always'] = FALSE;
-$handler->display->display_options['access']['type'] = 'perm';
-$handler->display->display_options['access']['perm'] = 'adminster tripal project';
+  $handler->display->display_options['access']['type'] = 'perm';
+  $handler->display->display_options['access']['perm'] = 'administer tripal project';
   $handler->display->display_options['cache']['type'] = 'none';
   $handler->display->display_options['query']['type'] = 'views_query';
   $handler->display->display_options['exposed_form']['type'] = 'basic';

+ 28 - 6
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -148,7 +148,7 @@ function chado_pub_form($node, $form_state) {
     $title        = $form_state['input']['pubtitle'];
     $uniquename   = $form_state['input']['uniquename'];
     $type_id      = $form_state['input']['type_id'];
-    $is_obsolete  = $form_state['input']['is_obsolete'];
+    $is_obsolete  = array_key_exists('is_obsolete', $form_state['input']) ? $form_state['input']['is_obsolete'] : '';
   }
 
   $form['pubtitle'] = array(
@@ -586,7 +586,7 @@ function chado_pub_insert($node) {
       if ($prop->name == 'Citation') {
         $citation_id = $prop->cvterm_id;
         if (!empty($node->uniquename)) {
-          $properties[$citation_id] = $node->uniquename;
+          $properties[$citation_id][0] = $node->uniquename;
         }
       }
     }
@@ -1091,11 +1091,22 @@ function tripal_pub_node_view($node, $view_mode, $langcode) {
 function tripal_pub_node_insert($node) {
 
   if ($node->type == 'chado_pub') {
+    
+    // get the pub
+    $pub_id = chado_get_id_from_nid('pub', $node->nid);
+    $values = array('pub_id' => $pub_id);
+    $pub = chado_generate_var('pub', $values);
 
+    // expand the 'text' fields as those aren't included by default
+    // and they really shouldn't be so large to cause problems
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
+    $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
+    $node->pub = $pub;
+    
     // Now get the title
     $node->title = chado_get_node_title($node);
-      
-    $pub_id = chado_get_id_from_nid('pub', $node->nid);
+
     tripal_pub_set_pub_url($node, $pub_id);
   }
 }
@@ -1140,10 +1151,21 @@ function tripal_pub_node_update($node) {
 
   if ($node->type == 'chado_pub') {
 
+    // get the pub
+    $pub_id = chado_get_id_from_nid('pub', $node->nid);
+    $values = array('pub_id' => $pub_id);
+    $pub = chado_generate_var('pub', $values);
+    
+    // expand the 'text' fields as those aren't included by default
+    // and they really shouldn't be so large to cause problems
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
+    $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
+    $node->pub = $pub;
+            
     // Now get the title
     $node->title = chado_get_node_title($node);
-      
-    $pub_id = chado_get_id_from_nid('pub', $node->nid);
+
     tripal_pub_set_pub_url($node, $pub_id);
   }
 }

+ 1 - 1
tripal_pub/includes/tripal_pub.pub_citation.inc

@@ -11,7 +11,7 @@
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_citation_form($form_state) {
+function tripal_pub_citation_form($form, &$form_state) {
 
   $form['instructions'] = array(
     '#markup' => '<p>Use this form to unify publication citations. Citations are created automtically when

+ 3 - 1
tripal_pub/includes/tripal_pub.pub_importers.inc

@@ -776,7 +776,9 @@ function theme_tripal_pub_importer_setup_form_elements($variables) {
   $table = array(
     'header' => $headers,
     'rows' => $rows,
-    'attributes' => array('class' => 'tripal-data-table'),
+    'attributes' => array(
+      'class' => array('tripal-data-table')
+    ),
     'sticky' => TRUE,
     'caption' => '',
     'colgroups' => array(),

+ 1 - 1
tripal_pub/includes/tripal_pub.pub_search.inc

@@ -93,7 +93,7 @@ function tripal_pub_search_page() {
       'attributes' => array(
         'id' => 'tripal-pub-search-results-table', 
         'border' => '0',
-        'class' => 'tripal-data-table'
+        'class' => array('tripal-data-table')
       ),
       'sticky' => TRUE,
       'caption' => '',

+ 3 - 3
tripal_pub/tripal_pub.module

@@ -137,7 +137,7 @@ function tripal_pub_menu() {
     'title' => t('Publication Importers'),
     'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
     'page callback' => 'tripal_pub_importers_list',
-    'access arguments' => array('administer tripal pubs'),
+    'access arguments' => array('administer tripal pub'),
     'type' => MENU_NORMAL_ITEM,
   );
 
@@ -341,7 +341,7 @@ function tripal_pub_permission() {
       'title' => t('Edit Publications'),
       'description' => t('Allow users to edit publication pages.'),
     ),
-    'adminster tripal pub' => array(
+    'administer tripal pub' => array(
       'title' => t('Administer Publications'),
       'description' => t('Allow users to administer all publications.'),
     ),
@@ -461,4 +461,4 @@ function tripal_pub_search_biological_data_views() {
       'link'         => 'find/publications'
     ),
   );
-}
+}

+ 1 - 1
tripal_stock/includes/tripal_stock.admin.inc

@@ -95,7 +95,7 @@ function tripal_stock_admin() {
       simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
       future data that may be added.  If you include the Chado table name, genus, species, type
       and uniquename you are guaranteed to have a unique URL. For example stock/[genus]/[species]/[type]/[uniquename]'),
-    '#size' => 150,
+    '#size' => 75,
     '#default_value' => variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]'),
   );
 

+ 16 - 0
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -888,6 +888,14 @@ function tripal_stock_node_insert($node) {
   // know the stock_id in the presave
   switch ($node->type) {
     case 'chado_stock':
+      
+      // get the feature details from chado
+      $stock_id = chado_get_id_from_nid('stock', $node->nid);
+      $values = array('stock_id' => $stock_id);
+      $stock = chado_generate_var('stock', $values);
+      $stock = chado_expand_var($stock, 'field', 'stock.uniquename');
+      $stock = chado_expand_var($stock, 'field', 'stock.description');
+      $node->stock = $stock;
 
       // If your module is using the Chado Node: Title & Path API to allow custom titles
       // for your node type. Every time you want the title of the node, you need to use the
@@ -920,6 +928,14 @@ function tripal_stock_node_update($node) {
   // add items to other nodes, build index and search results
   switch ($node->type) {
     case 'chado_stock':
+      
+      // get the feature details from chado
+      $stock_id = chado_get_id_from_nid('stock', $node->nid);
+      $values = array('stock_id' => $stock_id);
+      $stock = chado_generate_var('stock', $values);
+      $stock = chado_expand_var($stock, 'field', 'stock.uniquename');
+      $stock = chado_expand_var($stock, 'field', 'stock.description');
+      $node->stock = $stock;
 
       // If your module is using the Chado Node: Title & Path API to allow custom titles
       // for your node type. Every time you want the title of the node, you need to use the

+ 10 - 1
tripal_stock/tripal_stock.module

@@ -163,7 +163,7 @@ function tripal_stock_permission() {
       'title' => t('Edit Stocks'),
       'description' => t('Allow users to edit stock pages.'),
     ),
-    'adminster tripal stock' => array(
+    'administer tripal stock' => array(
       'title' => t('Administer Stocks'),
       'description' => t('Allow users to administer all stocks.'),
     ),
@@ -319,6 +319,12 @@ function tripal_stock_theme($existing, $type, $theme, $path) {
       'variables' =>  array(NULL),
       'path' => "$path/theme/templates",
     ),
+    // themed teaser
+    'tripal_stock_teaser' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_stock_teaser',
+      'path' => "$path/theme/templates",
+    ),
   );
   return $items;
 }
@@ -526,6 +532,9 @@ function tripal_stock_form_alter(&$form, &$form_state, $form_id) {
   // turn of preview button for insert/updates
   if ($form_id == "chado_stock_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
+    
+    //remove the body field
+    unset($form['body']);
   }
 }
 

+ 47 - 43
tripal_views/includes/tripal_views_integration_UI.inc

@@ -17,6 +17,7 @@
 function tripal_views_integration_setup_list() {
   $output = '';
 
+  // TODO: change the following to use theme_item_list()
   $output .= '<ul class="action-links">';
   $output .=  '<li>' . l(t('Add a New Entry'), "admin/tripal/views-integration/new") . '</li>';
   $output .=  '<li style="float: right;">' . l(t('Delete ALL Entries'), "admin/tripal/views-integration/delete-all/confirm") . '</li>';
@@ -143,7 +144,7 @@ function tripal_views_integration_delete($setup_id) {
  *
  * @ingroup tripal_views
  */
-function tripal_views_integration_delete_all_form ($form, $form_state) {
+function tripal_views_integration_delete_all_form($form, &$form_state) {
 
   $form['extra'] = array(
     '#type' => 'item',
@@ -185,7 +186,7 @@ function tripal_views_integration_delete_all_form ($form, $form_state) {
  *
  * @ingroup tripal_views
  */
-function tripal_views_integration_delete_all_form_submit ($form, &$form_state) {
+function tripal_views_integration_delete_all_form_submit($form, &$form_state) {
 
   tripal_views_rebuild_views_integrations(TRUE);
 
@@ -197,14 +198,13 @@ function tripal_views_integration_delete_all_form_submit ($form, &$form_state) {
  * Purpose: defines the web form used for specifing the base table, joins and
  *   handlers when integrating a table with views.  This form is used for both
  *   creating a new record and editing an existing record.
+ *   
+ * @param $form
+ *    The form array which is passed automatically by drupal
  *
  * @param $form_state
  *    The form state which is passed automatically by drupal
  *
- * @param $setup_id
- *    The unique setup for an integrated table.  This value is only set when
- *    the form is used for updating an existing record.
- *
  * @return
  *    A proper Drupal form associative array.
  *
@@ -213,7 +213,7 @@ function tripal_views_integration_delete_all_form_submit ($form, &$form_state) {
  *
  * @ingroup tripal_views
  */
-function tripal_views_integration_form($form, $form_state, $arg) {
+function tripal_views_integration_form($form, &$form_state) {
 
   $data = array();
   $form['#cache'] = TRUE;
@@ -289,7 +289,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
        '#value' => $setup_id,
     );
 
-  }
+  } // end if (isset($setup_id)) {
 
   // add a fieldset for the MView & Chado table selectors
   $form['base_table_type'] = array(
@@ -317,7 +317,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
     '#ajax' => array(
        //D6: 'path' => 'tripal/views-integration/ajax/view_setup_table',
        'callback' => 'tripal_views_integration_ajax_view_setup_table',
-       'wrapper' => 'fieldset-table-rows-wrapper',
+       'wrapper' => 'tripal-views-integration-form',
        'effect' => 'fade',
        'event' => 'change',
        'method' => 'replace',
@@ -346,7 +346,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
     '#ajax' => array(
        //D6: 'path' => 'tripal/views-integration/ajax/view_setup_table',
        'callback' => 'tripal_views_integration_ajax_view_setup_table',
-       'wrapper' => 'fieldset-table-rows-wrapper',
+       'wrapper' => 'tripal-views-integration-form',
        'effect' => 'fade',
        'event' => 'change',
        'method' => 'replace',
@@ -661,26 +661,26 @@ function tripal_views_integration_form($form, $form_state, $arg) {
       // create the handler fields
       $default_field_handler = 0;
       if (isset($setup_id) && !isset($form_state['values']["fields_field_handler_$table_id-$i"])) {
-        $default_field_handler = $default_handlers[$column_name]['field']['handler_name'];
+        $default_field_handler = array_key_exists('field', $default_handlers[$column_name]) ? $default_handlers[$column_name]['field']['handler_name'] : "";
         $form_state['values']["fields_field_handler_$table_id-$i"] = $default_field_handler;
       }
       else {
-        $default_field_handler = $form_state['values']["fields_field_handler_$table_id-$i"];
+        $default_field_handler = array_key_exists("fields_field_handler_$table_id-$i", $form_state['values']) ? $form_state['values']["fields_field_handler_$table_id-$i"] : '';
         if (!$default_field_handler) {
           if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
-            $default_field_handler = 'chado_views_handler_field_numeric';
+            $default_field_handler = 'views_handler_field_numeric';
           }
           elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
-            $default_field_handler = 'chado_views_handler_field';
+            $default_field_handler = 'views_handler_field';
           }
           elseif ($column_type == 'boolean') {
-            $default_field_handler = 'chado_views_handler_field_boolean';
+            $default_field_handler = 'views_handler_field_boolean';
           }
           elseif ($column_type == 'float') {
-            $default_field_handler = 'chado_views_handler_field_numeric';
+            $default_field_handler = 'views_handler_field_numeric';
           }
           elseif ($column_type == 'datetime') {
-            $default_field_handler = 'chado_views_handler_field_date';
+            $default_field_handler = 'views_handler_field_date';
           }
         }
       }
@@ -696,26 +696,26 @@ function tripal_views_integration_form($form, $form_state, $arg) {
 
       $default_filter_handler = 0;
       if (isset($setup_id) && !isset($form_state['values']["fields_filter_handler_$table_id-$i"])) {
-        $default_filter_handler = $default_handlers[$column_name]['filter']['handler_name'];
+        $default_filter_handler = array_key_exists('filter', $default_handlers[$column_name]) ? $default_handlers[$column_name]['filter']['handler_name'] : "";
         $form_state['values']["fields_filter_handler_$table_id-$i"]= $default_filter_handler;
       }
       else {
-        $default_filter_handler = $form_state['values']["fields_filter_handler_$table_id-$i"];
+        $default_filter_handler = array_key_exists("fields_filter_handler_$table_id-$i", $form_state['values']) ? $form_state['values']["fields_filter_handler_$table_id-$i"] : "";
         if (!$default_filter_handler) {
           if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
-            $default_filter_handler = 'chado_views_handler_filter_numeric';
+            $default_filter_handler = 'views_handler_filter_numeric';
           }
           elseif (preg_match("/^character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
-            $default_filter_handler = 'chado_views_handler_filter_string';
+            $default_filter_handler = 'views_handler_filter_string';
           }
           elseif ($column_type == 'boolean') {
-            $default_filter_handler = 'chado_views_handler_filter_boolean';
+            $default_filter_handler = 'views_handler_filter_boolean';
           }
           elseif ($column_type == 'float') {
-            $default_filter_handler = 'chado_views_handler_filter_float';
+            $default_filter_handler = 'views_handler_filter_float';
           }
           elseif ($column_type == 'datetime') {
-            $default_filter_handler = 'chado_views_handler_filter_date';
+            $default_filter_handler = 'views_handler_filter_date';
           }
         }
       }
@@ -730,26 +730,26 @@ function tripal_views_integration_form($form, $form_state, $arg) {
 
       $default_sort_handler = 0;
       if (isset($setup_id) && !isset($form_state['values']["fields_sort_handler_$table_id-$i"])) {
-        $default_sort_handler = $default_handlers[$column_name]['sort']['handler_name'];
+        $default_sort_handler = array_key_exists('sort', $default_handlers[$column_name]) ? $default_handlers[$column_name]['sort']['handler_name'] : "";
         $form_state['values']["fields_sort_handler_$table_id-$i"] = $default_sort_handler;
       }
       else {
-        $default_sort_handler = $form_state['values']["fields_sort_handler_$table_id-$i"];
+        $default_sort_handler = array_key_exists("fields_sort_handler_$table_id-$i", $form_state['values']) ? $form_state['values']["fields_sort_handler_$table_id-$i"] : "";
         if (!$default_sort_handler) {
           if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
-            $default_sort_handler = 'chado_views_handler_sort';
+            $default_sort_handler = 'views_handler_sort';
           }
           elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
-            $default_sort_handler = 'chado_views_handler_sort';
+            $default_sort_handler = 'views_handler_sort';
           }
           elseif ($column_type == 'boolean') {
-            $default_sort_handler = 'chado_views_handler_sort';
+            $default_sort_handler = 'views_handler_sort';
           }
           elseif ($column_type == 'float') {
-            $default_sort_handler = 'chado_views_handler_sort';
+            $default_sort_handler = 'views_handler_sort';
           }
           elseif ($column_type == 'datetime') {
-            $default_sort_handler = 'chado_views_handler_sort_date';
+            $default_sort_handler = 'views_handler_sort_date';
           }
         }
       }
@@ -768,7 +768,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
         && isset($default_handlers[$column_name]['argument']))
       {
         $default_argument_handler = $default_handlers[$column_name]['argument']['handler_name'];
-        $form_state['values']["fields_argument_handler_$table_id-$i"]=$default_argument_handler ;
+        $form_state['values']["fields_argument_handler_$table_id-$i"] = $default_argument_handler ;
       }
       else {
         if (isset($form_state['values']["fields_argument_handler_$table_id-$i"])) {
@@ -802,7 +802,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
       );
 
       $i++;
-    }
+    } // end foreach ($columns as $column) {
 
     $form['view_setup_join'] = array(
       '#type' => 'fieldset',
@@ -857,6 +857,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
       ->orderBy('tvj.relationship_only','ASC')
       ->orderBy('tvj.base_field', 'ASC')
       ->orderBy('tvj.left_table', 'ASC');
+    
     foreach ($query->execute() as $i => $result) {
       $form['view_setup_join']["$table_id-$i"] = array(
            '#type' => 'markup',
@@ -954,7 +955,7 @@ function tripal_views_integration_form($form, $form_state, $arg) {
         '#required' => FALSE,
         '#default_value' => $result->left_field
       );
-    }
+    } // end foreach ($query->execute() as $i => $result) {
 
     $form['num_joins'] = array(
       '#type' => 'hidden',
@@ -1070,9 +1071,9 @@ function tripal_views_integration_form($form, $form_state, $arg) {
     );
 
     $data['row_count'] = $i - 1;
-  } //end of if table/mview
+  } // end of if table/mview
 
-  //use this to put values into $form_state['values']
+  // use this to put values into $form_state['values']
   $form['data'] = array();
 
   // Ensure that we don't store an array
@@ -1091,9 +1092,11 @@ function tripal_views_integration_form($form, $form_state, $arg) {
       );
     }
   }
+  
+  $form['#prefix'] = '<div id="tripal-views-integration-form">';
+  $form['#suffix'] = '</div>';
 
   $form['#redirect'] = 'admin/tripal/views-integration/list';
-
   return $form;
 }
 
@@ -1155,12 +1158,12 @@ function tripal_views_integration_form_validate($form, &$form_state) {
  * @ingroup tripal_views
  */
 function tripal_views_integration_form_submit($form, &$form_state) {
-  $name = $form_state['values']['row_name'];
-  $mview_id = $form_state['values']['mview_id'];
+  $name       = trim($form_state['values']['row_name']);
+  $mview_id   = $form_state['values']['mview_id'];
   $table_name = $form_state['values']['table_name'];
-  $setup_id = $form_state['values']['setup_id'];
-  $priority = $form_state['values']['row_priority'];
-  $comment = $form_state['values']['row_description'];
+  $setup_id   = array_key_exists('setup_id', $form_state['values']) ? $form_state['values']['setup_id'] : "";
+  $priority   = $form_state['values']['row_priority'];
+  $comment    = $form_state['values']['row_description'];
 
   // get details about this mview
   if ($mview_id) {
@@ -1415,7 +1418,8 @@ function tripal_views_integration_discover_handlers() {
  * @ingroup tripal_views
  */
 function tripal_views_integration_ajax_view_setup_table($form, $form_state) {
-  return $form['view_setup_table'];
+  //return $form['view_setup_table'];
+  return $form;
 }
 
 /*

+ 1 - 1
tripal_views/includes/tripal_views_integration_port.inc

@@ -18,7 +18,7 @@
  *
  * @ingroup tripal_views
  */
-function tripal_views_integration_export_form($form, $form_state, $setup_id) {
+function tripal_views_integration_export_form($form, &$form_state, $setup_id) {
   $form = array();
 
   $defn_array = tripal_views_integration_export_entry($setup_id);

+ 2 - 2
tripal_views/theme/tripal_views_search_biological_content.tpl.php

@@ -19,7 +19,7 @@ this site:</p>
 <?php
 // How to disable/remove views from this list
 print tripal_set_message(
-  "To remove a view from this list, simply navigate to the Views UI (Adminster ->
+  "To remove a view from this list, simply navigate to the Views UI (Administer ->
     Structure -> Views; admin/structure/views) and choose 'disable' from the action
     drop-down to the right of the view you would like to remove.",
   TRIPAL_INFO,
@@ -53,4 +53,4 @@ print tripal_set_message(
   TRIPAL_INFO,
   array('return_html' => 1)
 );
-?>
+?>