From: Steve Sutton Date: Thu, 18 Jan 2018 17:55:57 +0000 (-0500) Subject: Fixing bugs for add and update. X-Git-Tag: v1.0.0^2~53^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c98031fe983eab75d1e414767f6e0c9836ea6d3a;p=WP-Plugins%2Fglm-member-db-registrations.git Fixing bugs for add and update. Fix issue with the data format when inserting the notification. --- diff --git a/models/admin/registrations/events_notifications.php b/models/admin/registrations/events_notifications.php index 2cf0947..759d85b 100644 --- a/models/admin/registrations/events_notifications.php +++ b/models/admin/registrations/events_notifications.php @@ -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 ); diff --git a/models/admin/registrations/events_notificationsUpdate.php b/models/admin/registrations/events_notificationsUpdate.php index b8064c1..3bd743c 100644 --- a/models/admin/registrations/events_notificationsUpdate.php +++ b/models/admin/registrations/events_notificationsUpdate.php @@ -16,20 +16,30 @@ // New and updated notifications if ( isset( $_REQUEST['name'] ) && is_array( $_REQUEST['name'] ) ) { + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + 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 '
$reg_notification_data: ' . print_r( $reg_notification_data, true ) . '
'; 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' ) ); } } diff --git a/views/admin/registrations/eventEditNotification.html b/views/admin/registrations/eventEditNotification.html index a9b5098..49a0dcb 100644 --- a/views/admin/registrations/eventEditNotification.html +++ b/views/admin/registrations/eventEditNotification.html @@ -49,11 +49,11 @@ 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"> - + +
diff --git a/views/admin/registrations/eventNotifications.html b/views/admin/registrations/eventNotifications.html index c9ea091..496afa9 100644 --- a/views/admin/registrations/eventNotifications.html +++ b/views/admin/registrations/eventNotifications.html @@ -34,7 +34,7 @@ class="" href="{$thisUrl}?page={$thisPage}&option=notifications®EventID={$regEventID}&id={$n.id}">{$n.name} - When? + {$n.notification_days|regex_replace:"/[-]/":""} days {if $n.notification_days > 0 }After{else}Before{/if}