function biblio_import_form_submit in Bibliography Module 6.2
Same name and namespace in other branches
- 6 biblio.import.export.inc \biblio_import_form_submit()
- 7 includes/biblio.import.export.inc \biblio_import_form_submit()
- 7.2 includes/biblio.import.export.inc \biblio_import_form_submit()
File
- includes/biblio.import.export.inc, line 197
- Functions that are used to import and export biblio data.
Code
function biblio_import_form_submit($form, &$form_state) {
global $user;
if ($form_state['values']['op'] == t('Import') && isset($form_state['values']['filetype'])) {
if ($import_files = biblio_file_save_uploads('biblio_import_mult')) {
if ($form_state['values']['batch_process'] == 1) {
$batch_proc = TRUE;
}
$terms = array();
foreach (array_keys($form_state['values']) as $key) {
if (preg_match('/(vocabulary[0-9]+)/', $key)) {
if (!empty($form_state['values'][$key])) {
if (is_array($form_state['values'][$key])) {
$terms[] = $form_state['values'][$key];
}
else {
$terms[] = array(
$form_state['values'][$key],
);
}
}
}
if ($key == 'copy_to_biblio') {
$terms['copy_to_biblio'] = $form_state['values'][$key];
}
}
$userid = isset($form_state['values']['userid']) ? $form_state['values']['userid'] : $user->uid;
$filetype = $form_state['values']['filetype'];
foreach ($import_files as $import_file) {
$filesize = sprintf("%01.1f", $import_file->filesize / 1000);
$filesize = " ({$filesize} KB)";
if ($batch_proc) {
$session_id = microtime();
$batch_op = array(
'title' => t('Importing ') . $import_file->filename . $filesize,
'operations' => array(
array(
'biblio_import',
array(
$import_file,
$filetype,
$userid,
$terms,
$batch_proc,
$session_id,
),
),
array(
'biblio_import_batch_operations',
array(
$session_id,
$user,
$userid,
$terms,
),
),
),
'progressive' => TRUE,
'finished' => 'biblio_import_batch_finished',
'init_message' => t('Parsing file...'),
'progress_message' => t('Saving nodes...'),
'file' => './' . drupal_get_path('module', 'biblio') . '/includes/biblio.import.export.inc',
);
batch_set($batch_op);
}
else {
$session_id = microtime();
$context = array();
biblio_import($import_file, $filetype, $userid, $terms, $batch_proc, $session_id, $context);
biblio_import_finalize(TRUE, $context['results']);
}
}
if ($batch_proc) {
$base = variable_get('biblio_base', 'biblio');
batch_process("{$base}/import");
}
foreach ($import_files as $import_file) {
file_delete($import_file->filepath);
}
}
else {
drupal_set_message(t("File was NOT successfully uploaded"), 'error');
}
}
}