function autoban_import_form_submit in Automatic IP ban (Autoban) 7
Form submission for autoban_import_form().
File
- ./
autoban.admin.inc, line 791 - Configuration for autoban module.
Code
function autoban_import_form_submit($form, &$form_state) {
$import = trim($form_state['values']['import']);
if (!empty($import)) {
$vars = explode(AUTOBAN_EXPORT_SEPARATOR, $import);
if (count($vars)) {
$errors = $imported = 0;
$import_rows = array();
foreach ($vars as $item) {
$var = drupal_json_decode($item);
if ($var) {
$imported++;
$import_rows[] = $var;
}
else {
$errors++;
}
}
if ($imported > 0) {
drupal_set_message(t('Import checked rows: @imported.', array(
'@imported' => $imported,
)));
}
if ($errors) {
drupal_set_message(t('Import errors: @errors.', array(
'@errors' => $errors,
)), 'error');
drupal_set_message(t('Import was failed.'), 'error');
}
else {
$clear_before = $form_state['values']['clear_before'];
if ($clear_before) {
drupal_set_message('Autoban rules table was cleared.');
db_delete('autoban')
->execute();
}
if (count($import_rows)) {
foreach ($import_rows as $fields) {
db_insert('autoban')
->fields($fields)
->execute();
}
drupal_set_message(t('Import was finished.'));
}
}
}
}
}