// 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' )
// 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' )
);
}
}
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">