function uc_file_admin_files_form_action_submit in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_file/uc_file.admin.inc \uc_file_admin_files_form_action_submit()
Submit handler for uc_file_admin_files_form_action().
See also
uc_file_admin_files_form_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 412 - 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.'), 'warning');
}
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->uri, $dir . '/' . $file_object->filename)) {
// Check if any hook_uc_file_action('upload', $args) are implemented.
foreach (module_implements('uc_file_action') as $module) {
$name = $module . '_uc_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,
)), 'error');
}
}
else {
drupal_set_message(t('Can not move file to %dir', array(
'%dir' => $dir,
)), 'error');
}
break;
default:
// This action isn't handled by us, so check if any
// hook_uc_file_action('submit', $args) are implemented.
foreach (module_implements('uc_file_action') as $module) {
$name = $module . '_uc_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');
}