You are here

function avatar_selection_upload_form_submit in Avatar Selection 5.2

Same name and namespace in other branches
  1. 6 avatar_selection.admin.inc \avatar_selection_upload_form_submit()
  2. 7 avatar_selection.admin.inc \avatar_selection_upload_form_submit()

Submit the image upload form in the Avatar Selection administration page.

Parameters

$form_id: The form id.

$form_values: Array containing the form values submitted.

File

./avatar_selection.module, line 1011
The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.

Code

function avatar_selection_upload_form_submit($form_id, $form_values) {
  $op = $form_values['op'];
  if ($op == t('Upload')) {

    // Get access settings.
    $access = array_keys(array_filter($form_values['access']));
    $og = array();
    if (module_exists("og")) {
      $og = array_keys(array_filter($form_values['og_access']));
    }
    $name = $form_values['avatar_name'];
    $weight = $form_values['avatar_weight'];

    // Scan for new files.
    if ($form_values['scan_avatars'] == 1) {
      $count = _avatar_selection_scan_images($name, $access, $og, $weight);
      drupal_set_message(t('Scan complete: %added new avatars found. %deleted avatars removed.', array(
        '%added' => $count['add'],
        '%deleted' => $count['delete'],
      )));
    }

    // Save uploaded files.
    $dir = file_create_path('avatar_selection');
    $is_writable = file_check_directory($dir, 1);
    if ($is_writable) {
      if ($source = file_check_upload('picture_upload')) {
        if ($file = file_save_upload($source, $dir)) {
          if (image_get_info($file->filepath)) {
            _avatar_selection_save_avatar_info(0, $file->filename, $name, $access, $og, $weight);
            drupal_set_message(t('New image saved.'));
          }
          else {
            file_delete($file->filepath);
            drupal_set_message(t('Uploaded file does not appear to be a valid image file. Please try again.'));
          }
        }
      }
    }
    else {
      form_set_error('picture_upload', t('Directory not writable: !dir', array(
        '!dir' => $dir,
      )));
    }
  }
}