You are here

function _location_save in Location 5

Saves a location. Needs a $user or $node object.

Parameters

$posted_location: The array

3 calls to _location_save()
location_extra_form_submit in ./location.module
location_nodeapi in ./location.module
Implementation of hook_nodeapi().
location_user in ./location.module

File

./location.module, line 1517

Code

function _location_save($posted_location, &$user_or_node, $type = 'node') {
  $field = $type == 'node' ? 'vid' : 'uid';
  if (isset($posted_location) && count($posted_location)) {
    $lid = $posted_location['lid'] ? $posted_location['lid'] : db_next_id('{location}_lid');
    $posted_location['lid'] = $lid;
    location_invoke_locationapi($posted_location, 'save');
    if (isset($posted_location['lat']) && isset($posted_location['lon'])) {
      db_query("DELETE FROM {location} WHERE lid = %d", $lid);
      db_query("INSERT INTO {location} (lid, type, eid, name, street, additional, city, province, postal_code, country, latitude, longitude, source) VALUES (%d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', %d)", $lid, $type, $user_or_node->{$field}, !isset($posted_location['name']) || is_null($posted_location['name']) ? '' : $posted_location['name'], !isset($posted_location['street']) || is_null($posted_location['street']) ? '' : $posted_location['street'], !isset($posted_location['additional']) || is_null($posted_location['additional']) ? '' : $posted_location['additional'], !isset($posted_location['city']) || is_null($posted_location['city']) ? '' : $posted_location['city'], !isset($posted_location['province']) || is_null($posted_location['province']) ? '' : $posted_location['province'], !isset($posted_location['postal_code']) || is_null($posted_location['postal_code']) ? '' : $posted_location['postal_code'], !isset($posted_location['country']) || is_null($posted_location['country']) ? NULL : $posted_location['country'], $posted_location['lat'], $posted_location['lon'], $posted_location['source']);
    }
    else {
      db_query("DELETE FROM {location} WHERE lid = %d", $lid);
      db_query("INSERT INTO {location} (lid, type, eid, name, street, additional, city, province, postal_code, country, source) VALUES (%d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $lid, $type, $user_or_node->{$field}, !isset($posted_location['name']) || is_null($posted_location['name']) ? '' : $posted_location['name'], !isset($posted_location['street']) || is_null($posted_location['street']) ? '' : $posted_location['street'], !isset($posted_location['additional']) || is_null($posted_location['additional']) ? '' : $posted_location['additional'], !isset($posted_location['city']) || is_null($posted_location['city']) ? '' : $posted_location['city'], !isset($posted_location['province']) || is_null($posted_location['province']) ? '' : $posted_location['province'], !isset($posted_location['postal_code']) || is_null($posted_location['postal_code']) ? '' : $posted_location['postal_code'], !isset($posted_location['country']) || is_null($posted_location['country']) ? NULL : $posted_location['country'], $posted_location['source']);
    }
  }
}