You are here

function uc_ip2country_admin_settings_submit in IP-based Determination of a Visitor's Country 5

Process Forms submitted by IP to Country administration page

File

./uc_ip2country.module, line 348
Determination of user's Country based on IP

Code

function uc_ip2country_admin_settings_submit($form_id, $form_values) {
  global $user;

  // Check to see if debug set
  if ($form_values['ip2country_debug']) {

    // Debug on
    if ($form_values['ip2country_test_type']) {

      // Dummy IP Address
      $ip = $form_values['ip2country_test_ip_address'];
      $country_code = uc_ip2country_get_country($ip);
    }
    else {

      // Dummy Country
      $country_code = db_result(db_query("SELECT country_iso_code_2 FROM {uc_countries} WHERE country_id = %d", $form_values['ip2country_test_country']));
    }
    drupal_set_message(t('Using DEBUG value for Country - @country', array(
      '@country' => $country_code,
    )));
  }
  else {

    // Debug off - make sure we set/reset IP/Country to their real values
    $ip = $_SERVER['REMOTE_ADDR'];
    $country_code = uc_ip2country_get_country($ip);
    drupal_set_message(t('Using ACTUAL value for Country - @country', array(
      '@country' => $country_code,
    )));
  }

  // Finally, save country, if it has been determined
  if ($country_code) {

    // Store the ISO country code in the $user object
    user_save($user, array(
      'country_iso_code_2' => $country_code,
    ));
  }
  system_settings_form_submit($form_id, $form_values);
}