Browse Source

Now can add/delete/edit sets of constants -ie: there are multiple sets of constants per bulk loading job

Lacey Sanderson 13 years ago
parent
commit
55f3d0ae9c

+ 502 - 0
base/tripal_bulk_loader/tripal_bulk_loader.constants.inc

@@ -0,0 +1,502 @@
+<?php
+
+/**
+ * Inserts/Updates a tripal bulk loading job constant
+ *
+ * @param $nid
+ *   The node ID of the the tripal bulk loading job the constant is associated with
+ * @param $table
+ *   The chado table the constant is associated with
+ * @param $field
+ *   The chado field the constant is associated with
+ * @param $record_id
+ *   The index in the template array for this record
+ * @param $field_id
+ *   The index in the template array for this field
+ *
+ * NOTE: $template_array[$record_id]['table'] = $table and $template_array[$record_id]['fields'][$field_id]['field'] = $field
+ *   both are included as a means of double-checking the constant still is still in thesame place in the template array.
+ *   For example, that the template was not edited and the records moved around after the job was submitted but before it was run.
+ *
+ * @return
+ *   On success it returns the object (with primary key if inserted);
+ *   on failure it returns FALSE
+ */
+function tripal_bulk_loader_update_constant ($nid, $group_id, $table, $field, $record_id, $field_id, $value) {
+  
+  $record = array(
+    'nid'=>$nid, 
+    'group_id' => $group_id,
+    'chado_table'=>$table, 
+    'chado_field'=>$field, 
+    'record_id'=>$record_id, 
+    'field_id'=>$field_id, 
+    'value'=>$value
+  );
+  
+  // Check to see if already exists
+  $exists = db_fetch_object(db_query(
+    "SELECT constant_id FROM {tripal_bulk_loader_constants} WHERE nid=%d AND record_id=%d AND field_id=%d AND group_id=%d",
+    $record['nid'],
+    $record['record_id'],
+    $record['field_id'],
+    $record['group_id']
+  ));
+  if ($exists->constant_id) {
+    $record['constant_id'] = $exists->constant_id;
+    $status = drupal_write_record('tripal_bulk_loader_constants',$record,'constant_id');
+    if ($status) {
+      return $record;
+    } else {
+      return FALSE;
+    }
+  } else {
+    $status = drupal_write_record('tripal_bulk_loader_constants',$record);
+    if ($status) {
+      return $record;
+    } else {
+      return FALSE;
+    }
+  }
+}
+
+///////////////////////////////////////////////////////////
+// Set Constants Form (on Bulk Loader Node)
+///////////////////////////////////////////////////////////
+
+/**
+ * Set constants (exposed fields in template)
+ *
+ * @param $form_state 
+ *   The current state of the form
+ * @param $node
+ *   The node to set constants for
+ *
+ * @return
+ *   A form array to be rendered by drupal_get_form()
+ */
+function tripal_bulk_loader_set_constants_form ($form_state, $node) {
+  $form = array();
+  
+  $form['nid'] = array(
+    '#type' => 'hidden',
+    '#value' => $node->nid
+  );
+  
+  $form['exposed_fields'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Constant Values'),
+    '#collapsible' => TRUE,
+    '#collapsed' => ($node->template_id) ? FALSE : TRUE,
+    '#prefix' => '<div id="set-constants">',
+    '#suffix' => '</div>',
+  );
+
+  // Display table of already added constant sets with the ability to re-arrange and delete
+  if (sizeof($node->constants) > 0) {
+    $form['exposed_fields']['explanation-1'] = array(
+      '#type' => 'item',
+      '#value' => t('You have already added constants to this bulk loading job. Each '
+        .'row in the following table represents a set of constants. Each set will be used '
+        .'to load your spreadsheet with the specified template resulting in the each record '
+        .'in the template to be loaded x number of times where there are x sets of '
+        .'constants (rows in the following table).')
+    );
+    
+    $form['exposed_fields']['existing'] = array(
+      '#tree' => TRUE,
+    );
+    
+    foreach ($node->constants as $set) {
+
+      foreach ($set as $record) {
+        foreach ($record as $field) {
+          $index = $field['record_id'].'-'.$field['field_id'];
+          $group = $field['group_id'];
+          $form['exposed_fields']['existing'][$group][$index] = array(
+            '#type' => 'markup',
+            '#value' => $field['value'],
+          );
+        }
+      }
+
+      $form['exposed_fields']['existing'][$group]['delete'] = array(
+        '#type' => 'markup',
+        '#value' => l('Edit', 'node/'. $node->nid . '/constants/'.$group.'/edit') .'<br />'.
+          l('Delete', 'node/'. $node->nid . '/constants/'.$group.'/delete'),
+      );
+                  
+    }
+  }
+  
+  $form['exposed_fields']['new'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('New set of Constants'),
+  );
+    
+  $form['exposed_fields']['new']['explanation-2'] = array(
+    '#type' => 'item',
+    '#value' => t('The following fields are constants in the selected template that you need to set values for.')
+  );
+  
+  // Add textifelds for exposed fields of the current template
+  $exposed_fields = FALSE;
+  $indexes = array();
+  if ($node->template_id) {
+    if (isset($node->template)) {
+      foreach ($node->template->template_array as $record_id => $record) {
+        foreach ($record['fields'] as $field_id => $field) {
+          if ($field['exposed']) {
+            $exposed_fields = TRUE;
+            $indexes[$record_id][] = $field_id;
+            
+            switch($field['type']) {
+              case 'table field':
+                $form['exposed_fields']['new'][$record_id.'-'.$field_id] = array(
+                  '#type' => 'textfield',
+                  '#title' => t($field['title']),
+                  '#description' => t($field['exposed_description']),
+                  '#default_value' => (isset($node->constants[$record_id][$field_id]['value'])) ? $node->constants[$record_id][$field_id]['value'] : $field['constant value'],
+                );
+              break;
+              case 'constant':
+                $form['exposed_fields']['new'][$record_id.'-'.$field_id] = array(
+                  '#type' => 'textfield',
+                  '#title' => t($field['title']),
+                  '#description' => t('Enter the case-sensitive value of this constant for your spreadsheet'),
+                  '#default_value' => (isset($node->constants[$record_id][$field_id]['value'])) ? $node->constants[$record_id][$field_id]['value'] : $field['constant value'],
+                );
+              break;
+            }
+            
+            $form['exposed_fields']['new'][$record_id.'-'.$field_id.'-table'] = array(
+              '#type' => 'hidden',
+              '#value' => $record['table'],
+            );
+            $form['exposed_fields']['new'][$record_id.'-'.$field_id.'-field'] = array(
+              '#type' => 'hidden',
+              '#value' => $field['field'],
+            );
+            $form['exposed_fields']['new'][$record_id.'-'.$field_id.'-type'] = array(
+              '#type' => 'hidden',
+              '#value' => $field['type'],
+            );
+          }
+        }
+      }
+    }
+  }
+  $form['template'] = array(
+    '#type' => 'hidden',
+    '#value' => serialize($node->template->template_array)
+  );
+  
+  $form['exposed_fields']['new']['indexes'] = array(
+    '#type' => 'hidden',
+    '#value' => serialize($indexes),
+  );
+  
+  if (!$exposed_fields) {
+    $form['exposed_fields']['new']['explanation'] = array(
+      '#type' => 'item',
+      '#value' => t('There are no exposed fields for this template.')
+    );    
+  }
+  
+  $form['exposed_fields']['new']['submit-2'] = array(
+    '#type' => 'submit',
+    '#name' => 'add_constant',
+    '#value' => t('Add Constant Set')
+  );
+  
+  return $form;
+}
+
+/**
+ * Validate that the values entered exist in the database
+ * if indicated in hte template array
+ */
+function tripal_bulk_loader_set_constants_form_validate ($form, $form_state) {
+
+  $template = unserialize($form_state['values']['template']);
+  $indexes = unserialize($form_state['values']['indexes']);
+
+  $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
+  if (strcmp('Add Constant Set',$op) == 0) {
+      foreach ($indexes as $record_id => $array) {
+        foreach($array as $field_id) {
+          if ($template[$record_id]['fields'][$field_id]['exposed_validate']) {
+            $result = db_fetch_object(db_query(
+              "SELECT 1 as valid FROM %s WHERE %s='%s'",
+              $template[$record_id]['table'],
+              $template[$record_id]['fields'][$field_id]['field'],
+              $form_state['values'][$record_id.'-'.$field_id]
+            ));
+    
+            if (!$result->valid) {
+              $msg = 'A '.$form['exposed_fields']['new'][$record_id.'-'.$field_id]['#title'].' of "'.$form['exposed_fields']['new'][$record_id.'-'.$field_id]['#value'].'" must already exist!';
+              form_set_error($record_id.'-'.$field_id, $msg);
+            } else {
+              drupal_set_message('Confirmed a '.$form['exposed_fields']['new'][$record_id.'-'.$field_id]['#title'].' of "'.$form['exposed_fields']['new'][$record_id.'-'.$field_id]['#value'].'" already exists.');
+            }
+          }
+        }
+      }
+  }
+  
+}
+
+/**
+ * Insert/update the constants associated with this node
+ */
+function tripal_bulk_loader_set_constants_form_submit ($form, $form_state) {
+
+	// Insert/Update constants
+  $template = unserialize($form_state['values']['template']);
+  $indexes = unserialize($form_state['values']['indexes']);
+  
+  $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
+  if (strcmp('Add Constant Set',$op) == 0) {
+      $max_group = db_fetch_object(db_query("SELECT max(group_id) as value FROM tripal_bulk_loader_constants WHERE nid=%d",$form_state['values']['nid']));
+      foreach ($indexes as $record_id => $array) {
+        foreach($array as $field_id) {	
+          tripal_bulk_loader_update_constant(
+            $form_state['values']['nid'], 
+            $max_group->value+1,
+            $form_state['values'][$record_id.'-'.$field_id.'-table'], 
+            $form_state['values'][$record_id.'-'.$field_id.'-field'],
+            $record_id,
+            $field_id,
+            $form_state['values'][$record_id.'-'.$field_id]
+          );
+        }
+      }
+  }
+  
+}
+
+function theme_tripal_bulk_loader_set_constants_form ($form) {
+  $output = '';
+  
+  // Add draggable table for constant sets
+  $exposed_field_keys = array();
+  //$header[] = ' ';
+  foreach ($form['exposed_fields']['new'] as $k => $element) {
+    if (preg_match('/^\d+-\d+$/',$k)) {
+      $exposed_field_keys[] = $k;
+      $header[] = $element['#title'];
+    }
+  }
+  
+  foreach (element_children($form['exposed_fields']['existing']) as $key) {
+    $element = &$form['exposed_fields']['existing'][$key];
+    $element['group']['#attributes']['class'] = 'weight-group';
+
+    $row = array();
+    foreach ($exposed_field_keys as $k) {
+      $row[] = drupal_render($element[$k]);
+    }
+    $row[] = drupal_render($element['delete']);
+    $row[] = drupal_render($element['group']) . drupal_render($element['id']);
+    $rows[] = array('data' => $row, 'class' => 'draggable');
+  }
+  //drupal_add_tabledrag('mytable', 'order', 'sibling', 'weight-group');
+  $form['exposed_fields']['existing'] = array(
+    '#type' => 'markup',
+    '#value' => theme('table', $header, $rows, array('id' => 'mytable')) . '<br />'
+  );
+  
+  $output .= drupal_render($form);
+  return $output;
+}
+
+///////////////////////////////////////////////////////////
+// Set Constants Form (on Bulk Loader Node)
+///////////////////////////////////////////////////////////
+
+/**
+ * Edit a constant set (exposed fields in template)
+ *
+ * @param $form_state 
+ *   The current state of the form
+ * @param $node
+ *   The node to set constants for
+ * @param $group_id
+ *   The constant set to edit
+ *
+ * @return
+ *   A form array to be rendered by drupal_get_form()
+ */
+function tripal_bulk_loader_edit_constant_set_form ($form_state, $node, $group_id) {
+  $form = array();
+
+  $form['#redirect'] = 'node/'.$node->nid;
+  
+  $form['nid'] = array(
+    '#type' => 'hidden',
+    '#value' => $node->nid,
+  );
+
+  $form['group_id'] = array(
+    '#type' => 'hidden',
+    '#value' => $group_id,
+  );
+
+    
+  $form['explanation'] = array(
+    '#type' => 'item',
+    '#value' => t('The following fields are constants in the selected template that you need to set values for.')
+  );
+  
+  // Add textifelds for exposed fields of the current template
+  $exposed_fields = FALSE;
+  $indexes = array();
+  if ($node->template_id) {
+    if (isset($node->template)) {
+      foreach ($node->template->template_array as $record_id => $record) {
+        foreach ($record['fields'] as $field_id => $field) {
+          if ($field['exposed']) {
+            $exposed_fields = TRUE;
+            $indexes[$record_id][] = $field_id;
+            
+            switch($field['type']) {
+              case 'table field':
+                $form[$record_id.'-'.$field_id] = array(
+                  '#type' => 'textfield',
+                  '#title' => t($field['title']),
+                  '#description' => t($field['exposed_description']),
+                  '#default_value' => (isset($node->constants[$group_id][$record_id][$field_id]['value'])) ? $node->constants[$group_id][$record_id][$field_id]['value'] : $field['constant value'],
+                );
+              break;
+              case 'constant':
+                $form[$record_id.'-'.$field_id] = array(
+                  '#type' => 'textfield',
+                  '#title' => t($field['title']),
+                  '#description' => t('Enter the case-sensitive value of this constant for your spreadsheet'),
+                  '#default_value' => (isset($node->constants[$group_id][$record_id][$field_id]['value'])) ? $node->constants[$group_id][$record_id][$field_id]['value'] : $field['constant value'],
+                );
+              break;
+            }
+            
+            $form[$record_id.'-'.$field_id.'-table'] = array(
+              '#type' => 'hidden',
+              '#value' => $record['table'],
+            );
+            $form[$record_id.'-'.$field_id.'-field'] = array(
+              '#type' => 'hidden',
+              '#value' => $field['field'],
+            );
+            $form[$record_id.'-'.$field_id.'-type'] = array(
+              '#type' => 'hidden',
+              '#value' => $field['type'],
+            );
+          }
+        }
+      }
+    }
+  }
+  $form['template'] = array(
+    '#type' => 'hidden',
+    '#value' => serialize($node->template->template_array)
+  );
+  
+  $form['indexes'] = array(
+    '#type' => 'hidden',
+    '#value' => serialize($indexes),
+  );
+  
+  $form['save'] = array(
+    '#type' => 'submit',
+    '#value' => 'Save',
+  );
+  
+  $form['cancel'] = array(
+    '#type' => 'submit',
+    '#value' => 'Cancel',
+  );
+    
+  return $form;
+}
+
+/**
+ * Edit constants in the current constant set
+ */
+function tripal_bulk_loader_edit_constant_set_form_submit ($form, $form_state) {
+  
+  // Update constants
+  $template = unserialize($form_state['values']['template']);
+  $indexes = unserialize($form_state['values']['indexes']);
+  
+  $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
+  if (strcmp('Save',$op) == 0) {
+
+    foreach ($indexes as $record_id => $array) {
+      foreach($array as $field_id) {	
+        tripal_bulk_loader_update_constant(
+          $form_state['values']['nid'], 
+          $form_state['values']['group_id'],
+          $form_state['values'][$record_id.'-'.$field_id.'-table'], 
+          $form_state['values'][$record_id.'-'.$field_id.'-field'],
+          $record_id,
+          $field_id,
+          $form_state['values'][$record_id.'-'.$field_id]
+        );
+      }
+    }
+    drupal_set_message('The constant set was successfully updated.');
+      
+  }
+  
+}
+
+/**
+ * Delete a constant set (exposed fields in template)
+ *
+ * @param $form_state 
+ *   The current state of the form
+ * @param $node
+ *   The node to set constants for
+ * @param $group_id
+ *   The constant set to delete
+ *
+ * @return
+ *   A form array to be rendered by drupal_get_form()
+ */
+function tripal_bulk_loader_delete_constant_set_form ($form_state, $node, $group_id) {
+  $form = array();
+
+  $form['#redirect'] = 'node/'.$node->nid;
+	
+	$form['nid'] = array(
+		'#type' => 'value',
+		'#value' => $node->nid,
+	);
+
+  $form['group_id'] = array(
+    '#type' => 'hidden',
+    '#value' => $group_id,
+  );
+   
+	return confirm_form($form,
+    	t('Are you sure you want to delete this constant set?'),
+    	'node/'.$node->nid,
+    	t('This action cannot be undone.'),
+    	t('Delete'),
+    	t('Cancel')
+  );
+  
+}
+
+/**
+ * Delete the current constant set
+ */
+function tripal_bulk_loader_delete_constant_set_form_submit ($form, $form_state) {
+
+  $group_id = $form_state['values']['group_id'];
+  $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.');
+  }
+        
+}

+ 28 - 224
base/tripal_bulk_loader/tripal_bulk_loader.module

@@ -1,6 +1,7 @@
 <?php
 
 include('tripal_bulk_loader.loader.inc');
+include('tripal_bulk_loader.constants.inc');
 
 /**
  * Implements hook_init
@@ -25,6 +26,25 @@ function tripal_bulk_loader_menu() {
      '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',
@@ -126,11 +146,15 @@ function tripal_bulk_loader_menu() {
   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'
@@ -335,10 +359,12 @@ function tripal_bulk_loader_load($node){
   }
   
   // Add constants
-  $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=%d ORDER BY record_id, field_id';
+  $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->record_id][$r->field_id] = array(
+    $node->constants[$r->group_id][$r->record_id][$r->field_id] = array(
+      'constant_id' => $r->constant_id,
+      'group_id' => $r->group_id,
       'chado_table'=>$r->chado_table, 
       'chado_field'=>$r->chado_field, 
       'record_id'=>$r->record_id, 
@@ -404,228 +430,6 @@ function tripal_bulk_loader_update ($node) {
   
 }
 
-///////////////////////////////////////////////////////////
-// Set Constants Form
-///////////////////////////////////////////////////////////
-
-/**
- * Set constants (exposed fields in template)
- *
- * @param $form_state 
- *   The current state of the form
- * @param $node
- *   The node to set constants for
- *
- * @return
- *   A form array to be rendered by drupal_get_form()
- */
-function tripal_bulk_loader_set_constants_form ($form_state, $node) {
-  $form = array();
-  
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-  
-  $form['exposed_fields'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Constant Values'),
-    '#collapsible' => TRUE,
-    '#collapsed' => ($node->template_id) ? FALSE : TRUE,
-    '#prefix' => '<div id="set-constants">',
-    '#suffix' => '</div>',
-  );
-  
-  $form['exposed_fields']['explanation'] = array(
-    '#type' => 'item',
-    '#value' => t('The following fields are constants in the selected template that you need to set values for.')
-  );
-  
-  // Add textifelds for exposed fields of the current template
-  $exposed_fields = FALSE;
-  $indexes = array();
-  if ($node->template_id) {
-    if (isset($node->template)) {
-      foreach ($node->template->template_array as $record_id => $record) {
-        foreach ($record['fields'] as $field_id => $field) {
-          if ($field['exposed']) {
-            $exposed_fields = TRUE;
-            $indexes[$record_id][] = $field_id;
-            
-            switch($field['type']) {
-              case 'table field':
-                $form['exposed_fields'][$record_id.'-'.$field_id] = array(
-                  '#type' => 'textfield',
-                  '#title' => t($field['title']),
-                  '#description' => t($field['exposed_description']),
-                  '#default_value' => (isset($node->constants[$record_id][$field_id]['value'])) ? $node->constants[$record_id][$field_id]['value'] : $field['constant value'],
-                );
-              break;
-              case 'constant':
-                $form['exposed_fields'][$record_id.'-'.$field_id] = array(
-                  '#type' => 'textfield',
-                  '#title' => t($field['title']),
-                  '#description' => t('Enter the case-sensitive value of this constant for your spreadsheet'),
-                  '#default_value' => (isset($node->constants[$record_id][$field_id]['value'])) ? $node->constants[$record_id][$field_id]['value'] : $field['constant value'],
-                );
-              break;
-            }
-            
-            $form['exposed_fields'][$record_id.'-'.$field_id.'-table'] = array(
-              '#type' => 'hidden',
-              '#value' => $record['table'],
-            );
-            $form['exposed_fields'][$record_id.'-'.$field_id.'-field'] = array(
-              '#type' => 'hidden',
-              '#value' => $field['field'],
-            );
-            $form['exposed_fields'][$record_id.'-'.$field_id.'-type'] = array(
-              '#type' => 'hidden',
-              '#value' => $field['type'],
-            );
-          }
-        }
-      }
-    }
-  }
-  $form['template'] = array(
-    '#type' => 'hidden',
-    '#value' => serialize($node->template->template_array)
-  );
-  
-  $form['exposed_fields']['indexes'] = array(
-    '#type' => 'hidden',
-    '#value' => serialize($indexes),
-  );
-  
-  if (!$exposed_fields) {
-    $form['exposed_fields']['explanation'] = array(
-      '#type' => 'item',
-      '#value' => t('There are no exposed fields for this template.')
-    );    
-  }
-  
-  $form['exposed_fields']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save Changes')
-  );
-  
-  return $form;
-}
-
-/**
- * Validate that the values entered exist in the database
- * if indicated in hte template array
- */
-function tripal_bulk_loader_set_constants_form_validate ($form_state, $form) {
-
-  $template = unserialize($form_state['template']['#value']);
-  $indexes = unserialize($form_state['exposed_fields']['indexes']['#value']);
-  
-  foreach ($indexes as $record_id => $array) {
-    foreach($array as $field_id) {
-      if ($template[$record_id]['fields'][$field_id]['exposed_validate']) {
-        $result = db_fetch_object(db_query(
-          "SELECT 1 as valid FROM %s WHERE %s='%s'",
-          $template[$record_id]['table'],
-          $template[$record_id]['fields'][$field_id]['field'],
-          $form_state['exposed_fields'][$record_id.'-'.$field_id]['#value']
-        ));
-
-        if (!$result->valid) {
-          $msg = 'A '.$form_state['exposed_fields'][$record_id.'-'.$field_id]['#title'].' of "'.$form_state['exposed_fields'][$record_id.'-'.$field_id]['#value'].'" must already exist!';
-          form_set_error($record_id.'-'.$field_id, $msg);
-        } else {
-          drupal_set_message('Confirmed a '.$form_state['exposed_fields'][$record_id.'-'.$field_id]['#title'].' of "'.$form_state['exposed_fields'][$record_id.'-'.$field_id]['#value'].'" already exists.');
-        }
-      }
-    }
-  }
-  
-}
-
-/**
- * Insert/update the constants associated with this node
- */
-function tripal_bulk_loader_set_constants_form_submit ($form, $form_state) {
-
-	// Insert/Update constants
-  $template = unserialize($form_state['values']['template']);
-  $indexes = unserialize($form_state['values']['indexes']);
-  
-  foreach ($indexes as $record_id => $array) {
-    foreach($array as $field_id) {	
-      tripal_bulk_loader_update_constant(
-        $form_state['values'][nid], 
-        $form_state['values'][$record_id.'-'.$field_id.'-table'], 
-        $form_state['values'][$record_id.'-'.$field_id.'-field'],
-        $record_id,
-        $field_id,
-        $form_state['values'][$record_id.'-'.$field_id]
-        );
-    }
-  }
-  
-}
-
-/**
- * Inserts/Updates a tripal bulk loading job constant
- *
- * @param $nid
- *   The node ID of the the tripal bulk loading job the constant is associated with
- * @param $table
- *   The chado table the constant is associated with
- * @param $field
- *   The chado field the constant is associated with
- * @param $record_id
- *   The index in the template array for this record
- * @param $field_id
- *   The index in the template array for this field
- *
- * NOTE: $template_array[$record_id]['table'] = $table and $template_array[$record_id]['fields'][$field_id]['field'] = $field
- *   both are included as a means of double-checking the constant still is still in thesame place in the template array.
- *   For example, that the template was not edited and the records moved around after the job was submitted but before it was run.
- *
- * @return
- *   On success it returns the object (with primary key if inserted);
- *   on failure it returns FALSE
- */
-function tripal_bulk_loader_update_constant ($nid, $table, $field, $record_id, $field_id, $value) {
-  
-  $record = array(
-    'nid'=>$nid, 
-    'chado_table'=>$table, 
-    'chado_field'=>$field, 
-    'record_id'=>$record_id, 
-    'field_id'=>$field_id, 
-    'value'=>$value
-  );
-  
-  // Check to see if already exists
-  $exists = db_fetch_object(db_query(
-    "SELECT constant_id FROM {tripal_bulk_loader_constants} WHERE nid=%d AND record_id=%d AND field_id=%d",
-    $record['nid'],
-    $record['record_id'],
-    $record['field_id']
-  ));
-  if ($exists->constant_id) {
-    $record['constant_id'] = $exists->constant_id;
-    $status = drupal_write_record('tripal_bulk_loader_constants',$record,'constant_id');
-    if ($status) {
-      return $record;
-    } else {
-      return FALSE;
-    }
-  } else {
-    $status = drupal_write_record('tripal_bulk_loader_constants',$record);
-    if ($status) {
-      return $record;
-    } else {
-      return FALSE;
-    }
-  }
-}
-
 ///////////////////////////////////////////////////////////
 
 /**