Browse Source

Merge branch '6.x-0.4-dev' of git.drupal.org:sandbox/spficklin/1337878 into 6.x-0.4-dev

Stephen Ficklin 12 years ago
parent
commit
b268543550
91 changed files with 7150 additions and 11787 deletions
  1. 2 2
      tripal_analysis/tripal_analysis.admin.inc
  2. 8 8
      tripal_analysis/tripal_analysis.api.inc
  3. 15 15
      tripal_analysis/tripal_analysis.install
  4. 92 92
      tripal_analysis/tripal_analysis.module
  5. 6 6
      tripal_analysis/tripal_analysis.views.inc
  6. 146 92
      tripal_bulk_loader/tripal_bulk_loader.admin.inc
  7. 0 2427
      tripal_bulk_loader/tripal_bulk_loader.admin.inc.orig
  8. 11 0
      tripal_bulk_loader/tripal_bulk_loader.coder_ignores.txt
  9. 6 5
      tripal_bulk_loader/tripal_bulk_loader.constants.inc
  10. 2 2
      tripal_bulk_loader/tripal_bulk_loader.install
  11. 100 29
      tripal_bulk_loader/tripal_bulk_loader.loader.inc
  12. 0 733
      tripal_bulk_loader/tripal_bulk_loader.loader.inc.orig
  13. 118 98
      tripal_bulk_loader/tripal_bulk_loader.module
  14. 0 647
      tripal_bulk_loader/tripal_bulk_loader.module.orig
  15. 2 2
      tripal_contact/tripal_contact.api.inc
  16. 9 9
      tripal_contact/tripal_contact.module
  17. 12 12
      tripal_contact/tripal_contact.views.inc
  18. 155 65
      tripal_core/tripal_core.api.inc
  19. 9 12
      tripal_core/tripal_core.coder_ignores.txt
  20. 2 0
      tripal_core/tripal_core.schema.api.inc
  21. 1 5
      tripal_cv/tripal_cv.coder_ignores.txt
  22. 3 2
      tripal_cv/tripal_cv.module
  23. 2 2
      tripal_cv/tripal_cv.views.inc
  24. 73 74
      tripal_db/tripal_db.api.inc
  25. 21 21
      tripal_db/tripal_db.install
  26. 238 239
      tripal_db/tripal_db.module
  27. 2 2
      tripal_db/tripal_db.views.inc
  28. 665 644
      tripal_feature/fasta_loader.php
  29. 617 605
      tripal_feature/gff_loader.php
  30. 146 139
      tripal_feature/indexFeatures.php
  31. 379 370
      tripal_feature/syncFeatures.php
  32. 116 116
      tripal_feature/tripal_feature-db_references.inc
  33. 142 143
      tripal_feature/tripal_feature-delete.inc
  34. 79 79
      tripal_feature/tripal_feature-properties.inc
  35. 110 112
      tripal_feature/tripal_feature-relationships.inc
  36. 461 462
      tripal_feature/tripal_feature.admin.inc
  37. 99 99
      tripal_feature/tripal_feature.api.inc
  38. 21 0
      tripal_feature/tripal_feature.coder_ignores.txt
  39. 146 146
      tripal_feature/tripal_feature.install
  40. 436 437
      tripal_feature/tripal_feature.module
  41. 12 12
      tripal_feature/tripal_feature.views.inc
  42. 0 473
      tripal_feature/tripal_feature.views.inc.orig
  43. 1 1
      tripal_feature/views_handlers/views_handler_field_residues.inc
  44. 2 2
      tripal_genetic/tripal_genetic.module
  45. 8 8
      tripal_genetic/tripal_genetic.views.inc
  46. 12 7
      tripal_library/reindex.php
  47. 11 7
      tripal_library/taxonify.php
  48. 4 4
      tripal_library/tripal_library.api.inc
  49. 101 101
      tripal_library/tripal_library.install
  50. 531 531
      tripal_library/tripal_library.module
  51. 7 7
      tripal_library/tripal_library.views.inc
  52. 2 2
      tripal_natural_diversity/tripal_natural_diversity.module
  53. 8 8
      tripal_natural_diversity/tripal_natural_diversity.views.inc
  54. 18 18
      tripal_organism/tripal_organism.api.inc
  55. 61 61
      tripal_organism/tripal_organism.install
  56. 442 441
      tripal_organism/tripal_organism.module
  57. 14 14
      tripal_organism/tripal_organism.views.inc
  58. 2 2
      tripal_phenotype/tripal_phenotype.module
  59. 13 13
      tripal_phenotype/tripal_phenotype.views.inc
  60. 3 3
      tripal_project/tripal_project.admin.inc
  61. 3 3
      tripal_project/tripal_project.install
  62. 63 63
      tripal_project/tripal_project.module
  63. 7 7
      tripal_project/tripal_project.views.inc
  64. 5 6
      tripal_pub/tripal_pub.install
  65. 483 491
      tripal_pub/tripal_pub.module
  66. 13 13
      tripal_pub/tripal_pub.views.inc
  67. 8 0
      tripal_search/tripal_search.coder_ignores.txt
  68. 28 15
      tripal_search/tripal_search.module
  69. 3 3
      tripal_stock/other_module_api_functions.inc
  70. 147 147
      tripal_stock/tripal_stock-administration.inc
  71. 25 25
      tripal_stock/tripal_stock-db_references.inc
  72. 20 20
      tripal_stock/tripal_stock-properties.inc
  73. 29 29
      tripal_stock/tripal_stock-relationships.inc
  74. 10 3
      tripal_stock/tripal_stock.install
  75. 92 92
      tripal_stock/tripal_stock.module
  76. 46 46
      tripal_stock/tripal_stock.views.inc
  77. 11 1
      tripal_views/tripal_views.api.inc
  78. 9 16
      tripal_views/tripal_views.coder_ignores.txt
  79. 8 0
      tripal_views/tripal_views.views.inc
  80. 18 13
      tripal_views/tripal_views_integration.inc
  81. 409 0
      tripal_views/views/chado_linking.TMP.inc
  82. 1 0
      tripal_views/views/handlers/views_handler_argument_stockprop_id.inc
  83. 2 0
      tripal_views/views/handlers/views_handler_field_chado_rel_by_type.inc
  84. 0 173
      tripal_views/views/handlers/views_handler_field_chado_relationship_by_type.inc.orig
  85. 1 0
      tripal_views/views/handlers/views_handler_field_dbxref_accession_link.inc
  86. 1 0
      tripal_views/views/handlers/views_handler_filter_chado_select_cvterm_name.inc
  87. 0 258
      tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc.orig
  88. 3 0
      tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
  89. 0 355
      tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc.orig
  90. 1 0
      tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
  91. 0 340
      tripal_views/views/handlers/views_handler_filter_stockprop_id.inc.orig

+ 2 - 2
tripal_analysis/tripal_analysis.admin.inc

@@ -73,8 +73,8 @@ function tripal_analysis_module_description_page() {
             </ul>
             </p>';
 
-   $text .= '<h3>Page Customizations</h3>';
-   $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
+  $text .= '<h3>Page Customizations</h3>';
+  $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
              Below is a description of several methods.  These methods may be used in conjunction with one another to
              provide fine-grained control.
              <ul>

+ 8 - 8
tripal_analysis/tripal_analysis.api.inc

@@ -10,9 +10,9 @@
  * @ingroup tripal_analysis
  * @ingroup tripal_api
  */
-/****************************************************************************
+/**
  * @section Chado Table Descriptions
- ****************************************************************************/
+ */
 /**
  * Implements hook_chado_analysis_schema()
  * Purpose: To add descriptions and foreign keys to default table description
@@ -143,7 +143,7 @@ function tripal_analysis_chado_analysisprop_schema() {
  * @ingroup tripal_analysis_api
  */
 function tripal_analysis_get_property($analysis_id, $property) {
-   return tripal_core_get_property('analysis', $analysis_id, $property, 'tripal');
+  return tripal_core_get_property('analysis', $analysis_id, $property, 'tripal');
 }
 
 /**
@@ -188,7 +188,7 @@ function tripal_analysis_insert_property($analysis_id, $property, $value, $updat
  * @ingroup tripal_analysis_api
  */
 function tripal_analysis_update_property($analysis_id, $property, $value, $insert_if_missing = 0) {
-   return tripal_core_update_property('analysis', $analysis_id, $property, 'tripal', $value, $insert_if_missing);
+  return tripal_core_update_property('analysis', $analysis_id, $property, 'tripal', $value, $insert_if_missing);
 }
 
 /**
@@ -208,7 +208,7 @@ function tripal_analysis_update_property($analysis_id, $property, $value, $inser
  * @ingroup tripal_analysis_api
  */
 function tripal_analysis_delete_property($analysis_id, $property) {
-   return tripal_core_delete_property('analysis', $analysis_id, $property, 'tripal');
+  return tripal_core_delete_property('analysis', $analysis_id, $property, 'tripal');
 }
 /**
  * Retreives the node of a sync'ed analysis
@@ -222,10 +222,10 @@ function tripal_analysis_delete_property($analysis_id, $property) {
  * @ingroup tripal_analysis_api
  */
 function tripal_analysis_get_node($analysis_id) {
-   $sql = "SELECT *
+  $sql = "SELECT *
            FROM chado_analysis CA
               INNER JOIN node N on CA.nid = N.nid
            WHERE analysis_id = %d";
-   $node = db_fetch_object(db_query($sql, $analysis_id));
-   return $node;
+  $node = db_fetch_object(db_query($sql, $analysis_id));
+  return $node;
 }

+ 15 - 15
tripal_analysis/tripal_analysis.install

@@ -20,7 +20,7 @@ function tripal_analysis_install() {
   // table is used to store Blast xml and Interpro html/goterms
   $previous_db = tripal_db_set_active('chado');
   if (!db_table_exists('analysisfeatureprop')) {
-     $sql = "CREATE TABLE {analysisfeatureprop} (".
+    $sql = "CREATE TABLE {analysisfeatureprop} (".
             "  analysisfeatureprop_id SERIAL PRIMARY KEY, ".
             "  analysisfeature_id INTEGER NOT NULL REFERENCES analysisfeature(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
             "  type_id INTEGER NOT NULL REFERENCES cvterm(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, ".
@@ -28,11 +28,11 @@ function tripal_analysis_install() {
             "  rank INTEGER NOT NULL, ".
             "  CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)".
             ")";
-     db_query($sql);
+    db_query($sql);
   }
   tripal_db_set_active($previous_db);
 
-   tripal_cv_add_cvterm(array('name' => 'analysis_type', 'def' => 'The type of analysis was performed. This value is automatically set by each Tripal Analysis module and should be equal to the module name (e.g. tripal_analysis_blast, tripal_analysis_go).'), 'tripal', 0, 1, 'tripal');
+  tripal_cv_add_cvterm(array('name' => 'analysis_type', 'def' => 'The type of analysis was performed. This value is automatically set by each Tripal Analysis module and should be equal to the module name (e.g. tripal_analysis_blast, tripal_analysis_go).'), 'tripal', 0, 1, 'tripal');
   tripal_cv_add_cvterm(array('name' => 'analysis_date', 'def' => 'The date that an analysis was performed.'), 'tripal', 0, 1, 'tripal');
   tripal_cv_add_cvterm(array('name' => 'analysis_short_name', 'def' => 'A computer legible (no spaces ' .
       'or special characters) abbreviation for the analysis.'), 'tripal', 0, 1 , 'tripal');
@@ -116,17 +116,17 @@ function tripal_analysis_schema() {
  * before installation
  */
 function tripal_analysis_requirements($phase) {
-   $requirements = array();
-   if ($phase == 'install') {
-      if (!function_exists('tripal_create_moddir')) {
-         $requirements ['tripal_analysis'] = array(
+  $requirements = array();
+  if ($phase == 'install') {
+    if (!function_exists('tripal_create_moddir')) {
+      $requirements ['tripal_analysis'] = array(
             'title' => "tripal_analysis",
             'value' => "error. Some required modules are just being installed. Please try again.",
             'severity' => REQUIREMENT_ERROR,
-         );
+      );
       }
-   }
-   return $requirements;
+  }
+  return $requirements;
 }
 
 /*******************************************************************************
@@ -134,10 +134,10 @@ function tripal_analysis_requirements($phase) {
  */
 function tripal_analysis_update_6001() {
    // we have some new cvterms to add
-   tripal_cv_add_cvterm(array('name' => 'based_on_analysis', 'def' => 'The analysis that this analysis was based on. For example, blast/kegg/interpro analyses are based on a unigene analysis. The unigene analysis_id should be stored in analysisprop as the rank using this cvterm. The name of said unigene analysis can be inserted as the value in analysisprop.'), 'tripal', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'additional_files', 'def' => 'Additional files for this analysis. Each file should be separated by a semi-colon and have this format: <file description>, <file path>;'), 'tripal', 0, 1, 'tripal');
-   $ret = array(
+  tripal_cv_add_cvterm(array('name' => 'based_on_analysis', 'def' => 'The analysis that this analysis was based on. For example, blast/kegg/interpro analyses are based on a unigene analysis. The unigene analysis_id should be stored in analysisprop as the rank using this cvterm. The name of said unigene analysis can be inserted as the value in analysisprop.'), 'tripal', 0, 1, 'tripal');
+  tripal_cv_add_cvterm(array('name' => 'additional_files', 'def' => 'Additional files for this analysis. Each file should be separated by a semi-colon and have this format: <file description>, <file path>;'), 'tripal', 0, 1, 'tripal');
+  $ret = array(
       '#finished' => 1,
-   );
-   return $ret;
+  );
+  return $ret;
 }

+ 92 - 92
tripal_analysis/tripal_analysis.module

@@ -23,8 +23,8 @@ require('tripal_analysis_privacy.inc');
  * @ingroup tripal_analysis
  */
 function tripal_analysis_register_child($modulename) {
-   $sql = "INSERT INTO {tripal_analysis} (modulename) VALUES ('%s')";
-   db_query($sql, $modulename);
+  $sql = "INSERT INTO {tripal_analysis} (modulename) VALUES ('%s')";
+  db_query($sql, $modulename);
 }
 /**
  *
@@ -32,10 +32,10 @@ function tripal_analysis_register_child($modulename) {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_unregister_child($modulename) {
-   if (db_table_exists('tripal_analysis')) {
+  if (db_table_exists('tripal_analysis')) {
       $sql = "DELETE FROM {tripal_analysis} WHERE modulename = '%s'";
       db_query($sql, $modulename);
-   }
+  }
 }
 
 /**
@@ -43,12 +43,12 @@ function tripal_analysis_unregister_child($modulename) {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_init() {
-   drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_analysis.js');
+  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_analysis.js');
 }
 
 /**
- * tripal_analysis_menu()
- * HOOK: Implementation of hook_menu()
+ * tripal_analysis_menu().
+ * Implementation of hook_menu().
  * Entry points and paths of the module
  *
  * @ingroup tripal_analysis
@@ -57,14 +57,14 @@ function tripal_analysis_menu() {
   // Display available analyses
   $items['analyses'] = array(
       'menu_name' => ('primary-links'), //Enable the 'Analysis' primary link
-      'title' => t('Analyses'),
+      'title' => 'Analyses',
       'page callback' => 'tripal_analysis_show_analyses',
       'access arguments' => array('access chado_analysis content'),
       'type' => MENU_NORMAL_ITEM
   );
   //Sync analysis
   $items['chado_sync_analyses'] = array(
-     'title' => t('Sync Data'),
+     'title' => 'Sync Data',
      'page callback' => 'tripal_analysis_sync_analyses',
      'access arguments' => array('administer site configuration'),
      'type' => MENU_CALLBACK
@@ -174,8 +174,8 @@ function chado_analysis_insert($node) {
           'timeexecuted' => $timestamp
       );
       if (tripal_core_chado_insert('analysis', $values)) {
-         $analysis = tripal_core_chado_select('analysis', array('*'), $values);
-         $analysis_id = $analysis[0]->analysis_id;
+        $analysis = tripal_core_chado_select('analysis', array('*'), $values);
+        $analysis_id = $analysis[0]->analysis_id;
       }
   }
 
@@ -215,8 +215,8 @@ function chado_analysis_insert($node) {
 
    // add the analysis to the node object for
    // use by other analysis modules that may be using this function
-   $node->analysis = $analysis;
-   $node->analysis_id = $analysis_id; // we need to set this for children
+    $node->analysis = $analysis;
+    $node->analysis_id = $analysis_id; // we need to set this for children
 }
 /**
  *
@@ -327,53 +327,53 @@ function chado_analysis_update($node) {
  */
 function chado_analysis_form($node) {
 
-   $analysis = $node->analysis;
-
-   // add in the description column. It is a text field and may not be included
-   // if the text is too big.
-   $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
-
-   // get form defaults
-   $analysis_id = $node->analysis_id;
-   if (!$analysis_id) {
-      $analysis_id = $analysis->analysis_id;
-   }
-   $analysisname = $node->analysisname;
-   if (!$analysisname) {
-      $analysisname = $analysis->name;
-   }
-   $program = $node->program;
-   if (!$program) {
-      $program = $analysis->program;
-   }
-   $programversion = $node->programversion;
-   if (!$programversion) {
-      $programversion = $analysis->programversion;
-   }
-   $algorithm = $node->algorithm;
-   if (!$algorithm) {
-      $algorithm = $analysis->algorithm;
-   }
-   $sourcename = $node->sourcename;
-   if (!$sourcename) {
-      $sourcename = $analysis->sourcename;
-   }
-   $sourceversion = $node->sourceversion;
-   if (!$sourceversion) {
-      $sourceversion = $analysis->sourceversion;
-   }
-   $sourceuri = $node->sourceuri;
-   if (!$sourceuri) {
-      $sourceuri = $analysis->sourceuri;
-   }
-   $timeexecuted = $node->timeexecuted;
-   if (!$timeexecuted) {
-      $timeexecuted = $analysis->timeexecuted;
-   }
-   $description = $node->description;
-   if (!$description) {
-      $description = $analysis->description;
-   }
+  $analysis = $node->analysis;
+
+  // add in the description column. It is a text field and may not be included
+  // if the text is too big.
+  $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
+
+  // get form defaults
+  $analysis_id = $node->analysis_id;
+  if (!$analysis_id) {
+    $analysis_id = $analysis->analysis_id;
+  }
+    $analysisname = $node->analysisname;
+  if (!$analysisname) {
+    $analysisname = $analysis->name;
+  }
+    $program = $node->program;
+  if (!$program) {
+    $program = $analysis->program;
+  }
+    $programversion = $node->programversion;
+  if (!$programversion) {
+    $programversion = $analysis->programversion;
+  }
+    $algorithm = $node->algorithm;
+  if (!$algorithm) {
+    $algorithm = $analysis->algorithm;
+  }
+    $sourcename = $node->sourcename;
+  if (!$sourcename) {
+    $sourcename = $analysis->sourcename;
+  }
+    $sourceversion = $node->sourceversion;
+  if (!$sourceversion) {
+    $sourceversion = $analysis->sourceversion;
+  }
+    $sourceuri = $node->sourceuri;
+  if (!$sourceuri) {
+    $sourceuri = $analysis->sourceuri;
+  }
+    $timeexecuted = $node->timeexecuted;
+  if (!$timeexecuted) {
+    $timeexecuted = $analysis->timeexecuted;
+  }
+    $description = $node->description;
+  if (!$description) {
+    $description = $analysis->description;
+  }
   $form = array();
   $form['title']= array(
       '#type' => 'hidden',
@@ -482,23 +482,23 @@ function chado_analysis_form($node) {
   return $form;
 }
 
-/**
- *  When a node is requested by the user this function is called to allow us
- *  to add auxiliary data to the node object.
- *
- * @ingroup tripal_analysis
- */
+ /**
+  *  When a node is requested by the user this function is called to allow us
+  *  to add auxiliary data to the node object.
+  *
+  * @ingroup tripal_analysis
+  */
 function chado_analysis_load($node) {
 
    // get the feature details from chado
-   $analysis_id = chado_get_id_for_node('analysis', $node);
+  $analysis_id = chado_get_id_for_node('analysis', $node);
 
-   $values = array('analysis_id' => $analysis_id);
-   $analysis = tripal_core_generate_chado_var('analysis', $values);
+  $values = array('analysis_id' => $analysis_id);
+  $analysis = tripal_core_generate_chado_var('analysis', $values);
 
-   $additions = new stdClass();
-   $additions->analysis = $analysis;
-   return $additions;
+  $additions = new stdClass();
+  $additions->analysis = $analysis;
+  return $additions;
 }
 
 /**
@@ -601,10 +601,10 @@ function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
          // This is a kegg analysis
         }
         elseif ($analysis_type->value == 'tripal_analysis_kegg' ) {
-           $new_node->type = 'chado_analysis_kegg';
+          $new_node->type = 'chado_analysis_kegg';
         }
         else {
-           $new_node->type = 'chado_analysis';
+          $new_node->type = 'chado_analysis';
         }
       // If it doesn't exist, this analysis is generic
       }
@@ -649,12 +649,12 @@ function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
         node_save($node);
 
         if ($node->nid) {
-          $page_content .= "Added $new_node->title<br>";
+          $page_content .= "Added $new_node->title<br />";
         }
       }
     }
     else {
-      $page_content .= "Skipped $new_node->title<br>";
+      $page_content .= "Skipped $new_node->title<br />";
     }
   }
   return $page_content;
@@ -666,12 +666,12 @@ function tripal_analysis_sync_analyses($analysis_id = NULL, $job_id = NULL) {
  */
 function chado_analysis_validate($node, &$form) {
    // use the analysis parent to validate the node
-   tripal_analysis_validate($node, $form);
+  tripal_analysis_validate($node, $form);
 }
 /**
- *
- *@ingroup tripal_analysis
- */
+  *
+  * @ingroup tripal_analysis
+  */
 function tripal_analysis_validate($node, &$form) {
 ##dprint_r($node);
 
@@ -715,9 +715,9 @@ function tripal_analysis_validate($node, &$form) {
             );
             $analysis = tripal_core_chado_select('analysis', array('analysis_id'), $values);
             if (sizeof($analysis) > 0) {
-               form_set_error('program', 'Cannot add the analysis with this program,
+              form_set_error('program', 'Cannot add the analysis with this program,
                   program version and source name. An analysis with these values already exists.');
-               return;
+              return;
             }
         }
     }
@@ -767,10 +767,10 @@ function chado_analysis_access($op, $node, $account) {
   }
   if ($op == 'view') {
     if (!user_access('access chado_analysis content', $account)) {
-         return FALSE;
+      return FALSE;
       }
   }
-   return NULL;
+    return NULL;
 }
 
 /**
@@ -853,13 +853,13 @@ function get_chado_analyses() {
  */
 function theme_tripal_analysis_analysis_page($analyses) {
 
-  $output = "<br>Analyses are listed in the descending order of their execution time.<br><a id=\"tripal_expandableBox_toggle_button\" onClick=\"toggleExpandableBoxes()\">[-] Collapse All</a>";
+  $output = "<br />Analyses are listed in the descending order of their execution time.<br /><a id=\"tripal_expandableBox_toggle_button\" onClick=\"toggleExpandableBoxes()\">[-] Collapse All</a>";
 
-   foreach ($analyses as $analysis) {
+  foreach ($analyses as $analysis) {
     // Prepare information for html output
     $ana_node_url = url("node/$analysis->node_id");
-     if ($analysis->sourceversion) {
-         $ver = "($analysis->sourceversion)";
+    if ($analysis->sourceversion) {
+      $ver = "($analysis->sourceversion)";
       }
       $date =  preg_replace("/^(\d+-\d+-\d+) .*/", "$1", $analysis->timeexecuted);
 
@@ -1057,7 +1057,7 @@ function tripal_analysis_taxonify_features ($analysis_id = NULL, $job_id = NULL)
     $i++;
   }
 }
-*/
+ */
 /**
  * Implements hook_views_api()
  * Purpose: Essentially this hook tells drupal that there is views support for
@@ -1067,7 +1067,7 @@ function tripal_analysis_taxonify_features ($analysis_id = NULL, $job_id = NULL)
  * @ingroup tripal_analysis
  */
 function tripal_analysis_views_api() {
-   return array(
-      'api' => 2.0,
-   );
+    return array(
+    'api' => 2.0,
+  );
 }

+ 6 - 6
tripal_analysis/tripal_analysis.views.inc

@@ -33,12 +33,12 @@ function tripal_analysis_views_data()  {
   $data = array();
 
   if (module_exists('tripal_views')) {
-		// Base Table: Analysis
-		$tablename = 'analysis';
-		if (!tripal_views_is_integrated($tablename, 10)) {
-			$table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
-			tripal_views_integration_add_entry($table_integration_array);
-		}
+    // Base Table: Analysis
+    $tablename = 'analysis';
+    if (!tripal_views_is_integrated($tablename, 10)) {
+      $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
+      tripal_views_integration_add_entry($table_integration_array);
+    }
 
 
     $tables = array(

+ 146 - 92
tripal_bulk_loader/tripal_bulk_loader.admin.inc

@@ -11,24 +11,24 @@
 function tripal_bulk_loader_admin_template() {
   $output = '';
 
-  $output .= '<br><h3>Quick Links:</h3>';
-  $output .= l('Create a new bulk loader template', 'admin/tripal/tripal_bulk_loader_template/create') . "<br>";
-  $output .= l('Edit a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/edit') . "<br>";
-  $output .= l('Delete a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/delete') . "<br>";
-  $output .= l('Export a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/export') . "<br>";
-  $output .= l('Import a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/import') . "<br>";
-  $output .= '<br>';
+  $output .= '<br /><h3>Quick Links:</h3>';
+  $output .= l(t('Create a new bulk loader template'), 'admin/tripal/tripal_bulk_loader_template/create') . "<br />";
+  $output .= l(t('Edit a bulk loader template'), 'admin/tripal/tripal_bulk_loader_template/edit') . "<br />";
+  $output .= l(t('Delete a bulk loader template'), 'admin/tripal/tripal_bulk_loader_template/delete') . "<br />";
+  $output .= l(t('Export a bulk loader template'), 'admin/tripal/tripal_bulk_loader_template/export') . "<br />";
+  $output .= l(t('Import a bulk loader template'), 'admin/tripal/tripal_bulk_loader_template/import') . "<br />";
+  $output .= '<br />';
 
   $output .= '<h3>Module Description:</h3>';
   $output .= '<p>This module provides the ability to create loading templates for any tab-delimited '
     . 'data file allowing it to be loaded into chado. The Loading Templates are a direct mapping '
     . 'between the columns in your file and the columns in chado tables. As such to use this tool '
     . 'you need to be very familar with the chado schema -See '
-    . l('Chado -Getting Started', 'http://gmod.org/wiki/Chado_-_Getting_Started')
+    . l(t('Chado -Getting Started'), 'http://gmod.org/wiki/Chado_-_Getting_Started')
     . '. The ability to add constants and specify foreign key contraints is also provided '
     . 'in order for the loader to fill chado columns which may be required but are not specified '
     . 'in your input file.</p>';
-  $output .= '<br>';
+  $output .= '<br />';
 
   $output .= '<h3>Setup Instructions</h3>';
   $output .= '<p>After intallation of the bulk loader module, the following tasks should be performed:</p>';
@@ -64,6 +64,54 @@ function tripal_bulk_loader_configuration_form($form_state = NULL) {
     '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE),
   );
 
+  $form['speed']['disable_triggers'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Delay Constraint Checking during loading job.'),
+    '#description' => t('This delays the constraint checking until the end of the
+    loading proccess.'),
+    '#default_value' => variable_get('tripal_bulk_loader_disable_triggers', TRUE),
+  );
+
+  $form['speed']['no_validate'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Skip Validation at the Tripal Core API level'),
+    '#description' => t('If an error is encountered, the Tripal core API will try
+      to provide informative error messages. With this turned off, you will not benifit
+      from these more informative error messages; however, your job will load faster
+      since it doesn\'t have to do the additional checking before inserting.'),
+    '#default_value' => variable_get('tripal_bulk_loader_skip_validation', FALSE),
+  );
+
+  $form['speed']['transactions'] = array(
+    '#type' => 'radios',
+    '#title' => t('Transaction Rollback when an error is encountered'),
+    '#options' => array(
+      'all' => t('Rollback the last constant set.'
+        .'<div class="description"If you added more then one constant set then the
+        successfully loaded constant sets will not be rolled back. However, once an error
+        is encountered no further constant sets will be loaded either.</div>'),
+      'row' => t('Only Rollback the last line of the input file.'
+        .'<div class="description">This option may allow you to restart the job after
+        fixing the error (manual intervention needed).</div>'),
+      'none' => t('Do not use transactions<div class="description">This is not recommended.</div>')
+    ),
+    '#default_value' => variable_get('tripal_bulk_loader_transactions',   'row')
+  );
+
+  $form['speed']['lock'] = array(
+    '#type' => 'radios',
+    '#title' => t('Lock Type'),
+    '#description' => t('The type of lock used by the bulk loading jobs. The lock is '
+      .'acquired at the beginning of the job and kept till the end. A lock of the type '
+      .'selected will be acquired for every table being inserted into.'),
+    '#options' => array(
+      'ROW EXCLUSIVE' => t('ROW EXCLUSIVE: The default lock type for insert queries.'),
+      'EXCLUSIVE' => t('EXCLUSIVE: Only Select Queries can access the table.'),
+      'ACCESS EXCLUSIVE' => t('ACCESS EXCLUSIVE: No other queries can access the table.'),
+    ),
+    '#default_value' => variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE'),
+  );
+
   $form['submit1'] = array(
     '#type' => 'submit',
     '#value' => t('Save')
@@ -78,6 +126,11 @@ function tripal_bulk_loader_configuration_form($form_state = NULL) {
 function tripal_bulk_loader_configuration_form_submit($form, $form_state) {
 
   variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']);
+  variable_set('tripal_bulk_loader_disable_triggers', $form_state['values']['disable_triggers']);
+  variable_set('tripal_bulk_loader_skip_validation', $form_state['values']['no_validate']);
+  variable_set('tripal_bulk_loader_transactions', $form_state['values']['transactions']);
+  variable_set('tripal_bulk_loader_lock', $form_state['values']['lock']);
+
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
@@ -92,7 +145,7 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
   $form = array();
 
    // get template id from path and rebuild form
-   if ($_GET['template_id']) {
+  if ($_GET['template_id']) {
     if (preg_match('/^\d+$/', $_GET['template_id'])) {
       $form_state['storage']['template_id'] = $_GET['template_id'];
     }
@@ -105,7 +158,7 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
     $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;
     }
   }
@@ -117,15 +170,15 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
 
   if ($form_state['storage']['template_id']) {
     $form['template_name'] = array(
-        '#type' => 'item',
-        '#title' => 'Template',
-        '#value' => $form_state['storage']['template_name'],
-        '#weight' => 1,
+      '#type' => 'item',
+      '#title' => 'Template',
+      '#value' => $form_state['storage']['template_name'],
+      '#weight' => 1,
     );
   }
   else {
     if (preg_match('/create/', $mode)) {
-     $form['new_template_name'] = array(
+      $form['new_template_name'] = array(
         '#type' => 'textfield',
         '#title' => 'Template Name',
         '#weight' => 1,
@@ -210,11 +263,11 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
         $form['records']['records-data'][$priority] = array(
           'title' => array(
             '#type' => 'markup',
-            '#value' => $table_array['record_id'],
+            '#value' => filter_xss($table_array['record_id']),
           ),
           'chado_table' => array(
             '#type' => 'markup',
-            '#value' => $table_array['table'],
+            '#value' => filter_xss($table_array['table']),
           ),
           'mode' => array(
             '#type' => 'item',
@@ -340,6 +393,7 @@ function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode)
     '#value' => $value,
     '#weight' => 4,
   );
+
   return $form;
 }
 
@@ -369,8 +423,8 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
       $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;
       }
     break;
@@ -390,11 +444,11 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
     case 'Save Order':
       $new_template = $form_state['storage']['template'];
       // unset old elements
-       $form_state['storage']['record2priority'] = array();
+      $form_state['storage']['record2priority'] = array();
       foreach ($new_template as $priority => $record_array) {
         if (preg_match('/\d+/', $priority)) {
-           unset($new_template[$priority]);
-         }
+          unset($new_template[$priority]);
+        }
       }
       //set elements in new order
       foreach ($form_state['values']['records-data'] as $item) {
@@ -460,7 +514,7 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
         unset($form_state['storage']['record2priority'][$form_state['storage']['template'][$priority]['record_id']]);
         unset($form_state['storage']['template'][$priority]);
       }
-      drupal_set_message('Deleted Field from Template.');
+      drupal_set_message(t('Deleted Field from Template.'));
     break;
   } //end of switch
 
@@ -470,7 +524,7 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
     'template_array' => serialize($form_state['storage']['template'])
   );
   drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
-  drupal_set_message('Template Saved.');
+  drupal_set_message(t('Template Saved.'));
 
 }
 
@@ -551,7 +605,7 @@ function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mod
   );
 
   if (preg_match('/import/', $mode)) {
-   $form['new_template_name'] = array(
+    $form['new_template_name'] = array(
       '#type' => 'textfield',
       '#title' => 'Template Name',
       '#weight' => 1,
@@ -616,7 +670,7 @@ function tripal_bulk_loader_import_export_template_form_submit($form, &$form_sta
       );
       drupal_write_record('tripal_bulk_loader_template', $record);
       if ($record->template_id) {
-        drupal_set_message('Successfully imported Tripal Bulk Loader Template.');
+        drupal_set_message(t('Successfully imported Tripal Bulk Loader Template.'));
       }
     break;
   }
@@ -640,20 +694,20 @@ function tripal_bulk_loader_import_export_template_form_submit($form, &$form_sta
  *   A form array to be rendered by drupal_get_form
  */
 function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
-   $form['#cache'] = TRUE; // Make sure the form is cached.
+  $form['#cache'] = TRUE; // Make sure the form is cached.
 
    // get template id from path
-   $template_id = ($_GET['template_id'] !== NULL) ? $_GET['template_id'] : $form_state['values']['template_id'];
+  $template_id = ($_GET['template_id'] !== NULL) ? $_GET['template_id'] : $form_state['values']['template_id'];
 
-   // if there is no template supplied don't return rest of form
-   if (!$template_id) {
-     return $form;
-   }
+  // if there is no template supplied don't return rest of form
+  if (!$template_id) {
+    return $form;
+  }
 
   // Pre-process values/defaults ---------------------------
 
-   // If this is the first load of the form (no form state) we need to initialize some variables
-   if (!$form_state['storage']['template']) {
+  // If this is the first load of the form (no form state) we need to initialize some variables
+  if (!$form_state['storage']['template']) {
     $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
     $template = db_fetch_object(db_query($sql, $template_id));
     $form_state['storage']['template_array'] = unserialize($template->template_array);
@@ -662,8 +716,8 @@ function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
     $form_state['storage']['record2priority'] = array();
     foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
       if (!is_array($record_array)) {
-         continue;
-       }
+        continue;
+      }
       $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
     }
 
@@ -673,10 +727,10 @@ function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
     $template = $form_state['storage']['template'];
   }
 
-   // get the record_id from the path
-   if ($_GET['record_id'] !== NULL) {
-     $form_state['values']['field_group'] = $_GET['record_id'];
-     $form_state['storage']['original_priority'] = $_GET['record_id'];
+  // get the record_id from the path
+  if ($_GET['record_id'] !== NULL) {
+    $form_state['values']['field_group'] = $_GET['record_id'];
+    $form_state['storage']['original_priority'] = $_GET['record_id'];
   }
 
 
@@ -801,8 +855,8 @@ function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state
       $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
       if ($success) {
-        drupal_set_message('Successfully Updated Template Record');
-        drupal_set_message('Template Saved.');
+        drupal_set_message(t('Successfully Updated Template Record'));
+        drupal_set_message(t('Template Saved.'));
 
         $path = explode('?', $form_state['storage']['referring URL']);
         parse_str($path[1], $query);
@@ -810,7 +864,7 @@ function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state
         drupal_goto($path[0], $query);
       }
       else {
-        drupal_set_message('Unable to Save Template!', 'error');
+        drupal_set_message(t('Unable to Save Template!'), 'error');
         watchdog('T_bulk_loader',
           'Unable to save bulk loader template: %template',
           array('%template' => print_r($form_state['storage']['template'], TRUE)),
@@ -848,32 +902,32 @@ function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state
  */
 function tripal_bulk_loader_add_template_field_form(&$form_state = NULL) {
   $form = array();
-   $form['#cache'] = TRUE; // Make sure the form is cached.
+  $form['#cache'] = TRUE; // Make sure the form is cached.
 
-   // get template id from path
-   $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
+  // get template id from path
+  $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
 
-   // if there is no template supplied don't return rest of form
-   if (!$template_id) {
-     return $form;
-   }
+  // if there is no template supplied don't return rest of form
+  if (!$template_id) {
+    return $form;
+  }
 
   // Pre-set Variables needed for form proper------------------------------------------
 
    // If this is the first load of the form (no form state) we need to initialize some variables
-   if (!$form_state['storage']['template']) {
+  if (!$form_state['storage']['template']) {
     $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
     $template = db_fetch_object(db_query($sql, $template_id));
     $form_state['storage']['template_array'] = unserialize($template->template_array);
     $form_state['storage']['template'] = $template;
 
     $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;
+  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;
+  }
 
     $form_state['storage']['referring URL'] = $_SERVER["HTTP_REFERER"];
   }
@@ -904,8 +958,8 @@ function tripal_bulk_loader_add_template_field_form(&$form_state = NULL) {
   }
 
    // get the record_id from the path
-   if ($_GET['record_id'] !== NULL) {
-     $form_state['values']['field_group'] = $_GET['record_id'];
+  if ($_GET['record_id'] !== NULL) {
+    $form_state['values']['field_group'] = $_GET['record_id'];
     if (preg_match('/\d+/', $_GET['record_id'])) {
       $priority = $form_state['values']['field_group'];
       $table = $form_state['storage']['template_array'][$priority]['table'];
@@ -1257,9 +1311,9 @@ function tripal_bulk_loader_add_template_field_form(&$form_state = NULL) {
     $form['add_fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
       .'The following references are also available for spreadsheet fields: <b><#column:<i>number</i>#></b>. '
       .'This allows you to substitute other spreadsheet values into the current field. For example, '
-      .'if you had the following line:<br>'
+      .'if you had the following line:<br />'
       . $tab . 'SNP' . $tab . '15-Jan-2011' . $tab . '1' . $tab . '54' . $tab . 'Contig34355'
-      .'<br> and your current field is for column #1 and you\'re inserting into the chado field '
+      .'<br /> and your current field is for column #1 and you\'re inserting into the chado field '
       .'feature.uniquename then you might want to add in the data to ensure your uniquename is '
       .'unique. The Match Pattern is (.*) to select all the first column and the Replacement '
       .'Pattern could be \1_<#column:2#> which would insert SNP_15-Jan-2011 into the database.</p>';
@@ -1387,8 +1441,8 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
       $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
       if ($success) {
-        drupal_set_message('Successfully Added Field to Template');
-        drupal_set_message('Template Saved.');
+        drupal_set_message(t('Successfully Added Field to Template'));
+        drupal_set_message(t('Template Saved.'));
 
         $path = explode('?', $form_state['storage']['referring URL']);
         parse_str($path[1], $query);
@@ -1396,7 +1450,7 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
         drupal_goto($path[0], $query);
       }
       else {
-        drupal_set_message('Unable to Save Template!', 'error');
+        drupal_set_message(t('Unable to Save Template!'), 'error');
         watchdog('T_bulk_loader',
           'Unable to save bulk loader template: %template',
           array('%template' => print_r($form_state['storage']['template'], TRUE)),
@@ -1415,7 +1469,7 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
       // Add transformation rule to original field
       $form_state['storage']['regex']['pattern'][] = '/' . $form_state['values']['pattern'] . '/';
       $form_state['storage']['regex']['replace'][] = $form_state['values']['replace'];
-      drupal_set_message('Successfully Added Transformation Rule');
+      drupal_set_message(t('Successfully Added Transformation Rule'));
 
     }
     elseif ($op == 'Save Transformation Rule Order') {
@@ -1472,20 +1526,20 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
  */
 function tripal_bulk_loader_edit_template_field_form(&$form_state = NULL) {
   $form = array();
-   $form['#cache'] = TRUE; // Make sure the form is cached.
+  $form['#cache'] = TRUE; // Make sure the form is cached.
 
-   // get template id from path
-   $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
+  // get template id from path
+  $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
 
-   // if there is no template supplied don't return rest of form
-   if (!$template_id) {
-     return $form;
-   }
+  // if there is no template supplied don't return rest of form
+  if (!$template_id) {
+    return $form;
+  }
 
   // Pre-set Variables needed for form proper------------------------------------------
 
-   // If this is the first load of the form (no form state) we need to initialize some variables
-   if (!$form_state['storage']['template']) {
+  // If this is the first load of the form (no form state) we need to initialize some variables
+  if (!$form_state['storage']['template']) {
     $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
     $template = db_fetch_object(db_query($sql, $template_id));
     $form_state['storage']['template_array'] = unserialize($template->template_array);
@@ -1494,8 +1548,8 @@ function tripal_bulk_loader_edit_template_field_form(&$form_state = NULL) {
     $form_state['storage']['record2priority'] = array();
     foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
       if (!is_array($record_array)) {
-         continue;
-       }
+        continue;
+      }
       $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
     }
 
@@ -1865,9 +1919,9 @@ function tripal_bulk_loader_edit_template_field_form(&$form_state = NULL) {
     $form['edit_fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
       .'The following references are also available for spreadsheet fields: <b><#column:<i>number</i>#></b>. '
       .'This allows you to substitute other spreadsheet values into the current field. For example, '
-      .'if you had the following line:<br>'
+      .'if you had the following line:<br />'
       . $tab . 'SNP' . $tab . '15-Jan-2011' . $tab . '1' . $tab . '54' . $tab . 'Contig34355'
-      .'<br> and your current field is for column #1 and you\'re inserting into the chado field '
+      .'<br /> and your current field is for column #1 and you\'re inserting into the chado field '
       .'feature.uniquename then you might want to add in the data to ensure your uniquename is '
       .'unique. The Match Pattern is (.*) to select all the first column and the Replacement '
       .'Pattern could be \1_<#column:2#> which would insert SNP_15-Jan-2011 into the database.</p>';
@@ -2008,8 +2062,8 @@ function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state)
       $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
       if ($success) {
-        drupal_set_message('Successfully Updated Field');
-        drupal_set_message('Template Saved.');
+        drupal_set_message(t('Successfully Updated Field'));
+        drupal_set_message(t('Template Saved.'));
 
         $path = explode('?', $form_state['storage']['referring URL']);
         parse_str($path[1], $query);
@@ -2017,7 +2071,7 @@ function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state)
         drupal_goto($path[0], $query);
       }
       else {
-        drupal_set_message('Unable to Save Template!', 'error');
+        drupal_set_message(t('Unable to Save Template!'), 'error');
         watchdog('T_bulk_loader',
           'Unable to save bulk loader template: %template',
           array('%template' => print_r($form_state['storage']['template'], TRUE)),
@@ -2050,11 +2104,11 @@ function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state)
       $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
       if ($success) {
-        drupal_set_message('Successfully Added Transformation Rule');
-        drupal_set_message('Template Saved.');
+        drupal_set_message(t('Successfully Added Transformation Rule'));
+        drupal_set_message(t('Template Saved.'));
       }
       else {
-        drupal_set_message('Unable to Save Template!', 'error');
+        drupal_set_message(t('Unable to Save Template!'), 'error');
         watchdog('T_bulk_loader',
           'Unable to save bulk loader template: %template',
           array('%template' => print_r($form_state['storage']['template'], TRUE)),
@@ -2087,11 +2141,11 @@ function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state)
       $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
       if ($success) {
-        drupal_set_message('Successfully Reordered Transformation Rules');
-        drupal_set_message('Template Saved.');
+        drupal_set_message(t('Successfully Reordered Transformation Rules'));
+        drupal_set_message(t('Template Saved.'));
       }
       else {
-        drupal_set_message('Unable to Save Template!', 'error');
+        drupal_set_message(t('Unable to Save Template!'), 'error');
         watchdog('T_bulk_loader',
           'Unable to save bulk loader template: %template',
           array('%template' => print_r($form_state['storage']['template'], TRUE)),
@@ -2115,11 +2169,11 @@ function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state)
       $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
 
       if ($success) {
-        drupal_set_message('Successfully Reordered Transformation Rules');
-        drupal_set_message('Template Saved.');
+        drupal_set_message(t('Successfully Reordered Transformation Rules'));
+        drupal_set_message(t('Template Saved.'));
       }
       else {
-        drupal_set_message('Unable to Save Template!', 'error');
+        drupal_set_message(t('Unable to Save Template!'), 'error');
         watchdog('T_bulk_loader',
           'Unable to save bulk loader template: %template',
           array('%template' => print_r($form_state['storage']['template'], TRUE)),
@@ -2153,7 +2207,7 @@ function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state)
 function tripal_bulk_loader_add_field_ahah() {
 
   $form_state = array('storage' => NULL, 'submitted' => FALSE);
-  $form_build_id = $_POST['form_build_id'];
+  $form_build_id = filter_xss($_POST['form_build_id']);
   $form = form_get_cache($form_build_id, $form_state);
   $args = $form['#parameters'];
   $form_id = array_shift($args);
@@ -2188,7 +2242,7 @@ function tripal_bulk_loader_add_field_ahah() {
 function tripal_bulk_loader_edit_field_ahah() {
 
   $form_state = array('storage' => NULL, 'submitted' => FALSE);
-  $form_build_id = $_POST['form_build_id'];
+  $form_build_id = filter_xss($_POST['form_build_id']);
   $form = form_get_cache($form_build_id, $form_state);
   $args = $form['#parameters'];
   $form_id = array_shift($args);

+ 0 - 2427
tripal_bulk_loader/tripal_bulk_loader.admin.inc.orig

@@ -1,2427 +0,0 @@
-<?php
-
-/**
- * @file
- * Handles Create/Edit/Delete Template Admin Forms
- */
-
-/**
- * Provides a description page and quick links for the bulk loader
- */
-<<<<<<< HEAD
-function tripal_bulk_loader_admin_template() {
-  $output = '';
-
-  $output .= '<br><h3>Quick Links:</h3>';
-  $output .= l('Create a new bulk loader template', 'admin/tripal/tripal_bulk_loader_template/create') . "<br>";
-  $output .= l('Edit a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/edit') . "<br>";
-  $output .= l('Delete a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/delete') . "<br>";
-  $output .= l('Export a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/export') . "<br>";
-  $output .= l('Import a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/import') . "<br>";
-=======
-function tripal_bulk_loader_admin_template () {
-	$output = '';
-
-	$output .= '<br><h3>Quick Links:</h3>';
-  $output .= l('Create a new bulk loader template', 'admin/tripal/tripal_bulk_loader_template/create')."<br>";
-  $output .= l('Edit a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/edit')."<br>";
-  $output .= l('Delete a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/delete')."<br>";
-  $output .= l('Export a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/export')."<br>";
-  $output .= l('Import a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/import')."<br>";
->>>>>>> 6.x-0.4-dev
-  $output .= '<br>';
-
-  $output .= '<h3>Module Description:</h3>';
-  $output .= '<p>This module provides the ability to create loading templates for any tab-delimited '
-    . 'data file allowing it to be loaded into chado. The Loading Templates are a direct mapping '
-    . 'between the columns in your file and the columns in chado tables. As such to use this tool '
-    . 'you need to be very familar with the chado schema -See '
-    . l('Chado -Getting Started', 'http://gmod.org/wiki/Chado_-_Getting_Started')
-    . '. The ability to add constants and specify foreign key contraints is also provided '
-    . 'in order for the loader to fill chado columns which may be required but are not specified '
-    . 'in your input file.</p>';
-  $output .= '<br>';
-
-  $output .= '<h3>Setup Instructions</h3>';
-  $output .= '<p>After intallation of the bulk loader module, the following tasks should be performed:</p>';
-  $output .= '<ol>';
-  $output .= '<li><b>Install Theme:</b> In order for Bulk Loading pages to be displayed correctly, '
-    .'the contents of the Tripal Bulk Loader theme directory ([drupal root]/sites/all/modules/tripal/tripal_bulk_loader/theme) '
-    .'should be moved to the base directory of the Tripal theme ([drupal root]/sites/all/themes/tripal). '
-    .'Finally the drupal cache should be cleared for the new theme to take effect -navigate to admin/settings/performance '
-    .'and click the Clear Cached Data button.</li>';
-  $output .= '</ol>';
-
-  return $output;
-}
-
-/**
- * A Configuration form for this module
- */
-function tripal_bulk_loader_configuration_form($form_state = NULL) {
-  $form = array();
-
-  $form['speed'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Possible Speed Improvements'),
-  );
-
-  $form['speed']['prepare'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Use Prepared Statements'),
-    '#description' => t('SQL Prepared Statements allow for SQL queries which will be run '
-      .'many times to be parsed, rewritten and planned only once rather then every time '
-      .'the query is run. In the case of the bulk loader, this ensures that planning only '
-      .'occurs once for each "record" in your bulk loading template.'),
-    '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE),
-  );
-
-  $form['submit1'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save')
-  );
-
-  return $form;
-}
-
-/**
- * A Configuration form for this module (Submit)
- */
-function tripal_bulk_loader_configuration_form_submit($form, $form_state) {
-
-  variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Modify Template
-//////////////////////////////////////////////////////////////////////////////////////
-
-
-/**
- * The main form reached at admin/tripal/tripal_bulk_loader/create and /edit
- */
-function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode) {
-  $form = array();
-
-   // get template id from path and rebuild form
-   if ($_GET['template_id']) {
-    if (preg_match('/^\d+$/', $_GET['template_id'])) {
-      $form_state['storage']['template_id'] = $_GET['template_id'];
-    }
-
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $result = db_fetch_object(db_query($sql, $form_state['storage']['template_id']));
-    $form_state['storage']['template'] = unserialize($result->template_array);
-    $form_state['storage']['template_name'] = $result->name;
-
-    $form_state['storage']['record2priority'] = array();
-    foreach ($form_state['storage']['template'] as $priority => $record_array) {
-      if (!is_array($record_array)) {
-      continue; }
-      $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
-    }
-  }
-
-  $form['mode'] = array(
-    '#type' => 'hidden',
-    '#value' => $mode,
-  );
-
-  if ($form_state['storage']['template_id']) {
-    $form['template_name'] = array(
-        '#type' => 'item',
-        '#title' => 'Template',
-        '#value' => $form_state['storage']['template_name'],
-        '#weight' => 1,
-    );
-  }
-  else {
-    if (preg_match('/create/', $mode)) {
-     $form['new_template_name'] = array(
-        '#type' => 'textfield',
-        '#title' => 'Template Name',
-        '#weight' => 1,
-      );
-    }
-    elseif (preg_match('/edit/', $mode)) {
-      $sql = "SELECT * FROM {tripal_bulk_loader_template}";
-      $resource = db_query($sql);
-      $templates = array();
-      $templates[''] = 'Select a Template';
-      while ($r = db_fetch_object($resource)) {
-        $templates[$r->template_id] = $r->name;
-      }
-
-      $form['template_id'] = array(
-        '#title'         => t('Template'),
-        '#description'   => t('Please select the template you would like to edit.'),
-        '#type'          => 'select',
-        '#options'       => $templates,
-        '#default_value' => $form_state['storage']['template_id'],
-        '#weight'        => 0,
-        '#required'      => TRUE,
-        '#weight' => 1,
-      );
-    }
-  }
-
-  $form['records'] = array(
-<<<<<<< HEAD
-    '#type' => ($form_state['storage']['template_id'])? 'fieldset' : 'hidden',
-    '#title' => t('Current Records'),
-    '#collapsible' => TRUE,
-    '#weight' => 2,
-=======
-		'#type' => ($form_state['storage']['template_id'])? 'fieldset' : 'hidden',
-		'#title' => t('Current Records'),
-		'#collapsible' => TRUE,
-		'#weight' => 2,
->>>>>>> 6.x-0.4-dev
-  );
-
-  $form['records']['description'] = array(
-    '#type' => 'item',
-    '#value' => 'Records will be inserted into the chado database in the order listed below. To '
-      .'change this order: <ul><li>Drag the rows into the correct order OR</li><li>Enter '
-      .'the numbers 1 and up in the Order textboxes to indicate the correct order.</li></ul>',
-  );
-
-  $form['records']['records-data'] = array(
-    '#tree' => TRUE,
-  );
-
-  $form['records']['no_records'] = array(
-    '#type' => 'hidden',
-    '#value' => TRUE,
-  );
-
-  $form['records']['submit-new_record'] = array(
-    '#type' => 'submit',
-    '#value' => 'New Record/Field',
-  );
-
-  $form['records']['submit-reorder'] = array(
-    '#type' => 'submit',
-    '#value' => 'Save Order',
-  );
-
-<<<<<<< HEAD
-  $form['fields'] = array(
-    '#type' => ($form_state['storage']['template_id'])? 'fieldset' : 'hidden',
-    '#title' => t('Current Fields'),
-    '#collapsible' => TRUE,
-    '#weight' => 3,
-  );
-=======
-	$form['fields'] = array(
-		'#type' => ($form_state['storage']['template_id'])? 'fieldset' : 'hidden',
-		'#title' => t('Current Fields'),
-		'#collapsible' => TRUE,
-		'#weight' => 3,
-	);
->>>>>>> 6.x-0.4-dev
-
-  $form['fields']['fields-data'] = array(
-    '#tree' => TRUE,
-  );
-
-<<<<<<< HEAD
-  if ($form_state['storage']['template']) {
-=======
-	if ($form_state['storage']['template']) {
->>>>>>> 6.x-0.4-dev
-
-    // List Current Fields -------------------------------------------------------------
-    $i=1;
-    foreach ($form_state['storage']['template'] as $priority => $table_array) {
-<<<<<<< HEAD
-      if (!is_array($table_array)) {
-      continue; }
-=======
-      if (!is_array($table_array)) { continue; }
->>>>>>> 6.x-0.4-dev
-
-        $form['records']['no_records']['#value'] = FALSE;
-
-        $form['records']['records-data'][$priority] = array(
-          'title' => array(
-            '#type' => 'markup',
-            '#value' => $table_array['record_id'],
-          ),
-          'chado_table' => array(
-            '#type' => 'markup',
-            '#value' => $table_array['table'],
-          ),
-          'mode' => array(
-            '#type' => 'item',
-            '#value' => ($table_array['mode']) ? $table_array['mode'] : 'insert_unique',
-          ),
-          'new_priority' => array(
-            '#type' => 'select',
-            '#options' => range(1, sizeof($form_state['storage']['template'])),
-            '#default_value' => $priority,
-          ),
-          'old_priority' => array(
-            '#type' => 'hidden',
-            '#value' => $priority,
-          ),
-          'id'  => array(
-            '#type' => 'hidden',
-            '#value' => $priority,
-          ),
-          'submit-edit_record' => array(
-            '#type' => 'submit',
-            '#name' => (string)$priority,
-            '#value' => 'Edit Record',
-          ),
-          'submit-add_field' => array(
-            '#type' => 'submit',
-            '#name' => (string)$priority,
-            '#value' => 'Add Field',
-          ),
-          'submit-duplicate_record' => array(
-            '#type' => 'submit',
-            '#name' => (string)$priority,
-            '#value' => 'Duplicate Record'
-          ),
-        );
-
-        foreach ($table_array['fields'] as $field_index => $field) {
-
-          $form['fields']['fields-data'][$i] = array(
-            'record_id' => array(
-              '#type' => 'item',
-              '#value' => $table_array['record_id'],
-            ),
-            'priority_hidden' => array(
-              '#type' => 'hidden',
-              '#value' => $priority,
-            ),
-            'field_name' => array(
-              '#type' => 'item',
-              '#value' => $field['title'],
-            ),
-            'chado_table_name' => array(
-              '#type' => 'item',
-              '#value' => $table_array['table'],
-            ),
-            'chado_table_hidden' => array(
-              '#type' => 'hidden',
-              '#value' => $table_array['table'],
-            ),
-            'chado_field_name' => array(
-              '#type' => 'item',
-              '#value' => $field['field'],
-            ),
-            'sheet_name' => array(
-              '#type' => 'item',
-              '#value' => $field['spreadsheet sheet'],
-            ),
-            'column_num' => array(
-              '#type' => 'item',
-              '#value' => $field['spreadsheet column'],
-            ),
-            'constant_value' => array(
-              '#type' => 'item',
-              '#value' => $field['constant value'],
-            ),
-            'field_index' => array(
-              '#type' => 'hidden',
-              '#value' => $field_index
-            ),
-            'foreign_record_id' => array(
-              '#type' => 'item',
-              '#value' => $field['foreign key'],
-            ),
-            'edit_submit' => array(
-              '#type' => 'submit',
-              '#name' => (string)$i,
-              '#value' => "Edit Field",
-            ),
-            'delete_submit' => array(
-              '#type' => 'submit',
-              '#name' => (string)$i,
-              '#value' => "Delete Field",
-            ),
-          );
-
-          $i++;
-        }
-    }
-    $form['fields']['total_fields'] = array(
-      '#type' => 'item',
-      '#value' => $i,
-    );
-
-  }
-
-  if ($form['records']['no_records']['#value']) {
-    $form['records']['description'] = array(
-      '#type' => 'item',
-      '#value' => 'There are currently no records.',
-    );
-    unset($form['records']['submit-reorder']);
-
-    $form['fields']['description'] = array(
-      '#type' => 'item',
-      '#value' => 'There are currently no fields.',
-    );
-
-  }
-
-<<<<<<< HEAD
-  $mode_title = (preg_match('/create/', $mode)) ? 'Create Template' : 'Edit Template';
-  $value = ($form_state['storage']['template_id'])? 'Save Template' : $mode_title;
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => $value,
-    '#weight' => 4,
-  );
-  return $form;
-=======
-  $mode_title = (preg_match('/create/',$mode)) ? 'Create Template' : 'Edit Template';
-	$value = ($form_state['storage']['template_id'])? 'Save Template' : $mode_title;
-	$form['submit'] = array(
-		'#type' => 'submit',
-		'#value' => $value,
-		'#weight' => 4,
-	);
-
-	return $form;
->>>>>>> 6.x-0.4-dev
-}
-
-/**
- * Submit for tripal_bulk_loader_modify_template_base_form
- */
-function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state) {
-
-  $form_state['rebuild'] = TRUE;
-  if ($form_state['storage']['template_id']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $result = db_fetch_object(db_query($sql, $form_state['storage']['template_id']));
-    $form_state['storage']['template'] = unserialize($result->template_array);
-  }
-
-  $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
-  switch ($op) {
-    // Initialize after template is chosen ----------------------------------------
-    case 'Edit Template':
-      $form_state['storage']['template_id'] = $form_state['values']['template_id'];
-
-      $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-      $result = db_fetch_object(db_query($sql, $form_state['storage']['template_id']));
-      $form_state['storage']['template'] = unserialize($result->template_array);
-      $form_state['storage']['template_name'] = $result->name;
-
-      $form_state['storage']['record2priority'] = array();
-      foreach ($form_state['storage']['template'] as $priority => $record_array) {
-        if (!is_array($record_array)) {
-         continue;
-         }
-        $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
-      }
-    break;
-
-    case 'Create Template':
-      $record = array(
-        'name' => $form_state['values']['new_template_name'],
-        'template_array' => array(),
-      );
-      drupal_write_record('tripal_bulk_loader_template', $record);
-      $form_state['storage']['template_id'] = $record['template_id'];
-      $form_state['storage']['template_name'] = $record['name'];
-      $form_state['storage']['template'] = array();
-    break;
-
-    // Save Reordered Records -----------------------------------------------------
-    case 'Save Order':
-      $new_template = $form_state['storage']['template'];
-      // unset old elements
-       $form_state['storage']['record2priority'] = array();
-      foreach ($new_template as $priority => $record_array) {
-<<<<<<< HEAD
-        if (preg_match('/\d+/', $priority)) {
-           unset($new_template[$priority]);
-         }
-=======
-        if (preg_match('/\d+/', $priority)) { unset($new_template[$priority]); }
->>>>>>> 6.x-0.4-dev
-      }
-      //set elements in new order
-      foreach ($form_state['values']['records-data'] as $item) {
-        $new_template[$item['new_priority']] = $form_state['storage']['template'][$item['old_priority']];
-        $record_name = $new_template[$item['new_priority']]['record_id'];
-        $form_state['storage']['record2priority'][$record_name] = $item['new_priority'];
-      }
-      ksort($new_template);
-      $form_state['storage']['template'] = $new_template;
-    break;
-
-    case 'New Record/Field':
-      $query = array(
-<<<<<<< HEAD
-        'template_id' => $form_state['storage']['template_id'],
-=======
-        'template_id'=> $form_state['storage']['template_id'],
->>>>>>> 6.x-0.4-dev
-        'record_id' => 'NEW',
-      );
-      drupal_goto('admin/tripal/tripal_bulk_loader_template/add_field', $query);
-    break;
-
-    case 'Edit Record':
-      $query = array(
-<<<<<<< HEAD
-        'template_id' => $form_state['storage']['template_id'],
-=======
-        'template_id'=> $form_state['storage']['template_id'],
->>>>>>> 6.x-0.4-dev
-        'record_id' => $form_state['clicked_button']['#name'],
-      );
-      drupal_goto('admin/tripal/tripal_bulk_loader_template/edit_record', $query);
-    break;
-
-    case 'Add Field':
-      $query = array(
-<<<<<<< HEAD
-        'template_id' => $form_state['storage']['template_id'],
-=======
-        'template_id'=> $form_state['storage']['template_id'],
->>>>>>> 6.x-0.4-dev
-        'record_id' => $form_state['clicked_button']['#name'],
-      );
-      drupal_goto('admin/tripal/tripal_bulk_loader_template/add_field', $query);
-    break;
-
-    case 'Duplicate Record':
-      // original record (one to be duplicated)
-      $orig_priority = $form_state['clicked_button']['#name'];
-      $record = $form_state['storage']['template'][ $orig_priority ];
-
-      // new record
-      $new_priority = sizeof($form_state['storage']['template']) + 1;
-      $record['record_id'] = $record['record_id'] . '_' . date('YzHi');
-      $form_state['storage']['template'][ $new_priority ] = $record;
-    break;
-
-    case 'Edit Field':
-      $field_data_index = $form_state['clicked_button']['#name'];
-      $query = array(
-<<<<<<< HEAD
-        'template_id' => $form_state['storage']['template_id'],
-=======
-        'template_id'=> $form_state['storage']['template_id'],
->>>>>>> 6.x-0.4-dev
-        'record_id' => $form_state['values']['fields-data'][$field_data_index]['priority_hidden'],
-        'field_index' => $form_state['values']['fields-data'][$field_data_index]['field_index'],
-      );
-      drupal_goto('admin/tripal/tripal_bulk_loader_template/edit_field', $query);
-    break;
-
-    case 'Delete Field':
-      $field_data = $form_state['values']['fields-data'][$form_state['clicked_button']['#name']];
-      $priority = $field_data['priority_hidden'];
-      $field_key = $field_data['field_index'];
-      unset($form_state['storage']['template'][$priority]['fields'][$field_key]);
-      if (!$form_state['storage']['template'][$priority]['fields']) {
-        unset($form_state['storage']['record2priority'][$form_state['storage']['template'][$priority]['record_id']]);
-        unset($form_state['storage']['template'][$priority]);
-      }
-      drupal_set_message('Deleted Field from Template.');
-    break;
-  } //end of switch
-
-  // Save Template
-  $record = array(
-    'template_id' => $form_state['storage']['template_id'],
-    'template_array' => serialize($form_state['storage']['template'])
-  );
-  drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
-  drupal_set_message('Template Saved.');
-
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Delete Template
-//////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Delete Template Form
- * This form allows admin to delete already existing templates
- */
-function tripal_bulk_loader_delete_template_base_form() {
-  $form = array();
-
-  $sql = "SELECT * FROM {tripal_bulk_loader_template}";
-  $resource = db_query($sql);
-  $templates = array();
-  $templates[''] = 'Select a Template';
-  while ($r = db_fetch_object($resource)) {
-    $templates[$r->template_id] = $r->name;
-  }
-  $form['template_name'] = array(
-      '#title'         => t('Template'),
-      '#description'   => t('Please select the template you would like to delete.'),
-      '#type'          => 'select',
-      '#options'       => $templates,
-      '#weight'        => 0,
-      '#required'      => TRUE,
-<<<<<<< HEAD
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => 'Delete Template',
-  );
-
-  return $form;
-=======
-	);
-
-	$form['submit'] = array(
-		'#type' => 'submit',
-		'#value' => 'Delete Template',
-	);
-
-	return $form;
->>>>>>> 6.x-0.4-dev
-}
-
-/**
- * Delete Template Form Submit
- *
- * @param $form
- *   The form that was submitted
- * @param $form_state
- *   The values and storage that were submitted
- */
-function tripal_bulk_loader_delete_template_base_form_submit($form, &$form_state) {
-  $sql = "DELETE FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-  db_query($sql, $form_state['values']['template_name']);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Import/Export Template
-//////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Import/Export Template Form
- *
- * On export, simply selects the serialized array from the db for a given template
- * and presents it to the user. On import, a serialized template array and a name is
- * supplied and a template record is created.
- *
- * @todo Make array presented to the user more readable. (ie: unserialize and print to the screen)
- *
- * @param $form_state
- *   The values and storage for the form
- * @param $mode
- *   Either 'import' or 'export' to indicate which function is being performed
- * @return
- *   A form array to be rendered by drupal_get_form
- */
-function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mode) {
-  $form = array();
-
-  $form['mode'] = array(
-    '#type' => 'hidden',
-    '#value' => $mode,
-  );
-
-  if (preg_match('/import/', $mode)) {
-   $form['new_template_name'] = array(
-      '#type' => 'textfield',
-      '#title' => 'Template Name',
-      '#weight' => 1,
-    );
-  }
-  elseif (preg_match('/export/', $mode)) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template}";
-    $resource = db_query($sql);
-    $templates = array();
-    $templates[''] = 'Select a Template';
-    while ($r = db_fetch_object($resource)) {
-      $templates[$r->template_id] = $r->name;
-    }
-
-    $form['template_id'] = array(
-      '#title'         => t('Template'),
-      '#description'   => t('Please select the template you would like to edit.'),
-      '#type'          => 'select',
-      '#options'       => $templates,
-      '#default_value' => $form_state['storage']['template_id'],
-      '#weight'        => 0,
-      '#required'      => TRUE,
-      '#weight' => 1,
-    );
-  }
-
-  $form['template_array'] = array(
-    '#type' => 'textarea',
-    '#title' => 'Template Array',
-    '#default_value' => $form_state['storage']['template_array'],
-    '#weight' => 2,
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => 'Submit',
-    '#weight' => 10,
-  );
-
-  return $form;
-}
-
-/**
- * Import/Export Template Form Submit
- *
- * @param $form
- *   The form that was submitted
- * @param $form_state
- *   The values and storage that were submitted
- */
-function tripal_bulk_loader_import_export_template_form_submit($form, &$form_state) {
-  switch ($form_state['values']['mode']) {
-    case 'export':
-      $record = db_fetch_object(db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d", $form_state['values']['template_id']));
-      $form_state['storage']['template_array'] = $record->template_array;
-      $form_state['storage']['template_id'] = $form_state['values']['template_id'];
-    break;
-    case 'import':
-      $record = array(
-        'name' => $form_state['values']['new_template_name'],
-        'template_array' => $form_state['values']['template_array'],
-      );
-      drupal_write_record('tripal_bulk_loader_template', $record);
-      if ($record->template_id) {
-        drupal_set_message('Successfully imported Tripal Bulk Loader Template.');
-      }
-    break;
-  }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Edit Record Form
-//////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Edit Record Form
- *
- * This form is meant to be called from a bulk loader form. The following should be set
- * in the query section of the path:
- *  - template_id=\d+: the template which the edited record is part of
- *  - record_id=\d+: the priority or key in the template array of the record to be edited
- *
- * @param $form_state
- *   Contains the values and storage for the form
- * @return
- *   A form array to be rendered by drupal_get_form
- */
-<<<<<<< HEAD
-function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
-   $form['#cache'] = TRUE; // Make sure the form is cached.
-
-   // get template id from path
-   $template_id = ($_GET['template_id'] !== NULL) ? $_GET['template_id'] : $form_state['values']['template_id'];
-
-   // if there is no template supplied don't return rest of form
-   if (!$template_id) {
-     return $form;
-   }
-=======
-function tripal_bulk_loader_edit_template_record_form (&$form_state = NULL) {
- 	$form['#cache'] = TRUE; // Make sure the form is cached.
-
- 	// get template id from path
- 	$template_id = ($_GET['template_id'] !== NULL) ? $_GET['template_id'] : $form_state['values']['template_id'];
-
- 	// if there is no template supplied don't return rest of form
- 	if (!$template_id) {
- 	  return $form;
- 	}
->>>>>>> 6.x-0.4-dev
-
-  // Pre-process values/defaults ---------------------------
-
-   // If this is the first load of the form (no form state) we need to initialize some variables
-   if (!$form_state['storage']['template']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $template = db_fetch_object(db_query($sql, $template_id));
-    $form_state['storage']['template_array'] = unserialize($template->template_array);
-    $form_state['storage']['template'] = $template;
-
-    $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;
-    }
-
-    $form_state['storage']['referring URL'] = $_SERVER["HTTP_REFERER"];
-  }
-  else {
-    $template = $form_state['storage']['template'];
-  }
-
-   // get the record_id from the path
-   if ($_GET['record_id'] !== NULL) {
-     $form_state['values']['field_group'] = $_GET['record_id'];
-     $form_state['storage']['original_priority'] = $_GET['record_id'];
-  }
-
-
-  // Tables and default table
-  $tables = tripal_core_get_chado_tables();
-  if ($form_state['values']['chado_table']) {
-    $table = $form_state['values']['chado_table'];
-<<<<<<< HEAD
-  }
-  else {
-=======
-  } else {
->>>>>>> 6.x-0.4-dev
-    $table = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['table'];
-  }
-
-  //dpm($form_state, 'form state');
-
-<<<<<<< HEAD
-   // Form Proper -------------------------------------------
-=======
- 	// Form Proper -------------------------------------------
->>>>>>> 6.x-0.4-dev
-  $form['template_name'] = array(
-    '#type' => 'item',
-    '#title' => 'Template',
-    '#value' => $template->name,
-  );
-
-  $form['template_id'] = array(
-    '#type' => 'hidden',
-    '#value' => $template_id,
-  );
-
-  $form['edit_record'] = array(
-    '#type' => 'fieldset',
-  );
-
-  // check template array for records then add one more
-  if (!$form_state['storage']['record2priority']) {
-    $groups = array();
-  }
-  else {
-    $groups = array_flip($form_state['storage']['record2priority']);
-  }
-  $priority_default = $form_state['values']['field_group'];
-  $form['edit_record']['field_group']  = array(
-    '#type' => 'select',
-    '#title' => 'Record',
-    '#description' => 'By Changing the record here, you can move all the fields from the current record into the selected record.',
-    '#options' => $groups,
-    '#default_value' => $priority_default,
-    '#required' => TRUE,
-  );
-
-  $form['edit_record']['record_name'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Unique Record Name',
-    '#default_value' => $groups[$priority_default],
-  );
-
-  $form['edit_record']['chado_table'] = array(
-    '#type' => 'select',
-    '#title' => t('Chado Table'),
-    '#description' => 'This changes the chado table for all fields in this record.',
-    '#options' => $tables,
-    '#default_value' => $table,
-  );
-
-  $form['edit_record']['mode'] = array(
-    '#type' => 'radios',
-    '#title' => 'Action to take when Loading Record',
-    '#options' => array(
-      'select' => 'SELECT: Don\'t insert this record: it\'s used to define a foreign key in another record',
-      'insert' => 'INSERT: Insert the record',
-      'optional' => 'OPTIONAL: Record will only be inserted if all required data is filled in',
-      'insert_once' => 'INSERT ONCE: Record will be inserted once for the entire spreadsheet',
-      'insert_unique' => 'INSERT UNIQUE: Only insert record if there isn\'t a record with the same values',
-    ),
-    '#default_value' => 'insert_unique'
-  );
-
-  $form['edit_record']['submit-edit_record'] = array(
-      '#type' => 'submit',
-      '#value' => 'Edit Record'
-  );
-
-  $form['edit_record']['submit-cancel'] = array(
-      '#type' => 'submit',
-      '#value' => 'Cancel'
-  );
-
-  return $form;
-}
-
-
-/**
- * Edit Record Form Submit
- *
- * @param $form
- *   The form that was submitted
- * @param $form_state
- *   Contains the values and storage for the form
- */
-function tripal_bulk_loader_edit_template_record_form_submit($form, &$form_state) {
-  //dpm($form_state, 'form state -start submit');
-
-  if (!$form_state['ahah_submission']) {
-    if ($form_state['values']['op'] ==  'Edit Record') {
-
-      $template = $form_state['storage']['template_array'];
-
-      // Edit Record
-      $record = $template[ $form_state['storage']['original_priority'] ];
-      $record['record_id'] = $form_state['values']['record_name'];
-      $record['mode'] = $form_state['values']['mode'];
-      $record['table'] = $form_state['values']['chado_table'];
-
-      if ($form_state['storage']['original_priority'] != $form_state['values']['field_group']) {
-        $record['fields'] = array_merge($record['fields'], $template[ $form_state['values']['field_group'] ]['fields']);
-        $template[ $form_state['values']['field_group'] ] = $record;
-        unset($template[ $form_state['storage']['original_priority'] ]);
-      }
-      else {
-        $template[ $form_state['storage']['original_priority'] ] = $record;
-      }
-
-      // Save Template
-      $form_state['storage']['template']->template_array = serialize($template);
-      $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
-
-      if ($success) {
-        drupal_set_message('Successfully Updated Template Record');
-        drupal_set_message('Template Saved.');
-
-<<<<<<< HEAD
-        $path = explode('?', $form_state['storage']['referring URL']);
-=======
-        $path = explode('?',$form_state['storage']['referring URL']);
->>>>>>> 6.x-0.4-dev
-        parse_str($path[1], $query);
-        $query['template_id'] = $form_state['storage']['template']->template_id;
-        drupal_goto($path[0], $query);
-      }
-      else {
-        drupal_set_message('Unable to Save Template!', 'error');
-        watchdog('T_bulk_loader',
-          'Unable to save bulk loader template: %template',
-          array('%template' => print_r($form_state['storage']['template'], TRUE)),
-          WATCHDOG_ERROR
-        );
-      }
-    }
-    elseif ($form_state['values']['op'] ==  'Cancel') {
-        $path = explode('?', $form_state['storage']['referring URL']);
-        parse_str($path[1], $query);
-        $query['template_id'] = $form_state['storage']['template']->template_id;
-        //dpm('Redirecting to: '.$path[0].'?'.print_r($query,TRUE).' where the referring URL:'.$form_state['storage']['referring URL']);
-        drupal_goto($path[0], $query);
-    }
-  }
-
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Add/Edit Field Forms
-//////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Add Field Form
- *
- * This form is meant to be called from a bulk loader form. Blank Defaults are in place but you
- * can use the following in the query of the path to set defaults for a given template:
- *  - template_id=\d+: the template to add the field to
- *  - record_id=\d+: the priority or key in the template array of the record to add the field to
- *
- * @param $form_state
- *   Contains the values and storage for the form
- * @return
- *   A form array to be rendered by drupal_get_form
- */
-function tripal_bulk_loader_add_template_field_form(&$form_state = NULL) {
-  $form = array();
-<<<<<<< HEAD
-   $form['#cache'] = TRUE; // Make sure the form is cached.
-
-   // get template id from path
-   $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
-
-   // if there is no template supplied don't return rest of form
-   if (!$template_id) {
-     return $form;
-   }
-=======
- 	$form['#cache'] = TRUE; // Make sure the form is cached.
-
- 	// get template id from path
- 	$template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
-
- 	// if there is no template supplied don't return rest of form
- 	if (!$template_id) {
- 	  return $form;
- 	}
->>>>>>> 6.x-0.4-dev
-
-  // Pre-set Variables needed for form proper------------------------------------------
-
-   // If this is the first load of the form (no form state) we need to initialize some variables
-   if (!$form_state['storage']['template']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $template = db_fetch_object(db_query($sql, $template_id));
-    $form_state['storage']['template_array'] = unserialize($template->template_array);
-    $form_state['storage']['template'] = $template;
-
-    $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;
-    }
-
-    $form_state['storage']['referring URL'] = $_SERVER["HTTP_REFERER"];
-  }
-  else {
-    $template = $form_state['storage']['template'];
-  }
-
-  $field_type = ($form_state['values']['field_type'])? $form_state['values']['field_type'] : 'table field';
-
-  // Tables and default table
-  $tables = tripal_core_get_chado_tables();
-  if ($form_state['values']) {
-    if (!preg_match('/^' . current($tables) . '$/', $form_state['values']['chado_table'])) {
-      $table = $form_state['values']['chado_table'];
-    }
-    elseif ($form_state['values']['record_name']) {
-      $record_name = $form_state['values']['record_name'];
-      $priority = $form_state['storage']['record2priority'][$record_name];
-      $table = $form_state['storage']['template_array'][$priority]['table'];
-    }
-    else {
-      $priority = $form_state['values']['field_group'];
-      $table = $form_state['storage']['template_array'][$priority]['table'];
-    }
-  }
-  if (!$table) {
-    $table = reset($tables);
-  }
-
-   // get the record_id from the path
-   if ($_GET['record_id'] !== NULL) {
-     $form_state['values']['field_group'] = $_GET['record_id'];
-    if (preg_match('/\d+/', $_GET['record_id'])) {
-      $priority = $form_state['values']['field_group'];
-      $table = $form_state['storage']['template_array'][$priority]['table'];
-    }
-  }
-
-  // Fields and foreign key mappings
-  $chado_fields = array();
-  $fk_options = array();
-  $fk_options['NULL'] = 'None';
-  $table_description = module_invoke_all('chado_' . $table . '_schema');
-  //dpm($table_description, 'table description for |'.$table.'|');
-  if ($field_type == 'foreign key') {
-    $foreign_field2table = array();
-    foreach ($table_description['foreign keys'] as $key_table => $key_array) {
-      foreach ($key_array['columns'] as $left_field => $right_field) {
-        $chado_fields[$left_field] = $left_field;
-        $foreign_field2table[$left_field] = $key_table;
-      }
-    }
-    reset($chado_fields);
-
-    // set default field
-    if (empty($chado_fields)) {
-      $field = NULL;
-    }
-    elseif ($chado_fields[$form_state['values']['chado_field']]) {
-      $field = $form_state['values']['chado_field'];
-    }
-    else {
-      $field = current($chado_fields);
-    }
-
-    // Foreign key options
-    $foreign_table = $foreign_field2table[$field];
-    if ($foreign_table) {
-      foreach ($form_state['storage']['record2priority'] as $record_name => $priority ) {
-        if (preg_match('/^' . $foreign_table . '$/', $form_state['storage']['template_array'][$priority]['table'])) {
-          $fk_options[$record_name] = $record_name;
-        }
-      }
-    }
-  }
-  else {
-    foreach ($table_description['fields'] as $field_name => $field_array) {
-        $chado_fields[$field_name] = $field_name;
-    }
-  }
-
-  $variables = array(
-    'form_state' => $form_state,
-    'tables' => $tables,
-    'default table' => $table,
-    'fields' => $chado_fields,
-    'default_field' => $field,
-    'priority' => $priority,
-    'record_name' => $record_name,
-    'table description' => $table_description,
-    'foreign key options' => $fk_options,
-    'foreign field=>table' => $foreign_field2table,
-    'foreign table' => $foreign_table,
-  );
-  //dpm($variables, 'variables');
-
-  // Start of Form Proper--------------------------------------------------------------
-  //dpm($form_state, 'Form State');
-
-  $form['template_name'] = array(
-    '#type' => 'item',
-    '#title' => 'Template',
-    '#value' => $template->name,
-  );
-
-  $form['template_id'] = array(
-    '#type' => 'hidden',
-    '#value' => $template_id,
-  );
-
-  $form['add_fields'] = array(
-    '#type' => 'fieldset',
-    '#prefix' => '<div id="tripal_bulk_loader_template-add_field">',
-    '#suffix' => '</div>',
-  );
-
-  $form['add_fields']['field_type'] = array(
-    '#type' => 'radios',
-    '#title' => t('Type of Field'),
-    '#options' => array(
-      'table field' => t('Spreadsheet: Fields which maps to a Spreadsheet Column'),
-      'constant' => t('Constant: Field which remains Constant throughout the Spreadsheet'),
-      'foreign key' => t('Foreign Key: Fields which map to a record in another table'),
-    ),
-    '#required' => TRUE,
-    '#default_value' => $field_type,
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/add_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-add_field',
-      'effect' => 'fade'
-    ),
-  );
-
-  // check template array for records then add one more
-  if (!$form_state['storage']['record2priority']) {
-    $groups = array();
-  }
-  else {
-    $groups = array_flip($form_state['storage']['record2priority']);
-  }
-  $groups['NONE'] = 'Select a Record';
-  $groups['NEW'] = 'New Record';
-  $form['add_fields']['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 spreadsheet',
-    '#options' => $groups,
-    '#default_value' => (preg_match('/\w+.*/', $form_state['values']['field_group'])) ? $form_state['values']['field_group'] : 'NONE',
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/add_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-add_field',
-      'effect' => 'fade'
-    ),
-    '#required' => TRUE,
-  );
-
-  $form['add_fields']['record_name'] = array(
-    '#type' => (preg_match('/NEW/', $form_state['values']['field_group'])) ? 'textfield' : 'hidden',
-    '#title' => 'Unique Record Name',
-    '#prefix' => '<div id="tripal_bulk_loader_template-add_record">',
-    '#suffix' => '</div>',
-    '#default_value' => $form_state['values']['record_name'],
-  );
-
-  $form['add_fields']['field_title'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Human-readable Title for Field'),
-    '#default_value' => $form_state['values']['field_title'],
-  );
-
-  // Spreadsheet column
-  $form['add_fields']['columns'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Spreadsheet Column'),
-    '#collapsible' => TRUE,
-    '#collapsed' => ($field_type == 'table field')? FALSE : TRUE,
-  );
-
-  $form['add_fields']['columns']['sheet_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Worksheet'),
-    '#description' => t('Specify the name of the worksheet.'),
-    '#size' => 5,
-    '#default_value' => ($form_state['values']['sheet_name'])? $form_state['values']['sheet_name'] : 'Sheet1',
-  );
-
-  $form['add_fields']['columns']['column_number'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Column'),
-    '#description' => t('Specify the column in the spreadsheet that this field maps to where the first column is 1.'),
-    '#size' => 5,
-    '#default_value' => $form_state['values']['column_number'],
-  );
-
-  $form['add_fields']['columns']['column_exposed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow Column to be set for each Bulk Loading Job'),
-    '#description' => t('Adds a textbox field to the Bulk Loader Page to allow users to set this value.'),
-    '#default_value' => ($form_state['values']['column_exposed']) ? $form_state['values']['column_exposed'] : $template_field['exposed'],
-  );
-
-  $form['add_fields']['columns']['column_exposed_desc'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Description for exposed field on bulk loading job'),
-    '#description' => t('This description should tell the user what column should be entered here.'),
-    '#default_value' => ($form_state['values']['column_exposed_desc']) ? $form_state['values']['column_exposed_desc'] : $template_field['exposed_description'],
-  );
-
-  // Global Value
-  $form['add_fields']['constant'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Constant'),
-    '#collapsible' => TRUE,
-    '#collapsed' => ($field_type == 'constant')? FALSE : TRUE,
-  );
-
-  $form['add_fields']['constant']['constant_value'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Constant Value'),
-    '#description' => t('Specify the value you wish this field to have regardless of spreadsheet data.'),
-    '#default_value' => $form_state['values']['constant_value']
-  );
-
-  $form['add_fields']['constant']['constant_exposed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow Constant to be set for each Bulk Loading Job'),
-    '#description' => t('Adds a textbox field to the Create Bulk Loader Form to allow users to set this value.')
-  );
-
-  $form['add_fields']['constant']['constant_validate'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Ensure value is in table'),
-    '#description' => t('Checks the database when a bulk loading job is created to ensure the value entered already exists in the database.'),
-  );
-
-  // Foreign Key
-  $form['add_fields']['foreign_key'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Foreign Key',
-    '#collapsible' => TRUE,
-    '#collapsed' => ($field_type == 'foreign key')? FALSE : TRUE,
-  );
-
-  $form['add_fields']['foreign_key']['foreign_record'] = array(
-    '#type' => 'select',
-    '#title' => 'Record to refer to',
-    '#descripion' => 'Select the record that this foreign key shouold refer to. The record needs to already exist and be of the correct table.',
-    '#options' => $fk_options,
-  );
-
-  // Chado Field
-  $form['add_fields']['chado'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Chado Field/Column Details'),
-    '#description' => t('Specify the Table/Field in chado that this field maps to.'),
-  );
-
-  $form['add_fields']['chado']['chado_table'] = array(
-    '#type' => 'select',
-    '#title' => t('Chado Table'),
-    '#options' => $tables,
-    '#default_value' => $table,
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/add_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-add_field',
-      'effect' => 'fade'
-      ),
-  );
-
-  $form['add_fields']['chado']['chado_field'] = array(
-    '#type' => 'select',
-    '#title' => t('Chado Field/Column'),
-    '#options' => $chado_fields,
-    '#default_value' => $form_state['values']['chado_field'],
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/add_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-add_field',
-      'effect' => 'fade'
-    ),
-  );
-
-  $form['add_fields']['additional'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Additional Options',
-  );
-
-  $form['add_fields']['additional']['required'] = array(
-    '#type' => 'checkbox',
-    '#title' => 'Make this file required',
-  );
-
-  $form['add_fields']['additional']['regex_transform'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Transform Spreadsheet Value Rules',
-    '#collapsible' => TRUE,
-    '#collapsed' => (!$form_state['storage']['regex']['pattern']) ? TRUE : FALSE,
-  );
-
-  $form['add_fields']['additional']['regex_transform']['regex_description'] = array(
-    '#type' => 'item',
-    '#value' => 'A transformation rule allows you to transform the original value '
-      .'(usually from a user submitted spreadsheet) into the form you would like it stored '
-      .'in the chado database. Each rule consists of a match pattern (a php regular expression '
-      .'which determines which replacement patterns are applied and captures regions of the '
-      .'original value) and a replacement pattern (a string which may contain capture references '
-      .'that describes what the new value should be). Each rule is applied to the result of the '
-      .'previous rule.'
-  );
-
-  $form['add_fields']['additional']['regex_transform']['regex-data'] = array(
-    '#tree' => TRUE,
-  );
-  if (!$form_state['storage']['regex']['pattern']) {
-    $form_state['storage']['regex']['pattern'] = array();
-  }
-  foreach ($form_state['storage']['regex']['pattern'] as $index => $pattern) {
-    $data_element = array(
-      'pattern' => array(
-        '#type' => 'item',
-        '#value' => $pattern,
-      ),
-      'replace' => array(
-        '#type' => 'item',
-        '#value' => $form_state['storage']['regex']['replace'][$index],
-      ),
-      'old_index' => array(
-        '#type' => 'hidden',
-        '#value' => $index,
-      ),
-      'new_index' => array(
-        '#type' => 'select',
-        '#options' => range(0, sizeof($form_state['storage']['regex']['pattern'])-1),
-        '#default_value' => $index,
-      ),
-      'id' => array(
-        '#type' => 'hidden',
-        '#value' => $index,
-      ),
-      'submit-delete' => array(
-        '#type' => 'submit',
-        '#value' => 'Delete Transformation',
-        '#name' => $index,
-      ),
-    );
-    $form['add_fields']['additional']['regex_transform']['regex-data'][$index] = $data_element;
-  }
-
-  $form['add_fields']['additional']['regex_transform']['submit-reorder_regex'] = array(
-    '#type' => ($form_state['storage']['regex']['pattern']) ? 'submit' : 'hidden',
-    '#value' => 'Save Transformation Rule Order'
-  );
-
-  $form['add_fields']['additional']['regex_transform']['new_regex'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Add a new Transformation Rule',
-  );
-
-  $form['add_fields']['additional']['regex_transform']['new_regex']['pattern'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Match Pattern',
-    '#description' => 'You can use standard php regular expressions in this field to specify a '
-      .'pattern. Only if this pattern matches the value in the spreadsheet does the replacement '
-      .'pattern get applied to the value. To capture a section of your value for use in the '
-      .'replacement patten surround with round brackets. For example, <i>GI:(\d+)</i> will match '
-      .' NCBI gi numbers and will capture the numerical digits for use in the replacement pattern. '
-      .' To match and capture any value use <i>.*</i>',
-  );
-
-  $form['add_fields']['additional']['regex_transform']['new_regex']['replace'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Replacement Pattern',
-    '#description' => 'This pattern should contain the text you want to replace the match pattern '
-    .'mentioned above. It can include references of the form \n where n is the number of the '
-    .'capture in the match pattern. For example, \1 will be replaced with the text matched in your '
-    .'first set of round brackets.',
-  );
-
-  if ($field_type == 'table field') {
-    $tab = '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp';
-    $form['add_fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
-      .'The following references are also available for spreadsheet fields: <b><#column:<i>number</i>#></b>. '
-      .'This allows you to substitute other spreadsheet values into the current field. For example, '
-      .'if you had the following line:<br>'
-      . $tab . 'SNP' . $tab . '15-Jan-2011' . $tab . '1' . $tab . '54' . $tab . 'Contig34355'
-      .'<br> and your current field is for column #1 and you\'re inserting into the chado field '
-      .'feature.uniquename then you might want to add in the data to ensure your uniquename is '
-      .'unique. The Match Pattern is (.*) to select all the first column and the Replacement '
-      .'Pattern could be \1_<#column:2#> which would insert SNP_15-Jan-2011 into the database.</p>';
-  }
-
-  $form['add_fields']['additional']['regex_transform']['new_regex']['submit-add_transform'] = array(
-    '#type' => 'submit',
-    '#value' => 'Add Transformation',
-  );
-
-  $form['add_fields']['additional']['regex_transform']['test_regex'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Test Transformation Rules',
-  );
-
-  $form['add_fields']['additional']['regex_transform']['test_regex']['test_string'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Test Value',
-    '#description' => 'This should be a value that you expect the above transformation rules '
-      .'to be applied to.',
-    '#default_value' => $form_state['storage']['test_regex_test'],
-  );
-
-  $form['add_fields']['additional']['regex_transform']['test_regex']['test_result'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Test Result',
-    '#description' => 'This is the value that would be saved to the database after the above transformation '
-      .'riles were applied to the Test Value.',
-    '#default_value' => $form_state['storage']['test_regex_result'],
-  );
-
-  $form['add_fields']['additional']['regex_transform']['test_regex']['submit-test'] = array(
-    '#type' => 'submit',
-    '#value' => 'Test Transformation Rules'
-  );
-
-  $form['add_fields']['submit-add_field'] = array(
-      '#type' => 'submit',
-      '#value' => 'Add Field'
-  );
-
-  $form['add_fields']['submit-cancel'] = array(
-      '#type' => 'submit',
-      '#value' => 'Cancel'
-  );
-
-  return $form;
-}
-
-/**
- * Add Field Submit
- *
- * @param $form
- *   The form that was submitted
- * @param $form_state
- *   The values and storage for the form
- */
-<<<<<<< HEAD
-function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state) {
-=======
-function tripal_bulk_loader_add_template_field_form_submit ($form, &$form_state) {
->>>>>>> 6.x-0.4-dev
-
-  $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
-
-  if (!$form_state['ahah_submission']) {
-    if ($op ==  'Add Field') {
-
-      $template = $form_state['storage']['template_array'];
-
-       // If new record
-      if (preg_match('/NEW/', $form_state['values']['field_group'])) {
-        $record_name = $form_state['values']['record_name'];
-        $priority = sizeof($form_state['storage']['template_array']) + 1;
-        $record2priority[$record_name] = $priority;
-        $template[$priority]['table'] = $form_state['values']['chado_table'];
-        $template[$priority]['record_id'] = $record_name;
-
-<<<<<<< HEAD
-      }
-      else {
-=======
-      } else {
->>>>>>> 6.x-0.4-dev
-        $priority = $form_state['values']['field_group'];
-        $record_name = $record2priority[$priority];
-      }
-
-      // Add field to template array
-      if ($form_state['values']['field_type'] == 'table field') {
-        $field = array(
-          'type' => 'table field',
-          'title' => $form_state['values']['field_title'],
-          'field' => $form_state['values']['chado_field'],
-          'required' => $form_state['values']['required'],
-          //'allowed values' => empty by default,
-          'spreadsheet sheet' => $form_state['values']['sheet_name'],
-          'spreadsheet column' => $form_state['values']['column_number'],
-          'exposed' => $form_state['values']['column_exposed'],
-          'exposed_description' => $form_state['values']['column_exposed_desc'],
-        );
-      }
-      elseif ($form_state['values']['field_type'] == 'constant') {
-        $field = array(
-          'type' => 'constant',
-          'title' => $form_state['values']['field_title'],
-          'field' => $form_state['values']['chado_field'],
-          'required' => $form_state['values']['required'],
-          //'allowed values' => empty by default,
-          'constant value' => $form_state['values']['constant_value'],
-          'exposed' => $form_state['values']['constant_exposed'],
-          'exposed_validate' => $form_state['values']['constant_validate'],
-        );
-<<<<<<< HEAD
-      }
-      elseif ($form_state['values']['field_type'] == 'foreign key') {
-=======
-      } elseif ($form_state['values']['field_type'] == 'foreign key') {
->>>>>>> 6.x-0.4-dev
-        $field = array(
-          'type' => 'foreign key',
-          'title' => $form_state['values']['field_title'],
-          'field' => $form_state['values']['chado_field'],
-          'foreign key' => $form_state['values']['foreign_record'],
-          'required' => $form_state['values']['required'],
-        );
-      }
-
-      // Deal with any additional options
-      if ($form_state['storage']['regex']) {
-        $field['regex'] = $form_state['storage']['regex'];
-      }
-
-      // Save Template
-      $template[$priority]['fields'][] = $field;
-      $form_state['storage']['template']->template_array = serialize($template);
-      $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
-
-      if ($success) {
-        drupal_set_message('Successfully Added Field to Template');
-        drupal_set_message('Template Saved.');
-
-<<<<<<< HEAD
-        $path = explode('?', $form_state['storage']['referring URL']);
-=======
-        $path = explode('?',$form_state['storage']['referring URL']);
->>>>>>> 6.x-0.4-dev
-        parse_str($path[1], $query);
-        $query['template_id'] = $form_state['storage']['template']->template_id;
-        drupal_goto($path[0], $query);
-      }
-      else {
-        drupal_set_message('Unable to Save Template!', 'error');
-        watchdog('T_bulk_loader',
-          'Unable to save bulk loader template: %template',
-          array('%template' => print_r($form_state['storage']['template'], TRUE)),
-          WATCHDOG_ERROR
-        );
-      }
-    }
-    elseif ($op ==  'Cancel') {
-        $path = explode('?', $form_state['storage']['referring URL']);
-        parse_str($path[1], $query);
-        $query['template_id'] = $form_state['storage']['template']->template_id;
-        drupal_goto($path[0], $query);
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Add Transformation') {
-=======
-    } elseif ($op == 'Add Transformation') {
->>>>>>> 6.x-0.4-dev
-
-      // Add transformation rule to original field
-      $form_state['storage']['regex']['pattern'][] = '/' . $form_state['values']['pattern'] . '/';
-      $form_state['storage']['regex']['replace'][] = $form_state['values']['replace'];
-      drupal_set_message('Successfully Added Transformation Rule');
-
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Save Transformation Rule Order') {
-=======
-    } elseif ($op == 'Save Transformation Rule Order') {
->>>>>>> 6.x-0.4-dev
-
-      // Generate new regex array
-      $new_regex = array();
-      $old_regex = $form_state['storage']['regex'];
-      foreach ($form_state['values']['regex-data'] as $key => $element) {
-        $new_regex['pattern'][ $element['new_index'] ] = $old_regex['pattern'][ $element['old_index'] ];
-        $new_regex['replace'][ $element['new_index'] ] = $old_regex['replace'][ $element['old_index'] ];
-      }
-
-      // sort new regex arrays
-      asort($new_regex['pattern']);
-      asort($new_regex['replace']);
-
-      $form_state['storage']['regex'] = $new_regex;
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Delete Transformation') {
-=======
-    } elseif ($op == 'Delete Transformation') {
->>>>>>> 6.x-0.4-dev
-
-      // Unset regex rule
-      $index = $form_state['clicked_button']['#name'];
-      unset($form_state['storage']['regex']['pattern'][$index]);
-      unset($form_state['storage']['regex']['replace'][$index]);
-
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Test Transformation Rules') {
-=======
-    } elseif ($op == 'Test Transformation Rules') {
->>>>>>> 6.x-0.4-dev
-
-      $patterns = $form_state['storage']['regex']['pattern'];
-      $replaces = $form_state['storage']['regex']['replace'];
-      $test_string = $form_state['values']['test_string'];
-      $form_state['storage']['test_regex_result'] = preg_replace($patterns, $replaces, $test_string);
-      $form_state['storage']['test_regex_test'] = $test_string;
-    }
-  }
-
-}
-
-/**
- * Edit Field Form
- *
- * This form is meant to be called from a bulk loader form. The following should be set
- * in the query section of the path:
- *  - template_id=\d+: the template which the edited field is part of
- *  - record_id=\d+: the priority or key in the template array of the record the field
- *      is currently part of
- *  - field_index=\d+: the key of the field in the fields array of the previously
- *      specified record
- *
- * @param $form_state
- *   Contains the values and storage for the form
- * @return
- *   A form array to be rendered by drupal_get_form
- */
-function tripal_bulk_loader_edit_template_field_form(&$form_state = NULL) {
-  $form = array();
-<<<<<<< HEAD
-   $form['#cache'] = TRUE; // Make sure the form is cached.
-
-   // get template id from path
-   $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
-
-   // if there is no template supplied don't return rest of form
-   if (!$template_id) {
-     return $form;
-   }
-=======
- 	$form['#cache'] = TRUE; // Make sure the form is cached.
-
- 	// get template id from path
- 	$template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
-
- 	// if there is no template supplied don't return rest of form
- 	if (!$template_id) {
- 	  return $form;
- 	}
->>>>>>> 6.x-0.4-dev
-
-  // Pre-set Variables needed for form proper------------------------------------------
-
-   // If this is the first load of the form (no form state) we need to initialize some variables
-   if (!$form_state['storage']['template']) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-    $template = db_fetch_object(db_query($sql, $template_id));
-    $form_state['storage']['template_array'] = unserialize($template->template_array);
-    $form_state['storage']['template'] = $template;
-
-    $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;
-    }
-
-    $form_state['storage']['referring URL'] = $_SERVER["HTTP_REFERER"];
-  }
-  else {
-    $template = $form_state['storage']['template'];
-  }
-
-  // get the field from the path
-  if (!($_GET['record_id']===NULL || $_GET['field_index']===NULL)) {
-    $priority = $_GET['record_id'];
-    $field_index = $_GET['field_index'];
-    $template_field = $form_state['storage']['template_array'][$priority]['fields'][$field_index];
-    $form_state['storage']['original_field'] = $template_field;
-    $form_state['storage']['original_field']['priority'] = $priority;
-    $form_state['storage']['original_field']['field_index'] = $field_index;
-  }
-
-  $field_type = ($form_state['values']['field_type'])? $form_state['values']['field_type'] : $template_field['type'];
-
-  // Tables and default table
-  $tables = tripal_core_get_chado_tables();
-  if ($form_state['values']) {
-    $table = $form_state['values']['chado_table'];
-<<<<<<< HEAD
-  }
-  else {
-    $table = $form_state['storage']['template_array'][$priority]['table'];
-  }
-=======
-  } else {
-    $table = $form_state['storage']['template_array'][$priority]['table'];
-  }
->>>>>>> 6.x-0.4-dev
-
-
-  // Fields and foreign key mappings
-  $chado_fields = array();
-  $fk_options = array();
-  $fk_options['NULL'] = 'None';
-  $table_description = module_invoke_all('chado_' . $table . '_schema');
-  if ($field_type == 'foreign key') {
-    $foreign_field2table = array();
-    foreach ($table_description['foreign keys'] as $key_table => $key_array) {
-      foreach ($key_array['columns'] as $left_field => $right_field) {
-        $chado_fields[$left_field] = $left_field;
-        $foreign_field2table[$left_field] = $key_table;
-      }
-    }
-    reset($chado_fields);
-
-    // set default field
-    if (empty($chado_fields)) {
-      $field = NULL;
-    }
-    elseif ($chado_fields[$form_state['values']['chado_field']]) {
-      $field = $form_state['values']['chado_field'];
-    }
-    elseif ($template_field['field']) {
-      $field = $template_field['field'];
-    }
-    else {
-      $field = current($chado_fields);
-    }
-    //dpm($field, 'field');
-
-    // Foreign key options
-    $foreign_table = $foreign_field2table[$field];
-    if ($foreign_table) {
-      foreach ($form_state['storage']['record2priority'] as $record_name_ => $priority_ ) {
-        if (preg_match('/^' . $foreign_table . '$/', $form_state['storage']['template_array'][$priority_]['table'])) {
-          $fk_options[$record_name_] = $record_name_;
-        }
-      }
-    }
-  }
-  else {
-    foreach ($table_description['fields'] as $field_name => $field_array) {
-        $chado_fields[$field_name] = $field_name;
-    }
-  }
-
-//  dpm(array( 'tables' => $tables, 'default table' => $table, 'record name' => $record_name, 'priority' => $priority,
-//    'fields' => $chad_fields, 'default field' => $field, 'foreign field=>table' => $foreign_field2table,
-//    'table desc' => $table_description, 'foreign record options' => $fk_options, 'foreign table' => $foreign_table
-//    ), 'Variables');
-
-  // Start of Form Proper--------------------------------------------------------------
-
-  $form['template_name'] = array(
-    '#type' => 'item',
-    '#title' => 'Template',
-    '#value' => $template->name,
-  );
-
-  $form['template_id'] = array(
-    '#type' => 'hidden',
-    '#value' => $template_id,
-  );
-
-  $form['edit_fields'] = array(
-    '#type' => 'fieldset',
-    '#prefix' => '<div id="tripal_bulk_loader_template-edit_field">',
-    '#suffix' => '</div>',
-  );
-
-  $form['edit_fields']['field_type'] = array(
-    '#type' => 'radios',
-    '#title' => t('Type of Field'),
-    '#options' => array(
-      'table field' => t('Spreadsheet: Fields which maps to a Spreadsheet Column'),
-      'constant' => t('Constant: Field which remains Constant throughout the Spreadsheet'),
-      'foreign key' => t('Foreign Key: Fields which map to a record in another table'),
-    ),
-    '#required' => TRUE,
-    '#default_value' => $field_type,
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/edit_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-edit_field',
-      'effect' => 'fade'
-    ),
-  );
-
-  // check template array for records then edit one more
-  if (!$form_state['storage']['record2priority']) {
-    $groups = array();
-  }
-  else {
-    $groups = array_flip($form_state['storage']['record2priority']);
-  }
-  $groups['NONE'] = 'Select a Record';
-  $groups['NEW'] = 'New Record';
-  $form['edit_fields']['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 spreadsheet',
-    '#options' => $groups,
-    '#default_value' => (preg_match('/(\d+|\w+)/', $form_state['values']['field_group'])) ? $form_state['values']['field_group'] : $priority,
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/edit_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-edit_field',
-      'effect' => 'fade'
-    ),
-    '#required' => TRUE,
-  );
-
-  $form['edit_fields']['record_name'] = array(
-    '#type' => (preg_match('/NEW/', $form_state['values']['field_group'])) ? 'textfield' : 'hidden',
-    '#title' => 'Unique Record Name',
-    '#prefix' => '<div id="tripal_bulk_loader_template-edit_record">',
-    '#suffix' => '</div>',
-    '#default_value' => $form_state['values']['record_name'],
-  );
-
-  $form['edit_fields']['field_title'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Human-readable Title for Field'),
-    '#default_value' => ($form_state['values']['field_title']) ? $form_state['values']['field_title'] : $template_field['title'],
-  );
-
-  // Spreadsheet column
-  $form['edit_fields']['columns'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Spreadsheet Column'),
-    '#collapsible' => TRUE,
-    '#collapsed' => ($field_type == 'table field')? FALSE : TRUE,
-  );
-
-  $form['edit_fields']['columns']['sheet_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Worksheet'),
-    '#description' => t('Specify the name of the worksheet.'),
-    '#size' => 5,
-    '#default_value' => ($form_state['values']['sheet_name'])? $form_state['values']['sheet_name'] : $template_field['spreadsheet sheet'],
-  );
-
-  $form['edit_fields']['columns']['column_number'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Column'),
-    '#description' => t('Specify the column in the spreadsheet that this field maps to where the first column is 1.'),
-    '#size' => 5,
-    '#default_value' => ($form_state['values']['column_number']) ? $form_state['values']['column_number'] : $template_field['spreadsheet column'],
-  );
-
-  $form['edit_fields']['columns']['column_exposed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow Column to be set for each Bulk Loading Job'),
-    '#description' => t('Adds a textbox field to the Bulk Loader Page to allow users to set this value.'),
-    '#default_value' => ($form_state['values']['column_exposed']) ? $form_state['values']['column_exposed'] : $template_field['exposed'],
-  );
-
-  $form['edit_fields']['columns']['column_exposed_desc'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Description for exposed field on bulk loading job'),
-    '#description' => t('This description should tell the user what column should be entered here.'),
-    '#default_value' => ($form_state['values']['column_exposed_desc']) ? $form_state['values']['column_exposed_desc'] : $template_field['exposed_description'],
-  );
-
-  // Global Value
-  $form['edit_fields']['constant'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Constant'),
-    '#collapsible' => TRUE,
-    '#collapsed' => ($field_type == 'constant')? FALSE : TRUE,
-  );
-
-  $form['edit_fields']['constant']['constant_value'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Constant Value'),
-    '#description' => t('Specify the value you wish this field to have regardless of spreadsheet data.'),
-    '#default_value' => ($form_state['values']['constant_value']) ? $form_state['values']['constant_value'] : $template_field['constant value'],
-  );
-
-  $form['edit_fields']['constant']['constant_exposed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow Constant to be set for each Bulk Loading Job'),
-    '#description' => t('Adds a textbox field to the Create Bulk Loader Form to allow users to set this value.'),
-    '#default_value' => ($form_state['values']['constant_exposed']) ? $form_state['values']['constant_exposed'] : $template_field['exposed'],
-  );
-
-  $form['edit_fields']['constant']['constant_validate'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Ensure value is in table'),
-    '#description' => t('Checks the database when a bulk loading job is created to ensure the value entered already exists in the database.'),
-    '#default_value' => ($form_state['values']['constant_validate']) ? $form_state['values']['constant_validate'] : $template_field['exposed_validate'],
-  );
-
-  // Foreign Key
-  $form['edit_fields']['foreign_key'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Foreign Key',
-    '#collapsible' => TRUE,
-    '#collapsed' => ($field_type == 'foreign key')? FALSE : TRUE,
-  );
-
-  $form['edit_fields']['foreign_key']['foreign_record'] = array(
-    '#type' => 'select',
-    '#title' => 'Record to refer to',
-    '#descripion' => 'Select the record that this foreign key shouold refer to. The record needs to already exist and be of the correct table.',
-    '#options' => $fk_options,
-  );
-
-  // Chado Field
-  $form['edit_fields']['chado'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Chado Field/Column Details'),
-    '#description' => t('Specify the Table/Field in chado that this field maps to.'),
-  );
-
-  $form['edit_fields']['chado']['chado_table'] = array(
-    '#type' => 'select',
-    '#title' => t('Chado Table'),
-    '#options' => $tables,
-    '#default_value' => $table,
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/edit_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-edit_field',
-      'effect' => 'fade'
-      ),
-  );
-
-  $form['edit_fields']['chado']['chado_field'] = array(
-    '#type' => 'select',
-    '#title' => t('Chado Field/Column'),
-    '#options' => $chado_fields,
-    '#default_value' => ($form_state['values']['chado_field']) ? $form_state['values']['chado_field'] : $template_field['field'],
-    '#ahah' => array(
-      'path' => 'admin/tripal/tripal_bulk_loader_template/edit_field_ahah',
-      'wrapper' => 'tripal_bulk_loader_template-edit_field',
-      'effect' => 'fade'
-    ),
-  );
-
-  $form['edit_fields']['additional'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Additional Options',
-  );
-
-  $form['edit_fields']['additional']['required'] = array(
-    '#type' => 'checkbox',
-    '#title' => 'Make this file required',
-    '#default_value' => $template_field['required'],
-  );
-
-  $form['edit_fields']['additional']['regex_transform'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Transform Spreadsheet Value Rules',
-    '#collapsible' => TRUE,
-    '#collapsed' => (!$template_field['regex']['pattern']) ? TRUE : FALSE,
-  );
-
-  $transformation_msg = '<p>A transformation rule allows you to transform the original value '
-      .'(usually from a user submitted spreadsheet) into the form you would like it stored '
-      .'in the chado database. Each rule consists of a match pattern (a php regular expression '
-      .'which determines which replacement patterns are applied and captures regions of the '
-      .'original value) and a replacement pattern (a string which may contain capture references '
-      .'that describes what the new value should be). Each rule is applied to the result of the '
-      .'previous rule.<p>';
-  $form['edit_fields']['additional']['regex_transform']['regex_description'] = array(
-    '#type' => 'item',
-    '#value' => $transformation_msg,
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['regex-data'] = array(
-    '#tree' => TRUE,
-  );
-  foreach ($template_field['regex']['pattern'] as $index => $pattern) {
-    $data_element = array(
-      'pattern' => array(
-        '#type' => 'item',
-        '#value' => $pattern,
-      ),
-      'replace' => array(
-        '#type' => 'item',
-        '#value' => $template_field['regex']['replace'][$index],
-      ),
-      'old_index' => array(
-        '#type' => 'hidden',
-        '#value' => $index,
-      ),
-      'new_index' => array(
-        '#type' => 'select',
-        '#options' => range(0, sizeof($template_field['regex']['pattern'])-1),
-        '#default_value' => $index,
-      ),
-      'id' => array(
-        '#type' => 'hidden',
-        '#value' => $index,
-      ),
-      'submit-delete' => array(
-        '#type' => 'submit',
-        '#value' => 'Delete Transformation',
-        '#name' => $index,
-      ),
-    );
-    $form['edit_fields']['additional']['regex_transform']['regex-data'][$index] = $data_element;
-  }
-
-  $form['edit_fields']['additional']['regex_transform']['submit-reorder_regex'] = array(
-    '#type' => 'submit',
-    '#value' => 'Save Transformation Rule Order'
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['new_regex'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Add a new Transformation Rule',
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['new_regex']['pattern'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Match Pattern',
-    '#description' => 'You can use standard <b>php regular expressions</b> in this field to specify a '
-      .'pattern. Only if this pattern matches the value in the spreadsheet does the replacement '
-      .'pattern get applied to the value. To capture a section of your value for use in the '
-      .'replacement patten surround with round brackets. For example, <i>GI:(\d+)</i> will match '
-      .' NCBI gi numbers and will capture the numerical digits for use in the replacement pattern. '
-      .' To match and capture any value use <i>.*</i>',
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['new_regex']['replace'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Replacement Pattern',
-    '#description' => '<p>This pattern should contain the text you want to replace the match pattern '
-    .'mentioned above. It can include references of the form <b>\n</b> where n is the number of the '
-    .'capture in the match pattern. For example, \1 will be replaced with the text matched in your '
-    .'first set of round brackets.</p>',
-  );
-
-  if ($field_type == 'table field') {
-    $tab = '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp';
-    $form['edit_fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
-      .'The following references are also available for spreadsheet fields: <b><#column:<i>number</i>#></b>. '
-      .'This allows you to substitute other spreadsheet values into the current field. For example, '
-      .'if you had the following line:<br>'
-      . $tab . 'SNP' . $tab . '15-Jan-2011' . $tab . '1' . $tab . '54' . $tab . 'Contig34355'
-      .'<br> and your current field is for column #1 and you\'re inserting into the chado field '
-      .'feature.uniquename then you might want to add in the data to ensure your uniquename is '
-      .'unique. The Match Pattern is (.*) to select all the first column and the Replacement '
-      .'Pattern could be \1_<#column:2#> which would insert SNP_15-Jan-2011 into the database.</p>';
-  }
-
-  $form['edit_fields']['additional']['regex_transform']['new_regex']['submit-add_transform'] = array(
-    '#type' => 'submit',
-    '#value' => 'Add Transformation',
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['test_regex'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Test Transformation Rules',
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['test_regex']['test_string'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Test Value',
-    '#description' => 'This should be a value that you expect the above transformation rules '
-      .'to be applied to.',
-    '#default_value' => $form_state['storage']['test_regex_test'],
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['test_regex']['test_result'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Test Result',
-    '#description' => 'This is the value that would be saved to the database after the above transformation '
-      .'riles were applied to the Test Value.',
-    '#default_value' => $form_state['storage']['test_regex_result'],
-  );
-
-  $form['edit_fields']['additional']['regex_transform']['test_regex']['submit-test'] = array(
-    '#type' => 'submit',
-    '#value' => 'Test Transformation Rules'
-  );
-
-  $form['edit_fields']['submit-edit_field'] = array(
-      '#type' => 'submit',
-      '#value' => 'Edit Field'
-  );
-
-  $form['edit_fields']['submit-cancel'] = array(
-      '#type' => 'submit',
-      '#value' => 'Cancel'
-  );
-
-  return $form;
-}
-
-/**
- * Edit Field Form Submit
- *
- * @param $form
- *   The form that was submitted
- * @param $form_state
- *   The values and storage for the form
- */
-function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state) {
-
-  $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
-  //dpm($op, 'Operation Submitted');
-
-  //Clear Test
-  $form_state['storage']['test_regex_result'] = NULL;
-  $form_state['storage']['test_regex_test'] = NULL;
-
-  if (!$form_state['ahah_submission']) {
-    if ($op ==  'Edit Field') {
-
-      // If new record
-      if (preg_match('/NEW/', $form_state['values']['field_group'])) {
-        // add new record
-        $record_name = $form_state['values']['record_name'];
-        $priority = sizeof($form_state['storage']['template_array']) + 1;
-        $old_priority = $form_state['storage']['original_field']['priority'];
-        $field_index = $form_state['storage']['original_field']['field_index'];
-        $form_state['storage']['record2priority'][$record_name] = $priority;
-        $form_state['storage']['template_array'][$priority]['table'] = $form_state['values']['chado_table'];
-        $form_state['storage']['template_array'][$priority]['record_id'] = $record_name;
-
-<<<<<<< HEAD
-      }
-      else {
-=======
-      } else {
->>>>>>> 6.x-0.4-dev
-        $priority = $form_state['values']['field_group'];
-        $old_priority = $form_state['storage']['original_field']['priority'];
-        $field_index = $form_state['storage']['original_field']['field_index'];
-        $record_name = $form_state['storage']['record2priority'][$priority];
-      }
-
-      $field = $form_state['storage']['original_field'];
-      if ($form_state['values']['field_type'] == 'table field') {
-          $field['type'] = 'table field';
-          $field['title'] = $form_state['values']['field_title'];
-          $field['field'] = $form_state['values']['chado_field'];
-          $field['required'] = $form_state['values']['required'];
-          //$field['allowed values'] = empty by default;
-          $field['spreadsheet sheet'] = $form_state['values']['sheet_name'];
-          $field['spreadsheet column'] = $form_state['values']['column_number'];
-          $field['exposed'] = $form_state['values']['column_exposed'];
-          $field['exposed_description'] = $form_state['values']['column_exposed_desc'];
-      }
-      elseif ($form_state['values']['field_type'] == 'constant') {
-          $field['type'] = 'constant';
-          $field['title'] = $form_state['values']['field_title'];
-          $field['field'] = $form_state['values']['chado_field'];
-          $field['required'] = $form_state['values']['required'];
-          //$field['allowed values'] = empty by default;
-          $field['constant value'] = $form_state['values']['constant_value'];
-          $field['exposed_validate'] = $form_state['values']['constant_validate'];
-          $field['exposed'] = $form_state['values']['constant_exposed'];
-<<<<<<< HEAD
-      }
-      elseif ($form_state['values']['field_type'] == 'foreign key') {
-=======
-      } elseif ($form_state['values']['field_type'] == 'foreign key') {
->>>>>>> 6.x-0.4-dev
-          $field['type'] = 'foreign key';
-          $field['title'] = $form_state['values']['field_title'];
-          $field['field'] = $form_state['values']['chado_field'];
-          $field['foreign key'] = $form_state['values']['foreign_record'];
-          $field['required'] = $form_state['values']['required'];
-      }
-
-      // Deal with any additional options
-
-      // if the record has changed...
-      $form_state['storage']['template_array'][$priority]['table'] = $form_state['values']['chado_table'];
-      if ($old_priority != $priority) {
-        $form_state['storage']['template_array'][$priority]['fields'][] = $field;
-        unset($form_state['storage']['template_array'][$old_priority]['fields'][$field_index]);
-
-        // if there are no fields left delete the old record
-        if (!$form_state['storage']['template_array'][$old_priority]['fields']) {
-          unset($form_state['storage']['template_array'][$old_priority]);
-        }
-      }
-      else {
-        $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $field;
-      }
-
-      // Save Template
-      $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
-      $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
-
-      if ($success) {
-        drupal_set_message('Successfully Updated Field');
-        drupal_set_message('Template Saved.');
-
-        $path = explode('?', $form_state['storage']['referring URL']);
-        parse_str($path[1], $query);
-        $query['template_id'] = $form_state['storage']['template']->template_id;
-        drupal_goto($path[0], $query);
-<<<<<<< HEAD
-      }
-      else {
-=======
-      } else {
->>>>>>> 6.x-0.4-dev
-        drupal_set_message('Unable to Save Template!', 'error');
-        watchdog('T_bulk_loader',
-          'Unable to save bulk loader template: %template',
-          array('%template' => print_r($form_state['storage']['template'], TRUE)),
-          WATCHDOG_ERROR
-        );
-      }
-
-<<<<<<< HEAD
-    }
-    elseif ($op ==  'Cancel') {
-
-        $path = explode('?', $form_state['storage']['referring URL']);
-=======
-    } elseif ($op ==  'Cancel') {
-
-        $path = explode('?',$form_state['storage']['referring URL']);
->>>>>>> 6.x-0.4-dev
-        parse_str($path[1], $query);
-        $query['template_id'] = $form_state['storage']['template']->template_id;
-        drupal_goto($path[0], $query);
-
-    }
-    elseif ($op == 'Add Transformation') {
-
-      // Add transformation rule to original field
-      $form_state['storage']['original_field']['regex']['pattern'][] = '/' . $form_state['values']['pattern'] . '/';
-      $form_state['storage']['original_field']['regex']['replace'][] = $form_state['values']['replace'];
-
-      // Add original field back into template
-      $priority = $form_state['storage']['original_field']['priority'];
-      $field_index = $form_state['storage']['original_field']['field_index'];
-      $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $form_state['storage']['original_field'];
-
-      // Save Template
-      $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
-      $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
-
-      if ($success) {
-        drupal_set_message('Successfully Added Transformation Rule');
-        drupal_set_message('Template Saved.');
-<<<<<<< HEAD
-      }
-      else {
-=======
-      } else {
->>>>>>> 6.x-0.4-dev
-        drupal_set_message('Unable to Save Template!', 'error');
-        watchdog('T_bulk_loader',
-          'Unable to save bulk loader template: %template',
-          array('%template' => print_r($form_state['storage']['template'], TRUE)),
-          WATCHDOG_ERROR
-        );
-      }
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Save Transformation Rule Order') {
-=======
-    } elseif ($op == 'Save Transformation Rule Order') {
->>>>>>> 6.x-0.4-dev
-
-      // Generate new regex array
-      $new_regex = array();
-      $old_regex = $form_state['storage']['original_field']['regex'];
-      foreach ($form_state['values']['regex-data'] as $key => $element) {
-        $new_regex['pattern'][ $element['new_index'] ] = $old_regex['pattern'][ $element['old_index'] ];
-        $new_regex['replace'][ $element['new_index'] ] = $old_regex['replace'][ $element['old_index'] ];
-      }
-
-      // sort new regex arrays
-      asort($new_regex['pattern']);
-      asort($new_regex['replace']);
-
-      // Add back to original field
-      $form_state['storage']['original_field']['regex'] = $new_regex;
-      $priority = $form_state['storage']['original_field']['priority'];
-      $field_index = $form_state['storage']['original_field']['field_index'];
-      $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $form_state['storage']['original_field'];
-
-      // Save Template
-      $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
-      $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
-
-      if ($success) {
-        drupal_set_message('Successfully Reordered Transformation Rules');
-        drupal_set_message('Template Saved.');
-<<<<<<< HEAD
-      }
-      else {
-=======
-      } else {
->>>>>>> 6.x-0.4-dev
-        drupal_set_message('Unable to Save Template!', 'error');
-        watchdog('T_bulk_loader',
-          'Unable to save bulk loader template: %template',
-          array('%template' => print_r($form_state['storage']['template'], TRUE)),
-          WATCHDOG_ERROR
-        );
-      }
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Delete Transformation') {
-=======
-    } elseif ($op == 'Delete Transformation') {
->>>>>>> 6.x-0.4-dev
-
-      // Unset regex rule
-      $index = $form_state['clicked_button']['#name'];
-      unset($form_state['storage']['original_field']['regex']['pattern'][$index]);
-      unset($form_state['storage']['original_field']['regex']['replace'][$index]);
-
-      $priority = $form_state['storage']['original_field']['priority'];
-      $field_index = $form_state['storage']['original_field']['field_index'];
-      $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $form_state['storage']['original_field'];
-
-      // Save Template
-      $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
-      $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
-
-      if ($success) {
-        drupal_set_message('Successfully Reordered Transformation Rules');
-        drupal_set_message('Template Saved.');
-<<<<<<< HEAD
-      }
-      else {
-=======
-      } else {
->>>>>>> 6.x-0.4-dev
-        drupal_set_message('Unable to Save Template!', 'error');
-        watchdog('T_bulk_loader',
-          'Unable to save bulk loader template: %template',
-          array('%template' => print_r($form_state['storage']['template'], TRUE)),
-          WATCHDOG_ERROR
-        );
-      }
-
-<<<<<<< HEAD
-    }
-    elseif ($op == 'Test Transformation Rules') {
-=======
-    } elseif ($op == 'Test Transformation Rules') {
->>>>>>> 6.x-0.4-dev
-
-      $patterns = $form_state['storage']['original_field']['regex']['pattern'];
-      $replaces = $form_state['storage']['original_field']['regex']['replace'];
-      $test_string = $form_state['values']['test_string'];
-      $form_state['storage']['test_regex_result'] = preg_replace($patterns, $replaces, $test_string);
-      $form_state['storage']['test_regex_test'] = $test_string;
-    }
-  }
-
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// AHAH Callbacks
-//////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * AHAH Function: Replace $form['add_fields'] in tripal_bulk_loader_add_template_field_form
- *
- * @return
- *  JSON Data printed to the screen
- */
-function tripal_bulk_loader_add_field_ahah() {
-
-  $form_state = array('storage' => NULL, 'submitted' => FALSE);
-  $form_build_id = $_POST['form_build_id'];
-  $form = form_get_cache($form_build_id, $form_state);
-  $args = $form['#parameters'];
-  $form_id = array_shift($args);
-  $form_state['post'] = $form['#post'] = $_POST;
-
-  // Enable the submit/validate handlers to determine whether AHAH-submittted.
-  $form_state['ahah_submission'] = TRUE;
-
-  $form['#programmed'] = $form['#redirect'] = FALSE;
-  drupal_process_form($form_id, $form, $form_state);
-  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
-
-  $form_element = $form['add_fields'];
-  // Remove the wrapper so we don't double it up.
-  //unset($form_element['#prefix'], $form_element['#suffix']);
-
-  $output = theme('status_messages');
-  $output .= drupal_render($form_element);
-
-  // Final rendering callback.
-  print drupal_json(array('status' => TRUE, 'data' => $output));
-  exit();
-
-}
-
-/**
- * AHAH Function: Replace $form['edit_fields'] in tripal_bulk_loader_edit_template_field_form
- *
- * @return
- *  JSON Data printed to the screen
- */
-function tripal_bulk_loader_edit_field_ahah() {
-
-  $form_state = array('storage' => NULL, 'submitted' => FALSE);
-  $form_build_id = $_POST['form_build_id'];
-  $form = form_get_cache($form_build_id, $form_state);
-  $args = $form['#parameters'];
-  $form_id = array_shift($args);
-  $form_state['post'] = $form['#post'] = $_POST;
-
-  // Enable the submit/validate handlers to determine whether AHAH-submittted.
-  $form_state['ahah_submission'] = TRUE;
-
-  $form['#programmed'] = $form['#redirect'] = FALSE;
-  drupal_process_form($form_id, $form, $form_state);
-  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
-
-  $form_element = $form['edit_fields'];
-  // Remove the wrapper so we don't double it up.
-  unset($form_element['#prefix'], $form_element['#suffix']);
-
-  $output = theme('status_messages');
-  $output .= drupal_render($form_element);
-
-  // Final rendering callback.
-  print drupal_json(array('status' => TRUE, 'data' => $output));
-  exit();
-
-<<<<<<< HEAD
-}
-=======
-}
->>>>>>> 6.x-0.4-dev

+ 11 - 0
tripal_bulk_loader/tripal_bulk_loader.coder_ignores.txt

@@ -0,0 +1,11 @@
+; The file should be formatted this way :
+; file:line:warning-type
+; where warning-type is one of security, style, sql, i18n, comment, etc.
+
+; all variables are filtered
+tripal_bulk_loader.admin.inc:398:security
+tripal_bulk_loader.constants.inc::260:security
+
+; doesn't need to be filtered b/c all variables set in code and not subjected to
+; user input
+tripal_bulk_loader.constants.inc:376:security

+ 6 - 5
tripal_bulk_loader/tripal_bulk_loader.constants.inc

@@ -160,15 +160,15 @@ function tripal_bulk_loader_set_constants_form($form_state, $node) {
           $group = $field['group_id'];
           $form['exposed_fields']['existing'][$group][$index] = array(
             '#type' => 'markup',
-            '#value' => $field['value'],
+            '#value' => filter_xss($field['value']),
           );
         }
       }
 
       $form['exposed_fields']['existing'][$group]['delete'] = array(
         '#type' => 'markup',
-        '#value' => l(t('Edit'), 'node/' . $node->nid . '/constants/' . $group . '/edit') . '<br />'  .
-          l(t('Delete'), 'node/' . $node->nid . '/constants/' . $group . '/delete'),
+        '#value' => filter_xss(l(t('Edit'), 'node/' . $node->nid . '/constants/' . $group . '/edit') . '&nbsp&nbsp|&nbsp&nbsp'  .
+          l(t('Delete'), 'node/' . $node->nid . '/constants/' . $group . '/delete')),
       );
 
     }
@@ -364,6 +364,7 @@ function theme_tripal_bulk_loader_set_constants_form($form) {
       $i++;
     }
     //drupal_add_tabledrag('mytable', 'order', 'sibling', 'weight-group');
+    // @coder-ignore: no user input thus don't need to filter
     $form['exposed_fields']['existing'] = array(
       '#type' => 'markup',
       '#value' => theme('table', $header, $rows, array('id' => 'mytable')) . '<br />'
@@ -509,7 +510,7 @@ function tripal_bulk_loader_edit_constant_set_form_submit($form, $form_state) {
         );
       }
     }
-    drupal_set_message('The constant set was successfully updated.');
+    drupal_set_message(t('The constant set was successfully updated.'));
 
   }
 
@@ -562,7 +563,7 @@ function tripal_bulk_loader_delete_constant_set_form_submit($form, $form_state)
   $nid = $form_state['values']['nid'];
   if ($nid && $form_state['values']['confirm']) {
     db_query("DELETE FROM {tripal_bulk_loader_constants} WHERE nid=%d AND group_id=%d", $nid, $group_id);
-    drupal_set_message('Constant set successfully deleted.');
+    drupal_set_message(t('Constant set successfully deleted.'));
   }
 
 }

+ 2 - 2
tripal_bulk_loader/tripal_bulk_loader.install

@@ -9,14 +9,14 @@
  * Implements hook_install
  */
 function tripal_bulk_loader_install() {
-   drupal_install_schema('tripal_bulk_loader');
+  drupal_install_schema('tripal_bulk_loader');
 }
 
 /**
  * Implements hook_uninstall
  */
 function tripal_bulk_loader_uninstall() {
-   drupal_uninstall_schema('tripal_bulk_loader');
+  drupal_uninstall_schema('tripal_bulk_loader');
 }
 
 /**

+ 100 - 29
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -135,13 +135,18 @@ function tripal_bulk_loader_load_data($nid) {
   $default_data = array();
   $field2column = array();
   $record2priority = array();
+  $tables = array();
 
   foreach ($node->template->template_array as $priority => $record_array) {
     if (!is_array($record_array)) {
       continue;
     }
 
-    //watchdog('T_bulk_loader','1)'.$record_array['record_id']." => \n<pre>".print_r($record_array,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
+    // Add tables being inserted into to a list to be treated differently
+    // this is used to acquire locks on these tables
+    if (preg_match('/insert/', $record_array['mode'])) {
+      $tables[$record_array['table']] = $record_array['table'];
+    }
 
     foreach ($record_array['fields'] as $field_index => $field_array) {
 
@@ -235,7 +240,11 @@ function tripal_bulk_loader_load_data($nid) {
     //print "\nField to Column Mapping: ".print_r($field2column, TRUE)."\n";
 
     // Parse File adding records as we go ========================================================
+
+    // Open File
     $file_handle = fopen($node->file, 'r');
+
+    // Set defaults
     if (preg_match('/(t|true|1)/', $node->file_has_header)) {
       fgets($file_handle, 4096);
     }
@@ -244,8 +253,38 @@ function tripal_bulk_loader_load_data($nid) {
     $num_errors = 0;
     $interval = intval($total_lines * 0.10);
     if ($interval == 0) {
-       $interval = 1;
-     }
+      $interval = 1;
+    }
+
+    // Start Transaction
+    switch (variable_get('tripal_bulk_loader_transactions', 'row')) {
+      case "none":
+        break;
+      case "all":
+        tripal_db_start_transaction();
+        $transactions = TRUE;
+        $savepoint = "";
+        break;
+      case "row":
+        tripal_db_start_transaction();
+        $transactions = TRUE;
+        $savepoint = "last_row_complete";
+        break;
+    }
+
+    // Disable triggers
+    $triggers_disabled = FALSE;
+    if ($transactions AND variable_get('tripal_bulk_loader_disable_triggers', TRUE)) {
+      $triggers_disabled = TRUE;
+      chado_query("SET CONSTRAINTS ALL DEFERRED");
+    }
+
+    // Acquire Locks
+    $lockmode = variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE');
+    foreach ($tables as $table) {
+      chado_query("LOCK TABLE %s IN %s MODE", $table, $lockmode);
+    }
+
     while (!feof($file_handle)) {
 
       // Clear variables
@@ -276,14 +315,6 @@ function tripal_bulk_loader_load_data($nid) {
         // and had a group percentage of 50% then the job progress would be
         // (2*100 + 50%) / 3 = 250%/3 = 83%
         $job_progress = round(((($group_index-1)*100)+$group_progress)/$total_num_groups);
-
-        /**
-          print "\nProgress Update:\n"
-            ."\t- ".$num_lines." lines have been processed for the current constant set.\n"
-            ."\t- ".$group_progress."% of the lines in the file have been processed for the current constant set.\n"
-            ."\t- ".$job_progress."% of the current job has been completed.\n";
-        */
-
         tripal_job_set_progress($node->job_id, $job_progress);
       }
 
@@ -293,11 +324,45 @@ function tripal_bulk_loader_load_data($nid) {
       foreach ($data_keys as $priority) {
         $status = process_data_array_for_line($priority, $data, $default_data, $field2column, $record2priority, $line, $nid, $num_lines, $group_index);
         if (!$status ) {
-          $loaded_without_errors = FALSE;
+          // Encountered an error
+          if ($transactions) {
+            tripal_db_rollback_transaction($savepoint);
+          }
+          $failed = TRUE;
+          break;
         }
       } // end of foreach table in default data array
 
+      if ($failed) {
+        break;
+      }
+      else {
+        // Row inserted successfully
+        // Set savepoint if supplied
+        if ($savepoint) {
+          if ($num_lines == 1) {
+            tripal_db_set_savepoint_transaction($savepoint);
+          }
+          else {
+            // Tell it to remove the previous savepoint of the same name
+            tripal_db_set_savepoint_transaction($savepoint, TRUE);
+          }
+        }
+      }
+
     } //end of foreach line of file
+
+    // END Transaction
+    if ($transactions) {
+      // end the transaction
+      tripal_db_commit_transaction();
+    }
+
+    if ($failed) {
+      $loaded_without_errors = FALSE;
+      break;
+    }
+
   } //end of foreach constant set
 
   // check that data was inserted and update job_status
@@ -310,11 +375,11 @@ function tripal_bulk_loader_load_data($nid) {
 
   // set the status of the job (in the node not the tripal jobs)
   if ($loaded_without_errors) {
-      $status = 'Loading Completed Successfully';
-    }
-    else {
-      $status = 'Errors Encountered';
-      }
+    $status = 'Loading Completed Successfully';
+  }
+  else {
+    $status = 'Errors Encountered';
+  }
   db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", $status, $nid);
 
 }
@@ -366,9 +431,9 @@ function process_data_array_for_line($priority, &$data, &$default_data, $field2c
       // a field is considered missing if it cannot be null and there is no default
       // value for it or it is of type 'serial'
       if ($def['not null'] == 1 and !array_key_exists($field, $insert_values) and !isset($def['default']) and strcmp($def['type'], serial)!=0) {
-         $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Missing Database Required Value: ' . $table . '.' . $field;
-         watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE);
-         $data[$priority]['error'] = TRUE;
+        $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Missing Database Required Value: ' . $table . '.' . $field;
+        watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE);
+        $data[$priority]['error'] = TRUE;
       }
     }
   } //end of if optional record
@@ -419,9 +484,9 @@ function process_data_array_for_line($priority, &$data, &$default_data, $field2c
 
 
   if (!preg_match('/select/', $table_data['mode'])) {
-    //watchdog('T_bulk_loader',$header.': Inserting:'.print_r($values, TRUE), array(), WATCHDOG_NOTICE);
-    if (variable_get('tripal_bulk_loader_prepare',TRUE)) {
-      $options = array('statement_name' => $priority);
+    // Use prepared statement?
+    if (variable_get('tripal_bulk_loader_prepare', TRUE)) {
+      $options = array('statement_name' => 'record_' . $priority);
       if ($line_num == 1 && $group_index == 1) {
         $options['prepare'] = TRUE;
       }
@@ -430,6 +495,11 @@ function process_data_array_for_line($priority, &$data, &$default_data, $field2c
       $options = array();
     }
 
+    // Skip tripal_core_chado_insert() built-in validation?
+    if (variable_get('tripal_bulk_loader_skip_validation', FALSE)) {
+      $options['skip_validation'] = TRUE;
+    }
+
     $record = tripal_core_chado_insert($table, $values, $options);
 
     if (!$record) {
@@ -482,6 +552,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $field2c
       $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') No Matching record in ' . $table . ' where values:' . print_r($values, TRUE);
       watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
       $data[$priority]['error'] = TRUE;
+      $no_errors = FALSE;
     }
   }
   return $no_errors;
@@ -564,8 +635,8 @@ function tripal_bulk_loader_regex_tranform_values($values, $table_data, $line) {
 
   foreach ($table_data['regex_transform'] as $field => $regex_array) {
     if (!is_array($regex_array['replace'])) {
-       continue;
-     }
+      continue;
+    }
 
     //print 'Match:'.print_r($regex_array['pattern'],TRUE)."\n";
     //print 'Replace:'.print_r($regex_array['replace'],TRUE)."\n";
@@ -609,8 +680,8 @@ function tripal_bulk_loader_flatten_array($values) {
     if (is_array($v)) {
       $vstr = array();
       foreach ($v as $vk => $vv) {
-        if (strlen($vv) > 20) {
-          $vstr[] = $vk . '=>' . substr($vv, 0, 20) . '...';
+        if (drupal_strlen($vv) > 20) {
+          $vstr[] = $vk . '=>' . drupal_substr($vv, 0, 20) . '...';
         }
         else {
           $vstr[] = $vk . '=>' . $vv;
@@ -618,8 +689,8 @@ function tripal_bulk_loader_flatten_array($values) {
       }
       $v = '{' . implode(',', $vstr) . '}';
     }
-    elseif (strlen($v) > 20) {
-      $v = substr($v, 0, 20) . '...';
+    elseif (drupal_strlen($v) > 20) {
+      $v = drupal_substr($v, 0, 20) . '...';
     }
     $flattened_values[] = $k . '=>' . $v;
   }

+ 0 - 733
tripal_bulk_loader/tripal_bulk_loader.loader.inc.orig

@@ -1,733 +0,0 @@
-<?php
-
-/**
- * @file
- * @todo Add file header description
- */
-
-/**
- * Add Loader Job Form
- *
- * This form is meant to be included on the node page to allow users to submit/re-submit
- * loading jobs
- */
-function tripal_bulk_loader_add_loader_job_form($form_state, $node) {
-  $form = array();
-
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid,
-  );
-
-  $form['file'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->file
-  );
-
-  $form['job_id'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->job_id,
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => ($node->job_id) ? 'Re-Submit Job' : 'Submit Job',
-  );
-
-  $form['submit-cancel'] = array(
-    '#type' => ($node->job_id)? 'submit' : 'hidden',
-    '#value' => 'Cancel Job',
-  );
-
-  $form['submit-revert'] = array(
-    '#type' => ($node->job_id) ? 'submit' : 'hidden',
-    '#value' => 'Revert',
-  );
-
-  return $form;
-}
-
-/**
- * Add Loader Job Form (Submit)
- */
-function tripal_bulk_loader_add_loader_job_form_submit($form, $form_state) {
-  global $user;
-
-  if (preg_match('/Submit Job/', $form_state['values']['op'])) {
-    //Submit Tripal Job
-<<<<<<< HEAD
-    $job_args[1] = $form_state['values']['nid'];
-    if (is_readable($form_state['values']['file'])) {
-      $fname = basename($form_state['values']['file']);
-      $job_id = tripal_add_job("Bulk Loading Job: $fname", 'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
-
-      // add job_id to bulk_loader node
-      $success = db_query("UPDATE {tripal_bulk_loader} SET job_id=%d WHERE nid=%d", $job_id, $form_state['values']['nid']);
-
-      // change status
-      db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Submitted to Queue', $form_state['values']['nid']);
-    }
-    else {
-      drupal_set_message(t("Can not open %file. Job not scheduled.", array('%file' => $form_state['values']['file'])));
-    }
-  }
-  elseif (preg_match('/Re-Submit Job/', $form_state['values']['op'])) {
-=======
-		$job_args[1] = $form_state['values']['nid'];
-		if (is_readable($form_state['values']['file'])) {
-			$fname = basename($form_state['values']['file']);
-			$job_id = tripal_add_job("Bulk Loading Job: $fname",'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
-
-			// add job_id to bulk_loader node
-      $success = db_query("UPDATE {tripal_bulk_loader} SET job_id=%d WHERE nid=%d", $job_id, $form_state['values']['nid']);
-
-      // change status
-      db_query("UPDATE tripal_bulk_loader SET job_status='%s' WHERE nid=%d",'Submitted to Queue', $form_state['values']['nid']);
-		} else {
-			drupal_set_message("Can not open ".$form_state['values']['file'].". Job not scheduled.");
-		}
-  } elseif (preg_match('/Re-Submit Job/', $form_state['values']['op'])) {
->>>>>>> 6.x-0.4-dev
-    tripal_jobs_rerun($form_state['values']['job_id']);
-    db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Submitted to Queue', $form_state['values']['nid']);
-  }
-  elseif (preg_match('/Cancel Job/', $form_state['values']['op'])) {
-    db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Job Cancelled', $form_state['values']['nid']);
-    tripal_jobs_cancel($form_state['values']['job_id']);
-<<<<<<< HEAD
-  }
-  elseif (preg_match('/Revert/', $form_state['values']['op'])) {
-=======
-  } elseif (preg_match('/Revert/', $form_state['values']['op'])) {
->>>>>>> 6.x-0.4-dev
-
-    // Remove the records from the database that were already inserted
-    $resource = db_query('SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d ORDER BY tripal_bulk_loader_inserted_id DESC', $form_state['values']['nid']);
-    while ($r = db_fetch_object($resource)) {
-      $ids = preg_split('/,/', $r->ids_inserted);
-      db_query('DELETE FROM %s WHERE %s IN (%s)', $r->table_inserted_into, $r->table_primary_key, $r->ids_inserted);
-      $result = db_fetch_object(db_query('SELECT true as present FROM %s WHERE %s IN (%s)', $r->table_inserted_into, $r->table_primary_key, $r->ids_inserted));
-      if (!$result->present) {
-        drupal_set_message(t('Successfully Removed data Inserted into the %tableto table.', array('%tableto' => $r->table_inserted_into)));
-        db_query('DELETE FROM {tripal_bulk_loader_inserted} WHERE tripal_bulk_loader_inserted_id=%d', $r->tripal_bulk_loader_inserted_id);
-      }
-      else {
-        drupal_set_message(t('Unable to remove data Inserted into the %tableto table!', array('%tableto' => $r->table_inserted_into)), 'error');
-      }
-    }
-
-    // reset status
-    db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Reverted -Data Deleted', $form_state['values']['nid']);
-  }
-
-}
-
-/**
- * Tripal Bulk Loader
- *
- * This is the function that's run by tripal_launch_jobs to bulk load chado data.
- *
- * @param $nid
- *   The Node ID of the bulk loading job node to be loaded. All other needed data is expected to be
- *   in the node (ie: template ID and file)
- *
- * Note: Instead of returning a value this function updates the tripal_bulk_loader.status.
- *   Errors are thrown through watchdog and can be viewed at admin/reports/dblog.
- */
-function tripal_bulk_loader_load_data($nid) {
-
-  // ensure no timeout
-  set_time_limit(0);
-
-  // set the status of the job (in the node not the tripal jobs)
-  db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Loading...', $nid);
-
-
-<<<<<<< HEAD
-=======
-
->>>>>>> 6.x-0.4-dev
-  $node = node_load($nid);
-  print "Template: " . $node->template->name . " (" . $node->template_id . ")\n";
-
-  $total_lines = trim(`wc --lines < $node->file`);
-<<<<<<< HEAD
-  print "File: " . $node->file . " (" . $total_lines . " lines)\n";
-=======
-  print "File: ".$node->file." (".$total_lines." lines)\n";
->>>>>>> 6.x-0.4-dev
-
-  // Prep Work ==================================================================================
-  $loaded_without_errors = TRUE;
-
-  // Generate default values array
-  $default_data = array();
-  $field2column = array();
-  $record2priority = array();
-
-  foreach ($node->template->template_array as $priority => $record_array) {
-    if (!is_array($record_array)) {
-      continue;
-    }
-
-    //watchdog('T_bulk_loader','1)'.$record_array['record_id']." => \n<pre>".print_r($record_array,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-
-    foreach ($record_array['fields'] as $field_index => $field_array) {
-
-      $default_data[$priority]['table'] = $record_array['table'];
-      $default_data[$priority]['mode'] = ($record_array['mode']) ? $record_array['mode'] : 'insert_unique';
-      $default_data[$priority]['record_id'] = $record_array['record_id'];
-      $record2priority[$record_array['record_id']] = $priority;
-      $default_data[$priority]['required'][$field_array['field']] = $field_array['required'];
-
-      $one = $default_data[$priority];
-      if (isset($field_array['regex'])) {
-        $default_data[$priority]['regex_transform'][$field_array['field']] = $field_array['regex'];
-      }
-
-      $two = $default_data[$priority];
-
-      if (preg_match('/table field/', $field_array['type'])) {
-        $default_data[$priority]['values_array'][$field_array['field']] = '';
-        $default_data[$priority]['need_further_processing'] = TRUE;
-        $field2column[$priority][$field_array['field']] = $field_array['spreadsheet column'];
-
-<<<<<<< HEAD
-      }
-      elseif (preg_match('/constant/', $field_array['type'])) {
-        $default_data[$priority]['values_array'][$field_array['field']] = $field_array['constant value'];
-
-      }
-      elseif (preg_match('/foreign key/', $field_array['type'])) {
-=======
-      } elseif (preg_match('/constant/', $field_array['type'])) {
-        $default_data[$priority]['values_array'][$field_array['field']] = $field_array['constant value'];
-
-      } elseif (preg_match('/foreign key/', $field_array['type'])) {
->>>>>>> 6.x-0.4-dev
-        $default_data[$priority]['values_array'][$field_array['field']] = array();
-        $default_data[$priority]['values_array'][$field_array['field']]['foreign record'] = $field_array['foreign key'];
-        $default_data[$priority]['need_further_processing'] = TRUE;
-
-<<<<<<< HEAD
-      }
-      else {
-        print 'WARNING: Unsupported type: ' . $field_array['type'] . ' for ' . $table . '.' . $field_array['field'] . "!\n";
-=======
-      } else {
-        print 'WARNING: Unsupported type: '. $field_array['type'] . ' for ' . $table . '.' . $field_array['field']."!\n";
->>>>>>> 6.x-0.4-dev
-      }
-
-      $three = $default_data[$priority];
-      //watchdog('T_bulk_loader','A)'.$field_index.':<pre>Field Array =>'.print_r($field_array,TRUE)."Initial => \n".print_r($one, TRUE)."\nAfter Regex =>".print_r($two, TRUE)."Final =>\n".print_r($three,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-
-    } // end of foreach field
-    //watchdog('T_bulk_loader','2)'.$record_array['record_id'].':<pre>'.print_r($default_data[$priority], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-  } //end of foreach record
-
-  ///////////////////////////////////////////////
-  // For each set of constants
-  ///////////////////////////////////////////////
-  $original_default_data = $default_data;
-  $group_index = 0;
-  $total_num_groups = sizeof($node->constants);
-  foreach ($node->constants as $group_id => $set) {
-    // revert default data array for next set of constants
-    $default_data = $original_default_data;
-    $group_index++;
-
-    // Add constants
-    if (!empty($set)) {
-      print "Constants:\n";
-      foreach ($set as $priority => $record) {
-        foreach ($record as $field_id => $field) {
-
-<<<<<<< HEAD
-          print "\t- " . $field['chado_table'] . '.' . $field['chado_field'] . ' = ' . $field['value'] . "\n";
-=======
-          print "\t- ".$field['chado_table'].'.'.$field['chado_field'].' = '.$field['value']."\n";
->>>>>>> 6.x-0.4-dev
-
-          if ($default_data[$priority]['table'] == $field['chado_table']) {
-            if (isset($default_data[$priority]['values_array'][$field['chado_field']])) {
-              if (isset($field2column[$priority][$field['chado_field']])) {
-                $field2column[$priority][$field['chado_field']] = $field['value'];
-              }
-              else {
-                $default_data[$priority]['values_array'][$field['chado_field']] = $field['value'];
-              }
-            }
-            else {
-              print "ERROR: Template has changed after constants were assigned!\n";
-              watchdog('T_bulk_loader', 'Template has changed after constants were assigned', array(), WATCHDOG_NOTICE);
-              exit(1);
-            }
-          }
-          else {
-            print "ERROR: Template has changed after constants were assigned!\n";
-            watchdog('T_bulk_loader', 'Template has changed after constants were assigned', array(), WATCHDOG_NOTICE);
-            exit(1);
-          }
-        }
-      }
-    }
-
-    //print "Default Data:".print_r($default_data,TRUE)."\n";
-    //watchdog('T_bulk_loader','Default Data:<pre>'.print_r($default_data, TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-
-    //print "\nDefault Values Array: ".print_r($default_data, TRUE)."\n";
-    //print "\nField to Column Mapping: ".print_r($field2column, TRUE)."\n";
-
-    // Parse File adding records as we go ========================================================
-    $file_handle = fopen($node->file, 'r');
-    if (preg_match('/(t|true|1)/', $node->file_has_header)) {
-      fgets($file_handle, 4096);
-    }
-    $num_records = 0;
-    $num_lines = 0;
-    $num_errors = 0;
-    $interval = intval($total_lines * 0.10);
-    if ($interval == 0) {
-       $interval = 1;
-     }
-    while (!feof($file_handle)) {
-
-      // Clear variables
-      // Was added to fix memory leak
-      unset($line);                     unset($raw_line);
-      unset($data);                     unset($data_keys);
-      unset($priority);                 unset($sql);
-      unset($result);
-
-      $raw_line = fgets($file_handle, 4096);
-      $raw_line = trim($raw_line);
-      if (empty($raw_line)) {
-        continue;
-      } // skips blank lines
-      $line = explode("\t", $raw_line);
-      $num_lines++;
-
-      // update the job status every 10% of lines processed for the current group
-      if ($node->job_id and $num_lines % $interval == 0) {
-        // percentage of lines processed for the current group
-        $group_progress = round(($num_lines/$total_lines)*100);
-
-        // percentage of lines processed for all groups
-        // <previous group index> * 100 + <current group progress>
-        // --------------------------------------------------------
-        //               <total number of groups>
-        // For example, if you were in the third group of 3 constant sets
-        // and had a group percentage of 50% then the job progress would be
-        // (2*100 + 50%) / 3 = 250%/3 = 83%
-        $job_progress = round(((($group_index-1)*100)+$group_progress)/$total_num_groups);
-
-        /**
-          print "\nProgress Update:\n"
-            ."\t- ".$num_lines." lines have been processed for the current constant set.\n"
-            ."\t- ".$group_progress."% of the lines in the file have been processed for the current constant set.\n"
-            ."\t- ".$job_progress."% of the current job has been completed.\n";
-        */
-
-<<<<<<< HEAD
-        tripal_job_set_progress($node->job_id, $job_progress);
-=======
-        tripal_job_set_progress($node->job_id,$job_progress);
->>>>>>> 6.x-0.4-dev
-      }
-
-      $data = $default_data;
-
-      $data_keys = array_keys($data);
-      foreach ($data_keys as $priority) {
-        $status = process_data_array_for_line($priority, $data, $default_data, $field2column, $record2priority, $line, $nid, $num_lines, $group_index);
-        if (!$status ) {
-          $loaded_without_errors = FALSE;
-        }
-      } // end of foreach table in default data array
-
-    } //end of foreach line of file
-  } //end of foreach constant set
-
-  // check that data was inserted and update job_status
-  $sql = 'SELECT count(*) as num_tables FROM {tripal_bulk_loader_inserted} WHERE nid=%d GROUP BY nid';
-  $result = db_fetch_object(db_query($sql, $nid));
-  if ($result->num_tables > 0) {
-    $node->job_status = 'Data Inserted';
-    drupal_write_record('node', $node, 'nid');
-  }
-
-  // set the status of the job (in the node not the tripal jobs)
-  if ($loaded_without_errors) {
-      $status = 'Loading Completed Successfully';
-    }
-    else {
-      $status = 'Errors Encountered';
-      }
-  db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", $status, $nid);
-
-}
-
-/**
- *
- *
- */
-function process_data_array_for_line($priority, &$data, &$default_data, $field2column, $record2priority, $line, $nid, $line_num, $group_index) {
-  $table_data = $data[$priority];
-
-  $no_errors = TRUE;
-
-  $table = $table_data['table'];
-  $values = $table_data['values_array'];
-
-  //watchdog('T_bulk_loader','Original:<pre>'.print_r($table_data, TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-
-  //print 'default values:'.print_r($values,TRUE)."\n";
-  if ($table_data['need_further_processing']) {
-    $values = tripal_bulk_loader_add_spreadsheetdata_to_values($values, $line, $field2column[$priority]);
-    if (!$values) {
-      watchdog('T_bulk_loader', 'Line ' . $line_num . ' Spreadsheet Added:' . print_r($values, TRUE), array(), WATCHDOG_NOTICE);
-    }
-
-    $values = tripal_bulk_loader_add_foreignkey_to_values($values, $data, $record2priority);
-    if (!$values) {
-      watchdog('T_bulk_loader', 'Line ' . $line_num . ' FK Added:<pre>' . print_r($values, TRUE) . print_r($data[$priority], TRUE) . '</pre>', array(), WATCHDOG_NOTICE);
-    }
-  }
-  $values = tripal_bulk_loader_regex_tranform_values($values, $table_data, $line);
-  if (!$values) {
-    watchdog('T_bulk_loader', 'Line ' . $line_num . ' Regex:<pre>' . print_r($values, TRUE) . print_r($table_data, TRUE) . '</pre>' . '</pre>', array(), WATCHDOG_NOTICE);
-  }
-
-  if (!$values) {
-<<<<<<< HEAD
-    $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Aborted due to error in previous record. Values of current record:' . print_r($table_data['values_array'], TRUE);
-    watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
-    print "ERROR: " . $msg . "\n";
-=======
-    $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Aborted due to error in previous record. Values of current record:'.print_r($table_data['values_array'],TRUE);
-    watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
-    print "ERROR: ".$msg."\n";
->>>>>>> 6.x-0.4-dev
-    $data[$priority]['error'] = TRUE;
-    $no_errors = FALSE;
-  }
-
-<<<<<<< HEAD
-  $table_desc = module_invoke_all('chado_' . $table . '_schema');
-=======
-  $table_desc = module_invoke_all('chado_'.$table.'_schema');
->>>>>>> 6.x-0.4-dev
-  if (preg_match('/optional/', $table_array['mode'])) {
-    // Check all db required fields are set
-    $fields = $table_desc['fields'];
-    foreach ($fields as $field => $def) {
-      // a field is considered missing if it cannot be null and there is no default
-      // value for it or it is of type 'serial'
-<<<<<<< HEAD
-      if ($def['not null'] == 1 and !array_key_exists($field, $insert_values) and !isset($def['default']) and strcmp($def['type'], serial)!=0) {
-         $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Missing Database Required Value: ' . $table . '.' . $field;
-=======
-      if($def['not null'] == 1 and !array_key_exists($field,$insert_values) and !isset($def['default']) and strcmp($def['type'],serial)!=0){
-         $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Missing Database Required Value: '.$table.'.'.$field;
->>>>>>> 6.x-0.4-dev
-         watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE);
-         $data[$priority]['error'] = TRUE;
-      }
-    }
-  } //end of if optional record
-
-  // Check required fields are present
-  foreach ($table_data['required'] as $field => $required) {
-    if ($required) {
-      if (!isset($values[$field])) {
-<<<<<<< HEAD
-        $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Missing Template Required Value: ' . $table . '.' . $field;
-=======
-        $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Missing Template Required Value: '.$table.'.'.$field;
->>>>>>> 6.x-0.4-dev
-        watchdog('T_bulk_loader', $msg, array(), WATCHDOG_NOTICE);
-        $data[$priority]['error'] = TRUE;
-      }
-    }
-  }
-
-  // add new values array into the data array
-  $data[$priority]['values_array'] = $values;
-
-  // check if it is already inserted
-  if ($table_data['inserted']) {
-    //watchdog('T_bulk_loader','Already Inserted:'.print_r($values,TRUE),array(),WATCHDOG_NOTICE);
-    return $no_errors;
-  }
-
-  // if there was an error already -> don't insert
-  if ($data[$priority]['error']) {
-    return $no_errors;
-  }
-
-  $header = '';
-  if (isset($values['feature_id'])) {
-    $header = $values['feature_id']['uniquename'] . ' ' . $table_data['record_id'];
-  }
-  else {
-    $header = $values['uniquename'] . ' ' . $table_data['record_id'];
-  }
-
-  // if insert unique then check to ensure unique
-  if (preg_match('/insert_unique/', $table_data['mode'])) {
-    $unique = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record' => TRUE));
-    //print 'Unique?'.print_r(array('table' => $table, 'columns' => array_keys($table_desc['fields']), 'values' => $values),TRUE).' returns '.$unique."\n";
-    if ($unique > 0) {
-      //$default_data[$priority]['inserted'] = TRUE;
-      //watchdog('T_bulk_loader', $header.': Not unique ('.$unique.'):'.print_r($values,'values')."\n".print_r($data,TRUE),array(),WATCHDOG_NOTICE);;
-      return $no_errors;
-    }
-  }
-
-
-<<<<<<< HEAD
-  if (!preg_match('/select/', $table_data['mode'])) {
-=======
-  if (!preg_match('/select/',$table_data['mode'])) {
->>>>>>> 6.x-0.4-dev
-    //watchdog('T_bulk_loader',$header.': Inserting:'.print_r($values, TRUE), array(), WATCHDOG_NOTICE);
-    if (variable_get('tripal_bulk_loader_prepare',TRUE)) {
-      $options = array('statement_name' => $priority);
-      if ($line_num == 1 && $group_index == 1) {
-        $options['prepare'] = TRUE;
-      }
-    }
-    else {
-      $options = array();
-    }
-
-    $record = tripal_core_chado_insert($table, $values, $options);
-
-    if (!$record) {
-<<<<<<< HEAD
-      $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') Unable to insert record into ' . $table . ' where values:' . print_r($values, TRUE);
-      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_ERROR);
-      print "ERROR: " . $msg . "\n";
-=======
-      $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') Unable to insert record into '.$table.' where values:'.print_r($values,TRUE);
-      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_ERROR);
-      print "ERROR: ".$msg."\n";
->>>>>>> 6.x-0.4-dev
-      $data[$priority]['error'] = TRUE;
-      $no_errors = FALSE;
-    }
-    else {
-      //add changes back to values array
-      $data[$priority]['values_array'] = $record;
-      $values = $record;
-
-      // if mode=insert_once then ensure we only insert it once
-      if (preg_match('/insert_once/', $table_data['mode'])) {
-        $default_data[$priority]['inserted'] = TRUE;
-      }
-
-      // add to tripal_bulk_loader_inserted
-      $insert_record = db_fetch_object(db_query(
-        "SELECT * FROM {tripal_bulk_loader_inserted} WHERE table_inserted_into='%s' AND nid=%d",
-        $table,
-        $nid
-      ));
-      if ($insert_record) {
-        $insert_record->ids_inserted .= ',' . $values[ $table_desc['primary key'][0] ];
-        drupal_write_record('tripal_bulk_loader_inserted', $insert_record, 'tripal_bulk_loader_inserted_id');
-        //print 'Update: '.print_r($insert_record,TRUE)."\n";
-        return $no_errors;
-      }
-      else {
-        $insert_record = array(
-          'nid' => $nid,
-          'table_inserted_into' => $table,
-          'table_primary_key' => $table_desc['primary key'][0],
-          'ids_inserted' => $values[ $table_desc['primary key'][0] ],
-        );
-        //print 'New: '.print_r($insert_record,TRUE)."\n";
-        $success = drupal_write_record('tripal_bulk_loader_inserted', $insert_record);
-        return $no_errors;
-      }//end of if insert record
-
-    } //end of if insert was successful
-  }
-  else {
-    $exists = tripal_core_chado_select($table, array_keys($table_desc['fields']), $values, array('has_record' => TRUE));
-    if (!$exists) {
-      // No record on select
-<<<<<<< HEAD
-      $msg = 'Line ' . $line_num . ' ' . $table_data['record_id'] . ' (' . $table_data['mode'] . ') No Matching record in ' . $table . ' where values:' . print_r($values, TRUE);
-=======
-      $msg = 'Line '.$line_num.' '.$table_data['record_id'].' ('.$table_data['mode'].') No Matching record in '.$table.' where values:'.print_r($values,TRUE);
->>>>>>> 6.x-0.4-dev
-      watchdog('T_bulk_loader', $msg, array(), WATCHDOG_WARNING);
-      $data[$priority]['error'] = TRUE;
-    }
-  }
-  return $no_errors;
-}
-
-/**
- * This function adds the file data to the values array
- *
- * @param $values
- *   The default values array -contains all constants
- * @param $line
- *   An array of values for the current line
- * @param $field2column
- *   An array mapping values fields to line columns
- * @return
- *   Supplemented values array
- */
-function tripal_bulk_loader_add_spreadsheetdata_to_values($values, $line, $field2column) {
-
-  foreach ($values as $field => $value) {
-<<<<<<< HEAD
-    if (is_array($value)) {
-      continue;
-    }
-
-    $column = $field2column[$field] - 1;
-    if ($column < 0) {
-      continue;
-    }
-
-    if (preg_match('/\S+/', $line[$column])) {
-=======
-    if (is_array($value)) { continue; }
-
-    $column = $field2column[$field] - 1;
-    if ($column < 0) { continue; }
-
-    if (preg_match('/\S+/',$line[$column])) {
->>>>>>> 6.x-0.4-dev
-      $values[$field] = $line[$column];
-    }
-    else {
-      unset($values[$field]);
-    }
-  }
-
-  return $values;
-}
-
-/**
- * Handles foreign keys in the values array.
- *
- * Specifically, if the value for a field is an array then it is assumed that the array contains
- * the name of the record whose values array should be substituted here. Thus the foreign
- * record is looked up and the values array is substituted in.
- *
- */
-function tripal_bulk_loader_add_foreignkey_to_values($values, $data, $record2priority) {
-
-  foreach ($values as $field => $value) {
-    if (is_array($value)) {
-      $foreign_record = $value['foreign record'];
-      $foreign_priority = $record2priority[$foreign_record];
-      $foreign_values = $data[$foreign_priority]['values_array'];
-
-      // add to current values array
-      $values[$field] = $foreign_values;
-    }
-  }
-
-  return $values;
-}
-
-/**
- * Uses a supplied regex to transform spreadsheet values
- *
- * @param $values
- *   The select/insert values array for the given table
- * @param $table_data
- *   The data array for the given table
- */
-function tripal_bulk_loader_regex_tranform_values($values, $table_data, $line) {
-
-  if (empty($table_data['regex_transform']) OR !is_array($table_data['regex_transform'])) {
-    return $values;
-  }
-
-<<<<<<< HEAD
-  //watchdog('T_bulk_loader','Regex Transformation:<pre>'.print_r($table_data['regex_transform'], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-
-  foreach ($table_data['regex_transform'] as $field => $regex_array) {
-    if (!is_array($regex_array['replace'])) {
-       continue;
-     }
-=======
-  if (empty($table_data['regex_transform']) OR !is_array($table_data['regex_transform'])) { return $values; }
-
-  //watchdog('T_bulk_loader','Regex Transformation:<pre>'.print_r($table_data['regex_transform'], TRUE).'</pre>', array(), WATCHDOG_NOTICE);
-
-  foreach ($table_data['regex_transform'] as $field => $regex_array) {
-    if (!is_array($regex_array['replace'])) { continue; }
->>>>>>> 6.x-0.4-dev
-
-    //print 'Match:'.print_r($regex_array['pattern'],TRUE)."\n";
-    //print 'Replace:'.print_r($regex_array['replace'],TRUE)."\n";
-    //print 'Was:'.$values[$field]."\n";
-
-    // Check for <#column:\d+#> notation
-    // if present replace with that column in the current line
-    foreach ($regex_array['replace'] as $key => $replace) {
-      if (preg_match_all('/<#column:(\d+)#>/', $replace, $matches)) {
-        foreach ($matches[1] as $k => $column_num) {
-          $replace = preg_replace('/' . $matches[0][$k] .'/', $line[$column_num-1], $replace);
-        }
-        $regex_array['replace'][$key] = $replace;
-      }
-    }
-
-    // do the full replacement
-    $old_value = $values[$field];
-    $new_value = preg_replace($regex_array['pattern'], $regex_array['replace'], $old_value);
-    $values[$field] = $new_value;
-
-    if ($values[$field] === '') {
-      unset($values[$field]);
-    }
-    //print 'Now:'.$values[$field]."\n";
-  }
-
-
-
-  return $values;
-}
-
-/**
- * Flattens an array up to two levels
- * Used for printing of arrays without taking up much space
- */
-function tripal_bulk_loader_flatten_array($values) {
-  $flattened_values = array();
-
-  foreach ($values as $k => $v) {
-    if (is_array($v)) {
-      $vstr = array();
-      foreach ($v as $vk => $vv) {
-        if (strlen($vv) > 20) {
-          $vstr[] = $vk . '=>' . substr($vv, 0, 20) . '...';
-        }
-        else {
-          $vstr[] = $vk . '=>' . $vv;
-        }
-      }
-      $v = '{' . implode(',', $vstr) . '}';
-    }
-    elseif (strlen($v) > 20) {
-      $v = substr($v, 0, 20) . '...';
-    }
-    $flattened_values[] = $k . '=>' . $v;
-  }
-
-<<<<<<< HEAD
-  return implode(', ', $flattened_values);
-}
-=======
-  return implode(', ',$flattened_values);
-}
->>>>>>> 6.x-0.4-dev

+ 118 - 98
tripal_bulk_loader/tripal_bulk_loader.module

@@ -18,130 +18,140 @@ function tripal_bulk_loader_init() {
  */
 function tripal_bulk_loader_menu() {
   $items = array();
-   // Show all loaders
-   $items['tripal_bulk_loaders'] = array(
-     'title' => 'Tripal Bulk Loaders',
-     'description' => 'Tripal bulk loaders for loading tab-delimited file into chado database',
-     'page callback' => 'tripal_bulk_loader_list',
-     'access arguments' => array('access tripal_bulk_loader'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   // Bulk Loading Job Node
-   $items['node/%node/constants/%/edit'] = array(
-      'title' => 'Edit Constant Set',
-      'description' => 'Edit a group of constants associated with the current bulk loader',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_edit_constant_set_form', 1, 3),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-      'file' => 'tripal_bulk_loader.constants.inc',
-   );
-   $items['node/%node/constants/%/delete'] = array(
-      'title' => 'Delete Constant Set',
-      'description' => 'Delete a group of constants associated with the current bulk loader',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_delete_constant_set_form', 1, 3),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-      'file' => 'tripal_bulk_loader.constants.inc',
-   );
-
-   // Admin page to create the template
-   $items['admin/tripal/tripal_bulk_loader_template'] = array(
-      'title' => 'Bulk Loader Template',
-      'description' => 'Templates for loading tab-delimited data',
-      'page callback' => 'tripal_bulk_loader_admin_template',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-      'file' => 'tripal_bulk_loader.admin.inc',
+  // Show all loaders
+  $items['tripal_bulk_loaders'] = array(
+    'title' => 'Tripal Bulk Loaders',
+    'description' => 'Tripal bulk loaders for loading tab-delimited file into chado database',
+    'page callback' => 'tripal_bulk_loader_list',
+    'access arguments' => array('access tripal_bulk_loader'),
+    'type' => MENU_NORMAL_ITEM,
   );
+  // Bulk Loading Job Node
+  $items['node/%node/constants/%/edit'] = array(
+    'title' => 'Edit Constant Set',
+    'description' => 'Edit a group of constants associated with the current bulk loader',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_edit_constant_set_form', 1, 3),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+    'file' => 'tripal_bulk_loader.constants.inc',
+  );
+  $items['node/%node/constants/%/delete'] = array(
+    'title' => 'Delete Constant Set',
+    'description' => 'Delete a group of constants associated with the current bulk loader',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_delete_constant_set_form', 1, 3),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+    'file' => 'tripal_bulk_loader.constants.inc',
+  );
+
+  // Admin page to create the template
+  $items['admin/tripal/tripal_bulk_loader_template'] = array(
+    'title' => 'Bulk Loader Template',
+    'description' => 'Templates for loading tab-delimited data',
+    'page callback' => 'tripal_bulk_loader_admin_template',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'tripal_bulk_loader.admin.inc',
+  );
+  $items['admin/tripal/tripal_bulk_loader_template/configure'] = array(
+    'title' => 'Configure',
+    'description' => 'Configuration of global options related to bulk loading jobs',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_configuration_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'tripal_bulk_loader.admin.inc',
+  );
+
   // Create/Edit Template -------
   $items['admin/tripal/tripal_bulk_loader_template/create'] = array(
-      'title' => 'Create Bulk Loader Template',
-      'description' => 'Create loader template for loading tab-delimited data',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'create'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
+    'title' => 'Create Template',
+    'description' => 'Create loader template for loading tab-delimited data',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'create'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
     'file' => 'tripal_bulk_loader.admin.inc',
   );
   $items['admin/tripal/tripal_bulk_loader_template/edit'] = array(
-      'title' => 'Edit Bulk Loader Template',
-      'description' => 'Edit loader template for loading tab-delimited data',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-      'file' => 'tripal_bulk_loader.admin.inc',
+    'title' => 'Edit Template',
+    'description' => 'Edit loader template for loading tab-delimited data',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'tripal_bulk_loader.admin.inc',
   );
   $items['admin/tripal/tripal_bulk_loader_template/edit_record'] = array(
-      'title' => 'Edit Template Record',
-      'description' => 'Edit a record in an existing tripal bulk loader template.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_edit_template_record_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
+    'title' => 'Edit Template Record',
+    'description' => 'Edit a record in an existing tripal bulk loader template.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_edit_template_record_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
     'file' => 'tripal_bulk_loader.admin.inc',
   );
   $items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
-      'title' => 'Add Template Field',
-      'description' => 'Add a template field to an existing tripal bulk loader template.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_add_template_field_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
+    'title' => 'Add Template Field',
+    'description' => 'Add a template field to an existing tripal bulk loader template.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_add_template_field_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
     'file' => 'tripal_bulk_loader.admin.inc',
   );
   $items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
-      'title' => 'Edit Template Field',
-      'description' => 'Edit an existing field from a tripal bulk loader template.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_edit_template_field_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
+    'title' => 'Edit Template Field',
+    'description' => 'Edit an existing field from a tripal bulk loader template.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_edit_template_field_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
     'file' => 'tripal_bulk_loader.admin.inc',
   );
   // Delete Template -----
   $items['admin/tripal/tripal_bulk_loader_template/delete'] = array(
-      'title' => 'Delete Bulk Loader Template',
-      'description' => 'Delete bulk loader template',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_delete_template_base_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
+    'title' => 'Delete Template',
+    'description' => 'Delete bulk loader template',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_delete_template_base_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
     'file' => 'tripal_bulk_loader.admin.inc',
   );
   // Import/Export ---------
   $items['admin/tripal/tripal_bulk_loader_template/import'] = array(
-      'title' => 'Import Bulk Loader Template',
-      'description' => 'Import Loaders',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'import'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-      'file' => 'tripal_bulk_loader.admin.inc',
+    'title' => 'Import Template',
+    'description' => 'Import Loaders',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'import'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'tripal_bulk_loader.admin.inc',
   );
   $items['admin/tripal/tripal_bulk_loader_template/export'] = array(
-      'title' => 'Export Bulk Loader Template',
-      'description' => 'Export Loaders',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'export'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-      'file' => 'tripal_bulk_loader.admin.inc',
+    'title' => 'Export Template',
+    'description' => 'Export Loaders',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'export'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'tripal_bulk_loader.admin.inc',
   );
   // AHAH ---------
   $items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
-      'page callback' => 'tripal_bulk_loader_add_field_ahah',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-      'file' => 'tripal_bulk_loader.admin.inc',
+    'page callback' => 'tripal_bulk_loader_add_field_ahah',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+    'file' => 'tripal_bulk_loader.admin.inc',
   );
   $items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
-      'page callback' => 'tripal_bulk_loader_edit_field_ahah',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-      'file' => 'tripal_bulk_loader.admin.inc',
+    'page callback' => 'tripal_bulk_loader_edit_field_ahah',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+    'file' => 'tripal_bulk_loader.admin.inc',
   );
 
   return $items;
@@ -181,8 +191,8 @@ function tripal_bulk_loader_theme() {
 function tripal_bulk_loader_access($op, $node, $account) {
   if ($op == 'create') {
     if (!user_access('create tripal_bulk_loader', $account)) {
-         return FALSE;
-      }
+      return FALSE;
+    }
   }
   if ($op == 'update') {
     if (!user_access('edit tripal_bulk_loader', $account)) {
@@ -416,7 +426,7 @@ function tripal_bulk_loader_insert($node) {
   drupal_write_record('node', $node, 'nid');
   drupal_write_record('node_revision', $node, 'nid');
 
-  drupal_set_message('After reviewing the details, please Submit this Job (by clicking the "Submit Job" button below). No data will be loaded until the submitted job is reached in the queue.');
+  drupal_set_message(t('After reviewing the details, please Submit this Job (by clicking the "Submit Job" button below). No data will be loaded until the submitted job is reached in the queue.'));
 
 }
 
@@ -494,3 +504,13 @@ function tripal_bulk_loader_job_describe_args($callback, $args) {
 
 }
 
+/**
+ * Implements hook_coder_ignore().
+ * Defines the path to the file (tripal_bulk_loader.coder_ignores.txt) where ignore rules for coder are stored
+ */
+function tripal_bulk_loader_coder_ignore() {
+  return array(
+    'path' => drupal_get_path('module', 'tripal_bulk_loader'),
+    'line prefix' => drupal_get_path('module', 'tripal_bulk_loader'),
+  );
+}

+ 0 - 647
tripal_bulk_loader/tripal_bulk_loader.module.orig

@@ -1,647 +0,0 @@
-<?php
-
-include('tripal_bulk_loader.loader.inc');
-include('tripal_bulk_loader.constants.inc');
-
-/**
- * Implements hook_init
- * Used to add stylesheets and javascript files to the header
- */
-function tripal_bulk_loader_init() {
-  // Add javascript and style sheet
-  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_bulk_loader.css');
-  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_bulk_loader.js');
-}
-
-/**
- * Implements hook_menu
- */
-function tripal_bulk_loader_menu() {
-  $items = array();
-   // Show all loaders
-   $items['tripal_bulk_loaders'] = array(
-     'title' => 'Tripal Bulk Loaders',
-     'description' => 'Tripal bulk loaders for loading tab-delimited file into chado database',
-     'page callback' => 'tripal_bulk_loader_list',
-     'access arguments' => array('access tripal_bulk_loader'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   // Bulk Loading Job Node
-   $items['node/%node/constants/%/edit'] = array(
-      'title' => 'Edit Constant Set',
-      'description' => 'Edit a group of constants associated with the current bulk loader',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_edit_constant_set_form', 1, 3),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-<<<<<<< HEAD
-      'file' => 'tripal_bulk_loader.constants.inc',
-=======
-		  'file' => 'tripal_bulk_loader.constants.inc',
->>>>>>> 6.x-0.4-dev
-   );
-   $items['node/%node/constants/%/delete'] = array(
-      'title' => 'Delete Constant Set',
-      'description' => 'Delete a group of constants associated with the current bulk loader',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_delete_constant_set_form', 1, 3),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-<<<<<<< HEAD
-      'file' => 'tripal_bulk_loader.constants.inc',
-=======
-		  'file' => 'tripal_bulk_loader.constants.inc',
->>>>>>> 6.x-0.4-dev
-   );
-
-   // Admin page to create the template
-   $items['admin/tripal/tripal_bulk_loader_template'] = array(
-      'title' => 'Bulk Loader Template',
-      'description' => 'Templates for loading tab-delimited data',
-      'page callback' => 'tripal_bulk_loader_admin_template',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-<<<<<<< HEAD
-      'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  // Create/Edit Template -------
-=======
-		  'file' => 'tripal_bulk_loader.admin.inc',
-	);
-   $items['admin/tripal/tripal_bulk_loader_template/configure'] = array(
-      'title' => 'Configuration',
-      'description' => 'Configure the Tripal Bulk Loader Module',
-    	'page callback' => 'drupal_get_form',
-    	'page arguments' => array('tripal_bulk_loader_configuration_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-		  'file' => 'tripal_bulk_loader.admin.inc',
-	);
-
-	// Create/Edit Template -------
->>>>>>> 6.x-0.4-dev
-  $items['admin/tripal/tripal_bulk_loader_template/create'] = array(
-      'title' => 'Create Bulk Loader Template',
-      'description' => 'Create loader template for loading tab-delimited data',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'create'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-<<<<<<< HEAD
-    'file' => 'tripal_bulk_loader.admin.inc',
-=======
-		'file' => 'tripal_bulk_loader.admin.inc',
->>>>>>> 6.x-0.4-dev
-  );
-  $items['admin/tripal/tripal_bulk_loader_template/edit'] = array(
-      'title' => 'Edit Bulk Loader Template',
-      'description' => 'Edit loader template for loading tab-delimited data',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-<<<<<<< HEAD
-      'file' => 'tripal_bulk_loader.admin.inc',
-=======
-		  'file' => 'tripal_bulk_loader.admin.inc',
->>>>>>> 6.x-0.4-dev
-  );
-  $items['admin/tripal/tripal_bulk_loader_template/edit_record'] = array(
-      'title' => 'Edit Template Record',
-      'description' => 'Edit a record in an existing tripal bulk loader template.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_edit_template_record_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-<<<<<<< HEAD
-    'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  $items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
-=======
-		'file' => 'tripal_bulk_loader.admin.inc',
-	);
-	$items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
->>>>>>> 6.x-0.4-dev
-      'title' => 'Add Template Field',
-      'description' => 'Add a template field to an existing tripal bulk loader template.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_add_template_field_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-<<<<<<< HEAD
-    'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  $items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
-=======
-		'file' => 'tripal_bulk_loader.admin.inc',
-	);
-	$items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
->>>>>>> 6.x-0.4-dev
-      'title' => 'Edit Template Field',
-      'description' => 'Edit an existing field from a tripal bulk loader template.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_edit_template_field_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-<<<<<<< HEAD
-    'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  // Delete Template -----
-  $items['admin/tripal/tripal_bulk_loader_template/delete'] = array(
-=======
-		'file' => 'tripal_bulk_loader.admin.inc',
-	);
-	// Delete Template -----
-	$items['admin/tripal/tripal_bulk_loader_template/delete'] = array(
->>>>>>> 6.x-0.4-dev
-      'title' => 'Delete Bulk Loader Template',
-      'description' => 'Delete bulk loader template',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_delete_template_base_form'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-<<<<<<< HEAD
-    'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  // Import/Export ---------
-=======
-		'file' => 'tripal_bulk_loader.admin.inc',
-	);
-	// Import/Export ---------
->>>>>>> 6.x-0.4-dev
-  $items['admin/tripal/tripal_bulk_loader_template/import'] = array(
-      'title' => 'Import Bulk Loader Template',
-      'description' => 'Import Loaders',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'import'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-<<<<<<< HEAD
-      'file' => 'tripal_bulk_loader.admin.inc',
-=======
-		  'file' => 'tripal_bulk_loader.admin.inc',
->>>>>>> 6.x-0.4-dev
-  );
-  $items['admin/tripal/tripal_bulk_loader_template/export'] = array(
-      'title' => 'Export Bulk Loader Template',
-      'description' => 'Export Loaders',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'export'),
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM,
-<<<<<<< HEAD
-      'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  // AHAH ---------
-  $items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
-      'page callback' => 'tripal_bulk_loader_add_field_ahah',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-      'file' => 'tripal_bulk_loader.admin.inc',
-  );
-  $items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
-      'page callback' => 'tripal_bulk_loader_edit_field_ahah',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-      'file' => 'tripal_bulk_loader.admin.inc',
-  );
-=======
-		  'file' => 'tripal_bulk_loader.admin.inc',
-  );
-	// AHAH ---------
-	$items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
-      'page callback' => 'tripal_bulk_loader_add_field_ahah',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-		  'file' => 'tripal_bulk_loader.admin.inc',
-	);
-	$items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
-      'page callback' => 'tripal_bulk_loader_edit_field_ahah',
-      'access arguments' => array('administer site configuration'),
-      'type' => MENU_CALLBACK,
-		  'file' => 'tripal_bulk_loader.admin.inc',
-	);
->>>>>>> 6.x-0.4-dev
-
-  return $items;
-}
-
-
-/**
- * Implements hook_theme
- */
-function tripal_bulk_loader_theme() {
-  return array(
-    'tripal_bulk_loader_set_constants_form' => array(
-      'arguments' => array('form' => NULL),
-    ),
-    'tripal_bulk_loader_template' => array(
-      'arguments' => array('template_id' => NULL),
-      'template' => 'tripal_bulk_loader_template'
-    ),
-    'tripal_bulk_loader_modify_template_base_form' => array(
-      'arguments' => array('form' => NULL),
-      'template' => 'tripal_bulk_loader_modify_template_base_form',
-    ),
-    'tripal_bulk_loader_edit_template_field_form' => array(
-      'arguments' => array('form' => NULL),
-      'template' => 'tripal_bulk_loader_edit_template_field_form',
-    ),
-    'tripal_bulk_loader_add_template_field_form' => array(
-      'arguments' => array('form' => NULL),
-      'template' => 'tripal_bulk_loader_add_template_field_form',
-    ),
-  );
-}
-
-/**
- *  Implements hook_access
- */
-function tripal_bulk_loader_access($op, $node, $account) {
-  if ($op == 'create') {
-    if (!user_access('create tripal_bulk_loader', $account)) {
-         return FALSE;
-      }
-  }
-  if ($op == 'update') {
-    if (!user_access('edit tripal_bulk_loader', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete tripal_bulk_loader', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'view') {
-    if (!user_access('access tripal_bulk_loader', $account)) {
-      return FALSE;
-    }
-  }
-  return NULL;
-}
-
-/**
- * Implements hook_perm
- */
-function tripal_bulk_loader_perm() {
-  return array(
-      'access tripal_bulk_loader',
-      'create tripal_bulk_loader',
-      'delete tripal_bulk_loader',
-      'edit tripal_bulk_loader',
-  );
-}
-
-/**
- * Creates a listing page for all bulk loading jobs
- */
-function tripal_bulk_loader_list() {
-  $num_results_per_page = 50;
-  $output = '';
-
-<<<<<<< HEAD
-  $header = array('', 'Status', 'Loader', 'File');
-=======
-  $header = array('','Status','Loader','File');
->>>>>>> 6.x-0.4-dev
-  $rows = array();
-
-  $query = 'SELECT * FROM {tripal_bulk_loader} l '
-    .'LEFT JOIN {node} n ON n.nid = l.nid '
-    .'LEFT JOIN {tripal_bulk_loader_template} t ON t.template_id = cast(l.template_id as integer)';
-  $resource = pager_query($query, $num_results_per_page, 0, NULL);
-  while ($r = db_fetch_object($resource)) {
-    $row = array(
-      l($r->title, 'node/' . $r->nid),
-      $r->job_status,
-      $r->name,
-      $r->file
-    );
-    $rows[] = $row;
-  }
-
-  $output .= theme('table', $header, $rows);
-  return $output;
-
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////
-// Node Functions
-//////////////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Implements hook_node_info
- */
-function tripal_bulk_loader_node_info() {
-  $nodes = array();
-  $nodes['tripal_bulk_loader'] = array(
-      'name' => t('Bulk Loading Job'),
-      'module' => 'tripal_bulk_loader',
-      'description' => t('A bulk loader for inserting tab-delimited data into chado database'),
-      'has_title' => TRUE,
-      'has_body' => FALSE,
-      'locked' => TRUE
-  );
-  return $nodes;
-}
-
-/**
- * Implements node_form
- * Used to gather the extra details stored with a Bulk Loading Job Node
- */
-function tripal_bulk_loader_form($node, $form_state) {
-  $form = array();
-
-  if (isset($form_state['values'])) {
-    $node = $form_state['values'] + (array)$node;
-    $node = (object) $node;
-  }
-
-  $sql = "SELECT * FROM {tripal_bulk_loader_template}";
-  $results = db_query($sql);
-  $templates = array();
-  while ($template = db_fetch_object ($results)) {
-    $templates [$template->template_id] = $template->name;
-  }
-
-  if (!$templates) {
-    $form['label'] = array(
-    '#type' => 'item',
-      '#description' => t("Loader template needs to be created before any bulk loader can be added. Go to 'Tripal Management > Bulk Loader Template' to create the template."),
-      '#weight'        => -10,
-    );
-
-    return $form;
-  }
-
-  $form['loader'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Basic Details'),
-  );
-
-  $form['loader']['loader_name'] = array(
-    '#type'          => 'textfield',
-    '#title'         => t('Loading Job Name'),
-    '#weight'        => -10,
-    '#required'      => TRUE,
-    '#default_value' => $node->loader_name
-  );
-
-  $form['loader']['template_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Template'),
-    '#description'   => t('Please specify a template for this loader'),
-    '#options'       => $templates,
-    '#weight'        => -9,
-    '#required'      => TRUE,
-    '#default_value' => $node->template_id,
-  );
-
-  $form['loader']['file']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('Data File'),
-    '#description'   => t('Please specify the data file to be loaded.'),
-    '#weight'        => -8,
-    '#default_value' => $node->file
-  );
-
-  $form['loader']['has_header'] = array(
-    '#type' => 'radios',
-    '#title' => t('File has a Header'),
-    '#options' => array( 1 => 'Yes', 2 => 'No'),
-    '#weight' => -7,
-    '#default_value' => $node->file_has_header,
-  );
-
-  return $form;
-}
-
-
-/**
- * Implements node_load
- */
-function tripal_bulk_loader_load($node) {
-  $sql = "SELECT * FROM {tripal_bulk_loader} WHERE nid = %d";
-  $node = db_fetch_object(db_query($sql, $node->nid));
-
-<<<<<<< HEAD
-  $node->title = 'Bulk Loading Job: ' . $node->loader_name;
-
-  // Add the loader template
-  $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-  $results = db_fetch_object(db_query($sql, $node->template_id));
-  $template = unserialize($results->template_array);
-  $node->template = $results;
-  $node->template->template_array = $template;
-=======
-	$node->title = 'Bulk Loading Job: '.$node->loader_name;
-
-	// Add the loader template
-	$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-	$results = db_fetch_object(db_query($sql, $node->template_id));
-	$template = unserialize($results->template_array);
-	$node->template = $results;
-	$node->template->template_array = $template;
->>>>>>> 6.x-0.4-dev
-
-  // Add inserted records
-  $sql = 'SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d';
-  $resource = db_query($sql, $node->nid);
-  while ($r = db_fetch_object($resource)) {
-<<<<<<< HEAD
-    $r->num_inserted = sizeof(preg_split('/,/', $r->ids_inserted));
-=======
-    $r->num_inserted = sizeof(preg_split('/,/',$r->ids_inserted));
->>>>>>> 6.x-0.4-dev
-    $node->inserted_records->{$r->table_inserted_into} = $r;
-  }
-
-  // Add exposed field list
-  $node->exposed_fields = array();
-  if ($template) {
-    foreach ($template as $record_id => $record) {
-      foreach ($record['fields'] as $field_id => $field) {
-        if ($field['exposed']) {
-          $node->exposed_fields[] = array(
-            'record_id' => $record_id,
-            'field_id' => $field_id,
-            'title' => $field['title'],
-          );
-        }
-      }
-    }
-
-    if (empty($node->exposed_fields)) {
-      $node->exposed_fields[] = array();
-    }
-  }
-
-
-  // Add constants
-  $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=%d ORDER BY group_id, record_id, field_id';
-  $resource = db_query($sql, $node->nid);
-  while ($r = db_fetch_object($resource)) {
-    $node->constants[$r->group_id][$r->record_id][$r->field_id] = array(
-      'constant_id' => $r->constant_id,
-      'group_id' => $r->group_id,
-<<<<<<< HEAD
-      'chado_table' => $r->chado_table,
-      'chado_field' => $r->chado_field,
-      'record_id' => $r->record_id,
-      'field_id' => $r->field_id,
-      'value' => $r->value
-=======
-      'chado_table'=>$r->chado_table,
-      'chado_field'=>$r->chado_field,
-      'record_id'=>$r->record_id,
-      'field_id'=>$r->field_id,
-      'value'=>$r->value
->>>>>>> 6.x-0.4-dev
-    );
-  }
-  if (!$node->constants) {
-    $node->constants[] = array();
-  }
-
-<<<<<<< HEAD
-  return $node;
-=======
-	return $node;
->>>>>>> 6.x-0.4-dev
-}
-
-/**
- * Implements node_insert
- * Insert the data from the node form on Create content
- */
-<<<<<<< HEAD
-function tripal_bulk_loader_insert($node) {
-=======
-function tripal_bulk_loader_insert ($node) {
->>>>>>> 6.x-0.4-dev
-
-  // Insert into tripal_bulk_loader
-  $sql = "INSERT INTO {tripal_bulk_loader} (nid, loader_name, template_id, file, file_has_header, job_status) VALUES (%d, '%s', %d, '%s', %d, '%s')";
-  db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, 'Initialized');
-
-<<<<<<< HEAD
-  // Update title
-  $node->title =$node->loader_name;
-  drupal_write_record('node', $node, 'nid');
-  drupal_write_record('node_revision', $node, 'nid');
-=======
-	// Update title
-	$node->title =$node->loader_name;
-	drupal_write_record('node',$node,'nid');
-	drupal_write_record('node_revision',$node,'nid');
->>>>>>> 6.x-0.4-dev
-
-  drupal_set_message('After reviewing the details, please Submit this Job (by clicking the "Submit Job" button below). No data will be loaded until the submitted job is reached in the queue.');
-
-}
-
-/**
- * Implements node_delete
- * Deletes the data when the delete button on the node form is clicked
- */
-function tripal_bulk_loader_delete($node) {
-  $sql = "DELETE FROM {tripal_bulk_loader} WHERE nid = %d";
-  db_query($sql, $node->nid);
-}
-
-/**
- * Implements node_update
- * Updates the data submitted by the node form on edit
- */
-<<<<<<< HEAD
-function tripal_bulk_loader_update($node) {
-
-  // Update tripal_bulk_loader
-  $sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";
-  db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->nid);
-
-  // Add a job if the user want to load the data
-  global $user;
-  if ($node->job) {
-    $job_args[0] =$node->loader_name;
-    $job_args[1] = $node->template_id;
-    $job_args[2] = $node->file;
-    if (is_readable($node->file)) {
-      $fname = preg_replace("/.*\/(.*)/", "$1", $node->file);
-      tripal_add_job("Bulk Load: $fname", 'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
-    }
-    else {
-      drupal_set_message(t("Can not open %file. Job not scheduled.", array('%file' => $node->file)));
-    }
-  }
-=======
-function tripal_bulk_loader_update ($node) {
-
-  // Update tripal_bulk_loader
-	$sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";
-	db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->nid);
-
-	// Add a job if the user want to load the data
-	global $user;
-	if($node->job) {
-		$job_args[0] =$node->loader_name;
-		$job_args[1] = $node->template_id;
-		$job_args[2] = $node->file;
-		if (is_readable($node->file)) {
-			$fname = preg_replace("/.*\/(.*)/", "$1", $node->file);
-			tripal_add_job("Bulk Load: $fname",'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
-		} else {
-			drupal_set_message("Can not open $node->file. Job not scheduled.");
-		}
-	}
->>>>>>> 6.x-0.4-dev
-
-}
-
-///////////////////////////////////////////////////////////
-
-/**
- * Preprocessor function for the tripal_bulk_loader template
- */
-function tripal_bulk_loader_preprocess_tripal_bulk_loader_template(&$variables) {
-
-  $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-  $template = db_fetch_object(db_query($sql, $variables['template_id']));
-  $template->template_array = unserialize($template->template_array);
-  $variables['template'] = $template;
-
-<<<<<<< HEAD
-=======
-	$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
-	$template = db_fetch_object(db_query($sql, $variables['template_id']));
-	$template->template_array = unserialize($template->template_array);
-	$variables['template'] = $template;
-
->>>>>>> 6.x-0.4-dev
-}
-
-/**
- * Implements hook_job_describe_args()
- * Specifically to make viewing past tripal jobs more readable for jobs registered by this module
- *
- * @params $callback
- *   The callback passed into tripal_add_job()
- * @param $args
- *   The arguements passed into tripal_add_job()
- * @return
- *   An array where keys are the human readable headers describing each arguement
- *   and the value is the aguement passed in after formatting
- */
-function tripal_bulk_loader_job_describe_args($callback, $args) {
-
-  $new_args = array();
-  if ($callback == 'tripal_bulk_loader_load_data') {
-    //1st arg is the nid for a bulk loader node
-    $node = node_load($args[0]);
-    $new_args['Bulk Loading Job'] = l($node->title, 'node/' . $args[0]);
-    return $new_args;
-  }
-
-}
-

+ 2 - 2
tripal_contact/tripal_contact.api.inc

@@ -5,9 +5,9 @@
  * @todo Add file header description
  */
 
-/****************************************************************************
+/**
  * @section Chado Table Descriptions
- ****************************************************************************/
+ */
 
  /**
  * Implements hook_chado_contact_schema()

+ 9 - 9
tripal_contact/tripal_contact.module

@@ -3,20 +3,20 @@
 /**
  *  @file
  * This file contains the basic functions needed for this drupal module.
- * The drupal tripal_contact module maps directly to the chado X module. 
+ * The drupal tripal_contact module maps directly to the chado X module.
  *
- * For documentation regarding the Chado X module: 
+ * For documentation regarding the Chado X module:
  * @see http://gmod.org/wiki/Chado_General_Module
  */
 
 /**
  * @defgroup tripal_contact Contact Module
  * @{
- * Currently this module only provides support for integration with Drupal 
- * views and some support for querying using the Tripal Core API. 
+ * Currently this module only provides support for integration with Drupal
+ * views and some support for querying using the Tripal Core API.
  *
- * This module needs further development to support full management of 
- * contact information within Chado, and full definitions for foreign 
+ * This module needs further development to support full management of
+ * contact information within Chado, and full definitions for foreign
  * key relationships in Chado.
  * @}
  * @ingroup tripal_modules
@@ -31,9 +31,9 @@ require('tripal_contact.api.inc');
  *  views integration code is
  *
  * @ingroup tripal_contact
- */ 
+ */
 function tripal_contact_views_api() {
-   return array(
+  return array(
       'api' => 2.0,
-   );
+  );
 }

+ 12 - 12
tripal_contact/tripal_contact.views.inc

@@ -6,17 +6,17 @@
  *  chado/tripal_contact tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
- 
+
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -26,14 +26,14 @@ function tripal_contact_views_data()  {
   $data = array();
 
   if (module_exists('tripal_views')) {
-    
+
     // Base Table: contact
     $table_name = 'contact';
     if (!tripal_views_is_integrated($tablename, 10)) {
       $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
       tripal_views_integration_add_entry($table_integration_array);
     }
-      
+
     // Additional tables
     $tables = array(
       'contact_relationship',
@@ -45,14 +45,14 @@ function tripal_contact_views_data()  {
       }
     }
   }
-    
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions
@@ -60,12 +60,12 @@ function tripal_contact_views_data()  {
  * @ingroup tripal_contact
  */
 function tripal_contact_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_contact') . '/views/handlers',
-   ),
+  ),
    'handlers' => array(
 
-   ),
- );
-}
+  ),
+  );
+}

+ 155 - 65
tripal_core/tripal_core.api.inc

@@ -71,6 +71,16 @@ require_once "tripal_core.schema.api.inc";
  *  The name of the chado table for inserting
  * @param $values
  *  An associative array containing the values for inserting.
+ * @param $options
+ *  An array of options such as:
+ *    -prepare: TRUE or FALSE. Whether or not to prepare the current statement.
+ *       statement_name must also be supplied.
+ *    -statement_name: the name of the prepared statement to use. If prepare is TRUE,
+ *       this indicates the name of the prepared statement to created; otherwise,
+ *       it indicates the name of the already prepared statement to use.
+ *    -skip_validation: TRUE or FALSE. If TRUE will skip all the validation steps and
+ *       just try to insert as is. This is much faster but results in unhandled
+ *       non user-friendly errors if the insert fails.
  *
  * @return
  *  On success this function returns TRUE. On failure, it returns FALSE.
@@ -102,13 +112,14 @@ require_once "tripal_core.schema.api.inc";
  *
  * @ingroup tripal_chado_api
  */
-function tripal_core_chado_insert($table, $values) {
+function tripal_core_chado_insert($table, $values, $options) {
   $insert_values = array();
   $chado_db = tripal_db_persistent_chado();
 
   // Determine plan of action
   if ($options['statement_name']) {
     $prepared = TRUE;
+    $connection = tripal_db_persistent_chado();
     if ($options['prepare']) {
       $build_sql = TRUE;
     }
@@ -120,6 +131,13 @@ function tripal_core_chado_insert($table, $values) {
     $build_sql = TRUE;
   }
 
+  if (array_key_exists('skip_validation', $options)) {
+    $validate = !$options['skip_validation'];
+  }
+  else {
+    $validate = TRUE;
+  }
+
   // get the table description
   $table_desc = module_invoke_all('chado_' . $table . '_schema');
   if (empty($table_desc)) {
@@ -148,48 +166,50 @@ function tripal_core_chado_insert($table, $values) {
     }
   }
 
-  // check for violation of any unique constraints
-  $ukeys = $table_desc['unique keys'];
-  $ukselect_cols = array();
-  $ukselect_vals = array();
-  if ($ukeys) {
-    foreach ($ukeys as $name => $fields) {
-      foreach ($fields as $index => $field) {
-        // build the arrays for performing a select that will check the contraint
-        array_push($ukselect_cols, $field);
-        $ukselect_vals[$field] = $insert_values[$field];
+  if ($validate) {
+
+    // check for violation of any unique constraints
+    $ukeys = $table_desc['unique keys'];
+    $ukselect_cols = array();
+    $ukselect_vals = array();
+    if ($ukeys) {
+      foreach ($ukeys as $name => $fields) {
+        foreach ($fields as $index => $field) {
+          // build the arrays for performing a select that will check the contraint
+          array_push($ukselect_cols, $field);
+          $ukselect_vals[$field] = $insert_values[$field];
+        }
+        // now check the constraint
+        if (tripal_core_chado_select($table, $ukselect_cols, $ukselect_vals)) {
+          watchdog('tripal_core', "tripal_core_chado_insert: Cannot insert duplicate record into $table table: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
+          return FALSE;
+        }
       }
-      // now check the constraint
-      if (tripal_core_chado_select($table, $ukselect_cols, $ukselect_vals)) {
-        watchdog('tripal_core', "tripal_core_chado_insert: Cannot insert duplicate record into $table table: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
+    }
+
+    // if trying to insert a field that is the primary key, make sure it also is unique
+    $pkey = $table_desc['primary key'][0];
+    if ($insert_values[$pkey]) {
+      if (tripal_core_chado_select($table, array($pkey), array($pkey => $insert_values[$pkey]))) {
+        watchdog('tripal_core', "tripal_core_chado_insert: Cannot insert duplicate primary key into $table table: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
         return FALSE;
       }
     }
-  }
 
-  // if trying to insert a field that is the primary key, make sure it also is unique
-  $pkey = $table_desc['primary key'][0];
-  if ($insert_values[$pkey]) {
-    if (tripal_core_chado_select($table, array($pkey), array($pkey => $insert_values[$pkey]))) {
-      watchdog('tripal_core', "tripal_core_chado_insert: Cannot insert duplicate primary key into $table table: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
-      return FALSE;
+    // make sure required fields have a value
+    if (!is_array($table_desc['fields'])) {
+      $table_desc['fields'] = array();
+      watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
     }
-  }
-
-  // make sure required fields have a value
-  $fields = $table_desc['fields'];
-  if (!is_array($fields)) {
-    $fields = array();
-    watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
-  }
-  foreach ($fields as $field => $def) {
-    // a field is considered missing if it cannot be NULL and there is no default
-    // value for it or it is of type 'serial'
-    if ($def['not NULL'] == 1 and !array_key_exists($field, $insert_values) and !isset($def['default']) and strcmp($def['type'], serial) != 0) {
-      watchdog('tripal_core', "tripal_core_chado_insert: Field $table.$field cannot be NULL: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
-      return FALSE;
+    foreach ($table_desc['fields'] as $field => $def) {
+      // a field is considered missing if it cannot be NULL and there is no default
+      // value for it or it is of type 'serial'
+      if ($def['not NULL'] == 1 and !array_key_exists($field, $insert_values) and !isset($def['default']) and strcmp($def['type'], serial) != 0) {
+        watchdog('tripal_core', "tripal_core_chado_insert: Field $table.$field cannot be NULL: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
+        return FALSE;
+      }
     }
-  }
+  } //end of validation
 
   // Now build the insert SQL statement
   $ifields = array(); //contains the names of the fields
@@ -198,17 +218,18 @@ function tripal_core_chado_insert($table, $values) {
   $iplaceholders = array(); // contains $1/$2 placeholders for the prepare query
   $idatatypes = array(); //contains the data type of the fields (int, text, etc.)
   $i = 1;
-  foreach ($insert_values as $field => $value){
+  foreach ($insert_values as $field => $value) {
     $ifields[] = $field;
     $ivalues[] = $value;
-    $iplaceholders[] = '$'.$i;
+    $iplaceholders[] = '$' . $i;
     $i++;
-    if(strcmp($value,'__NULL__')==0){
+    if (strcmp($value, '__NULL__')==0) {
       $itypes[] = "NULL";
       $idatatypes[] = "NULL";
     }
-    elseif(strcmp($fields[$field]['type'],'serial')==0 or
-      strcmp($fields[$field]['type'],'int')==0){
+    elseif (strcasecmp($table_desc['fields'][$field]['type'], 'serial')==0 OR
+      strcasecmp($table_desc['fields'][$field]['type'], 'int')==0 OR
+      strcasecmp($table_desc['fields'][$field]['type'], 'integer')==0) {
       $itypes[] = "%d";
       $idatatypes[] = 'int';
     }
@@ -222,17 +243,15 @@ function tripal_core_chado_insert($table, $values) {
     // prepare the statement
     if ($prepared) {
       $prepare_sql = "PREPARE " . $options['statement_name'] . " (" . implode(', ', $idatatypes) . ") AS INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $iplaceholders) . ")";
-
-      $previous_db = tripal_db_set_active('chado');
-      $status = db_query($prepare_sql);
-      tripal_db_set_active($previous_db);
+      $status = chado_query($prepare_sql);
 
       if (!$status) {
-        watchdog('tripal_core',"tripal_core_chado_insert: not able to prepare '%name' statement for: %sql", array('%name' => $options['statement_name'], '%sql' => $sql), 'WATCHDOG ERROR');
+        watchdog('tripal_core', "tripal_core_chado_insert: not able to prepare '%name' statement for: %sql", array('%name' => $options['statement_name'], '%sql' => $sql), 'WATCHDOG ERROR');
         return FALSE;
-       }
-    } else {
-      $sql = "INSERT INTO {$table} (" . implode(", ",$ifields) . ") VALUES (". implode(", ",$itypes) .")";
+      }
+    }
+    else {
+      $sql = "INSERT INTO {$table} (" . implode(", ", $ifields) . ") VALUES (" . implode(", ", $itypes) . ")";
     }
   }
 
@@ -240,16 +259,14 @@ function tripal_core_chado_insert($table, $values) {
   if ($prepared) {
 
     $sql = "EXECUTE " . $options['statement_name'] . "(" . implode(", ", $itypes) . ")";
+    $result = chado_query($sql, $ivalues);
 
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_query($sql, $ivalues);
-    tripal_db_set_active($previous_db);
     if ($result) {
       // add primary keys to values before return
       $primary_key = array();
       if (!is_array($table_desc['primary key'])) {
         $table_desc['primary key'] = array();
-        watchdog('tripal_core',"tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
+        watchdog('tripal_core', "tripal_core_chado_insert: %table not defined in tripal schema api", array('%table' => $table), 'WATCHDOG WARNING');
       }
       foreach ($table_desc['primary key'] as $field) {
         $value = db_last_insert_id($table, $field);
@@ -258,7 +275,7 @@ function tripal_core_chado_insert($table, $values) {
       return $values;
     }
     else {
-      watchdog('tripal_core',"tripal_core_chado_insert: not able to execute prepared statement '%name' with values: %values", array('%name' => $options['statement_name'], '%values' => print_r($values,1)), 'WATCHDOG ERROR');
+      watchdog('tripal_core', "tripal_core_chado_insert: not able to execute prepared statement '%name' with values: %values", array('%name' => $options['statement_name'], '%values' => print_r($values, TRUE)), 'WATCHDOG ERROR');
       return FALSE;
     }
   }
@@ -972,6 +989,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
     }
 
     //if criteria then remove from query
+    // @coder-ignore: only module designers can populate $criteria -not security risk
     $success = drupal_eval('<?php return ' . $criteria . '; ?>');
 //    watchdog('tripal_core',
 //      'Evaluating criteria (%criteria) for field %field in tripal_core_generate_chado_var for %table evaluated to %success',
@@ -1007,6 +1025,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
           break;
         }
         //if criteria then remove from query
+        // @coder-ignore: only module designers can populate $criteria -not security risk
         $success = drupal_eval('<?php return ' . $criteria . '; ?>');
 //        watchdog('tripal_core',
 //          'Evaluating criteria (%criteria) for field %field of $type in tripal_core_generate_chado_var for %table evaluated to %success',
@@ -1037,6 +1056,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
       if (db_table_exists('chado_' . $table)) {
         // that has a foreign key to this one ($table_desc['primary key'][0]
         // and to the node table (nid)
+        // @coder-ignore: acting on chado schema rather then drupal schema therefore, table prefixing does not apply
         $sql = "SELECT %s, nid FROM chado_%s WHERE %s=%d";
         $mapping = db_fetch_object(db_query(
           $sql,
@@ -1058,6 +1078,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
         }
         $criteria = preg_replace('/&gt;field_value&lt; /', $object->{$field_name}, $criteria);
         //if criteria then remove from query
+        // @coder-ignore: only module designers can populate $criteria -not security risk
         $success = drupal_eval('<?php return ' . $criteria . '; ?>');
 //      watchdog('tripal_core',
 //        'Evaluating criteria (%criteria) for field %field in tripal_core_generate_chado_var for   %table evaluated to %success',
@@ -1238,10 +1259,11 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
             $table_options
           );
           if ($foreign_object) {
-            // in the case where the a foreign key relationships exists more
+            // in the case where the foreign key relationships exists more
             // than once with the same table we want to alter the
             // array structure
             if (count($foreign_table_desc['foreign keys'][$base_table]['columns']) > 1) {
+              $object->{$foreign_table} = new stdClass();
               $object->{$foreign_table}->{$left} = $foreign_object;
               $object->expanded = $to_expand;
             }
@@ -1406,10 +1428,17 @@ function tripal_core_exclude_field_from_feature_by_default() {
 }
 
 /**
- *  Use this function instead of db_query() to avoid switching databases
- *  when making query to the chado database
+ * Use this function instead of db_query() to avoid switching databases
+ * when making query to the chado database
+ *
+ * Will use a chado persistent connection if it already exists
+ *
+ * @param $sql
+ *   The sql statement to execute
  */
 function chado_query($sql) {
+  global $active_db;
+
   $args = func_get_args();
   array_shift($args);
   $sql = db_prefix_tables($sql);
@@ -1418,9 +1447,22 @@ function chado_query($sql) {
   }
   _db_query_callback($args, TRUE);
   $sql = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);
-  $previous_db = tripal_db_set_active('chado');
-  $results = _db_query($sql);
-  tripal_db_set_active($previous_db);
+
+  // Execute the query on the chado database/schema
+  // Use the persistent chado connection if it already exists
+  $persistent_connection = variable_get('tripal_perisistent_chado', NULL);
+  if ($persistent_connection) {
+    $previously_active_db = $active_db;
+    $active_db = $persistent_connection;
+    $results = _db_query($sql);
+    $active_db = $previously_active_db;
+  }
+  else {
+    $previous_db = tripal_db_set_active('chado');
+    $results = _db_query($sql);
+    tripal_db_set_active($previous_db);
+  }
+
   return $results;
 }
 
@@ -1860,21 +1902,23 @@ function tripal_db_set_active($dbname) {
  * @return
  *   A postgresql connection object which can be used by pg_prepare, pg_execute, etc.
  */
-function tripal_db_persistent_chado () {
+function tripal_db_persistent_chado() {
   global $db_url;
 
   // get connection if it already exists
-  $connection = variable_get('tripal_perisistent_chado',NULL);
+  $connection = variable_get('tripal_perisistent_chado', NULL);
 
   if ($connection) {
     return $connection;
 
   // Otherwise we need to set it
-  } else {
+  }
+  else {
     if (is_array($db_url) && isset($db_url['chado'])) {
       $connection = db_connect($db_url['chado']);
       variable_set('tripal_perisistent_chado', $connection);
-    } else {
+    }
+    else {
       $connection = db_connect($db_url);
       variable_set('tripal_perisistent_chado', $connection);
     }
@@ -1887,10 +1931,55 @@ function tripal_db_persistent_chado () {
 /**
  * Release a persistent chado connection
  */
-function tripal_db_release_persistent_chado () {
+function tripal_db_release_persistent_chado() {
   variable_del('tripal_perisistent_chado');
 }
 
+/**
+ * Start a transaction block. Ensures the use of a persistent chado connection
+ */
+function tripal_db_start_transaction() {
+  $connection = tripal_db_persistent_chado();
+  chado_query("BEGIN");
+}
+
+/**
+ * Set a savepoint to roll the current transaction back to if an error is encountered
+ */
+function tripal_db_set_savepoint_transaction($savepoint, $release = FALSE) {
+  // Postgresql requires a savepoint of the same name to be unset before re-use
+  if ($release) {
+    chado_query("RELEASE SAVEPOINT %s", $savepoint);
+  }
+  chado_query("SAVEPOINT %s", $savepoint);
+}
+
+/**
+ * Commit changes made during the current transaction
+ */
+function tripal_db_commit_transaction() {
+  chado_query("COMMIT");
+}
+
+/**
+ * Rollback changes.
+ *
+ * If $savepoint is NULL then rollback to the beginning of the transaction,
+ * Otherwise, rollback to the point at which the named $savepoint was created
+ *
+ * @param $savepoint
+ *   The name of the saved point in the transaction to rollback to
+ */
+function tripal_db_rollback_transaction($savepoint = NULL) {
+
+  if ($savepoint) {
+    chado_query("ROLLBACK TO SAVEPOINT %s", $savepoint);
+  }
+  else {
+    chado_query("ROLLBACK");
+  }
+
+}
 
 /**
  * Purpose: Get max rank for a given set of criteria
@@ -2061,6 +2150,7 @@ function tripal_get_chado_custom_schema($table) {
 function tripal_core_chado_schema_exists() {
 
   // This is postgresql-specific code to check the existence of the chado schema
+  // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
   $sql = "SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = 'chado'";
   if (db_fetch_object(db_query($sql))) {
     return TRUE;

+ 9 - 12
tripal_core/tripal_core.coder_ignores.txt

@@ -2,20 +2,17 @@
 ; file:line:warning-type
 ; where warning-type is one of security, style, sql, i18n, comment, etc.
 
-; This select statement is acting upon the pg_catalog schema rather then the Drupal
-; schema and thus the curly brackets ({}) are not needed.
-tripal_core.schema.api.inc:54:sql
-tripal_core.schema.api.inc:59:sql
-tripal_core.api.inc:1953:sql
-
 ; This query selects from a non-drupal schema where the database prefixes are not
 ; applied and thus the curcly brackets ({}) are not needed
-tripal_core.api.inc:971:sql
+tripal_core.schema.api.inc:55:sql
+tripal_core.schema.api.inc:61:sql
+tripal_core.api.inc:1060:sql
+tripal_core.api.inc:2153:sql
 
 ; Only module designers can create the criteria evaluated by drupal_eval since it
-; is designed in a hook. Since module designers can already write php code to act on 
-; the database and the criteria is never subject to user input, this is not a security 
+; is designed in a hook. Since module designers can already write php code to act on
+; the database and the criteria is never subject to user input, this is not a security
 ; risk.
-tripal_core.api.inc:906:security
-tripal_core.api.inc:941:security
-tripal_core.api.inc:992:security
+tripal_core.api.inc:993:security
+tripal_core.api.inc:1029:security
+tripal_core.api.inc:1082:security

+ 2 - 0
tripal_core/tripal_core.schema.api.inc

@@ -51,11 +51,13 @@
 function tripal_core_get_chado_tables($include_custom = NULL) {
   if (is_array($db_url) AND array_key_exists('chado', $db_url)) {
     $previous_db = tripal_db_set_active('chado');
+    // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
     $sql = 'SELECT tablename FROM pg_tables';
     $resource = db_query($sql);
     tripal_db_set_active($previous_db);
   }
   else {
+    // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
     $sql = "SELECT tablename FROM pg_tables WHERE schemaname='chado'";
     $resource = db_query($sql);
   }

+ 1 - 5
tripal_cv/tripal_cv.coder_ignores.txt

@@ -4,8 +4,4 @@
 
 ; This query selects from a non-drupal schema where the database prefixes are not
 ; applied and thus the curcly brackets ({}) are not needed
-tripal_cv.module:1059:sql
-
-; Need to use POST since this is part of a JS callback
-tripal_cv.module:407:security
-tripal_cv.module:813:security
+tripal_cv.module:1062:sql

+ 3 - 2
tripal_cv/tripal_cv.module

@@ -404,7 +404,7 @@ function tripal_cv_select_form() {
 function tripal_ajax_cv_edit() {
 
   // get the database id, build the form and then return the JSON object
-  $cvid = $_POST['cvid'];
+  $cvid = filter_xss($_POST['cvid']);
   $form = drupal_get_form('tripal_cv_edit_form', $cvid);
   drupal_json(array('status' => TRUE, 'data' => $form));
 
@@ -810,7 +810,7 @@ function tripal_cv_add_cvterm_callback() {
 
   // Retrieve the form from the cache
   $form_state = array('storage' => NULL);
-  $form_build_id = $_POST['form_build_id'];
+  $form_build_id = filter_xss($_POST['form_build_id']);
   $form = form_get_cache($form_build_id, $form_state);
 
   // Preparing to process the form
@@ -1056,6 +1056,7 @@ function tripal_cv_update_cvtermpath($cvid = NULL, $job_id = NULL) {
   print "\nUpdating cvtermpath for $cv->name...\n";
 
   // now fill the cvtermpath table
+  // @coder-ignore: using a function rather then tablename therefore table prefixing doesn't apply
   $sql = "SELECT * FROM fill_cvtermpath('%s')";
   db_query($sql, $cv->name);
   tripal_db_set_active($previous_db);

+ 2 - 2
tripal_cv/tripal_cv.views.inc

@@ -41,7 +41,7 @@ function tripal_cv_views_data() {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -56,7 +56,7 @@ function tripal_cv_views_data() {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }

+ 73 - 74
tripal_db/tripal_db.api.inc

@@ -298,86 +298,85 @@ function tripal_db_chado_dbxref_schema() {
   return $description;
 }
 /**
-* Adds a new database to the Chado DB table and returns the DB object.
-*
-* @param $dbname
-*   The name of the database. This name is usually used as the prefix for
-*   CV term accessions
-* @param $description
-*   Optional. A description of the database.  By default no description is required.
-* @param $url
-*   Optional. The URL for the database
-* @param $urlprefix
-*   Optional. The URL that is to be used as a prefix when constructing a link to
-*   a database term
-* @param $update
-*   Optional. Set this to '1' to force an update of the database if it
-*   already exists. The default is to not update. If the database exists
-*   then nothing is added.
-*
-* @return
-*   An object populated with fields from the newly added database.
-*
-* @ingroup tripal_db_api
-*/
+ * Adds a new database to the Chado DB table and returns the DB object.
+ *
+ * @param $dbname
+ *   The name of the database. This name is usually used as the prefix for
+ *   CV term accessions
+ * @param $description
+ *   Optional. A description of the database.  By default no description is required.
+ * @param $url
+ *   Optional. The URL for the database
+ * @param $urlprefix
+ *   Optional. The URL that is to be used as a prefix when constructing a link to
+ *   a database term
+ * @param $update
+ *   Optional. Set this to '1' to force an update of the database if it
+ *   already exists. The default is to not update. If the database exists
+ *   then nothing is added.
+ *
+ * @return
+ *   An object populated with fields from the newly added database.
+ *
+ * @ingroup tripal_db_api
+ */
 function tripal_db_add_db($dbname, $description='', $url='', $urlprefix='', $update=0) {
 
+  $values = array(
+    'name' => $dbname,
+    'description' => $description,
+    'url' => $url,
+    'urlprefix' => $urlprefix
+  );
 
-   $values = array(
-      'name' => $dbname,
-      'description' => $description,
-      'url' => $url,
-      'urlprefix' => $urlprefix
-   );
-
-   $db_sql = "SELECT * FROM {db} WHERE name ='%s'";
-   $db = db_fetch_object(db_query($db_sql, $dbname));
-   if (!$db) {
-      if (!tripal_core_chado_insert('db', $values)) {
-         watchdog('tripal_db', "Cannot create db '$dbname'.", NULL, WATCHDOG_WARNING);
-         return 0;
-      }
-      $db = tripal_core_chado_select('db', array('*'), $values);
-   }
-   elseif ($update) {
-      $match = array('db_id' => $db->db_id);
-      if (!tripal_core_chado_update('db', $match, $values)) {
-         watchdog('tripal_db', "Cannot update db '$dbname'.", NULL, WATCHDOG_WARNING);
-         return 0;
-      }
-      $db = tripal_core_chado_select('db', array('*'), $values);
-   }
-   else {
-      return $db;
-   }
+  $db_sql = "SELECT * FROM {db} WHERE name ='%s'";
+  $db = db_fetch_object(db_query($db_sql, $dbname));
+  if (!$db) {
+    if (!tripal_core_chado_insert('db', $values)) {
+      watchdog('tripal_db', "Cannot create db '$dbname'.", NULL, WATCHDOG_WARNING);
+      return 0;
+    }
+    $db = tripal_core_chado_select('db', array('*'), $values);
+  }
+  elseif ($update) {
+    $match = array('db_id' => $db->db_id);
+    if (!tripal_core_chado_update('db', $match, $values)) {
+      watchdog('tripal_db', "Cannot update db '$dbname'.", NULL, WATCHDOG_WARNING);
+      return 0;
+    }
+    $db = tripal_core_chado_select('db', array('*'), $values);
+  }
+  else {
+    return $db;
+  }
 }
 /**
-*
-* @ingroup tripal_db_api
-*/
+ *
+ * @ingroup tripal_db_api
+ */
 function tripal_db_add_dbxref($db_id, $accession, $version='', $description='') {
 
-   // check to see if the dbxref exists if not, add it
-   $dbxsql = "
-      SELECT DBX.dbxref_id, DBX.db_id, DBX.description, DBX.version, DBX.accession,
-         DB.name as db_name
-      FROM {dbxref} DBX
-         INNER JOIN db DB on DB.db_id = DBX.db_id
-      WHERE DBX.db_id = %d and DBX.accession = '%s'
-   ";
-   $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
-   if (!$dbxref) {
-      $sql = "
-         INSERT INTO {dbxref} (db_id, accession, version, description)
-         VALUES (%d,'%s','%s','%s')
-      ";
-      if (!db_query($sql, $db_id, $accession, $version, $description)) {
-         watchdog('tripal_cv', "Failed to insert the dbxref record $accession", NULL, WATCHDOG_WARNING);
-         return 0;
-      }
-      print "Added Dbxref accession: $accession\n";
-      $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
-   }
-   return $dbxref;
+  // check to see if the dbxref exists if not, add it
+  $dbxsql = "
+    SELECT DBX.dbxref_id, DBX.db_id, DBX.description, DBX.version, DBX.accession,
+       DB.name as db_name
+    FROM {dbxref} DBX
+       INNER JOIN db DB on DB.db_id = DBX.db_id
+    WHERE DBX.db_id = %d and DBX.accession = '%s'
+  ";
+  $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
+  if (!$dbxref) {
+    $sql = "
+       INSERT INTO {dbxref} (db_id, accession, version, description)
+       VALUES (%d,'%s','%s','%s')
+    ";
+    if (!db_query($sql, $db_id, $accession, $version, $description)) {
+      watchdog('tripal_cv', "Failed to insert the dbxref record $accession", NULL, WATCHDOG_WARNING);
+      return 0;
+    }
+    print "Added Dbxref accession: $accession\n";
+    $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
+  }
+  return $dbxref;
 
 }

+ 21 - 21
tripal_db/tripal_db.install

@@ -6,22 +6,22 @@
  */
 
 /**
-*  Implementation of hook_install();
-*
-* @ingroup tripal_db
-*/
+ * Implementation of hook_install().
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_install() {
 
-   // create the module's data directory
-   tripal_create_moddir('tripal_db');
+  // create the module's data directory
+  tripal_create_moddir('tripal_db');
 
 }
 
 /**
-* Implementation of hook_uninstall()
-*
-* @ingroup tripal_db
-*/
+ * Implementation of hook_uninstall().
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_uninstall() {
 
 }
@@ -33,15 +33,15 @@ function tripal_db_uninstall() {
  * @ingroup tripal_db
  */
 function tripal_db_requirements($phase) {
-   $requirements = array();
-   if ($phase == 'install') {
-      if (!function_exists('tripal_create_moddir')) {
-         $requirements ['tripal_db'] = array(
-            'title' => "tripal_db",
-            'value' => "Required modules must be installed first before Tripal DB module can be installed. Please try again.",
-            'severity' => REQUIREMENT_ERROR,
-         );
-      }
-   }
-   return $requirements;
+  $requirements = array();
+  if ($phase == 'install') {
+    if (!function_exists('tripal_create_moddir')) {
+      $requirements ['tripal_db'] = array(
+        'title' => "tripal_db",
+        'value' => "Required modules must be installed first before Tripal DB module can be installed. Please try again.",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
 }

+ 238 - 239
tripal_db/tripal_db.module

@@ -8,69 +8,69 @@ require_once "tripal_db.api.inc";
  */
 
 /**
-*
-* @ingroup tripal_db
-*/
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_init() {
 
-   // add the tripal_db JS and CSS
-   drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_db.css');
-   drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_db.js');
+  // add the tripal_db JS and CSS
+  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_db.css');
+  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_db.js');
 }
 /**
-*
-* @ingroup tripal_db
-*/
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_menu() {
-   $items = array();
-
-   $items['admin/tripal/tripal_db'] = array(
-     'title' => 'Databases',
-     'description' => 'Basic Description of Tripal DB Module Functionality',
-     'page callback' => 'tripal_db_module_description_page',
-     'access arguments' => array('administer site configuration'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-
-   $items['admin/tripal/tripal_db/edit_db'] = array(
-     'title' => 'Update/Delete Database References',
-     'description' => 'Manage Databases ',
-     'page callback' => 'tripal_db_admin_page',
-     'access arguments' => array('administer site configuration'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-
-   $items['admin/tripal/tripal_db/add_db'] = array(
-     'title' => 'Add a Database',
-     'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_db_form'),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   $items['admin/tripal/tripal_db/edit/js'] = array(
-     'title' => 'Edit Databases',
-     'page callback' => 'tripal_ajax_db_edit',
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK,
-   );
-
-   return $items;
+  $items = array();
+
+  $items['admin/tripal/tripal_db'] = array(
+    'title' => 'Databases',
+    'description' => 'Basic Description of Tripal DB Module Functionality',
+    'page callback' => 'tripal_db_module_description_page',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['admin/tripal/tripal_db/edit_db'] = array(
+    'title' => 'Update/Delete Database References',
+    'description' => 'Manage Databases ',
+    'page callback' => 'tripal_db_admin_page',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['admin/tripal/tripal_db/add_db'] = array(
+    'title' => 'Add a Database',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_db_form'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/tripal_db/edit/js'] = array(
+    'title' => 'Edit Databases',
+    'page callback' => 'tripal_ajax_db_edit',
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
+
+  return $items;
 }
 
 /**
-*  Set the permission types that the chado module uses.  Essentially we
-*  want permissionis that protect creation, editing and deleting of chado
-*  data objects
-*
-* @ingroup tripal_db
-*/
+ *  Set the permission types that the chado module uses.  Essentially we
+ *  want permissionis that protect creation, editing and deleting of chado
+ *  data objects
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_perm() {
-   return array(
-      'access chado_db content',
-      'create chado_db content',
-      'delete chado_db content',
-      'edit chado_db content',
-   );
+  return array(
+    'access chado_db content',
+    'create chado_db content',
+    'delete chado_db content',
+    'edit chado_db content',
+  );
 }
 
 /**
@@ -137,22 +137,22 @@ function tripal_db_module_description_page() {
 }
 
 /**
-*
-*
-* @ingroup tripal_db
-*/
+ *
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_admin_page() {
-   $add_url = url("admin/tripal/tripal_db/add_db");
-   $output = "<a href=\"$add_url\">Add a new external database</a>";
-   $output .= drupal_get_form('tripal_db_select_form');
-   $output .= '<div id="db-edit-div">Please select a database above to view or edit</div>';
-   return $output;
+  $add_url = url("admin/tripal/tripal_db/add_db");
+  $output = "<a href=\"$add_url\">Add a new external database</a>";
+  $output .= drupal_get_form('tripal_db_select_form');
+  $output .= '<div id="db-edit-div">Please select a database above to view or edit</div>';
+  return $output;
 }
 /**
-*
-*
-* @ingroup tripal_db
-*/
+ *
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_select_form() {
 
   $previous_db = tripal_db_set_active('chado');  // use chado database
@@ -162,206 +162,205 @@ function tripal_db_select_form() {
   tripal_db_set_active($previous_db); // use drupal database
 
   $dbs = array();
-   $dbs[] = '';
+  $dbs[] = '';
   while ($db = db_fetch_object($results)) {
     $dbs[$db->db_id] = $db->name;
   }
 
   $form['dbid'] = array(
-      '#title' => t('External Database Name'),
-      '#type' => 'select',
-      '#options' => $dbs,
-      '#ahah' => array(
-         'path' => 'admin/tripal/tripal_db/edit/js',
-         'wrapper' => 'db-edit-div',
-         'effect' => 'fade',
-         'event' => 'change',
-         'method' => 'replace',
-      ),
+    '#title' => t('External Database Name'),
+    '#type' => 'select',
+    '#options' => $dbs,
+    '#ahah' => array(
+      'path' => 'admin/tripal/tripal_db/edit/js',
+      'wrapper' => 'db-edit-div',
+      'effect' => 'fade',
+      'event' => 'change',
+      'method' => 'replace',
+    ),
   );
 
-   return $form;
+  return $form;
 }
 /**
-*
-* @ingroup tripal_db
-*/
+ *
+ * @ingroup tripal_db
+ */
 function tripal_ajax_db_edit() {
-   // get the database id, build the form and then return the JSON object
-   $dbid = $_POST['dbid'];
-   $form = drupal_get_form('tripal_db_form', $dbid);
-   drupal_json(array('status' => TRUE, 'data' => $form));
+  // get the database id, build the form and then return the JSON object
+  $dbid = filter_xss($_POST['dbid']);
+  $form = drupal_get_form('tripal_db_form', $dbid);
+  drupal_json(array('status' => TRUE, 'data' => $form));
 }
 /**
-*
-* @ingroup tripal_db
-*/
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_form(&$form_state = NULL, $dbid = NULL) {
 
-   // get this requested database
-   if ($dbid) {
-      $sql = "SELECT * FROM {db} WHERE db_id = %d ";
-      $previous_db = tripal_db_set_active('chado');
-      $db = db_fetch_object(db_query($sql, $dbid));
-      tripal_db_set_active($previous_db);
+  // get this requested database
+  if ($dbid) {
+    $sql = "SELECT * FROM {db} WHERE db_id = %d ";
+    $previous_db = tripal_db_set_active('chado');
+    $db = db_fetch_object(db_query($sql, $dbid));
+    tripal_db_set_active($previous_db);
+
+
+    // set the default values.  If there is a value set in the
+    // form_state then let's use that, otherwise, we'll pull
+    // the values from the database
+    $default_db = $form_state['values']['name'];
+    $default_desc = $form_state['values']['description'];
+    $default_url = $form_state['values']['url'];
+    $default_urlprefix = $form_state['values']['urlprefix'];
+    if (!$default_db) {
+      $default_db = $db->name;
+    }
+    if (!$default_desc) {
+      $default_desc = $db->description;
+    }
+    if (!$default_url) {
+      $default_url = $db->url;
+    }
+    if (!$default_urlprefix) {
+      $default_urlprefix = $db->urlprefix;
+    }
+    $action = 'Update';
+  }
+  else {
+    $action = 'Add';
+  }
 
+  $form['dbid'] = array(
+    '#type' => 'hidden',
+    '#value' => $dbid
+  );
 
-      // set the default values.  If there is a value set in the
-      // form_state then let's use that, otherwise, we'll pull
-      // the values from the database
-      $default_db = $form_state['values']['name'];
-      $default_desc = $form_state['values']['description'];
-      $default_url = $form_state['values']['url'];
-      $default_urlprefix = $form_state['values']['urlprefix'];
-      if (!$default_db) {
-         $default_db = $db->name;
-      }
-      if (!$default_desc) {
-         $default_desc = $db->description;
-      }
-      if (!$default_url) {
-         $default_url = $db->url;
-      }
-      if (!$default_urlprefix) {
-         $default_urlprefix = $db->urlprefix;
-      }
-      $action = 'Update';
-   }
-   else {
-      $action = 'Add';
-   }
-
-   $form['dbid'] = array(
-      '#type' => 'hidden',
-      '#value' => $dbid
-   );
-
-   $form['name']= array(
-      '#type'          => 'textfield',
-      '#title'         => t("Database Name"),
-      '#description'   => t('Please enter the name for this external database.'),
-      '#required'      => TRUE,
-      '#default_value' => $default_db,
-      '#weight'        => 1
-   );
-
-   $form['description']= array(
-      '#type'          => 'textarea',
-      '#title'         => t('Description'),
-      '#description'   => t('Please enter a description for this database'),
-      '#default_value' => $default_desc,
-      '#weight'        => 2
-   );
-   $form['url']= array(
-      '#type'          => 'textfield',
-      '#title'         => t('URL'),
-      '#description'   => t('Please enter the web address for this database.'),
-      '#default_value' => $default_url,
-      '#weight'        => 3
-   );
-   $form['urlprefix']= array(
-      '#type'          => 'textfield',
-      '#title'         => t('URL prefix'),
-      '#description'   => t('Tripal can provide links to external databases when accession numbers or unique identifiers are known.  Typically, a database will provide a unique web address for each accession and the accession usually is the last component of the page address.  Please enter the web address, minus the accession number for this database.  When an accession number is present, Tripal will combine this web address with the accession and provide a link to the external site.'),
-      '#default_value' => $default_urlprefix,
-      '#weight'        => 4
-   );
-
-
-   if (strcmp($action, 'Update')==0) {
-      $form['update'] = array(
-        '#type'         => 'submit',
-        '#value'        => t('Update'),
-        '#weight'       => 5,
-        '#executes_submit_callback' => TRUE,
-      );
-      $form['delete'] = array(
-        '#type'         => 'submit',
-        '#value'        => t('Delete'),
-        '#weight'       => 6,
-        '#executes_submit_callback' => TRUE,
-      );
-   }
-   else {
-      $form['add'] = array(
-        '#type'         => 'submit',
-        '#value'        => t('Add'),
-        '#weight'       => 5,
-        '#executes_submit_callback' => TRUE,
-      );
-   }
-   $form['#redirect'] = 'admin/tripal/tripal_db';
-
-
-   return $form;
+  $form['name']= array(
+    '#type'          => 'textfield',
+    '#title'         => t("Database Name"),
+    '#description'   => t('Please enter the name for this external database.'),
+    '#required'      => TRUE,
+    '#default_value' => $default_db,
+    '#weight'        => 1
+  );
+
+  $form['description']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Description'),
+    '#description'   => t('Please enter a description for this database'),
+    '#default_value' => $default_desc,
+    '#weight'        => 2
+  );
+  $form['url']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('URL'),
+    '#description'   => t('Please enter the web address for this database.'),
+    '#default_value' => $default_url,
+    '#weight'        => 3
+  );
+  $form['urlprefix']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('URL prefix'),
+    '#description'   => t('Tripal can provide links to external databases when accession numbers or unique identifiers are known.  Typically, a database will provide a unique web address for each accession and the accession usually is the last component of the page address.  Please enter the web address, minus the accession number for this database.  When an accession number is present, Tripal will combine this web address with the accession and provide a link to the external site.'),
+    '#default_value' => $default_urlprefix,
+    '#weight'        => 4
+  );
+
+
+  if (strcmp($action, 'Update')==0) {
+    $form['update'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Update'),
+      '#weight'       => 5,
+      '#executes_submit_callback' => TRUE,
+    );
+    $form['delete'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Delete'),
+      '#weight'       => 6,
+      '#executes_submit_callback' => TRUE,
+    );
+  }
+  else {
+    $form['add'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Add'),
+      '#weight'       => 5,
+      '#executes_submit_callback' => TRUE,
+    );
+  }
+  $form['#redirect'] = 'admin/tripal/tripal_db';
+
+
+  return $form;
 }
 /**
-*
-* @ingroup tripal_db
-*/
+ *
+ * @ingroup tripal_db
+ */
 function tripal_db_form_submit($form, &$form_state) {
 
-   $name =  $form_state['values']['name'];
-   $desc =  $form_state['values']['description'];
-   $url  =  $form_state['values']['url'];
-   $urlp =  $form_state['values']['urlprefix'];
-   $dbid =  $form_state['values']['dbid'];
-   $op   =  $form_state['values']['op'];
-
-   if ($dbid) {
-      if (strcmp($op, 'Update')==0) {
-         $sql = "
-            UPDATE {db} SET
-              name = '%s',
-              description = '%s',
-              url = '%s',
-              urlprefix = '%s'
-            WHERE db_id = %d
-         ";
-         $previous_db = tripal_db_set_active('chado');
-         $db = db_query($sql, $name, $desc, $url, $urlp, $dbid);
-         tripal_db_set_active($previous_db);
-         if ($db) {
-           drupal_set_message("External database updated");
-         }
-         else {
-           drupal_set_message("Failed to update external database.");
-         }
+  $name =  $form_state['values']['name'];
+  $desc =  $form_state['values']['description'];
+  $url  =  $form_state['values']['url'];
+  $urlp =  $form_state['values']['urlprefix'];
+  $dbid =  $form_state['values']['dbid'];
+  $op   =  $form_state['values']['op'];
+
+  if ($dbid) {
+    if (strcmp($op, 'Update')==0) {
+      $sql = "
+        UPDATE {db} SET
+          name = '%s',
+          description = '%s',
+          url = '%s',
+          urlprefix = '%s'
+        WHERE db_id = %d
+      ";
+      $previous_db = tripal_db_set_active('chado');
+      $db = db_query($sql, $name, $desc, $url, $urlp, $dbid);
+      tripal_db_set_active($previous_db);
+      if ($db) {
+        drupal_set_message(t("External database updated"));
       }
-      if (strcmp($op, 'Delete')==0) {
-         $sql = "
-            DELETE FROM {db}
-            WHERE db_id = %d
-         ";
-         $previous_db = tripal_db_set_active('chado');
-         $db = db_query($sql, $dbid);
-         tripal_db_set_active($previous_db);
-         if ($db) {
-           drupal_set_message("External database deleted");
-         }
-         else {
-           drupal_set_message("Failed to delete external database.");
-         }
+      else {
+        drupal_set_message(t("Failed to update external database."));
       }
-   }
-   else {
+    }
+    if (strcmp($op, 'Delete')==0) {
       $sql = "
-         INSERT INTO {db}
-          (name,description,url,urlprefix)
-         VALUES
-          ('%s','%s','%s','%s')
-      ";
+        DELETE FROM {db}
+        WHERE db_id = %d
+        ";
       $previous_db = tripal_db_set_active('chado');
-      $db = db_query($sql, $name, $desc, $url, $urlp);
+      $db = db_query($sql, $dbid);
       tripal_db_set_active($previous_db);
       if ($db) {
-        drupal_set_message("External database added");
+        drupal_set_message(t("External database deleted"));
       }
       else {
-        drupal_set_message("Failed to add external database.");
+        drupal_set_message(t("Failed to delete external database."));
       }
-   }
+    }
+  }
+  else {
+    $sql = "
+          INSERT INTO {db}
+          (name,description,url,urlprefix)
+          VALUES
+          ('%s','%s','%s','%s')
+          ";
+    $previous_db = tripal_db_set_active('chado');
+    $db = db_query($sql, $name, $desc, $url, $urlp);
+    tripal_db_set_active($previous_db);
+    if ($db) {
+      drupal_set_message(t("External database added"));
+    }
+    else {
+      drupal_set_message(t("Failed to add external database."));
+    }
+  }
 
-   return '';
+  return '';
 }
-

+ 2 - 2
tripal_db/tripal_db.views.inc

@@ -38,7 +38,7 @@ function tripal_db_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -49,7 +49,7 @@ function tripal_db_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }

+ 665 - 644
tripal_feature/fasta_loader.php

@@ -1,5 +1,11 @@
 <?php
 
+/**
+ * @file
+ * @todo Add file header description
+ */
+
+
 /**
  * @defgroup fasta_loader FASTA Feature Loader
  * @{
@@ -7,264 +13,264 @@
  * @}
  * @ingroup tripal_feature
  */
- 
+
 /**
  *
  *
  * @ingroup fasta_loader
  */
-function tripal_feature_fasta_load_form (){
-
-   $form['fasta_file']= array(
-      '#type'          => 'textfield',
-      '#title'         => t('FASTA File'),
-      '#description'   => t('Please enter the full system path for the FASTA file, or a path within the Drupal
-                             installation (e.g. /sites/default/files/xyz.obo).  The path must be accessible to the
-                             server on which this Drupal instance is running.'),
-      '#required' => TRUE,
-   );
-
-   // get the list of organisms
-   $sql = "SELECT * FROM {organism} ORDER BY genus, species";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $org_rset = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $organisms = array();
-   $organisms[''] = '';
-   while($organism = db_fetch_object($org_rset)){
-      $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-   }
-   $form['organism_id'] = array (
-     '#title'       => t('Organism'),
-     '#type'        => t('select'),
-     '#description' => t("Choose the organism to which these sequences are associated "),
-     '#required'    => TRUE,
-     '#options'     => $organisms,
-   );
-
-   $form['seqtype']= array(
-      '#type' => 'textfield',
-      '#title' => t('Sequence Type'),
-      '#required' => TRUE,
-      '#description' => t('Please enter the Sequence Ontology term that describes the sequences in the FASTA file.'),
-   );
-
-
-   // get the list of organisms
-   $sql = "SELECT L.library_id, L.name, CVT.name as type
-           FROM {library} L
-              INNER JOIN {cvterm} CVT ON L.type_id = CVT.cvterm_id
-           ORDER BY name";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $lib_rset = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $libraries = array();
-   $libraries[''] = '';
-   while($library = db_fetch_object($lib_rset)){
-      $libraries[$library->library_id] = "$library->name ($library->type)";
-   }
-//   $form['library_id'] = array (
-//     '#title'       => t('Library'),
-//     '#type'        => t('select'),
-//     '#description' => t("Choose the library to which these sequences are associated "),
-//     '#required'    => FALSE,
-//     '#options'     => $libraries,
-//     '#weight'      => 5,
-//   );
-   $form['method']= array(
-      '#type' => 'radios',
-      '#title' => 'Method',
-      '#required' => TRUE,
-      '#options' => array(
-         t('Insert only'),
-         t('Update only'),
-         t('Insert and update'),
-      ),
-      '#description' => t('Select how features in the FASTA file are handled.  
-         Select "Insert only" to insert the new features. If a feature already 
-         exists with the same name or unique name and type then it is skipped.
-         Select "Update only" to only update featues that already exist in the
-         database.  Select "Insert and Update" to insert features that do
-         not exist and upate those that do.'),
-      '#default_value' => 2,
-   );
-
-$form['match_type']= array(
-      '#type' => 'radios',
-      '#title' => 'Name Match Type',
-      '#required' => TRUE,
-      '#options' => array(
-         t('Name'),
-         t('Unique name'),
-      ),
-      '#description' => t('Feature data is stored in Chado with both a human-readable
-        name and a unique name. If the features in your FASTA file are identified using
-        a human-readable name then select the "Name" button. If your features are
-        identified using the unique name then select the "Unique name" button.  If you 
-        loaded your features first using the GFF loader then the unique name of each
-        features were indicated by the "ID=" attribute and the name by the "Name=" attribute.
-        By default, the FASTA loader will use the first word (character string
-        before the first space) as  the name for your feature. If 
-        this does not uniquely identify your feature consider specifying a regular expression in the advanced section below. 
-        Additionally, you may import both a name and a unique name for each sequence using the advanced options. 
-        When updating a sequence, the value selected here will be used to identify the sequence in the 
-        database in combination with any regular expression provided below.'),
-      '#default_value' => 1,
-   );
-
-   $form['analysis'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Analysis Used to Derive Features'),
-      '#collapsed' => TRUE
-   ); 
-   $form['analysis']['desc'] = array(
-      '#type' => 'markup',
-      '#value' => t("Why specify an analysis for a data load?  All data comes 
-         from some place, even if downloaded from Genbank. By specifying
-         analysis details for all data uploads, it allows an end user to reproduce the
-         data set, but at least indicates the source of the data."), 
-   );
-
-   // get the list of organisms
-   $sql = "SELECT * FROM {analysis} ORDER BY name";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $org_rset = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $analyses = array();
-   $analyses[''] = '';
-   while($analysis = db_fetch_object($org_rset)){
-      $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
-   }
-   $form['analysis']['analysis_id'] = array (
-     '#title'       => t('Analysis'),
-     '#type'        => t('select'),
-     '#description' => t("Choose the analysis to which these features are associated "),
-     '#required'    => TRUE,
-     '#options'     => $analyses,
-   );
-
-   // Advanced Options
-   $form['advanced'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Advanced Options'),
-      '#collapsed' => TRUE
-   );
-   $form['advanced']['re_help']= array(
-      '#type' => 'item',
-      '#value' => t('A regular expression is an advanced method for extracting information from a string of text.  
-                     Your FASTA file may contain both a human-readable name and a unique name for each sequence.  
-                     If you want to import
-                     both the name and unique name for all sequences, then you must provide regular expressions 
-                     so that the loader knows how to separate them.  
-                     Otherwise the name and uniquename will be the same.  
-                     By default, this loader will use the first word in the definition 
-                     lines of the FASTA file
-                     as the name or unique name of the feature.'),
-   );
-   $form['advanced']['re_name']= array(
-      '#type' => 'textfield',
-      '#title' => t('Regular expression for the name'),
-      '#required' => FALSE,
-      '#description' => t('Enter the regular expression that will extract the 
-         feature name from the FASTA definition line. For example, for a 
-         defintion line with a name and unique name separated by a bar \'|\' (>seqname|uniquename), 
-         the regular expression for the name would be, "^(.*?)\|.*$".'),
-   );  
-   $form['advanced']['re_uname']= array(
-      '#type' => 'textfield',
-      '#title' => t('Regular expression for the unique name'),
-      '#required' => FALSE,
-      '#description' => t('Enter the regular expression that will extract the 
-         feature name from the FASTA definition line. For example, for a 
-         defintion line with a name and unique name separated by a bar \'|\' (>seqname|uniquename), 
-         the regular expression for the unique name would be "^.*?\|(.*)$").'),
-   );   
- 
-
-   // Advanced database cross-reference optoins
-   $form['advanced']['db'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('External Database Reference'),
-      '#weight'=> 6,
-      '#collapsed' => TRUE
-   );
-   $form['advanced']['db']['re_accession']= array(
-      '#type' => 'textfield',
-      '#title' => t('Regular expression for the accession'),
-      '#required' => FALSE,
-      '#description' => t('Enter the regular expression that will extract the accession for the external database for each feature from the FASTA definition line.'),
-      '#weight' => 2
-   ); 
+function tripal_feature_fasta_load_form( ) {
+
+  $form['fasta_file']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('FASTA File'),
+    '#description'   => t('Please enter the full system path for the FASTA file, or a path within the Drupal
+                           installation (e.g. /sites/default/files/xyz.obo).  The path must be accessible to the
+                           server on which this Drupal instance is running.'),
+    '#required' => TRUE,
+  );
+
+  // get the list of organisms
+  $sql = "SELECT * FROM {organism} ORDER BY genus, species";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $org_rset = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $organisms = array();
+  $organisms[''] = '';
+  while ($organism = db_fetch_object($org_rset)) {
+    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
+  }
+  $form['organism_id'] = array(
+   '#title'       => t('Organism'),
+   '#type'        => t('select'),
+   '#description' => t("Choose the organism to which these sequences are associated"),
+   '#required'    => TRUE,
+   '#options'     => $organisms,
+  );
+
+  $form['seqtype']= array(
+    '#type' => 'textfield',
+    '#title' => t('Sequence Type'),
+    '#required' => TRUE,
+    '#description' => t('Please enter the Sequence Ontology term that describes the sequences in the FASTA file.'),
+  );
+
+
+  // get the list of organisms
+  $sql = "SELECT L.library_id, L.name, CVT.name as type
+         FROM {library} L
+            INNER JOIN {cvterm} CVT ON L.type_id = CVT.cvterm_id
+         ORDER BY name";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $lib_rset = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $libraries = array();
+  $libraries[''] = '';
+  while ($library = db_fetch_object($lib_rset)) {
+    $libraries[$library->library_id] = "$library->name ($library->type)";
+  }
+  //   $form['library_id'] = array (
+  //     '#title'       => t('Library'),
+  //     '#type'        => t('select'),
+  //     '#description' => t("Choose the library to which these sequences are associated "),
+  //     '#required'    => FALSE,
+  //     '#options'     => $libraries,
+  //     '#weight'      => 5,
+  //   );
+  $form['method']= array(
+    '#type' => 'radios',
+    '#title' => 'Method',
+    '#required' => TRUE,
+    '#options' => array(
+      t('Insert only'),
+      t('Update only'),
+      t('Insert and update'),
+    ),
+    '#description' => t('Select how features in the FASTA file are handled.
+       Select "Insert only" to insert the new features. If a feature already
+       exists with the same name or unique name and type then it is skipped.
+       Select "Update only" to only update featues that already exist in the
+       database.  Select "Insert and Update" to insert features that do
+       not exist and upate those that do.'),
+    '#default_value' => 2,
+  );
+
+  $form['match_type']= array(
+    '#type' => 'radios',
+    '#title' => 'Name Match Type',
+    '#required' => TRUE,
+    '#options' => array(
+      t('Name'),
+      t('Unique name'),
+    ),
+    '#description' => t('Feature data is stored in Chado with both a human-readable
+      name and a unique name. If the features in your FASTA file are identified using
+      a human-readable name then select the "Name" button. If your features are
+      identified using the unique name then select the "Unique name" button.  If you
+      loaded your features first using the GFF loader then the unique name of each
+      features were indicated by the "ID=" attribute and the name by the "Name=" attribute.
+      By default, the FASTA loader will use the first word (character string
+      before the first space) as  the name for your feature. If
+      this does not uniquely identify your feature consider specifying a regular expression in the advanced section below.
+      Additionally, you may import both a name and a unique name for each sequence using the advanced options.
+      When updating a sequence, the value selected here will be used to identify the sequence in the
+      database in combination with any regular expression provided below.'),
+    '#default_value' => 1,
+  );
+
+  $form['analysis'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Analysis Used to Derive Features'),
+    '#collapsed' => TRUE
+  );
+  $form['analysis']['desc'] = array(
+    '#type' => 'markup',
+    '#value' => t("Why specify an analysis for a data load?  All data comes
+       from some place, even if downloaded from Genbank. By specifying
+       analysis details for all data uploads, it allows an end user to reproduce the
+       data set, but at least indicates the source of the data."),
+  );
+
+  // get the list of organisms
+  $sql = "SELECT * FROM {analysis} ORDER BY name";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $org_rset = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $analyses = array();
+  $analyses[''] = '';
+  while ($analysis = db_fetch_object($org_rset)) {
+    $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
+  }
+  $form['analysis']['analysis_id'] = array(
+    '#title'       => t('Analysis'),
+    '#type'        => t('select'),
+    '#description' => t("Choose the analysis to which these features are associated"),
+    '#required'    => TRUE,
+    '#options'     => $analyses,
+  );
+
+  // Advanced Options
+  $form['advanced'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Advanced Options'),
+    '#collapsed' => TRUE
+  );
+  $form['advanced']['re_help']= array(
+    '#type' => 'item',
+    '#value' => t('A regular expression is an advanced method for extracting information from a string of text.
+                   Your FASTA file may contain both a human-readable name and a unique name for each sequence.
+                   If you want to import
+                   both the name and unique name for all sequences, then you must provide regular expressions
+                   so that the loader knows how to separate them.
+                   Otherwise the name and uniquename will be the same.
+                   By default, this loader will use the first word in the definition
+                   lines of the FASTA file
+                   as the name or unique name of the feature.'),
+  );
+  $form['advanced']['re_name']= array(
+    '#type' => 'textfield',
+    '#title' => t('Regular expression for the name'),
+    '#required' => FALSE,
+    '#description' => t('Enter the regular expression that will extract the
+       feature name from the FASTA definition line. For example, for a
+       defintion line with a name and unique name separated by a bar \'|\' (>seqname|uniquename),
+       the regular expression for the name would be, "^(.*?)\|.*$".'),
+  );
+  $form['advanced']['re_uname']= array(
+    '#type' => 'textfield',
+    '#title' => t('Regular expression for the unique name'),
+    '#required' => FALSE,
+    '#description' => t('Enter the regular expression that will extract the
+       feature name from the FASTA definition line. For example, for a
+       defintion line with a name and unique name separated by a bar \'|\' (>seqname|uniquename),
+       the regular expression for the unique name would be "^.*?\|(.*)$").'),
+  );
+
+
+  // Advanced database cross-reference optoins
+  $form['advanced']['db'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('External Database Reference'),
+    '#weight' => 6,
+    '#collapsed' => TRUE
+  );
+  $form['advanced']['db']['re_accession']= array(
+    '#type' => 'textfield',
+    '#title' => t('Regular expression for the accession'),
+    '#required' => FALSE,
+    '#description' => t('Enter the regular expression that will extract the accession for the external database for each feature from the FASTA definition line.'),
+    '#weight' => 2
+  );
 
   // get the list of databases
-   $sql = "SELECT * FROM {db} ORDER BY name";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $db_rset = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $dbs = array();
-   $dbs[''] = '';
-   while($db = db_fetch_object($db_rset)){
-      $dbs[$db->db_id] = "$db->name";
-   }
-   $form['advanced']['db']['db_id'] = array (
-     '#title'       => t('External Database'),
-     '#type'        => t('select'),
-     '#description' => t("Plese choose an external database for which these sequences have a cross reference."),
-     '#required'    => FALSE,
-     '#options'     => $dbs,
-     '#weight'      => 1,
-   );
-
-   $form['advanced']['relationship'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Relationships'),
-      '#weight'=> 6,
-      '#collapsed' => TRUE
-   );
-   $rels = array();
-   $rels[''] = '';
-   $rels['part_of'] = 'part of';
-   $rels['derives_from'] = 'produced by';
-
-
-   // Advanced references options
-   $form['advanced']['relationship']['rel_type']= array(
-     '#title'       => t('Relationship Type'),
-     '#type'        => t('select'),
-     '#description' => t("Use this option to create associations, or relationships between the 
-                          features of this FASTA file and existing features in the database. For 
-                          example, to associate a FASTA file of peptides to existing genes or transcript sequence, 
-                          select the type 'produced by'. For a CDS sequences select the type 'part of'"),
-     '#required'    => FALSE,
-     '#options'     => $rels,
-     '#weight'      => 5,
-   );
-   $form['advanced']['relationship']['re_subject']= array(
-      '#type' => 'textfield',
-      '#title' => t('Regular expression for the parent'),
-      '#required' => FALSE,
-      '#description' => t('Enter the regular expression that will extract the unique 
-                           name needed to identify the existing sequence for which the 
-                           relationship type selected above will apply.'),
-      '#weight' => 6
-   ); 
-   $form['advanced']['relationship']['parent_type']= array(
-      '#type' => 'textfield',
-      '#title' => t('Parent Type'),
-      '#required' => FALSE,
-      '#description' => t('Please enter the Sequence Ontology term for the parent.  For example
-                           if the FASTA file being loaded is a set of proteins that are 
-                           products of genes, then use the SO term \'gene\' or \'transcript\' or equivalent. However,
-                           this type must match the type for already loaded features.'),
-      '#weight' => 7
-   );
-
-   $form['button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Import FASTA file'),
-      '#weight' => 10,
-   );
-   return $form;   
+  $sql = "SELECT * FROM {db} ORDER BY name";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $db_rset = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $dbs = array();
+  $dbs[''] = '';
+  while ($db = db_fetch_object($db_rset)) {
+    $dbs[$db->db_id] = "$db->name";
+  }
+  $form['advanced']['db']['db_id'] = array(
+   '#title'       => t('External Database'),
+   '#type'        => t('select'),
+   '#description' => t("Plese choose an external database for which these sequences have a cross reference."),
+   '#required'    => FALSE,
+   '#options'     => $dbs,
+   '#weight'      => 1,
+  );
+
+  $form['advanced']['relationship'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Relationships'),
+    '#weight' => 6,
+    '#collapsed' => TRUE
+  );
+  $rels = array();
+  $rels[''] = '';
+  $rels['part_of'] = 'part of';
+  $rels['derives_from'] = 'produced by';
+
+
+  // Advanced references options
+  $form['advanced']['relationship']['rel_type']= array(
+   '#title'       => t('Relationship Type'),
+   '#type'        => t('select'),
+   '#description' => t("Use this option to create associations, or relationships between the
+                        features of this FASTA file and existing features in the database. For
+                        example, to associate a FASTA file of peptides to existing genes or transcript sequence,
+                        select the type 'produced by'. For a CDS sequences select the type 'part of'"),
+   '#required'    => FALSE,
+   '#options'     => $rels,
+   '#weight'      => 5,
+  );
+  $form['advanced']['relationship']['re_subject']= array(
+    '#type' => 'textfield',
+    '#title' => t('Regular expression for the parent'),
+    '#required' => FALSE,
+    '#description' => t('Enter the regular expression that will extract the unique
+                         name needed to identify the existing sequence for which the
+                         relationship type selected above will apply.'),
+    '#weight' => 6
+  );
+  $form['advanced']['relationship']['parent_type']= array(
+    '#type' => 'textfield',
+    '#title' => t('Parent Type'),
+    '#required' => FALSE,
+    '#description' => t('Please enter the Sequence Ontology term for the parent.  For example
+                         if the FASTA file being loaded is a set of proteins that are
+                         products of genes, then use the SO term \'gene\' or \'transcript\' or equivalent. However,
+                         this type must match the type for already loaded features.'),
+    '#weight' => 7
+  );
+
+  $form['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Import FASTA file'),
+    '#weight' => 10,
+  );
+  return $form;
 }
 
 /**
@@ -272,98 +278,98 @@ $form['match_type']= array(
  *
  * @ingroup fasta_loader
  */
-function tripal_feature_fasta_load_form_validate($form, &$form_state){
-   $fasta_file = trim($form_state['values']['fasta_file']);
-   $organism_id  = $form_state['values']['organism_id'];
-   $type         = trim($form_state['values']['seqtype']);
-   $method       = trim($form_state['values']['method']);
-   $match_type   = trim($form_state['values']['match_type']);
-   $library_id   = $form_state['values']['library_id'];
-   $re_name      = trim($form_state['values']['re_name']);
-   $re_uname     = trim($form_state['values']['re_uname']);
-   $re_accession = trim($form_state['values']['re_accession']);
-   $db_id        = $form_state['values']['db_id'];
-   $rel_type     = $form_state['values']['rel_type'];
-   $re_subject   = trim($form_state['values']['re_subject']);
-   $parent_type   = trim($form_state['values']['parent_type']);
-
-   if($method == 0){
-      $method = 'Insert only';
-   }
-   if($method == 1){
-      $method = 'Update only';
-   }
-   if($method == 2){
-      $method = 'Insert and update';
-   }
-
-   if($match_type == 0){
-      $match_type = 'Name';
-   }
-
-   if($match_type == 1){
-      $match_type = 'Unique name';
-   }
-
-
-   if ($re_name and !$re_uname and strcmp($match_type,'Unique name')==0){
-      form_set_error('re_uname',t("You must provide a regular expression to identify the sequence unique name"));     
-   }
-
-   if (!$re_name and $re_uname and strcmp($match_type,'Name')==0){
-      form_set_error('re_name',t("You must provide a regular expression to identify the sequence name"));     
-   }
-
-   // check to see if the file is located local to Drupal
-   $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $fasta_file; 
-   if(!file_exists($dfile)){
-      // if not local to Drupal, the file must be someplace else, just use
-      // the full path provided
-      $dfile = $fasta_file;
-   }
-   if(!file_exists($dfile)){
-      form_set_error('fasta_file',t("Cannot find the file on the system. Check that the file exists or that the web server has permissions to read the file."));
-   }
-
-   // make sure if a relationship is specified that all fields are provided.
-   if(($rel_type or $parent_type) and !$re_subject){
-      form_set_error('re_subject',t("Please provide a regular expression for the parent"));
-   }
-   if(($rel_type or $re_subject) and !$parent_type){
-      form_set_error('parent_type',t("Please provide a SO term for the parent"));
-   }
-   if(($parent_type or $re_subject) and !$rel_type){
-      form_set_error('rel_type',t("Please select a relationship type"));
-   }
-
-
-   // make sure if a database is specified that all fields are provided
-   if($db_id and !$re_accession){
-      form_set_error('re_accession',t("Please provide a regular expression for the accession"));
-   }
-   if($re_accession and !$db_id){
-      form_set_error('db_id',t("Please select a database"));
-   }
-
-   // check to make sure the types exists
-   $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 = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
-   $cvterm = db_fetch_object(db_query($cvtermsql,'sequence',$type,$type));
-   if(!$cvterm){
-      form_set_error('type',t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
-   }
-   if($rel_type){
-      $cvterm = db_fetch_object(db_query($cvtermsql,'sequence',$parent_type,$parent_type));
-      if(!$cvterm){
-         form_set_error('parent_type',t("The Sequence Ontology (SO) term selected for the parent relationship is not available in the database. Please check spelling or select another."));
-      }
-   }
-
-   // check to make sure the 'relationship' and 'sequence' ontologies are loaded
-   $form_state['storage']['dfile'] = $dfile;
+function tripal_feature_fasta_load_form_validate($form, &$form_state) {
+  $fasta_file = trim($form_state['values']['fasta_file']);
+  $organism_id  = $form_state['values']['organism_id'];
+  $type         = trim($form_state['values']['seqtype']);
+  $method       = trim($form_state['values']['method']);
+  $match_type   = trim($form_state['values']['match_type']);
+  $library_id   = $form_state['values']['library_id'];
+  $re_name      = trim($form_state['values']['re_name']);
+  $re_uname     = trim($form_state['values']['re_uname']);
+  $re_accession = trim($form_state['values']['re_accession']);
+  $db_id        = $form_state['values']['db_id'];
+  $rel_type     = $form_state['values']['rel_type'];
+  $re_subject   = trim($form_state['values']['re_subject']);
+  $parent_type   = trim($form_state['values']['parent_type']);
+
+  if ($method == 0) {
+    $method = 'Insert only';
+  }
+  if ($method == 1) {
+    $method = 'Update only';
+  }
+  if ($method == 2) {
+    $method = 'Insert and update';
+  }
+
+  if ($match_type == 0) {
+    $match_type = 'Name';
+  }
+
+  if ($match_type == 1) {
+    $match_type = 'Unique name';
+  }
+
+
+  if ($re_name and !$re_uname and strcmp($match_type, 'Unique name')==0) {
+    form_set_error('re_uname', t("You must provide a regular expression to identify the sequence unique name"));
+  }
+
+  if (!$re_name and $re_uname and strcmp($match_type, 'Name')==0) {
+    form_set_error('re_name', t("You must provide a regular expression to identify the sequence name"));
+  }
+
+  // check to see if the file is located local to Drupal
+  $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $fasta_file;
+  if (!file_exists($dfile)) {
+    // if not local to Drupal, the file must be someplace else, just use
+    // the full path provided
+    $dfile = $fasta_file;
+  }
+  if (!file_exists($dfile)) {
+    form_set_error('fasta_file', t("Cannot find the file on the system. Check that the file exists or that the web server has permissions to read the file."));
+  }
+
+  // make sure if a relationship is specified that all fields are provided.
+  if (($rel_type or $parent_type) and !$re_subject) {
+    form_set_error('re_subject', t("Please provide a regular expression for the parent"));
+  }
+  if (($rel_type or $re_subject) and !$parent_type) {
+    form_set_error('parent_type', t("Please provide a SO term for the parent"));
+  }
+  if (($parent_type or $re_subject) and !$rel_type) {
+    form_set_error('rel_type', t("Please select a relationship type"));
+  }
+
+
+  // make sure if a database is specified that all fields are provided
+  if ($db_id and !$re_accession) {
+    form_set_error('re_accession', t("Please provide a regular expression for the accession"));
+  }
+  if ($re_accession and !$db_id) {
+    form_set_error('db_id', t("Please select a database"));
+  }
+
+  // check to make sure the types exists
+  $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 = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
+  $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $type, $type));
+  if (!$cvterm) {
+    form_set_error('type', t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
+  }
+  if ($rel_type) {
+    $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $parent_type, $parent_type));
+    if (!$cvterm) {
+      form_set_error('parent_type', t("The Sequence Ontology (SO) term selected for the parent relationship is not available in the database. Please check spelling or select another."));
+    }
+  }
+
+  // check to make sure the 'relationship' and 'sequence' ontologies are loaded
+  $form_state['storage']['dfile'] = $dfile;
 }
 
 /**
@@ -371,48 +377,48 @@ function tripal_feature_fasta_load_form_validate($form, &$form_state){
  *
  * @ingroup fasta_loader
  */
-function tripal_feature_fasta_load_form_submit ($form, &$form_state){
-   global $user;
-
-   $dfile        = $form_state['storage']['dfile'];
-   $organism_id  = $form_state['values']['organism_id'];
-   $type         = trim($form_state['values']['seqtype']);
-   $method       = trim($form_state['values']['method']);
-   $match_type   = trim($form_state['values']['match_type']);
-   $library_id   = $form_state['values']['library_id'];
-   $re_name      = trim($form_state['values']['re_name']);
-   $re_uname     = trim($form_state['values']['re_uname']);
-   $re_accession = trim($form_state['values']['re_accession']);
-   $db_id        = $form_state['values']['db_id'];
-   $rel_type     = $form_state['values']['rel_type'];
-   $re_subject   = trim($form_state['values']['re_subject']);
-   $parent_type   = trim($form_state['values']['parent_type']);
-   $analysis_id = $form_state['values']['analysis_id'];
-
-   if($method == 0){
-      $method = 'Insert only';
-   }
-   if($method == 1){
-      $method = 'Update only';
-   }
-   if($method == 2){
-      $method = 'Insert and update';
-   }
-
-   if($match_type == 0){
-      $match_type = 'Name';
-   }
-
-   if($match_type == 1){
-      $match_type = 'Unique name';
-   }
-
-   $args = array($dfile,$organism_id,$type,$library_id,$re_name,$re_uname,
-            $re_accession,$db_id,$rel_type,$re_subject,$parent_type,$method,
-            $user->uid,$analysis_id,$match_type);
-
-   tripal_add_job("Import FASTA file: $dfile",'tripal_feature',
-      'tripal_feature_load_fasta',$args,$user->uid);
+function tripal_feature_fasta_load_form_submit($form, &$form_state) {
+  global $user;
+
+  $dfile        = $form_state['storage']['dfile'];
+  $organism_id  = $form_state['values']['organism_id'];
+  $type         = trim($form_state['values']['seqtype']);
+  $method       = trim($form_state['values']['method']);
+  $match_type   = trim($form_state['values']['match_type']);
+  $library_id   = $form_state['values']['library_id'];
+  $re_name      = trim($form_state['values']['re_name']);
+  $re_uname     = trim($form_state['values']['re_uname']);
+  $re_accession = trim($form_state['values']['re_accession']);
+  $db_id        = $form_state['values']['db_id'];
+  $rel_type     = $form_state['values']['rel_type'];
+  $re_subject   = trim($form_state['values']['re_subject']);
+  $parent_type   = trim($form_state['values']['parent_type']);
+  $analysis_id = $form_state['values']['analysis_id'];
+
+  if ($method == 0) {
+    $method = 'Insert only';
+  }
+  if ($method == 1) {
+    $method = 'Update only';
+  }
+  if ($method == 2) {
+    $method = 'Insert and update';
+  }
+
+  if ($match_type == 0) {
+    $match_type = 'Name';
+  }
+
+  if ($match_type == 1) {
+    $match_type = 'Unique name';
+  }
+
+  $args = array($dfile, $organism_id, $type, $library_id, $re_name, $re_uname,
+          $re_accession, $db_id, $rel_type, $re_subject, $parent_type, $method,
+          $user->uid, $analysis_id, $match_type);
+
+  tripal_add_job("Import FASTA file: $dfile", 'tripal_feature',
+    'tripal_feature_load_fasta', $args, $user->uid);
 }
 
 /**
@@ -421,94 +427,95 @@ function tripal_feature_fasta_load_form_submit ($form, &$form_state){
  * @ingroup fasta_loader
  */
 function tripal_feature_load_fasta($dfile, $organism_id, $type,
-   $library_id, $re_name, $re_uname, $re_accession, $db_id, $rel_type,
-   $re_subject, $parent_type, $method, $uid, $analysis_id, 
-   $match_type,$job = NULL)
-{
-
-   print "Opening FASTA file $dfile\n";
-
-    
-   $lines = file($dfile,FILE_SKIP_EMPTY_LINES);
-   $i = 0;
-
-   $name = '';
-   $uname = '';
-   $residues = '';
-   $num_lines = sizeof($lines);
-   $interval = intval($num_lines * 0.01);
-   if($interval == 0){
-      $interval = 1;
-   }
-
-   foreach ($lines as $line_num => $line) {
-      $i++;  // update the line count     
-
-      // update the job status every 1% features
-      if($job and $i % $interval == 0){
-         tripal_job_set_progress($job,intval(($i/$num_lines)*100));
+  $library_id, $re_name, $re_uname, $re_accession, $db_id, $rel_type,
+  $re_subject, $parent_type, $method, $uid, $analysis_id,
+  $match_type, $job = NULL) {
+
+  print "Opening FASTA file $dfile\n";
+
+
+  $lines = file($dfile, FILE_SKIP_EMPTY_LINES);
+  $i = 0;
+
+  $name = '';
+  $uname = '';
+  $residues = '';
+  $num_lines = sizeof($lines);
+  $interval = intval($num_lines * 0.01);
+  if ($interval == 0) {
+    $interval = 1;
+  }
+
+  foreach ($lines as $line_num => $line) {
+    $i++;  // update the line count
+
+    // update the job status every 1% features
+    if ($job and $i % $interval == 0) {
+      tripal_job_set_progress($job, intval(($i/$num_lines)*100));
+    }
+
+    // if we encounter a definition line then get the name, uniquename,
+    // accession and relationship subject from the definition line
+    if (preg_match('/^>/', $line)) {
+      // if we have a feature name then we are starting a new sequence
+      // so let's handle the previous one before moving on
+      if ($name or $uname) {
+        tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id,
+          $accession, $subject, $rel_type, $parent_type, $analysis_id, $organism_id, $type,
+          $source, $residues, $method, $re_name, $match_type);
+        $residues = '';
+        $name = '';
+        $uname = '';
       }
 
-      // if we encounter a definition line then get the name, uniquename, 
-      // accession and relationship subject from the definition line
-      if(preg_match('/^>/',$line)){
-         // if we have a feature name then we are starting a new sequence
-         // so let's handle the previous one before moving on
-         if($name or $uname){
-           tripal_feature_fasta_loader_handle_feature($name,$uname,$db_id,
-              $accession,$subject,$rel_type,$parent_type,$analysis_id,$organism_id,$type,
-              $source,$residues,$method,$re_name,$match_type);
-           $residues = '';
-           $name = '';
-           $uname = '';
-         }
-
-         $line = preg_replace("/^>/",'',$line);
-         // get the feature name
-         if($re_name){
-            if(!preg_match("/$re_name/",$line,$matches)){
-               print "WARNING: Regular expression for the feature name finds nothing\n";
-            }
-            $name = trim($matches[1]);
-         } else {
-            // if the match_type is name and no regular expression was provided
-            // then use the first word as the name, otherwise we don't set the name
-            if(strcmp($match_type,'Name')==0){
-               preg_match("/^\s*(.*?)[\s\|].*$/",$line,$matches);
-               $name = trim($matches[1]);
-            }
-         } 
-         // get the feature unique name
-         if($re_uname){
-            if(!preg_match("/$re_uname/",$line,$matches)){
-               print "WARNING: Regular expression for the feature unique name finds nothing\n";
-            }
-            $uname = trim($matches[1]);
-         } else {
-            // if the match_type is name and no regular expression was provided
-            // then use the first word as the name, otherwise, we don't set the unqiuename
-            if(strcmp($match_type,'Unique name')==0){
-               preg_match("/^\s*(.*?)[\s\|].*$/",$line,$matches);
-               $uname = trim($matches[1]);
-            }
-         } 
-         // get the accession    
-         preg_match("/$re_accession/",$line,$matches);
-         $accession = trim($matches[1]);
-
-         // get the relationship subject
-         preg_match("/$re_subject/",$line,$matches);
-         $subject = trim($matches[1]);
+      $line = preg_replace("/^>/", '', $line);
+      // get the feature name
+      if ($re_name) {
+        if (!preg_match("/$re_name/", $line, $matches)) {
+          print "WARNING: Regular expression for the feature name finds nothing\n";
+        }
+        $name = trim($matches[1]);
+      }
+      else {
+        // if the match_type is name and no regular expression was provided
+        // then use the first word as the name, otherwise we don't set the name
+        if (strcmp($match_type, 'Name')==0) {
+          preg_match("/^\s*(.*?)[\s\|].*$/", $line, $matches);
+          $name = trim($matches[1]);
+        }
+      }
+      // get the feature unique name
+      if ($re_uname) {
+        if (!preg_match("/$re_uname/", $line, $matches)) {
+          print "WARNING: Regular expression for the feature unique name finds nothing\n";
+        }
+        $uname = trim($matches[1]);
       }
       else {
-         $residues .= trim($line);
+        // if the match_type is name and no regular expression was provided
+        // then use the first word as the name, otherwise, we don't set the unqiuename
+        if (strcmp($match_type, 'Unique name')==0) {
+          preg_match("/^\s*(.*?)[\s\|].*$/", $line, $matches);
+          $uname = trim($matches[1]);
+        }
+      }
+      // get the accession
+      preg_match("/$re_accession/", $line, $matches);
+      $accession = trim($matches[1]);
+
+      // get the relationship subject
+      preg_match("/$re_subject/", $line, $matches);
+      $subject = trim($matches[1]);
       }
-   }
+    else {
+      $residues .= trim($line);
+    }
+  }
    // now load the last sequence in the file
-   tripal_feature_fasta_loader_handle_feature($name,$uname,$db_id,
-      $accession,$subject,$rel_type,$parent_type,$analysis_id,$organism_id,$type,
-      $source,$residues,$method,$re_name,$match_type);
-   return '';
+  tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id,
+    $accession, $subject, $rel_type, $parent_type, $analysis_id, $organism_id, $type,
+    $source, $residues, $method, $re_name, $match_type);
+  return '';
 }
 
 /**
@@ -516,194 +523,208 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
  *
  * @ingroup fasta_loader
  */
-function tripal_feature_fasta_loader_handle_feature($name,$uname,$db_id,$accession,
-              $parent,$rel_type,$parent_type,$analysis_id,$organism_id,$type, 
-              $source,$residues,$method,$re_name,$match_type) 
-{
-   $previous_db = tripal_db_set_active('chado');
-
-   // 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 = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
-   $cvterm = db_fetch_object(db_query($cvtermsql,'sequence',$type,$type));
-   if(!$cvterm){
-      print "ERROR: cannot find the term type: '$type'\n";
-      return 0;
-   }
+function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $accession,
+  $parent, $rel_type, $parent_type, $analysis_id, $organism_id, $type,
+  $source, $residues, $method, $re_name, $match_type) {
+
+  $previous_db = tripal_db_set_active('chado');
+
+  // 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 = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
+  $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $type, $type));
+  if (!$cvterm) {
+    print "ERROR: cannot find the term type: '$type'\n";
+    return 0;
+  }
 
    // check to see if this feature already exists
-   if(strcmp($match_type,'Name')==0){
-      $cnt_sql = "SELECT count(*) as cnt FROM {feature} 
-                      WHERE organism_id = %d and name = '%s' and type_id = %d";
-      $cnt = db_fetch_object(db_query($cnt_sql,$organism_id,$name,$cvterm->cvterm_id));
-      if($cnt->cnt > 1){
-         print "ERROR: multiple features exist with the name '$name' of type '$type' for the organism.  skipping\n";
-         return 0;
-      } else {
-         $feature_sql = "SELECT * FROM {feature} 
-                      WHERE organism_id = %d and name = '%s' and type_id = %d";
-         $feature = db_fetch_object(db_query($feature_sql,$organism_id,$name,$cvterm->cvterm_id));
-      }
-   }
-   if(strcmp($match_type,'Unique name')==0){
-      $feature_sql = "SELECT * FROM {feature} 
-                      WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
-      $feature = db_fetch_object(db_query($feature_sql,$organism_id,$uname,$cvterm->cvterm_id));
-   }
-
-   if(!$feature and (strcmp($method,'Insert only')==0 or strcmp($method,'Insert and update')==0)){
-       // if we have a unique name but not a name then set them to be teh same 
-       // and vice versa
-       if(!$uname){
-          $uname = $name;
-       }
-       elseif(!$name){
-          $name = $uname;
-       }
-      // now insert the feature
-      $sql = "INSERT INTO {feature} 
-                 (organism_id, name, uniquename, residues, seqlen, 
-                  md5checksum,type_id,is_analysis,is_obsolete)
-              VALUES(%d,'%s','%s','%s',%d, '%s', %d, %s, %s)";
-      $result = db_query($sql,$organism_id,$name,$uname,$residues,strlen($residues),
-                  md5($residues),$cvterm->cvterm_id,'false','false');
-      if(!$result){
-         print "ERROR: failed to insert feature '$name ($uname)'\n";
-         return 0;
-      } else {
-         print "Inserted feature $name ($uname)\n";
-      }
-      $feature = db_fetch_object(db_query($feature_sql,$organism_id,$uname,$cvterm->cvterm_id));
-   } 
-   if(!$feature and (strcmp($method,'Update only')==0 or strcmp($method,'Insert and update')==0)){
-      print "WARNING: failed to find feature '$name' ('$uname') while matching on " . strtolower($match_type) . ". Skipping\n";
+  if (strcmp($match_type, 'Name')==0) {
+    $cnt_sql = "SELECT count(*) as cnt FROM {feature}
+                  WHERE organism_id = %d and name = '%s' and type_id = %d";
+    $cnt = db_fetch_object(db_query($cnt_sql, $organism_id, $name, $cvterm->cvterm_id));
+    if ($cnt->cnt > 1) {
+      print "ERROR: multiple features exist with the name '$name' of type '$type' for the organism.  skipping\n";
       return 0;
-   }
-
-   if($feature and (strcmp($method,'Update only')==0 or strcmp($method,'Insert and update')==0)){
-       if(strcmp($method,'Update only')==0 or strcmp($method,'Insert and update')==0){
-         if(strcmp($match_type,'Name')==0){
-            // if we're matching on the name but do not have a new unique name then we
-            // don't want to update the uniquename.  If we do have a uniquename then we 
-            // should update it.  We only get a uniquename if there was a regular expression
-            // provided for pulling it out
-            if($uname){
-               $sql = "UPDATE {feature} 
-                        SET uniquename = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s'
-                        WHERE organism_id = %d and name = '%s' and type_id = %d";
-               $result = db_query($sql,$uname,$residues,strlen($residues),md5($residues),$organism_id,$name,$cvterm->cvterm_id);
-            } else {
-               $sql = "UPDATE {feature} 
-                        SET residues = '%s', seqlen = '%s', md5checksum = '%s'
-                        WHERE organism_id = %d and name = '%s' and type_id = %d";
-               $result = db_query($sql,$residues,strlen($residues),md5($residues),$organism_id,$name,$cvterm->cvterm_id);
-            }
-         } else {
-            // if we're matching on the unique name but do not have a new name then we
-            // don't want to update the name.  If we do have a name then we 
-            // should update it.  We only get a name if there was a regular expression
-            // provided for pulling it out
-            if($name){
-               $sql = "UPDATE {feature} 
-                        SET name = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s'
-                        WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
-               $result = db_query($sql,$name,$residues,strlen($residues),md5($residues),$organism_id,$uname,$cvterm->cvterm_id);
-            } else {
-               $sql = "UPDATE {feature} 
-                        SET residues = '%s', seqlen = '%s', md5checksum = '%s'
-                        WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
-               $result = db_query($sql,$residues,strlen($residues),md5($residues),$organism_id,$uname,$cvterm->cvterm_id);
-            }
-         }
-         if(!$result){
-            print "ERROR: failed to update feature '$name ($uname)'\n";
-            return 0;
-         } else {
-            print "Updated feature $name ($uname)\n";
-         }
-      } else {
-         print "WARNING: feature already exists: '$name' ('$uname'). Skipping\n";
-      }
-   }
-   // now get the feature
-   $feature = db_fetch_object(db_query($feature_sql,$organism_id,$uname,$cvterm->cvterm_id));
-   if(!$feature){
-      print "Something bad has happened: $organism_id, $uname, $cvterm->cvterm_id\n";
+    }
+    else {
+      $feature_sql = "SELECT * FROM {feature}
+                  WHERE organism_id = %d and name = '%s' and type_id = %d";
+      $feature = db_fetch_object(db_query($feature_sql, $organism_id, $name, $cvterm->cvterm_id));
+    }
+  }
+  if (strcmp($match_type, 'Unique name')==0) {
+    $feature_sql = "SELECT * FROM {feature}
+                    WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
+    $feature = db_fetch_object(db_query($feature_sql, $organism_id, $uname, $cvterm->cvterm_id));
+  }
+
+  if (!$feature and (strcmp($method, 'Insert only')==0 or strcmp($method, 'Insert and update')==0)) {
+    // if we have a unique name but not a name then set them to be teh same
+    // and vice versa
+    if (!$uname) {
+      $uname = $name;
+    }
+    elseif (!$name) {
+      $name = $uname;
+    }
+    // now insert the feature
+    $sql = "INSERT INTO {feature}
+           (organism_id, name, uniquename, residues, seqlen,
+            md5checksum,type_id,is_analysis,is_obsolete)
+        VALUES(%d,'%s','%s','%s',%d, '%s', %d, %s, %s)";
+    $result = db_query($sql, $organism_id, $name, $uname, $residues, drupal_strlen($residues),
+            md5($residues), $cvterm->cvterm_id, 'false', 'false');
+    if (!$result) {
+      print "ERROR: failed to insert feature '$name ($uname)'\n";
       return 0;
-   }
-
-	 // add in the analysis link
-	 if ($analysis_id) {
-	 	$analysis_link_sql = 'SELECT * FROM analysisfeature WHERE analysis_id=%d AND feature_id=%d';
-	 	$analysis_link = db_fetch_object(db_query($analysis_link_sql, $analysis_id, $feature->feature_id));
-	 	if (!$analysis_link) {
-	 		$sql = "INSERT INTO analysisfeature (analysis_id, feature_id) VALUES (%d, %d)";
-	 		$result = db_query($sql, $analysis_id, $feature->feature_id);
-		  if(!$result){
-			  print "WARNING: could not add link between analysis: ".$analysis_id." and feature: ".$feature->uniquename."\n";
-		  }
-		  $analysis_link = db_fetch_object(db_query($analysis_link_sql, $analysis_id, $feature->feature_id));
-	 	}
-	 }
-	 
-   // now add the database cross reference
-   if($db_id){
-      // check to see if this accession reference exists, if not add it
-      $dbxrefsql = "SELECT * FROM {dbxref} WHERE db_id = %s and accession = '%s'";
-      $dbxref = db_fetch_object(db_query($dbxrefsql,$db_id,$accession));
-      if(!$dbxref){
-         $sql = "INSERT INTO {dbxref} (db_id,accession) VALUES (%d,'%s')";
-         $result = db_query($sql,$db_id,$accession);
-         if(!$result){
-           print "WARNING: could not add external database acession: '$name accession: $accession'\n";
-         }
-         $dbxref = db_fetch_object(db_query($dbxrefsql,$db_id,$accession));
+    }
+    else {
+      print "Inserted feature $name ($uname)\n";
+    }
+    $feature = db_fetch_object(db_query($feature_sql, $organism_id, $uname, $cvterm->cvterm_id));
+    }
+  if (!$feature and (strcmp($method, 'Update only')==0 or drupal_strcmp($method, 'Insert and update')==0)) {
+    print "WARNING: failed to find feature '$name' ('$uname') while matching on " . drupal_strtolower($match_type) . ". Skipping\n";
+    return 0;
+  }
+
+  if ($feature and (strcmp($method, 'Update only')==0 or strcmp($method, 'Insert and update')==0)) {
+    if (strcmp($method, 'Update only')==0 or strcmp($method, 'Insert and update')==0) {
+      if (strcmp($match_type, 'Name')==0) {
+        // if we're matching on the name but do not have a new unique name then we
+        // don't want to update the uniquename.  If we do have a uniquename then we
+        // should update it.  We only get a uniquename if there was a regular expression
+        // provided for pulling it out
+        if ($uname) {
+          $sql = "UPDATE {feature}
+                SET uniquename = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s'
+                WHERE organism_id = %d and name = '%s' and type_id = %d";
+          $result = db_query($sql, $uname, $residues, drupal_strlen($residues), md5($residues), $organism_id, $name, $cvterm->cvterm_id);
+        }
+        else {
+          $sql = "UPDATE {feature}
+                  SET residues = '%s', seqlen = '%s', md5checksum = '%s'
+                  WHERE organism_id = %d and name = '%s' and type_id = %d";
+          $result = db_query($sql, $residues, durpal_strlen($residues), md5($residues), $organism_id, $name, $cvterm->cvterm_id);
+        }
+        }
+        else {
+          // if we're matching on the unique name but do not have a new name then we
+          // don't want to update the name.  If we do have a name then we
+          // should update it.  We only get a name if there was a regular expression
+          // provided for pulling it out
+          if ($name) {
+            $sql = "UPDATE {feature}
+                    SET name = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s'
+                    WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
+            $result = db_query($sql, $name, $residues, drupal_strlen($residues), md5($residues), $organism_id, $uname, $cvterm->cvterm_id);
+          }
+          else {
+            $sql = "UPDATE {feature}
+                    SET residues = '%s', seqlen = '%s', md5checksum = '%s'
+                    WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
+            $result = db_query($sql, $residues, drupal_strlen($residues), md5($residues), $organism_id, $uname, $cvterm->cvterm_id);
+          }
+    }
+    if (!$result) {
+      print "ERROR: failed to update feature '$name ($uname)'\n";
+      return 0;
+    }
+    else {
+      print "Updated feature $name ($uname)\n";
+    }
+    }
+    else {
+      print "WARNING: feature already exists: '$name' ('$uname'). Skipping\n";
+    }
+  }
+   // now get the feature
+  $feature = db_fetch_object(db_query($feature_sql, $organism_id, $uname, $cvterm->cvterm_id));
+  if (!$feature) {
+    print "Something bad has happened: $organism_id, $uname, $cvterm->cvterm_id\n";
+    return 0;
+  }
+
+  // add in the analysis link
+  if ($analysis_id) {
+    // @coder-ignore: non-drupal table thus table prefixing doesn't apply
+    $analysis_link_sql = 'SELECT * FROM analysisfeature WHERE analysis_id=%d AND feature_id=%d';
+    $analysis_link = db_fetch_object(db_query($analysis_link_sql, $analysis_id, $feature->feature_id));
+    if (!$analysis_link) {
+      // @coder-ignore: non-drupal table thus table prefixing doesn't apply
+      $sql = "INSERT INTO analysisfeature (analysis_id, feature_id) VALUES (%d, %d)";
+      $result = db_query($sql, $analysis_id, $feature->feature_id);
+      if (!$result) {
+        print "WARNING: could not add link between analysis: " . $analysis_id . " and feature: " . $feature->uniquename . "\n";
       }
+      $analysis_link = db_fetch_object(db_query($analysis_link_sql, $analysis_id, $feature->feature_id));
+    }
+  }
 
-      // check to see if the feature dbxref record exists if not, then add it 
-      $fdbxrefsql = "SELECT * FROM {feature_dbxref} WHERE feature_id = %d and dbxref_id = %d";
-      $fdbxref = db_fetch_object(db_query($fdbxrefsql,$feature->feature_id,$dbxref->dbxref_id));
-      if(!$fdbxref){
-         $sql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) VALUES (%d,%d)";
-         $result = db_query($sql,$feature->feature_id,$dbxref->dbxref_id);
-         if(!$result){
-            print "WARNING: could not associate database cross reference with feature: '$name accession: $accession'\n";
-         } else {
-            print "Added database crossreference $name ($uname) -> $accession\n";
-         }
+   // now add the database cross reference
+  if ($db_id) {
+    // check to see if this accession reference exists, if not add it
+    // @coder-ignore: non-drupal table thus table prefixing doesn't apply
+    $dbxrefsql = "SELECT * FROM dbxref WHERE db_id = %d and accession = '%s'";
+    $dbxref = db_fetch_object(db_query($dbxrefsql, $db_id, $accession));
+    if (!$dbxref) {
+      // @coder-ignore: non-drupal table thus table prefixing doesn't apply
+      $sql = "INSERT INTO dbxref (db_id,accession) VALUES (%d, '%s')";
+      $result = db_query($sql, $db_id, $accession);
+      if (!$result) {
+        print "WARNING: could not add external database acession: '$name accession: $accession'\n";
+      }
+      $dbxref = db_fetch_object(db_query($dbxrefsql, $db_id, $accession));
+    }
+
+    // check to see if the feature dbxref record exists if not, then add it
+    $fdbxrefsql = "SELECT * FROM {feature_dbxref} WHERE feature_id = %d and dbxref_id = %d";
+    $fdbxref = db_fetch_object(db_query($fdbxrefsql, $feature->feature_id, $dbxref->dbxref_id));
+    if (!$fdbxref) {
+      $sql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) VALUES (%d, %d)";
+      $result = db_query($sql, $feature->feature_id, $dbxref->dbxref_id);
+      if (!$result) {
+        print "WARNING: could not associate database cross reference with feature: '$name accession: $accession'\n";
+      }
+      else {
+        print "Added database crossreference $name ($uname) -> $accession\n";
       }
-   }
+    }
+    }
 
    // now add in the relationship if one exists.  First, get the parent type for the relationship
-   // then get the parent feature 
-   if($rel_type){
-      $parentcvterm = db_fetch_object(db_query($cvtermsql,'sequence',$parent_type,$parent_type));
-      $relcvterm = db_fetch_object(db_query($cvtermsql,'relationship',$rel_type,$rel_type));
-      $parent_feature = db_fetch_object(db_query($feature_sql,$organism_id,$parent,$parentcvterm->cvterm_id));
-      if($parent_feature){
-         // check to see if the relationship already exists
-         $sql = "SELECT * FROM {feature_relationship} WHERE subject_id = %d and object_id = %d and type_id = %d";
-         $rel = db_fetch_object(db_query($sql,$feature->feature_id,$parent_feature->feature_id,$relcvterm->cvterm_id));
-         if($rel){
-            print "WARNING: relationship already exists, skipping '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
-         } else {      
-            $sql = "INSERT INTO {feature_relationship} (subject_id,object_id,type_id)
-                    VALUES (%d,%d,%d)";
-            $result = db_query($sql,$feature->feature_id,$parent_feature->feature_id,$relcvterm->cvterm_id);
-            if(!$result){
-               print "WARNING: failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
-            } else {
-               print "Inserted relationship relationship: '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
-            }
-         } 
+   // then get the parent feature
+  if ($rel_type) {
+    $parentcvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $parent_type, $parent_type));
+    $relcvterm = db_fetch_object(db_query($cvtermsql, 'relationship', $rel_type, $rel_type));
+    $parent_feature = db_fetch_object(db_query($feature_sql, $organism_id, $parent, $parentcvterm->cvterm_id));
+    if ($parent_feature) {
+      // check to see if the relationship already exists
+      $sql = "SELECT * FROM {feature_relationship} WHERE subject_id = %d and object_id = %d and type_id = %d";
+      $rel = db_fetch_object(db_query($sql, $feature->feature_id, $parent_feature->feature_id, $relcvterm->cvterm_id));
+      if ($rel) {
+        print "WARNING: relationship already exists, skipping '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
       }
       else {
-         print "WARNING: cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent\n";
+        $sql = "INSERT INTO {feature_relationship} (subject_id,object_id,type_id)
+                VALUES (%d,%d,%d)";
+        $result = db_query($sql, $feature->feature_id, $parent_feature->feature_id, $relcvterm->cvterm_id);
+        if (!$result) {
+          print "WARNING: failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
+        }
+        else {
+          print "Inserted relationship relationship: '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
+        }
       }
-   }
-   tripal_db_set_active($previous_db);
+    }
+    else {
+      print "WARNING: cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent\n";
+    }
+    }
+  tripal_db_set_active($previous_db);
 }
 

File diff suppressed because it is too large
+ 617 - 605
tripal_feature/gff_loader.php


+ 146 - 139
tripal_feature/indexFeatures.php

@@ -1,61 +1,41 @@
 <?php
+/**
+ * @file
+ * @todo Add file header description
+ */
+
 
 // This script can be run as a stand-alone script to sync all the features from chado to drupal
 //
 // To index a single feature
 // -i feature_id
-// -n node_id 
+// -n node_id
 //
 // To index all features
-// -i 0 
+// -i 0
 
 $arguments = getopt("i:n:");
 
-if(isset($arguments['i'])){
-   $drupal_base_url = parse_url('http://www.example.com');
-   $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
-   $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
-   $_SERVER['REMOTE_ADDR'] = NULL;
-   $_SERVER['REQUEST_METHOD'] = NULL;
-	
-   require_once 'includes/bootstrap.inc';
-   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-
-   $feature_id = $arguments['i'];
-   $nid        = $arguments['n'];
-
-   # print "\n";
-   # print "feature id is $feature_id\n";
-   # print "nid is $nid\n";
-   # print "\n";
-
-   if($feature_id > 0){ 
-      # print "indexing feature $feature_id\n";
-     // We register a shutdown function to ensure that the nodes
-     // that are indexed will have proper entries in the search_totals
-     // table.  Without these entries, the searching doesn't work
-     // properly. This function may run for quite a while since
-     // it must calculate the sum of the scores of all entries in
-     // the search_index table.  In the case of common words like
-     // 'contig', this will take quite a while
-      register_shutdown_function('search_update_totals');
-      tripal_feature_index_feature($feature_id, $nid); 
-   }
-   else{ 
-      print "indexing all features...\n";
-      tripal_features_reindex(0);
-   }
+if (isset($arguments['i'])) {
+  $drupal_base_url = parse_url('http://www.example.com');
+  $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
+  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
+  $_SERVER['REMOTE_ADDR'] = NULL;
+  $_SERVER['REQUEST_METHOD'] = NULL;
 
-}
+  require_once 'includes/bootstrap.inc';
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
-/**
- *
- *
- * @ingroup tripal_feature
- */
-function tripal_features_reindex ($max_sync,$job_id = NULL){
-   $i = 0;
+  $feature_id = $arguments['i'];
+  $nid        = $arguments['n'];
 
+  # print "\n";
+  # print "feature id is $feature_id\n";
+  # print "nid is $nid\n";
+  # print "\n";
+
+  if ($feature_id > 0) {
+    # print "indexing feature $feature_id\n";
    // We register a shutdown function to ensure that the nodes
    // that are indexed will have proper entries in the search_totals
    // table.  Without these entries, the searching doesn't work
@@ -63,63 +43,90 @@ function tripal_features_reindex ($max_sync,$job_id = NULL){
    // it must calculate the sum of the scores of all entries in
    // the search_index table.  In the case of common words like
    // 'contig', this will take quite a while
-   register_shutdown_function('search_update_totals');
-
-   // use this SQL statement to get the features that we're going to index. This
-   // SQL statement is derived from the hook_search function in the Drupal API.
-   // Essentially, this is the SQL statement that finds all nodes that need
-   // reindexing, but adjusted to include the chado_feature
-   $sql = "SELECT N.nid, N.title, CF.feature_id ".
-          "FROM {node} N ".
-          "  INNER JOIN chado_feature CF ON CF.nid = N.nid ";
-   $results = db_query($sql);
-
-   // load into ids array
-   $count = 0;
-   $chado_features = array();
-   while($chado_feature = db_fetch_object($results)){
-      $chado_features[$count] = $chado_feature;
-      $count++;
-   }
-
-   // Iterate through features that need to be indexed 
-   $interval = intval($count * 0.01);
-   if($interval >= 0){
-      $interval = 1;
-   }
-   foreach($chado_features as $chado_feature){
-
-      // update the job status every 1% features
-      if($job_id and $i % $interval == 0){
-         $prog = intval(($i/$count)*100);
-         tripal_job_set_progress($job_id,$prog);
-         print "$prog%\n";
-      }
-
-      // sync only the max requested
-      if($max_sync and $i == $max_sync){
-         return '';
-      }
-      $i++;
-
-      # tripal_feature_index_feature ($chado_feature->feature_id,$chado_feature->nid);
-      # parsing all the features can cause memory overruns 
-      # we are not sure why PHP does not clean up the memory as it goes
-      # to avoid this problem we will call this script through an
-      # independent system call
-
-      $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/indexFeatures.php ";
-      $cmd .= "-i $chado_feature->feature_id -n $chado_feature->nid ";
-
-      # print "\t$cmd\n";
-      # print "\tfeature id is $chado_feature->feature_id\n";
-      # print "\tnid is $chado_feature->nid\n";
-      # print "\n";
-
-      system($cmd);
-   }
-
-   return '';
+    register_shutdown_function('search_update_totals');
+    tripal_feature_index_feature($feature_id, $nid);
+  }
+  else{
+    print "indexing all features...\n";
+    tripal_features_reindex(0);
+  }
+
+}
+
+/**
+ *
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_features_reindex($max_sync, $job_id = NULL) {
+  $i = 0;
+
+  // We register a shutdown function to ensure that the nodes
+  // that are indexed will have proper entries in the search_totals
+  // table.  Without these entries, the searching doesn't work
+  // properly. This function may run for quite a while since
+  // it must calculate the sum of the scores of all entries in
+  // the search_index table.  In the case of common words like
+  // 'contig', this will take quite a while
+  register_shutdown_function('search_update_totals');
+
+  // use this SQL statement to get the features that we're going to index. This
+  // SQL statement is derived from the hook_search function in the Drupal API.
+  // Essentially, this is the SQL statement that finds all nodes that need
+  // reindexing, but adjusted to include the chado_feature
+  $sql = "SELECT N.nid, N.title, CF.feature_id ".
+        "FROM {node} N ".
+        "  INNER JOIN chado_feature CF ON CF.nid = N.nid ";
+  $results = db_query($sql);
+
+  // load into ids array
+  $count = 0;
+  $chado_features = array();
+  while ($chado_feature = db_fetch_object($results)) {
+    $chado_features[$count] = $chado_feature;
+    $count++;
+  }
+
+  // Iterate through features that need to be indexed
+  $interval = intval($count * 0.01);
+  if ($interval >= 0) {
+    $interval = 1;
+  }
+  foreach ($chado_features as $chado_feature) {
+
+    // update the job status every 1% features
+    if ($job_id and $i % $interval == 0) {
+      $prog = intval(($i/$count)*100);
+      tripal_job_set_progress($job_id, $prog);
+      print "$prog%\n";
+    }
+
+    // sync only the max requested
+    if ($max_sync and $i == $max_sync) {
+      return '';
+    }
+    $i++;
+
+  /**
+    * tripal_feature_index_feature ($chado_feature->feature_id,$chado_feature->nid);
+    * parsing all the features can cause memory overruns
+    * we are not sure why PHP does not clean up the memory as it goes
+    * to avoid this problem we will call this script through an
+    * independent system call
+    */
+
+    $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/indexFeatures.php ";
+    $cmd .= "-i $chado_feature->feature_id -n $chado_feature->nid ";
+
+    # print "\t$cmd\n";
+    # print "\tfeature id is $chado_feature->feature_id\n";
+    # print "\tnid is $chado_feature->nid\n";
+    # print "\n";
+
+    system($cmd);
+    }
+
+  return '';
 }
 
 /**
@@ -127,44 +134,44 @@ function tripal_features_reindex ($max_sync,$job_id = NULL){
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_index_feature ($feature_id,$nid){
-   #print "\tfeature $feature_id nid $nid\n";
-   // return if we haven't been provided with a feature_id
-   if(!$feature_id){
+function tripal_feature_index_feature($feature_id, $nid) {
+  #print "\tfeature $feature_id nid $nid\n";
+  // return if we haven't been provided with a feature_id
+  if (!$feature_id) {
+    return 0;
+  }
+
+  // if we only have a feature_id then let's find a corresponding
+  // node.  If we can't find a node then return.
+  if (!$nid) {
+    $nsql = "SELECT N.nid,N.title FROM {chado_feature} CF ".
+            "  INNER JOIN {node} N ON N.nid = CF.nid ".
+            "WHERE CF.feature_id = %d";
+    $node = db_fetch_object(db_query($nsql, $feature_id));
+    if (!$node) {
       return 0;
-   }
-
-   // if we only have a feature_id then let's find a corresponding
-   // node.  If we can't find a node then return.
-   if(!$nid){
-      $nsql = "SELECT N.nid,N.title FROM {chado_feature} CF ".
-              "  INNER JOIN {node} N ON N.nid = CF.nid ".
-              "WHERE CF.feature_id = %d";
-      $node = db_fetch_object(db_query($nsql,$feature_id));
-      if(!$node){
-         return 0;
-      }
-      $node = node_load($node->nid);
-   } else {
-      $node = node_load($nid);
-   }
-
-   // node load the noad, the comments and the taxonomy and
-   // index
-   $node->build_mode = NODE_BUILD_SEARCH_INDEX;
-   $node = node_build_content($node, FALSE, FALSE);
-   $node->body = drupal_render($node->content);
-   node_invoke_nodeapi($node, 'view', FALSE, FALSE);
-//   $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
-//   $node->body .= module_invoke('taxonomy','nodeapi', $node, 'update index');
-   //   print "$node->title: $node->body\n";
-   search_index($node->nid,'node',$node->body);
-
-   # $mem = memory_get_usage(TRUE);
-   # $mb = $mem/1048576;
-   # print "$mb mb\n";
-
-   return 1;
+    }
+    $node = node_load($node->nid);
+  }
+  else {
+    $node = node_load($nid);
+  }
+
+  // node load the noad, the comments and the taxonomy and
+  // index
+  $node->build_mode = NODE_BUILD_SEARCH_INDEX;
+  $node = node_build_content($node, FALSE, FALSE);
+  $node->body = drupal_render($node->content);
+  node_invoke_nodeapi($node, 'view', FALSE, FALSE);
+  //   $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
+  //   $node->body .= module_invoke('taxonomy','nodeapi', $node, 'update index');
+  //   print "$node->title: $node->body\n";
+  search_index($node->nid, 'node', $node->body);
+
+  # $mem = memory_get_usage(TRUE);
+  # $mb = $mem/1048576;
+  # print "$mb mb\n";
+
+  return 1;
 }
 
-?>

+ 379 - 370
tripal_feature/syncFeatures.php

@@ -1,268 +1,274 @@
 <?php
 
+/**
+ * @file
+ * @todo Add file header description
+ */
+
 
 # This script can be run as a stand-alone script to sync all the features from chado to drupal
 // Parameter f specifies the feature_id to sync
-// -f 0 will sync all features 
+// -f 0 will sync all features
 
 $arguments = getopt("f:");
 
-if(isset($arguments['f'])){
-   $drupal_base_url = parse_url('http://www.example.com');
-   $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
-   $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
-   $_SERVER['REMOTE_ADDR'] = NULL;
-   $_SERVER['REQUEST_METHOD'] = NULL;
-	
-   require_once 'includes/bootstrap.inc';
-   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-
-   $feature_id = $arguments['f'];
-
-   if($feature_id > 0 ){ 
-      tripal_feature_sync_feature($feature_id); 
-   }
-   else{ 
-      print "syncing all features...\n";
-      tripal_feature_sync_features();
-   }   
+if (isset($arguments['f'])) {
+  $drupal_base_url = parse_url('http://www.example.com');
+  $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
+  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
+  $_SERVER['REMOTE_ADDR'] = NULL;
+  $_SERVER['REQUEST_METHOD'] = NULL;
+
+  require_once 'includes/bootstrap.inc';
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+
+  $feature_id = $arguments['f'];
+
+  if ($feature_id > 0 ) {
+    tripal_feature_sync_feature($feature_id);
+  }
+  else{
+    print "syncing all features...\n";
+    tripal_feature_sync_features();
+  }
 }
 /**
-*
-*/
-function tripal_feature_sync_form (){
-
-   $form['description'] = array(
-      '#type' => 'item',
-      '#value' => t("Add feature types, optionally select an organism and ".
-         "click the 'Sync all Features' button to create Drupal ".
-         "content for features in chado. Only features of the types listed ".
-         "below in the Feature Types box will be synced. You may limit the ".
-         "features to be synced by a specific organism. Depending on the ".
-         "number of features in the chado database this may take a long ".
-         "time to complete. "),
-   );
-
-   $form['feature_types'] = array(
-      '#title'       => t('Feature Types'),
-      '#type'        => 'textarea',
-      '#description' => t('Enter the names of the sequence types that the ".
-         "site will support with independent pages.  Pages for these data ".
-         "types will be built automatically for features that exist in the ".
-         "chado database.  The names listed here should be spearated by ".
-         "spaces or entered separately on new lines. The names must match ".
-         "exactly (spelling and case) with terms in the sequence ontology'),
-      '#required'    => TRUE,
-      '#default_value' => variable_get('chado_sync_feature_types','gene contig'),
-   );
-
-   // get the list of organisms
-   $sql = "SELECT * FROM {organism} ORDER BY genus, species";
-   $orgs = tripal_organism_get_synced(); 
-   $organisms[] = ''; 
-   foreach($orgs as $organism){
-      $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-   }
-   $form['organism_id'] = array (
-     '#title'       => t('Organism'),
-     '#type'        => t('select'),
-     '#description' => t("Choose the organism for which features will be deleted."),
-     '#options'     => $organisms,
-   );
-
-
-   $form['button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Sync all Features'),
-      '#weight' => 3,
-   );
-
-   return $form;
+ *
+ */
+function tripal_feature_sync_form() {
+
+  $form['description'] = array(
+  '#type' => 'item',
+  '#value' => t("Add feature types, optionally select an organism and ".
+     "click the 'Sync all Features' button to create Drupal ".
+     "content for features in chado. Only features of the types listed ".
+     "below in the Feature Types box will be synced. You may limit the ".
+     "features to be synced by a specific organism. Depending on the ".
+     "number of features in the chado database this may take a long ".
+     "time to complete. "),
+  );
+
+  $form['feature_types'] = array(
+    '#title'       => t('Feature Types'),
+    '#type'        => 'textarea',
+    '#description' => t('Enter the names of the sequence types that the ".
+       "site will support with independent pages.  Pages for these data ".
+       "types will be built automatically for features that exist in the ".
+       "chado database.  The names listed here should be spearated by ".
+       "spaces or entered separately on new lines. The names must match ".
+       "exactly (spelling and case) with terms in the sequence ontology'),
+    '#required'    => TRUE,
+    '#default_value' => variable_get('chado_sync_feature_types', 'gene contig'),
+  );
+
+  // get the list of organisms
+  $sql = "SELECT * FROM {organism} ORDER BY genus, species";
+  $orgs = tripal_organism_get_synced();
+  $organisms[] = '';
+  foreach ($orgs as $organism) {
+    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
+  }
+  $form['organism_id'] = array(
+    '#title'       => t('Organism'),
+    '#type'        => t('select'),
+    '#description' => t("Choose the organism for which features will be deleted."),
+    '#options'     => $organisms,
+  );
+
+
+  $form['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Sync all Features'),
+    '#weight' => 3,
+  );
+
+  return $form;
 }
 /**
-*
-*/
-function tripal_feature_sync_form_validate ($form, &$form_state){
-   $organism_id   = $form_state['values']['organism_id'];
-   $feature_types = $form_state['values']['feature_types'];
+ *
+ */
+function tripal_feature_sync_form_validate($form, &$form_state) {
+  $organism_id   = $form_state['values']['organism_id'];
+  $feature_types = $form_state['values']['feature_types'];
 
-   // nothing to do
+  // nothing to do
 }
 /**
-*
-*/
-function tripal_feature_sync_form_submit ($form, &$form_state){
+ *
+ */
+function tripal_feature_sync_form_submit($form, &$form_state) {
 
-   global $user;
+  global $user;
 
-   $organism_id   = $form_state['values']['organism_id'];
-   $feature_types = $form_state['values']['feature_types'];
+  $organism_id   = $form_state['values']['organism_id'];
+  $feature_types = $form_state['values']['feature_types'];
 
-   $job_args = array(0,$organism_id,$feature_types);
+  $job_args = array(0, $organism_id, $feature_types);
 
-   if($organism_id){
-      $organism = tripal_core_chado_select('organism',array('genus','species'),array('organism_id' => $organism_id));
-      $title = "Sync all features for " .  $organism[0]->genus . " " . $organism[0]->species;
-   } else {
-      $title = t('Sync all features for all synced organisms');
-   }
+  if ($organism_id) {
+    $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $organism_id));
+    $title = "Sync all features for " .  $organism[0]->genus . " " . $organism[0]->species;
+  }
+  else {
+    $title = t('Sync all features for all synced organisms');
+  }
 
-   variable_set('chado_sync_feature_types',$feature_types);
+  variable_set('chado_sync_feature_types', $feature_types);
 
-   tripal_add_job($title,'tripal_feature',
-         'tripal_feature_sync_features',$job_args,$user->uid);
+  tripal_add_job($title, 'tripal_feature',
+    'tripal_feature_sync_features', $job_args, $user->uid);
 }
 /**
-*
-*/   
-function tripal_feature_set_urls($job_id = NULL){
-   // first get the list of features that have been synced
-   $sql = "SELECT * FROM {chado_feature}";
-   $nodes = db_query($sql);
-   while($node = db_fetch_object($nodes)){
-      // now get the feature details
-      $feature_arr = tripal_core_chado_select('feature',
-         array('feature_id','name','uniquename'),
-         array('feature_id' => $node->feature_id));
-      $feature = $feature_arr[0];
-
-      tripal_feature_set_feature_url($node,$feature);
-   }
+ *
+ */
+function tripal_feature_set_urls($job_id = NULL) {
+  // first get the list of features that have been synced
+  $sql = "SELECT * FROM {chado_feature}";
+  $nodes = db_query($sql);
+  while ($node = db_fetch_object($nodes)) {
+    // now get the feature details
+    $feature_arr = tripal_core_chado_select('feature',
+      array('feature_id', 'name', 'uniquename'),
+      array('feature_id' => $node->feature_id));
+    $feature = $feature_arr[0];
+
+    tripal_feature_set_feature_url($node, $feature);
+  }
 }
 /**
-*
-*/
-function tripal_feature_set_feature_url($node,$feature){
-
-   // determine which URL alias to use
-   $alias_type = variable_get('chado_feature_url','internal ID');
-   $aprefix = variable_get('chado_feature_accession_prefix','ID');
-   switch ($alias_type) {
-      case 'feature name':
-         $url_alias = $feature->name;
-         break;
-      case 'feature unique name':
-         $url_alias = $feature->uniquename;
-         break;
-      default:
-         $url_alias = "$aprefix$feature->feature_id";
-   }
-   print "Setting $alias_type as URL alias for $feature->name: node/$node->nid => $url_alias\n";
-   // remove any previous alias
-   db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
-   // add the new alias
-   path_set_alias("node/$node->nid",$url_alias);
+ *
+ */
+function tripal_feature_set_feature_url($node, $feature) {
+
+  // determine which URL alias to use
+  $alias_type = variable_get('chado_feature_url', 'internal ID');
+  $aprefix = variable_get('chado_feature_accession_prefix', 'ID');
+  switch ($alias_type) {
+    case 'feature name':
+      $url_alias = $feature->name;
+      break;
+    case 'feature unique name':
+      $url_alias = $feature->uniquename;
+      break;
+    default:
+      $url_alias = "$aprefix$feature->feature_id";
+  }
+  print "Setting $alias_type as URL alias for $feature->name: node/$node->nid => $url_alias\n";
+  // remove any previous alias
+  db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
+  // add the new alias
+  path_set_alias("node/$node->nid", $url_alias);
 }
 /**
  *
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_sync_features ($max_sync = 0, $organism_id = NULL, 
-   $feature_types = NULL, $job_id = NULL)
-{
-   //print "Syncing features (max of $max_sync)\n";
-   $i = 0;
-
-   // get the list of available sequence ontology terms for which
-   // we will build drupal pages from features in chado.  If a feature
-   // is not one of the specified typse we won't build a node for it.
-   if(!$feature_types){
-      $allowed_types = variable_get('chado_sync_feature_types','gene contig');
-   } else {
-      $allowed_types = $feature_types;
-   }
-   $allowed_types = preg_replace("/[\s\n\r]+/"," ",$allowed_types);
-
-   print "Looking for features of type: $allowed_types\n";
-
-   $so_terms = split(' ',$allowed_types);
-   $where_cvt = "";
-   foreach ($so_terms as $term){
-      $where_cvt .= "CVT.name = '$term' OR ";
-   }
-   $where_cvt = substr($where_cvt,0,strlen($where_cvt)-3);  # strip trailing 'OR'
-
-   // get the list of organisms that are synced and only include features from
-   // those organisms
-   $orgs = tripal_organism_get_synced();
-   $where_org = "";
-   foreach($orgs as $org){
-      if($organism_id){
-         if($org->organism_id and $org->organism_id == $organism_id){
-            $where_org .= "F.organism_id = $org->organism_id OR ";
-         }
-      } 
-      else {
-         if($org->organism_id){
-            $where_org .= "F.organism_id = $org->organism_id OR ";
-         }
-      }
-   }
-   $where_org = substr($where_org,0,strlen($where_org)-3);  # strip trailing 'OR'
-
-   // use this SQL statement to get the features that we're going to upload
-   $sql = "SELECT feature_id ".
-          "FROM {FEATURE} F ".
-          "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
-          "  INNER JOIN CV on CV.cv_id = CVT.cv_id ".
-          "WHERE ($where_cvt) AND ($where_org) AND CV.name = 'sequence' ".
-          "ORDER BY feature_id";
-
-   // get the list of features
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $results = db_query($sql);
-
-   tripal_db_set_active($previous_db);  // now use drupal database
-
-   // load into ids array
-   $count = 0;
-   $ids = array();
-   while($id = db_fetch_object($results)){
-      $ids[$count] = $id->feature_id;
-      $count++;
-   }
-
-   // make sure our vocabularies are set before proceeding
-   tripal_feature_set_vocabulary();
-
-   // pre-create the SQL statement that will be used to check
-   // if a feature has already been synced.  We skip features
-   // that have been synced
-   $sql = "SELECT * FROM {chado_feature} WHERE feature_id = %d";
-
-   // Iterate through features that need to be synced
-   $interval = intval($count * 0.01);
-   if($interval > 1){
-      $interval = 1;
-   }
-   $num_ids = sizeof($ids);
-   $i = 0;
-   foreach($ids as $feature_id){
-      // update the job status every 1% features
-      if($job_id and $i % $interval == 0){
-         tripal_job_set_progress($job_id,intval(($i/$count)*100));
-      }
-      // if we have a maximum number to sync then stop when we get there
-      // if not then just continue on
-      if($max_sync and $i == $max_sync){
-         return '';
+function tripal_feature_sync_features($max_sync = 0, $organism_id = NULL,
+  $feature_types = NULL, $job_id = NULL) {
+  //print "Syncing features (max of $max_sync)\n";
+  $i = 0;
+
+  // get the list of available sequence ontology terms for which
+  // we will build drupal pages from features in chado.  If a feature
+  // is not one of the specified typse we won't build a node for it.
+  if (!$feature_types) {
+    $allowed_types = variable_get('chado_sync_feature_types', 'gene contig');
+  }
+  else {
+    $allowed_types = $feature_types;
+  }
+  $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
+
+  print "Looking for features of type: $allowed_types\n";
+
+  $so_terms = split(' ', $allowed_types);
+  $where_cvt = "";
+  foreach ($so_terms as $term) {
+    $where_cvt .= "CVT.name = '$term' OR ";
+  }
+  $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt)-3);  # strip trailing 'OR'
+
+  // get the list of organisms that are synced and only include features from
+  // those organisms
+  $orgs = tripal_organism_get_synced();
+  $where_org = "";
+  foreach ($orgs as $org) {
+    if ($organism_id) {
+      if ($org->organism_id and $org->organism_id == $organism_id) {
+        $where_org .= "F.organism_id = $org->organism_id OR ";
       }
-      if(!db_fetch_object(db_query($sql,$feature_id))){
-        
-         # parsing all the features can cause memory overruns 
-         # we are not sure why PHP does not clean up the memory as it goes
-         # to avoid this problem we will call this script through an
-         # independent system call
-         print "$i of $num_ids Syncing feature id: $feature_id\n";
-         $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/syncFeatures.php -f $feature_id ";
-         system($cmd);
-
-      }
-      $i++;
-   }
-
-   return '';
+    }
+    else {
+    if ($org->organism_id) {
+      $where_org .= "F.organism_id = $org->organism_id OR ";
+    }
+    }
+  }
+  $where_org = drupal_substr($where_org, 0, drupal_strlen($where_org)-3);  # strip trailing 'OR'
+
+  // use this SQL statement to get the features that we're going to upload
+  $sql = "SELECT feature_id ".
+        "FROM {FEATURE} F ".
+        "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
+        "  INNER JOIN CV on CV.cv_id = CVT.cv_id ".
+        "WHERE ($where_cvt) AND ($where_org) AND CV.name = 'sequence' ".
+        "ORDER BY feature_id";
+
+  // get the list of features
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $results = db_query($sql);
+
+  tripal_db_set_active($previous_db);  // now use drupal database
+
+  // load into ids array
+  $count = 0;
+  $ids = array();
+  while ($id = db_fetch_object($results)) {
+    $ids[$count] = $id->feature_id;
+    $count++;
+  }
+
+  // make sure our vocabularies are set before proceeding
+  tripal_feature_set_vocabulary();
+
+  // pre-create the SQL statement that will be used to check
+  // if a feature has already been synced.  We skip features
+  // that have been synced
+  $sql = "SELECT * FROM {chado_feature} WHERE feature_id = %d";
+
+  // Iterate through features that need to be synced
+  $interval = intval($count * 0.01);
+  if ($interval > 1) {
+    $interval = 1;
+  }
+  $num_ids = sizeof($ids);
+  $i = 0;
+  foreach ($ids as $feature_id) {
+    // update the job status every 1% features
+    if ($job_id and $i % $interval == 0) {
+      tripal_job_set_progress($job_id, intval(($i/$count)*100));
+    }
+    // if we have a maximum number to sync then stop when we get there
+    // if not then just continue on
+    if ($max_sync and $i == $max_sync) {
+      return '';
+    }
+    if (!db_fetch_object(db_query($sql, $feature_id))) {
+
+      # parsing all the features can cause memory overruns
+      # we are not sure why PHP does not clean up the memory as it goes
+      # to avoid this problem we will call this script through an
+      # independent system call
+      print "$i of $num_ids Syncing feature id: $feature_id\n";
+      $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/syncFeatures.php -f $feature_id ";
+      system($cmd);
+
+    }
+    $i++;
+  }
+
+  return '';
 }
 
 /**
@@ -270,149 +276,152 @@ function tripal_feature_sync_features ($max_sync = 0, $organism_id = NULL,
  *
  * @ingroup tripal_feature
  */
-function tripal_feature_sync_feature ($feature_id){
-//   print "\tSyncing feature $feature_id\n";
-
-   $mem = memory_get_usage(TRUE);
-   $mb = $mem/1048576;
-//   print "$mb mb\n";
-
-   global $user;
-   $create_node = 1;   // set to 0 if the node exists and we just sync and not create
-
-   // get the accession prefix
-   $aprefix = variable_get('chado_feature_accession_prefix','ID');
-
-   // if we don't have a feature_id then return
-   if(!$feature_id){
-      drupal_set_message(t("Please provide a feature_id to sync"));
-      return '';
-   }
-
-   // get information about this feature
-   $fsql = "SELECT F.feature_id, F.name, F.uniquename,O.genus, ".
-           "    O.species,CVT.name as cvname,F.residues,F.organism_id ".
-           "FROM {FEATURE} F ".
-           "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
-           "  INNER JOIN Organism O ON F.organism_id = O.organism_ID ".
-           "WHERE F.feature_id = %d";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $feature = db_fetch_object(db_query($fsql,$feature_id));
-   tripal_db_set_active($previous_db);  // now use drupal database
-
-   // get the synonyms for this feature
-   $synsql = "SELECT S.name ".
-             "FROM {feature_synonym} FS ".
-             "  INNER JOIN {synonym} S on FS.synonym_id = S.synonym_id ".
-             "WHERE FS.feature_id = %d";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $synonyms = db_query($synsql,$feature_id);
-   tripal_db_set_active($previous_db);  // now use drupal database
-
-   // now add these synonyms to the feature object as a single string   
-   $synstring = '';
-   while($synonym = db_fetch_object($synonyms)){
-      $synstring .= "$synonym->name\n";
-   }        
-   $feature->synonyms = $synstring;
-
-   // check to make sure that we don't have any nodes with this feature name as a title
-   // but without a corresponding entry in the chado_feature table if so then we want to
-   // clean up that node.  (If a node is found we don't know if it belongs to our feature or
-   // not since features can have the same name/title.)
-   $tsql =  "SELECT * FROM {node} N ".
-            "WHERE title = '%s'";
-   $cnsql = "SELECT * FROM {chado_feature} ".
-            "WHERE nid = %d";
-   $nodes = db_query($tsql,$feature->name);
-   // cycle through all nodes that may have this title
-   while($node = db_fetch_object($nodes)){
-      $feature_nid = db_fetch_object(db_query($cnsql,$node->nid));
-      if(!$feature_nid){
-         drupal_set_message(t("$feature_id: A node is present but the chado_feature entry is missing... correcting"));
-         node_delete($node->nid);
+function tripal_feature_sync_feature($feature_id) {
+  //   print "\tSyncing feature $feature_id\n";
+
+  $mem = memory_get_usage(TRUE);
+  $mb = $mem/1048576;
+  //   print "$mb mb\n";
+
+  global $user;
+  $create_node = 1;   // set to 0 if the node exists and we just sync and not create
+
+  // get the accession prefix
+  $aprefix = variable_get('chado_feature_accession_prefix', 'ID');
+
+  // if we don't have a feature_id then return
+  if (!$feature_id) {
+    drupal_set_message(t("Please provide a feature_id to sync"));
+    return '';
+  }
+
+  // get information about this feature
+  $fsql = "SELECT F.feature_id, F.name, F.uniquename,O.genus, ".
+         "    O.species,CVT.name as cvname,F.residues,F.organism_id ".
+         "FROM {FEATURE} F ".
+         "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
+         "  INNER JOIN Organism O ON F.organism_id = O.organism_ID ".
+         "WHERE F.feature_id = %d";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $feature = db_fetch_object(db_query($fsql, $feature_id));
+  tripal_db_set_active($previous_db);  // now use drupal database
+
+  // get the synonyms for this feature
+  $synsql = "SELECT S.name ".
+           "FROM {feature_synonym} FS ".
+           "  INNER JOIN {synonym} S on FS.synonym_id = S.synonym_id ".
+           "WHERE FS.feature_id = %d";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $synonyms = db_query($synsql, $feature_id);
+  tripal_db_set_active($previous_db);  // now use drupal database
+
+  // now add these synonyms to the feature object as a single string
+  $synstring = '';
+  while ($synonym = db_fetch_object($synonyms)) {
+    $synstring .= "$synonym->name\n";
+  }
+  $feature->synonyms = $synstring;
+
+  // check to make sure that we don't have any nodes with this feature name as a title
+  // but without a corresponding entry in the chado_feature table if so then we want to
+  // clean up that node.  (If a node is found we don't know if it belongs to our feature or
+  // not since features can have the same name/title.)
+  $tsql =  "SELECT * FROM {node} N ".
+          "WHERE title = '%s'";
+  $cnsql = "SELECT * FROM {chado_feature} ".
+          "WHERE nid = %d";
+  $nodes = db_query($tsql, $feature->name);
+  // cycle through all nodes that may have this title
+  while ($node = db_fetch_object($nodes)) {
+    $feature_nid = db_fetch_object(db_query($cnsql, $node->nid));
+    if (!$feature_nid) {
+      drupal_set_message(t("%feature_id: A node is present but the chado_feature entry is missing... correcting", array('%feature_id' => $feature_id)));
+      node_delete($node->nid);
+    }
+  }
+
+  // check if this feature already exists in the chado_feature table.
+  // if we have a chado feature, we want to check to see if we have a node
+  $cfsql = "SELECT * FROM {chado_feature} ".
+          "WHERE feature_id = %d";
+  // @coder-ignore: don't need to use db_rewrite_sql() since need all nodes regardless of access control
+  $nsql =  "SELECT * FROM {node} ".
+          "WHERE nid = %d";
+  $chado_feature = db_fetch_object(db_query($cfsql, $feature->feature_id));
+  if ($chado_feature) {
+    drupal_set_message(t("%feature_id: A chado_feature entry exists", array('%feature_id' => $feature_id)));
+    $node = db_fetch_object(db_query($nsql, $chado_feature->nid));
+    if (!$node) {
+      // if we have a chado_feature but not a node then we have a problem and
+      // need to cleanup
+      drupal_set_message(t("%feature_id: The node is missing, but has a chado_feature entry... correcting", array('%feature_id' => $feature_id)));
+      $df_sql = "DELETE FROM {chado_feature} WHERE feature_id = %d";
+      db_query($df_sql, $feature_id);
+    }
+    else {
+      drupal_set_message(t("%feature_id: A corresponding node exists", array('%feature_id' => $feature_id)));
+      $create_node = 0;
+    }
+  }
+
+  // if we've encountered an error then just return.
+  if ($error_msg = db_error()) {
+    //print "$error_msg\n";
+    return '';
+  }
+
+  // if a drupal node does not exist for this feature then we want to
+  // create one.  Note that the node_save call in this block
+  // will call the hook_submit function which
+  if ($create_node) {
+    // get the organism for this feature
+    $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
+    $organism = db_fetch_object(db_query($sql, $feature->organism_id));
+
+    drupal_set_message(t("%feature_id: Creating node $feature->name", array('%feature_id' => $feature_id)));
+    $new_node = new stdClass();
+    $new_node->type = 'chado_feature';
+    $new_node->uid = $user->uid;
+    $new_node->title = "$feature->name, $feature->uniquename ($feature->cvname) $organism->genus $organism->species";
+    $new_node->fname = "$feature->name";
+    $new_node->uniquename = "$feature->uniquename";
+    $new_node->feature_id = $feature->feature_id;
+    $new_node->residues = $feature->residues;
+    $new_node->organism_id = $feature->organism_id;
+    $new_node->feature_type = $feature->cvname;
+    $new_node->synonyms = $feature->synonyms;
+
+    // validate the node and if okay then submit
+    node_validate($new_node);
+    if ($errors = form_get_errors()) {
+      foreach ($errors as $key => $msg) {
+        drupal_set_message(t("%msg", array('%msg' => $msg)));
       }
-   }
-
-   // check if this feature already exists in the chado_feature table.
-   // if we have a chado feature, we want to check to see if we have a node
-   $cfsql = "SELECT * FROM {chado_feature} ".
-            "WHERE feature_id = %d";
-   $nsql =  "SELECT * FROM {node} ".
-            "WHERE nid = %d";
-   $chado_feature = db_fetch_object(db_query($cfsql,$feature->feature_id));
-   if($chado_feature){
-      drupal_set_message(t("$feature_id: A chado_feature entry exists"));
-      $node = db_fetch_object(db_query($nsql,$chado_feature->nid));
-      if(!$node){
-         // if we have a chado_feature but not a node then we have a problem and
-         // need to cleanup
-         drupal_set_message(t("$feature_id: The node is missing, but has a chado_feature entry... correcting"));
-         $df_sql = "DELETE FROM {chado_feature} WHERE feature_id = %d";
-         db_query($df_sql,$feature_id);
-      } else {
-         drupal_set_message(t("$feature_id: A corresponding node exists"));
-         $create_node = 0;
-      }
-   }
+      return $errors;
+    }
+    else {
+      $node = node_submit($new_node);
+      node_save($node);
+    }
 
-   // if we've encountered an error then just return.
-   if($error_msg = db_error()){
-      //print "$error_msg\n";
-      return '';
-   }
-
-   // if a drupal node does not exist for this feature then we want to
-   // create one.  Note that the node_save call in this block
-   // will call the hook_submit function which
-   if($create_node){
-      // get the organism for this feature
-      $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
-      $organism = db_fetch_object(db_query($sql,$feature->organism_id));
-
-      drupal_set_message(t("$feature_id: Creating node $feature->name"));
-      $new_node = new stdClass();
-      $new_node->type = 'chado_feature';
-      $new_node->uid = $user->uid;
-      $new_node->title = "$feature->name, $feature->uniquename ($feature->cvname) $organism->genus $organism->species";
-      $new_node->fname = "$feature->name";
-      $new_node->uniquename = "$feature->uniquename";
-      $new_node->feature_id = $feature->feature_id;
-      $new_node->residues = $feature->residues;
-      $new_node->organism_id = $feature->organism_id;
-      $new_node->feature_type = $feature->cvname;
-      $new_node->synonyms = $feature->synonyms;
-
-      // validate the node and if okay then submit
-      node_validate($new_node);
-      if ($errors = form_get_errors()) {
-         foreach($errors as $key => $msg){
-            drupal_set_message($msg);
-         }
-         return $errors;
-      } else {
-         $node = node_submit($new_node);
-         node_save($node);
-      }
-
-   }
-   else {
-      $node = $chado_feature;
-   }
+  }
+  else {
+    $node = $chado_feature;
+  }
 
 
-   // set the taxonomy for this node
-   drupal_set_message(t("$feature_id ($node->nid): setting taxonomy"));
-   tripal_feature_set_taxonomy($node,$feature_id);
+  // set the taxonomy for this node
+  drupal_set_message(t("%feature_id ($node->nid): setting taxonomy", array('%feature_id' => $feature_id)));
+  tripal_feature_set_taxonomy($node, $feature_id);
 
-   // reindex the node
-   // drupal_set_message(t("$feature_id( $node->nid): indexing"));
-   // tripal_feature_index_feature ($feature_id,$node->nid);
+  // reindex the node
+  // drupal_set_message(t("$feature_id( $node->nid): indexing"));
+  // tripal_feature_index_feature ($feature_id,$node->nid);
 
-   // set the URL alias for this node
-   tripal_feature_set_feature_url($node,$feature);
+  // set the URL alias for this node
+  tripal_feature_set_feature_url($node, $feature);
 
 
-   return '';
+  return '';
 }
-?>
+

+ 116 - 116
tripal_feature/tripal_feature-db_references.inc

@@ -13,13 +13,13 @@
 function tripal_feature_add_ALL_dbreferences_page($node) {
   $output = '';
 
-  $output .= tripal_feature_implement_add_chado_properties_progress('db_references') . '<br>';
-  $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br>';
-  $output .= '<br><b>Current Database References</b><br>';
+  $output .= tripal_feature_implement_add_chado_properties_progress('db_references') . '<br />';
+  $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br />';
+  $output .= '<br /><b>Current Database References</b><br />';
   $output .= list_dbreferences_for_node($node->db_references);
-  $output .= '<br><br>';
+  $output .= '<br /><br />';
   $output .= drupal_get_form('tripal_feature_add_ONE_dbreference_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_feature_implement_add_chado_properties_navigate', 'db_references', $node->nid);
   return $output;
 }
@@ -84,29 +84,29 @@ function tripal_feature_add_ONE_dbreference_form($form_state, $node) {
  */
 function tripal_feature_add_ONE_dbreference_form_validate($form, &$form_state) {
 
-   $db_id = $form_state['values']['db_id'];
-   $accession = $form_state['values']['accession'];
-   $description = $form_state['values']['description'];
-   $feature_id = $form_state['values']['feature_id'];
-   $nid = $form_state['values']['nid'];
-
-   // Check database is valid db_id in chado
-   $previous_db = tripal_db_set_active('chado');
-   $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $db_id));
-   tripal_db_set_active($previous_db);
-   if ($tmp_obj->count != 1) {
-      form_set_error('database', 'The database you selected is not valid. Please choose another one.');
-   }
-
-   // Check Accession is unique for database
-   $previous_db = tripal_db_set_active('chado');
-   $sql = "SELECT count(*) as count FROM {dbxref} WHERE accession='%s' and db_id = %d";
-   $tmp_obj = db_fetch_object(db_query($sql, $accession, $db_id));
-   tripal_db_set_active($previous_db);
-
-   if ($tmp_obj->count > 0) {
-      form_set_error('accession', 'This accession has already been assigned to another feature in the selected database.');
-   }
+  $db_id = $form_state['values']['db_id'];
+  $accession = $form_state['values']['accession'];
+  $description = $form_state['values']['description'];
+  $feature_id = $form_state['values']['feature_id'];
+  $nid = $form_state['values']['nid'];
+
+  // Check database is valid db_id in chado
+  $previous_db = tripal_db_set_active('chado');
+  $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $db_id));
+  tripal_db_set_active($previous_db);
+  if ($tmp_obj->count != 1) {
+    form_set_error('database', 'The database you selected is not valid. Please choose another one.');
+  }
+
+  // Check Accession is unique for database
+  $previous_db = tripal_db_set_active('chado');
+  $sql = "SELECT count(*) as count FROM {dbxref} WHERE accession='%s' and db_id = %d";
+  $tmp_obj = db_fetch_object(db_query($sql, $accession, $db_id));
+  tripal_db_set_active($previous_db);
+
+  if ($tmp_obj->count > 0) {
+    form_set_error('accession', 'This accession has already been assigned to another feature in the selected database.');
+  }
 
 }
 
@@ -117,33 +117,33 @@ function tripal_feature_add_ONE_dbreference_form_validate($form, &$form_state) {
  */
 function tripal_feature_add_ONE_dbreference_form_submit($form, &$form_state) {
 
-   $db_id = $form_state['values']['db_id'];
-   $accession = $form_state['values']['accession'];
-   $description = $form_state['values']['description'];
-   $feature_id = $form_state['values']['feature_id'];
-   $nid = $form_state['values']['nid'];
+  $db_id = $form_state['values']['db_id'];
+  $accession = $form_state['values']['accession'];
+  $description = $form_state['values']['description'];
+  $feature_id = $form_state['values']['feature_id'];
+  $nid = $form_state['values']['nid'];
 
-   // create dbxref
-   $previous_db = tripal_db_set_active('chado');
-   $isql =  "INSERT INTO {dbxref} (db_id, accession, description) VALUES (%d, '%s', '%s')";
-   db_query($isql, $db_id, $accession, $description);
-   tripal_db_set_active($previous_db);
+  // create dbxref
+  $previous_db = tripal_db_set_active('chado');
+  $isql =  "INSERT INTO {dbxref} (db_id, accession, description) VALUES (%d, '%s', '%s')";
+  db_query($isql, $db_id, $accession, $description);
+  tripal_db_set_active($previous_db);
 
-   //create feature_dbxref
-   $dbxref = tripal_db_get_dbxref( array('db_id' => array('type' => 'INT', 'value' => $form_state['values']['db_id']),
-                       'accession' => array('type' => 'STRING', 'exact' => TRUE, 'value' => $form_state['values']['accession']) ) );
+  //create feature_dbxref
+  $dbxref = tripal_db_get_dbxref( array('db_id' => array('type' => 'INT', 'value' => $form_state['values']['db_id']),
+                     'accession' => array('type' => 'STRING', 'exact' => TRUE, 'value' => $form_state['values']['accession']) ) );
 
   if (!empty($dbxref->dbxref_id)) {
     $previous_db = tripal_db_set_active('chado');
       $isql = "INSERT INTO {feature_dbxref} (feature_id, dbxref_id) VALUES (%d, %d)";
       db_query($isql, $feature_id, $dbxref->dbxref_id);
     tripal_db_set_active($previous_db);
-      drupal_set_message('Successfully Added Database Reference');
+      drupal_set_message(t('Successfully Added Database Reference'));
       drupal_goto('node/' . $nid);
-   }
-   else {
-      drupal_set_message('Database reference NOT successfully created...', 'error');
-   } //end of if dbxref was created successfully
+  }
+  else {
+    drupal_set_message(t('Database reference NOT successfully created...'), 'error');
+  } //end of if dbxref was created successfully
 
 }
 
@@ -157,9 +157,9 @@ function tripal_feature_edit_ALL_dbreferences_page($node) {
   $output = '';
 
   $output .= drupal_get_form('tripal_feature_edit_ALL_db_references_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_feature_add_ONE_dbreference_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_feature_implement_back_to_feature_button', $node->nid);
 
   return $output;
@@ -190,52 +190,52 @@ function tripal_feature_edit_ALL_db_references_form($form_state, $node) {
   ksort($db_options);
 
   if (sizeof($references) != 0) {
-     foreach ($references as $ref) {
-       $i++;
-       $form["num-$i"] = array(
-         '#type' => 'fieldset',
-         '#title' => t("Database Reference") . " $i"
-       );
-
-       $form["num-$i"]["accession-$i"] = array(
-         '#type' => 'textfield',
-         '#title' => t('Accession'),
-         '#size' => 30,
-         '#required' => TRUE,
-         '#default_value' => $ref->accession
-       );
-
-       $form["num-$i"]["db_id-$i"] = array(
-         '#type' => 'select',
-         '#title' => t('Database'),
-         '#options' => $db_options,
-         '#required' => TRUE,
-         '#default_value' => $ref->db_id
-       );
-
-
-       $form["num-$i"]["dbxref_id-$i"] = array(
-         '#type' => 'hidden',
-         '#value' => $ref->dbxref_id
-       );
-
-       $form["num-$i"]["delete-$i"] = array(
-         '#type' => 'submit',
-         '#value' => t("Delete"),
-         '#name' => "delete-$i",
-       );
-
-     }
-
-     $form['num_db_references'] = array(
-       '#type' => 'hidden',
-       '#value' => $i
-     );
-
-     $form["submit-edits"] = array(
-       '#type' => 'submit',
-       '#value' => t('Update All References')
-     );
+    foreach ($references as $ref) {
+      $i++;
+      $form["num-$i"] = array(
+        '#type' => 'fieldset',
+        '#title' => t("Database Reference") . " $i"
+      );
+
+      $form["num-$i"]["accession-$i"] = array(
+        '#type' => 'textfield',
+        '#title' => t('Accession'),
+        '#size' => 30,
+        '#required' => TRUE,
+        '#default_value' => $ref->accession
+      );
+
+      $form["num-$i"]["db_id-$i"] = array(
+        '#type' => 'select',
+        '#title' => t('Database'),
+        '#options' => $db_options,
+        '#required' => TRUE,
+        '#default_value' => $ref->db_id
+      );
+
+
+      $form["num-$i"]["dbxref_id-$i"] = array(
+        '#type' => 'hidden',
+        '#value' => $ref->dbxref_id
+      );
+
+      $form["num-$i"]["delete-$i"] = array(
+        '#type' => 'submit',
+        '#value' => t("Delete"),
+        '#name' => "delete-$i",
+      );
+
+      }
+
+      $form['num_db_references'] = array(
+        '#type' => 'hidden',
+        '#value' => $i
+      );
+
+      $form["submit-edits"] = array(
+        '#type' => 'submit',
+        '#value' => t('Update All References')
+      );
   } //end of foreach db ref
   return $form;
 }
@@ -253,29 +253,29 @@ function tripal_feature_edit_ALL_db_references_form_submit($form, &$form_state)
   $nid = $form_state['values']['nid'];
 
   if (strcmp($action, 'Update All References')==0) {
-     for ($i=1; $i<=$num_refs; $i++) {
-     $dbxref_id = $form_state['values']["dbxref_id-$i"];
-     $db_id = $form_state['values']["db_id-$i"];
-     $accession = $form_state['values']["accession-$i"];
-       tripal_feature_update_db_reference($dbxref_id, $db_id, $accession);
-     }
-     drupal_set_message("Updated all Database References");
-     drupal_goto('node/' . $nid);
+    for ($i=1; $i<=$num_refs; $i++) {
+    $dbxref_id = $form_state['values']["dbxref_id-$i"];
+    $db_id = $form_state['values']["db_id-$i"];
+    $accession = $form_state['values']["accession-$i"];
+      tripal_feature_update_db_reference($dbxref_id, $db_id, $accession);
+    }
+    drupal_set_message(t("Updated all Database References"));
+    drupal_goto('node/' . $nid);
   }
   elseif (strcmp($action, 'Delete')==0) {
-     if (preg_match('/delete-(\d+)/', $button, $matches) ) {
-        $i = $matches[1];
-       $dbxref_id = $form_state['values']["dbxref_id-$i"];
-        tripal_feature_delete_db_reference($dbxref_id);
-        drupal_set_message("Deleted Database Reference");
-        drupal_goto('node/' . $nid);
-     }
-     else {
-        drupal_set_message("Could not remove database reference: ", 'error');
-     }
-  }
+    if (preg_match('/delete-(\d+)/', $button, $matches) ) {
+      $i = $matches[1];
+      $dbxref_id = $form_state['values']["dbxref_id-$i"];
+      tripal_feature_delete_db_reference($dbxref_id);
+      drupal_set_message(t("Deleted Database Reference"));
+      drupal_goto('node/' . $nid);
+    }
+    else {
+      drupal_set_message(t("Could not remove database reference:"), 'error');
+    }
+    }
   else {
-    drupal_set_message("Unrecognized Button Pressed", 'error');
+    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
   }
 
 }
@@ -323,7 +323,7 @@ function tripal_feature_delete_db_reference($dbxref_id) {
 function theme_tripal_feature_edit_ALL_db_references_form($form) {
   $output = '';
 
-  $output .= '<br><fieldset>';
+  $output .= '<br /><fieldset>';
   $output .= '<legend>Edit Existing Database References<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing database references, one per line. When entering a database reference, the accession '
          .'is a unique identifier for this feature in the specified database.</p>';
@@ -337,7 +337,7 @@ function theme_tripal_feature_edit_ALL_db_references_form($form) {
          . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
-  $output .= '</table><br>';
+  $output .= '</table><br />';
   $output .= drupal_render($form);
   $output .= '</fieldset>';
 

+ 142 - 143
tripal_feature/tripal_feature-delete.inc

@@ -5,167 +5,166 @@
  */
 
 function tripal_feature_delete_form() {
-   // get the list of organisms
-   $sql = "SELECT * FROM {organism} ORDER BY genus, species";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $org_rset = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $organisms = array();
-   $organisms[''] = '';
-   while ($organism = db_fetch_object($org_rset)) {
-      $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-   }
-   $form['desc'] = array(
-      '#type' => 'markup',
-      '#value' => t("Use one or more of the following fields to identify sets of features to be deleted."),
-   );
-
-   $form['feature_names']= array(
-      '#type' => 'textarea',
-      '#title' => t('Feature Names'),
-      '#description' => t('Please provide a list of feature names or unique names,
-         separated by spaces or by new lines to be delete. If you specify feature names then
-         all other options below will be ignored (except the unique checkbox).'),
-   );
+  // get the list of organisms
+  $sql = "SELECT * FROM {organism} ORDER BY genus, species";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $org_rset = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $organisms = array();
+  $organisms[''] = '';
+  while ($organism = db_fetch_object($org_rset)) {
+    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
+  }
+  $form['desc'] = array(
+    '#type' => 'markup',
+    '#value' => t("Use one or more of the following fields to identify sets of features to be deleted."),
+  );
+
+  $form['feature_names']= array(
+    '#type' => 'textarea',
+    '#title' => t('Feature Names'),
+    '#description' => t('Please provide a list of feature names or unique names,
+       separated by spaces or by new lines to be delete. If you specify feature names then
+       all other options below will be ignored (except the unique checkbox).'),
+  );
   $form['is_unique'] = array(
-      '#title' => t('Names are Unique Names'),
-      '#type' => 'checkbox',
-      '#description' => t('Select this checbox if the names listed in the feature
-        names box above are the unique name of the feature rather than the human readable names.'),
+    '#title' => t('Names are Unique Names'),
+    '#type' => 'checkbox',
+    '#description' => t('Select this checbox if the names listed in the feature
+      names box above are the unique name of the feature rather than the human readable names.'),
+  );
+  $form['seq_type']= array(
+    '#type' => 'textfield',
+    '#title' => t('Sequence Type'),
+    '#description' => t('Please enter the Sequence Ontology term that describes the features to be deleted. Use in conjunction with an organism or anaylysis.'),
+  );
+
+  $form['organism_id'] = array(
+   '#title'       => t('Organism'),
+   '#type'        => t('select'),
+   '#description' => t("Choose the organism for which features will be deleted."),
+   '#options'     => $organisms,
+  );
+
+
+  // get the list of analyses
+  $sql = "SELECT * FROM {analysis} ORDER BY name";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $org_rset = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $analyses = array();
+  $analyses[''] = '';
+  while ($analysis = db_fetch_object($org_rset)) {
+    $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
+  }
+  //  TODO: ADD THIS BACK IN LATER
+  //
+  //   $form['analysis']['analysis_id'] = array (
+  //     '#title'       => t('Analysis'),
+  //     '#type'        => t('select'),
+  //     '#description' => t("Choose the analysis for which associated features will be deleted."),
+  //     '#options'     => $analyses,
+  //   );
+
+  $form['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Delete Features'),
   );
-   $form['seq_type']= array(
-      '#type' => 'textfield',
-      '#title' => t('Sequence Type'),
-      '#description' => t('Please enter the Sequence Ontology term that describes the features to be deleted. Use in conjunction with an organism or anaylysis.'),
-   );
-
-   $form['organism_id'] = array(
-     '#title'       => t('Organism'),
-     '#type'        => t('select'),
-     '#description' => t("Choose the organism for which features will be deleted."),
-     '#options'     => $organisms,
-   );
-
-
-   // get the list of analyses
-   $sql = "SELECT * FROM {analysis} ORDER BY name";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $org_rset = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $analyses = array();
-   $analyses[''] = '';
-   while ($analysis = db_fetch_object($org_rset)) {
-      $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
-   }
-//  TODO: ADD THIS BACK IN LATER
-//
-//   $form['analysis']['analysis_id'] = array (
-//     '#title'       => t('Analysis'),
-//     '#type'        => t('select'),
-//     '#description' => t("Choose the analysis for which associated features will be deleted."),
-//     '#options'     => $analyses,
-//   );
-
-   $form['button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Delete Features'),
-   );
-   return $form;
+  return $form;
 }
 
 function tripal_feature_delete_form_validate($form, &$form_state) {
-   $organism_id   = $form_state['values']['organism_id'];
-   $seq_type      = trim($form_state['values']['seq_type']);
-   $analysis_id   = $form_state['values']['analysis_id'];
-   $is_unique     = $form_state['values']['is_unique'];
-   $feature_names = $form_state['values']['feature_names'];
-
-   if (!$organism_id and !$anaysis_id and !$seq_type and !$feature_names) {
-      form_set_error('feature_names', t("Please select at least one option"));
-   }
-
-   // check to make sure the types exists
-   if ($seq_type) {
-      $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 = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
-      $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $seq_type, $seq_type));
-      if (!$cvterm) {
-         form_set_error('seq_type', t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
-      }
-   }
+  $organism_id   = $form_state['values']['organism_id'];
+  $seq_type      = trim($form_state['values']['seq_type']);
+  $analysis_id   = $form_state['values']['analysis_id'];
+  $is_unique     = $form_state['values']['is_unique'];
+  $feature_names = $form_state['values']['feature_names'];
+
+  if (!$organism_id and !$anaysis_id and !$seq_type and !$feature_names) {
+    form_set_error('feature_names', t("Please select at least one option"));
+  }
+
+  // check to make sure the types exists
+  if ($seq_type) {
+    $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 = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
+    $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $seq_type, $seq_type));
+    if (!$cvterm) {
+      form_set_error('seq_type', t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
+    }
+  }
 }
 
 function tripal_feature_delete_form_submit($form, &$form_state) {
-   global $user;
+  global $user;
 
-   $organism_id   = $form_state['values']['organism_id'];
-   $seq_type      = trim($form_state['values']['seq_type']);
-   $analysis_id   = $form_state['values']['analysis_id'];
-   $is_unique     = $form_state['values']['is_unique'];
-   $feature_names = $form_state['values']['feature_names'];
+  $organism_id   = $form_state['values']['organism_id'];
+  $seq_type      = trim($form_state['values']['seq_type']);
+  $analysis_id   = $form_state['values']['analysis_id'];
+  $is_unique     = $form_state['values']['is_unique'];
+  $feature_names = $form_state['values']['feature_names'];
 
-   $args = array($organism_id, $analysis_id, $seq_type, $is_unique, $feature_names);
+  $args = array($organism_id, $analysis_id, $seq_type, $is_unique, $feature_names);
 
-   tripal_add_job("Delete features", 'tripal_feature',
-      'tripal_feature_delete_features', $args, $user->uid);
+  tripal_add_job("Delete features", 'tripal_feature',
+    'tripal_feature_delete_features', $args, $user->uid);
 }
 
 
 function tripal_feature_delete_features($organism_id, $analysis_id, $seq_type,
-   $is_unique, $feature_names, $job = NULL) {
-
-   global $user;
-   $match = array();
-
-   // if feature names have been provided then handle that separately
-   if ($feature_names) {
-      $names = preg_split('/\s+/', $feature_names);
-      if (sizeof($names) == 1) {
-         $names = $names[0];
-      }
-      if ($is_unique) {
-         $match['uniquename'] = $names;
-      }
-      else {
-         $match['name'] = $names;
-      }
-      $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
-      print "Deleting " . $num_deletes[0]->cnt . " features\n";
-      tripal_core_chado_delete('feature', $match);
-   }
-
-   // if the user has provided an analysis_id then handle that separately
-   elseif ($analysis_id) {
-      tripal_feature_delete_by_analysis();
-   }
-   else {
-
-
-      if ($organism_id) {
-         $match['organism_id'] = $organism_id;
-      }
-      if ($seq_type) {
-         $match['type_id'] = array(
-            'name' => $seq_type,
-            'cv_id' => array(
-               'name' => 'sequence'
-            ),
-         );
-      }
-      $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
-      print "Deleting " . $num_deletes[0]->cnt . " features\n";
-      tripal_core_chado_delete('feature', $match);
-   }
-
-   print "Removing orphaned feature pages\n";
-   tripal_features_cleanup(array(), $user->uid);
+  $is_unique, $feature_names, $job = NULL) {
+
+  global $user;
+  $match = array();
+
+  // if feature names have been provided then handle that separately
+  if ($feature_names) {
+    $names = preg_split('/\s+/', $feature_names);
+    if (sizeof($names) == 1) {
+      $names = $names[0];
+    }
+    if ($is_unique) {
+      $match['uniquename'] = $names;
+    }
+    else {
+      $match['name'] = $names;
+    }
+    $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
+    print "Deleting " . $num_deletes[0]->cnt . " features\n";
+    tripal_core_chado_delete('feature', $match);
+  }
+
+  // if the user has provided an analysis_id then handle that separately
+  elseif ($analysis_id) {
+    tripal_feature_delete_by_analysis();
+  }
+  else {
+
+    if ($organism_id) {
+      $match['organism_id'] = $organism_id;
+    }
+    if ($seq_type) {
+      $match['type_id'] = array(
+        'name' => $seq_type,
+        'cv_id' => array(
+          'name' => 'sequence'
+        ),
+      );
+    }
+    $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
+    print "Deleting " . $num_deletes[0]->cnt . " features\n";
+    tripal_core_chado_delete('feature', $match);
+  }
+
+  print "Removing orphaned feature pages\n";
+  tripal_features_cleanup(array(), $user->uid);
 }
 
 function tripal_feature_delete_by_analysis($organism_id, $analysis_id, $seq_type,
-   $is_unique, $feature_names, $job = NULL) {
+  $is_unique, $feature_names, $job = NULL) {
 
 }
 

+ 79 - 79
tripal_feature/tripal_feature-properties.inc

@@ -101,19 +101,19 @@ function tripal_feature_add_ONE_property_form($form_state, $node, $expand) {
  */
 function tripal_feature_add_ONE_property_form_validate($form, &$form_state) {
 
-   // Only Require if Adding Property
-   if ($form_state['clicked_button']['#value'] == t('Add Property') ) {
+  // Only Require if Adding Property
+  if ($form_state['clicked_button']['#value'] == t('Add Property') ) {
 
-      // Check that there is a feature
-      if ( $form_state['values']['feature_id'] <= 0 ) {
-         form_set_error('feature_id', 'There is no associated feature.');
-      }
+    // Check that there is a feature
+    if ( $form_state['values']['feature_id'] <= 0 ) {
+      form_set_error('feature_id', 'There is no associated feature.');
+    }
 
-      // Check that Selected a type
-      if ( !$form_state['values']['property']) {
-         form_set_error('property', 'Please select a type of property.');
-      }
-   }
+    // Check that Selected a type
+    if ( !$form_state['values']['property']) {
+      form_set_error('property', 'Please select a type of property.');
+    }
+  }
 }
 
 /**
@@ -122,18 +122,18 @@ function tripal_feature_add_ONE_property_form_validate($form, &$form_state) {
  * @ingroup tripal_feature
  */
 function tripal_feature_add_ONE_property_form_submit($form, &$form_state) {
-   $feature_id = $form_state['values']['feature_id'];
-   $property = $form_state['values']['property'];
-   $value = $form_state['values']['prop_value'];
-   $cv_name = $form_state['values']['cv_name'];
-
-   $succes = tripal_feature_insert_property($feature_id, $property, $value, 0, $cv_name);
-   if ($succes) {
-      drupal_set_message(t("Successfully Added Property: %property => %value", array('%property' => $property), array('%value' => $value)));
-   }
-   else {
-      drupal_set_message(t("Failed to Add Property: %property => %value", array('%property' => $property), array('%value' => $value)));
-   }
+  $feature_id = $form_state['values']['feature_id'];
+  $property = $form_state['values']['property'];
+  $value = $form_state['values']['prop_value'];
+  $cv_name = $form_state['values']['cv_name'];
+
+  $succes = tripal_feature_insert_property($feature_id, $property, $value, 0, $cv_name);
+  if ($succes) {
+    drupal_set_message(t("Successfully Added Property: %property => %value", array('%property' => $property), array('%value' => $value)));
+  }
+  else {
+    drupal_set_message(t("Failed to Add Property: %property => %value", array('%property' => $property), array('%value' => $value)));
+  }
 }
 
 /**
@@ -170,9 +170,9 @@ function tripal_feature_edit_ALL_properties_form($form_state, $node, $properties
     $prop_type_options = array();
     $columns = array('cvterm_id', 'name');
     $values = array(
-       'cv_id' => array(
-          'name' => $form['cv_name']['#value']
-       )
+      'cv_id' => array(
+        'name' => $form['cv_name']['#value']
+      )
     );
     $results = tripal_core_chado_select('cvterm', $columns, $values);
     foreach ($results as $r) {
@@ -180,30 +180,30 @@ function tripal_feature_edit_ALL_properties_form($form_state, $node, $properties
     }
 
     // iterate through all of the properties and create a set of form elements
-    foreach ($properties as $i => $property) {
-       $form["num-$i"] = array(
-          '#type' => 'fieldset',
-          '#value' => "Property $i"
-       );
-       $form["num-$i"]["id-$i"] = array(
-          '#type' => 'hidden',
-          '#value' => $property->featureprop_id
-       );
-       $default = array_search($property->type, $prop_type_options);
-       $form["num-$i"]["type-$i"] = array(
-          '#type' => 'select',
-          '#options' => $prop_type_options,
-          '#default_value' => $property->type_id->name
-       );
-       $form["num-$i"]["value-$i"] = array(
-          '#type' => 'textfield',
-          '#default_value' => $property->value
-       );
-       $form["num-$i"]["delete-$i"] = array(
-          '#type' => 'submit',
-          '#value' => t("Delete"),
-         '#name' => "delete-$i",
-       );
+  foreach ($properties as $i => $property) {
+    $form["num-$i"] = array(
+      '#type' => 'fieldset',
+      '#value' => "Property $i"
+    );
+    $form["num-$i"]["id-$i"] = array(
+      '#type' => 'hidden',
+      '#value' => $property->featureprop_id
+    );
+    $default = array_search($property->type, $prop_type_options);
+    $form["num-$i"]["type-$i"] = array(
+      '#type' => 'select',
+      '#options' => $prop_type_options,
+      '#default_value' => $property->type_id->name
+    );
+    $form["num-$i"]["value-$i"] = array(
+      '#type' => 'textfield',
+      '#default_value' => $property->value
+    );
+    $form["num-$i"]["delete-$i"] = array(
+      '#type' => 'submit',
+      '#value' => t("Delete"),
+      '#name' => "delete-$i",
+    );
     } //end of foreach property
 
     $form['num_properties'] = array(
@@ -233,38 +233,38 @@ function tripal_feature_edit_ALL_properties_form_submit($form, &$form_state) {
 
   // if the update button was clicked then do the update
   if ($form_state['clicked_button']['#value'] == t('Update All Properties') ) {
-     // iterate through each of the properties and set each one
-     for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
-       $featureprop_id = $form_state['values']["id-$i"];
-       $property = $form_state['values']["type-$i"];
-       $value = $form_state['values']["value-$i"];
-       $success = tripal_feature_update_property_by_id($featureprop_id, $property, $value, $cv_name);
-       if (!$success) {
-          drupal_set_message(t("Failed to Update Property: %property => %value", array('%property' => $property), array('%value' => $value)));
-          $all_good = 0;
-       }
-     }
-     if ($all_good) {
-        drupal_set_message("Updated all Properties");
-     }
-     drupal_goto('node/' . $form_state['values']['nid']);
+    // iterate through each of the properties and set each one
+    for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
+      $featureprop_id = $form_state['values']["id-$i"];
+      $property = $form_state['values']["type-$i"];
+      $value = $form_state['values']["value-$i"];
+      $success = tripal_feature_update_property_by_id($featureprop_id, $property, $value, $cv_name);
+      if (!$success) {
+        drupal_set_message(t("Failed to Update Property: %property => %value", array('%property' => $property), array('%value' => $value)));
+        $all_good = 0;
+      }
+    }
+    if ($all_good) {
+      drupal_set_message(t("Updated all Properties"));
+    }
+    drupal_goto('node/' . $form_state['values']['nid']);
   }
   // if the delete button was clicked then remove the property
   elseif (preg_match('/delete-(\d+)/', $form_state['clicked_button']['#name'], $matches) ) {
-     $i = $matches[1];
-     $featureprop_id = $form_state['values']["id-$i"];
-     $property = $form_state['values']["type-$i"];
-     $value = $form_state['values']["value-$i"];
-     $success = tripal_feature_delete_property_by_id($featureprop_id);
-     if ($success) {
-        drupal_set_message("Deleted Property");
-     }
-     else {
-        drupal_set_message("Unable to Delete Property");
-     }
+    $i = $matches[1];
+    $featureprop_id = $form_state['values']["id-$i"];
+    $property = $form_state['values']["type-$i"];
+    $value = $form_state['values']["value-$i"];
+    $success = tripal_feature_delete_property_by_id($featureprop_id);
+    if ($success) {
+      drupal_set_message(t("Deleted Property"));
+    }
+    else {
+      drupal_set_message(t("Unable to Delete Property"));
+    }
   }
   else {
-    drupal_set_message("Unrecognized Button Pressed", 'error');
+    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
   }
 }
 /**
@@ -275,7 +275,7 @@ function tripal_feature_edit_ALL_properties_form_submit($form, &$form_state) {
 function theme_tripal_feature_edit_ALL_properties_form($form) {
   $output = '';
 
-  $output .= '<br><fieldset>';
+  $output .= '<br /><fieldset>';
   $output .= '<legend>Edit Already Existing Properties<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing properties for this feature, one property per line. The type refers to the type of '
          .'property and the value is the value for that property. </p>';
@@ -289,7 +289,7 @@ function theme_tripal_feature_edit_ALL_properties_form($form) {
     }
   }
 
-  $output .= '</table><br>';
+  $output .= '</table><br />';
   $output .= drupal_render($form);
   $output .= '</fieldset>';
 

+ 110 - 112
tripal_feature/tripal_feature-relationships.inc

@@ -12,13 +12,13 @@
 function tripal_feature_add_ALL_relationships_page($node) {
   $output = '';
 
-  $output .= tripal_feature_implement_add_chado_properties_progress('relationships') . '<br>';
-  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->uniquename . ')</b><br>';
-  $output .= '<br><b>Current Relationships</b><br>';
+  $output .= tripal_feature_implement_add_chado_properties_progress('relationships') . '<br />';
+  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->uniquename . ')</b><br />';
+  $output .= '<br /><b>Current Relationships</b><br />';
   $output .= list_relationships_for_node($node->uniquename, $node->subject_relationships, $node->object_relationships);
-  $output .= '<br><br>';
+  $output .= '<br /><br />';
   $output .= drupal_get_form('tripal_feature_add_ONE_relationship_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_feature_implement_add_chado_properties_navigate', 'relationships', $node->nid);
   return $output;
 }
@@ -120,13 +120,13 @@ function tripal_feature_add_ONE_relationship_form_validate($form, &$form_state)
       for ($i=0; $i<sizeof($subject_results); $i++) {
       $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
       $message = "Too many stocks match '" . $form_state['values']['subject_id'] . "'! "
-                  . " Please refine your input to match ONLY ONE stock. <br>"
+                  . " Please refine your input to match ONLY ONE stock. <br />"
      . "To aid in this process, here are the stocks that match your initial input: "
      . join(', ', $links);
       form_set_error('subject_id', $message);
     }
     elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      form_set_error('subject_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
     }
     elseif (sizeof($subject_results) == 1) {
       $form_state['values']['subject_id'] = $subject_results[0]->stock_id;
@@ -141,13 +141,13 @@ function tripal_feature_add_ONE_relationship_form_validate($form, &$form_state)
       for ($i=0; $i<sizeof($object_results); $i++) {
       $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
       $message = "Too many stocks match '" . $form_state['values']['object_id'] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>"
+                 . "Please refine your input to match ONLY ONE stock. <br />"
                  . "To aid in this process, here are the stocks that match your initial input: "
                  . join(', ', $links);
       form_set_error('object_id', $message);
     }
     elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      form_set_error('object_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
     }
     elseif (sizeof($object_results) == 1) {
       $form_state['values']['object_id'] = $object_results[0]->stock_id;
@@ -194,7 +194,7 @@ function tripal_feature_add_ONE_relationship_form_submit($form, &$form_state) {
     );
     db_set_active($previous_db);
 
-    drupal_set_message('Successfully Added Relationship.');
+    drupal_set_message(t('Successfully Added Relationship.'));
   } //end of insert relationship
 
 }
@@ -208,9 +208,9 @@ function tripal_feature_edit_ALL_relationships_page($node) {
   $output = '';
 
   $output .= drupal_get_form('tripal_feature_edit_ALL_relationships_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_feature_add_ONE_relationship_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_feature_implement_back_to_feature_button', $node->nid);
 
   return $output;
@@ -243,93 +243,91 @@ function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
   $relationships = array_merge($orelationships, $srelationships);
 
   if (sizeof($relationships) != 0) {
-     foreach ($relationships as $r) {
-
-       $i++;
-       $form["num-$i"] = array(
-         '#type' => 'fieldset',
-         '#title' => t("Relationship %i", array('%i' => $i)),
-       );
-
-       $form["num-$i"]["id-$i"] = array(
-         '#type' => 'hidden',
-         '#value' => $r->stock_relationship_id
-       );
-
-       //Enter relationship specific fields
-       if ( !empty($r->subject_id) ) {
-         $default = $r->subject_uniquename;
-         $description = l($r->subject_name, 'node/' . $r->subject_nid);
-       }
-       else {
-          $default = $node->uniquename;
-          $description = "Current Feature";
-       }
-       $description .= " (" . $r->subject_type . ")";
-       $form["num-$i"]["subject_id-$i"] = array(
-         '#type' => 'textfield',
-         //'#title' => t('Subject'),
-         '#required'   => TRUE,
-         '#size' => 30,
-         '#default_value' => $default,
-         '#description' => t('%description', array('%description' => $description)),
-       );
-
-       $cv = tripal_cv_get_cv_by_name('relationship');
-       $type_options = tripal_cv_get_cvterm_options($cv->cv_id);
-       ksort($type_options);
-       $form["num-$i"]["type_id-$i"] = array(
-         '#type' => 'select',
-         //'#title' => t('Type of Relationship'),
-         '#options' => $type_options,
-         '#required' => TRUE,
-         '#default_value' => $r->relationship_type_id
-       );
-
-       if (!empty($r->object_id) ) {
-         $default = $r->object_uniquename;
-         $description = l($r->object_name, 'node/' . $r->object_nid);
-       }
-       else {
-         $default = $node->uniquename;
-         $description = 'Current Feature';
-       }
-       $description .= " (" . $r->object_type . ")";
-       $form["num-$i"]["object_id-$i"] = array(
-         '#type' => 'textfield',
-         //'#title' => t('Object'),
-         '#required'   => TRUE,
-         '#size' => 30,
-         '#default_value' => $default,
-         '#description' => $description
-       );
-
-       $form["num-$i"]["delete-$i"] = array(
-         '#type' => 'submit',
-         '#value' => t("Delete"),
-         '#name' => "delete-$i",
-       );
-
-     } //end of foreach relationship
-     $form['num_relationships'] = array(
-       '#type' => 'hidden',
-       '#value' => $i
-     );
-
-     $form["submit-edits"] = array(
-       '#type' => 'submit',
-       '#value' => t('Update All Relationships')
-     );
+    foreach ($relationships as $r) {
+
+      $i++;
+      $form["num-$i"] = array(
+        '#type' => 'fieldset',
+        '#title' => t("Relationship %i", array('%i' => $i)),
+      );
+
+      $form["num-$i"]["id-$i"] = array(
+        '#type' => 'hidden',
+        '#value' => $r->stock_relationship_id
+      );
+
+      //Enter relationship specific fields
+      if ( !empty($r->subject_id) ) {
+        $default = $r->subject_uniquename;
+        $description = l($r->subject_name, 'node/' . $r->subject_nid);
+      }
+      else {
+        $default = $node->uniquename;
+        $description = "Current Feature";
+      }
+      $description .= " (" . $r->subject_type . ")";
+      $form["num-$i"]["subject_id-$i"] = array(
+        '#type' => 'textfield',
+        //'#title' => t('Subject'),
+        '#required'   => TRUE,
+        '#size' => 30,
+        '#default_value' => $default,
+        '#description' => t('%description', array('%description' => $description)),
+      );
+
+      $cv = tripal_cv_get_cv_by_name('relationship');
+      $type_options = tripal_cv_get_cvterm_options($cv->cv_id);
+      ksort($type_options);
+      $form["num-$i"]["type_id-$i"] = array(
+        '#type' => 'select',
+        //'#title' => t('Type of Relationship'),
+        '#options' => $type_options,
+        '#required' => TRUE,
+        '#default_value' => $r->relationship_type_id
+      );
+
+      if (!empty($r->object_id) ) {
+        $default = $r->object_uniquename;
+        $description = l($r->object_name, 'node/' . $r->object_nid);
+      }
+      else {
+        $default = $node->uniquename;
+        $description = 'Current Feature';
+      }
+      $description .= " (" . $r->object_type . ")";
+      $form["num-$i"]["object_id-$i"] = array(
+        '#type' => 'textfield',
+        //'#title' => t('Object'),
+        '#required'   => TRUE,
+        '#size' => 30,
+        '#default_value' => $default,
+        '#description' => $description
+      );
+
+      $form["num-$i"]["delete-$i"] = array(
+        '#type' => 'submit',
+        '#value' => t("Delete"),
+        '#name' => "delete-$i",
+      );
+
+    } //end of foreach relationship
+    $form['num_relationships'] = array(
+      '#type' => 'hidden',
+      '#value' => $i
+    );
+
+    $form["submit-edits"] = array(
+      '#type' => 'submit',
+      '#value' => t('Update All Relationships')
+    );
   }
   else {
-     $form["info"] = array(
-       '#type' => 'markup',
-       '#value' => t('No relationships currently exist for this feature.')
-     );
+    $form["info"] = array(
+      '#type' => 'markup',
+      '#value' => t('No relationships currently exist for this feature.')
+    );
   }
 
-
-
   return $form;
 }
 
@@ -354,13 +352,13 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
         for ($j=0; $j<sizeof($subject_results); $j++) {
         $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
         $message = "Too many stocks match '" . $form_state['values']["subject_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>"
+                 . "Please refine your input to match ONLY ONE stock. <br />"
                  . "To aid in this process, here are the stocks that match your initial input: "
                  . join(', ', $links);
         form_set_error("subject_id-$i", $message);
       }
       elseif (sizeof($subject_results) < 1) {
-        form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+        form_set_error("subject_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
       }
       elseif (sizeof($subject_results) == 1) {
         $form_state['values']["subject_id-$i"] = $subject_results[0]->stock_id;
@@ -375,13 +373,13 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
         for ($j=0; $j<sizeof($object_results); $j++) {
         $links[] = l($j+1, "node/" . $object_results[$j]->nid); }
         $message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>"
+                 . "Please refine your input to match ONLY ONE stock. <br />"
                  . "To aid in this process, here are the stocks that match your initial input: "
                  . join(', ', $links);
         form_set_error("object_id-$i", $message);
       }
       elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+        form_set_error("object_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
       }
       elseif (sizeof($object_results) == 1) {
         $form_state['values']["object_id-$i"] = $object_results[0]->stock_id;
@@ -421,33 +419,33 @@ function tripal_feature_edit_ALL_relationships_form_validate($form, &$form_state
 function tripal_feature_edit_ALL_relationships_form_submit($form, &$form_state) {
 
   if ($form_state['clicked_button']['#value'] == t('Update Relationships') ) {
-     //Update all
-     for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
+    //Update all
+    for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
 
-       //process stock textfields
-       tripal_feature_update_relationship(
+      //process stock textfields
+      tripal_feature_update_relationship(
         $form_state['values']["id-$i"],
         $form_state['values']["subject_id-$i"],
         $form_state['values']["type_id-$i"],
         $form_state['values']["object_id-$i"]
       );
-     }
-     drupal_set_message("Updated all Relationships");
-     drupal_goto('node/' . $form_state['values']['nid']);
+    }
+    drupal_set_message(t("Updated all Relationships"));
+    drupal_goto('node/' . $form_state['values']['nid']);
 
   }
   elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
 
-     $i = $matches[1];
-     tripal_feature_delete_relationship($form_state['values']["id-$i"]);
-     drupal_set_message("Deleted Relationship");
+    $i = $matches[1];
+    tripal_feature_delete_relationship($form_state['values']["id-$i"]);
+    drupal_set_message(t("Deleted Relationship"));
 
   }
   elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
     drupal_goto('node/' . $form_state['values']['nid']);
   }
   else {
-    drupal_set_message("Unrecognized Button Pressed", 'error');
+    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
   }
 
 }
@@ -495,7 +493,7 @@ function tripal_feature_delete_relationship($stock_relationship_id) {
 function theme_tripal_feature_edit_ALL_relationships_form($form) {
   $output = '';
 
-  $output .= '<br><fieldset>';
+  $output .= '<br /><fieldset>';
   $output .= '<legend>Edit Already Existing Relationships<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Each relationship for this stock is listed below, one per line. The textboxes indicating '
         .'the subject and object of the relationship can contain the uniquename, name, database '
@@ -511,7 +509,7 @@ function theme_tripal_feature_edit_ALL_relationships_form($form) {
               '<td>' . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
-  $output .= '</table><br>';
+  $output .= '</table><br />';
   $output .= drupal_render($form);
   $output .= '</fieldset>';
 

File diff suppressed because it is too large
+ 461 - 462
tripal_feature/tripal_feature.admin.inc


+ 99 - 99
tripal_feature/tripal_feature.api.inc

@@ -225,13 +225,13 @@ function tripal_feature_chado_feature_cvterm_schema() {
           'pub_id' => 'pub_id',
         ),
   );
-  
+
   return $description;
 }
 /**
-*
-* @ingroup tripal_schema_api
-*/
+ *
+ * @ingroup tripal_schema_api
+ */
 function tripal_feature_chado_feature_synonym_schema() {
   $description = array();
 
@@ -286,26 +286,26 @@ function tripal_feature_chado_feature_synonym_schema() {
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id = NUll,
-   $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
-
-   // check that the incoming arguments are correct
-   if (($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)) {
-       watchdog('tripal_feature',
-          'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
-           array(), WATCHDOG_WARNING);
-   }
-
-   // get the analysisfeature_id if one is not provided
-   if (!$analysisfeature_id) {
-      $columns = array('analysisfeature_id');
-      $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
-      $analysisfeature_id = $result[0]->analysisfeature_id;
-   }
-
-   // get the property.
-   return tripal_core_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
+  $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
+
+  // check that the incoming arguments are correct
+  if (($analysis_id and !$feature_id) or
+    (!$analysis_id and $feature_id)) {
+      watchdog('tripal_feature',
+      'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
+      array(), WATCHDOG_WARNING);
+  }
+
+  // get the analysisfeature_id if one is not provided
+  if (!$analysisfeature_id) {
+    $columns = array('analysisfeature_id');
+    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
+    $result = tripal_core_chado_select('analysisfeature', $columns, $values);
+    $analysisfeature_id = $result[0]->analysisfeature_id;
+  }
+
+  // get the property.
+  return tripal_core_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
 }
 
 /**
@@ -339,28 +339,28 @@ function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id =
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
-   $analysisfeature_id = NULL, $property, $value, $update_if_present = 0,
-   $cv_name = 'tripal') {
-
-   // check that the incoming arguments are correct
-   if (($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)) {
-       watchdog('tripal_feature',
-          'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
-           array(), WATCHDOG_WARNING);
-   }
-
-   // get the analysisfeature_id if one is not provided
-   if (!$analysisfeature_id) {
-      $columns = array('analysisfeature_id');
-      $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
-      $analysisfeature_id = $result[0]->analysisfeature_id;
-   }
-
-   // insert the property.
-   return tripal_core_insert_property('analysisfeature', $analysisfeature_id,
-      $property, $cv_name, $value, $update_if_present);
+  $analysisfeature_id = NULL, $property, $value, $update_if_present = 0,
+  $cv_name = 'tripal') {
+
+  // check that the incoming arguments are correct
+  if (($analysis_id and !$feature_id) or
+    (!$analysis_id and $feature_id)) {
+    watchdog('tripal_feature',
+      'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
+      array(), WATCHDOG_WARNING);
+  }
+
+  // get the analysisfeature_id if one is not provided
+  if (!$analysisfeature_id) {
+    $columns = array('analysisfeature_id');
+    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
+    $result = tripal_core_chado_select('analysisfeature', $columns, $values);
+    $analysisfeature_id = $result[0]->analysisfeature_id;
+  }
+
+  // insert the property.
+  return tripal_core_insert_property('analysisfeature', $analysisfeature_id,
+    $property, $cv_name, $value, $update_if_present);
 }
 
 /**
@@ -400,27 +400,27 @@ function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_i
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
-   $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
-   $cv_name = 'tripal') {
-
-   // check that the incoming arguments are correct
-   if (($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)) {
-       watchdog('tripal_feature',
-          'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
-           array(), WATCHDOG_WARNING);
-   }
-
-   // get the analysisfeature_id if one is not provided
-   if (!$analysisfeature_id) {
-      $columns = array('analysisfeature_id');
-      $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
-      $analysisfeature_id = $result[0]->analysisfeature_id;
-   }
-
-   // update the property.
-   return tripal_core_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
+  $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
+  $cv_name = 'tripal') {
+
+  // check that the incoming arguments are correct
+  if (($analysis_id and !$feature_id) or
+    (!$analysis_id and $feature_id)) {
+      watchdog('tripal_feature',
+      'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
+      array(), WATCHDOG_WARNING);
+  }
+
+  // get the analysisfeature_id if one is not provided
+  if (!$analysisfeature_id) {
+    $columns = array('analysisfeature_id');
+    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
+    $result = tripal_core_chado_select('analysisfeature', $columns, $values);
+    $analysisfeature_id = $result[0]->analysisfeature_id;
+  }
+
+  // update the property.
+  return tripal_core_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
 }
 
 /**
@@ -442,10 +442,10 @@ function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_i
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
-   $property, $value, $cv_name = 'tripal') {
+  $property, $value, $cv_name = 'tripal') {
 
-   // update the property.
-   return tripal_core_update_property_by_id('analysisfeature',
+    // update the property.
+    return tripal_core_update_property_by_id('analysisfeature',
       $analysisfeatureprop_id, $property, $cv_name, $value);
 }
 /**
@@ -481,25 +481,25 @@ function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
-   $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
-   // check that the incoming arguments are correct
-   if (($analysis_id and !$feature_id) or
-       (!$analysis_id and $feature_id)) {
-       watchdog('tripal_feature',
-          'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
-           array(), WATCHDOG_WARNING);
-   }
-
-   // get the analysisfeature_id if one is not provided
-   if (!$analysisfeature_id) {
-      $columns = array('analysisfeature_id');
-      $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-      $result = tripal_core_chado_select('analysisfeature', $columns, $values);
-      $analysisfeature_id = $result[0]->analysisfeature_id;
-   }
-
-   // get the property.
-   return tripal_core_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
+  $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
+  // check that the incoming arguments are correct
+  if (($analysis_id and !$feature_id) or
+    (!$analysis_id and $feature_id)) {
+      watchdog('tripal_feature',
+      'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
+        array(), WATCHDOG_WARNING);
+  }
+
+  // get the analysisfeature_id if one is not provided
+  if (!$analysisfeature_id) {
+    $columns = array('analysisfeature_id');
+    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
+    $result = tripal_core_chado_select('analysisfeature', $columns, $values);
+    $analysisfeature_id = $result[0]->analysisfeature_id;
+  }
+
+  // get the property.
+  return tripal_core_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
 }
 /**
  * Delete a property using the analysisfeatureprop_id
@@ -513,8 +513,8 @@ function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_i
  * @ingroup tripal_feature_api
  */
 function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id) {
-   // get the property.
-   return tripal_core_delete_property_by_id('analysisfeature', $analysisfeatureprop_id);
+  // get the property.
+  return tripal_core_delete_property_by_id('analysisfeature', $analysisfeatureprop_id);
 }
 /**
  * Retrieve properties of a given type for a given feature
@@ -533,7 +533,7 @@ function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id)
  * @ingroup tripal_feature_api
  */
 function tripal_feature_get_property($feature_id, $property, $cv_name='tripal') {
-   return tripal_core_get_property('feature', $feature_id, $property, $cv_name);
+  return tripal_core_get_property('feature', $feature_id, $property, $cv_name);
 }
 
 /**
@@ -557,9 +557,9 @@ function tripal_feature_get_property($feature_id, $property, $cv_name='tripal')
  * @ingroup tripal_feature_api
  */
 function tripal_feature_insert_property($feature_id, $property, $value,
-   $update_if_present = 0, $cv_name = 'tripal') {
-    return tripal_core_insert_property('feature', $feature_id, $property,
-       $cv_name, $value, $update_if_present);
+  $update_if_present = 0, $cv_name = 'tripal') {
+  return tripal_core_insert_property('feature', $feature_id, $property,
+    $cv_name, $value, $update_if_present);
 }
 /**
  * Update a feature property using the property name. Only use this
@@ -587,7 +587,7 @@ function tripal_feature_insert_property($feature_id, $property, $value,
  */
 function tripal_feature_update_property($feature_id, $property,
   $value, $insert_if_missing = 0, $cv_name = 'tripal') {
-   return tripal_core_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
+    return tripal_core_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
 }
 
 /**
@@ -610,7 +610,7 @@ function tripal_feature_update_property($feature_id, $property,
  */
 function tripal_feature_update_property_by_id($featureprop_id, $property,
   $value, $cv_name = 'tripal') {
-   return tripal_core_update_property_by_id('feature', $featureprop_id, $property, $cv_name, $value);
+    return tripal_core_update_property_by_id('feature', $featureprop_id, $property, $cv_name, $value);
 }
 
 /**
@@ -634,7 +634,7 @@ function tripal_feature_update_property_by_id($featureprop_id, $property,
  * @ingroup tripal_feature_api
  */
 function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal') {
-   return tripal_core_delete_property('feature', $feature_id, $property, $cv_name);
+  return tripal_core_delete_property('feature', $feature_id, $property, $cv_name);
 }
 /**
  * Delete a given feature property using the featureprop_id
@@ -648,5 +648,5 @@ function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal
  * @ingroup tripal_feature_api
  */
 function tripal_feature_delete_property_by_id($featureprop_id) {
-   return tripal_core_delete_property_by_id('feature', $featureprop_id);
+  return tripal_core_delete_property_by_id('feature', $featureprop_id);
 }

+ 21 - 0
tripal_feature/tripal_feature.coder_ignores.txt

@@ -0,0 +1,21 @@
+; The file should be formatted this way :
+; file:line:warning-type
+; where warning-type is one of security, style, sql, i18n, comment, etc.
+
+; This query selects from a non-drupal schema where the database prefixes are not
+; applied and thus the curcly brackets ({}) are not needed
+fasta_loader.php:655:sql
+fasta_loader.php:659:sql
+fasta_loader.php:672:sql
+fasta_loader.php:676:sql
+gff_loader.php:243:sql
+gff_loader.php:252:sql
+gff_loader.php:919:sql
+
+; This is a multi-line conditional that needs to be re-written to be more readable
+gff_loader.php:164:style
+gff_loader.php:165:style
+gff_loader.php:166:style
+
+; Don't need to use db_rewrite_sql() since need all nodes regardless of access control
+syncFeatures.php:425:sql

+ 146 - 146
tripal_feature/tripal_feature.install

@@ -5,173 +5,173 @@
  */
 
 /**
-*  Implementation of hook_install();
-*
-* @ingroup tripal_feature
-*/
+ * Implementation of hook_install().
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_install() {
-   // create the module's data directory
-   tripal_create_moddir('tripal_feature');
+  // create the module's data directory
+  tripal_create_moddir('tripal_feature');
 
-   // create the tables that correlate drupal nodes with chado
-   // features, organisms, etc....
-   drupal_install_schema('tripal_feature');
+  // create the tables that correlate drupal nodes with chado
+  // features, organisms, etc....
+  drupal_install_schema('tripal_feature');
 
-   // add the materialized view
-   tripal_feature_add_organism_count_mview();
+  // add the materialized view
+  tripal_feature_add_organism_count_mview();
 
 }
 /**
-*  Update for Drupal 6.x, Tripal 0.2b, Feature Module 0.2
-*  This update adjusts the materialized view by adding a 'cvterm_id' column
-*
-* @ingroup tripal_feature
-*/
+ *  Update for Drupal 6.x, Tripal 0.2b, Feature Module 0.2
+ *  This update adjusts the materialized view by adding a 'cvterm_id' column
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_update_6000() {
-   // recreate the materialized view
-   tripal_feature_add_organism_count_mview();
-   $ret = array(
-      '#finished' => 1,
-   );
+  // recreate the materialized view
+  tripal_feature_add_organism_count_mview();
+  $ret = array(
+    '#finished' => 1,
+  );
 
-   return $ret;
+  return $ret;
 }
 
 /**
-*
-* @ingroup tripal_feature
-*/
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_update_6300() {
-   // add the relationship aggregator table to the database
-   $schema = tripal_feature_get_schemas('tripal_feature_relagg');
-   $ret = array();
-   db_create_table($ret, 'tripal_feature_relagg', $schema['tripal_feature_relagg']);
+  // add the relationship aggregator table to the database
+  $schema = tripal_feature_get_schemas('tripal_feature_relagg');
+  $ret = array();
+  db_create_table($ret, 'tripal_feature_relagg', $schema['tripal_feature_relagg']);
 
-   return $ret;
+  return $ret;
 }
 /**
-*
-* @ingroup tripal_feature
-*/
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_add_organism_count_mview() {
-   $view_name = 'organism_feature_count';
-
-   // Drop the MView table if it exists
-   $mview_id = tripal_mviews_get_mview_id($view_name);
-   if ($mview_id) {
-      tripal_mviews_action("delete", $mview_id);
-   }
-
-   // Create the MView
-   tripal_add_mview(
-      // view name
-      $view_name,
-      // tripal module name
-      'tripal_feature',
-      // table name
-      $view_name,
-      // table schema definition
-      'organism_id integer, genus character varying(255), '.
-      '  species character varying(255), '.
-      '  common_name character varying(255), '.
-      '  num_features integer, cvterm_id integer, '.
-      '  feature_type character varying(255)',
-      // columns for indexing
-      'organism_id,cvterm_id,feature_type',
-      // SQL statement to populate the view
-      'SELECT O.organism_id, O.genus, O.species, O.common_name,
-          count(F.feature_id) as num_features,
-          CVT.cvterm_id, CVT.name as feature_type
-       FROM {Organism} O
-          INNER JOIN Feature F           ON O.Organism_id = F.organism_id
-          INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id
-       GROUP BY O.Organism_id, O.genus, O.species, O.common_name,
-          CVT.cvterm_id, CVT.name',
-      // special index
-      ''
-   );
-
-   // add a job to the job queue so this view gets updated automatically next
-   // time the job facility is run
-   $mview_id = tripal_mviews_get_mview_id($view_name);
-   if ($mview_id) {
-      tripal_mviews_action('update', $mview_id);
-   }
+  $view_name = 'organism_feature_count';
+
+  // Drop the MView table if it exists
+  $mview_id = tripal_mviews_get_mview_id($view_name);
+  if ($mview_id) {
+    tripal_mviews_action("delete", $mview_id);
+  }
+
+  // Create the MView
+  tripal_add_mview(
+    // view name
+    $view_name,
+    // tripal module name
+    'tripal_feature',
+    // table name
+    $view_name,
+    // table schema definition
+    'organism_id integer, genus character varying(255), '.
+    '  species character varying(255), '.
+    '  common_name character varying(255), '.
+    '  num_features integer, cvterm_id integer, '.
+    '  feature_type character varying(255)',
+    // columns for indexing
+    'organism_id,cvterm_id,feature_type',
+    // SQL statement to populate the view
+    'SELECT O.organism_id, O.genus, O.species, O.common_name,
+        count(F.feature_id) as num_features,
+        CVT.cvterm_id, CVT.name as feature_type
+     FROM {Organism} O
+        INNER JOIN Feature F           ON O.Organism_id = F.organism_id
+        INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id
+     GROUP BY O.Organism_id, O.genus, O.species, O.common_name,
+        CVT.cvterm_id, CVT.name',
+    // special index
+    ''
+  );
+
+  // add a job to the job queue so this view gets updated automatically next
+  // time the job facility is run
+  $mview_id = tripal_mviews_get_mview_id($view_name);
+  if ($mview_id) {
+    tripal_mviews_action('update', $mview_id);
+  }
 }
 /**
-* Implementation of hook_schema().
-*
-* @ingroup tripal_feature
-*/
+ * Implementation of hook_schema().
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_schema() {
-   $schema = tripal_feature_get_schemas();
-   return $schema;
+  $schema = tripal_feature_get_schemas();
+  return $schema;
 }
 /**
-* Implementation of hook_uninstall()
-*
-* @ingroup tripal_feature
-*/
+ * Implementation of hook_uninstall().
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_uninstall() {
 
-   // Drop the MView table if it exists
-   $mview_id = tripal_mviews_get_mview_id('organism_feature_count');
-   if ($mview_id) {
-      tripal_mviews_action("delete", $mview_id);
-   }
-
-   drupal_uninstall_schema('tripal_feature');
-
-   // Get the list of nodes to remove
-   $sql_feature_id = "SELECT nid, vid " .
-                 "FROM {node} " .
-                 "WHERE type='chado_feature'";
-   $result = db_query($sql_feature_id);
-   while ($node = db_fetch_object($result)) {
-      node_delete($node->nid);
-   }
+  // Drop the MView table if it exists
+  $mview_id = tripal_mviews_get_mview_id('organism_feature_count');
+  if ($mview_id) {
+    tripal_mviews_action("delete", $mview_id);
+  }
+
+  drupal_uninstall_schema('tripal_feature');
+
+  // Get the list of nodes to remove
+  $sql_feature_id = "SELECT nid, vid " .
+               "FROM {node} " .
+               "WHERE type='chado_feature'";
+  $result = db_query($sql_feature_id);
+  while ($node = db_fetch_object($result)) {
+    node_delete($node->nid);
+  }
 }
 
 /**
-* This function simply defines all tables needed for the module to work
-* correctly.  By putting the table definitions in a separate function we
-* can easily provide the entire list for hook_install or individual
-* tables for an update.
-*
-* @ingroup tripal_feature
-*/
+ * This function simply defines all tables needed for the module to work
+ * correctly.  By putting the table definitions in a separate function we
+ * can easily provide the entire list for hook_install or individual
+ * tables for an update.
+ *
+ * @ingroup tripal_feature
+ */
 function tripal_feature_get_schemas($table = NULL) {
   $schema = array();
 
 
   if (!$table or strcmp($table, 'chado_feature')==0) {
-     $schema['chado_feature'] = array(
-         'fields' => array(
-            'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-            'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-            'feature_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-            'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
-         ),
-         'indexes' => array(
-            'feature_id' => array('feature_id')
-          ),
-         'unique keys' => array(
-            'nid_vid' => array('nid', 'vid'),
-            'vid' => array('vid')
-         ),
-         'primary key' => array('nid'),
-     );
+    $schema['chado_feature'] = array(
+      'fields' => array(
+        'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'feature_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+        'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
+      ),
+      'indexes' => array(
+        'feature_id' => array('feature_id')
+      ),
+      'unique keys' => array(
+        'nid_vid' => array('nid', 'vid'),
+        'vid' => array('vid')
+      ),
+      'primary key' => array('nid'),
+    );
   }
   if (!$table or strcmp($table, 'tripal_feature_relagg')==0) {
-     $schema['tripal_feature_relagg'] = array(
-        'fields' => array(
-           'type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-           'rel_type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-        ),
-        'indexes' => array(
-           'type_id' => array('type_id')
-        ),
-     );
+    $schema['tripal_feature_relagg'] = array(
+      'fields' => array(
+        'type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+        'rel_type_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      ),
+      'indexes' => array(
+        'type_id' => array('type_id')
+      ),
+    );
   }
 
   return $schema;
@@ -184,16 +184,16 @@ function tripal_feature_get_schemas($table = NULL) {
  * @ingroup tripal_feature
  */
 function tripal_feature_requirements($phase) {
-   $requirements = array();
-   if ($phase == 'install') {
-      // make sure the core module is installed...
-      if (!function_exists('tripal_create_moddir')) {
-         $requirements ['tripal_feature'] = array(
-            'title' => "tripal_feature",
-            'value' => "error. Some required modules are just being installed. Please try again.",
-            'severity' => REQUIREMENT_ERROR,
-         );
-      }
-   }
-   return $requirements;
+  $requirements = array();
+  if ($phase == 'install') {
+    // make sure the core module is installed...
+    if (!function_exists('tripal_create_moddir')) {
+      $requirements ['tripal_feature'] = array(
+        'title' => "tripal_feature",
+        'value' => "error. Some required modules are just being installed. Please try again.",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
 }

File diff suppressed because it is too large
+ 436 - 437
tripal_feature/tripal_feature.module


+ 12 - 12
tripal_feature/tripal_feature.views.inc

@@ -38,7 +38,7 @@ function tripal_feature_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -67,7 +67,7 @@ function tripal_feature_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -88,16 +88,16 @@ function tripal_feature_views_data()  {
  * @ingroup tripal_feature_views
  */
 function tripal_feature_views_handlers() {
- return array(
-   'info' => array(
-     'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
-   ),
-   'handlers' => array(
-     'views_handler_field_residues' => array(
-       'parent' => 'views_handler_field',
-     ),
-   ),
- );
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
+    ),
+    'handlers' => array(
+    'views_handler_field_residues' => array(
+      'parent' => 'views_handler_field',
+    ),
+    ),
+  );
 }
 
 /**

+ 0 - 473
tripal_feature/tripal_feature.views.inc.orig

@@ -1,473 +0,0 @@
-<?php
-
-/**
- *  @file
- *  This file contains the basic functions for views integration of
- *  chado/tripal organism tables. Supplementary functions can be found in
- *  ./views/
- *
- *  Documentation on views integration can be found at
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/**
- * @defgroup tripal_feature_views Feature Views Integration
- * @ingroup views
- * @ingroup tripal_feature
- */
-
-/**
- * Implements hook_views_data()
- *
- * Purpose: Describe chado/tripal tables & fields to views
- *
- * @return: a data array which follows the structure outlined in the
- *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition
- *   includes basic details about the table, fields in that table and
- *   relationships between that table and others (joins)
- *
- * @ingroup tripal_feature_views
- */
-function tripal_feature_views_data()  {
-  $data = array();
-
-<<<<<<< HEAD
-  if (module_exists('tripal_views')) {
-    $tables = array(
-      'feature',
-    );
-    foreach ($tables as $tablename) {
-      if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
-        tripal_views_integration_add_entry($table_integration_array);
-      }
-    }
-
-    $tables = array(
-      'feature_cvterm',
-      'feature_cvterm_dbxref',
-      'feature_cvterm_pub',
-      'feature_cvtermprop',
-      'feature_dbxref',
-      'feature_pub',
-      'feature_pubprop',
-      'feature_relationship',
-      'feature_relationship_pub',
-      'feature_relationshipprop',
-      'feature_relationshipprop_pub',
-      'feature_synonym',
-      'featureloc',
-      'featureloc_pub',
-      'featureprop',
-      'featureprop_pub',
-      'featuremap',
-      'featuremap_pub',
-      'featurepos',
-      'featurerange'
-    );
-    foreach ($tables as $tablename) {
-      if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
-        tripal_views_integration_add_entry($table_integration_array);
-      }
-    }
-  }
-=======
-  $data = array_merge($data, retrieve_feature_views_data());
-  $data = array_merge($data, retrieve_chado_feature_views_data());
-  $data = array_merge($data, retrieve_feature_misc_tables_views_data());
->>>>>>> 6.x-0.4-dev
-
-  return $data;
-}
-
-/**
- * Implements hook_views_handlers()
- *
- * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field",
- *   "how a field should be filtered", "how a field should be sorted"
- *
- * @return: An array of handler definitions
- *
- * @ingroup tripal_feature_views
- */
-function tripal_feature_views_handlers() {
- return array(
-   'info' => array(
-     'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
-   ),
-   'handlers' => array(
-     'views_handler_field_residues' => array(
-       'parent' => 'views_handler_field',
-     ),
-   ),
- );
-}
-
-/**
- * Implementation of hook_views_data_alter().
- */
-function tripal_feature_views_data_alter(&$data) {
-
-  if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
-
-    // Add featuer relationship to node
-    $data['node']['feature_chado_nid'] = array(
-      'group' => 'Feature',
-      'title' => 'Feature Node',
-      'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
-      'real field' => 'nid',
-      'relationship' => array(
-        'handler' => 'views_handler_relationship',
-        'title' => t('Node => Chado'),
-        'label' => t('Node => Chado'),
-        'real field' => 'nid',
-        'base' => 'chado_feature',
-        'base field' => 'nid'
-      ),
-    );
-  }
-
-}
-
-/**
- *
- * @ingroup tripal_feature_views
- */
-function tripal_feature_views_default_views() {
-  $views = array();
-
-  // Main default view
-  // List all cvterms based on cv
-  $view = new view;
-  $view->name = 'all_features';
-  $view->description = 'A listing of all Sequence FEatures';
-  $view->tag = 'chado';
-  $view->view_php = '';
-  $view->base_table = 'feature';
-  $view->is_cacheable = FALSE;
-  $view->api_version = 2;
-  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
-  $handler = $view->new_display('default', 'Defaults', 'default');
-  $handler->override_option('fields', array(
-    'uniquename' => array(
-      'label' => 'Unique Name',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'uniquename',
-      'table' => 'feature',
-      'field' => 'uniquename',
-      'relationship' => 'none',
-    ),
-    'name' => array(
-      'label' => 'Name',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'name',
-      'table' => 'feature',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-    'common_name' => array(
-      'label' => 'Organism',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'common_name',
-      'table' => 'organism',
-      'field' => 'common_name',
-      'relationship' => 'none',
-    ),
-    'name_3' => array(
-      'label' => 'Type',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'exclude' => 0,
-      'id' => 'name_3',
-      'table' => 'cvterm',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-    'accession_link' => array(
-      'label' => 'External Reference',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'exclude' => 0,
-      'id' => 'accession_link',
-      'table' => 'dbxref',
-      'field' => 'accession_link',
-      'relationship' => 'none',
-    ),
-    'name_1' => array(
-      'label' => 'Library',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'name_1',
-      'table' => 'library',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-    'name_2' => array(
-      'label' => 'Analysis',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'name_2',
-      'table' => 'analysis',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-  ));
-  $handler->override_option('filters', array(
-    'common_name' => array(
-      'operator' => '=',
-      'value' => '<select organism>',
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'common_name_op',
-        'identifier' => 'organism',
-        'label' => 'Organism',
-        'optional' => 1,
-        'remember' => 0,
-      ),
-      'case' => 1,
-      'id' => 'common_name',
-      'table' => 'organism',
-      'field' => 'common_name',
-      'relationship' => 'none',
-    ),
-    'name' => array(
-      'operator' => 'contains',
-      'value' => '',
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'name_op',
-        'identifier' => 'name',
-        'label' => 'Name Contains',
-        'optional' => 1,
-        'remember' => 0,
-      ),
-      'case' => 0,
-      'id' => 'name',
-      'table' => 'feature',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-    'name_1' => array(
-      'operator' => 'contains',
-      'value' => '',
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'name_1_op',
-        'identifier' => 'library',
-        'label' => 'Library Name Contains',
-        'optional' => 1,
-        'remember' => 0,
-      ),
-      'case' => 0,
-      'id' => 'name_1',
-      'table' => 'library',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-    'name_2' => array(
-      'operator' => 'contains',
-      'value' => '',
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'name_2_op',
-        'identifier' => 'analysis',
-        'label' => 'Analysis Name Contains',
-        'optional' => 1,
-        'remember' => 0,
-      ),
-      'case' => 0,
-      'id' => 'name_2',
-      'table' => 'analysis',
-      'field' => 'name',
-      'relationship' => 'none',
-    ),
-  ));
-  $handler->override_option('access', array(
-    'type' => 'perm',
-    'perm' => 'access chado_feature content',
-  ));
-  $handler->override_option('cache', array(
-    'type' => 'none',
-  ));
-  $handler->override_option('title', 'Sequence Features');
-  $handler->override_option('empty', 'There are no features matching that criteria. Please select a different organism above.');
-  $handler->override_option('empty_format', '1');
-  $handler->override_option('items_per_page', 50);
-  $handler->override_option('style_plugin', 'table');
-  $handler = $view->new_display('page', 'Page', 'page_1');
-  $handler->override_option('path', 'features');
-  $handler->override_option('menu', array(
-    'type' => 'normal',
-    'title' => 'Sequence Features',
-    'description' => '',
-    'weight' => '0',
-    'name' => 'primary-links',
-  ));
-  $handler->override_option('tab_options', array(
-    'type' => 'none',
-    'title' => '',
-    'description' => '',
-    'weight' => 0,
-    'name' => 'navigation',
-  ));
-  $views[$view->name] = $view;
-
-  return $views;
-}

+ 1 - 1
tripal_feature/views_handlers/views_handler_field_residues.inc

@@ -24,7 +24,7 @@ class views_handler_field_residues extends views_handler_field {
 
   function render($values) {
     // add a <br> every 100 bp
-    return ereg_replace("(.{100})", "\\1<br>", $values->feature_residues);
+    return ereg_replace("(.{100})", "\\1<br />", $values->feature_residues);
 
   }
 }

+ 2 - 2
tripal_genetic/tripal_genetic.module

@@ -18,9 +18,9 @@ require('tripal_genetic.api.inc');
  *  views integration code is
  */
 function tripal_genetic_views_api() {
-   return array(
+  return array(
       'api' => 2.0,
-   );
+  );
 }
 
 function tripal_genetic_theme() {

+ 8 - 8
tripal_genetic/tripal_genetic.views.inc

@@ -31,20 +31,20 @@ function tripal_genetic_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
 
     $tables = array(
       'environment_cvterm',
-      'feautre_genotype',
+      'feature_genotype',
       'phendesc',
       'phenotype_comparison'
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -62,12 +62,12 @@ function tripal_genetic_views_data()  {
  * @return: An array of handler definitions
  */
 function tripal_genetic_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_genetic') . '/views/handlers',
-   ),
+  ),
    'handlers' => array(
 
-   ),
- );
-}
+  ),
+  );
+}

+ 12 - 7
tripal_library/reindex.php

@@ -1,19 +1,24 @@
 <?php
+
+/**
+ * @file
+ * @todo Add file header description
+ */
+
+
 //
 // Copyright 2009 Clemson University
 //
 
 
-/* 
-
-This script must be run at the base directory level of the drupal installation 
-in order to pick up all necessary dependencies 
-
-*/
+/*
+ This script must be run at the base directory level of the drupal installation
+ in order to pick up all necessary dependencies
+ */
 
 require_once './includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
 jlibrary_feature_reindex($argv[1]);
 
-?>
+

+ 11 - 7
tripal_library/taxonify.php

@@ -1,18 +1,22 @@
 <?php
+
+/**
+ * @file
+ * @todo Add file header description
+ */
+
 //
 // Copyright 2009 Clemson University
 //
 
-/* 
-
-This script must be run at the base directory level of the drupal installation 
-in order to pick up all necessary dependencies 
-
-*/
+/*
+ This script must be run at the base directory level of the drupal installation
+ in order to pick up all necessary dependencies
+ */
 
 require_once './includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
 jlibrary_feature_set_taxonomy($argv[1]);
 
-?>
+

+ 4 - 4
tripal_library/tripal_library.api.inc

@@ -128,7 +128,7 @@ function tripal_library_chado_libraryprop_schema() {
  * @ingroup tripal_library_api
  */
 function tripal_library_get_property($library_id, $property) {
-   return tripal_core_get_property('library', $library_id, $property, 'tripal');
+  return tripal_core_get_property('library', $library_id, $property, 'tripal');
 }
 
 /**
@@ -149,7 +149,7 @@ function tripal_library_get_property($library_id, $property) {
  * @ingroup tripal_library_api
  */
 function tripal_library_insert_property($library_id, $property, $value, $update_if_present = 0) {
-   return tripal_core_insert_property('library', $library_id, $property, 'tripal', $value, $update_if_present);
+  return tripal_core_insert_property('library', $library_id, $property, 'tripal', $value, $update_if_present);
 }
 
 /**
@@ -173,7 +173,7 @@ function tripal_library_insert_property($library_id, $property, $value, $update_
  * @ingroup tripal_library_api
  */
 function tripal_library_update_property($library_id, $property, $value, $insert_if_missing = 0) {
-   return tripal_core_update_property('library', $library_id, $property, 'tripal', $value, $insert_if_missing);
+  return tripal_core_update_property('library', $library_id, $property, 'tripal', $value, $insert_if_missing);
 }
 /**
  * Delete a given property
@@ -192,5 +192,5 @@ function tripal_library_update_property($library_id, $property, $value, $insert_
  * @ingroup tripal_library_api
  */
 function tripal_library_delete_property($library_id, $property) {
-   return tripal_core_delete_property('library', $library_id, $property, 'tripal');
+  return tripal_core_delete_property('library', $library_id, $property, 'tripal');
 }

+ 101 - 101
tripal_library/tripal_library.install

@@ -5,56 +5,56 @@
  */
 
 /**
-*  Implementation of hook_install();
-*
-* @ingroup tripal_library
-*/
+ * Implementation of hook_install().
+ *
+ * @ingroup tripal_library
+ */
 function tripal_library_install() {
-   // create the module's data directory
-   tripal_create_moddir('tripal_library');
+  // create the module's data directory
+  tripal_create_moddir('tripal_library');
 
-   // create the tables that correlate drupal nodes with chado
-   // features, librarys, etc....
-   drupal_install_schema('tripal_library');
+  // create the tables that correlate drupal nodes with chado
+  // features, librarys, etc....
+  drupal_install_schema('tripal_library');
 
-   // Insert cvterm 'library_description' into cvterm table of chado
-   // database. This CV term is used to keep track of the library
-   // description in the libraryprop table.
-   tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'), 'tripal', 0, 1, 'tripal');
+  // Insert cvterm 'library_description' into cvterm table of chado
+  // database. This CV term is used to keep track of the library
+  // description in the libraryprop table.
+  tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'), 'tripal', 0, 1, 'tripal');
 
-   // Add CVTerms for the library types
-   tripal_cv_add_cvterm(array('name' => 'cdna_library', 'def' => 'cDNA Library'), 'tripal', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'bac_library', 'def' => 'BAC Library'), 'tripal', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'fosmid_library', 'def' => 'FOSMID Library'), 'tripal', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'cosmid_library', 'def' => 'COSMID Library'), 'tripal', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'yac_library', 'def' => 'YAC Library'), 'tripal', 0, 1, 'tripal');
+  // Add CVTerms for the library types
+  tripal_cv_add_cvterm(array('name' => 'cdna_library', 'def' => 'cDNA Library'), 'tripal', 0, 1, 'tripal');
+  tripal_cv_add_cvterm(array('name' => 'bac_library', 'def' => 'BAC Library'), 'tripal', 0, 1, 'tripal');
+  tripal_cv_add_cvterm(array('name' => 'fosmid_library', 'def' => 'FOSMID Library'), 'tripal', 0, 1, 'tripal');
+  tripal_cv_add_cvterm(array('name' => 'cosmid_library', 'def' => 'COSMID Library'), 'tripal', 0, 1, 'tripal');
+  tripal_cv_add_cvterm(array('name' => 'yac_library', 'def' => 'YAC Library'), 'tripal', 0, 1, 'tripal');
 
-   // Add the materialized view needed to count the features for the library
-   // Drop the MView table if it exists
-   $previous_db = tripal_db_set_active('chado');
-   if (db_table_exists('library_feature_count')) {
-      $sql = "DROP TABLE library_feature_count";
-      db_query($sql);
-   }
-   tripal_db_set_active($previous_db);
-   // Create the MView
-   tripal_add_mview('library_feature_count', 'tripal_library',
-      'library_feature_count',
-      'library_id integer, name character varying(255), '.
-    '  num_features integer, feature_type character varying(255)',
-     'library_id',
-     'SELECT '.
-      '   L.library_id, '.
-      '   L.name, '.
-      '    count(F.feature_id) as num_features, '.
-      '    CVT.name as feature_type '.
-      'FROM {Library} L '.
-      '    INNER JOIN Library_Feature LF  ON LF.library_id = L.library_id '.
-      '    INNER JOIN Feature F           ON LF.feature_id = F.feature_id '.
-      '    INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id '.
-      'GROUP BY L.library_id, L.name, CVT.name',
-     ''
-   );
+  // Add the materialized view needed to count the features for the library
+  // Drop the MView table if it exists
+  $previous_db = tripal_db_set_active('chado');
+  if (db_table_exists('library_feature_count')) {
+    $sql = "DROP TABLE library_feature_count";
+    db_query($sql);
+  }
+  tripal_db_set_active($previous_db);
+  // Create the MView
+  tripal_add_mview('library_feature_count', 'tripal_library',
+    'library_feature_count',
+    'library_id integer, name character varying(255), '.
+  '  num_features integer, feature_type character varying(255)',
+   'library_id',
+   'SELECT '.
+    '   L.library_id, '.
+    '   L.name, '.
+    '    count(F.feature_id) as num_features, '.
+    '    CVT.name as feature_type '.
+    'FROM {Library} L '.
+    '    INNER JOIN Library_Feature LF  ON LF.library_id = L.library_id '.
+    '    INNER JOIN Feature F           ON LF.feature_id = F.feature_id '.
+    '    INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id '.
+    'GROUP BY L.library_id, L.name, CVT.name',
+   ''
+  );
 
 }
 
@@ -64,37 +64,37 @@ function tripal_library_install() {
  * @ingroup tripal_library
  */
 function tripal_library_schema() {
-   $schema = tripal_library_get_schemas();
-   return $schema;
+  $schema = tripal_library_get_schemas();
+  return $schema;
 }
 
 /**
- * Implementation of hook_uninstall()
+ * Implementation of hook_uninstall().
  *
  * @ingroup tripal_library
  */
 function tripal_library_uninstall() {
-   drupal_uninstall_schema('tripal_library');
+  drupal_uninstall_schema('tripal_library');
 
-   // remove the materialized view
-   $sql = "SELECT * FROM {tripal_mviews} ".
-          "WHERE name = 'library_feature_count'";
+  // remove the materialized view
+  $sql = "SELECT * FROM {tripal_mviews} ".
+        "WHERE name = 'library_feature_count'";
 
-   if (db_table_exists('tripal_mviews')) {
-      $mview = db_fetch_object(db_query($sql));
-      if ($mview) {
-         tripal_mviews_action('delete', $mview->mview_id);
-      }
-   }
+  if (db_table_exists('tripal_mviews')) {
+    $mview = db_fetch_object(db_query($sql));
+    if ($mview) {
+      tripal_mviews_action('delete', $mview->mview_id);
+    }
+  }
 
-   // Get the list of nodes to remove
-   $sql_lib_id = "SELECT nid, vid ".
-                 "FROM {node} ".
-                 "WHERE type='chado_library'";
-   $result = db_query($sql_lib_id);
-   while ($node = db_fetch_object($result)) {
-      node_delete($node->nid);
-   }
+  // Get the list of nodes to remove
+  $sql_lib_id = "SELECT nid, vid ".
+               "FROM {node} ".
+               "WHERE type='chado_library'";
+  $result = db_query($sql_lib_id);
+  while ($node = db_fetch_object($result)) {
+    node_delete($node->nid);
+  }
 }
 
 /**
@@ -108,33 +108,33 @@ function tripal_library_uninstall() {
 function tripal_library_get_schemas() {
   $schema = array();
   $schema['chado_library'] = array(
-      'fields' => array(
-         'vid' => array(
-            'type' => 'int',
-            'unsigned' => TRUE,
-            'not null' => TRUE,
-            'default' => 0
-         ),
-         'nid' => array(
-            'type' => 'int',
-            'unsigned' => TRUE,
-            'not null' => TRUE,
-            'default' => 0
-         ),
-         'library_id' => array(
-            'type' => 'int',
-            'not null' => TRUE,
-            'default' => 0
-         )
+    'fields' => array(
+      'vid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0
+      ),
+    'nid' => array(
+      'type' => 'int',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0
+      ),
+    'library_id' => array(
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0
+      )
       ),
-      'indexes' => array(
-         'library_id' => array('library_id')
+    'indexes' => array(
+      'library_id' => array('library_id')
       ),
-      'unique keys' => array(
-         'nid_vid' => array('nid', 'vid'),
-         'vid' => array('vid')
+    'unique keys' => array(
+      'nid_vid' => array('nid', 'vid'),
+      'vid' => array('vid')
       ),
-      'primary key' => array('nid'),
+    'primary key' => array('nid'),
   );
   return $schema;
 }
@@ -146,15 +146,15 @@ function tripal_library_get_schemas() {
  * @ingroup tripal_library
  */
 function tripal_library_requirements($phase) {
-   $requirements = array();
-   if ($phase == 'install') {
-      if (!function_exists('tripal_create_moddir')) {
-         $requirements ['tripal_library'] = array(
-            'title' => "tripal_library",
-            'value' => "error. Some required modules are just being installed. Please try again.",
-            'severity' => REQUIREMENT_ERROR,
-         );
-      }
-   }
-   return $requirements;
+  $requirements = array();
+  if ($phase == 'install') {
+    if (!function_exists('tripal_create_moddir')) {
+      $requirements ['tripal_library'] = array(
+        'title' => "tripal_library",
+        'value' => "error. Some required modules are just being installed. Please try again.",
+        'severity' => REQUIREMENT_ERROR,
+        );
+    }
+  }
+  return $requirements;
 }

File diff suppressed because it is too large
+ 531 - 531
tripal_library/tripal_library.module


+ 7 - 7
tripal_library/tripal_library.views.inc

@@ -36,7 +36,7 @@ function tripal_library_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -50,7 +50,7 @@ function tripal_library_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -69,16 +69,16 @@ function tripal_library_views_data()  {
  * @ingroup tripal_library_views
  */
 function tripal_library_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_library') . '/views/handlers',
-   ),
+      ),
    'handlers' => array(
      'views_handler_field_computed_library_nid' => array(
        'parent' => 'views_handler_field_numeric',
-     ),
-   ),
- );
+      ),
+    ),
+  );
 }
 
 /**

+ 2 - 2
tripal_natural_diversity/tripal_natural_diversity.module

@@ -18,9 +18,9 @@ require_once('tripal_natural_diversity.api.inc');
  *  views integration code is
  */
 function tripal_natural_diversity_views_api() {
-   return array(
+  return array(
       'api' => 2.0,
-   );
+  );
 }
 
 /**

+ 8 - 8
tripal_natural_diversity/tripal_natural_diversity.views.inc

@@ -32,7 +32,7 @@ function tripal_natural_diversity_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -57,7 +57,7 @@ function tripal_natural_diversity_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -75,17 +75,17 @@ function tripal_natural_diversity_views_data()  {
  * @return: An array of handler definitions
  */
 function tripal_natural_diversity_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_natural_diversity') . '/views/handlers',
-   ),
+  ),
    'handlers' => array(
   'views_handler_field_chado_relationship_all' => array(
        'parent' => 'views_handler_field_prerender_list',
-     ),
+  ),
   'views_handler_field_chado_relationship_by_type' => array(
        'parent' => 'views_handler_field_prerender_list',
-     ),
-   ),
- );
+  ),
+  ),
+  );
 }

+ 18 - 18
tripal_organism/tripal_organism.api.inc

@@ -59,18 +59,18 @@ function tripal_organism_get_organism_by_organism_id($organism_id) {
     return node_load($r->nid);
   }
   else {
-    drupal_set_message("Function: tripal_organism_get_organism_by_organism_id() -no organism with that organism id sync'd with drupal", 'error');
+    drupal_set_message(t("Function: tripal_organism_get_organism_by_organism_id() -no organism with that organism id sync'd with drupal"), 'error');
   }
 
   return 0;
 
 }
 
-/*****
+/**
  * @section Chado Table Descriptions
  * There should be a default table description for all chado tables included
  * in core.
- ****************************************************************************/
+ */
 
 /**
  * Implements hook_chado_organism_schema()
@@ -137,22 +137,22 @@ function tripal_organism_chado_organismprop_schema() {
  */
 function tripal_organism_get_synced() {
 
-   // use this SQL for getting synced organisms
-   $dsql =  "SELECT * FROM {chado_organism}";
-   $orgs = db_query($dsql);
+  // use this SQL for getting synced organisms
+  $dsql =  "SELECT * FROM {chado_organism}";
+  $orgs = db_query($dsql);
 
-   // use this SQL statement for getting the organisms
-   $csql =  "SELECT * FROM {Organism} ".
-            "WHERE organism_id = %d";
+  // use this SQL statement for getting the organisms
+  $csql =  "SELECT * FROM {Organism} ".
+          "WHERE organism_id = %d";
 
-   $org_list = array();
+  $org_list = array();
 
-   // iterate through the organisms and build an array of those that are synced
-   while ($org = db_fetch_object($orgs)) {
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      $info = db_fetch_object(db_query($csql, $org->organism_id));
-      tripal_db_set_active($previous_db);  // now use drupal database
-      $org_list[] = $info;
-   }
-   return $org_list;
+  // iterate through the organisms and build an array of those that are synced
+  while ($org = db_fetch_object($orgs)) {
+    $previous_db = tripal_db_set_active('chado');  // use chado database
+    $info = db_fetch_object(db_query($csql, $org->organism_id));
+    tripal_db_set_active($previous_db);  // now use drupal database
+    $org_list[] = $info;
+  }
+  return $org_list;
 }

+ 61 - 61
tripal_organism/tripal_organism.install

@@ -6,73 +6,73 @@
  */
 
 /**
-*  Implementation of hook_install();
-*
-* @ingroup tripal_organism
-*/
+ * Implementation of hook_install().
+ *
+ * @ingroup tripal_organism
+ */
 function tripal_organism_install() {
 
-   // create the module's data directory
-   tripal_create_moddir('tripal_organism');
+  // create the module's data directory
+  tripal_create_moddir('tripal_organism');
 
-   // create the directory where image files will be stored.  We create this
-   // here otherwise it will get created when the first organism is synced.
-   // The user that performs the syncing will receive ownership of the
-   // images directory which may not allow for write access by the web server
-   // user.  So, we create it here
-   $dest = file_directory_path() . "/tripal/tripal_organism/images";
-   file_check_directory($dest, FILE_CREATE_DIRECTORY);
+  // create the directory where image files will be stored.  We create this
+  // here otherwise it will get created when the first organism is synced.
+  // The user that performs the syncing will receive ownership of the
+  // images directory which may not allow for write access by the web server
+  // user.  So, we create it here
+  $dest = file_directory_path() . "/tripal/tripal_organism/images";
+  file_check_directory($dest, FILE_CREATE_DIRECTORY);
 
-   // create the tables that correlate drupal nodes with chado
-   // features, organisms, etc....
-   drupal_install_schema('tripal_organism');
+  // create the tables that correlate drupal nodes with chado
+  // features, organisms, etc....
+  drupal_install_schema('tripal_organism');
 
 }
 
 /**
-* Implementation of hook_schema().
-*
-* @ingroup tripal_organism
-*/
+ * Implementation of hook_schema().
+ *
+ * @ingroup tripal_organism
+ */
 function tripal_organism_schema() {
-   $schema = tripal_organism_get_schemas();
+  $schema = tripal_organism_get_schemas();
   return $schema;
 }
 
 /**
-* Implementation of hook_uninstall()
-*
-* @ingroup tripal_organism
-*/
+ * Implementation of hook_uninstall().
+ *
+ * @ingroup tripal_organism
+ */
 function tripal_organism_uninstall() {
-   drupal_uninstall_schema('tripal_organism');
+  drupal_uninstall_schema('tripal_organism');
 
-   // Get the list of nodes to remove
-   $sql_lib_id = "SELECT nid, vid ".
-                 "FROM {node} ".
-                 "WHERE type='chado_organism'";
-   $result = db_query($sql_lib_id);
-   while ($node = db_fetch_object($result)) {
-      node_delete($node->nid);
-   }
+  // Get the list of nodes to remove
+  $sql_lib_id = "SELECT nid, vid ".
+               "FROM {node} ".
+               "WHERE type='chado_organism'";
+  $result = db_query($sql_lib_id);
+  while ($node = db_fetch_object($result)) {
+    node_delete($node->nid);
+  }
 
-   // remove the materialized views
+  // remove the materialized views
 
-   // Remove the custom view if exists
-   if (db_table_exists('tripal_organism_views_common_name')) {
-      $sql = "DROP TABLE {tripal_organism_views_common_name}";
-      db_query($sql);
-   }
+  // Remove the custom view if exists
+  if (db_table_exists('tripal_organism_views_common_name')) {
+    $sql = "DROP TABLE {tripal_organism_views_common_name}";
+    db_query($sql);
+  }
 }
 
 /**
-* This function simply defines all tables needed for the module to work
-* correctly.  By putting the table definitions in a separate function we
-* can easily provide the entire list for hook_install or individual
-* tables for an update.
-*
-* @ingroup tripal_organism
-*/
+ * This function simply defines all tables needed for the module to work
+ * correctly.  By putting the table definitions in a separate function we
+ * can easily provide the entire list for hook_install or individual
+ * tables for an update.
+ *
+ * @ingroup tripal_organism
+ */
 function tripal_organism_get_schemas() {
   $schema = array();
 
@@ -83,18 +83,18 @@ function tripal_organism_get_schemas() {
             'unsigned' => TRUE,
             'not null' => TRUE,
             'default' => 0
-         ),
+          ),
          'nid' => array(
             'type' => 'int',
             'unsigned' => TRUE,
             'not null' => TRUE,
             'default' => 0
-         ),
+          ),
          'organism_id' => array(
             'type' => 'int',
             'not null' => TRUE,
             'default' => 0
-         )
+          )
       ),
       'indexes' => array(
          'organism_id' => array('organism_id')
@@ -115,15 +115,15 @@ function tripal_organism_get_schemas() {
  * @ingroup tripal_organism
  */
 function tripal_organism_requirements($phase) {
-   $requirements = array();
-   if ($phase == 'install') {
-      if (!function_exists('tripal_create_moddir')) {
-         $requirements ['tripal_organism'] = array(
-            'title' => "tripal_organism",
-            'value' => "error. Some required modules are just being installed. Please try again.",
-            'severity' => REQUIREMENT_ERROR,
-         );
-      }
-   }
-   return $requirements;
+  $requirements = array();
+  if ($phase == 'install') {
+    if (!function_exists('tripal_create_moddir')) {
+      $requirements ['tripal_organism'] = array(
+        'title' => "tripal_organism",
+        'value' => "error. Some required modules are just being installed. Please try again.",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
 }

File diff suppressed because it is too large
+ 442 - 441
tripal_organism/tripal_organism.module


+ 14 - 14
tripal_organism/tripal_organism.views.inc

@@ -37,7 +37,7 @@ function tripal_organism_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -49,7 +49,7 @@ function tripal_organism_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -68,19 +68,19 @@ function tripal_organism_views_data()  {
  * @ingroup tripal_organism_views
  */
 function tripal_organism_views_handlers() {
- return array(
-   'info' => array(
-     'path' => drupal_get_path('module', 'tripal_organism') . '/views/handlers',
-   ),
-   'handlers' => array(
-     'views_handler_field_computed_organism_nid' => array(
-       'parent' => 'views_handler_field_numeric',
-     ),
-     'views_handler_filter_organism_common_name' => array(
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'tripal_organism') . '/views/handlers',
+    ),
+    'handlers' => array(
+      'views_handler_field_computed_organism_nid' => array(
+        'parent' => 'views_handler_field_numeric',
+      ),
+      'views_handler_filter_organism_common_name' => array(
       'parent' => 'views_handler_filter_string',
-     ),
-   ),
- );
+    ),
+    ),
+  );
 }
 
 /**

+ 2 - 2
tripal_phenotype/tripal_phenotype.module

@@ -16,7 +16,7 @@
  *  views integration code is
  */
 function tripal_phenotype_views_api() {
-   return array(
+  return array(
       'api' => 2.0,
-   );
+  );
 }

+ 13 - 13
tripal_phenotype/tripal_phenotype.views.inc

@@ -6,17 +6,17 @@
  *  chado/tripal_phenotype tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
- 
+
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  */
@@ -29,41 +29,41 @@ function tripal_phenotype_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
-        
+
     $tables = array(
       'feature_phenotype',
       'phenotype_cvterm'
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
   }
-  
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions
  */
 function tripal_phenotype_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_phenotype') . '/views/handlers',
-   ),
+  ),
    'handlers' => array(
 
-   ),
- );
-}
+  ),
+  );
+}

+ 3 - 3
tripal_project/tripal_project.admin.inc

@@ -5,10 +5,10 @@
  */
 
 function tripal_project_administration_description_page() {
- $output = '';
+  $output = '';
 
 
- return $output;
+  return $output;
 }
 
 function tripal_project_configuration_page() {
@@ -91,7 +91,7 @@ function tripal_project_sync_all_projects() {
       $node = node_submit($new_node);
       node_save($node);
       if ($node->nid) {
-         print "Added " . $project[0]->name . " (Node ID:" . $node->nid . ")\n";
+        print "Added " . $project[0]->name . " (Node ID:" . $node->nid . ")\n";
       }
     }
     else {

+ 3 - 3
tripal_project/tripal_project.install

@@ -11,21 +11,21 @@
  */
 
 /**
- * Implementation of hook_install()
+ * Implementation of hook_install().
  */
 function tripal_project_install() {
   drupal_install_schema('tripal_project');
 }
 
 /**
- * Implementation of hook_uninstall()
+ * Implementation of hook_uninstall().
  */
 function tripal_project_uninstall() {
   drupal_uninstall_schema('tripal_project');
 }
 
 /**
- * Implementation of hook_schema()
+ * Implementation of hook_schema().
  */
 function tripal_project_schema() {
 

+ 63 - 63
tripal_project/tripal_project.module

@@ -25,9 +25,9 @@ require('tripal_project.admin.inc');
  *
  */
 function tripal_project_views_api() {
-   return array(
+  return array(
       'api' => 2.0,
-   );
+  );
 }
 
 /**
@@ -35,14 +35,14 @@ function tripal_project_views_api() {
  */
 function tripal_project_menu() {
   $items[ 'admin/tripal/tripal_project' ]= array(
-    'title' => t('Projects'),
+    'title' => 'Projects',
     'page callback' => 'tripal_project_administration_description_page',
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM
   );
 
   $items[ 'admin/tripal/tripal_project/configuration' ]= array(
-    'title' => t('Configuration'),
+    'title' => 'Configuration',
     'page callback' => 'tripal_project_configuration_page',
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM
@@ -99,10 +99,10 @@ function chado_project_access($op, $node, $account) {
   if ($op == 'update' || $op == 'delete') {
 
     if (!user_access('edit own chado_projects', $account)) {
-       return FALSE;
+      return FALSE;
     }
     if (user_access('edit own chado_projects', $account) &&
-       $account->uid != $node->uid) {
+      $account->uid != $node->uid) {
       return FALSE;
     }
   }
@@ -120,13 +120,13 @@ function chado_project_access($op, $node, $account) {
 //-----------------------------------------------------------------------------
 
 /**
-* Implementation of hook_node_info()
-*
-* This node_info, is a simple node that describes the functionallity of the module. It specifies
-* that the title(Project Name) and body(Description) set to true so that they information can be
-* entered
-*
-*/
+ * Implementation of hook_node_info().
+ *
+ * This node_info, is a simple node that describes the functionallity of the module. It specifies
+ * that the title(Project Name) and body(Description) set to true so that they information can be
+ * entered
+ *
+ */
 function tripal_project_node_info() {
   return array(
     'chado_project' => array(
@@ -142,21 +142,21 @@ function tripal_project_node_info() {
 }
 
 /**
-* Implementation of hook_form().
-*
-*  This form takes the Project Title information and description from the user.
-*
-*  @parm &$node
-*    The initialized node
-*
-*  @parm $form_state
-*    The state of the form, that has the user entered information that is neccessary for adding
-*    information to the project
-*
-*  @return $form
-*    An array as described by the Drupal Form API
-*
-*/
+ * Implementation of hook_form().
+ *
+ *  This form takes the Project Title information and description from the user.
+ *
+ *  @parm &$node
+ *    The initialized node
+ *
+ *  @parm $form_state
+ *    The state of the form, that has the user entered information that is neccessary for adding
+ *    information to the project
+ *
+ *  @return $form
+ *    An array as described by the Drupal Form API
+ *
+ */
 function chado_project_form(&$node, $form_state) {
 
   $type = node_get_types('type', $node);
@@ -193,23 +193,23 @@ function chado_project_form(&$node, $form_state) {
 }
 
 /**
-* Implementation of hook_insert()
-*
-*  @parm $node
-*    Then node that has the information stored within, accessed given the nid
-*
-*/
+ * Implementation of hook_insert().
+ *
+ *  @parm $node
+ *    Then node that has the information stored within, accessed given the nid
+ *
+ */
 function chado_project_insert($node) {
 
   $values =  array(
      'name' => $node->title,
      'description' => $node->description,
-   );
+  );
 
-   if (!$node->project_id) {
+  if (!$node->project_id) {
      //inserts info into chado table.
-     $result = tripal_core_chado_insert('project', $values);
-     $node->project_id = $result['project_id'];
+  $result = tripal_core_chado_insert('project', $values);
+  $node->project_id = $result['project_id'];
   }
 
   //inserts the row of vid,nid,project_id into the chado_project table
@@ -218,21 +218,21 @@ function chado_project_insert($node) {
 }
 
 /**
-*
-* Implementation of hook_delete().
-*
-* @param $node
-* The node which is to be deleted, only chado project and chado_project need to be dealt with
-* since the drupal node is deleted automagically
-*
-*/
+ *
+ * Implementation of hook_delete().
+ *
+ * @param $node
+ * The node which is to be deleted, only chado project and chado_project need to be dealt with
+ * since the drupal node is deleted automagically
+ *
+ */
 function chado_project_delete($node) {
   // Notice that we're matching all revision, by using the node's nid.
 
   // Find the project to delete
   $values =  array(
      'project_id' => $node->project->project_id,
-   );
+  );
   tripal_core_chado_delete('project', $values);
 
   //deleteing in drupal chado_project table
@@ -241,13 +241,13 @@ function chado_project_delete($node) {
 }
 
 /**
-* Implements hook_update()
-*
-* @param $node
-*  The node which is to have its containing information updated when the user modifies information
-*  pertaining to the specific project
-*
-*/
+ * Implements hook_update().
+ *
+ * @param $node
+ *  The node which is to have its containing information updated when the user modifies information
+ *  pertaining to the specific project
+ *
+ */
 function chado_project_update($node) {
 
   // Find the project to update
@@ -266,15 +266,15 @@ function chado_project_update($node) {
 }
 
 /**
-* Implementation of node_load().
-*
-* @param $node
-*   The node that is to have its containing information loaded
-*
-* @return $node
-*   The node, containing the loaded project with the current nid
-*
-*/
+ * Implementation of node_load().
+ *
+ * @param $node
+ *   The node that is to have its containing information loaded
+ *
+ * @return $node
+ *   The node, containing the loaded project with the current nid
+ *
+ */
 function chado_project_load($node) {
 
   //selecting the coresponding table information

+ 7 - 7
tripal_project/tripal_project.views.inc

@@ -29,7 +29,7 @@ function tripal_project_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -38,7 +38,7 @@ function tripal_project_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -56,12 +56,12 @@ function tripal_project_views_data()  {
  * @return: An array of handler definitions
  */
 function tripal_project_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_project') . '/views/handlers',
-   ),
+  ),
    'handlers' => array(
 
-   ),
- );
-}
+  ),
+  );
+}

+ 5 - 6
tripal_pub/tripal_pub.install

@@ -12,7 +12,7 @@
 
 
 /**
- * Implementation of hook_install()
+ * Implementation of hook_install().
  */
 function tripal_pub_install() {
 
@@ -20,14 +20,13 @@ function tripal_pub_install() {
   $dbxref = array('accession' => 'abstract', 'db_id' => array('name' => 'tripal'));
   $success = tripal_core_chado_insert('dbxref', $dbxref);
   if ($success) {
-    tripal_core_chado_insert('cvterm', array('name' => 'abstract', 'cv_id' => array('name' => 'tripal'), 'db
-xref_id' => $dbxref));
+    tripal_core_chado_insert('cvterm', array('name' => 'abstract', 'cv_id' => array('name' => 'tripal'), 'dbxref_id' => $dbxref));
   }
 }
 
 
 /**
- * Implementation of hook_uninstall()
+ * Implementation of hook_uninstall().
  */
 function tripal_pub_uninstall() {
   //Remove tables
@@ -37,7 +36,7 @@ function tripal_pub_uninstall() {
 
 
 /**
- * Implementation of hook_schema()
+ * Implementation of hook_schema().
  */
 function tripal_pub_schema() {
 //specification for 'tripal_pub_instances'
@@ -78,7 +77,7 @@ function tripal_pub_schema() {
         'default' => '',
         'description' => 'The Author Name.',
       ),
-     ),
+      ),
      //end of shema
 
     'primary key' => array('nid'),

File diff suppressed because it is too large
+ 483 - 491
tripal_pub/tripal_pub.module


+ 13 - 13
tripal_pub/tripal_pub.views.inc

@@ -6,17 +6,17 @@
  *  chado/tripal_pub tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
- 
+
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  */
@@ -29,11 +29,11 @@ function tripal_pub_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
-        
+
     $tables = array(
       'pub_dbxref',
       'pub_relationship',
@@ -42,30 +42,30 @@ function tripal_pub_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
   }
-  
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions
  */
 function tripal_pub_views_handlers() {
- return array(
+  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'tripal_pub') . '/views/handlers',
-   ),
+    ),
    'handlers' => array(
 
-   ),
- );
-}
+    ),
+  );
+}

+ 8 - 0
tripal_search/tripal_search.coder_ignores.txt

@@ -0,0 +1,8 @@
+; The file should be formatted this way :
+; file:line:warning-type
+; where warning-type is one of security, style, sql, i18n, comment, etc.
+
+; Can't use db placeholders in this case since the variable contains the SQL describing
+; a join and this would be sanitized if that was added through a placeholder
+tripal_search.module:126:sql
+tripal_search.module:136:sql

+ 28 - 15
tripal_search/tripal_search.module

@@ -7,15 +7,15 @@
 //
 // Copyright 2009 Clemson University
 //
-/*******************************************************************************
+/**
  * Tripal Search initiation
- ******************************************************************************/
+ */
 function tripal_search_init() {
-   // Add javascript
-   drupal_add_js(drupal_get_path('theme', 'tripal') .
+  // Add javascript
+  drupal_add_js(drupal_get_path('theme', 'tripal') .
                                   '/js/tripal_search.js');
 }
-/*******************************************************************************
+/**
  *  Tripal Search adds advanced search functions to Drupal's Search module
  */
 function tripal_search_menu() {
@@ -33,8 +33,8 @@ function tripal_search_menu() {
   return $items;
 }
 
-/*******************************************************************************
- * Implementation of hook_form_alter
+/**
+ * Implementation of hook_form_alter().
  */
 function tripal_search_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'search_form' && arg(2)) {
@@ -42,10 +42,10 @@ function tripal_search_form_alter(&$form, $form_state, $form_id) {
     $get = drupal_query_string_encode($_GET, array('q'));
     if (preg_match("/node/", arg(1))) {
       $form['basic']['inline']['fasta'] = array('#type' => 'markup',
-          '#value' => "<br><br><a id=\"tripal_search_link\" href=\"".
+          '#value' => "<br /><br /><a id=\"tripal_search_link\" href=\"".
                       url('tripal_search/'. arg(1) .'/'. urlencode(search_get_keys()),
                       array('query' => trim($get)?$get:NULL)) .
-                      "\">Download features (multi-FASTA format)</a><br><br>");
+                      "\">Download features (multi-FASTA format)</a><br /><br />");
 
     }
   }
@@ -82,12 +82,12 @@ function tripal_search_file($type, $keys, $results) {
     $sqld = "SELECT * FROM {chado_feature} CF INNER JOIN {node} N on N.nid = CF.nid WHERE CF.nid = %d";
     if ($f_objd = db_fetch_object(db_query($sqld, $result->sid))) {
 
-       // Get sequence from chado database
-       $previous_db = tripal_db_set_active('chado');  // use chado database
-       $sqlc = "SELECT * FROM {feature} WHERE feature_id = '%s'";
-       $f_objc = db_fetch_object(db_query($sqlc, $f_objd->feature_id));
-       tripal_db_set_active($previous_db);  // now use drupal database
-       print tripal_feature_return_fasta($f_objc, $desc);
+      // Get sequence from chado database
+      $previous_db = tripal_db_set_active('chado');  // use chado database
+      $sqlc = "SELECT * FROM {feature} WHERE feature_id = '%s'";
+      $f_objc = db_fetch_object(db_query($sqlc, $f_objd->feature_id));
+      tripal_db_set_active($previous_db);  // now use drupal database
+      print tripal_feature_return_fasta($f_objc, $desc);
     }
   }
 }
@@ -122,6 +122,7 @@ function tripal_do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arg
   }
 
   // Calculate maximum keyword relevance, to normalize it.
+  // @coder-ignore: can't use placeholders since variable defines a join
   $select = "SELECT SUM(i.score * t.count) AS score FROM {search_index} i " . $join . " WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d ORDER BY score DESC";
   $arguments = array_merge($arguments1, array($query[4]));
   $normalize = db_result(db_query_range($select, $arguments, 0, 1));
@@ -131,6 +132,7 @@ function tripal_do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arg
   $columns2 = str_replace('i.relevance', '('. (1.0 / $normalize) .' * SUM(i.score * t.count))', $columns2);
 
   // Build query to retrieve results.
+  // @coder-ignore: can't use placeholders since variable defines a join
   $select = "SELECT i.type, i.sid, $columns2 FROM {search_index} i " . $join . " " . $join2 . " WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d";
   $count_select =  "SELECT COUNT(*) FROM ($select) n1";
   $arguments = array_merge($arguments2, $arguments1, array($query[4]));
@@ -144,3 +146,14 @@ function tripal_do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arg
   }
   return $results;
 }
+
+/**
+ * Implements hook_coder_ignore().
+ * Defines the path to the file (tripal_search.coder_ignores.txt) where ignore rules for coder are stored
+ */
+function tripal_search_coder_ignore() {
+  return array(
+    'path' => drupal_get_path('module', 'tripal_search'),
+    'line prefix' => drupal_get_path('module', 'tripal_search'),
+  );
+}

+ 3 - 3
tripal_stock/other_module_api_functions.inc

@@ -35,11 +35,11 @@ function get_max_chado_rank($tablename, $where_options) {
     if (preg_match('/INT/', $val_array['type'])) {
       $where[] = $key . "=" . $val_array['value'];
     }
-     else {
+    else {
       if ($val_array['exact']) {
-      $operator='='; }
+        $operator='='; }
       else { $operator='~'; }
-      $where[] = $key . $operator . "'" . $val_array['value'] . "'";
+        $where[] = $key . $operator . "'" . $val_array['value'] . "'";
     }
   }
 

+ 147 - 147
tripal_stock/tripal_stock-administration.inc

@@ -17,8 +17,8 @@ function tripal_stock_module_description_page() {
 
   $text = '<h3>Tripal Stock Administrative Tools Quick Links</h3>';
     $text .= '<ul>';
-      $text .= '<li>' . l('Configuration', 'admin/tripal/tripal_stock/configuration') . '</li>';
-      $text .= '<li>' . l('Stock Listing', 'stocks') . '</li>';
+      $text .= '<li>' . l(t('Configuration'), 'admin/tripal/tripal_stock/configuration') . '</li>';
+      $text .= '<li>' . l(t('Stock Listing'), 'stocks') . '</li>';
     $text .= '</ul>';
 
   $text .= '<h3>Module Description:</h3>';
@@ -81,8 +81,8 @@ function tripal_stock_module_description_page() {
   $text .= '<p>In order to access a more flexible listing of stocks you must first install the <a href="http://drupal.org/project/views">Drupal Views2 module</a>. You should then be able to access the default views <a href="../build/views/">here</a>. Essentially, Views is a module which allows you to create custom SQL queries completely through the web interface without knowing SQL. Furthermore, it also does some formatting of the results allowing you to display them as HTML lists, tables or grids. You can also expose filters to the user to let them customize the results they see and even implement various sorting.</p>';
   $text .= '<p>To use one of the Default Views simply click "Enable" and then "Edit" to change it to show exactly what you want. To view the current listing simply clikc "View Page" at the top of the Edit user interface. There are a number of good tutorials out there for Views2, any of which can be used to help you create your own custom listings of biological content. (Note: there aren\'t any tutorials specifically for tripal content but any tutorial for Views2 will show you how to use the views interface.</p></li>';
 
-   $text .= '<h3>Page Customizations</h3>';
-   $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
+  $text .= '<h3>Page Customizations</h3>';
+  $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
              Below is a description of several methods.  These methods may be used in conjunction with one another to
              provide fine-grained control.
              <ul>
@@ -148,90 +148,90 @@ function tripal_stock_module_description_page() {
 function tripal_stock_admin() {
   $form = array();
 
-   // before proceeding check to see if we have any
-   // currently processing jobs. If so, we don't want
-   // to give the opportunity to sync Stocks
-   $active_jobs = FALSE;
-   if (tripal_get_module_active_jobs('tripal_stock')) {
-      $active_jobs = TRUE;
-   }
-   if ($active_jobs) {
-
-   $form['notice'] = array(
-         '#type' => 'fieldset',
-         '#title' => t('Stock Management Temporarily Unavailable')
-      );
-
-   $form['notice']['message'] = array(
-         '#value' => t("Currently, stock management jobs are waiting or ".
-            "are running. Managemment features have been hidden until these ".
-            "jobs complete.  Please check back later once these jobs have ".
-            "finished.  You can view the status of pending jobs in the Tripal ".
-            "jobs page."),
-      );
-
-   }
-   else {
-
-   // SET Vocabularies -----------------------------------------------------------------------------------------
-   $form['set_cv'] = array(
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync Stocks
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_stock')) {
+    $active_jobs = TRUE;
+  }
+  if ($active_jobs) {
+
+  $form['notice'] = array(
+       '#type' => 'fieldset',
+       '#title' => t('Stock Management Temporarily Unavailable')
+    );
+
+  $form['notice']['message'] = array(
+       '#value' => t("Currently, stock management jobs are waiting or ".
+          "are running. Managemment features have been hidden until these ".
+          "jobs complete.  Please check back later once these jobs have ".
+          "finished.  You can view the status of pending jobs in the Tripal ".
+          "jobs page."),
+    );
+
+  }
+  else {
+
+    // SET Vocabularies -----------------------------------------------------------------------------------------
+    $form['set_cv'] = array(
       '#type' => 'fieldset',
       '#title' => t('Set Stock Controlled Vocabularies'),
       '#weight' => -10
-   );
+    );
 
-   $form['set_cv']['message'] = array(
+    $form['set_cv']['message'] = array(
          '#value' => t("This setting allows you to set which chado controlled vocabularies (cv)"
                 ." are used. Cvs are used to control user input for the type of stock,"
           ." any properties they enter for a stock & the types of relationships"
           ." between stocks. Only cvs already loaded into chado can be selected here.")
-   );
+    );
 
-   $cv_options = tripal_cv_get_cv_options();
+    $cv_options = tripal_cv_get_cv_options();
 
-   $form['set_cv']['stock_types_cv'] = array(
+    $form['set_cv']['stock_types_cv'] = array(
      '#type' => 'select',
      '#title' => t('Controlled Vocabulary governing Stock Types'),
      '#options' => $cv_options,
      '#default_value' => variable_get('chado_stock_types_cv', 0)
-   );
+    );
 
-   $form['set_cv']['stock_prop_types_cv'] = array(
+    $form['set_cv']['stock_prop_types_cv'] = array(
      '#type' => 'select',
      '#title' => t('Controlled Vocabulary governing Types of Stock Properties'),
      '#description' => t("This cv must contain a cvterm entry where name='synonym'."),
      '#options' => $cv_options,
      '#default_value' => variable_get('chado_stock_prop_types_cv', 0)
-   );
+    );
 
-   $form['set_cv']['stock_relationship_cv'] = array(
+    $form['set_cv']['stock_relationship_cv'] = array(
      '#type' => 'select',
      '#title' => t('Controlled Vocabulary governing Types of Relationsips between Stocks'),
      '#options' => $cv_options,
      '#default_value' => variable_get('chado_stock_relationship_cv', 0)
-   );
+    );
 
-   $form['set_cv']['button'] = array(
+    $form['set_cv']['button'] = array(
       '#type' => 'submit',
       '#value' => t('Set Controlled Vacabularies')
-   );
+    );
 
-   // SYNC STOCKS-----------------------------------------------------------------------------------------------
-   $form['sync'] = array(
+    // SYNC STOCKS-----------------------------------------------------------------------------------------------
+    $form['sync'] = array(
       '#type' => 'fieldset',
       '#title' => t('Sync Stocks'),
       '#weight' => -10
-   );
+    );
 
-   $form['sync']['description'] = array(
+    $form['sync']['description'] = array(
       '#type' => 'item',
       '#value' => t("Click the 'Sync all Germplasm' button to create Drupal ".
          "content for stocks in chado. Depending on the ".
          "number of stocks in the chado database this may take a long ".
          "time to complete. ")
-   );
+    );
 
-   $form['sync']['organisms'] = array(
+    $form['sync']['organisms'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Organisms for which Stocks should be sync\'d'),
       '#description' => t('Only sync\'d Organisms are listed. Leaving an organism unchecked does not delete already sync\'d Stocks.'),
@@ -239,13 +239,13 @@ function tripal_stock_admin() {
       '#required'    => FALSE,
       '#prefix'      => '<div id="lib_boxes">',
       '#suffix'      => '</div>'
-   );
+    );
 
-   $form['sync']['button'] = array(
+    $form['sync']['button'] = array(
       '#type' => 'submit',
       '#value' => t('Sync Stocks')
-   );
-}
+    );
+  }
 
   return system_settings_form($form);
 
@@ -262,31 +262,31 @@ function tripal_stock_admin() {
  * @ingroup tripal_stock
  */
 function tripal_stock_admin_validate($form, &$form_state) {
-   global $user;  // we need access to the user info
-   $job_args = array();
-
-   // Sync Stocks
-   if ($form_state['values']['op'] == t('Sync Stocks')) {
-      // Array organism_id => organims common_name
-      //  which only includes those organisms which the user wants to select stocks for
-      $organisms_2b_syncd = $form_state['values']['organisms'];
-
-      //for each organism selected submit job (handled by tripal_stock_sync_stock_set)
-      //  which syncs all stocks with an organism_id equal to the selelcted organism
-      foreach ( $organisms_2b_syncd as $organism_id ) {
-        if ($organism_id != 0) {
-          $job_args[0] = $organism_id;
-          tripal_add_job("Sync Stocks from Organism $organism_id", 'tripal_stock',
-            'tripal_stock_sync_stock_set', $job_args, $user->uid);
-        }
+  global $user;  // we need access to the user info
+  $job_args = array();
+
+  // Sync Stocks
+  if ($form_state['values']['op'] == t('Sync Stocks')) {
+    // Array organism_id => organims common_name
+    //  which only includes those organisms which the user wants to select stocks for
+    $organisms_2b_syncd = $form_state['values']['organisms'];
+
+    //for each organism selected submit job (handled by tripal_stock_sync_stock_set)
+    //  which syncs all stocks with an organism_id equal to the selelcted organism
+    foreach ( $organisms_2b_syncd as $organism_id ) {
+      if ($organism_id != 0) {
+        $job_args[0] = $organism_id;
+        tripal_add_job("Sync Stocks from Organism $organism_id", 'tripal_stock',
+          'tripal_stock_sync_stock_set', $job_args, $user->uid);
       }
     }
+  }
 
-    if ($form_state['values']['op'] == t('Set Controlled Vacabularies')) {
-      variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
-      variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
-      variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
-    }
+  if ($form_state['values']['op'] == t('Set Controlled Vacabularies')) {
+    variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
+    variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
+    variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
+  }
 }
 
 /**
@@ -304,7 +304,7 @@ function tripal_stock_admin_validate($form, &$form_state) {
  *
  * @ingroup tripal_stock
  */
- function tripal_stock_sync_stock_set($organism_id, $job_id) {
+function tripal_stock_sync_stock_set($organism_id, $job_id) {
   global $user;
 
   if (!$organism_id) {
@@ -312,86 +312,86 @@ function tripal_stock_admin_validate($form, &$form_state) {
   }
   else {
 
-    // Get list of stocks to sync
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_query(
-       "SELECT stock_id, uniquename, type_id, organism_id FROM {stock} WHERE organism_id=%d",
-       $organism_id
+  // Get list of stocks to sync
+  $previous_db = tripal_db_set_active('chado');
+  $result = db_query(
+     "SELECT stock_id, uniquename, type_id, organism_id FROM {stock} WHERE organism_id=%d",
+      $organism_id
+  );
+  tripal_db_set_active($previous_db);
+
+  $stocks_created_count = 0; //keeps track of total number of stocks successfully created
+  $stocks_attempted = 0;
+  // foreach stock to be sync'd -> create node & add stock_id
+  while ( $r = db_fetch_object($result) ) {
+    // $r is the current stock to be sync'd
+    $stocks_attempted++;
+
+    print 'Processing ' . $r->uniquename . "... ";
+
+    // check not already in drupal
+    $in_drupal_query = db_query(
+      "SELECT * FROM {chado_stock} WHERE stock_id=%d",
+      $r->stock_id
     );
-    tripal_db_set_active($previous_db);
-
-    $stocks_created_count = 0; //keeps track of total number of stocks successfully created
-    $stocks_attempted = 0;
-    // foreach stock to be sync'd -> create node & add stock_id
-    while ( $r = db_fetch_object($result) ) {
-      // $r is the current stock to be sync'd
-      $stocks_attempted++;
-
-      print 'Processing ' . $r->uniquename . "... ";
-
-      // check not already in drupal
-      $in_drupal_query = db_query(
-        "SELECT * FROM {chado_stock} WHERE stock_id=%d",
-         $r->stock_id
-      );
-      if ( !db_fetch_object($in_drupal_query) ) {
-
-        //create new chado_stock node
-        $new_node = new stdClass();
-         $new_node->type = 'chado_stock';
-        $new_node->uid = $user->uid;
-         $new_node->title = $r->uniquename;
-         $new_node->type_id = $r->type_id;
-         $new_node->organism_id = $r->organism_id;
-         $new_node->stock_id = $r->stock_id;
-        $new_node->chado_stock_exists = TRUE;
-
-         //print 'New Node:';
-         //print_r($new_node);
-
-         node_validate($new_node);
-
-        if (!form_get_errors()) {
-          //print 'Try to Create Node ';
-          $node = node_submit($new_node);
-          node_save($node);
-          if ($node->nid) {
-            $stocks_created_count++;
-
-            //Add stock id to chado_stock table
-            /**
-             db_query(
-               "INSERT INTO chado_stock (stock_id, nid, vid) VALUES (%d, %d, %d)",
-               $r->stock_id,
-               $node->nid,
-               $node->vid
-             );
-             */
-          }
+    if ( !db_fetch_object($in_drupal_query) ) {
+
+      //create new chado_stock node
+      $new_node = new stdClass();
+      $new_node->type = 'chado_stock';
+      $new_node->uid = $user->uid;
+      $new_node->title = $r->uniquename;
+      $new_node->type_id = $r->type_id;
+      $new_node->organism_id = $r->organism_id;
+      $new_node->stock_id = $r->stock_id;
+      $new_node->chado_stock_exists = TRUE;
+
+      //print 'New Node:';
+      //print_r($new_node);
+
+      node_validate($new_node);
+
+      if (!form_get_errors()) {
+        //print 'Try to Create Node ';
+        $node = node_submit($new_node);
+        node_save($node);
+        if ($node->nid) {
+          $stocks_created_count++;
+
+          //Add stock id to chado_stock table
+          /**
+           db_query(
+             "INSERT INTO chado_stock (stock_id, nid, vid) VALUES (%d, %d, %d)",
+             $r->stock_id,
+             $node->nid,
+             $node->vid
+           );
+           */
         }
-        else {
-          print "Not completed due to errors:\nCreate Stock Form Errors: ";
-           print_r(form_get_errors());
-        }
-         print "Nid=" . $node->nid . "\n";
       }
       else {
-        print "Skipped $r->uniquename because it's already in drupal.\n";
-      } //end of if not already in drupal
-    } //end of while still stocks to be sync'd
+        print "Not completed due to errors:\nCreate Stock Form Errors: ";
+        print_r(form_get_errors());
+      }
+        print "Nid=" . $node->nid . "\n";
+    }
+    else {
+      print "Skipped $r->uniquename because it's already in drupal.\n";
+    } //end of if not already in drupal
+  } //end of while still stocks to be sync'd
   } //end of if organism_id not supplied
 
   if ($stocks_attempted == 0) {
-    print "No stocks retrieved for organism (" . $organism_id . ")\n";
+  print "No stocks retrieved for organism (" . $organism_id . ")\n";
+  return 1;
+  }
+  else {
+  if ($stocks_created_count > 0) {
+    print "$stocks_created_count Stocks Successfully Created\n";
     return 1;
   }
   else {
-    if ($stocks_created_count > 0) {
-      print "$stocks_created_count Stocks Successfully Created\n";
-      return 1;
-    }
-    else {
-      return 0;
-    }
+    return 0;
+  }
   }
 }

+ 25 - 25
tripal_stock/tripal_stock-db_references.inc

@@ -20,13 +20,13 @@
 function tripal_stock_add_ALL_dbreferences_page($node) {
   $output = '';
 
-  $output .= tripal_stock_add_chado_properties_progress('db_references') . '<br>';
-  $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br>';
-  $output .= '<br>';
+  $output .= tripal_stock_add_chado_properties_progress('db_references') . '<br />';
+  $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br />';
+  $output .= '<br />';
   $output .= theme('tripal_stock_references', $node);
-  $output .= '<br><br>';
+  $output .= '<br /><br />';
   $output .= drupal_get_form('tripal_stock_add_ONE_dbreference_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_add_chado_properties_navigate', 'db_references', $node->nid);
   return $output;
 }
@@ -182,10 +182,10 @@ function tripal_stock_add_ONE_dbreference_form_submit($form, &$form_state) {
       );
       tripal_db_set_active($previous_db);
 
-      drupal_set_message('Successfully Added Database Reference');
+      drupal_set_message(t('Successfully Added Database Reference'));
     }
     else {
-      drupal_set_message('Database reference NOT successfully created...', 'error');
+      drupal_set_message(t('Database reference NOT successfully created...'), 'error');
     } //end of if dbxref was created successfully
   } //end of if valid db reference
 
@@ -208,9 +208,9 @@ function tripal_stock_edit_ALL_dbreferences_page($node) {
   $output = '';
 
   $output .= drupal_get_form('tripal_stock_edit_ALL_db_references_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_add_ONE_dbreference_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_back_to_stock_button', $node->nid);
 
   return $output;
@@ -315,29 +315,29 @@ function tripal_stock_edit_ALL_db_references_form_submit($form, &$form_state) {
 
   if ($form_state['clicked_button']['#value'] == t('Update DB References') ) {
 
-     //Update all
-     for ($i=1; $i<=$form_state['values']['num_db_references']; $i++) {
-       tripal_stock_update_db_reference(
-          $form_state['values']["id-$i"],
-          $form_state['values']["database-$i"],
-          $form_state['values']["accession-$i"]
+       //Update all
+    for ($i=1; $i<=$form_state['values']['num_db_references']; $i++) {
+      tripal_stock_update_db_reference(
+        $form_state['values']["id-$i"],
+        $form_state['values']["database-$i"],
+        $form_state['values']["accession-$i"]
       );
-     }
-     drupal_set_message("Updated all Database References");
-     drupal_goto('node/' . $form_state['values']['nid']);
+    }
+      drupal_set_message(t("Updated all Database References"));
+      drupal_goto('node/' . $form_state['values']['nid']);
 
   }
   elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
 
-     $i = $matches[1];
-     tripal_stock_delete_db_reference($form_state['values']["id-$i"]);
-     drupal_set_message("Deleted Database Reference");
+    $i = $matches[1];
+    tripal_stock_delete_db_reference($form_state['values']["id-$i"]);
+    drupal_set_message(t("Deleted Database Reference"));
 
   }
   else {
-    drupal_set_message("Unrecognized Button Pressed", 'error');
-  }
+    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
 
+  }
 }
 
 /**
@@ -408,7 +408,7 @@ function tripal_stock_delete_db_reference($dbxref_id) {
 function theme_tripal_stock_edit_ALL_db_references_form($form) {
   $output = '';
 
-  $output .= '<br><fieldset>';
+  $output .= '<br /><fieldset>';
   $output .= '<legend>Edit Existing Database References<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing database references, one per line. When entering a database reference, the accession '
          .'is a unique identifier for this stock in the specified database.</p>';
@@ -422,7 +422,7 @@ function theme_tripal_stock_edit_ALL_db_references_form($form) {
          . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
-  $output .= '</table><br>';
+  $output .= '</table><br />';
   $output .= drupal_render($form);
   $output .= '</fieldset>';
 

+ 20 - 20
tripal_stock/tripal_stock-properties.inc

@@ -12,13 +12,13 @@
 function tripal_stock_add_ALL_property_page($node) {
   $output = '';
 
-  $output .= tripal_stock_add_chado_properties_progress('properties') . '<br>';
-  $output .= '<b>All Properties should strictly pertain to THE CURRENT Individual</b><br>';
-  $output .= '<br>';
+  $output .= tripal_stock_add_chado_properties_progress('properties') . '<br />';
+  $output .= '<b>All Properties should strictly pertain to THE CURRENT Individual</b><br />';
+  $output .= '<br />';
   $output .= theme('tripal_stock_properties', $node);
-  $output .= '<br><br>';
+  $output .= '<br /><br />';
   $output .= drupal_get_form('tripal_stock_add_ONE_property_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_add_chado_properties_navigate', 'properties', $node->nid);
   return $output;
 }
@@ -147,7 +147,7 @@ function tripal_stock_add_ONE_property_form_submit($form, &$form_state) {
     );
     tripal_db_set_active($previous_db);
 
-    drupal_set_message("Successfully Added Property");
+    drupal_set_message(t("Successfully Added Property"));
 
     // Set Preferred Synonym
     if ($form_state['values']['preferred_synonym'] == 1) {
@@ -178,9 +178,9 @@ function tripal_stock_edit_ALL_properties_page($node) {
   $output = '';
 
   $output .= drupal_get_form('tripal_stock_edit_ALL_properties_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_add_ONE_property_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_back_to_stock_button', $node->nid);
 
   return $output;
@@ -265,20 +265,20 @@ function tripal_stock_edit_ALL_properties_form($form_state, $node) {
 function tripal_stock_edit_ALL_properties_form_submit($form, &$form_state) {
 
   if ($form_state['clicked_button']['#value'] == t('Update Properties') ) {
-     //Update all
-     for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
-       tripal_stock_update_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"], $form_state['values']["preferred-$i"], $form_state['values']["nid"]);
-     }
-     drupal_set_message("Updated all Properties");
-     drupal_goto('node/' . $form_state['values']['nid']);
+    //Update all
+    for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
+      tripal_stock_update_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"], $form_state['values']["preferred-$i"], $form_state['values']["nid"]);
+    }
+    drupal_set_message(t("Updated all Properties"));
+    drupal_goto('node/' . $form_state['values']['nid']);
   }
   elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
-     $i = $matches[1];
-     tripal_stock_delete_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"]);
-     drupal_set_message("Deleted Property");
+    $i = $matches[1];
+    tripal_stock_delete_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"]);
+    drupal_set_message(t("Deleted Property"));
   }
   else {
-    drupal_set_message("Unrecognized Button Pressed", 'error');
+    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
   }
 
 
@@ -367,7 +367,7 @@ function tripal_stock_delete_property($stockprop_id) {
 function theme_tripal_stock_edit_ALL_properties_form($form) {
   $output = '';
 
-  $output .= '<br><fieldset>';
+  $output .= '<br /><fieldset>';
   $output .= '<legend>Edit Already Existing Properties<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing properties for this stock, one property per line. The type refers to the type of '
          .'property and the value is the value for that property. For example, if this stock has a seed coat colour of green then '
@@ -380,7 +380,7 @@ function theme_tripal_stock_edit_ALL_properties_form($form) {
     $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>' . drupal_render($form["type-$i"]) . '</td><td>' . drupal_render($form["value-$i"]) . drupal_render($form["preferred-$i"]) . '</td><td>' . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
-  $output .= '</table><br>';
+  $output .= '</table><br />';
   $output .= drupal_render($form);
   $output .= '</fieldset>';
 

+ 29 - 29
tripal_stock/tripal_stock-relationships.inc

@@ -12,13 +12,13 @@
 function tripal_stock_add_ALL_relationships_page($node) {
   $output = '';
 
-  $output .= tripal_stock_add_chado_properties_progress('relationships') . '<br>';
-  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->stock->uniquename . ')</b><br>';
-  $output .= '<br>';
+  $output .= tripal_stock_add_chado_properties_progress('relationships') . '<br />';
+  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->stock->uniquename . ')</b><br />';
+  $output .= '<br />';
   $output .= theme('tripal_stock_relationships', $node);
-  $output .= '<br><br>';
+  $output .= '<br /><br />';
   $output .= drupal_get_form('tripal_stock_add_ONE_relationship_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_add_chado_properties_navigate', 'relationships', $node->nid);
   return $output;
 }
@@ -115,13 +115,13 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
       for ($i=0; $i<sizeof($subject_results); $i++) {
       $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
       $message = "Too many stocks match '" . $form_state['values']['subject_id'] . "'! "
-                  . " Please refine your input to match ONLY ONE stock. <br>"
+                  . " Please refine your input to match ONLY ONE stock. <br />"
      . "To aid in this process, here are the stocks that match your initial input: "
      . join(', ', $links);
       form_set_error('subject_id', $message);
     }
     elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      form_set_error('subject_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
     }
     elseif (sizeof($subject_results) == 1) {
       $form_state['values']['subject_id'] = $subject_results[0]->stock->stock_id;
@@ -134,13 +134,13 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
       for ($i=0; $i<sizeof($object_results); $i++) {
       $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
       $message = "Too many stocks match '" . $form_state['values']['object_id'] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>"
+                 . "Please refine your input to match ONLY ONE stock. <br />"
                  . "To aid in this process, here are the stocks that match your initial input: "
                  . join(', ', $links);
       form_set_error('object_id', $message);
     }
     elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      form_set_error('object_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
     }
     elseif (sizeof($object_results) == 1) {
       $form_state['values']['object_id'] = $object_results[0]->stock->stock_id;
@@ -187,7 +187,7 @@ function tripal_stock_add_ONE_relationship_form_submit($form, &$form_state) {
     );
     tripal_db_set_active($previous_db);
 
-    drupal_set_message('Successfully Added Relationship.');
+    drupal_set_message(t('Successfully Added Relationship.'));
   } //end of insert relationship
 
 }
@@ -201,9 +201,9 @@ function tripal_stock_edit_ALL_relationships_page($node) {
   $output = '';
 
   $output .= drupal_get_form('tripal_stock_edit_ALL_relationships_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_add_ONE_relationship_form', $node);
-  $output .= '<br>';
+  $output .= '<br />';
   $output .= drupal_get_form('tripal_stock_back_to_stock_button', $node->nid);
 
   return $output;
@@ -343,13 +343,13 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
         for ($j=0; $j<sizeof($subject_results); $j++) {
         $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
         $message = "Too many stocks match '" . $form_state['values']["subject_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>"
+                 . "Please refine your input to match ONLY ONE stock. <br />"
                  . "To aid in this process, here are the stocks that match your initial input: "
                  . join(', ', $links);
         form_set_error("subject_id-$i", $message);
       }
       elseif (sizeof($subject_results) < 1) {
-        form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+        form_set_error("subject_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
       }
       elseif (sizeof($subject_results) == 1) {
         $form_state['values']["subject_id-$i"] = $subject_results[0]->stock->stock_id;
@@ -362,13 +362,13 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
         for ($j=0; $j<sizeof($object_results); $j++) {
         $links[] = l($j+1, "node/" . $object_results[$j]->nid); }
         $message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>"
+                 . "Please refine your input to match ONLY ONE stock. <br />"
                  . "To aid in this process, here are the stocks that match your initial input: "
                  . join(', ', $links);
         form_set_error("object_id-$i", $message);
       }
       elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+        form_set_error("object_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock %link", array('%link' => l(t('here'), 'stocks'))));
       }
       elseif (sizeof($object_results) == 1) {
         $form_state['values']["object_id-$i"] = $object_results[0]->stock->stock_id;
@@ -408,33 +408,33 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
 function tripal_stock_edit_ALL_relationships_form_submit($form, &$form_state) {
 
   if ($form_state['clicked_button']['#value'] == t('Update Relationships') ) {
-     //Update all
-     for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
+    //Update all
+    for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
 
-       //process stock textfields
-       tripal_stock_update_relationship(
+      //process stock textfields
+      tripal_stock_update_relationship(
         $form_state['values']["id-$i"],
         $form_state['values']["subject_id-$i"],
         $form_state['values']["type_id-$i"],
         $form_state['values']["object_id-$i"]
       );
-     }
-     drupal_set_message("Updated all Relationships");
-     drupal_goto('node/' . $form_state['values']['nid']);
+    }
+    drupal_set_message(t("Updated all Relationships"));
+    drupal_goto('node/' . $form_state['values']['nid']);
 
   }
   elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
 
-     $i = $matches[1];
-     tripal_stock_delete_relationship($form_state['values']["id-$i"]);
-     drupal_set_message("Deleted Relationship");
+    $i = $matches[1];
+    tripal_stock_delete_relationship($form_state['values']["id-$i"]);
+    drupal_set_message(t("Deleted Relationship"));
 
   }
   elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
     drupal_goto('node/' . $form_state['values']['nid']);
   }
   else {
-    drupal_set_message("Unrecognized Button Pressed", 'error');
+    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
   }
 
 }
@@ -482,7 +482,7 @@ function tripal_stock_delete_relationship($stock_relationship_id) {
 function theme_tripal_stock_edit_ALL_relationships_form($form) {
   $output = '';
 
-  $output .= '<br><fieldset>';
+  $output .= '<br /><fieldset>';
   $output .= '<legend>Edit Already Existing Relationships<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Each relationship for this stock is listed below, one per line. The textboxes indicating '
         . 'the subject and object of the relationship can contain the uniquename, name, database '
@@ -498,7 +498,7 @@ function theme_tripal_stock_edit_ALL_relationships_form($form) {
          . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
-  $output .= '</table><br>';
+  $output .= '</table><br />';
   $output .= drupal_render($form);
   $output .= '</fieldset>';
 

+ 10 - 3
tripal_stock/tripal_stock.install

@@ -6,12 +6,17 @@
  * @file
  */
 
-/** Implementation of hook_install() */
+/**
+ * Implementation of hook_install().
+ */
 function tripal_stock_install() {
   drupal_install_schema('tripal_stock');
 }
 
-/** Implementation of hook_uninstall() */
+/**
+ * Implementation of hook_uninstall().
+ */
+
 function tripal_stock_uninstall() {
   drupal_uninstall_schema('tripal_stock');
 
@@ -28,7 +33,9 @@ function tripal_stock_uninstall() {
 
 }
 
-/** Implementation of hook_schema() */
+/**
+ * Implementation of hook_schema().
+ */
 function tripal_stock_schema() {
   $schema['chado_stock'] = array(
     'fields' => array(

+ 92 - 92
tripal_stock/tripal_stock.module

@@ -44,16 +44,16 @@ function tripal_stock_menu() {
 
   //Administrative settings menu-----------------
   $items['admin/tripal/tripal_stock'] = array(
-    'title' => t('Stocks'),
-    'description' => t('Basic Description of Tripal Stock Module Functionality'),
+    'title' => 'Stocks',
+    'description' => 'Basic Description of Tripal Stock Module Functionality',
     'page callback' => 'tripal_stock_module_description_page',
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM
   );
 
   $items['admin/tripal/tripal_stock/configuration'] = array(
-    'title' => t('Configuration'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Configuration',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_stock_admin'),
     'access arguments' => array('administer site configuration'),
@@ -63,7 +63,7 @@ function tripal_stock_menu() {
   //Displaying stocks----------------------------
   $items['stocks'] = array(
     'menu_name' => ('primary-links'),
-    'title' => t('Stocks'),
+    'title' => 'Stocks',
     'page callback' => 'tripal_stock_show_stocks',
     'access arguments' => array('access chado_stock content'),
     'type' => MENU_NORMAL_ITEM,
@@ -71,8 +71,8 @@ function tripal_stock_menu() {
 
   // Adding Secondary Properties-----------------
   $items['node/%cs_node/properties'] = array(
-    'title' => t('Add Properties & Synonyms'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Add Properties & Synonyms',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'tripal_stock_add_ALL_property_page',
     'page arguments' => array(1),
     'access arguments' => array('create chado_stock content'),
@@ -80,8 +80,8 @@ function tripal_stock_menu() {
   );
 
   $items['node/%cs_node/db_references'] = array(
-    'title' => t('Add Database References'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Add Database References',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'tripal_stock_add_ALL_dbreferences_page',
     'page arguments' => array(1),
     'access arguments' => array('create chado_stock content'),
@@ -89,8 +89,8 @@ function tripal_stock_menu() {
   );
 
   $items['node/%cs_node/relationships'] = array(
-    'title' => t('Add Relationships'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Add Relationships',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'tripal_stock_add_ALL_relationships_page',
     'page arguments' => array(1),
     'access arguments' => array('create chado_stock content'),
@@ -99,8 +99,8 @@ function tripal_stock_menu() {
 
   //Edit/Deleting Secondary Properties-------------
   $items['node/%cs_node/edit_properties'] = array(
-    'title' => t('Edit Properties'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Edit Properties',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'tripal_stock_edit_ALL_properties_page',
     'page arguments' => array(1),
     'access arguments' => array('edit chado_stock content'),
@@ -109,8 +109,8 @@ function tripal_stock_menu() {
   );
 
     $items['node/%cs_node/edit_relationships'] = array(
-    'title' => t('Edit Relationships'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Edit Relationships',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'tripal_stock_edit_ALL_relationships_page',
     'page arguments' => array(1),
     'access arguments' => array('edit chado_stock content'),
@@ -119,8 +119,8 @@ function tripal_stock_menu() {
   );
 
   $items['node/%cs_node/edit_db_references'] = array(
-    'title' => t('Edit DB References'),
-    'description' => t('Settings for Chado Stocks'),
+    'title' => 'Edit DB References',
+    'description' => 'Settings for Chado Stocks',
     'page callback' => 'tripal_stock_edit_ALL_dbreferences_page',
     'page arguments' => array(1),
     'access arguments' => array('edit chado_stock content'),
@@ -158,7 +158,7 @@ function cs_node_load($nid) {
 }
 
 /**
- * Implementation of hook_perm()
+ * Implementation of hook_perm().
  *
  * Purpose: Set the permission types that the chado stock module uses
  *
@@ -192,27 +192,27 @@ function tripal_stock_perm() {
  * @ingroup tripal_stock
  */
 function chado_stock_access($op, $node, $account) {
-   if ($op == 'create') {
-      if (!user_access('create chado_stock content', $account)) {
-        return FALSE;
-      }
-   }
-   if ($op == 'update') {
-      if (!user_access('edit chado_stock content', $account)) {
-         return FALSE;
-      }
-   }
-   if ($op == 'delete') {
-      if (!user_access('delete chado_stock content', $account)) {
-         return FALSE;
-      }
-   }
-   if ($op == 'view') {
-      if (!user_access('access chado_stock content', $account)) {
-         return FALSE;
-      }
-   }
-   return NULL;
+  if ($op == 'create') {
+    if (!user_access('create chado_stock content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_stock content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_stock content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_stock content', $account)) {
+      return FALSE;
+    }
+  }
+  return NULL;
 }
 
 /**
@@ -228,9 +228,9 @@ function chado_stock_access($op, $node, $account) {
  * @ingroup tripal_stock
  */
 function tripal_stock_views_api() {
-   return array(
-      'api' => 2.0,
-   );
+  return array(
+    'api' => 2.0,
+  );
 }
 
 /**
@@ -297,18 +297,18 @@ function tripal_stock_theme() {
  */
 function tripal_stock_show_stocks() {
   $sql = "SELECT COUNT(stock_id) FROM {chado_stock}";
-   $no_stocks = db_result(db_query($sql));
-   if ($no_stocks != 0) {
-      $stocks = tripal_stock_get_all_stocks();
-      if ($no_stocks != count($stocks)) {
-         drupal_set_message("Synchronization needed.");
-      }
-      return theme('tripal_stock_stock_table', &$stocks);
-   }
-   else {
-      return t("No Stocks exists. Please contact administrators to " .
-               "synchronize stocks.");
-   }
+  $no_stocks = db_result(db_query($sql));
+  if ($no_stocks != 0) {
+    $stocks = tripal_stock_get_all_stocks();
+    if ($no_stocks != count($stocks)) {
+      drupal_set_message(t("Synchronization needed."));
+    }
+    return theme('tripal_stock_stock_table', &$stocks);
+  }
+  else {
+    return t("No Stocks exists. Please contact administrators to " .
+             "synchronize stocks.");
+  }
 }
 
 /**
@@ -345,7 +345,7 @@ function theme_tripal_stock_stock_table(&$stocks) {
   $output .= "</table>";
   $output .= "</div>";
 
-   return $output;
+  return $output;
 }
 
 /**
@@ -677,7 +677,7 @@ function chado_stock_insert($node) {
         $values['version'] = '1';
         $dbxref_status = tripal_core_chado_insert('dbxref', $values);
         if (!$dbxref_status) {
-          drupal_set_message('Unable to add database reference to this stock.', 'warning');
+          drupal_set_message(t('Unable to add database reference to this stock.'), 'warning');
           watchdog('tripal_stock',
             'Insert Stock: Unable to create dbxref where values:%values',
             array('%values' => print_r($values, TRUE)),
@@ -739,7 +739,7 @@ function chado_stock_insert($node) {
       }
     }
     else {
-      drupal_set_message('Error during stock creation.', 'error');
+      drupal_set_message(t('Error during stock creation.'), 'error');
       watchdog('tripal_stock',
         'Insert Stock: Unable to find newly created stock where values:%values',
         array('%values' => print_r($values, TRUE)),
@@ -749,7 +749,7 @@ function chado_stock_insert($node) {
     }
   }
   else {
-    drupal_set_message('Error during stock creation.', 'error');
+    drupal_set_message(t('Error during stock creation.'), 'error');
     watchdog('tripal_stock',
       'Insert Stock: Unable to create stock where values:%values',
       array('%values' => print_r($values, TRUE)),
@@ -820,7 +820,7 @@ function chado_stock_update($node) {
             $dbxref_mode = 'Create';
           }
           else {
-            drupal_set_message('Unable to find stock to Update', 'error');
+            drupal_set_message(t('Unable to find stock to Update'), 'error');
             watchdog(
               'tripal_stock',
               'Stock Update: Unable to find stock to update using values: %values',
@@ -863,7 +863,7 @@ function chado_stock_update($node) {
     );
 
     if (!$status) {
-      drupal_set_message('Unable to update stock', 'error');
+      drupal_set_message(t('Unable to update stock'), 'error');
       watchdog(
         'tripal_stock',
         'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
@@ -943,39 +943,39 @@ function tripal_stock_block($op = 'list', $delta = 0, $edit=array()) {
 
       return $blocks;
 
-     case 'view':
-       if (user_access('access chado_stock content') and arg(0) == 'node' and is_numeric(arg(1))) {
-        $nid = arg(1);
-        $node = node_load($nid);
-
-        $block = array();
-        switch ($delta) {
-          case 'base':
-            $block['subject'] = t('Stock Details');
-            $block['content'] = theme('tripal_stock_base', $node);
-            break;
-
-          case 'properties':
-            $block['subject'] = t('Properties');
-            $block['content'] = theme('tripal_stock_properties', $node);
-            break;
-
-          case 'references':
-            $block['subject'] = t('References');
-            $block['content'] = theme('tripal_stock_references', $node);
-            break;
-
-          case 'relationships':
-            $block['subject'] = t('Relationships');
-            $block['content'] = theme('tripal_stock_relationships', $node);
-            break;
-
-          case 'synonyms':
-            $block['subject'] = t('Synonyms');
-            $block['content'] = theme('tripal_stock_synonyms', $node);
-            break;
+    case 'view':
+      if (user_access('access chado_stock content') and arg(0) == 'node' and is_numeric(arg(1))) {
+      $nid = arg(1);
+      $node = node_load($nid);
+
+      $block = array();
+      switch ($delta) {
+        case 'base':
+          $block['subject'] = t('Stock Details');
+          $block['content'] = theme('tripal_stock_base', $node);
+          break;
+
+        case 'properties':
+          $block['subject'] = t('Properties');
+          $block['content'] = theme('tripal_stock_properties', $node);
+          break;
+
+        case 'references':
+          $block['subject'] = t('References');
+          $block['content'] = theme('tripal_stock_references', $node);
+          break;
+
+        case 'relationships':
+          $block['subject'] = t('Relationships');
+          $block['content'] = theme('tripal_stock_relationships', $node);
+          break;
+
+        case 'synonyms':
+          $block['subject'] = t('Synonyms');
+          $block['content'] = theme('tripal_stock_synonyms', $node);
+          break;
 
-        }
+      }
         return $block;
       }
   }

+ 46 - 46
tripal_stock/tripal_stock.views.inc

@@ -38,7 +38,7 @@ function tripal_stock_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -57,7 +57,7 @@ function tripal_stock_views_data()  {
     );
     foreach ($tables as $tablename) {
       if (!tripal_views_is_integrated($tablename, 10)) {
-        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
         tripal_views_integration_add_entry($table_integration_array);
       }
     }
@@ -79,46 +79,46 @@ function tripal_stock_views_data()  {
  * @ingroup tripal_stock_views
  */
 function tripal_stock_views_handlers() {
- return array(
-   'info' => array(
-     'path' => drupal_get_path('module', 'tripal_stock') . '/views/handlers',
-   ),
-   'handlers' => array(
-     'views_handler_field_computed_stock_nid' => array(
-       'parent' => 'views_handler_field_numeric',
-     ),
-     'views_handler_field_stockprop_by_type' => array(
-       'parent' => 'views_handler_field_prerender_list',
-     ),
-    'views_handler_field_stockprop_all' => array(
-       'parent' => 'views_handler_field_prerender_list',
-     ),
-    'views_handler_field_stockrel_by_type' => array(
-       'parent' => 'views_handler_field_prerender_list',
-     ),
-    'views_handler_field_stockrel_all' => array(
-       'parent' => 'views_handler_field_prerender_list',
-     ),
-    'views_handler_field_stock_dbxref_by_type' => array(
-       'parent' => 'views_handler_field_prerender_list',
-     ),
-    'views_handler_field_stock_dbxref_all' => array(
-       'parent' => 'views_handler_field_prerender_list',
-     ),
-     'views_handler_filter_stockprop_id' => array(
-       'parent' => 'views_handler_filter',
-     ),
-     'views_handler_filter_stock_dbxref_id' => array(
-       'parent' => 'views_handler_filter',
-     ),
-     'views_handler_filter_stock_relationship_id' => array(
-       'parent' => 'views_handler_filter',
-     ),
-     'views_handler_argument_stockprop_id' => array(
-       'parent' => 'views_handler_argument_string',
-     ),
-   ),
- );
+  return array(
+  'info' => array(
+    'path' => drupal_get_path('module', 'tripal_stock') . '/views/handlers',
+  ),
+  'handlers' => array(
+    'views_handler_field_computed_stock_nid' => array(
+      'parent' => 'views_handler_field_numeric',
+    ),
+  'views_handler_field_stockprop_by_type' => array(
+    'parent' => 'views_handler_field_prerender_list',
+    ),
+  'views_handler_field_stockprop_all' => array(
+    'parent' => 'views_handler_field_prerender_list',
+    ),
+  'views_handler_field_stockrel_by_type' => array(
+    'parent' => 'views_handler_field_prerender_list',
+    ),
+  'views_handler_field_stockrel_all' => array(
+    'parent' => 'views_handler_field_prerender_list',
+    ),
+  'views_handler_field_stock_dbxref_by_type' => array(
+    'parent' => 'views_handler_field_prerender_list',
+    ),
+  'views_handler_field_stock_dbxref_all' => array(
+    'parent' => 'views_handler_field_prerender_list',
+    ),
+  'views_handler_filter_stockprop_id' => array(
+    'parent' => 'views_handler_filter',
+    ),
+  'views_handler_filter_stock_dbxref_id' => array(
+    'parent' => 'views_handler_filter',
+    ),
+  'views_handler_filter_stock_relationship_id' => array(
+    'parent' => 'views_handler_filter',
+    ),
+  'views_handler_argument_stockprop_id' => array(
+    'parent' => 'views_handler_argument_string',
+    ),
+  ),
+  );
 }
 
 /**
@@ -163,7 +163,7 @@ function tripal_stock_views_pre_render  (&$view) {
   if (preg_match('/stock/', $view->base_table)) {
 
     //-----Node IDs---------------------------------------------
-    // @see file: tripal_core.views.inc function: tripal_core_add_node_ids_to_view (&$view);
+    // @see tripal_core.views.inc, tripal_core_add_node_ids_to_view()
 
     // retrieve the stock_id for each record in the views current page
     $stock_ids = array();
@@ -183,7 +183,7 @@ function tripal_stock_views_pre_render  (&$view) {
           ."WHERE stockprop.stock_id IN (" . implode(',', $stock_ids) . ")";
         $previous_db = tripal_db_set_active('chado');
         $resource = db_query($sql);
-       tripal_db_set_active($previous_db);
+        tripal_db_set_active($previous_db);
 
         $view->result[$key]->properties = array();
         while ($r = db_fetch_object($resource)) {
@@ -206,7 +206,7 @@ function tripal_stock_views_pre_render  (&$view) {
           ."OR stock_relationship.object_id IN (" . implode(',', $stock_ids) . ") ";
         $previous_db = tripal_db_set_active('chado');
         $resource = db_query($sql);
-       tripal_db_set_active($previous_db);
+        tripal_db_set_active($previous_db);
 
         while ($r = db_fetch_object($resource)) {
           if (in_array($r->subject_id, $stock_ids)) {
@@ -234,7 +234,7 @@ function tripal_stock_views_pre_render  (&$view) {
           ."WHERE stock_dbxref.stock_id IN (" . implode(',', $stock_ids) . ")";
         $previous_db = tripal_db_set_active('chado');
         $resource = db_query($sql);
-       tripal_db_set_active($previous_db);
+        tripal_db_set_active($previous_db);
 
         $view->result[$key]->dbxref = array();
         while ($r = db_fetch_object($resource)) {

+ 11 - 1
tripal_views/tripal_views.api.inc

@@ -134,7 +134,7 @@ function tripal_views_integration_add_entry($defn_array) {
     'name' => $defn_array['name'],
     'comment' => $defn_array['description'],
     'priority' => $defn_array['priority'],
-    'base_table' => ($defn_array['base_table']) ? 1 : 0,
+    'base_table' => $defn_array['base_table'],
   );
   if ($defn_array['type'] == 'mview') {
       $mview = db_fetch_object(db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table='%s'", $defn_array['table']));
@@ -153,6 +153,16 @@ function tripal_views_integration_add_entry($defn_array) {
 
   if ($status) {
 
+    // Need to update the tripal_views record so base_table can be false
+    // this is a fix because drupal_write_record() puts in defaults if !isset()
+    // and a variable is considered not set if its null!
+    db_query(
+      "UPDATE {tripal_views} SET base_table=%d WHERE table_name='%s' AND priority=%d",
+      $defn_array['base_table'],
+      $defn_array['table'],
+      $defn_array['priority']
+    );
+
     // Insert Field Definitions
     foreach ($defn_array['fields'] as $field) {
       $field_record = array(

+ 9 - 16
tripal_views/tripal_views.coder_ignores.txt

@@ -2,25 +2,18 @@
 ; file:line:warning-type
 ; where warning-type is one of security, style, sql, i18n, comment, etc.
 
-; All <?php should be closed with a ?> in theme template files
-tripal_views_integration_fields_form.tpl.php:48:style
-tripal_views_data_export_download_form.tpl.php:8:style
-
-; All variables are set through the code and thus don't need to be filtered
-tripal_views_integration.inc:809:security
+; All variables are filtered
+tripal_views_integration.inc:814:security
 
 ; SQL queries the chado database which does not use the drupal prefixing functionality
 ; therefore, curly brackets ({}) are not appropriate.
-views/handlers/views_handler_filter_chado_select_cvterm_name.inc:53:sql
-views/handlers/views_handler_filter_chado_select_cvterm_name.inc:61:sql
-views/handlers/views_handler_field_dbxref_accession_link.inc:31:sql
-views/handlers/views_handler_filter_stockprop_id.inc:78:sql
-views/handlers/views_handler_filter_stockprop_id.inc:104:sql
-views/handlers/views_handler_filter_stock_relationship_id.inc:23:sql
-views/handlers/views_handler_filter_stock_relationship_id.inc:72:sql
-views/handlers/views_handler_filter_stock_relationship_id.inc:79:sql
-views/handlers/views_handler_filter_stock_relationship_id.inc:160:sql
-views/handlers/views_handler_argument_stockprop_id.inc:21:sql
+views/handlers/views_handler_filter_chado_select_cvterm_name.inc:62:sql
+views/handlers/views_handler_field_dbxref_accession_link.inc:32:sql
+views/handlers/views_handler_filter_stockprop_id.inc:105:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:24:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:74:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:82:sql
+views/handlers/views_handler_argument_stockprop_id.inc:22:sql
 
 ; SQL queries the pg_tables table to check if a table exists in chado; drupal
 ; prefixing is not appropriate

+ 8 - 0
tripal_views/tripal_views.views.inc

@@ -4,6 +4,10 @@ include('views/handlers/views_handler_join_chado_through_linking.inc');
 include('views/handlers/views_handler_join_chado_aggregator.inc');
 include('tripal_views.api.inc');
 
+
+// TEMPORARY
+include('views/chado_linking.TMP.inc');
+
 /**
  * @file
  * Tripal Views Integration
@@ -579,6 +583,10 @@ function tripal_views_views_data() {
     }
   }
 
+  // TEMPORARY: needed to join chado base tables to node linking tables
+  // currently done using old-style data arrays
+  $data = tripal_views_TEMPORARY_chado_linking_data($data);
+
   return $data;
 }
 

+ 18 - 13
tripal_views/tripal_views_integration.inc

@@ -90,7 +90,7 @@ function tripal_views_integration_setup_list() {
   $rows = array();
 
   // get the list of materialized views
-  $tviews = db_query('SELECT tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
+  $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
                      .'FROM {tripal_views} tv '
                      .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
                      .'WHERE tv.mview_id IS NOT NULL '
@@ -107,7 +107,12 @@ function tripal_views_integration_setup_list() {
     );
   }
 
-  $output .= theme('table', $header, $rows);
+  if ($rows) {
+    $output .= theme('table', $header, $rows);
+  }
+  else {
+    $output .= '<p>There are currently no Materialized Views defined.</p>';
+  }
 
   // Now list non-mview custom tables
   $output .= '<br /><h3>Custom Tables</h3>';
@@ -115,7 +120,7 @@ function tripal_views_integration_setup_list() {
   $rows = array();
 
   // get the list of chado tables
-  $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
+  $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tv.priority, tv.comment '
                      .'FROM {tripal_views} tv '
                      .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
                      .'WHERE mview_id IS NULL AND tc.table_id IS NOT NULL '
@@ -144,7 +149,7 @@ function tripal_views_integration_setup_list() {
   $rows = array();
 
   // get the list of chado tables
-  $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
+  $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tv.priority, tv.comment '
                      .'FROM {tripal_views} tv '
                      .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
                      .'WHERE mview_id IS NULL AND tc.table_id IS NULL '
@@ -363,9 +368,9 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
   // we need a div block where the table fields will get put when the
   // AHAH callback is made
   $form['view_setup_table'] = array(
-     '#type' => 'item',
-       '#prefix' => '<div id="table-rows-div">',
-       '#suffix' => '</div>',
+    '#type' => 'item',
+    '#prefix' => '<div id="table-rows-div">',
+    '#suffix' => '</div>',
   );
 
 
@@ -376,10 +381,10 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
     $mview_id = $form_state['storage']['mview_id'];
     $table_name = $form_state['storage']['table_name'];
     $form['view_setup_table'] = array(
-     '#type' => 'fieldset',
-     '#title' => 'Join Selection',
-     '#prefix' => '<div id="fieldset-table-rows-wrapper">',
-     '#suffix' => '</div>',
+      '#type' => 'fieldset',
+      '#title' => 'Join Selection',
+      '#prefix' => '<div id="fieldset-table-rows-wrapper">',
+      '#suffix' => '</div>',
     );
 
     // get the columns in this materialized view.  They are separated by commas
@@ -481,8 +486,8 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
       $form['view_setup_table']["$table_id-$i"]["fields_name_$table_id-$i"] = array(
         '#type' => 'markup',
         '#prefix' => "<div class=\"column-one\">",
-        '#value' => "<span class=\"column-name\">$column_name</span>".
-                    "<br /><span class=\"column-type\">$column_type</span>",
+        '#value' => "<span class=\"column-name\">" . filter_xss($column_name) . "</span>".
+                    "<br /><span class=\"column-type\">" . filter_xss($column_type) . "</span>",
         '#suffix' => "</div>",
       );
       $data['field_types'][$column_name] = $column_type;

+ 409 - 0
tripal_views/views/chado_linking.TMP.inc

@@ -0,0 +1,409 @@
+<?php
+
+/**
+ * @file
+ * This is a temporary function holding all the old-style views integration
+ * needed to link the base tables to their node. This will remain to keep things working
+ * until it has been best determined how to do this via the new tripal_views integration
+ *
+ * It's called att the bottom of tripal_views_views_data()
+ */
+function tripal_views_TEMPORARY_chado_linking_data($data) {
+  global $db_url;
+
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
+    // return empty data array b/c if chado is external then no join to the nodetable can be made
+    return $data;
+  }
+
+  // FEATURE ====================================
+  if (module_exists('tripal_feature')) {
+    // Basic table definition
+    $data['chado_feature']['table'] = array(
+      'field' => 'nid',
+      'group' => 'Chado Feature'
+    );
+
+    $data['chado_feature']['nid'] = array(
+      'title' => t('Feature Node ID'),
+      'help' => t('The node ID for this feature'),
+      'field' => array(
+        'handler' => 'views_handler_field_numeric',
+        'click sortable' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+    );
+
+    // Note: No joins need to be made from $data['feature']['table']
+
+    // Join the chado feature table to feature
+    $data['chado_feature']['table']['join']['feature'] = array(
+      'left_field' => 'feature_id',
+      'field' => 'feature_id',
+    );
+
+    // Join the node table to chado feature
+    $data['node']['table']['join']['chado_feature'] = array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Join the node table to feature
+    $data['node']['table']['join']['feature'] = array(
+      'left_table' => 'chado_feature',
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Add relationship between chado_feature and feature
+    $data['chado_feature']['feature_nid'] = array(
+      'group' => 'Feature',
+      'title' => 'Feature Node',
+      'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
+      'real field' => 'feature_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Feature'),
+        'label' => t('Chado => Feature'),
+        'real field' => 'feature_id',
+        'base' => 'feature',
+        'base field' => 'feature_id'
+      ),
+    );
+
+    // Add node relationship to feature
+    $data['chado_feature']['feature_chado_nid'] = array(
+      'group' => 'Feature',
+      'title' => 'Feature Node',
+      'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
+      'real field' => 'nid',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Node'),
+        'label' => t('Chado => Node'),
+        'real field' => 'nid',
+        'base' => 'node',
+        'base field' => 'nid'
+      ),
+    );
+  }
+
+  // ANALYSIS ===================================
+  if (module_exists('tripal_analysis')) {
+    // Basic table definition
+    $data['chado_analysis']['table'] = array(
+      'field' => 'nid',
+      'group' => 'Chado Analysis'
+    );
+
+    $data['chado_analysis']['nid'] = array(
+      'title' => t('Analysis Node ID'),
+      'help' => t('The node ID for this analysis'),
+      'field' => array(
+        'handler' => 'views_handler_field_numeric',
+        'click sortable' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+    );
+
+    // Note: No joins need to be made from $data['analysis']['table']
+
+    // Join the chado analysis table to analysis
+    $data['chado_analysis']['table']['join']['analysis'] = array(
+      'left_field' => 'analysis_id',
+      'field' => 'analysis_id',
+    );
+
+    // Join the node table to chado analysis
+    $data['node']['table']['join']['chado_analysis'] = array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Join the node table to analysis
+    $data['node']['table']['join']['analysis'] = array(
+      'left_table' => 'chado_analysis',
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Add relationship between chado_analysis and analysis
+    $data['chado_analysis']['analysis_nid'] = array(
+      'group' => 'Analysis',
+      'title' => 'Analysis Node',
+      'help' => 'Links Chado Analysis Fields/Data to the Nodes in the current View.',
+      'real field' => 'analysis_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Analysis'),
+        'label' => t('Chado => Analysis'),
+        'real field' => 'analysis_id',
+        'base' => 'analysis',
+        'base field' => 'analysis_id'
+      ),
+    );
+
+    // Add node relationship to analysis
+    $data['chado_analysis']['analysis_chado_nid'] = array(
+      'group' => 'Analysis',
+      'title' => 'Analysis Node',
+      'help' => 'Links Chado Analysis Fields/Data to the Nodes in the current View.',
+      'real field' => 'nid',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Node'),
+        'label' => t('Chado => Node'),
+        'real field' => 'nid',
+        'base' => 'node',
+        'base field' => 'nid'
+      ),
+    );
+  }
+
+  // ORGANISM ===================================
+  if (module_exists('tripal_organism')) {
+    // Basic table definition
+    $data['chado_organism']['table'] = array(
+      'field' => 'nid',
+      'group' => 'Chado Organism'
+    );
+
+    $data['chado_organism']['nid'] = array(
+      'title' => t('Organism Node ID'),
+      'help' => t('The node ID for this organism'),
+      'field' => array(
+        'handler' => 'views_handler_field_numeric',
+        'click sortable' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+    );
+
+    // Note: No joins need to be made from $data['organism']['table']
+
+    // Join the chado organism table to organism
+    $data['chado_organism']['table']['join']['organism'] = array(
+      'left_field' => 'organism_id',
+      'field' => 'organism_id',
+    );
+
+    // Join the node table to chado organism
+    $data['node']['table']['join']['chado_organism'] = array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Join the node table to organism
+    $data['node']['table']['join']['organism'] = array(
+      'left_table' => 'chado_organism',
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Add relationship between chado_organism and organism
+    $data['chado_organism']['organism_id'] = array(
+      'group' => 'Organism',
+      'title' => 'Organism Node',
+      'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
+      'real field' => 'organism_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Organism'),
+        'label' => t('Chado => Organism'),
+        'real field' => 'organism_id',
+        'base' => 'organism',
+        'base field' => 'organism_id'
+      ),
+    );
+  /*
+    // Add node relationship to organism
+    $data['chado_organism']['nid'] = array(
+      'group' => 'Organism',
+      'title' => 'Organism Node',
+      'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
+      'real field' => 'nid',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Node'),
+        'label' => t('Chado => Node'),
+        'real field' => 'nid',
+        'base' => 'node',
+        'base field' => 'nid'
+      ),
+    );
+  */
+  }
+
+  // LIBRARY ====================================
+  if (module_exists('tripal_library')) {
+    // Basic table definition
+    $data['chado_library']['table'] = array(
+      'field' => 'nid',
+      'group' => 'Chado Library'
+    );
+
+    $data['chado_library']['nid'] = array(
+      'title' => t('Library Node ID'),
+      'help' => t('The node ID for this library'),
+      'field' => array(
+        'handler' => 'views_handler_field_numeric',
+        'click sortable' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+    );
+
+    // Note: No joins need to be made from $data['library']['table']
+
+    // Join the chado library table to library
+    $data['chado_library']['table']['join']['library'] = array(
+      'left_field' => 'library_id',
+      'field' => 'library_id',
+    );
+
+    // Join the node table to chado library
+    $data['node']['table']['join']['chado_library'] = array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Join the node table to library
+    $data['node']['table']['join']['library'] = array(
+      'left_table' => 'chado_library',
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Add relationship between chado_library and library
+    $data['chado_library']['library_nid'] = array(
+      'group' => 'Library',
+      'title' => 'Library Node',
+      'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
+      'real field' => 'library_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Library'),
+        'label' => t('Chado => Library'),
+        'real field' => 'library_id',
+        'base' => 'library',
+        'base field' => 'library_id'
+      ),
+    );
+
+    // Add node relationship to library
+    $data['chado_library']['library_chado_nid'] = array(
+      'group' => 'Library',
+      'title' => 'Library Node',
+      'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
+      'real field' => 'nid',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Node'),
+        'label' => t('Chado => Node'),
+        'real field' => 'nid',
+        'base' => 'node',
+        'base field' => 'nid'
+      ),
+    );
+  }
+
+  // STOCK ======================================
+  if (module_exists('tripal_stock')) {
+    // Basic table definition
+    $data['chado_stock']['table'] = array(
+      'field' => 'stock_id',
+      'group' => 'Chado Stock',
+    );
+
+    $data['chado_stock']['nid'] = array(
+      'title' => t('Stock Node ID'),
+      'help' => t('The node ID for this analysis'),
+      'field' => array(
+        'handler' => 'views_handler_field_numeric',
+        'click sortable' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+    );
+
+    // Note: No joins need to be made from $data['stock']['table']
+
+    // Join the chado stock table to stock
+    $data['chado_stock']['table']['join']['stock'] = array(
+      'left_field' => 'stock_id',
+      'field' => 'stock_id',
+    );
+
+    // Join the node table to chado stock
+    $data['node']['table']['join']['chado_stock'] = array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Join the node table to stock
+    $data['node']['table']['join']['stock'] = array(
+      'left_table' => 'chado_stock',
+      'left_field' => 'nid',
+      'field' => 'nid',
+    );
+
+    // Add relationship between chado_stock and stock
+    $data['chado_stock']['stock_nid'] = array(
+      'group' => 'Stock',
+      'title' => 'Stock Node',
+      'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
+      'real field' => 'stock_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Stock'),
+        'label' => t('Chado => Stock'),
+        'real field' => 'stock_id',
+        'base' => 'stock',
+        'base field' => 'stock_id'
+      ),
+    );
+
+    // Add node relationship to stock
+    $data['chado_stock']['stock_chado_nid'] = array(
+      'group' => 'Stock',
+      'title' => 'Stock Node',
+      'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
+      'real field' => 'nid',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Chado => Node'),
+        'label' => t('Chado => Node'),
+        'real field' => 'nid',
+        'base' => 'node',
+        'base field' => 'nid'
+      ),
+    );
+  }
+
+  return $data;
+}

+ 1 - 0
tripal_views/views/handlers/views_handler_argument_stockprop_id.inc

@@ -18,6 +18,7 @@ class views_handler_argument_stockprop_id extends views_handler_argument_string
 
     //get options & display as options
     $previous_db = tripal_db_set_active('chado');
+    // @coder-ignore: non-drupal schema therefore table prefixing does not apply
     $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM cvterm cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM stockprop)");
     tripal_db_set_active($previous_db);
     $types = array();

+ 2 - 0
tripal_views/views/handlers/views_handler_field_chado_rel_by_type.inc

@@ -84,6 +84,7 @@ class views_handler_field_chado_rel_by_type extends views_handler_field_prerende
       );
 
       $options = array();
+      // @coder-ignore: non-drupal schema therefore table prefixing does not apply
       $sql = 'SELECT rel.type_id, cvt.name FROM %s_relationship rel LEFT JOIN cvterm cvt ON cvt.cvterm_id=rel.type_id GROUP BY rel.type_id,cvt.name';
       $previous_db = tripal_db_set_active('chado');
       $resource = db_query($sql, $this->table);
@@ -124,6 +125,7 @@ class views_handler_field_chado_rel_by_type extends views_handler_field_prerende
       }
 
       // Add relationships to the view results
+      // @coder-ignore: non-drupal schema therefore table prefixing does not apply
       $sql = "SELECT rel.*, cvterm.name as type_name, "
         ."subject.name as subject_name, object.name as object_name "
         ."FROM " . $this->table . "_relationship rel "

+ 0 - 173
tripal_views/views/handlers/views_handler_field_chado_relationship_by_type.inc.orig

@@ -1,173 +0,0 @@
-<?php
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_field_chado_relationship_by_type.inc
-=======
-/**
- * @file
- * @todo Add file header description
- */
->>>>>>> 6.x-0.4-dev:tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_by_type.inc
-
-/**
- * @file
- * Field handler for terms.
- */
-class views_handler_field_chado_relationship_by_type extends views_handler_field_prerender_list {
-  function init(&$view, $options) {
-    parent::init($view, $options);
-
-    // Boolean to determine whether
-    //    TRUE =>  value (property type)      -more than one property type displayed
-    //    FALSE => or just value is rendered  -only 1 porperty type is displayed
-    $this->display_type = TRUE;
-
-  }
-
-  function option_definition() {
-    $options = parent::option_definition();
-    $options['stockrel_type_ids'] = array('default' => array());
-    $options['stockrel_display_options'] = array('default' => array('subject', 'type', 'object'));
-    return $options;
-  }
-
-  /**
-   * Provide "link to term" option.
-   */
-  function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);
-
-    $form['stockrel_display_parts'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Display Relationship Parts'),
-      '#description' => t('Check each part of the relationship you want displayed where the part '
-        .'of a relationship are: \<Subject\> \<Relationship Type\> \<Object\>. '
-        .'For example, with the relationship Sarah is the maternal parent of Fred '
-        .'if you checked only Object then "Fred" would be displayed.'),
-      '#options' => array(
-        'subject' => 'Subject',
-        'type' => 'Relationship Type',
-        'object' => 'Object',
-      ),
-      '#default_value' => array($this->options['stockrel_display_parts']['subject'], $this->options['stockrel_display_parts']['type'], $this->options['stockrel_display_parts']['object']),
-    );
-
-    $form['stockrel_display_rels'] = array(
-      '#type' => 'radios',
-      '#title' => t('Display Relationships Where'),
-      '#description' => t('Only relationships where the selected criteria is met will be shown. '
-        .'The parts of a relationship are: \<Subject\> \<Relationship Type\> \<Object\>. '
-        .'For example, with the relationships Sarah is the maternal parent of Fred and '
-        .'Fred is the paternal_parent of Max where Fred is the current stock, '
-        .'if you selected "Current Stock is the Object" only Sarah is the maternal parent of Fred'
-        .' would be displayed.'),
-      '#options' => array(
-        'subject' => 'Current Stock is the Subject',
-        'object' => 'Current Stock is the Object',
-        'all' => 'Current Stock is the Subject and/or Object',
-      ),
-      '#default_value' => $this->options['stockrel_display_rels'],
-    );
-
-    $options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
-    $form['stockrel_type_ids'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Relationship Types'),
-      '#options' => $options,
-      '#default_value' => $this->options['stockrel_type_ids'],
-    );
-  }
-
-  /**
-   * Add this term to the query
-   */
-  function query() {
-    $this->add_additional_fields();
-  }
-
-  function pre_render($values) {
-    $this->aliases['relationships'] = 'relationships';
-    $this->aliases['stock_id'] = 'stock_id';
-    $this->field_alias = $this->aliases['stock_id'];
-
-    //for each stock in this view page
-    foreach ($values as $result) {
-      if (!empty($result->{$this->aliases['relationships']})) {
-
-        // all relationships including the current stock
-        $relationships = $result->{$this->aliases['relationships']};
-        foreach ($relationships as $relationship) {
-          // perform filtering------
-          //type
-          if (!empty($this->options['stockrel_type_ids'])) {
-            $relationships2keep = array_filter($this->options['stockrel_type_ids']);
-            if (!in_array($relationship->type_id, $relationships2keep)) {
-              continue;
-            }
-          }
-
-          //"Display Relationships Where" criteria
-          if (preg_match('/subject/', $this->options['stockrel_display_rels'])) {
-            if ($relationship->stock_id != $relationship->subject_id) {
-              continue;
-            }
-          }
-          elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
-            if ($relationship->stock_id != $relationship->object_id) {
-              continue;
-            }
-          }
-
-          // Add relationship to the list of items to be rendered
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_id'] = $relationship->stock_id;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_relationship_id'] = $relationship->stock_relationship_id;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_id'] = $relationship->subject_id;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_name'] = $relationship->subject_name;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_id'] = $relationship->object_id;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_name'] = $relationship->object_name;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_id'] = $relationship->type_id;
-          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_name'] = $relationship->type_name;
-        }
-      }
-    }
-  }
-
-  function render_item($count, $item) {
-    $text = array();
-
-    // Render Parts
-    if ($this->options['stockrel_display_parts']['subject']) {
-      $text[] = $item['subject_name'];
-    }
-    if ($this->options['stockrel_display_parts']['type']) {
-      $text[] = $item['type_name'];
-    }
-    if ($this->options['stockrel_display_parts']['object']) {
-      $text[] = $item['object_name'];
-    }
-
-    return implode(' ', $text);
-  }
-
-  function document_self_tokens(&$tokens) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-    $tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = t('Relationship ID');
-    $tokens['[' . $this->options['id'] . '-subject_id' . ']'] = t('Subject ID');
-    $tokens['[' . $this->options['id'] . '-subject_name' . ']'] = t('Subject Name');
-    $tokens['[' . $this->options['id'] . '-object_id' . ']'] = t('Object ID');
-    $tokens['[' . $this->options['id'] . '-object_name' . ']'] = t('Object Name');
-    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('Type ID');
-    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('Type Name');
-  }
-
-  function add_self_tokens(&$tokens, $item) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-    $tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = $item['stock_relationship_id'];
-    $tokens['[' . $this->options['id'] . '-subject_id' . ']'] = $item['subject_id'];
-    $tokens['[' . $this->options['id'] . '-subject_name' . ']'] = $item['subject_name'];
-    $tokens['[' . $this->options['id'] . '-object_id' . ']'] = $item['object_id'];
-    $tokens['[' . $this->options['id'] . '-object_name' . ']'] = $item['object_name'];
-    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
-    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
-
-  }
-}
-

+ 1 - 0
tripal_views/views/handlers/views_handler_field_dbxref_accession_link.inc

@@ -28,6 +28,7 @@ class views_handler_field_dbxref_accession_link extends views_handler_field {
 
     if (!empty($db_id) AND !empty($accession)) {
       $previous_db = tripal_db_set_active('chado');
+      // @coder-ignore: non-drupal schema therefore table prefixing does not apply
       $result = db_fetch_object(db_query('SELECT urlprefix FROM db WHERE db_id=%d', $db_id));
       tripal_db_set_active($previous_db);
       $urlprefix = $result->urlprefix;

+ 1 - 0
tripal_views/views/handlers/views_handler_filter_chado_select_cvterm_name.inc

@@ -58,6 +58,7 @@ class views_handler_filter_chado_select_cvterm_name extends views_handler_filter
 
     }
     else {
+      // @coder-ignore: non-drupal schema therefore table prefixing does not apply
       $sql = "SELECT cvterm_id, name FROM cvterm WHERE cvterm_id IN (SELECT distinct(type_id) FROM %s)";
       $previous_db = tripal_db_set_active('chado');
       $resource = db_query($sql, $this->view->base_table);

+ 0 - 258
tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc.orig

@@ -1,258 +0,0 @@
-<?php
-
-/**
- * @file
- * Allows stocks to be filtered by associated database reference accession
- *
- * @ingroup tripal_stock
- * @ingroup views_filter_handlers
- */
-class views_handler_filter_stock_dbxref_id extends views_handler_filter {
-
-  function init(&$view, $options) {
-    parent::init($view, $options);
-    $this->db = $this->options['db'];
-  }
-
-  function options_form(&$form, &$form_state) {
-    if ($this->can_expose()) {
-      $this->show_expose_button($form, $form_state);
-    }
-
-    $form['op_val_start'] = array('#value' => '<div class="clear-block">');
-
-    $this->types_form($form, $form_state);
-
-    $this->show_operator_form($form, $form_state);
-    $form['operator']['#prefix'] = '<div class="views-right-70">';
-    $this->show_value_form($form, $form_state);
-    $form['op_val_end'] = array('#value' => '</div>');
-
-    if ($this->can_expose()) {
-      $this->show_expose_form($form, $form_state);
-    }
-
-  }
-
-  function query() {
-    $this-> db = array_filter($this->db);
-
-    if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-      $new_where_sql = "stock.stock_id IN "
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc
-      ."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (" . implode(', ', $this->db) . "))";
-=======
-      . "(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (" . implode(', ', $this->db) . "))";
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-    elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-      $new_where_sql = "stock.stock_id NOT IN "
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc
-      ."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (" . implode(', ', $this->db) . "))";
-=======
-      . "(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (" . implode(', ', $this->db) . "))";
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-    else {
-      if (!empty($this->value)) {
-        $new_where_sql = "stock.stock_id IN "
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc
-          ."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id "
-          ."AND dbxref.db_id IN (" . implode(', ', $this->db) . ") AND dbxref.accession" . $this->operator . "'" . $this->value . "')";
-=======
-          . "(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id "
-          . "AND dbxref.db_id IN (" . implode(', ', $this->db) . ") AND dbxref.accession" . $this->operator . "'" . $this->value . "')";
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc
-        $this->query->add_where($this->options['group'], $new_where_sql);
-      }
-    }
-  }
-
-  /////////// Form Parts/////////////////////////
-  function types_form(&$form, &$form_state) {
-
-    $db_options = tripal_db_get_db_options();
-    ksort($db_options);
-    $form['db'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Databases'),
-      '#options' => $db_options,
-      '#default_value' => $this->db,
-      '#prefix' => '<div class="views-left-30">',
-      '#suffix' => '</div>',
-    );
-
-  }
-
-  function value_form(&$form, &$form_state) {
-    parent::value_form($form, $form_state);
-
-    $form['value'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Accession'),
-      '#default_value' => $this->value,
-    );
-  }
-
-  function operator_options() {
-    return array(
-      '=' => t('Is equal to'),
-      '!=' => t('Is not equal to'),
-      '~' => t('Contains'),
-      '!~' => t('Does not contain'),
-      'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),
-    );
-  }
-
- /**
-  * Render our chunk of the exposed filter form when selecting
-  */
-  function exposed_form(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    if (!empty($this->options['expose']['use_type']) && !empty($this->options['expose']['type'])) {
-      $type = $this->options['expose']['type'];
-      $form[$type] = array(
-        '#type' => 'select',
-        '#title' => t('Database References'),
-        '#options' => $this->type_options(),
-        '#default_value' => $this->type,
-      );
-
-      if (isset($form[$type]['#title'])) {
-        unset($form[$type]['#title']);
-      }
-    }
-
-    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) {
-      $operator = $this->options['expose']['operator'];
-      $this->operator_form($form, $form_state);
-      $form[$operator] = $form['operator'];
-
-      if (isset($form[$operator]['#title'])) {
-        unset($form[$operator]['#title']);
-      }
-
-      $this->exposed_translate($form[$operator], 'operator');
-
-      unset($form['operator']);
-    }
-
-    if (!empty($this->options['expose']['identifier'])) {
-      $value = $this->options['expose']['identifier'];
-      $this->value_form($form, $form_state);
-      $form[$value] = $form['value'];
-
-      if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
-        unset($form[$value]['#title']);
-      }
-
-      $this->exposed_translate($form[$value], 'value');
-
-      if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) {
-        unset($form[$value]['#default_value']);
-      }
-
-      if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
-        $form[$value]['#default_value'] = 'All';
-      }
-
-      if ($value != 'value') {
-        unset($form['value']);
-      }
-    }
-  }
-
-  function expose_form_left(&$form, &$form_state) {
-    $form['expose']['label'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['label'],
-      '#title' => t('Label'),
-      '#size' => 40,
-    );
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-  }
-
-  function expose_form_right(&$form, &$form_state) {
-    if (!empty($form['type']['#type'])) {
-      $form['expose']['use_type'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock Database Reference'),
-        '#description' => t('When checked, the Database Reference will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_type']),
-      );
-      $form['expose']['type'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['type'],
-        '#title' => t('Database Reference identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this Database Reference.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-type' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['type'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-    if (!empty($form['operator']['#type'])) {
-      $form['expose']['use_operator'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock operator'),
-        '#description' => t('When checked, the operator will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_operator']),
-      );
-      $form['expose']['operator'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['operator'],
-        '#title' => t('Operator identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this operator.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-operator' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['operator'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['optional'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Optional'),
-      '#description' => t('This exposed filter is optional and will have added options to allow it not to be set.'),
-      '#default_value' => $this->options['expose']['optional'],
-    );
-  }
-}
-

+ 3 - 0
tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc

@@ -19,6 +19,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
 
       // determine if just checking presence
       if (preg_match('/NULL/', $this->operator)) {
+          // @coder-ignore: non-drupal schema therefore table prefixing does not apply
           $where = 'stock.stock_id IN ('
             .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
             .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' AND type_id = ' . $this->options['type']
@@ -68,6 +69,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
 
         //generate where
         if (sizeof($fixed_stock_ids) == 1) {
+          // @coder-ignore: non-drupal schema therefore table prefixing does not apply
           $where = 'stock.stock_id IN ('
             .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
             .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' ' . $fixed_stock_ids[0] . ' AND type_id = ' . $this->options['type']
@@ -75,6 +77,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
           $this->query->add_where($this->options['group'], $where);
         }
         elseif (sizeof($fixed_stock_ids) > 1) {
+          // @coder-ignore: non-drupal schema therefore table prefixing does not apply
           $where = 'stock.stock_id IN ('
             .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
             .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' (' . implode(', ', $fixed_stock_ids) . ') AND type_id = ' . $this->options['type']

+ 0 - 355
tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc.orig

@@ -1,355 +0,0 @@
-<?php
-/**
- * @file
- * @todo Add file header description
- */
-
-/**
- * @file
- * Filter stocks via stock_relationships
- */
-class views_handler_filter_stock_relationship_id extends views_handler_filter {
-
-  function query() {
-    if ($this->value) {
-
-      // get variable position
-      if ($this->options['fixed_position'] == 'subject_id') {
-        $this->options['variable_position'] = 'object_id';
-      }
-      else {
-        $this->options['variable_position'] = 'subject_id';
-      }
-
-      // determine if just checking presence
-      if (preg_match('/NULL/', $this->operator)) {
-          $where = 'stock.stock_id IN ('
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
-            .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
-            .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' AND type_id = ' . $this->options['type']
-          .')';
-=======
-            . 'SELECT ' . $this->options['variable_position'] . ' FROM {stock_relationship} '
-            . 'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' AND type_id = ' . $this->options['type']
-          . ')';
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc
-          $this->query->add_where($this->options['group'], $where);
-      }
-      else {
-
-        // determine whether regex was requested
-        if ($this->operator == '~') {
-          $search_options = array('regex_columns' => array('name', 'uniquename'));
-          $this->operator = '=';
-        }
-        elseif ($this->operator == '!~') {
-          $search_options = array('regex_columns' => array('name', 'uniquename'));
-          $this->operator = '!=';
-        }
-        else {
-          $search_options = array();
-        }
-
-        // get fixed stock id(s)
-        $fixed_stock = tripal_core_chado_select('stock', array('stock_id'), array('uniquename' => $this->value), $search_options);
-        $fixed_stock_ids = array();
-        if ($fixed_stock[0]->stock_id) {
-          $fixed_stock_ids[] = $fixed_stock[0]->stock_id;
-        }
-        else {
-          $fixed_stock = tripal_core_chado_select('stock', array('stock_id'), array('name' => $this->value), $search_options);
-          if (sizeof($fixed_stock) > 1) {
-            foreach ($fixed_stock as $s) {
-              $fixed_stock_ids[] = $s->stock_id;
-            }
-          }
-          elseif (sizeof($fixed_stock) == 1) {
-            $fixed_stock_ids[] = $fixed_stock[0]->stock_id;
-          }
-        }
-
-        // determine operator
-        if ($this->operator == '=' && sizeof($fixed_stock_ids) > 1) {
-          $this->operator = 'IN';
-        }
-        elseif ($this->operator == '!=' && sizeof($fixed_stock_ids) > 1) {
-          $this->operator = 'NOT IN';
-        }
-
-        //generate where
-        if (sizeof($fixed_stock_ids) == 1) {
-          $where = 'stock.stock_id IN ('
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
-            .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
-            .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' ' . $fixed_stock_ids[0] . ' AND type_id = ' . $this->options['type']
-          .')';
-=======
-            . 'SELECT ' . $this->options['variable_position'] . ' FROM {stock_relationship} '
-            . 'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' ' . $fixed_stock_ids[0] . ' AND type_id = ' . $this->options['type']
-          . ')';
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc
-          $this->query->add_where($this->options['group'], $where);
-        }
-        elseif (sizeof($fixed_stock_ids) > 1) {
-          $where = 'stock.stock_id IN ('
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
-            .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
-            .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' (' . implode(', ', $fixed_stock_ids) . ') AND type_id = ' . $this->options['type']
-          .')';
-          $this->query->add_where($this->options['group'], $where);
-        }
-        else {
-          drupal_set_message(t('No stock with the name or uniquename %value was found -No filtering done.', array('%value' => $this->value)), 'error');
-=======
-            . 'SELECT ' . $this->options['variable_position'] . ' FROM {stock_relationship} '
-            . 'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' (' . implode(', ', $fixed_stock_ids) . ') AND type_id = ' . $this->options['type']
-          . ')';
-          $this->query->add_where($this->options['group'], $where);
-        }
-        else {
-          drupal_set_message(t('No stock with the name or uniquename %value was found -No filtering done.',  array('%value' => $this->value ), 'error'));
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc
-        }
-      } //end of not just checking presence
-    }
-  }
-
-  function options_form(&$form, &$form_state) {
-
-    if ($this->can_expose()) {
-      $this->show_expose_button($form, $form_state);
-    }
-
-    $instructions = 'This filter allows you to enter a stock, the position of that stock in the '
-      .'relationship and relationship type and only stocks with a relationship of the type described '
-      .'will be shown. For example, if you want all stocks where Fred is_paternal_parent_of, then '
-      .'you would enter Fred as the value, select is_paternal_parent_of as the Relationship Type '
-      .'and subject as the Fixed Position.';
-    $form['instructions'] = array(
-      '#type' => 'item',
-      '#value' => t($instructions)
-    );
-
-    $form['op_val_start'] = array('#value' => '<div class="clear-block">');
-
-    // left side
-
-    $this->types_form($form, $form_state);
-    $form['type']['#prefix'] = '<div class="views-left-50">';
-    $form['type']['#suffix'] = '</div>';
-
-    $this->show_operator_form($form, $form_state);
-    $form['operator']['#prefix'] = '<div class="views-right-50">';
-    $form['operator']['#suffix'] = '</div>';
-
-    $this->show_value_form($form, $form_state);
-    $form['value']['#prefix'] = '<div class="views-right-50">';
-    $form['value']['#suffix'] = '</div>';
-
-    // right side
-
-
-    $this->fixed_position_form($form, $form_state);
-    $form['fixed_position']['#prefix'] = '<div class="views-right-50">';
-    $form['fixed_position']['#suffix'] = '</div>';
-
-
-    if ($this->can_expose()) {
-      $this->show_expose_form($form, $form_state);
-    }
-
-    $form['op_val_start'] = array('#value' => '</div>');
-
-  }
-
-  function value_form(&$form, &$form_state) {
-    parent::value_form($form, $form_state);
-
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
-    if (!$this->options['label']) {
-      $label = 'Stock Name';
-    }
-    else {
-      $label = $this->options['label'];
-=======
-    if ($this->options['label']) {
-      $label = $this->options['label'];
-    }
-    else {
-      $label = 'Stock Name';
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc
-    }
-    $form['value'] = array(
-      '#type' => 'textfield',
-      '#title' => t('%label', array('%label' => $label)),
-      '#default_value' => $this->value,
-      '#size' => 40,
-    );
-
-  }
-
-  function type_options() {
-
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM {cvterm} cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM {stock_relationship})");
-    tripal_db_set_active($previous_db);
-
-    $types = array();
-    while ($r = db_fetch_object($result)) {
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
-      $types[$r->type_id] = $r->name;
-    }
-=======
-    $types[$r->type_id] = $r->name; }
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc
-
-    return $types;
-  }
-
-  function types_form(&$form, &$form_state) {
-
-    $form['type'] = array(
-      '#type' => count($options) < 10 ? 'radios' : 'select',
-      '#title' => t('Relationship Types'),
-      '#options' => $this->type_options(),
-      '#default_value' => $this->options['type'],
-    );
-
-  }
-
-  function fixed_position_form(&$form, &$form_state) {
-
-    $form['fixed_position'] = array(
-      '#type' => 'radios',
-      '#title' => 'Position of Stock to Filter on',
-      '#description' => t('Where a relationship consists of a subject type object, this field indicates '
-        .'what position in the relationship remains fixed (is the stock entered as the value).'),
-      '#options' => array(
-        'subject_id' => 'Subject',
-        'object_id' => 'Object'
-      ),
-      '#default_value' => ($this->options['fixed_position']) ? $this->options['fixed_position'] : 'subject_id',
-    );
-
-  }
-
-  function operator_options() {
-    return array(
-      '=' => t('Is equal to'),
-      '!=' => t('Is not equal to'),
-      '~' => t('Contains'),
-      '!~' => t('Does not contain'),
-      'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),
-    );
-  }
-
- /**
-  * Render our chunk of the exposed filter form when selecting
-  */
-  function exposed_form(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) {
-      $operator = $this->options['expose']['operator'];
-      $this->operator_form($form, $form_state);
-      $form[$operator] = $form['operator'];
-
-      if (isset($form[$operator]['#title'])) {
-        unset($form[$operator]['#title']);
-      }
-
-      $this->exposed_translate($form[$operator], 'operator');
-
-      unset($form['operator']);
-    }
-
-    if (!empty($this->options['expose']['identifier'])) {
-      $value = $this->options['expose']['identifier'];
-      $this->value_form($form, $form_state);
-      $form[$value] = $form['value'];
-
-      if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
-        unset($form[$value]['#title']);
-      }
-
-      $this->exposed_translate($form[$value], 'value');
-
-      if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) {
-        unset($form[$value]['#default_value']);
-      }
-
-      if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
-        $form[$value]['#default_value'] = 'All';
-      }
-
-      if ($value != 'value') {
-        unset($form['value']);
-      }
-    }
-  }
-
-  function expose_form_left(&$form, &$form_state) {
-    $form['expose']['label'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['label'],
-      '#title' => t('Label'),
-      '#size' => 40,
-    );
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-  }
-
-  function expose_form_right(&$form, &$form_state) {
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-    if (!empty($form['operator']['#type'])) {
-      $form['expose']['use_operator'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock operator'),
-        '#description' => t('When checked, the operator will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_operator']),
-      );
-      $form['expose']['operator'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['operator'],
-        '#title' => t('Operator identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this operator.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-operator' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['operator'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['optional'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Optional'),
-      '#description' => t('This exposed filter is optional and will have added options to allow it not to be set.'),
-      '#default_value' => $this->options['expose']['optional'],
-    );
-  }
-}

+ 1 - 0
tripal_views/views/handlers/views_handler_filter_stockprop_id.inc

@@ -101,6 +101,7 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
 
       // Get options
       $previous_db = tripal_db_set_active('chado');
+      // @coder-ignore: non-drupal schema therefore table prefixing does not apply
       $resource = db_query("SELECT value FROM stockprop WHERE type_id=" . $this->type . " ORDER BY value");
       tripal_db_set_active($previous_db);
       while ($r = db_fetch_object($resource)) {

+ 0 - 340
tripal_views/views/handlers/views_handler_filter_stockprop_id.inc.orig

@@ -1,340 +0,0 @@
-<?php
-
-/**
- * @file
- * Allows stocks to be filtered by proeprty values
- *
- * @ingroup tripal_stock
- * @ingroup views_filter_handlers
- */
-class views_handler_filter_stockprop_id extends views_handler_filter {
-
-  function init(&$view, $options) {
-    parent::init($view, $options);
-    $this->type = $this->options['type'];
-  }
-
-  function options_form(&$form, &$form_state) {
-    if ($this->can_expose()) {
-      $this->show_expose_button($form, $form_state);
-    }
-
-    $form['op_val_start'] = array('#value' => '<div class="clear-block">');
-
-    $this->types_form($form, $form_state);
-
-    $this->show_operator_form($form, $form_state);
-    $form['operator']['#prefix'] = '<div class="views-right-70">';
-    $this->show_value_form($form, $form_state);
-    $form['op_val_end'] = array('#value' => '</div>');
-
-    if ($this->can_expose()) {
-      $this->show_expose_form($form, $form_state);
-    }
-
-  }
-
-  function options_validate(&$form, &$form_state) {
-    parent::options_validate($form, $form_state);
-
-    if (preg_match('/NULL/', $form_state['values']['options']['operator'])) {
-      $value = $form_state['values']['options']['value'];
-      if (!empty($value)) {
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-        drupal_set_message(t('The Value (%value) will be IGNORED when the Operator is set to "Is Present" or Is Absent".', array('%value' => $value)), 'warning');
-=======
-        drupal_set_message(t('The Value %value will be IGNORED when the Operator is set to "Is Present" or Is Absent". ', array('%value' => $value), 'warning'));
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-      }
-    }
-    else {
-      $value = $form_state['values']['options']['value'];
-      if (empty($value)) {
-        form_error($form['value'], t('Value required. The value will be used in conjunction with the operator. For example, if the '
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-           .'operator="Is equal to" and the value="2010" then only properties with a value of 2010 and the type specified will be displayed.'));
-=======
-           . 'operator="Is equal to" and the value="2010" then only properties with a value of 2010 and the type specified will be displayed.'));
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-      }
-    }
-
-    if (empty($form_state['values']['options']['type'])) {
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-      drupal_set_message(t('No Property Type was choosen. As such, any property type whose value %op %value will be displayed.',
-        array('%op' => $form_state['values']['options']['operator'], '%value' => $form_state['values']['options']['value'])), 'warning');
-=======
-      drupal_set_message('No Property Type was choosen. As such, any property type whose value '
-                 . $form_state['values']['options']['operator'] . ' ' . $form_state['values']['options']['value'] . ' will be displayed', 'warning');
-    }
-  }
-
-  function query() {
-    if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
-      $this->query->add_where($this->options['group'], $new_where_sql);
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-    }
-    elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-      $new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-    elseif ($this->value) {
-      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . " AND stockprop.value" . $this->operator . "'" . $this->value . "')";
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-
-  }
-
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-  function query() {
-    if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-    elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-      $new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-    elseif ($this->value) {
-      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . " AND stockprop.value" . $this->operator . "'" . $this->value . "')";
-      $this->query->add_where($this->options['group'], $new_where_sql);
-    }
-
-  }
-
-=======
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-  function types_form(&$form, &$form_state) {
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM {cvterm} cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM {stockprop})");
-    tripal_db_set_active($previous_db);
-
-    $types = array();
-    while ($r = db_fetch_object($result)) {
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-      $types[$r->type_id] = $r->name;
-    }
-=======
-    $types[$r->type_id] = $r->name; }
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-
-    $form['type'] = array(
-      '#type' => count($options) < 10 ? 'radios' : 'select',
-      '#title' => t('Property Types'),
-      '#options' => $types,
-      '#default_value' => $this->type,
-      '#prefix' => '<div class="views-left-30">',
-      '#suffix' => '</div>',
-    );
-
-  }
-
-  function value_form(&$form, &$form_state) {
-    parent::value_form($form, $form_state);
-
-    if ($this->options['expose']['display_type'] == 'select') {
-
-      // Get options
-      $previous_db = tripal_db_set_active('chado');
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-      $resource = db_query("SELECT value FROM stockprop WHERE type_id=" . $this->type . " ORDER BY value");
-      tripal_db_set_active($previous_db);
-=======
-      $resource = db_query("SELECT value FROM {stockprop} WHERE type_id=" . $this->type . " ORDER BY value");
-     tripal_db_set_active($previous_db);
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-      while ($r = db_fetch_object($resource)) {
-        $options[$r->value] = $r->value;
-      }
-      $form['value'] = array(
-        '#type' => 'select',
-<<<<<<< HEAD:tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
-        '#title' => t('%label', array('%label' => $this->options['label'])),
-=======
-        '#title' => t('%label', array('%title' => $this->options['label'])),
->>>>>>> 6.x-0.4-dev:tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
-        '#options' => $options,
-        '#default_value' => $this->value,
-      );
-    }
-    else {
-      $form['value'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Value'),
-        '#default_value' => $this->value,
-      );
-    }
-  }
-
-  function operator_options() {
-    return array(
-      '=' => t('Is equal to'),
-      '!=' => t('Is not equal to'),
-      '~' => t('Contains'),
-      '!~' => t('Does not contain'),
-      'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),
-    );
-  }
-
- /**
-  * Render our chunk of the exposed filter form when selecting
-  */
-  function exposed_form(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    if (!empty($this->options['expose']['use_type']) && !empty($this->options['expose']['type'])) {
-      $type = $this->options['expose']['type'];
-      $form[$type] = array(
-        '#type' => 'select',
-        '#title' => t('Property Types'),
-        '#options' => $this->type_options(),
-        '#default_value' => $this->type,
-      );
-
-      if (isset($form[$type]['#title'])) {
-        unset($form[$type]['#title']);
-      }
-    }
-
-    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) {
-      $operator = $this->options['expose']['operator'];
-      $this->operator_form($form, $form_state);
-      $form[$operator] = $form['operator'];
-
-      if (isset($form[$operator]['#title'])) {
-        unset($form[$operator]['#title']);
-      }
-
-      $this->exposed_translate($form[$operator], 'operator');
-
-      unset($form['operator']);
-    }
-
-    if (!empty($this->options['expose']['identifier'])) {
-      $value = $this->options['expose']['identifier'];
-      $this->value_form($form, $form_state);
-      $form[$value] = $form['value'];
-
-      if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
-        unset($form[$value]['#title']);
-      }
-
-      $this->exposed_translate($form[$value], 'value');
-
-      if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) {
-        unset($form[$value]['#default_value']);
-      }
-
-      if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
-        $form[$value]['#default_value'] = 'All';
-      }
-
-      if ($value != 'value') {
-        unset($form['value']);
-      }
-    }
-  }
-
-  function expose_form_left(&$form, &$form_state) {
-    $form['expose']['label'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['label'],
-      '#title' => t('Label'),
-      '#size' => 40,
-    );
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-    $form['expose']['display_type'] = array(
-      '#type' => 'radios',
-      '#default_value' => $this->options['expose']['display_type'],
-      '#title' => t('Display Type'),
-      '#description' => t('This will change the form item type of the exposed value form. ie: it can be used to let the user select the property value from a select box rather than a textfield.'),
-      '#options' => array(
-        'textfield' => 'Text Field',
-        'select' => 'Drop Down',
-      ),
-    );
-  }
-
-  function expose_form_right(&$form, &$form_state) {
-    if (!empty($form['type']['#type'])) {
-      $form['expose']['use_type'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock Property Type'),
-        '#description' => t('When checked, the property type will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_type']),
-      );
-      $form['expose']['type'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['type'],
-        '#title' => t('Property Type identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this property type.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-type' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['type'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-    if (!empty($form['operator']['#type'])) {
-      $form['expose']['use_operator'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock operator'),
-        '#description' => t('When checked, the operator will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_operator']),
-      );
-      $form['expose']['operator'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['operator'],
-        '#title' => t('Operator identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this operator.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-operator' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['operator'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['optional'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Optional'),
-      '#description' => t('This exposed filter is optional and will have added options to allow it not to be set.'),
-      '#default_value' => $this->options['expose']['optional'],
-    );
-  }
-
-
-}

Some files were not shown because too many files changed in this diff