/**
     * Output our edit screen
     *
     * @access public
     * @since 2.8
     * @return void
     */
    public function edit_screen($id = '')
    {
        ?>
		<tr>
			<th scope="row"><label for="settings-redirect_url"><?php 
        _e('Url', 'ninja-forms');
        ?>
</label></th>
			<td><input type="text" name="settings[redirect_url]" id="settings-redirect_url" value="<?php 
        echo esc_attr(nf_get_object_meta_value($id, 'redirect_url'));
        ?>
" class="regular-text"/></td>
		</tr>
		<?php 
    }
 /**
  * Detect Limited List Field
  */
 public function detect_limited_list_field()
 {
     global $ninja_forms_loading;
     if (!$ninja_forms_loading) {
         return;
     }
     $form_id = $ninja_forms_loading->get_form_ID();
     $notifications = nf_get_notifications_by_form_id($form_id);
     if (is_array($notifications)) {
         foreach ($notifications as $id => $n) {
             if (nf_get_object_meta_value($id, 'type') == $this->slug && nf_get_object_meta_value($id, 'active') == 1) {
                 $this->is_detect_limited_list_field = $id;
                 break;
             }
         }
     }
 }
    /**
     * Output our edit screen
     * 
     * @access public
     * @since 2.8
     * @return void
     */
    public function edit_screen($id = '')
    {
        $settings = array('textarea_name' => 'settings[success_msg]');
        $loc_opts = apply_filters('nf_success_message_locations', array(array('action' => 'ninja_forms_display_before_fields', 'name' => __('Before Form', 'ninja-forms')), array('action' => 'ninja_forms_display_after_fields', 'name' => __('After Form', 'ninja-forms'))));
        ?>
		<!-- <tr>
			<th scope="row"><label for="success_message_loc"><?php 
        _e('Location', 'ninja-forms');
        ?>
</label></th>
			<td>
				<select name="settings[success_message_loc]">
					<?php 
        foreach ($loc_opts as $opt) {
            ?>
						<option value="<?php 
            echo $opt['action'];
            ?>
" <?php 
            selected(nf_get_object_meta_value($id, 'success_message_loc'), $opt['action']);
            ?>
><?php 
            echo $opt['name'];
            ?>
</option>
						<?php 
        }
        ?>
				</select>
			</td>
		</tr> -->
		<tr>
			<th scope="row"><label for="success_msg"><?php 
        _e('Message', 'ninja-forms');
        ?>
</label></th>
			<td>
				<?php 
        wp_editor(nf_get_object_meta_value($id, 'success_msg'), 'success_msg', $settings);
        ?>
			</td>
		</tr>

		<?php 
    }
Example #4
0
function nf_modify_admin_mailto($setting, $setting_name, $id)
{
    global $ninja_forms_processing;
    // Bail if this isn't our admin notification
    if (!nf_get_object_meta_value($id, 'admin_email')) {
        return $setting;
    }
    // Bail if this isn't the "to" setting.
    if ($setting_name != 'to') {
        return $setting;
    }
    $admin_mailto = $ninja_forms_processing->get_form_setting('admin_mailto');
    $ninja_forms_processing->update_form_setting('admin_mailto', '');
    if (is_array($admin_mailto) && !empty($admin_mailto)) {
        $setting = array_merge($setting, $admin_mailto);
    }
    return $setting;
}
Example #5
0
 /**
  * Get a notification setting
  * 
  * @access public
  * @since 2.8
  * @return string $meta_value
  */
 public function get_setting($meta_key)
 {
     return nf_get_object_meta_value($this->id, $meta_key);
 }
 /**
  * Get our input value labels
  * 
  * @access public
  * @since 2.8
  * @return string $label
  */
 public function get_value($id, $meta_key, $form_id)
 {
     $meta_value = nf_get_object_meta_value($id, $meta_key);
     $meta_value = explode('`', $meta_value);
     $return = array();
     foreach ($meta_value as $val) {
         if (strpos($val, 'field_') !== false) {
             $val = str_replace('field_', '', $val);
             $label = nf_get_field_admin_label($val, $form_id);
             if (strlen($label) > 30) {
                 $label = substr($label, 0, 30);
             }
             $return[] = array('value' => 'field_' . $val, 'label' => $label . ' - ID: ' . $val);
         } else {
             $return[] = array('value' => $val, 'label' => $val);
         }
     }
     return $return;
 }
Example #7
0
function ninja_forms_conditionals_admin_js($page)
{
    global $ninja_forms_fields;
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'ninja-forms' && isset($_REQUEST['tab']) && $_REQUEST['tab'] != '') {
        $form_id = isset($_REQUEST['form_id']) ? $_REQUEST['form_id'] : '';
        if (defined('NINJA_FORMS_JS_DEBUG') && NINJA_FORMS_JS_DEBUG) {
            $suffix = '';
            $src = 'dev';
        } else {
            $suffix = '.min';
            $src = 'min';
        }
        wp_enqueue_script('nf-cl-admin', NINJA_FORMS_CON_URL . '/js/' . $src . '/ninja-forms-conditionals-admin' . $suffix . '.js?nf_ver=' . NINJA_FORMS_CON_VERSION, array('jquery', 'ninja-forms-admin', 'backbone', 'underscore'));
        if (empty($form_id)) {
            return false;
        }
        $fields = Ninja_Forms()->form($form_id)->fields;
        /**
         * We need to localize our script so that we have the appropriate JSON values to work with our backbone/underscore templates.
         * First, we'll get a list of conditionals currently on this object.
         * We need to check and see if we are on a notification page or editing a form.
         */
        $conditions_json = array();
        if (isset($_REQUEST['notification-action']) && 'edit' == $_REQUEST['notification-action']) {
            $n_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
            if (!empty($n_id)) {
                $conditionals = nf_cl_get_conditions($n_id);
                foreach ($conditionals as $cond_id) {
                    $action = nf_get_object_meta_value($cond_id, 'action');
                    $criteria = nf_cl_get_criteria($cond_id);
                    $criteria_json = array();
                    foreach ($criteria as $cr_id) {
                        $selected_param = nf_get_object_meta_value($cr_id, 'param');
                        $compare = nf_get_object_meta_value($cr_id, 'compare');
                        $value = nf_get_object_meta_value($cr_id, 'value');
                        $criteria_json[] = array('id' => $cr_id, 'param' => $selected_param, 'compare' => $compare, 'value' => $value);
                    }
                    $connector = nf_get_object_meta_value($cond_id, 'connector');
                    $conditions_json[$cond_id] = array('id' => $cond_id, 'action' => $action, 'connector' => $connector, 'criteria' => $criteria_json);
                }
            }
        }
        /**
         * Now we get a list of all of our fields and their conditional values.
         * $cl_fields will hold our fields and their labels.
         * $field_conditions will hold our field type conditional settings.
         */
        $cl_fields = array();
        $field_conditions = array();
        foreach ($fields as $field) {
            $field_type = $field['type'];
            $field_id = $field['id'];
            if (isset($ninja_forms_fields[$field_type]['process_field']) && $ninja_forms_fields[$field_type]['process_field']) {
                $label = nf_get_field_admin_label($field_id);
                $con_value = isset($ninja_forms_fields[$field_type]['conditional']['value']) ? $ninja_forms_fields[$field_type]['conditional']['value'] : array('type' => 'text');
                $compare = array('==' => __('Equal To', 'ninja-forms-conditionals'), '!=' => __('Not Equal To', 'ninja-forms-conditionals'), '<' => __('Less Than', 'ninja-forms-conditionals'), '>' => __('Greater Than', 'ninja-forms-conditionals'), 'contains' => __('Contains', 'ninja-forms-conditionals'), 'notcontains' => __('Does Not Contain', 'ninja-forms-conditionals'), 'on' => __('On', 'ninja-forms-conditionals'), 'before' => __('Before', 'ninja-forms-conditionals'), 'after' => __('After', 'ninja-forms-conditionals'));
                $type = $con_value['type'];
                if ('list' == $type) {
                    if (isset($field['data']['list']['options']) && is_array($field['data']['list']['options'])) {
                        $list_options = array();
                        foreach ($field['data']['list']['options'] as $opt) {
                            $opt_label = $opt['label'];
                            $opt_value = $opt['value'];
                            if (!isset($field['data']['list_show_value']) || $field['data']['list_show_value'] != 1) {
                                $opt_value = $opt['label'];
                            }
                            $list_options[] = array('value' => $opt_value, 'label' => $opt_label);
                        }
                        $con_value = array('type' => 'select', 'options' => $list_options);
                    }
                    unset($compare['contains']);
                    unset($compare['notcontains']);
                    unset($compare['on']);
                    unset($compare['before']);
                    unset($compare['after']);
                } else {
                    if ('_checkbox' == $field_type) {
                        $options[] = array('value' => 'checked', 'label' => __('Checked', 'ninja-forms'));
                        $options[] = array('value' => 'unchecked', 'label' => __('Unchecked', 'ninja-forms'));
                        $con_value = array('type' => 'select', 'options' => $options);
                        unset($compare['<']);
                        unset($compare['>']);
                        unset($compare['contains']);
                        unset($compare['notcontains']);
                        unset($compare['on']);
                        unset($compare['before']);
                        unset($compare['after']);
                    } else {
                        if ('_text' == $field_type) {
                            if (isset($field['data']['datepicker']) && $field['data']['datepicker'] == 1) {
                                $field_type = 'date';
                                unset($compare['==']);
                                unset($compare['!=']);
                                unset($compare['<']);
                                unset($compare['>']);
                                unset($compare['contains']);
                                unset($compare['notcontains']);
                            } else {
                                unset($compare['on']);
                                unset($compare['before']);
                                unset($compare['after']);
                            }
                        }
                    }
                }
                $compare = apply_filters('nf_cl_compare_array', $compare, $field_id);
                $cl_fields[] = array('id' => $field_id, 'label' => $label . ' ID - ' . $field_id, 'conditions' => $con_value, 'compare' => $compare, 'type' => $field_type);
            }
        }
        $cl_fields = apply_filters('nf_cl_criteria_fields', $cl_fields);
        usort($cl_fields, 'nf_cl_sort_by_label');
        $triggers = array();
        if (isset(Ninja_Forms()->cl_triggers)) {
            foreach (Ninja_Forms()->cl_triggers as $slug => $trigger) {
                $triggers[] = array('id' => $slug, 'label' => $trigger->label, 'type' => $trigger->type, 'compare' => $trigger->comparison_operators, 'conditions' => $trigger->conditions);
            }
        }
        $cr_param_groups = apply_filters('nf_cl_criteria_param_groups', array(__('Triggers', 'ninja-forms-conditionals') => $triggers, __('Fields', 'ninja-forms-conditionals') => $cl_fields));
        wp_localize_script('nf-cl-admin', 'nf_cl', array('cr_param_groups' => $cr_param_groups, 'conditions' => $conditions_json));
    }
}
    /**
     * Output our notifications admin.
     * 
     * @access public
     *
     * @since 2.8
     * @return void
     */
    public function output_admin()
    {
        $action = isset($_REQUEST['notification-action']) ? $_REQUEST['notification-action'] : '';
        ?>
		<div class="wrap">
			<?php 
        if ('' == $action) {
            ?>
			<h2><?php 
            _e('Email & Actions', 'ninja-forms');
            ?>
 <a href="<?php 
            echo esc_url(add_query_arg(array('notification-action' => 'new')));
            ?>
" class="add-new-h2"><?php 
            _e('Add New', 'ninja-forms');
            ?>
</a></h2>

	        <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
	      	 <form id="forms-filter" method="get">
	            <!-- For plugins, we also need to ensure that the form posts back to our current page -->
	            <input type="hidden" name="page" value="<?php 
            echo esc_attr($_REQUEST['page']);
            ?>
" />
	            <input type="hidden" name="tab" value="<?php 
            echo esc_attr($_REQUEST['tab']);
            ?>
" />
	            <input type="hidden" name="form_id" value="<?php 
            echo esc_attr($_REQUEST['form_id']);
            ?>
" />
				<?php 
            //Create an instance of our package class...
            $nf_all_forms = new NF_Notifications_List_Table();
            //Fetch, prepare, sort, and filter our data...
            $nf_all_forms->prepare_items();
            // Now we can render the completed list table
            $nf_all_forms->display();
            ?>
        	</form>
            <?php 
        } else {
            $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
            if ($id == '') {
                $id = 'new';
                $this_type = 'email';
                $title = __('New Action', 'ninja-forms');
            } else {
                $this_type = Ninja_Forms()->notification($id)->type;
                $title = __('Edit Action', 'ninja-forms') . ' - ID ' . $id;
            }
            ?>
			<h2><?php 
            echo $title;
            ?>
 <a href="<?php 
            echo esc_url(remove_query_arg(array('notification-action', 'id', 'update_message')));
            ?>
" class="button-secondary"><?php 
            _e('Back To List', 'ninja-forms');
            ?>
</a></h2>

			<input type="hidden" id="notification_id" name="notification_id" value="<?php 
            echo $id;
            ?>
" />
			<table class="form-table">
				<tbody id="notification-main">
					<tr>
						<th scope="row"><label for="setting-name"><?php 
            _e('Action Name', 'ninja-forms');
            ?>
</label></th>
						<td><input name="settings[name]" type="text" id="settings-name" value="<?php 
            echo nf_get_object_meta_value($id, 'name');
            ?>
" class="regular-text"></td>
					</tr>
					<tr>
						<th scope="row"><label for="type"><?php 
            _e('Type', 'ninja-forms');
            ?>
</label></th>
						<td>
							<select name="settings[type]" id="settings-type">
								<?php 
            foreach ($this->get_types() as $slug => $nicename) {
                ?>
									<option value="<?php 
                echo $slug;
                ?>
" <?php 
                selected($this_type, $slug);
                ?>
><?php 
                echo $nicename;
                ?>
</option>
									<?php 
            }
            ?>
						
							</select>
						</td>
					</tr>
				</tbody>
				<?php 
            do_action('nf_edit_notification_settings', $id);
            foreach ($this->get_types() as $slug => $nicename) {
                if ($this_type == $slug) {
                    $display = '';
                } else {
                    $display = 'display:none;';
                }
                ?>
					<tbody id="notification-<?php 
                echo $slug;
                ?>
" class="notification-type" style="<?php 
                echo $display;
                ?>
">
						<?php 
                // Call our type edit screen.
                Ninja_Forms()->notification_types[$slug]->edit_screen($id);
                ?>
					</tbody>
					<?php 
            }
            ?>
			
			</table>
			<?php 
        }
        ?>
		
    	</div>
    	<?php 
    }
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  *
  * @global WPDB $wpdb
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 public function prepare_items()
 {
     global $wpdb;
     //This is used only if making any database queries
     /**
      * First, lets decide how many records per page to show
      */
     $per_page = 99999;
     /**
      * REQUIRED. Now we need to define our column headers. This includes a complete
      * array of columns to be displayed (slugs & titles), a list of columns
      * to keep hidden, and a list of columns that are sortable. Each of these
      * can be defined in another method (as we've done here) before being
      * used to build the value for our _column_headers property.
      */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     /**
      * REQUIRED. Finally, we build an array to be used by the class for column
      * headers. The $this->_column_headers property takes an array which contains
      * 3 other arrays. One for all columns, one for hidden columns, and one
      * for sortable columns.
      */
     $this->_column_headers = array($columns, $hidden, $sortable);
     /**
      * Optional. You can handle your bulk actions however you see fit. In this
      * case, we'll handle them within our package just to keep things clean.
      */
     //$this->process_bulk_action();
     /**
      * Instead of querying a database, we're going to fetch the example data
      * property we created for use in this plugin. This makes this example
      * package slightly different than one you might build on your own. In
      * this example, we'll be using array manipulation to sort and paginate
      * our data. In a real-world implementation, you will probably want to
      * use sort and pagination data to build a custom query instead, as you'll
      * be able to use your precisely-queried data immediately.
      */
     $notifications = nf_get_notifications_by_form_id($this->form_id);
     $data = array();
     if (is_array($notifications)) {
         foreach ($notifications as $id => $n) {
             if (isset($_REQUEST['type']) && !empty($_REQUEST['type'])) {
                 if (nf_get_object_meta_value($id, 'type') == esc_html($_REQUEST['type'])) {
                     $n['id'] = $id;
                     $data[] = $n;
                 }
             } else {
                 $n['id'] = $id;
                 $data[] = $n;
             }
         }
     }
     /**
      * This checks for sorting input and sorts the data in our array accordingly.
      *
      * In a real-world situation involving a database, you would probably want
      * to handle sorting by passing the 'orderby' and 'order' values directly
      * to a custom query. The returned data will be pre-sorted, and this array
      * sorting technique would be unnecessary.
      */
     function usort_reorder($a, $b)
     {
         $orderby = !empty($_REQUEST['orderby']) ? esc_html($_REQUEST['orderby']) : 'name';
         //If no sort, default to title
         $order = !empty($_REQUEST['order']) ? esc_html($_REQUEST['order']) : 'asc';
         //If no order, default to asc
         $result = strcmp($a[$orderby], $b[$orderby]);
         //Determine sort order
         return $order === 'asc' ? $result : -$result;
         //Send final sort direction to usort
     }
     usort($data, 'usort_reorder');
     /***********************************************************************
      * ---------------------------------------------------------------------
      * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
      *
      * In a real-world situation, this is where you would place your query.
      *
      * For information on making queries in WordPress, see this Codex entry:
      * http://codex.wordpress.org/Class_Reference/wpdb
      *
      * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      * ---------------------------------------------------------------------
      **********************************************************************/
     /**
      * REQUIRED for pagination. Let's figure out what page the user is currently
      * looking at. We'll need this later, so you should always include it in
      * your own package classes.
      */
     $current_page = $this->get_pagenum();
     /**
      * REQUIRED for pagination. Let's check how many items are in our data array.
      * In real-world use, this would be the total number of items in your database,
      * without filtering. We'll need this later, so you should always include it
      * in your own package classes.
      */
     $total_items = count($data);
     /**
      * The WP_List_Table class does not handle pagination for us, so we need
      * to ensure that the data is trimmed to only the current page. We can use
      * array_slice() to
      */
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     /**
      * REQUIRED. Now we can add our *sorted* data to the items property, where
      * it can be used by the rest of the class.
      */
     $this->items = $data;
     /**
      * REQUIRED. We also have to register our pagination options & calculations.
      */
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
Example #10
0
 /**
  * Get one of our form settings.
  *
  * @access public
  * @since 2.7
  * @return string $setting
  */
 public function get_setting($setting, $bypass_cache = false)
 {
     if ($bypass_cache) {
         return nf_get_object_meta_value($this->form_id, 'last_sub');
     }
     if (isset($this->settings[$setting])) {
         return $this->settings[$setting];
     } else {
         return false;
     }
 }
Example #11
0
/**
 * Filter our form export.
 */
function nf_cl_form_export($form_row)
{
    // Make sure that this form has notifications on it.
    if (isset($form_row['notifications'])) {
        // Loop through our notifications and check conditions.
        foreach ($form_row['notifications'] as $id => $notification) {
            $conditions = nf_cl_get_conditions($id);
            // Make sure that we actually notifications to connect.
            if (empty($conditions)) {
                continue;
            }
            $c_array = array();
            // Stores all of our conditions.
            // Loop over each condition.
            foreach ($conditions as $c_id) {
                // Grab the criteria ids for this condition.
                $criteria = nf_cl_get_criteria($c_id);
                $cr_array = array();
                // Stores all of our criteria.
                // Loop through our criteria and populate our criteria array
                foreach ($criteria as $cr_id) {
                    // Grab our three criteria settings.
                    $cr_array[] = array('param' => nf_get_object_meta_value($cr_id, 'param'), 'compare' => nf_get_object_meta_value($cr_id, 'compare'), 'value' => nf_get_object_meta_value($cr_id, 'value'));
                }
                // Add the criteria to the condition array.
                $c_array[] = array('action' => nf_get_object_meta_value($c_id, 'action'), 'connector' => nf_get_object_meta_value($c_id, 'connector'), 'criteria' => $cr_array);
            }
            $form_row['notifications'][$id]['conditions'] = $c_array;
        }
    }
    return $form_row;
}