You are here

class FrxEmailMergeDoc in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 docformats/FrxEmailMergeDoc.inc \FrxEmailMergeDoc

@file FrxEmailMergeDoc.inc email merge document. @author davidmetzler

Hierarchy

Expanded class hierarchy of FrxEmailMergeDoc

1 string reference to 'FrxEmailMergeDoc'
forena_forena_document_types in ./forena.module
Self register document formats with Forena

File

docformats/FrxEmailMergeDoc.inc, line 8
FrxEmailMergeDoc.inc email merge document. @author davidmetzler

View source
class FrxEmailMergeDoc extends FrxDocument {
  public function render($r, $format, $options = array()) {
    $body = $r->html;
    $doc = new DOMDocument('1.0', 'UTF-8');
    $doc->strictErrorChecking = FALSE;
    libxml_use_internal_errors(true);
    $doc
      ->loadHTML($body);
    libxml_clear_errors();
    $xml = simplexml_import_dom($doc);
    $docs = $xml
      ->xpath('.//*[@class="email-document"]');
    $prompt_subject = TRUE;
    $prompt_body = TRUE;
    if ($docs) {
      foreach ($docs as $doc) {
        $from = $doc
          ->xpath('.//*[@class="email-header-from"]');
        $from = $from ? (string) $from[0] : '';
        $subject = $doc
          ->xpath('.//*[@class="email-header-subject"]');
        if ($subject) {
          $prompt_subject = FALSE;
        }
        $subject = $subject ? (string) $subject[0] : '';
        $to = $doc
          ->xpath('.//*[@class="email-header-to"]');
        $to = $to ? (string) $to[0] : '';
        if ($to) {
          $prompt_to = FALSE;
        }
        $body = $doc
          ->xpath('.//*[@class="email-body"]');
        if ($body) {
          $prompt_body = FALSE;
        }
        $body = $body ? $body[0]
          ->asXML() : $body;
        $email = array(
          'to' => $to,
          'from' => $from,
          'parms' => array(
            'subject' => $subject,
            'body' => $body,
          ),
        );
        $emails[] = $email;
      }
    }
    $count = count($docs);
    if ($count) {
      $form = drupal_get_form('forena_confirm_email', $emails, $count, $prompt_subject, $prompt_body);
      $output = drupal_render($form);
    }
    else {
      drupal_set_message(t('No mail merge information in report. Displaying report instead.'), 'error');
      $output = $body;
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxDocument::$charset public property
FrxDocument::$content_type public property
FrxDocument::$format public property
FrxDocument::check_markup public function Wrapper function for check output to default the right type.
FrxDocument::convertCharset public function
FrxDocument::loadCSSFiles public function
FrxDocument::output public function 9
FrxEmailMergeDoc::render public function Overrides FrxDocument::render