You are here

function _ip2country_update in IP-based Determination of a Visitor's Country 7

Same name and namespace in other branches
  1. 5 uc_ip2country.module \_ip2country_update()
  2. 6 ip2country.admin.inc \_ip2country_update()

AJAX callback to update the IP to Country database.

Parameters

string $rir: String with name of IP registry. One of 'afrinic', 'arin', 'lacnic', 'ripe'. Not case sensitive.

Return value

string JSON object for display by jQuery script.

2 string references to '_ip2country_update'
ip2country_menu in ./ip2country.module
Implements hook_menu().
ip2country_test_menu in tests/ip2country_test.module
Implements hook_menu().

File

./ip2country.admin.inc, line 46
Determination of user's Country based on IP address.

Code

function _ip2country_update($rir) {

  // Update DB from RIR.
  $status = ip2country_update_database($rir);
  if ($status != FALSE) {
    if (variable_get('ip2country_watchdog', TRUE)) {
      watchdog('ip2country', 'Manual database update from @registry server.', array(
        '@registry' => drupal_strtoupper($rir),
      ), WATCHDOG_NOTICE);
    }
    print drupal_json_encode(array(
      'count' => t('@rows rows affected.', array(
        '@rows' => ip2country_get_count(),
      )),
      'server' => $rir,
      'message' => t('The IP to Country database has been updated from @server.', array(
        '@server' => drupal_strtoupper($rir),
      )),
    ));
  }
  else {
    if (variable_get('ip2country_watchdog', TRUE)) {
      watchdog('ip2country', 'Manual database update from @registry server FAILED.', array(
        '@registry' => drupal_strtoupper($rir),
      ), WATCHDOG_NOTICE);
    }
    print drupal_json_encode(array(
      'count' => t('@rows rows affected.', array(
        '@rows' => 0,
      )),
      'server' => $rir,
      'message' => t('The IP to Country database update failed.'),
    ));
  }
  exit;
}