Binary files salesforce_api/.DS_Store and salesforce_api/.DS_Store differ
diff -cr salesforce_api/misc/salesforce_api.admin.css salesforce_api/misc/salesforce_api.admin.css
*** salesforce_api/misc/salesforce_api.admin.css	2010-09-01 19:01:54.000000000 -0400
--- salesforce_api/misc/salesforce_api.admin.css	2010-09-01 18:52:54.000000000 -0400
***************
*** 6,9 ****
--- 6,14 ----
  
  .fieldmap-extra-text label  {
    display: inline;
+ }
+ 
+ #salesforce-api-fieldmap-edit-form #edit-new-field-wrapper {
+   display: inline;
+   margin-right: 15px;
  }
\ No newline at end of file
diff -cr salesforce_api/salesforce_api.admin.inc salesforce_api/salesforce_api.admin.inc
*** salesforce_api/salesforce_api.admin.inc	2010-03-17 12:58:21.000000000 -0400
--- salesforce_api/salesforce_api.admin.inc	2010-09-01 19:05:09.000000000 -0400
***************
*** 294,300 ****
   */
  function salesforce_api_fieldmap_edit_form(&$form_state, $fieldmap) {
    // Load the fieldmap from the database.
!   $map = salesforce_api_fieldmap_load($fieldmap);
  
    // Return to the admin page if the fieldmap did not exist.
    if (empty($map)) {
--- 294,300 ----
   */
  function salesforce_api_fieldmap_edit_form(&$form_state, $fieldmap) {
    // Load the fieldmap from the database.
!   $map = salesforce_api_fieldmap_load($fieldmap, TRUE);
  
    // Return to the admin page if the fieldmap did not exist.
    if (empty($map)) {
***************
*** 344,349 ****
--- 344,370 ----
      '#description' => t('Automatically create and link new salesforce objects when Drupal objects are created?'),
    );
  
+   // Get a list of Salesforce-side fields which haven't been set yet.
+   $not_set = array('');
+   forEach($target['fields'] as $key => $field) {
+     if(!isSet($map['fields'][$key])) {
+       $not_set[$key] = $field['label'];
+     }
+   }
+   // Provide a control for setting a new field
+   $form['add_field'] = array(
+     '#type' => 'fieldset',
+     '#title' => t('Add a field'),
+     'new_field' => array(
+       '#type' => 'select',
+       '#options' => $not_set,
+     ),
+     'add_button' => array(
+       '#type' => 'submit',
+       '#value' => t('Add'),
+     ),
+   );
+ 
    // Add the data to the form for the required fields table.
    $form['fields'] = array(
      '#theme' => 'salesforce_api_fieldmap_edit_form_table',
***************
*** 355,363 ****
      array('#value' => t('Source: @label (@type)', array('@label' => $source['label'], '@type' => $map['action'] == 'import' ? t('Salesforce') : t('Drupal')))),
    );
  
!   // Loop through each of the target fields.
    $rows = array('required' => array(), 'optional' => array());
!   foreach ($target['fields'] as $key => $value) {    
      // Determine to which table this field should belong.
      if (!($value['type'] & (SALESFORCE_FIELD_NILLABLE | SALESFORCE_FIELD_DEFAULTEDONCREATE))) {
        // If the field is not nillable and not defaulted on create, then it must be required.
--- 376,386 ----
      array('#value' => t('Source: @label (@type)', array('@label' => $source['label'], '@type' => $map['action'] == 'import' ? t('Salesforce') : t('Drupal')))),
    );
  
!   // Loop through each of the mapped fields.
    $rows = array('required' => array(), 'optional' => array());
!   foreach (array_keys($map['fields']) as $key) {
!     $value = $target['fields'][$key];
! 
      // Determine to which table this field should belong.
      if (!($value['type'] & (SALESFORCE_FIELD_NILLABLE | SALESFORCE_FIELD_DEFAULTEDONCREATE))) {
        // If the field is not nillable and not defaulted on create, then it must be required.
***************
*** 453,458 ****
--- 476,485 ----
        $map['fields'][$field] = $form_state['values'][$field];
      }
    }
+   if(!empty($form_state['values']['new_field'])) {
+     $field = $form_state['values']['new_field'];
+     $map['fields'][$field] = 0;
+   }
  
    // set the automatic flag on the map
    $map['automatic'] = $form_state['values']['drupal_sfapi_automatic'];
***************
*** 460,469 ****
    // Save the updated fieldmap.
    salesforce_api_fieldmap_save($map);
  
!   // Display a message and return to the admin page.
!   drupal_set_message(t('The changes have been saved.'));
! 
!   $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS;
  }
  
  /**
--- 487,502 ----
    // Save the updated fieldmap.
    salesforce_api_fieldmap_save($map);
  
!   if(empty($form_state['values']['new_field'])) {
!     // Display a message and return to the admin page.
!     drupal_set_message(t('The changes have been saved.'));
!     $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS;
!   }
!   else {
!     drupal_set_message(t('Field added.'));
!     $form_state['rebuild'] = TRUE;
!     $form_state['submitted'] = FALSE;
!   }
  }
  
  /**
diff -cr salesforce_api/salesforce_api.module salesforce_api/salesforce_api.module
*** salesforce_api/salesforce_api.module	2010-09-01 19:01:09.000000000 -0400
--- salesforce_api/salesforce_api.module	2010-09-01 19:03:31.000000000 -0400
***************
*** 373,384 ****
   *
   * @param $fieldmap
   *   The index of the fieldmap to load.
   * @return
   *   An array containing the fieldmap data.
   */
! function salesforce_api_fieldmap_load($fieldmap) {
    static $maps;
!   if (!isset($maps[$fieldmap]) && $fieldmap != '') {
      $result = db_query("SELECT * FROM {salesforce_field_map} WHERE fieldmap = %d", $fieldmap);
      $map = db_fetch_array($result);
      if (isset($map['fields'])) {
--- 373,387 ----
   *
   * @param $fieldmap
   *   The index of the fieldmap to load.
+  * @param $reset
+  *   FALSE by default. If TRUE, the fieldmap will be loaded from the database
+  *   rather than from the cache.
   * @return
   *   An array containing the fieldmap data.
   */
! function salesforce_api_fieldmap_load($fieldmap, $reset = FALSE) {
    static $maps;
!   if ((!isset($maps[$fieldmap]) && $fieldmap != '') || (isset($maps[$fieldmap]) && $reset)) {
      $result = db_query("SELECT * FROM {salesforce_field_map} WHERE fieldmap = %d", $fieldmap);
      $map = db_fetch_array($result);
      if (isset($map['fields'])) {
