You are here

function imagepicker_import_form_submit in Image Picker 6.2

Same name and namespace in other branches
  1. 7 imagepicker.import.inc \imagepicker_import_form_submit()

Submit form

File

./imagepicker.import.inc, line 199

Code

function imagepicker_import_form_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  if ($op == t('Import')) {
    if (isset($form_state['values']['account']) && isset($form_state['values']['admin'])) {
      $user = user_load(array(
        'uid' => $form_state['values']['account'],
      ));
    }
    else {
      global $user;
    }
    $destdir = imagepicker_get_path(FALSE, isset($form_state['values']['admin']) ? array(
      'name' => $user->name,
      'uid' => $user->uid,
    ) : TRUE);
    $thumbsdir = $destdir . IMAGEPICKER_THUMBS_DIR;
    $browserdir = $destdir . IMAGEPICKER_BROWSER_DIR;
    $origdir = $destdir . IMAGEPICKER_ORIG_DIR;
    $sourcedir = variable_get('imagepicker_import_dir', '');
    if (file_check_directory($destdir, TRUE) && file_check_directory($thumbsdir, TRUE) && file_check_directory($browserdir, TRUE) && file_check_directory($origdir, TRUE) && ($selected = imagepicker_import_dir_check())) {

      // clear out the noisy 'created' messages
      drupal_get_messages('status', TRUE);

      // Add DIRECTORY_SEPARATORS here because drupals' functions remove trailing slashes
      $options['destdir'] = $destdir . DIRECTORY_SEPARATOR;
      $options['thumbsdir'] = $thumbsdir . DIRECTORY_SEPARATOR;
      $options['browserdir'] = $browserdir . DIRECTORY_SEPARATOR;
      $options['origdir'] = $origdir . DIRECTORY_SEPARATOR;
      $options['sourcedir'] = $sourcedir;
      $batch = array(
        'title' => t('Importing images'),
        'operations' => array(
          array(
            'imagepicker_import_batch',
            array(
              $form_state,
              $selected,
              $options,
              $user,
            ),
          ),
        ),
        'finished' => 'imagepicker_import_finished',
        'file' => drupal_get_path('module', 'imagepicker') . "/imagepicker.import.inc",
        'progress_message' => t('Processed @current out of @total.'),
      );
      batch_set($batch);

      // batch_process();
    }
    else {
      drupal_set_message(t('Unable to import.'), 'error');
    }
  }
}