function countries_admin_import_form in Countries 7
Same name and namespace in other branches
- 7.2 countries.admin.inc \countries_admin_import_form()
Menu callback to update the database from the CSV file.
1 string reference to 'countries_admin_import_form'
- countries_menu in ./
countries.module - Implement hook_menu().
File
- ./
countries.admin.inc, line 329 - Admin page callbacks for the Countries module.
Code
function countries_admin_import_form($form, &$form_state) {
$changes = countries_csv_updates();
if (count($changes['inserts'])) {
$form_state['inserts'] = $changes['inserts'];
$form['inserts'] = array(
'#type' => 'checkboxes',
'#title' => t('Select the countries to import'),
);
foreach ($changes['inserts'] as $iso2 => $country) {
$t_options = array(
'%name' => $country->name,
'%continent' => $country->continent,
'%official_name' => $country->official_name,
'%iso2' => $country->iso2,
'%iso3' => $country->iso3,
'%numcode' => theme('countries_number', array(
'country' => $country,
)),
'%enabled' => $country->enabled ? t('Enabled') : t('Disabled'),
);
$form['inserts']['#options'][$iso2] = t('New country %name, %continent (%official_name): %iso2, %iso3, %numcode, %enabled', $t_options);
$form['inserts']['#default_options'][$iso2] = $iso2;
}
}
else {
$form['inserts'] = array(
'#type' => 'markup',
'#markup' => '<div class="form-item">' . t('There are no new records to import.') . '</div>',
);
}
if (count($changes['updates'])) {
$form_state['updates'] = $changes['updates'];
$form['updates'] = array(
'#type' => 'checkboxes',
'#title' => t('Select the countries and their properties to update'),
);
// $updates[$country->iso2][$key] = array('new' => $country->{$key}, 'old' => $existing->{$key});
foreach ($changes['updates'] as $iso2 => $changes) {
$country = country_load($iso2);
foreach ($changes as $key => $values) {
$t_options = array(
'%name' => $country->name,
'%iso2' => $country->iso2,
'%code' => $key,
'%new' => $values['new'],
'%old' => $values['old'],
);
if ($key == 'enabled') {
if ($values['new']) {
$form['updates']['#options'][$iso2 . '-' . $key] = t('%name (%iso2): Enable this country', $t_options);
}
else {
$form['updates']['#options'][$iso2 . '-' . $key] = t('%name (%iso2): Disable this country', $t_options);
}
}
else {
$form['updates']['#options'][$iso2 . '-' . $key] = t('%name (%iso2): Change %code from "%old" to "%new"', $t_options);
}
$form['updates']['#default_options'][$iso2 . '-' . $key] = $iso2 . '-' . $key;
}
}
}
else {
$form['updates'] = array(
'#type' => 'markup',
'#markup' => '<div class="form-item">' . t('There are no updates to import.') . '</div>',
);
}
if (!empty($form_state['inserts']) || !empty($form_state['updates'])) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
);
}
return $form;
}