You are here

function forena_confirm_email_submit in Forena Reports 7.3

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.5 forena.common.inc \forena_confirm_email_submit()
  5. 7 forena.common.inc \forena_confirm_email_submit()
  6. 7.2 forena.common.inc \forena_confirm_email_submit()
  7. 7.4 forena.common.inc \forena_confirm_email_submit()

File

./forena.common.inc, line 263
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;
  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'];
    if (isset($form_state['values']['body'])) {
      $doc['parms']['body'] = $body;
    }
    if (isset($form_state['values']['subject'])) {
      $doc['parms']['subject'] = $form_state['values']['subject'];
    }
    if ($test_send) {
      $i++;
    }
    if ($i <= $max) {
      drupal_mail('forena', 'mailmerge', $to, language_default(), $doc['parms'], $from, TRUE);
    }
  }
  $form_state['rebuild'] = TRUE;
}