Updating how the emails are getting the email_notifications.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 18 Aug 2017 19:58:22 +0000 (15:58 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 18 Aug 2017 19:58:22 +0000 (15:58 -0400)
Adding these setting for email_notifications into the main event
settings array when it is setup for config. Now we can just use
$this->config['settings'] for grabbing any of the email_notification
settings.

classes/data/dataEmailNotifications.php
index.php
models/admin/events/list.php
models/front/events/frontAdd.php
setup/adminHooks.php
setup/databaseScripts/create_database_V0.1.4.sql
setup/databaseScripts/update_database_V0.1.4.php
setup/databaseScripts/update_database_V0.1.4.sql
views/admin/settings/emailNotifications.html

index cf8d99a..d93c33d 100644 (file)
@@ -122,6 +122,13 @@ class GlmDataEmailNotifications extends GlmDataAbstract
                 'use' => 'a'
             ),
 
+            // Email Notification Message
+            'email_notification' => array(
+                'field' => 'email_notification',
+                'type' => 'text',
+                'required' => false,
+                'use' => 'a'
+            ),
             // Event Declined Message
             'declined_message' => array(
                 'field' => 'declined_message',
index e5f5bde..06a1333 100644 (file)
--- a/index.php
+++ b/index.php
@@ -149,6 +149,12 @@ if (is_file(GLM_MEMBERS_EVENTS_PLUGIN_DB_SCRIPTS.'/dbVersions.php')) {
 
 // Load Events Management Settings data
 $eventsManagementSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A );
+// Grab the new email_notification to_email and from_email to add to these (override)
+$emailNotifications = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."email_notifications WHERE id = 1", ARRAY_A );
+if ( $eventsManagementSettings ) {
+    $eventsManagementSettings = array_merge( $eventsManagementSettings, $emailNotifications );
+}
+
 unset($eventsManagementSettings['id']);
 
 function glmMembersRegisterEvents($addOns) {
index 1b6b7d1..615a701 100644 (file)
@@ -400,7 +400,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                     $haveEvent = false;
                     $event = false;
                 }
-                
+
                 $view = 'edit';
                 break;
 
@@ -644,7 +644,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                 } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
                     unset( $_SESSION['search']['prevStart'] );
                 }
-  
+
                 // Check for Archived filter
                 if (isset($_REQUEST['filterArchived']) && $_REQUEST['filterArchived'] == 'on') {
                     $filterArchived = true;
@@ -793,7 +793,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                         $start = $newStart;
                     }
                 }
-                
+
                 if( isset($_SESSION['search']['pageSelect']) ){
                      // If request is for Next
                     if ($_SESSION['search']['pageSelect'][0] == 'N') {
@@ -891,20 +891,21 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
 
             }
 
-            
+
         }
             // DECLINED & APPROVED EVENT EMAIL FUNCTIONALITY ///////
-            $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "email_notifications";
-            $email_notifications = !empty($this->wpdb->get_results($sql, ARRAY_A)) ? $this->wpdb->get_results($sql, ARRAY_A)[0] : false;
+            //$sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "email_notifications";
+            //$email_notifications = !empty($this->wpdb->get_results($sql, ARRAY_A)) ? $this->wpdb->get_results($sql, ARRAY_A)[0] : false;
+            $email_notifications = $this->config['settings'];
             $from_email = $email_notifications ? $email_notifications['from_email'] : false;
 //            echo '<pre>', print_r($event), '</pre>';
-            
+
             $to_email = (isset($event['fieldData']['admin_email']) ? $event['fieldData']['admin_email'] : '' );
             $event_title = (isset($event['fieldData']['name']) ? $event['fieldData']['name'] : '' );
             $admin_name = (isset($event['fieldData']['admin_name']) ? $event['fieldData']['admin_name'] : '' );
             $event_intro = (isset($event['fieldData']['intro']) ? $event['fieldData']['intro'] : '' );
             $site_name = get_bloginfo( 'name' );
-            
+
             $header[] = "From: $site_name <$from_email>";
             $header[] = 'Reply-To: ' . $from_email;
             $header[] = "Return-Path: $from_email";
@@ -933,8 +934,8 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                 $message .= "Event Name: " . $event_title . "<br>";
                 $message .= "Event Description: $event_intro<br>";
                 $message .= "Contact Name: $admin_name<br><br>";
-                
-                
+
+
                 if( $old_event_status === '20' && $current_status === '10' ) {
                     $subject  = 'Event Approved';
                     $message  .= $email_notifications['approved_message'];
@@ -950,7 +951,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
             remove_filter( 'wp_mail_content_type', 'set_content_type' );
             // END DECLINED & APPROVED EVENT EMAIL FUNCTIONALITY ////////
 
-        
+
         if (!$this->config['settings']['event_default_state']) {
             $this->config['settings']['event_default_state'] = $this->config['settings']['default_state'];
         }
index 2925b5f..fd06b9d 100644 (file)
@@ -238,8 +238,11 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         $view = 'frontAdd';
         // populate category dropdown
         $categories = new GlmDataEventsCategories( $this->wpdb, $this->config );
-        $emailInfo  = new GlmDataEventsManagement( $this->wpdb, $this->config );
-        $emailInfo  = $emailInfo->getEntry(1);
+        //$emailInfo  = new GlmDataEventsManagement( $this->wpdb, $this->config );
+        //$emailInfo  = $emailInfo->getEntry(1);
+        // Get email setting from config['settings']
+        $emailInfo = $this->config['settings'];
+
 
         // get and validate recipient email address, put into an array to pass to wp_mail
         $toEmail = $emailInfo['to_email'];
@@ -661,30 +664,30 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
 //                        $siteName = get_bloginfo('name');
 //                        return $siteName;
 //                    }
-//                    
-//                   // Send confirmation email to the admin, set the content type to allow html by using this filter 
-                    $sql = "SELECT to_email, from_email FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "email_notifications";
-                    $email_addresses = $this->wpdb->get_results($sql, ARRAY_A)[0];
-                    
+//
+//                  // Send confirmation email to the admin, set the content type to allow html by using this filter
+                    //$sql = "SELECT to_email, from_email FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "email_notifications";
+                    //$email_addresses = $this->wpdb->get_results($sql, ARRAY_A)[0];
+
                     add_filter( 'wp_mail_content_type', 'set_content_type' );
 
-                    $site_name = get_bloginfo('name');
-                    $adminEmail      = $email_addresses['to_email'];
-                    $fromEmail = $email_addresses['from_email'];
-                    $subject = 'Event Form Submission';
+                    $site_name  = get_bloginfo('name');
+                    $adminEmail = $emailInfo['to_email'];
+                    $fromEmail  = $emailInfo['from_email'];
+                    $subject    = 'Event Form Submission';
+
+                    $message    = $htmlMessage;
+                    $userBody   = $userMessage;
 
-                    $message = $htmlMessage;
-                    $userBody = $userMessage;
+                    $header[]   = "From: $site_name <$fromEmail>";
+                    $header[]   = 'Reply-To:' . $userEmail;
 
-                    $header[] = "From: $site_name <$fromEmail>";
-                    $header[] = 'Reply-To:' . $userEmail;
-             
                     wp_mail($adminEmail, $subject, $message, $header);
-                    
+
                     // send a copy to the user submitting the email, using different headers and email template file
                     $userHeader[] = "From: $site_name <$fromEmail>";
                     $userHeader[] = 'Reply-To: No-Reply@gaslightmedia.com';
-                    
+
                     if(wp_mail($userEmail, $subject, $userBody, $userHeader)){
 
                     } else {
index 1758c81..43f30df 100644 (file)
@@ -86,7 +86,9 @@ add_filter( 'glm-member-db-events-get-event', function( $eventID ){
 } );
 
 // check the settings to see if members are allow to manage events
-$memberEventsAllowed = $this->config['settings']['member_events_allowed'];
+$memberEventsAllowed = isset( $this->config['settings']['member_events_allowed'] )
+    ? $this->config['settings']['member_events_allowed']
+    : true;
 
 if ( $memberEventsAllowed ) {
     add_filter(
index 518a8fb..3686fba 100644 (file)
@@ -262,6 +262,7 @@ CREATE TABLE {prefix}email_notifications (
     approved_message TEXT NULL,    -- Event approved message
     to_email TINYTEXT NULL,        -- To Email Address
     from_email TINYTEXT NULL,      -- From Email Address
+    email_notification TEXT NULL,  -- Email notification message
     PRIMARY KEY (id)
 );
 
index 22615cd..88a1356 100644 (file)
@@ -7,7 +7,7 @@
 
 // Update new email_notification table with the old to from email from management
 $managementOptions = $wpdb->get_results(
-    'SELECT id, to_email, from_email FROM '.GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX.'management where id = 1',
+    'SELECT * FROM '.GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX.'management where id = 1',
     ARRAY_A
 );
 if ($managementOptions && count($managementOptions) > 0) {
@@ -15,11 +15,12 @@ if ($managementOptions && count($managementOptions) > 0) {
         $wpdb->update(
                 GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX.'email_notifications',
                 array(
-                    'to_email'   => $i['to_email'],
-                    'from_email' => $i['from_email']
+                    'to_email'           => $i['to_email'],
+                    'from_email'         => $i['from_email'],
+                    'email_notification' => $i['email_notification']
                 ),
                 array( 'id' => $i['id'] ),
-                array( '%s', '%s' ),
+                array( '%s', '%s', '%s' ),
                 array( '%d')
         );
     }
index ba2739d..bc53fda 100644 (file)
@@ -12,3 +12,8 @@ ALTER TABLE {prefix}management ADD COLUMN member_events_allowed BOOLEAN NULL;  -
 ----
 
 UPDATE {prefix}management SET member_events_allowed = 1 WHERE id = 1;
+
+----
+
+-- new field in email_notifications
+ALTER TABLE {prefix}email_notifications ADD COLUMN email_notification TEXT NULL;  -- Email notification message
index d258006..4519842 100644 (file)
@@ -1,6 +1,6 @@
 {include file='admin/settings/header.html'}
     <!-- Add Categories Button and Dialog Box -->
-    
+
     <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
         <input type="hidden" name="glm_action" value="emailNotifications">
         {if $email_settings}
                 <div class="email-notification-info">This email address is what recipient will receive from the accept/decline email message that is automatically sent once action has been taken on event record.</div>
             </div>
         </div>
+        <div class="glm-row">
+            <div class="glm-small-12 glm-medium-3 glm-column email-notification-label"> Email Notification Message </div>
+            <div class="glm-small-12 glm-medium-9 glm-column email-notification-editor">
+                    {php}
+                        wp_editor('{if $email_settings} {$email_settings.email_notification|escape:quotes} {/if}', 'glm_notification', array(
+                            'media_buttons' => false,
+                            // 'quicktags' => false,
+                            // 'wpautop' => false,  NOTE: Dont's use. Problem when numerous spaces before text.
+                            'textarea_name' => 'email_notification',
+                            'editor_height' => 300,     // Height in px, overrides editor_rows
+                                // 'textarea_rows' => 8
+                        ));
+                    {/php}
+            </div>
+        </div>
         <div class="glm-row">
             <div class="glm-small-12 glm-medium-3 glm-column email-notification-label"> Declined Message </div>
             <div class="glm-small-12 glm-medium-9 glm-column email-notification-editor">
@@ -55,7 +70,7 @@
 
     <script type="text/javascript">
         jQuery(document).ready(function($) {
-               
+
         });
     </script>
 {include file='admin/footer.html'}