You are here

function asset_wizard_form_submit in Asset 6

Same name in this branch
  1. 6 asset_wizard.inc \asset_wizard_form_submit()
  2. 6 inc/asset_wizard.inc \asset_wizard_form_submit()
Same name and namespace in other branches
  1. 5 asset_wizard.inc \asset_wizard_form_submit()

Submit callback for asset_wizard_form().

File

inc/asset_wizard.inc, line 846

Code

function asset_wizard_form_submit($form, &$form_state) {
  if ($form_state['values']['delta'] == "directory") {
    if (!$form_state['values']['title']) {
      form_set_error('folder', t('You must specify a folder name.'));
    }
    elseif (preg_match('/[^A-Za-z0-9-_.]/', $form_state['values']['title'])) {
      form_set_error('title', t('The folder name may only contain alpha-numeric characters and dashes(-), underscores(_) and periods(.).'));
    }
    else {
      $dir = file_create_path($form_state['values']['parent'] . '/' . $form_state['values']['title']);
      if (!asset_check_directory($dir, FILE_CREATE_DIRECTORY, 'folder', $form_state['values'])) {
        drupal_set_message(t('Error creating %dir.', array(
          '%dir' => $dir,
        )));
      }
    }
    return FALSE;
  }
  if ($form_state['values']['delta'] == "upload") {
    if ($file = file_save_upload('upload')) {
      $parent_tmp = $form_state['values']['parent'] ? $form_state['values']['parent'] . '/' : $form_state['values']['parent'];
      $path = file_create_path($parent_tmp . $file->filename);
      if (file_copy($file, $path, FILE_EXISTS_RENAME)) {
        $asset = asset_save($file, $form_state['values']);
        drupal_set_message(t("The file {$file->filename} has been successfully uploaded."));
        if (isset($_SESSION['asset_fieldname'])) {
          drupal_goto(filter_xss($_GET['q']), 'dir=' . filter_xss($_GET['dir']));
        }
        else {
          return $asset->aid;
        }
      }
      else {
        form_set_error('upload', 'Error saving file to <em>' . $path . '</em>');
      }
    }
    else {
      form_set_error('upload', 'Error uploading file</em>');
    }
  }
  if ($form_state['values']['step'] == 1 && isset($form_state['values']['module'])) {

    // allow module submits to return an aid
    $retval = module_invoke($form_state['values']['module'], 'asset_type', 'submit', $form_state['values']['delta'], $form_state['values']);
    if (is_numeric($retval)) {
      $_POST['aid'] = $retval;
    }
    return FALSE;
  }

  // If we haven't processed the form and completed fully, we have
  // to return FALSE so that Drupal redisplays our form.
  return FALSE;
}