function tripal_db_db_edit_form

2.x tripal_db.admin.inc tripal_db_db_edit_form($form, &$form_state)

Form to edit existing databases. Implements hook_form().

Related topics

1 string reference to 'tripal_db_db_edit_form'
tripal_db_menu in tripal_db/tripal_db.module
Implements hook_menu().

File

tripal_db/includes/tripal_db.admin.inc, line 54
Provide administration of dbs & dbxrefs

Code

function tripal_db_db_edit_form($form, &$form_state) {

  // get the dbid if form was submitted via AJAX
  $dbid = 0;
  if (array_key_exists('values', $form_state)) {
    $dbid = $form_state['values']['dbid'];
  }
  elseif (isset($form_state['build_info']['args'][0])) {
    $dbid = $form_state['build_info']['args'][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[] = 'Select a database';
  foreach ($results as $db) {
    $dbs[$db->db_id] = $db->name;
  }

  $form['dbid'] = array(
    '#title' => t('External Database Name'),
    '#type' => 'select',
    '#options' => $dbs,
    '#ajax' => array(
      'callback' => 'tripal_db_edit_form_ajax',
      'wrapper' => 'db-edit-div',
      'effect' => 'fade',
      'event' => 'change',
      'method' => 'replace',
    ),
    '#default_value' => $dbid,
  );


  // if we don't have a db_id then we can  return the form, otherwise
  // add in the other fields
  if ($dbid) {
    tripal_db_add_db_form_fields($form, $form_state, $dbid);

    $form['update'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
    );
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#attributes' => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
    );
  }
  else {
    // if we don't have a dbid then this is the first time the form has
    // benn loaded and we need to create the div where ajax replacement elements get stored
    $form['div_replace'] = array(
      '#type' => 'item',
      '#prefix' => '<div id="db-edit-div">',
      '#suffix' => '</div>',
    );
  }
  return $form;
}