$whereParts = array();
$catsToUse = array();
$emailsQueued = false;
+ $emailsSent = false;
wp_enqueue_style( 'select2','https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css' );
wp_enqueue_script( 'select2js', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js' );
$Categories = new GlmDataCategories( $this->wpdb, $this->config );
$categories = $Categories->getListSortedParentChild( false );
- // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-
+ // Filters
if ( isset( $_REQUEST['filterMemberStatus'] ) && $filterStatus = filter_var( $_REQUEST['filterMemberStatus'], FILTER_VALIDATE_INT) ) {
$whereParts[] = " T.ref_dest IN ( SELECT member FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info WHERE status = " . $filterStatus . ")";
} else {
}
if ( $catsToUse && $catsToUse !== '' ) {
- $cats = '';
- $catsSep = '';
+ // Reset $cats and $catSep
+ $cats = $catsSep = '';
// For each selected category
foreach ( $catsToUse as $c ) {
".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M,
".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C
WHERE I.id = M.member_info
- AND I.status != " . $this->config['status_numb']['Archived'] ."
+ AND I.status != " . $this->config['status_numb']['Archived'] . "
AND (
M.category in ($cats)
OR (C.parent in ($cats) AND M.category = C.id)
)
)";
- // $catSelectedString = $cats;
}
// Get a list of member_types for filtering
$messages = $this->getList( $where );
if ( $option2 === 'sendMessages' && isset( $_REQUEST['message_id'] ) && $messageId = filter_var( $_REQUEST['message_id'], FILTER_VALIDATE_INT ) ) {
- $this->sendHtmlMessages( $searchResults, $messageId );
- $emailsQueued = true;
+ $sendNow = filter_var( $_REQUEST['sendNow'], FILTER_VALIDATE_BOOLEAN );
+ $this->queueHtmlMessages( $searchResults, $messageId, $sendNow );
+ if ( $sendNow ) {
+ $emailsSent = true;
+ } else {
+ $emailsQueued = true;
+ }
}
}
'cities' => $cities,
'counties' => $counties,
'emailsQueued' => $emailsQueued,
+ 'emailsSent' => $emailsSent,
);
break;
$Templates->deleteEntry( $id, true );
}
-
case 'listTemplates':
$view = 'listTemplates';
$Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config );
}
/**
- * sendHtmlMessages
+ * queueHtmlMessages
*
- * Bulid the html email message for the each member and send it out.
+ * Bulid the html email message for the each member and queue it.
*
* @param $data Contact data from search
* @param $message Message array
*/
- public function sendHtmlMessages( $data, $messageId )
+ public function queueHtmlMessages( $data, $messageId, $sendNow = false )
{
$message = $this->getEntry( $messageId );
$fromEmail = $message['from_email'];
);
$messageBody = $this->generateHTML( $emailData, wpautop( $message['message_body'] ), $message, $process_id, $contact['email'] );
- // Add this to the email_queue
- $this->wpdb->insert(
- GLM_MEMBERS_MESSAGES_PLUGIN_DB_PREFIX . 'email_queue',
- array(
- 'message_id' => $messageId,
- 'to_email' => $contact['email'],
- 'subject' => $subject,
- 'from_email' => $fromEmail,
- 'reply_to_email' => $replyToEmail,
- 'message_body' => $messageBody,
- 'queue_date' => date( 'Y-m-d H:i:s' ),
- 'processed' => false,
- 'process_id' => $process_id,
- ),
- array(
- '%d', // message_id
- '%s', // to_email
- '%s', // subject
- '%s', // from_email
- '%s', // reply_to_email
- '%s', // message_body
- '%s', // queue_date
- '%s', // processed
- '%s', // process_id
- )
- );
+ if ( $sendNow ) {
+ $this->sendHtmlEmail(
+ $fromEmail,
+ $contact['email'],
+ $subject,
+ $messageBody,
+ $fromName,
+ $replyToEmail
+ );
+ // Move this entry into the email_log
+ $this->wpdb->insert(
+ GLM_MEMBERS_MESSAGES_PLUGIN_DB_PREFIX . 'email_logs',
+ array(
+ 'message_id' => $messageId,
+ 'to_email' => $contact['email'],
+ 'subject' => $subject,
+ 'from_email' => $fromEmail,
+ 'reply_to_email' => $replyToEmail,
+ 'message_body' => '',
+ 'send_date' => date( 'Y-m-d H:i:s' ),
+ 'process_id' => $process_id,
+ ),
+ array(
+ '%d', // message_id
+ '%s', // to_email
+ '%s', // subject
+ '%s', // from_email
+ '%s', // reply_to_email
+ '%s', // message_body
+ '%s', // send_date
+ '%s', // process_id
+ )
+ );
+ } else {
+ // Add this to the email_queue
+ $this->wpdb->insert(
+ GLM_MEMBERS_MESSAGES_PLUGIN_DB_PREFIX . 'email_queue',
+ array(
+ 'message_id' => $messageId,
+ 'to_email' => $contact['email'],
+ 'subject' => $subject,
+ 'from_email' => $fromEmail,
+ 'reply_to_email' => $replyToEmail,
+ 'message_body' => $messageBody,
+ 'queue_date' => date( 'Y-m-d H:i:s' ),
+ 'processed' => false,
+ 'process_id' => $process_id,
+ ),
+ array(
+ '%d', // message_id
+ '%s', // to_email
+ '%s', // subject
+ '%s', // from_email
+ '%s', // reply_to_email
+ '%s', // message_body
+ '%s', // queue_date
+ '%s', // processed
+ '%s', // process_id
+ )
+ );
+ }
}
}
}
}
+ /**
+ * sendHtmlEmail
+ *
+ * Create html email and send using wp_mail.
+ *
+ * @param mixed $to To email address
+ * @param mixed $subject Subject line for the email
+ * @param mixed $htmlMessage Html message for the email
+ *
+ * @access public
+ * @return void
+ */
+ public function sendHtmlEmail( $from, $to, $subject, $htmlMessage, $fromName, $replyTo = null )
+ {
+
+ // Set the From name using this wordpress hook.
+ add_filter(
+ 'wp_mail_from_name',
+ function ( $fromName ) {
+ return $fromName;
+ }
+ );
+ // Send confirmation email, set the content type to allow html by using this filter
+ add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+
+
+ $message = $htmlMessage;
+ $header[] = 'From:' . $from;
+ if ( $replyTo ) {
+ $header[] = 'Reply-To:' . $replyTo;
+ }
+
+ wp_mail( $to, $subject, $message, $header );
+
+ }
+
+ /**
+ * Set content type of the email.
+ *
+ * Used as filter for the wp_mail_content_type
+ */
+ function set_content_type()
+ {
+ return 'text/html';
+ }
}
<?php
/**
* Gaslight Media Members Database
- * Admin Registrations - Send any current notifications
+ * Admin Send Messages Emails - Send any current queued emails.
*
* PHP version 5.5
*
* @link http://dev.gaslightmedia.com/
*/
-// Load Registrations Notification data class
-// require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegNotification.php';
-
-class GlmMembersAdmin_messages_sendMessagesEmails //extends GlmDataRegistrationsRegNotification
+class GlmMembersAdmin_messages_sendMessagesEmails
{
use GlmLock;
*
* @return array Array containing status, suggested view, and any data
*/
- public function __construct ($wpdb, $config)
+ public function __construct ( $wpdb, $config )
{
// Save WordPress Database object
}
// $notiicationTest to true to just display notification messages
- public function modelAction( $actionData = false, $notificationTest = false )
+ public function modelAction( $actionData = false )
{
trigger_error( 'sendMessagesEmail started', E_USER_NOTICE );
)
);
- echo '<pre>$lock: ' . print_r( $lock, true ) . '</pre>';
+ // echo '<pre>$lock: ' . print_r( $lock, true ) . '</pre>';
if ( $lock && !empty( $lock ) ) {
// Process Emails Queue
+{*
+ Search Form for Contacts
+
+ Show search results and two options with select list of messages.
+ Option 1 Queue messages.
+ Option 2 Send Messages Now
+*}
+
+{* header *}
{include file='admin/header.html'}
<h3>Search</h3>
{if $searchResults}
- <form action="{$thisUrl}?page={$thisPage}" method="post">
+ {* Emails Queued *}
+ {$ui = [
+ 'label' => 'Emails Queued',
+ 'active' => $emailsQueued,
+ 'type' => 'success'
+ ]}
+ {include file='ui/f6/callout.html'}
+ {* Emails Sent *}
+ {$ui = [
+ 'label' => 'Emails Sent',
+ 'active' => $emailsSent,
+ 'type' => 'success'
+ ]}
+ {include file='ui/f6/callout.html'}
+
+
+ <form id="sendMessagesForm" action="{$thisUrl}?page={$thisPage}" method="post">
<input type="hidden" name="page" value="{$thisPage}" />
<input type="hidden" name="option" value="search" />
<input type="hidden" name="option2" value="sendMessages" />
<input type="hidden" name="filterContactLastName" value="{$smarty.request.filterContactLastName}" />
{/if}
<div class="grid-x grid-margin-x">
- <div class="cell small-12">
+ <div class="cell small-12 medium-6">
<label for="message_id">Message</label>
<select id="message_id" name="message_id" required>
<option value="">-- Select --</option>
{/foreach}
</select>
</div>
- </div>
- <div class="grid-x grid-margin-x">
- <div class="cell small-12">
- <input type="submit" class="button primary" value="Send Messages" />
+ <div class="cell small-12 medium-6">
+ <input type="submit" class="button primary" value="Queue Messages" />
+ <input id="sendNowVar" type="hidden" name="sendNow" value="0">
+ <input id="sendNow" type="submit" class="button primary" value="Send Messages Now" />
</div>
</div>
</form>
</form>
{/if}
-{if $emailsQueued}<span class="glm-notice glm-flash-updated">Emails Queued</span>{/if}
-
{if $searchResults}
<table class="stack" style="max-width: 800px;">
<thead>
<script>
jQuery(document).ready(function($) {
+ $('#sendNow').on('click', function(e){
+ e.preventDefault();
+ $('#sendNowVar').val( '1' );
+ $('#sendMessagesForm').submit();
+ });
+
// Flash certain elements for a short time after display
$(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);