$notification ) {
if ( $id == $notification_id ) {
return $notification;
}
}
return array();
}
public static function notification_page() {
$form_id = rgget( 'id' );
$notification_id = rgget( 'nid' );
if ( ! rgblank( $notification_id ) ) {
self::notification_edit_page( $form_id, $notification_id );
} else {
self::notification_list_page( $form_id );
}
}
public static function notification_edit_page( $form_id, $notification_id ) {
if ( ! rgempty( 'gform_notification_id' ) ) {
$notification_id = rgpost( 'gform_notification_id' );
}
$form = RGFormsModel::get_form_meta( $form_id );
$form = gf_apply_filters( 'gform_form_notification_page', $form_id, $form, $notification_id );
$notification = ! $notification_id ? array() : self::get_notification( $form, $notification_id );
// added second condition to account for new notifications with errors as notification ID will
// be available in $_POST but the notification has not actually been saved yet
$is_new_notification = empty( $notification_id ) || empty( $notification );
$is_valid = true;
$is_update = false;
if ( rgpost( 'save' ) ) {
check_admin_referer( 'gforms_save_notification', 'gforms_save_notification' );
//clear out notification because it could have legacy data populated
$notification = array( 'isActive' => isset( $notification['isActive'] ) ? rgar( $notification, 'isActive' ) : true );
$is_update = true;
if ( $is_new_notification ) {
$notification_id = uniqid();
$notification['id'] = $notification_id;
} else {
$notification['id'] = $notification_id;
}
$notification['name'] = sanitize_text_field( rgpost( 'gform_notification_name' ) );
$notification['event'] = sanitize_text_field( rgpost( 'gform_notification_event' ) );
$notification['to'] = rgpost( 'gform_notification_to_type' ) == 'field' ? rgpost( 'gform_notification_to_field' ) : rgpost( 'gform_notification_to_email' );
$to_type = rgpost( 'gform_notification_to_type' );
if ( ! in_array( $to_type, array( 'email', 'field', 'routing', 'hidden' ) ) ) {
$to_type = 'email';
}
$notification['toType'] = $to_type;
$notification['bcc'] = rgpost( 'gform_notification_bcc' );
$notification['subject'] = sanitize_text_field( rgpost( 'gform_notification_subject' ) );
$notification['message'] = rgpost( 'gform_notification_message' );
$notification['from'] = sanitize_text_field( rgpost( 'gform_notification_from' ) );
$notification['fromName'] = sanitize_text_field( rgpost( 'gform_notification_from_name' ) );
$notification['replyTo'] = rgpost( 'gform_notification_reply_to' );
$routing = ! rgempty( 'gform_routing_meta' ) ? GFCommon::json_decode( rgpost( 'gform_routing_meta' ), true ) : null;
if ( ! empty ( $routing ) ) {
$routing_logic = array( 'rules' => $routing );
$routing_logic = GFFormsModel::sanitize_conditional_logic( $routing_logic );
$notification['routing'] = $routing_logic['rules'];
}
$notification['routing'] = $routing;
$conditional_logic = ! rgempty( 'gform_conditional_logic_meta' ) ? GFCommon::json_decode( rgpost( 'gform_conditional_logic_meta' ), true ) : null;
$notification['conditionalLogic'] = GFFormsModel::sanitize_conditional_logic( $conditional_logic );
$notification['disableAutoformat'] = (bool) rgpost( 'gform_notification_disable_autoformat' );
if ( rgpost( 'gform_is_default' ) ) {
$notification['isDefault'] = true;
}
$notification = gf_apply_filters( 'gform_pre_notification_save', $form_id, $notification, $form, $is_new_notification );
//validating input...
$is_valid = self::validate_notification();
if ( $is_valid ) {
//input valid, updating...
//emptying notification email if it is supposed to be disabled
if ( $_POST['gform_notification_to_type'] == 'routing' ) {
$notification['to'] = '';
} else {
$notification['routing'] = null;
}
// trim values
$notification = GFFormsModel::trim_conditional_logic_values_from_element( $notification, $form );
$form['notifications'][ $notification_id ] = $notification;
RGFormsModel::save_form_notifications( $form_id, $form['notifications'] );
}
}
if ( $is_update && $is_valid ) {
$url = remove_query_arg( 'nid' );
GFCommon::add_message( sprintf( esc_html__( 'Notification saved successfully. %sBack to notifications.%s', 'gravityforms' ), '', '' ) );
} else if ( $is_update && ! $is_valid ) {
GFCommon::add_error_message( esc_html__( 'Notification could not be updated. Please enter all required information below.', 'gravityforms' ) );
}
// moved page header loading here so the admin messages can be set upon saving and available for the header to print out
GFFormSettings::page_header( esc_html__( 'Notifications', 'gravityforms' ) );
$notification_ui_settings = self::get_notification_ui_settings( $notification );
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min';
?>
0 ) );
?>
prepare_items();
?>
';
$ui_settings = array();
$form_id = rgget( 'id' );
$form = RGFormsModel::get_form_meta( $form_id );
$form = gf_apply_filters( 'gform_admin_pre_render', $form_id, $form );
$is_valid = empty( GFCommon::$errors );
ob_start(); ?>
>
|
|
|
esc_html__( 'Form is submitted', 'gravityforms' ) );
if ( rgars( $form, 'save/enabled' ) ) {
$notification_events['form_saved'] = esc_html__( 'Form is saved', 'gravityforms' );
$notification_events['form_save_email_requested'] = esc_html__( 'Save and continue email is requested', 'gravityforms' );
}
$notification_events = apply_filters( 'gform_notification_events', $notification_events, $form );
$event_style = count( $notification_events ) == 1 || rgar( $notification, 'isDefault' ) ? "style='display:none'" : '';
?>
>
|
|
|
>
|
|
value="email" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_email_container').show('slow');" />
value="field" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_field_container').show('slow');" />
value="routing" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_routing_container').show('slow');" />
|
';
}
?>
>
|
.
|
>
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
>
|
|
false, 'editor_class' => 'merge-tag-support mt-wp_editor mt-manual_position mt-position-right' ) );
} else {
?>
|
|
|
/>
|
>
|
|
/>
|
|
|
id;
}
}
return 0;
}
private static function get_routing_fields( $form, $selected_field_id ) {
$str = '';
foreach ( $form['fields'] as $field ) {
$input_type = RGFormsModel::get_input_type( $field );
$field_label = RGFormsModel::get_label( $field );
if ( in_array( $input_type, self::get_routing_field_types() ) ) {
$selected = $field->id == $selected_field_id ? "selected='selected'" : '';
$str .= "';
}
}
return $str;
}
public static function get_routing_field_types() {
$field_types = apply_filters( 'gform_routing_field_types', self::$supported_fields );
return $field_types;
}
private static function get_field_values( $i, $form, $field_id, $selected_value, $max_field_length = 16 ) {
if ( empty( $field_id ) ) {
$field_id = self::get_first_routing_field( $form );
}
if ( empty( $field_id ) ) {
return '';
}
$field = RGFormsModel::get_field( $form, $field_id );
$is_any_selected = false;
$str = '';
if ( ! $field ) {
return '';
}
if ( $field->type == 'post_category' && $field->displayAllCategories == true ) {
$str .= wp_dropdown_categories( array( 'class' => 'gfield_routing_select gfield_category_dropdown gfield_routing_value_dropdown', 'orderby' => 'name', 'id' => 'routing_value_' . $i, 'selected' => $selected_value, 'hierarchical' => true, 'hide_empty' => 0, 'echo' => false ) );
} elseif ( $field->choices ) {
$str .= "';
} else {
//create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...)
$str = "";
}
return $str;
}
public static function get_post_category_values() {
$id = 'routing_value_' . rgpost( 'ruleIndex' );
$selected = rgempty( 'selectedValue' ) ? 0 : rgpost( 'selectedValue' );
$dropdown = wp_dropdown_categories( array( 'class' => 'gfield_routing_select gfield_routing_value_dropdown gfield_category_dropdown', 'orderby' => 'name', 'id' => $id, 'selected' => $selected, 'hierarchical' => true, 'hide_empty' => 0, 'echo' => false ) );
die( $dropdown );
}
/**
* Delete a form notification by ID.
*
* @param mixed $notification_id
* @param mixed $form_id Can pass a form ID or a form object
*
* @return mixed
*/
public static function delete_notification( $notification_id, $form_id ) {
if ( ! $form_id ) {
return false;
}
$form = ! is_array( $form_id ) ? RGFormsModel::get_form_meta( $form_id ) : $form_id;
do_action( 'gform_pre_notification_deleted', $form['notifications'][ $notification_id ], $form );
unset( $form['notifications'][ $notification_id ] );
// clear Form cache so next retrieval of form meta will reflect deleted notification
RGFormsModel::flush_current_forms();
return RGFormsModel::save_form_notifications( $form['id'], $form['notifications'] );
}
public static function duplicate_notification( $notification_id, $form_id ) {
if ( ! $form_id ) {
return false;
}
$form = ! is_array( $form_id ) ? RGFormsModel::get_form_meta( $form_id ) : $form_id;
$new_notification = $form['notifications'][ $notification_id ];
$name = rgar( $new_notification, 'name' );
$new_id = uniqid();
$count = 2;
$new_name = $name . ' - Copy 1';
while ( ! self::is_unique_name( $new_name, $form['notifications'] ) ) {
$new_name = $name . " - Copy $count";
$count ++;
}
$new_notification['name'] = $new_name;
$new_notification['id'] = $new_id;
unset( $new_notification['isDefault'] );
if ( $new_notification['toType'] == 'hidden' ) {
$new_notification['toType'] = 'email';
}
$form['notifications'][ $new_id ] = $new_notification;
// clear Form cache so next retrieval of form meta will return duplicated notification
RGFormsModel::flush_current_forms();
return RGFormsModel::save_form_notifications( $form['id'], $form['notifications'] );
}
public static function is_unique_name( $name, $notifications ) {
foreach ( $notifications as $notification ) {
if ( strtolower( rgar( $notification, 'name' ) ) == strtolower( $name ) ) {
return false;
}
}
return true;
}
}
class GFNotificationTable extends WP_List_Table {
public $form;
function __construct( $form ) {
$this->form = $form;
$this->_column_headers = array(
array(
'cb' => '',
'name' => esc_html__( 'Name', 'gravityforms' ),
'subject' => esc_html__( 'Subject', 'gravityforms' )
),
array(),
array(),
'name',
);
parent::__construct();
}
function prepare_items() {
$this->items = $this->form['notifications'];
}
function display() {
$singular = rgar( $this->_args, 'singular' );
?>
print_column_headers(); ?>
print_column_headers( false ); ?>
>
display_rows_or_placeholder(); ?>
';
echo $this->single_row_columns( $item );
echo '';
}
function get_columns() {
return $this->_column_headers[0];
}
function column_default( $item, $column ) {
echo rgar( $item, $column );
}
function column_cb( $item ) {
if ( rgar( $item, 'isDefault' ) ) {
return;
}
$is_active = isset( $item['isActive'] ) ? $item['isActive'] : true;
?>
$item['id'] ) );
$actions = apply_filters(
'gform_notification_actions', array(
'edit' => '' . esc_html__( 'Edit', 'gravityforms' ) . '',
'duplicate' => '' . esc_html__( 'Duplicate', 'gravityforms' ) . '',
'delete' => '' . esc_html__( 'Delete', 'gravityforms' ) . ''
)
);
if ( isset( $item['isDefault'] ) && $item['isDefault'] ) {
unset( $actions['delete'] );
}
?>
$html ) {
$divider = $key == $last_key ? '' : ' | ';
?>
0 ) );
printf( esc_html__( "This form doesn't have any notifications. Let's go %screate one%s.", 'gravityforms' ), "", '' );
}
}