Commit 15f6cbd6 authored by metzlerd's avatar metzlerd
Browse files

Implemented email cc and bcc fucntionality.

parent cae9c48b
......@@ -19,23 +19,46 @@ class FrxEmailMergeDoc extends FrxDocument {
$prompt_subject = TRUE;
$prompt_body = TRUE;
if ($docs) foreach ($docs as $doc) {
// From
$from = $doc->xpath('.//*[@class="email-header-from"]');
$from = $from ? (string)$from[0] : '';
$from = $from ? html_entity_decode(strip_tags($from[0])) : '';
// Subject
$subject = $doc->xpath('.//*[@class="email-header-subject"]');
if ($subject) $prompt_subject = FALSE;
$subject = $subject ? (string)$subject[0] : '';
// To
$to = $doc->xpath('.//*[@class="email-header-to"]');
$to = $to ? (string)$to[0] : '';
$to = $to ? html_entity_decode(strip_tags($to[0]->asXML())) : '';
if ($to) $prompt_to = FALSE;
$body = $doc->xpath('.//*[@class="email-body"]');
if ($body) $prompt_body = FALSE;
$body = $body ? $body[0]->asXML() : $body;
// Assemble email
$email = array(
'to' => $to,
'from' => $from,
'parms' => array('subject' => $subject,
'body' => $body),
'parms' => array(
'subject' => $subject,
'body' => $body,
),
);
// Check for cc
$cc = $doc->xpath('.//*[@class="email-header-cc"]');
if ($cc) {
$email['parms']['headers']['Cc'] = html_entity_decode(strip_tags($cc[0]->asXML()));
}
// Check for bcc
$bcc = $doc->xpath('.//*[@class="email-header-bcc"]');
if ($bcc) {
$email['parms']['headers']['Bcc'] = html_entity_decode(strip_tags($bcc[0]->asXML()));
}
$emails [] = $email;
}
$count = count($docs);
......
......@@ -238,13 +238,19 @@ function forena_confirm_email_submit($form, &$form_state) {
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++;
if ($test_send) {
$i++;
// Remove bcc and cc
unset($doc['parms']['headers']);
}
if ($i <= $max) drupal_mail('forena', 'mailmerge', $to, language_default(), $doc['parms'], $from, TRUE);
}
$form_state['rebuild'] = TRUE;
......
......@@ -1353,6 +1353,7 @@ function forena_mail($key, &$message, $parms) {
$message['subject'] = $parms['subject'];
$body = $parms['body'];
$message['body'][] = $body;
if (isset($parms['headers'])) $message['headers'] += $parms['headers'];
$htmlmail = FALSE;
break;
}
......
......@@ -15,10 +15,10 @@ class FrxEmailMerge extends FrxRenderer {
public function scrapeConfig() {
$config=array();
$config['class'] = get_class($this);
$config['from'] = $this->extractXPathInnerHTML("*//*[@class='email-header-from']", $this->reportDocDomNode);
$config['to']= $this->extractXPathInnerHTML("*//*[@class='email-header-to']", $this->reportDocDomNode);
$config['cc'] = $this->extractXPathInnerHTML("*//*[@class='email-header-cc']", $this->reportDocDomNode);
$config['bcc'] = $this->extractXPathInnerHTML("*//*[@class='email-header-bcc']", $this->reportDocDomNode);
$config['from'] = html_entity_decode($this->extractXPathInnerHTML("*//*[@class='email-header-from']", $this->reportDocDomNode));
$config['to']= html_entity_decode($this->extractXPathInnerHTML("*//*[@class='email-header-to']", $this->reportDocDomNode));
$config['cc'] = html_entity_decode($this->extractXPathInnerHTML("*//*[@class='email-header-cc']", $this->reportDocDomNode));
$config['bcc'] = html_entity_decode($this->extractXPathInnerHTML("*//*[@class='email-header-bcc']", $this->reportDocDomNode));
$config['subject'] = $this->extractXPathInnerHTML("*//*[@class='email-header-subject']", $this->reportDocDomNode);
$config['body']['value'] = $this->extractXPathInnerHTML("*//*[@class='email-body']", $this->reportDocDomNode);
return $config;
......@@ -38,6 +38,18 @@ class FrxEmailMerge extends FrxRenderer {
'#default_value' => @$config['to'],
);
$form_ctl['cc'] = array(
'#type' => 'textfield',
'#title' => t('Cc'),
'#default_value' => @$config['cc'],
);
$form_ctl['bcc'] = array(
'#type' => 'textfield',
'#title' => t('Bcc'),
'#default_value' => @$config['bcc'],
);
$form_ctl['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
......@@ -58,10 +70,12 @@ class FrxEmailMerge extends FrxRenderer {
}
public function generate($xml, &$config) {
$from = $this->extract('from', $config);
$to = $this->extract('to', $config);
$subject = $this->extract('subject', $config);
$body = $this->extract('body', $config);
$from = @$config['from'];
$to = @$config['to'];
$cc = @$config['cc'];
$bcc = @$config['bcc'];
$subject = @$config['subject'];
$body = @$config['body'];
$body = $body['value'];
$config['foreach'] = "*";
$div = $this->blockDiv($config);
......@@ -71,10 +85,21 @@ class FrxEmailMerge extends FrxRenderer {
$table = $this->addNode($header, 8, 'table');
$tr = $this->addNode($table, 10, 'tr');
$td = $this->addNode($tr, 12, 'th', 'From');
$td = $this->addNode($tr, 12, 'td', $from, array('class' => 'email-header-from'));
$td = $this->addNode($tr, 12, 'td', htmlentities($from), array('class' => 'email-header-from'));
$tr = $this->addNode($table, 10, 'tr');
$td = $this->addNode($tr, 12, 'th', 'To');
$td = $this->addNode($tr, 12, 'td', $to, array('class' => 'email-header-to'));
$td = $this->addNode($tr, 12, 'td', htmlentities($to), array('class' => 'email-header-to'));
if ($cc) {
$tr = $this->addNode($table, 10, 'tr');
$td = $this->addNode($tr, 12, 'th', 'Cc');
$td = $this->addNode($tr, 12, 'td', htmlentities($cc), array('class' => 'email-header-cc'));
}
if ($bcc) {
$tr = $this->addNode($table, 10, 'tr');
$td = $this->addNode($tr, 12, 'th', 'Bcc');
$td = $this->addNode($tr, 12, 'td', htmlentities($bcc), array('class' => 'email-header-bcc'));
}
$tr = $this->addNode($table, 10, 'tr');
$td = $this->addNode($tr, 12, 'th', 'Subject');
$td = $this->addNode($tr, 12, 'td', $subject, array('class' => 'email-header-subject'));
......
......@@ -114,7 +114,7 @@ class FrxRenderer {
if ($node_type == XML_TEXT_NODE|| $node_type == XML_ENTITY_REF_NODE || $node_type == XML_ENTITY_NODE)
{
$text = $dom_node->textContent;
$o .= $this->teng->replace($text);
$o .= htmlspecialchars($this->teng->replace($text));
return $o;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment