You are here

function ip_geoloc_ip_lookup_submit in IP Geolocation Views & Maps 7

Lookup geoloc data.

1 string reference to 'ip_geoloc_ip_lookup_submit'
ip_geoloc_ip_lookup_form in ./ip_geoloc_blocks.inc
Generates a simple form for collecting the IP address to be reverse-geocoded.

File

./ip_geoloc_blocks.inc, line 934
Blocks available in IP Geolocation Views & Maps.

Code

function ip_geoloc_ip_lookup_submit($form, &$form_state) {
  $store = !empty($form_state['values']['store']);
  $location = ip_geoloc_get_location_by_ip(trim($form_state['values']['ip_address']), TRUE, $store);
  if (db_table_exists('accesslog')) {
    $last_visit = db_query('SELECT MAX(timestamp) FROM {accesslog} WHERE hostname = :ip_address', array(
      ':ip_address' => $location['ip_address'],
    ))
      ->fetchField();
    if ($last_visit) {
      $last_visit = format_date($last_visit, 'short');
      $form_state['storage']['last_visit'] = t('<strong>Last visit:</strong> %date', array(
        '%date' => $last_visit,
      ));
    }
  }
  $form_state['storage']['formatted_address'] = isset($location['formatted_address']) ? t('%ip: <strong>%address</strong>', array(
    '%ip' => $location['ip_address'],
    '%address' => $location['formatted_address'],
  )) : '';

  // To preserve entered values and storage array.
  $form_state['rebuild'] = TRUE;
}