You are here

function user_badges_images_form_submit in User Badges 7.3

Same name and namespace in other branches
  1. 5 user_badges.module \user_badges_images_form_submit()
  2. 6.2 user_badges.admin.inc \user_badges_images_form_submit()
  3. 6 user_badges.admin.inc \user_badges_images_form_submit()
  4. 7 user_badges.admin.inc \user_badges_images_form_submit()
  5. 7.2 user_badges.admin.inc \user_badges_images_form_submit()

Submission action for user_badges_images_form

Save the uploaded file or delete the selected one

File

./user_badges.admin.inc, line 610
@brief User Badges admin functions

Code

function user_badges_images_form_submit($form, &$form_state) {
  $count = 0;
  $files_to_delete = array_keys(array_filter($form_state['values']['images']));
  if (!empty($files_to_delete)) {
    $dir = 'public://badges';
    if (file_prepare_directory($dir)) {
      foreach ($files_to_delete as $path) {
        $file = _user_badges_managed_file($path);
        if ($file) {
          if (file_usage_list($file)) {
            drupal_set_message(t('The file %file is in use and cannot be deleted.', array(
              '%file' => $path,
            )), 'error');
          }
          else {
            $count++;
            file_delete($file);
          }
        }
        else {
          drupal_set_message(t('The file %file cannot be deleted by User Badges.', array(
            '%file' => $path,
          )), 'error');
        }
      }
    }
    else {
      drupal_set_message(t('The image directory %dir cannot be accessed.', array(
        '%dir' => $dir,
      )), 'error');
    }
    if ($count > 0) {
      drupal_set_message(t('Deleted @count image(s).', array(
        '@count' => $count,
      )));
    }
  }
}