You are here

function forena_confirm_email_submit in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 forena.common.inc \forena_confirm_email_submit()
  2. 6.2 forena.common.inc \forena_confirm_email_submit()
  3. 6 forena.common.inc \forena_confirm_email_submit()
  4. 7 forena.common.inc \forena_confirm_email_submit()
  5. 7.2 forena.common.inc \forena_confirm_email_submit()
  6. 7.3 forena.common.inc \forena_confirm_email_submit()
  7. 7.4 forena.common.inc \forena_confirm_email_submit()

File

./forena.common.inc, line 230
Common functions used throughout the project but loaded in this file to keep the module file lean.

Code

function forena_confirm_email_submit($form, &$form_state) {
  global $user;
  $test_send = @$form_state['values']['send'] == 'test' ? TRUE : variable_get('forena_email_override', FALSE);
  $max = (int) $form_state['values']['max'];
  $i = 0;
  $sent = 0;
  if (isset($form_state['values']['body']['value'])) {
    $body = check_markup($form_state['values']['body']['value'], $form_state['values']['body']['format']);
  }
  foreach ($form_state['storage']['docs'] as $doc) {
    $to = $test_send ? $user->mail : $doc['to'];
    $from = $doc['from'];

    // Replace body
    if (isset($form_state['values']['body'])) {
      $doc['parms']['body'] = $body;
    }

    // Replace subject
    if (isset($form_state['values']['subject'])) {
      $doc['parms']['subject'] = $form_state['values']['subject'];
    }
    if ($test_send) {
      $i++;

      // Remove bcc and cc
      unset($doc['parms']['headers']);
    }
    if ($i <= $max) {
      $sent++;
      drupal_mail('forena', 'mailmerge', $to, language_default(), $doc['parms'], $from, TRUE);
    }
  }
  drupal_set_message(t('Sent %count messages ', array(
    '%count' => $sent,
  )));
  if (isset($form_state['values']['send']) && $form_state['values']['send'] == 'test') {
    $form_state['rebuild'] = TRUE;
  }
  else {
    $form_state['redirect'] = 'forena';
  }
}