function chado_contact_node_form_add_contactprop_table_props

1.x tripal_contact.form.inc chado_contact_node_form_add_contactprop_table_props(&$form, $form_state, $contact_id, &$d_properties, &$d_removed)
1 call to chado_contact_node_form_add_contactprop_table_props()
chado_contact_form in tripal_contact/includes/tripal_contact.form.inc
Implementation of tripal_contact_form().

File

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

Code

function chado_contact_node_form_add_contactprop_table_props(&$form, $form_state, $contact_id, &$d_properties, &$d_removed) {

  // get the properties for this contact
  $num_properties = 0;

  if (!$contact_id) {
    return $num_properties;
  }

  $sql = "
    SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
    FROM {contactprop} PP
      INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
    WHERE PP.contact_id = %d
    ORDER BY CVT.name, PP.rank
  ";
  $contact_props = chado_query($sql, $contact_id);
  while ($prop = db_fetch_object($contact_props)) {

    $type_id = $prop->cvterm_id;
    $rank = count($d_properties[$type_id]);

    // skip the description as we have a separate form element for that
    if ($prop->name == "contact_description") {
      continue;
    }

    // skip any properties that the user requested to delete through a previous
    // AHAH callback or through the current AHAH callback
    if ($d_removed["$type_id-$rank"]) {
      continue;
    }
    if ($form_state['post']['remove-' . $type_id . '-' . $rank]) {
      $d_removed["$type_id-$rank"] = 1;
      continue;
    }

    $d_properties[$type_id][$rank]['name'] = $prop->name;
    $d_properties[$type_id][$rank]['id'] = $type_id;
    $d_properties[$type_id][$rank]['value'] = $prop->value;
    $d_properties[$type_id][$rank]['definition'] = $prop->definition;
    $num_properties++;

    $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
      '#type' => 'item',
      '#value' => $prop->name,
    );
    $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
      '#type' => 'textarea',
      '#default_value' => $prop->value,
      '#cols' => 50,
      '#rows' => $rows,
      '#description' => $prop->definition,
    );

    $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
      '#type' => 'image_button',
      '#value' => t('Remove'),
      '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
      '#ahah' => array(
        'path' => "tripal_contact/properties/minus/$type_id/$rank",
        'wrapper' => 'tripal-contact-edit-properties-table',
        'event' => 'click',
        'method' => 'replace',
      ),
      '#attributes' => array('onClick' => 'return false;'),
    );
  }
  return $num_properties;
}