Skip to content

Commit

Permalink
newsletter_send.php: add preview
Browse files Browse the repository at this point in the history
Provide more details in the admin page about the newsletter that
will be sent (i.e. newsletter number, html text, and plain text).
If there are no newsletters, displays a message saying so, rather
than sending a blank newsletter.

To ensure that the sent newsletter is the same as the previewed
one, we no longer query the database in the processing page;
instead, we _only_ do it in the preview page and then pass that
data onward.

This addresses the preview capabilities requested in issue smrealms#39.
  • Loading branch information
hemberger committed Aug 17, 2017
1 parent 360ead2 commit f37df39
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
18 changes: 16 additions & 2 deletions admin/Default/newsletter_send.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@

$template->assign('CurrentEmail', $account->getEmail());

$container = create_container('newsletter_send_processing.php', '');
$template->assignByRef('ProcessingContainer', $container);
$processingContainer = create_container('newsletter_send_processing.php');

// Get the most recent newsletter text for preview
$db = new SmrMySqlDatabase();
$db->query('SELECT newsletter_id, newsletter_html, newsletter_text FROM newsletter ORDER BY newsletter_id DESC LIMIT 1');
if ($db->nextRecord()) {
// Give both the template and processing container access to the same data
$processingContainer['newsletter_id'] = $db->getField('newsletter_id');
$processingContainer['newsletter_html'] = $db->getField('newsletter_html');
$processingContainer['newsletter_text'] = $db->getField('newsletter_text');
$template->assign('NewsletterId', $db->getField('newsletter_id'));
$template->assign('NewsletterHtml', $db->getField('newsletter_html'));
$template->assign('NewsletterText', $db->getField('newsletter_text'));
}

// Create the form for the populated processing container
$template->assign('ProcessingForm', create_echo_form($processingContainer));
?>
23 changes: 11 additions & 12 deletions admin/Default/newsletter_send_processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@
$mail->Encoding = 'base64';
$mail->WordWrap = 72;

$db = new SmrMySqlDatabase();
$db->query('SELECT newsletter_id, newsletter_html, newsletter_text FROM newsletter ORDER BY newsletter_id DESC LIMIT 1');
if ($db->nextRecord()) {
$mail->Subject = 'Space Merchant Realms Newsletter #' . $db->getField('newsletter_id');

$newsletterHtml = $db->getField('newsletter_html');
$newsletterText = $db->getField('newsletter_text');
$mail->Subject = 'Space Merchant Realms Newsletter #' . $var['newsletter_id'];

function set_mail_body(&$mail, $newsletterHtml, $newsletterText) {
if(!empty($newsletterHtml)) {
$mail->MsgHTML($newsletterHtml);
if(!empty($newsletterText))
if(!empty($newsletterText)) {
$mail->AltBody = $newsletterText;
}
else
}
} else {
$mail->Body = $newsletterText;
}

// attach footer
// $mail->Body .= EOL.EOL.'Thank you,'.EOL.' SMR Support Team'.EOL.EOL.'Note: You receive this e-mail because you are registered with Space Merchant Realms. If you prefer not to get any further notices please respond and we will disable your account.';
//$mail->Body .= EOL.EOL.'Thank you,'.EOL.' SMR Support Team'.EOL.EOL.'Note: You receive this e-mail because you are registered with Space Merchant Realms. If you prefer not to get any further notices please respond and we will disable your account.';
}

// Set the body of the e-mail
set_mail_body($mail, $var['newsletter_html'], $var['newsletter_text']);

if($_REQUEST['to_email']=='*') {
// counter
$total = 0;
Expand Down Expand Up @@ -84,4 +83,4 @@

forward(create_container('skeleton.php', 'newsletter_send.php'))

?>
?>
41 changes: 35 additions & 6 deletions templates/Default/admin/Default/newsletter_send.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
This uses the last newsletter to be added to the DB!<br />
Please enter an eMail address where the newsletter should be sent (* for all):
<?php echo create_echo_form($ProcessingContainer); ?>
<input type="text" name="to_email" value="<?php echo htmlspecialchars($CurrentEmail); ?>" id="InputFields" size="25">&nbsp;
<?php echo create_submit('Send'); ?>
</form>
<?php
if (!isset($NewsletterId)) { ?>
No newsletters in the database!<?php
} else { ?>
<h2>Send Newsletter</h2>
<p>This sends the latest newsletter added to the DB: Newsletter #<?php echo $NewsletterId; ?></p>

<p>Enter a recipient address (* for all players). Please send to yourself first to verify that
everything displays as intended.</p>
<?php echo $ProcessingForm; ?>
<input type="text" name="to_email" value="<?php echo htmlspecialchars($CurrentEmail); ?>" id="InputFields" size="25">

<p><?php echo create_submit('Send'); ?></p>
</form>
<br /><br />

<h2>Newsletter #<?php echo $NewsletterId; ?> Preview</h2>
<p>HTML body (will be displayed in most e-mail clients):</p>
<table class="standard">
<tr>
<td><?php echo $NewsletterHtml; ?></td>
</tr>
</table>
<br />

<p>Plain text body (will only be displayed if HTML is empty or in e-mail clients that don't support HTML):</p>
<table class="standard">
<tr>
<td><pre><?php echo $NewsletterText; ?></pre></td>
</tr>
</table>

<?php
}
?>

0 comments on commit f37df39

Please sign in to comment.