Fixing bugs for add and update.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 18 Jan 2018 17:55:57 +0000 (12:55 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 18 Jan 2018 17:55:57 +0000 (12:55 -0500)
Fix issue with the data format when inserting the notification.

models/admin/registrations/events_notifications.php
models/admin/registrations/events_notificationsUpdate.php
views/admin/registrations/eventEditNotification.html
views/admin/registrations/eventNotifications.html

index 2cf0947..759d85b 100644 (file)
@@ -19,6 +19,7 @@ $Notifications = new GlmDataRegistrationsRegNotification($this->wpdb, $this->con
 $regEvent = $this->getEntry($regEventID);
 
 if ( isset( $_REQUEST['delete'] ) && filter_var( $_REQUEST['delete'], FILTER_VALIDATE_BOOLEAN ) ) {
+    $regNotifications = $Notifications->getList("T.reg_event = $regEventID", 'notification_days');
     $view = 'eventNotifications';
 } else if ( isset( $_REQUEST['id'] ) && $notice_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
     $regNotifications = $Notifications->editEntry( $notice_id );
index b8064c1..3bd743c 100644 (file)
 // New and updated notifications
 if ( isset( $_REQUEST['name'] ) && is_array( $_REQUEST['name'] ) ) {
 
+    // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
     foreach ( $_REQUEST['name'] as $key => $val ) {
 
         // Make sure key is positive integer
         $id = ( $key - 0 );
+        // Check the before or after for setting the sign for notification_days
+        $notification_days = filter_var( $_REQUEST['notification_days'][$id], FILTER_VALIDATE_INT );
+        $notification_when = filter_var( $_REQUEST['when'][$id], FILTER_SANITIZE_STRING );
+        if ( $notification_when === 'before' ) {
+            $notification_days = '-' . $notification_days;
+        }
+        $reg_notification_data = array(
+            'name'              => $_REQUEST['name'][$id],
+            'notification_days' => $notification_days,
+            'message'           => $_REQUEST['message'][$id]
+        );
+        // echo '<pre>$reg_notification_data: ' . print_r( $reg_notification_data, true ) . '</pre>';
         if ( $id > 0 ) {
 
             // Update existing entry
             $this->wpdb->update(
                 GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_notification',
-                array(
-                    'name'              => $_REQUEST['name'][$id],
-                    'notification_days' => $_REQUEST['notification_days'][$id],
-                    'message'           => $_REQUEST['message'][$id]
-                ),
+                $reg_notification_data,
                 array( 'id' => $id ),
                 array( '%s', '%d', '%s' ),
                 array( '%d' )
@@ -38,16 +48,12 @@ if ( isset( $_REQUEST['name'] ) && is_array( $_REQUEST['name'] ) ) {
             // Otherwise if the id is less than 0 it must be a new one
         } elseif ( $id < 0 ) {
 
+            $reg_notification_data['reg_event'] = $regEventID;
             // Insert a new entry
             $this->wpdb->insert(
                 GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_notification',
-                array(
-                    'reg_event'         => $regEventID,
-                    'name'              => $_REQUEST['name'][$id],
-                    'notification_days' => $_REQUEST['notification_days'][$id],
-                    'message'           => $_REQUEST['message'][$id]
-                ),
-                array( '%d', '%s', '%d', '%s' )
+                $reg_notification_data,
+                array( '%s', '%d', '%s', '%d' )
             );
         }
     }
index a9b5098..49a0dcb 100644 (file)
                         type="number"
                         min="0"
                         name="notification_days[{if $newEntry}-1{else}{$regNotifications.fieldData.id}{/if}]"
-                        value="{if $newEntry}0{else}{$regNotifications.fieldData.notification_days}{/if}"
-                        class="glm-form-text-input-veryshort">
-                        <select name="when">
-                            <option value="before"{if $when === 'before'} selected{/if}>Before</option>
-                            <option value="after"{if $when === 'after'} selected{/if}>After</option>
+                        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}]">
+                            <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>
                     </div>
                     <div class="glm-small-12 glm-column">
index c9ea091..496afa9 100644 (file)
@@ -34,7 +34,7 @@
                             class=""
                             href="{$thisUrl}?page={$thisPage}&option=notifications&regEventID={$regEventID}&id={$n.id}">{$n.name}</a>
                     </td>
-                    <td>When?</td>
+                    <td>{$n.notification_days|regex_replace:"/[-]/":""} days {if $n.notification_days > 0 }After{else}Before{/if}</td>
                     <td>
                         <a
                             class="button button-secondary glm-button-small glm-right delete-notice"