You are here

function forena_confirm_email_submit in Forena Reports 8

Same name and namespace in other branches
  1. 6.2 forena.common.inc \forena_confirm_email_submit()
  2. 6 forena.common.inc \forena_confirm_email_submit()
  3. 7.5 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 224
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) {
  $user = \Drupal::currentUser();
  $test_send = @$form_state['values']['send'] == 'test' ? TRUE : \Drupal::config('forena.settings')
    ->get('forena_email_override');
  $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'];

    // 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) {
      drupal_mail('forena', 'mailmerge', $to, \Drupal::languageManager()
        ->getLanguages(), $doc['parms'], $from, TRUE);
    }
  }
  $form_state['rebuild'] = TRUE;
}