You are here

function _ldapdata_user_update_profile in LDAP integration 6

Find out which profile attributes should be synced back to LDAP.

Parameters

$edit: A submitted form data.

$user: A user object.

Return value

An associated array of attributes to write to LDAP.

1 call to _ldapdata_user_update_profile()
_ldapdata_user_submit in ./ldapdata.module
Implements hook_user() submit operation.

File

./ldapdata.module, line 635
ldapdata provides data maping against ldap server.

Code

function _ldapdata_user_update_profile(&$edit, &$user) {
  if (_ldapdata_ldap_info($user, 'mapping_type') != LDAPDATA_MAP_ATTRIBUTES) {
    return array();
  }
  $ldap_drupal_reverse_mappings = _ldapdata_reverse_mappings($user->ldap_config);

  // Retrieve profile fields list.
  $profile_fields = _ldapdata_retrieve_profile_fields();
  if (empty($profile_fields)) {
    return array();
  }

  // Determine which profile fields are dates
  $placeholders = implode(',', array_fill(0, count($profile_fields), "'%s'"));
  $result = db_query("SELECT name, options from {profile_fields} WHERE name IN ({$placeholders}) AND type = 'date'", $profile_fields);
  $date_fields = array();
  while ($row = db_fetch_object($result)) {
    array_push($date_fields, $row->name);
  }

  // Compare against $edit list.
  $writeout = array();
  foreach ($profile_fields as $key => $field) {
    if (isset($edit[$field]) && isset($ldap_drupal_reverse_mappings[$key]) && in_array($field, $date_fields)) {

      // LDAP GeneralizedTime/Integer Format -> YYYYMMDD
      $writeout[$ldap_drupal_reverse_mappings[$key]] = sprintf('%04d%02d%02d', $edit[$field]['year'], $edit[$field]['month'], $edit[$field]['day']);
    }
    elseif (isset($edit[$field]) && isset($ldap_drupal_reverse_mappings[$key])) {
      $writeout[$ldap_drupal_reverse_mappings[$key]] = $edit[$field];
    }
  }
  return $writeout;
}