You are here

function uc_file_admin_files_form_action_submit in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_file/uc_file.admin.inc \uc_file_admin_files_form_action_submit()

Submit handler for uc_file_admin_files_form().

See also

uc_file_admin_files_action()

1 string reference to 'uc_file_admin_files_form_action_submit'
uc_file_admin_files_form in uc_file/uc_file.admin.inc
Form builder for file products admin.

File

uc_file/uc_file.admin.inc, line 411
File administration menu items.

Code

function uc_file_admin_files_form_action_submit($form, &$form_state) {
  switch ($form_state['values']['action']) {
    case 'uc_file_delete':

      // File deletion status.
      $status = TRUE;

      // Delete the selected file(s), with recursion if selected.
      $status = uc_file_remove_by_id($form_state['values']['file_ids'], !empty($form_state['values']['recurse_directories'])) && $status;
      if ($status) {
        drupal_set_message(t('The selected file(s) have been deleted.'));
      }
      else {
        drupal_set_message(t('One or more files could not be deleted.'));
      }
      break;
    case 'uc_file_upload':

      // Build the destination location. We start with the base directory, then add any
      // directory which was explicitly selected.
      $dir = variable_get('uc_file_base_dir', NULL) . '/';
      $dir = is_null($form_state['values']['upload_dir']) ? $dir : $dir . $form_state['values']['upload_dir'];
      if (is_dir($dir)) {

        // Retrieve our uploaded file.
        $file_object = $form_state['storage']['temp_file'];

        // Copy the file to its final location.
        if (copy($file_object->filepath, $dir . '/' . $file_object->filename)) {

          // Check if any hook_file_action('upload', $args) are implemented
          foreach (module_implements('file_action') as $module) {
            $name = $module . '_file_action';
            $result = $name('upload', array(
              'file_object' => $file_object,
              'form_id' => $form_id,
              'form_state' => $form_state,
            ));
          }

          // Update the file list
          uc_file_refresh();
          drupal_set_message(t('The file %file has been uploaded to %dir', array(
            '%file' => $file_object->filename,
            '%dir' => $dir,
          )));
        }
        else {
          drupal_set_message(t('An error occurred while copying the file to %dir', array(
            '%dir' => $dir,
          )));
        }
      }
      else {
        drupal_set_message(t('Can not move file to %dir', array(
          '%dir' => $dir,
        )));
      }
      break;
    default:

      // This action isn't handled by us, so check if any hook_file_action('submit', $args) are implemented
      foreach (module_implements('file_action') as $module) {
        $name = $module . '_file_action';
        $result = $name('submit', array(
          'form_id' => $form_id,
          'form_state' => $form_state,
        ));
      }
      break;
  }

  // Return to the original form state.
  $form_state['rebuild'] = FALSE;
  drupal_goto('admin/store/products/files');
}