--- /dev/null
+<?php
+/**
+ * Gaslight Media Associate
+ * Billings Plugin support class
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmBilling
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release notifications.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+class GlmRegNotifications
+{
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+
+ /**
+ * Constructor
+ *
+ * @param object $d database connection
+ * @param array $config Configuration array
+ *
+ * @return void
+ * @access public
+ */
+ public function __construct($wpdb, $config)
+ {
+
+ // If this class is not being extended along with existing $wpdb and $config
+ if (!$this->wpdb) {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ }
+
+ /**
+ * sendEmailNotification
+ *
+ * Send out the email notification based on reg_notification and the regEventID.
+ *
+ * @param mixed $reg_notification Id for reg_notifgication.
+ * @param mixed $reg_event_id Id for the reg Event.
+ *
+ * @access public
+ * @return void
+ */
+ public function sendEmailNotification( $reg_notification, $reg_event_id )
+ {
+ $to_email = $account['email'];
+ // echo '<pre>$to_email: ' . print_r( $to_email, true ) . '</pre>';
+ if ( !$to_email ) {
+ // If there's no email then return false.
+ return false;
+ }
+
+ // get the Notification type
+ var_dump( $reg_notification );
+ $notification = $this->getRegNotificationById( $reg_notification );
+ echo '<pre>$notification: ' . print_r( $notification, true ) . '</pre>';
+ if ( !$notification ) {
+ // If there's no notification type then return false.
+ return false;
+ }
+ $subject = $notification['subject'];
+ if ( !$subject ) {
+ // If there's no subject then return false.
+ return false;
+ }
+ $from_header = $notification['from_header'];
+ $replyto = $notification['replyto'];
+
+ // Setup the Smarty Engine
+ $smarty = new smartyTemplateSupport();
+ $viewPath = GLM_MEMBERS_BILLING_PLUGIN_PATH . '/views';
+ $smarty->template->setTemplateDir( $viewPath );
+
+ // Add standard parameters
+ require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
+ $viewFile = 'admin/notifications/notification.html';
+
+ $account_data = array(
+ 'account' => array(
+ 'name' => $account['ref_name'],
+ 'email' => $account['email'],
+ 'addr1' => $account['billing_addr1'],
+ 'addr2' => $account['billing_addr2'],
+ 'city' => $account['billing_city'],
+ 'state' => $account['billing_state'],
+ 'zip' => $account['billing_zip'],
+ 'phone' => $account['billing_phone'],
+ )
+ );
+ echo '<pre>$notification[message]: ' . print_r( $notification['message'], true ) . '</pre>';
+ $notification_message = $this->parseSmartyTemplateString(
+ $account_data,
+ wpautop( $notification['message'] )
+ );
+ echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
+ echo '<pre>$notification_message: ' . print_r( $notification_message, true ) . '</pre>';
+ // exit;
+
+ $smarty->templateAssign( 'title', $notification['subject'] );
+ $smarty->templateAssign( 'html_content', $notification_message );
+
+ // Generate output from model data and view
+ $htmlMessage = $smarty->template->fetch( $viewFile );
+
+
+ // change the default wordpress from name when sending mail
+ add_filter(
+ 'wp_mail_from_name',
+ function ( $name ) {
+ $siteName = get_bloginfo( 'name' );
+ return $siteName;
+ }
+ );
+ // 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_header;
+ $header[] = 'Reply-To:' . $replyto;
+
+ wp_mail( $to_email, $subject, $message, $header );
+
+ // remove the filter to avoid conflicts
+ remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+
+ // Send notification to recordNotification
+ $notice_data = array(
+ 'reg_notification' => $reg_notification,
+ 'account' => $account_id,
+ 'from_replyto' => $from_header,
+ 'subject' => $subject,
+ 'message' => $message,
+ 'email_sent' => $to_email,
+ );
+ $this->recordNotification( $notice_data );
+ }
+
+ /**
+ * getRegNotificationById
+ *
+ * Grab the reg_notification given an id.
+ *
+ * @param mixed $id Id of the reg_notification to return.
+ *
+ * @access public
+ * @return array or false if not found
+ */
+ public function getRegNotificationById( $id )
+ {
+ return $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT *
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_notification
+ WHERE id = %d",
+ $id
+ )
+ );
+ }
+
+ /**
+ * parseSmartyTemplateString
+ *
+ *
+ *
+ * @param mixed $data
+ * @param mixed $template_string
+ *
+ * @access public
+ * @return void
+ */
+ public function parseSmartyTemplateString( $data, $template_string )
+ {
+ // Load Smarty Template support
+ $smarty = new smartyTemplateSupport();
+
+ // Add standard parameters
+ require GLM_MEMBERS_PLUGIN_SETUP_PATH . '/standardTemplateParams.php';
+
+ // Add data from model to Smarty template
+ if ( is_array( $data ) && count( $data ) > 0 ) {
+ foreach ( $data as $key => $value ) {
+ echo '<pre>$key: ' . print_r( $key, true ) . '</pre>';
+ $smarty->templateAssign( $key, $value );
+ }
+ }
+
+ return $smarty->template->fetch( 'eval:' . $template_string );
+ }
+
+ /**
+ * recordNotification
+ *
+ * Record the notification.
+ *
+ * @param mixed $notification Array of data for the notification
+ i
+ * @access public
+ * @return void
+ */
+ public function recordNotification( $notification )
+ {
+ if ( !$notification['notification_type'] || !$notification['account']
+ || !$notification['from_replyto'] || !$notification['subject']
+ || !$notification['message'] || !$notification['email_sent']
+ ) {
+ return false;
+ }
+ $this->wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notifications',
+ array(
+ 'notification_type' => $notification['notification_type'],
+ 'account' => $notification['account'],
+ 'from_replyto' => $notification['from_replyto'],
+ 'subject' => $notification['subject'],
+ 'message' => $notification['message'],
+ 'date_sent' => date('Y-m-d H:i;s'),
+ 'email_sent' => $notification['email_sent'],
+ ),
+ array(
+ '%d', // notification_type
+ '%d', // account
+ '%s', // from_replyto
+ '%s', // subject
+ '%s', // message
+ '%s', // date_sent
+ '%s', // email_sent
+ )
+ );
+ return true;
+ }
+
+ /**
+ * Set content type of the email.
+ *
+ * Used as filter for the wp_mail_content_type
+ */
+ function set_content_type()
+ {
+ return "text/html";
+ }
+
+ /**
+ * queueNotice
+ *
+ * Queue the noticifation.
+ *
+ * @param mixed $notification_type Id for the notification type
+ * @param mixed $account Id for the account
+ *
+ * @access public
+ * @return void
+ */
+ public function queueNotice( $notification_type, $account )
+ {
+ // First check to see if there's already one in the queue.
+ $queue_id = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue
+ WHERE notification_type = %d
+ AND account = %d",
+ $notification_type,
+ $account
+ )
+ );
+ if ( !$queue_id ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notification_queue',
+ array(
+ 'notification_type' => $notification_type,
+ 'account' => $account
+ ),
+ array(
+ '%d',
+ '%d'
+ )
+ );
+ }
+ }
+
+ /**
+ * getQueuedNotifications
+ *
+ * Grab queued notifications. Number is based on input.
+ * If nothing given then defaults to all queued notifications.
+ *
+ * @param int $limit Number of queued items to fetch.
+ *
+ * @access public
+ * @return array
+ */
+ public function getQueuedNotifications( $limit )
+ {
+ $query =
+ "SELECT *
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_queue";
+ if ( $numb = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
+ $query .= " LIMIT $limit OFFSET 0";
+ }
+ return $this->wpdb->get_results(
+ $query,
+ ARRAY_A
+ );
+ }
+
+ /**
+ * deleteQueue
+ *
+ * Remove notice from the queue.
+ *
+ * @param mixed $queue_id Queue id to delete.
+ *
+ * @access public
+ * @return void
+ */
+ public function deleteQueue( $queue_id )
+ {
+ $this->wpdb->delete(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'notification_queue',
+ array( 'id' => $queue_id ),
+ array( '%d' )
+ );
+ }
+}
<div class="glm-row">
<div class="glm-small-12 glm-column">
<input
+ id="notificationDays"
type="number"
min="0"
name="notification_days[{if $newEntry}-1{else}{$regNotifications.fieldData.id}{/if}]"
value="{if $newEntry}0{else}{$regNotifications.fieldData.notification_days|regex_replace:"/[-]/":""}{/if}"
class="glm-form-text-input-veryshort"> Days
- <select name="when[{if $newEntry}-1{else}{$regNotifications.fieldData.id}{/if}]">
+ <select id="notificationWhen" name="when[{if $newEntry}-1{else}{$regNotifications.fieldData.id}{/if}]">
<option value="before"{if $regNotifications.fieldData.notification_days lt 0} selected{/if}>Before</option>
<option value="after"{if $regNotifications.fieldData.notification_days gt 0} selected{/if}>After</option>
</select>
var calendar;
var regEvent = {
id: 'regEvent',
- title: 'regEvent',
- start: '01/27/2018',
- end: '01/27/2018',
+ title: 'Event',
+ start: '{$regEvent.first_datetime.datetime}',
+ end: '{$regEvent.first_datetime.datetime}',
allDay: true,
};
+ function getSendDate(){
+ var EventDate = new Date(
+ {$regEvent.first_datetime.timestamp|date_format:"%Y"},
+ {$regEvent.first_datetime.timestamp|date_format:"%m"} - 1,
+ {$regEvent.first_datetime.timestamp|date_format:"%e"}
+ );
+ var notificationDays = $('#notificationDays').val();
+ var notificationWhen = $('#notificationWhen').val();
+ var sendDate = new Date(
+ {$regEvent.first_datetime.timestamp|date_format:"%Y"},
+ {$regEvent.first_datetime.timestamp|date_format:"%m"} - 1,
+ {$regEvent.first_datetime.timestamp|date_format:"%e"}
+ );
+ if ( notificationWhen == 'before' ) {
+ sendDate.setDate(sendDate.getDate() - parseInt(notificationDays));
+ } else {
+ sendDate.setDate(sendDate.getDate() + parseInt(notificationDays));
+ }
+ calendar.fullCalendar('removeEvents', 'notice');
+ var dateString = (sendDate.getMonth() + 1 ) + '/' + sendDate.getDate() + '/' + sendDate.getFullYear();
+ var newEvent = {
+ id: 'notice',
+ title: 'Send',
+ start: dateString,
+ end: dateString,
+ allDay: true,
+ color: 'rgb(255,0,0)'
+ };
+ calendar.fullCalendar('renderEvent', newEvent, true);
+ }
+
function initFullCalendar(){
calendar = $('#datepicker').fullCalendar({
timezone: 'local',
events: [
regEvent
+ {if !$newEntry}
+ ,{
+ id: 'notice',
+ title: 'Send',
+ start: '01/16/2018',
+ end: '01/16/2018',
+ allDay: true,
+ }
+ {/if}
],
defaultDate: '01/27/2018',
- dayClick: function( date, allDay, jsEvent, view ){
- // console.log( 'jsEvent: ', jsEvent );
- console.log( 'date: ', date );
- calendar.fullCalendar('removeEvents', 'selected');
- var newEvent = {
- id: 'selected',
- title: 'selected',
- start: date.format(),
- end: date.format(),
- allDay: true,
- };
- calendar.fullCalendar('renderEvent', newEvent, true);
- },
});
// console.log( 'cal:', calendar );
}
initFullCalendar();
+ getSendDate();
+ $('#notificationDays').click(function(){
+ getSendDate();
+ });
+ $('#notificationWhen').click(function(){
+ getSendDate();
+ });
// 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);