Ver Fonte

Fixed tripal db module to use Tripal API, adjusted the help text, validates if database name already exists before trying to add/edit. And added checks in tripal core select/insert/update/delete functions to make sure and arguments are arrays and they have values

spficklin há 12 anos atrás
pai
commit
66ef98e133

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

@@ -121,6 +121,18 @@ require_once "tripal_core.schema_v1.11.api.inc";
  * @ingroup tripal_chado_api
  */
 function tripal_core_chado_insert($table, $values, $options = array()) {
+  
+  if (!is_array($values)) {
+    watchdog('tripal_core', 'Cannot pass non array as values for inserting.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;  
+  }
+  if (count($values)==0) {
+    watchdog('tripal_core', 'Cannot pass an empty array as values for inserting.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;
+  }
+  
   // set defaults for options. If we don't set defaults then
   // we get memory leaks when we try to access the elements
   if (!is_array($options)) {
@@ -462,6 +474,28 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
  */
 function tripal_core_chado_update($table, $match, $values, $options = NULL) {
 
+  if (!is_array($values)) {
+    watchdog('tripal_core', 'Cannot pass non array as values for updating.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;  
+  }
+  if (count($values)==0) {
+    watchdog('tripal_core', 'Cannot pass an empty array as values for updating.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;
+  }
+  
+  if (!is_array($match)) {
+    watchdog('tripal_core', 'Cannot pass non array as values for matching.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;  
+  }
+  if (count($match)==0) {
+    watchdog('tripal_core', 'Cannot pass an empty array as values for matching.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;
+  }
+  
   // set defaults for options. If we don't set defaults then
   // we get memory leaks when we try to access the elements
   if (!is_array($options)) {
@@ -840,6 +874,18 @@ function tripal_core_chado_update($table, $match, $values, $options = NULL) {
  * @ingroup tripal_chado_api
  */
 function tripal_core_chado_delete($table, $match, $options = NULL) {
+  
+  if (!is_array($match)) {
+    watchdog('tripal_core', 'Cannot pass non array as values for matching.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;  
+  }
+  if (count($match)==0) {
+    watchdog('tripal_core', 'Cannot pass an empty array as values for matching.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;
+  }
+  
   // set defaults for options. If we don't set defaults then
   // we get memory leaks when we try to access the elements
   if (!is_array($options)) {
@@ -1123,6 +1169,28 @@ function tripal_core_chado_delete($table, $match, $options = NULL) {
  */
 function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
 
+  if (!is_array($values)) {
+    watchdog('tripal_core', 'Cannot pass non array as values for selecting.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;  
+  }
+  if (count($values)==0) {
+    watchdog('tripal_core', 'Cannot pass an empty array as values for selecting.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;
+  }
+  
+  if (!is_array($columns)) {
+    watchdog('tripal_core', 'Cannot pass non array as columns for selecting.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;  
+  }
+  if (count($columns)==0) {
+    watchdog('tripal_core', 'Cannot pass an empty array as columns for selecting.', array(), 
+      WATCHDOG_ERROR);
+    return FALSE;
+  }
+  
   // set defaults for options. If we don't set defaults then
   // we get memory leaks when we try to access the elements
   if (!is_array($options)) {
@@ -3396,8 +3464,8 @@ function tripal_core_get_chado_version($exact = FALSE, $warn_if_unsupported = FA
   if (strcmp($exact_version, '1.11 or older') == 0) {
     $exact_version = "1.11";
     if ($warn_if_unsupported) {
-      drupal_set_message(t("WARNING: Tripal does not fully support Chado version less than v1.1.  If you are certain this is v1.1
-         of if Chado was installed using an earlier version of Tripal then all is well. If not please upgrade to v1.1 or later"),
+      drupal_set_message(t("WARNING: Tripal does not fully support Chado version less than v1.11.  If you are certain this is v1.11
+         of if Chado was installed using an earlier version of Tripal then all is well. If not please upgrade to v1.11 or later"),
          'warning');
     }
   }

+ 0 - 0
tripal_db/tripal_db.api.inc → tripal_db/api/tripal_db.api.inc


+ 322 - 0
tripal_db/includes/tripal_db.admin.inc

@@ -0,0 +1,322 @@
+<?php
+/**
+ * Purpose: Provide Guidance to new Tripal Admin
+ *
+ * @return HTML Formatted text
+ *
+ * @ingroup tripal_db
+ */
+function tripal_db_module_description_page() {
+  $text = '';
+
+  $text = '<h3>Tripal External Database Administrative Tools Quick Links</h3>';
+  $text .= '<ul>';
+  $text .= '<li>' . l('Add an external database for cross-refernces.', 'admin/tripal/tripal_db/add_db') . '</li>';
+  $text .= '<li>' . l('Update or delete an external database.', 'admin/tripal/tripal_db/edit_db') . '</li>';
+  $text .= '</ul><br>';
+
+  $text .= '<h3>Module Description:</h3>';
+  $text .= '<p>The Tripal DB Module provides the ability to add database cross reference to the 
+    data in your Tripal Website.  Typically an external database (such as NCBI Genbank, Gene Ontology (GO),
+    stocks database) contains a collection of objects (genomic sequences, vocabulary terms, stocks) that are 
+    uniquely identified using an accession number (or identifier).  Data loaded into Tripal can be a
+    associated with these objects in remote databases, and links can appear on pages allowing site visitors
+    to view the associated objects on the remote database\'s website </p>';
+
+  $text .= '<h3>Setup Instructions:</h3>';
+  $text .= '<ol>';
+  $text .= '<li><b>Set Permissions</b>: This module supports the Drupal user permissions interface for
+               controlling administrative access for creating, editing and deleting database cross-reference resources. 
+               The default is that only the site administrator has these
+               permissions.  Best practice is to create <a href="' . url('admin/user/roles') . '">a new role</a> 
+               for administrative tasks, (such as a webmaster role),
+               and then <a href="' . url('admin/user/user') . '">assign users to the role</a>. Finally,
+               <a href="' . url('admin/user/permissions') . '">assign the permission</a> titled "administer tripal db cross-reference".
+               to the new role.</li>';
+  $text .= '<li><b>Adding or Editing an External Databases</b>. Many resources such as NCBI nr or ExPASy SwissProt (to name a few) 
+            come pre-loaded with Chado.  However, you can add new entries or edit existing entries. Also, when loading 
+            ontologies (controlled vocabularies) using the Tripal CV module new databases are added automaticaly for 
+            each ontology.  To enable linking of accession on a page to the page for that accession on the external
+            database, simply add the URL and the URL prefix when adding or editing a database.</li>';
+  
+  $text .= '<li><b>Associate Data with Accessions</b>.  The Tripal loaders (e.g. GFF, OBO) can associate accessions from
+            remote data to genomic features and controlled vocabularies automatically.  Use the loaders to load genomic
+            features and controlled vocabularies respectively.  Additionally, the bulk loader can be used to create
+            loading templates for associating external database accessions.  
+            </li>';
+  $text .= '</ol>';
+
+
+  $text .= '<br><h3>Features of this Module:</h3>';
+  $text .= '<ul>';
+  $text .= '<li><b>Add an External Databases</b>:';
+  $text .= 'By entering the name and any additional details into the <a href="tripal_db/add_db">add database form</a> you register an external database with your website. This allows you to specify that a sequence feature or other data is also stored in an external database. This is escpecially useful if the external database may contain additional details not stored in yours. If the external database is online you can even provide a URL prefix which will automatically link any data in your website to theirs via a web link.</li>';
+
+  $text .= '<li><b>Update or Delete and External Databases</b>';
+  $text .= 'To edit the details of an external database record or to delete an already existing external database, go to the <a href="tripal_db/edit_db">Update/Delete DBs form</a>. This will allow you to change details or enter new details.</li>';
+
+  $text .= '</ul>';
+
+  return $text;
+}
+/**
+ *
+ *
+ * @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;
+}
+/**
+ *
+ *
+ * @ingroup tripal_db
+ */
+function tripal_db_select_form() {
+
+
+
+  return $form;
+}
+/**
+ *
+ * @ingroup tripal_db
+ */
+function tripal_ajax_db_edit() {
+  $status = TRUE;
+
+  // prepare and render the form
+  $form = tripal_core_ahah_prepare_form();   
+  $data = drupal_render($form);  
+
+  // bind javascript events to the new objects that will be returned 
+  // so that AHAH enabled elements will work.
+  $settings = tripal_core_ahah_bind_events();
+
+  // return the updated JSON
+  drupal_json(
+    array(
+      'status'   => $status, 
+      'data'     => $data,
+      'settings' => $settings,
+    )  
+  );
+}
+
+/**
+ *
+ * @ingroup tripal_db
+ */
+function tripal_db_form(&$form_state = NULL, $action = 'Update') {
+  
+  $dbid = $form_state['values']['dbid'];
+  
+  
+  if (strcmp($action,'Update')==0) {
+    // get a list of db from chado for user to choose
+    $sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
+    $results = chado_query($sql);
+  
+    $dbs = array();
+    $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',
+      ),
+      '#prefix' => '<div id="db-edit-div">',
+      '#suffix' => '</div>',
+      '#default_value' => $dbid,
+      '#description' => t('Please select a database to edit'),
+    );
+  }   
+  else {
+    $default_db = $form_state['values']['name'];
+    $default_desc = $form_state['values']['description'];
+    $default_url = $form_state['values']['url'];
+    $default_urlprefix = $form_state['values']['urlprefix']; 
+  }
+  
+  // get this requested database
+  if ($dbid) {
+    $values = array('db_id' => $dbid);
+    $result = tripal_core_chado_select('db', array('*'), $values);
+    $db = $result[0];
+    $prev_dbid = $form_state['values']['prev_dbid'];
+    // if the database has changed then repopulate the fields with the databaes values
+    if ($prev_dbid != $dbid) {
+      $default_db        = $db->name;
+      $default_desc      = $db->description;
+      $default_url       = $db->url;
+      $default_urlprefix = $db->urlprefix;
+    }
+    // if the database did not change then keep the values in the form values
+    else {
+      $default_db = $form_state['values']['name'];
+      $default_desc = $form_state['values']['description'];
+      $default_url = $form_state['values']['url'];
+      $default_urlprefix = $form_state['values']['urlprefix'];      
+    }
+  }
+  
+  $form['form_action'] = array(
+    '#type' => 'hidden',
+    '#value' => $action, 
+  );  
+
+  // we need to distinguish between edits in a field that may have failed
+  // and when the user selects a different database from the list.  
+  $form['prev_dbid'] = array(
+    '#type' => 'hidden',
+    '#value' => $dbid, 
+  );  
+  
+  // if we want to update a database but the user has not
+  // yet selected a database then return so we don't show the other fields
+  // the rest of the fields will be added with the AHAH callback. 
+  if (strcmp($action,'Update')==0 and !$dbid) {
+    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,
+    );
+  }
+
+  return $form;
+}
+/**
+ *
+ * @ingroup tripal_db
+ */
+function tripal_db_form_validate($form, &$form_state) {
+  $name =  trim($form_state['values']['name']);
+  $desc =  trim($form_state['values']['description']);
+  $url  =  trim($form_state['values']['url']);
+  $urlp =  trim($form_state['values']['urlprefix']);
+  $dbid =  trim($form_state['values']['dbid']);
+  $op   =  trim($form_state['values']['op']);
+  $action =  $form_state['values']['form_action'];
+ 
+  // make sure the database name is unique
+  $values = array('name' => $name);
+  $results = tripal_core_chado_select('db', array('db_id'), $values);   
+  if (count($results) > 0 and $results[0]->db_id != $dbid) {
+    form_set_error('name', 'The database name must be unique');
+  }
+}
+/**
+ *
+ * @ingroup tripal_db
+ */
+function tripal_db_form_submit($form, &$form_state) {
+
+  $name =  trim($form_state['values']['name']);
+  $desc =  trim($form_state['values']['description']);
+  $url  =  trim($form_state['values']['url']);
+  $urlp =  trim($form_state['values']['urlprefix']);
+  $dbid =  trim($form_state['values']['dbid']);
+  $op   =  trim($form_state['values']['op']);
+
+  $values = array(
+    'name' => $name,
+    'description' => $desc,
+    'url' => $url,
+    'urlprefix' => $urlp,
+  );
+  if ($dbid) {
+    if (strcmp($op, 'Update')==0) {      
+      $match = array('db_id' => $dbid);
+      $success = tripal_core_chado_update('db', $match, $values);
+      if ($success) {
+        drupal_set_message(t("External database updated"));
+      }
+      else {
+        drupal_set_message(t("Failed to update external database."));
+      }
+    }
+    if (strcmp($op, 'Delete')==0) {
+      $match = array('db_id' => $dbid);
+      $success = tripal_core_chado_delete('db', $match);
+      if ($success) {
+        drupal_set_message(t("External database deleted"));
+      }
+      else {
+        drupal_set_message(t("Failed to delete external database."));
+      }
+    }
+  }
+  else {
+    $success = tripal_core_chado_insert('db', $values);
+    if ($success) {
+      drupal_set_message(t("External database added"));
+    }
+    else {
+      drupal_set_message(t("Failed to add external database."));
+    }
+  }
+}

+ 25 - 279
tripal_db/tripal_db.module

@@ -1,6 +1,7 @@
 <?php
 
-require_once "tripal_db.api.inc";
+require_once "api/tripal_db.api.inc";
+require_once "includes/tripal_db.admin.inc";
 
 /**
  * @defgroup tripal_db DB Module
@@ -28,28 +29,32 @@ function tripal_db_menu() {
     'title' => 'Databases',
     'description' => 'Basic Description of Tripal DB Module Functionality',
     'page callback' => 'tripal_db_module_description_page',
-    'access arguments' => array('administer site configuration'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer tripal db cross-references'),
     'type' => MENU_NORMAL_ITEM,
   );
 
   $items['admin/tripal/tripal_db/edit_db'] = array(
-    'title' => 'Update/Delete Database References',
+    'title' => 'Edit a Database',
     'description' => 'Manage Databases ',
-    'page callback' => 'tripal_db_admin_page',
-    'access arguments' => array('administer site configuration'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_db_form', 'Update'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer tripal db cross-references'),
     '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'),
+    'page arguments' => array('tripal_db_form', 'Add'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer tripal db cross-references'),
     'type' => MENU_NORMAL_ITEM,
   );
   $items['admin/tripal/tripal_db/edit/js'] = array(
-    'title' => 'Edit Databases',
     'page callback' => 'tripal_ajax_db_edit',
+    'access callback' => 'user_access',
     'access arguments' => array('access administration pages'),
     'type' => MENU_CALLBACK,
   );
@@ -66,10 +71,7 @@ function tripal_db_menu() {
  */
 function tripal_db_perm() {
   return array(
-    'access chado_db content',
-    'create chado_db content',
-    'delete chado_db content',
-    'edit chado_db content',
+    'administer tripal db cross-references',
   );
 }
 
@@ -85,272 +87,16 @@ function tripal_db_views_api() {
   return array('api' => 2.0);
 }
 
-/**
- * Purpose: Provide Guidance to new Tripal Admin
- *
- * @return HTML Formatted text
- *
- * @ingroup tripal_db
- */
-function tripal_db_module_description_page() {
-  $text = '';
-
-  $text = '<h3>Tripal External Database Administrative Tools Quick Links</h3>';
-    $text .= '<ul>';
-      $text .= '<li>' . l('Add External DB', 'admin/tripal/tripal_db/add_db') . '</li>';
-      $text .= '<li>' . l('Update/Delete External DBs', 'admin/tripal/tripal_db/edit_db') . '</li>';
-      $text .= '<li>' . l('Database References Listing', 'admin/tripal/tripal_db/list_dbxrefs') . '</li>';
-    $text .= '</ul>';
-
-  $text .= '<h3>Module Description:</h3>';
-  $text .= '<p>The Tripal DB Module provides functionality for linking the data in your Tripal Website with other biological websites out there. Essentially you register an enternal database with your website and then associate any of your data (usually sequence features) with that external database by providing the accession for your data in the other database. If the other database is online and you provided a URL prefix when you registered the external database with your site then there will be a link on the details page for your data that takes the user to the same record in the external database.</p>';
-
-  $text .= '<h3>Setup Instructions:</h3>';
-  $text .= '<ol>';
-  $text .= '<li><p><b>Set Permissions</b>: The feature module supports the Drupal user permissions interface for
-               controlling access to feature content and functions. These permissions include viewing,
-               creating, editing or administering of
-               feature content. The default is that only the original site administrator has these
-               permissions.  You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
-               <a href="' . url('admin/user/user') . '">assign users to roles</a> and
-               <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the feature content to
-               those roles.  For a simple setup, allow anonymous users access to view organism content and
-               allow the site administrator all other permissions.</p></li>';
-  $text .= '<li><b>Register any external databases</b> with data pertinent to your site.</li>';
-  $text .= '<li><b>Create Database References</b>: Then as you load in your data, create database references linking your data to the external database.</li>';
-  $text .= '</ol>';
-
-
-  $text .= '<h3>Features of this Module:</h3>';
-  $text .= '<ul>';
-  $text .= '<li><b>Add/Register External Databases</b>:';
-  $text .= 'By entering the name and any additional details into the <a href="tripal_db/add_db">add database form</a> you register an external database with your website. This allows you to specify that a sequence feature or other data is also stored in an external database. This is escpecially useful if the external database may contain additional details not stored in yours. If the external database is online you can even provide a URL prefix which will automatically link any data in your website to theirs via a web link.</li>';
-
-  $text .= '<li><b>Update/Delete External Databases</b>';
-  $text .= 'To edit the details of an external database record or to delete an already existing external database, go to the <a href="tripal_db/edit_db">Update/Delete DBs form</a>. This will allow you to change details or enter new details.</li>';
-
-  $text .= '<li><b>List all External Database References</b>';
-  $text .= 'If you have views installed, there will be a link to a default listing of all database references currently in your database. This listing can be accessed <a href="tripal_db/list_dbxrefs">here</a>. It requires the Drupal Module Views version 2 to be installed (<a href="http://drupal.org/project/views">Drupal Views</a>)</li>';
-  $text .= '</ul>';
-
-  return $text;
-}
-
-/**
- *
- *
- * @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;
-}
-/**
- *
- *
- * @ingroup tripal_db
- */
-function tripal_db_select_form() {
-
-  // get a list of db from chado for user to choose
-  $sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
-  $results = chado_query($sql);
-
-  $dbs = array();
-  $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',
-    ),
-  );
-
-  return $form;
-}
-/**
- *
- * @ingroup tripal_db
- */
-function tripal_ajax_db_edit() {
-  // 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
- */
-function tripal_db_form(&$form_state = NULL, $dbid = NULL) {
-
-  // get this requested database
-  if ($dbid) {
-    $sql = "SELECT * FROM {db} WHERE db_id = %d ";
-    $db = db_fetch_object(chado_query($sql, $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;
-}
-/**
- *
- * @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
-      ";
-      $db = chado_query($sql, $name, $desc, $url, $urlp, $dbid);
-      if ($db) {
-        drupal_set_message(t("External database updated"));
-      }
-      else {
-        drupal_set_message(t("Failed to update external database."));
-      }
+function tripal_db_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == "tripal_db_form") {    
+    // updating the form through the ahah callback sets the action of
+    // the form to the ahah callback URL. We need to set it back
+    // to the normal form URL 
+    if ($form_state['values']['form_action'] == 'Update') {
+      $form['#action'] = url("admin/tripal/tripal_db/edit_db");
     }
-    if (strcmp($op, 'Delete')==0) {
-      $sql = "
-        DELETE FROM {db}
-        WHERE db_id = %d
-        ";
-      $db = chado_query($sql, $dbid);
-      if ($db) {
-        drupal_set_message(t("External database deleted"));
-      }
-      else {
-        drupal_set_message(t("Failed to delete external database."));
-      }
+    if ($form_state['values']['form_action'] == 'Add') {
+      $form['#action'] = url("admin/tripal/tripal_db/add_db");
     }
-  }
-  else {
-    $sql = "
-          INSERT INTO {db}
-          (name,description,url,urlprefix)
-          VALUES
-          ('%s','%s','%s','%s')
-          ";
-    $db = chado_query($sql, $name, $desc, $url, $urlp);
-    if ($db) {
-      drupal_set_message(t("External database added"));
-    }
-    else {
-      drupal_set_message(t("Failed to add external database."));
-    }
-  }
-
-  return '';
-}
+  } 
+}