You are here

function views_send_mail_action_submit in Views Send 6

Action configuration submission callback.

See also

http://drupal.org/node/172152

File

./views_send.module, line 298
The Views Send module.

Code

function views_send_mail_action_submit($form, &$form_state) {
  $display = $form['display']['#value'];
  $values =& $form_state['values'];
  $return = array();
  foreach ($values as $key => $value) {
    $key = $key == 'format' ? 'views_send_message_format' : $key;
    if (substr($key, 0, 11) == 'views_send_') {
      if ($values['views_send_remember']) {
        variable_set($key . '_' . $display, $value);
      }
      else {
        variable_del($key . '_' . $display);
      }
      $return += array(
        $key => $value,
      );
    }
  }

  // If a file was uploaded, process it.
  if (VIEWS_SEND_MIMEMAIL && user_access('allow attachments with views_send') && isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['views_send_attachments'])) {

    // attempt to save the uploaded file
    $dir = file_directory_path() . '/views_send_attachments';
    $dest = file_check_directory($dir, FILE_CREATE_DIRECTORY);
    $file = file_save_upload('views_send_attachments', array(), $dir);

    // set error if file was not uploaded
    if (!$file) {

      //form_set_error('views_send_attachment', 'Error uploading file.');
    }
    else {

      // set files to form_state, to process when form is submitted
      // @todo: when we add a multifile formfield then loop through to add each file to attachments array
      $file->filepath = base_path() . $file->filepath;
      $file->list = true;
      $return['views_send_attachments'][] = (array) $file;
    }
  }
  return $return;
}