function ip2country_admin_settings in IP-based Determination of a Visitor's Country 7
Same name and namespace in other branches
- 6 ip2country.admin.inc \ip2country_admin_settings()
Default IP to Country administration settings.
Return value
array Forms for store administrator to set configuration options.
See also
ip2country_admin_settings_submit()
2 string references to 'ip2country_admin_settings'
- ip2country_menu in ./
ip2country.module - Implements hook_menu().
- ip2country_test_menu in tests/
ip2country_test.module - Implements hook_menu().
File
- ./
ip2country.admin.inc, line 121 - Determination of user's Country based on IP address.
Code
function ip2country_admin_settings() {
drupal_add_js(drupal_get_path('module', 'ip2country') . '/ip2country.js');
drupal_add_css(drupal_get_path('module', 'ip2country') . '/ip2country.css');
// Define submit handler function.
$form['#submit'][] = 'ip2country_admin_settings_submit';
// Container for database update preference forms.
$form['ip2country_database_update'] = array(
'#type' => 'fieldset',
'#title' => t('Database updates'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
// Form to enable watchdog logging of updates.
$form['ip2country_database_update']['ip2country_watchdog'] = array(
'#type' => 'checkbox',
'#title' => t('Log database updates to watchdog'),
'#default_value' => variable_get('ip2country_watchdog', TRUE),
);
// Form to choose RIR.
$form['ip2country_database_update']['ip2country_rir'] = array(
'#type' => 'select',
'#title' => t('Regional Internet Registry'),
'#options' => array(
'afrinic' => 'AFRINIC',
'apnic' => 'APNIC',
'arin' => 'ARIN',
'lacnic' => 'LACNIC',
'ripe' => 'RIPE',
),
'#default_value' => variable_get('ip2country_rir', 'arin'),
'#description' => t('Database will be downloaded from the selected RIR. You may find that the regional server nearest you has the best response time, but note that AFRINIC provides only its own subset of registration data.'),
);
// Form to enable MD5 checksum of downloaded databases.
$form['ip2country_database_update']['ip2country_md5_checksum'] = array(
'#type' => 'checkbox',
'#title' => t('Perform MD5 checksum comparison'),
'#description' => t("Compare MD5 checksum downloaded from the RIR with MD5 checksum calculated locally to ensure the data has not been corrupted. RIRs don't always store current checksums, so if this option is checked your database updates may sometimes fail."),
'#default_value' => variable_get('ip2country_md5_checksum', FALSE),
);
$period = drupal_map_assoc(array(
86400,
302400,
604800,
1209600,
2419200,
), 'format_interval');
$period[0] = t('Never');
// Form to set automatic update interval.
$form['ip2country_database_update']['ip2country_update_interval'] = array(
'#type' => 'select',
'#title' => t('Database update frequency'),
'#default_value' => variable_get('ip2country_update_interval', 604800),
'#options' => $period,
'#description' => t('Database will be automatically updated via cron.php. Cron must be enabled for this to work. Default period is 1 week (604800 seconds).'),
);
$update_time = variable_get('ip2country_last_update', 0);
if (!empty($update_time)) {
$message = t('Database last updated on @date at @time from @registry server.', array(
'@date' => format_date($update_time, 'custom', variable_get('date_format_ip2country_date', 'n/j/Y')),
'@time' => format_date($update_time, 'custom', variable_get('date_format_ip2country_time', 'H:i:s T')),
'@registry' => drupal_strtoupper(variable_get('ip2country_last_update_rir', 'unknown')),
));
}
else {
$message = t('Database is empty. You may fill the database by pressing the @update button.', array(
'@update' => t('Update'),
));
}
// Form to customize database insertion batch size.
$form['ip2country_database_update']['ip2country_update_batch_size'] = array(
'#type' => 'textfield',
'#title' => t('Database update batch size'),
'#default_value' => variable_get('ip2country_update_batch_size', 200),
'#description' => t('The number of rows to insert simultaneously. A larger number means faster filling of the databse, but more system resources (memory usage).'),
);
// Form to initiate manual updating of the IP-Country database.
$form['ip2country_database_update']['ip2country_update_database'] = array(
'#type' => 'button',
'#value' => t('Update'),
'#executes_submit_callback' => FALSE,
'#prefix' => '<p>' . t('The IP to Country Database may be updated manually by pressing the "Update" button below. Note, this may take several minutes. Changes to the above settings will not be permanently saved unless you press the "Save configuration" button at the bottom of this page.') . '</p>',
'#suffix' => '<span id="dbthrobber" class="message">' . $message . '</span>',
);
// Container for manual lookup.
$form['ip2country_manual_lookup'] = array(
'#type' => 'fieldset',
'#title' => t('Manual lookup'),
'#description' => t('Examine database values'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
// Form for IP address for manual lookup.
$form['ip2country_manual_lookup']['ip2country_lookup'] = array(
'#type' => 'textfield',
'#title' => t('Manual lookup'),
'#description' => t('Enter IP address'),
);
// Form to initiate manual lookup.
$form['ip2country_manual_lookup']['ip2country_lookup_button'] = array(
'#type' => 'button',
'#value' => t('Lookup'),
'#executes_submit_callback' => FALSE,
'#prefix' => '<div>' . t('An IP address may be looked up in the database by entering the address above then pressing the Lookup button below.') . '</div>',
'#suffix' => '<span id="lookup-message" class="message"></span>',
);
// Container for debugging preference forms.
$form['ip2country_debug_preferences'] = array(
'#type' => 'fieldset',
'#title' => t('Debug preferences'),
'#description' => t('Set debugging values'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
// Form to turn on debugging.
$form['ip2country_debug_preferences']['ip2country_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Admin debug'),
'#default_value' => variable_get('ip2country_debug', FALSE),
'#description' => t('Enables administrator to spoof an IP Address or Country for debugging purposes.'),
);
// Form to select Dummy Country or Dummy IP Address for testing.
$form['ip2country_debug_preferences']['ip2country_test_type'] = array(
'#type' => 'radios',
'#title' => t('Select which parameter to spoof'),
'#default_value' => variable_get('ip2country_test_type', 0),
'#options' => array(
t('Country'),
t('IP Address'),
),
);
$default_country = variable_get('ip2country_test_country', ip2country_get_country(ip_address()));
// Form to enter Country to spoof.
$form['ip2country_debug_preferences']['ip2country_test_country'] = array(
'#type' => 'select',
'#title' => t('Country to use for testing'),
'#default_value' => $default_country,
'#options' => country_get_list(),
);
// Form to enter IP address to spoof.
$form['ip2country_debug_preferences']['ip2country_test_ip_address'] = array(
'#type' => 'textfield',
'#title' => t('IP address to use for testing'),
'#default_value' => variable_get('ip2country_test_ip_address', ip_address()),
);
return system_settings_form($form);
}