function chado_contact_form

2.x tripal_contact.chado_node.inc chado_contact_form(&$node, $form_state)
3.x tripal_contact.chado_node.inc chado_contact_form(&$node, $form_state)
1.x tripal_contact.form.inc chado_contact_form(&$node, $form_state)

Implementation of tripal_contact_form().

@parm $node The node that is created when the database is initialized

@parm $form_state The state of the form, that has the user entered information that is neccessary for, setting up the database tables for the contact

Return value

$form The information that was enterd allong with

File

tripal_contact/includes/tripal_contact.form.inc, line 18

Code

function chado_contact_form(&$node, $form_state) {
  tripal_core_ahah_init_form();
  $form = array();

  $contact = $node->contact;
  $contact_id = $contact->contact_id;

  $d_title = $form_state['values']['title'] ? $form_state['values']['title'] : $contact->name;
  $d_description = $form_state['values']['description'] ? $form_state['values']['description'] : $contact->description;
  $d_type_id = $form_state['values']['type_id'] ? $form_state['values']['type_id'] : $contact->type_id->cvterm_id;

  // on AHAH callbacks we want to keep a list of all the properties that have been removed
  // we'll store this info in a hidden field and retrieve it here
  $d_removed = $form_state['values']['removed'];

  // get the number of new fields that have been aded via AHAH callbacks
  $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;

  // initialze default properties array. This is where we store the property defaults
  $d_properties = array();

  // get the contact default values.  When this module was first created
  // the contact description was incorrectly stored in the $node->body field.
  // It is better to store it in the Chado tables.  However, the 'description'
  // field of the contact table is only 255 characters.  So, we are going
  // to follow the same as the contact module and store the description in
  // the contactprop table and leave the contact.description field blank.
  // however, for backwards compatibitily, we check to see if the description
  // is in the $node->body field. If it is we'll use that.  When the node is
  // edited the text will be moved out of the body and into the contactprop
  // table where it should belong.
  if ($node->body) {
    $description = $node->body;
  }
  else {
    $description = $node->description;
  }
  if (!$description) {
    $contactprop = tripal_contact_get_property($contact->contact_id, 'contact_description');
    $description = $contactprop->value;
  }

  // keep track of the contact id if we have.  If we do have one then
  // this is an update as opposed to an insert.
  $form['contact_id'] = array(
    '#type' => 'hidden',
    '#value' => $contact_id,
  );

  // get the contact type
  $sql = "
    SELECT CVTS.cvterm_id, CVTS.name
    FROM {cvtermpath} CVTP
      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
      INNER JOIN {cv} CV       ON CVTO.cv_id = CV.cv_id
    WHERE 
      CV.name = 'tripal_contact' AND 
      CVTO.name = 'Contact Type' AND
      CVTP.pathdistance = 1      
    ORDER BY CVTS.name ASC 
  ";
  $results = chado_query($sql);
  $contact_types = array();
  while ($contact_type = db_fetch_object($results)) {
    $contact_types[$contact_type->cvterm_id] = $contact_type->name;
    if (strcmp($contact_type->name, "Person") == 0 and !$d_type_id) {
      $d_type_id = $contact_type->cvterm_id;
    }
  }

  // get the contact properties 
  $properties_select = array();
  $properties_select[] = 'Select a Property';
  $properties_list = array();
  $sql = "
    SELECT CVTS.cvterm_id, CVTS.name
    FROM {cvtermpath} CVTP
      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
      INNER JOIN {cv} CV       ON CVTO.cv_id = CV.cv_id
    WHERE 
      CV.name = 'tripal_contact' AND 
      NOT CVTO.name = 'Contact Type' 
    ORDER BY CVTS.name ASC 
  ";
  $prop_types = chado_query($sql);
  while ($prop = db_fetch_object($prop_types)) {
    $properties_select[$prop->cvterm_id] = $prop->name;
    $properties_list[$prop->cvterm_id] = $prop;
  }

  $form['type_id'] = array(
    '#type' => 'select',
    '#title' => t('Contact Type'),
    '#options' => $contact_types,
    '#required' => TRUE,
    '#default_value' => $d_type_id,
  );

  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Contact Name'),
    '#description' => t('Enter the name of this contact'),
    '#required' => TRUE,
    '#default_value' => $d_title,
    '#weight' => 1,
    '#maxlength' => 255,
  );

  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Contact Description'),
    '#description' => t('A brief description of the contact'),
    '#required' => TRUE,
    '#default_value' => $d_description,
    '#weight' => 5
  );

  // add in the properties from the contactprop table
  $num_properties += chado_contact_node_form_add_contactprop_table_props($form, $form_state, $contact_id, $d_properties, $d_removed);

  // add in any new properties that have been added by the user through an AHAH callback
  $num_new = chado_contact_node_form_add_new_props($form, $form_state, $d_properties, $d_removed);

  // add an empty row of field to allow for addition of a new property
  chado_contact_node_form_add_new_empty_props($form, $properties_select);


  return $form;

}