You are here

function smart_ip_admin_settings_validate in Smart IP 7

Same name and namespace in other branches
  1. 6.2 includes/smart_ip.admin.inc \smart_ip_admin_settings_validate()
  2. 6 includes/smart_ip.admin.inc \smart_ip_admin_settings_validate()
  3. 7.2 includes/smart_ip.admin.inc \smart_ip_admin_settings_validate()
1 string reference to 'smart_ip_admin_settings_validate'
smart_ip_admin_settings in includes/smart_ip.admin.inc
Smart IP administration settings.

File

includes/smart_ip.admin.inc, line 320
Admin interface callbacks/handlers to configure Smart IP.

Code

function smart_ip_admin_settings_validate($form, &$form_state) {
  if ($form_state['values']['smart_ip_source'] == 'ipinfodb_service' && empty($form_state['values']['smart_ip_ipinfodb_key'])) {
    form_set_error('smart_ip_ipinfodb_key', t('Please provide IPInfoDB key.'));
  }
  $ipinfodb_key = variable_get('smart_ip_ipinfodb_key', '');
  if ($form_state['values']['smart_ip_ipinfodb_key'] != $ipinfodb_key) {
    variable_set('smart_ip_correct_ipinfodb_key', FALSE);
  }
  if ($form_state['values']['smart_ip_source'] == 'ip2location_bin') {
    if (empty($form_state['values']['smart_ip_ip2location_bin_path'])) {
      form_set_error('smart_ip_ip2location_bin_path', t('Please provide IP2Location binary file path.'));
    }
    if (!empty($form_state['values']['smart_ip_ip2location_bin_path'])) {

      // Check IP2Location binary file path if valid
      if (!is_file($form_state['values']['smart_ip_ip2location_bin_path'])) {
        form_set_error('smart_ip_ip2location_bin_path', t('The IP2Location binary file path is not valid.'));
      }
      else {

        // Check IP2Location binary file if valid
        try {
          module_load_include('inc', 'smart_ip', 'includes/IP2Location');
          $location_data = new IP2Location($form_state['values']['smart_ip_ip2location_bin_path'], IP2Location::FILE_IO);
          $record = $location_data
            ->lookup('8.8.8.8', IP2Location::ALL);
          if (empty($record->ipNumber)) {
            form_set_error('smart_ip_ip2location_bin_path', t('The IP2Location binary file is not valid or corrupted.'));
          }
        } catch (Exception $error) {
          form_set_error('smart_ip_ip2location_bin_path', t('The IP2Location binary file is not valid or corrupted.'));
        }
      }
    }
  }
  if ($form_state['values']['smart_ip_source'] == 'maxmindgeoip_service' && empty($form_state['values']['smart_ip_maxmind_key'])) {
    form_set_error('smart_ip_maxmind_key', t('Please provide Maxmind GeoIP developer key.'));
  }
}