function nf_fu_add_attachment_type($types)
{
    // Bail if we don't have a form id set.
    if (!isset($_REQUEST['form_id'])) {
        return $types;
    }
    foreach (Ninja_Forms()->form($_REQUEST['form_id'])->fields as $field_id => $field) {
        if ('_upload' == $field['type']) {
            $label = nf_get_field_admin_label($field_id);
            $types['file_upload_' . $field_id] = $label . ' - ID: ' . $field_id;
        }
    }
    return $types;
}
 public function step($step)
 {
     global $ninja_forms_fields;
     // Get our form ID
     $form_id = $this->args['forms'][$step];
     // Bail if we've already converted the notifications for this form.
     if (in_array($form_id, $this->completed_forms)) {
         return false;
     }
     // Grab our form from the database
     $form_settings = Ninja_Forms()->form($form_id)->settings;
     $fields = Ninja_Forms()->form($form_id)->fields;
     $process_fields = array();
     foreach ($fields as $field_id => $field) {
         $label = strip_tags(nf_get_field_admin_label($field_id));
         if (strlen($label) > 30) {
             $tmp_label = substr($label, 0, 30);
         } else {
             $tmp_label = $label;
         }
         $tmp_array = array('value' => $field_id, 'label' => $tmp_label . ' - ID: ' . $field_id);
         $admin_label = $label;
         $label = isset($field['data']['label']) ? $field['data']['label'] : '';
         // Check to see if this field is supposed to be "processed"
         $type = $field['type'];
         if (isset($ninja_forms_fields[$type]['process_field']) && $ninja_forms_fields[$type]['process_field']) {
             $process_fields[$field_id] = array('field_id' => $field_id, 'label' => $label, 'admin_label' => $admin_label);
         }
     }
     // Create a notification for our admin email
     if (isset($form_settings['admin_email_msg']) && !empty($form_settings['admin_email_msg']) || isset($form_settings['admin_email_fields']) && 1 == $form_settings['admin_email_fields']) {
         // Create a notification
         $n_id = nf_insert_notification($form_id);
         // Update our notification type
         nf_update_object_meta($n_id, 'type', 'email');
         // Activate our notification
         Ninja_Forms()->notification($n_id)->activate();
         // Update our notification name
         Ninja_Forms()->notification($n_id)->update_setting('name', __('Admin Email', 'ninja-forms'));
         $admin_mailto = isset($form_settings['admin_mailto']) ? $form_settings['admin_mailto'] : array();
         // Implode our admin email addresses
         $to = implode('`', $admin_mailto);
         // Update our to setting
         Ninja_Forms()->notification($n_id)->update_setting('to', $to);
         // Update our Format Setting
         Ninja_Forms()->notification($n_id)->update_setting('email_format', $form_settings['email_type']);
         // Update our attach csv option
         Ninja_Forms()->notification($n_id)->update_setting('attach_csv', $form_settings['admin_attach_csv']);
         // Update our subject
         $subject = $this->replace_shortcodes($form_settings['admin_subject']);
         Ninja_Forms()->notification($n_id)->update_setting('email_subject', $subject);
         // Update our From Name
         if (isset($form_settings['email_from_name'])) {
             Ninja_Forms()->notification($n_id)->update_setting('from_name', $form_settings['email_from_name']);
         }
         foreach ($fields as $field) {
             if (isset($field['data']['from_name']) && $field['data']['from_name'] == 1) {
                 // Update our From Name
                 Ninja_Forms()->notification($n_id)->update_setting('from_name', 'field_' . $field['id']);
                 break;
             }
         }
         // Update our From Address
         Ninja_Forms()->notification($n_id)->update_setting('from_address', $form_settings['email_from']);
         // Get our reply-to address
         foreach ($fields as $field) {
             if (isset($field['data']['replyto_email']) && $field['data']['replyto_email'] == 1) {
                 Ninja_Forms()->notification($n_id)->update_setting('reply_to', 'field_' . $field['id']);
                 break;
             }
         }
         $email_message = $form_settings['admin_email_msg'];
         // Check to see if the "include list of fields" checkbox was checked.
         if (isset($form_settings['admin_email_fields']) && $form_settings['admin_email_fields'] == 1) {
             $email_message .= '<br />[ninja_forms_all_fields]';
         }
         // Update our email message
         Ninja_Forms()->notification($n_id)->update_setting('email_message', $email_message);
         Ninja_Forms()->notification($n_id)->update_setting('admin_email', true);
     }
     // Create a notification for our user email
     if (!empty($fields)) {
         $addresses = array();
         foreach ($fields as $field_id => $field) {
             if (isset($field['data']['send_email']) && $field['data']['send_email'] == 1) {
                 // Add this field to our $addresses variable.
                 $addresses[] = 'field_' . $field_id;
                 unset($field['data']['send_email']);
                 unset($field['data']['replyto_email']);
                 unset($field['data']['from_name']);
                 $args = array('update_array' => array('data' => serialize($field['data'])), 'where' => array('id' => $field_id));
                 ninja_forms_update_field($args);
             }
         }
         if (!empty($addresses)) {
             // We have a user email, so create a notification
             $n_id = nf_insert_notification($form_id);
             // Update our notification type
             nf_update_object_meta($n_id, 'type', 'email');
             // Activate our notification
             Ninja_Forms()->notification($n_id)->activate();
             // Update our notification name
             Ninja_Forms()->notification($n_id)->update_setting('name', __('User Email', 'ninja-forms'));
             // Implode our admin email addresses
             $n_var = count($addresses) > 1 ? 'bcc' : 'to';
             $addresses = implode('`', $addresses);
             Ninja_Forms()->notification($n_id)->update_setting($n_var, $addresses);
             // Update our Format Setting
             Ninja_Forms()->notification($n_id)->update_setting('email_format', $form_settings['email_type']);
             // Update our subject
             $subject = $this->replace_shortcodes($form_settings['user_subject']);
             Ninja_Forms()->notification($n_id)->update_setting('email_subject', $subject);
             // Update our From Name
             if (isset($form_settings['email_from_name'])) {
                 Ninja_Forms()->notification($n_id)->update_setting('from_name', $form_settings['email_from_name']);
             }
             // Update our From Address
             Ninja_Forms()->notification($n_id)->update_setting('from_address', $form_settings['email_from']);
             $email_message = $form_settings['user_email_msg'];
             // Check to see if the "include list of fields" checkbox was checked. If so, add our table to the end of the email message.
             if (isset($form_settings['user_email_fields']) && $form_settings['user_email_fields'] == 1) {
                 $email_message .= '<br />[ninja_forms_all_fields]';
             }
             // Update our email message
             Ninja_Forms()->notification($n_id)->update_setting('email_message', $email_message);
             Ninja_Forms()->notification($n_id)->update_setting('user_email', true);
         }
     }
     if (isset($form_settings['success_msg']) && !empty($form_settings['success_msg'])) {
         // Create a notification for our success message
         $n_id = nf_insert_notification($form_id);
         nf_update_object_meta($n_id, 'name', __('Success Message', 'ninja-forms'));
         nf_update_object_meta($n_id, 'type', 'success_message');
         nf_update_object_meta($n_id, 'active', 1);
         nf_update_object_meta($n_id, 'success_msg', $form_settings['success_msg']);
     }
     if (isset($form_settings['landing_page']) && !empty($form_settings['landing_page'])) {
         // Create a notification for our redirect
         $n_id = nf_insert_notification($form_id);
         nf_update_object_meta($n_id, 'name', __('Redirect', 'ninja-forms'));
         nf_update_object_meta($n_id, 'type', 'redirect');
         nf_update_object_meta($n_id, 'active', 1);
         nf_update_object_meta($n_id, 'redirect_url', $form_settings['landing_page']);
     }
     $completed_forms = get_option('nf_convert_notifications_forms');
     if (!is_array($completed_forms) || empty($completed_forms)) {
         $completed_forms = array($form_id);
     } else {
         $completed_forms[] = $form_id;
     }
     update_option('nf_convert_notifications_forms', $completed_forms);
     // Unset our admin email settings and save the form.
     if (isset($form_settings['admin_mailto'])) {
         unset($form_settings['admin_mailto']);
         unset($form_settings['admin_attach_csv']);
         unset($form_settings['admin_subject']);
         unset($form_settings['admin_email_msg']);
         unset($form_settings['admin_email_fields']);
         unset($form_settings['success_msg']);
         unset($form_settings['user_email_msg']);
         unset($form_settings['user_subject']);
         unset($form_settings['landing_page']);
         $args = array('update_array' => array('data' => serialize($form_settings)), 'where' => array('id' => $form_id));
         ninja_forms_update_form($args);
     }
 }
 /**
  * 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;
 }
Exemple #4
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));
    }
}
 /**
  * Enqueue JS
  * 
  * @access public
  * @since 2.8
  * @return void
  */
 public function add_js()
 {
     global $ninja_forms_fields;
     $form_id = isset($_REQUEST['form_id']) ? $_REQUEST['form_id'] : '';
     if (empty($form_id)) {
         return false;
     }
     if (defined('NINJA_FORMS_JS_DEBUG') && NINJA_FORMS_JS_DEBUG) {
         $suffix = '';
         $src = 'dev';
     } else {
         $suffix = '.min';
         $src = 'min';
     }
     wp_enqueue_script('nf-notifications', NF_PLUGIN_URL . 'assets/js/' . $src . '/notifications' . $suffix . '.js', array('jquery', 'jquery-ui-autocomplete'));
     wp_enqueue_script('nf-tokenize', NF_PLUGIN_URL . 'assets/js/' . $src . '/bootstrap-tokenfield' . $suffix . '.js', array('jquery', 'jquery-ui-autocomplete'));
     wp_enqueue_script('nf-combobox', NF_PLUGIN_URL . 'assets/js/' . $src . '/combobox' . $suffix . '.js', array('jquery', 'jquery-ui-core', 'jquery-ui-button', 'jquery-ui-autocomplete'));
     $all_fields = Ninja_Forms()->form($form_id)->fields;
     $process_fields = array();
     $search_fields = array();
     $search_fields['email'] = array();
     $search_fields['name'] = array();
     $fields = array();
     // Generate our search fields JS var.
     foreach ($all_fields as $field_id => $field) {
         $label = esc_attr(nf_get_field_admin_label($field_id));
         $fields[$field_id] = array('field_id' => $field_id, 'label' => $label);
         if (strlen($label) > 30) {
             $tmp_label = substr($label, 0, 30);
         } else {
             $tmp_label = $label;
         }
         $tmp_array = array('value' => 'field_' . $field_id, 'label' => $tmp_label . ' - ID: ' . $field_id);
         $admin_label = $label;
         $label = isset($field['data']['label']) ? $field['data']['label'] : '';
         // Check to see if this field is supposed to be "processed"
         $type = $field['type'];
         if (isset($ninja_forms_fields[$type]['process_field']) && $ninja_forms_fields[$type]['process_field']) {
             $process_fields[$field_id] = array('field_id' => $field_id, 'label' => $label, 'admin_label' => $admin_label);
             $search_fields['all'][] = $tmp_array;
         }
         if ($field['type'] == '_text' && isset($field['data']['email']) && $field['data']['email'] == 1) {
             $search_fields['email'][] = $tmp_array;
         } else {
             if ($field['type'] == '_text' && isset($field['data']['first_name']) && $field['data']['first_name'] == 1) {
                 $search_fields['name'][] = $tmp_array;
             } else {
                 if ($field['type'] == '_text' && isset($field['data']['last_name']) && $field['data']['last_name'] == 1) {
                     $search_fields['name'][] = $tmp_array;
                 }
             }
         }
     }
     // Add our "process_fields" to our form global
     Ninja_Forms()->form($form_id)->process_fields = $process_fields;
     $js_vars = apply_filters('nf_notification_admin_js_vars', array('activate' => __('Activate', 'ninja-forms'), 'deactivate' => __('Deactivate', 'ninja-forms'), 'search_fields' => $search_fields, 'tokens' => array(), 'all_fields' => $fields, 'process_fields' => $process_fields, 'filter_type' => esc_url_raw(remove_query_arg(array('type')))));
     wp_localize_script('nf-notifications', 'nf_notifications', $js_vars);
 }