You are here

function location_user in Location 5

2 string references to 'location_user'
location_admin_settings in ./location.module
Callback for admin/settings/location
_location_effective_user_setting in ./location.module

File

./location.module, line 1432

Code

function location_user($op, &$edit, &$user, $category = NULL) {
  $user_setting = _location_effective_user_setting();
  if ($user_setting == LOCATION_USER_DONT_COLLECT) {
    return;
  }
  if ($op == 'form' && $category == 'account' && $user_setting == LOCATION_USER_COLLECT) {
    $form = array(
      1 => array(),
    );
    $form[0]['location'] = location_form(array(
      'street',
      'city',
      'province',
      'postal_code',
      'country',
    ), isset($user->location) && !_location_is_empty($user->location) ? location_api2form($user->location) : array(
      'country' => variable_get('location_default_country', 'us'),
    ), array(), variable_get('location_suppress_country', 0) ? array(
      'country' => variable_get('location_default_country', 'us'),
    ) : array());
    $form[0]['location']['#type'] = 'fieldset';
    $form[0]['location']['#title'] = t('Location');
    $form[0]['location']['#tree'] = TRUE;
    $form[0]['location']['#collapsible'] = TRUE;
    $form[0]['location']['#description'] = t('Enter as much of your address as you are comfortable with. Your address will only be viewable by those who have the appropriate permissions. The site will be able to automatically link you to driving directions and other features if it already knows your address.');
    if ($user->location['lid']) {
      $form[0]['location']['lid'] = array(
        '#type' => 'hidden',
        '#value' => $user->location['lid'],
      );
    }
    return $form;
  }
  if ($op == 'load' && $user_setting != LOCATION_USER_DONT_COLLECT) {
    $res = db_query("SELECT * FROM {location} WHERE type = 'user' AND eid = %d", $user->uid);
    if ($location = db_fetch_object($res)) {
      $user->location = (array) $location;
    }
    else {
      $user->location = array();
    }
  }
  if (($op == 'update' || $op == 'insert') && $category == 'account') {
    $edit['location'] = location_form2api($edit['location']);
    if ($data = location_latlon_exact($edit['location'])) {
      $edit['location']['source'] = LOCATION_LATLON_GEOCODED_EXACT;
      $edit['location']['lat'] = $data['lat'];
      $edit['location']['lon'] = $data['lon'];
    }
    elseif ($data = location_get_postalcode_data($edit['location'])) {
      $edit['location']['source'] = LOCATION_LATLON_GEOCODED_APPROX;
      $edit['location']['lat'] = $data['lat'];
      $edit['location']['lon'] = $data['lon'];
    }
    else {
      unset($edit['location']['lat']);
      unset($edit['location']['lon']);
      $edit['location']['source'] = LOCATION_LATLON_UNDEFINED;
    }
    _location_save($edit['location'] ? $edit['location'] : array(), $user, 'user');
    unset($edit['location']);
  }
  if ($user_setting == LOCATION_USER_COLLECT && $op == 'view' && (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) && variable_get('location_display_location', 1) && !_location_is_empty($user->location)) {
    $items[] = array(
      'value' => theme('location', $user->location),
      'class' => 'location',
    );
    if (user_access('submit latitude/longitude')) {
      if ($user->location['latitude'] != NULL && $user->location['longitude'] != NULL) {
        $items[] = array(
          'title' => t('Coordinates'),
          'value' => t('lat: %latitude', array(
            '%latitude' => $user->location['latitude'],
          )) . '<br/>' . t('lon: %longitude', array(
            '%longitude' => $user->location['longitude'],
          )),
          'class' => 'location',
        );
      }
    }
    return array(
      t('Location') => $items,
    );
  }
}