function ninja_forms_get_form_by_id($form_id)
{
    global $wpdb;
    $form_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NINJA_FORMS_TABLE_NAME . " WHERE id = %d", $form_id), ARRAY_A);
    $form_row['data'] = unserialize($form_row['data']);
    $form_row['data'] = ninja_forms_stripslashes_deep($form_row['data']);
    return $form_row;
}
function ninja_forms_output_tab_metabox($form_id = '', $slug, $metabox)
{
    $plugin_settings = nf_get_settings();
    if ($form_id != '') {
        $form_row = ninja_forms_get_form_by_id($form_id);
        $current_settings = $form_row['data'];
    } else {
        $form_id = '';
        $current_settings = nf_get_settings();
    }
    $page = $metabox['page'];
    $tab = $metabox['tab'];
    $title = $metabox['title'];
    if (isset($metabox['settings'])) {
        $settings = $metabox['settings'];
    } else {
        $settings = '';
    }
    if (isset($metabox['display_function'])) {
        $display_function = $metabox['display_function'];
    } else {
        $display_function = '';
    }
    if ($metabox['state'] == 'closed') {
        $state = 'display:none;';
    } else {
        $state = '';
    }
    if (isset($plugin_settings['metabox_state'][$page][$tab][$slug])) {
        $state = $plugin_settings['metabox_state'][$page][$tab][$slug];
    }
    if (isset($metabox['display_container'])) {
        $display_container = $metabox['display_container'];
    } else {
        $display_container = true;
    }
    if ($display_container) {
        ?>
		<div id="ninja_forms_metabox_<?php 
        echo $slug;
        ?>
" class="postbox ">
			<span class="item-controls">
				<a class="item-edit metabox-item-edit" id="edit_id" title="<?php 
        _e('Edit Menu Item', 'ninja-forms');
        ?>
" href="#"><?php 
        _e('Edit Menu Item', 'ninja-forms');
        ?>
</a>
			</span>
			<h3 class="hndle"><span><?php 
        _e($title, 'ninja-forms');
        ?>
</span></h3>
			<div class="inside" style="<?php 
        echo $state;
        ?>
">
			<table class="form-table">
				<tbody>
		<?php 
    }
    if (is_array($settings) and !empty($settings)) {
        foreach ($settings as $s) {
            $value = '';
            if (isset($s['name'])) {
                $name = $s['name'];
            } else {
                $name = '';
            }
            $name_array = '';
            if (strpos($name, '[') !== false) {
                $name_array = str_replace(']', '', $name);
                $name_array = explode('[', $name_array);
            }
            if (isset($s['type'])) {
                $type = $s['type'];
            } else {
                $type = '';
            }
            if (isset($s['desc'])) {
                $desc = $s['desc'];
            } else {
                $desc = '';
            }
            if (isset($s['help_text'])) {
                $help_text = $s['help_text'];
            } else {
                $help_text = '';
            }
            if (isset($s['label'])) {
                $label = $s['label'];
            } else {
                $label = '';
            }
            if (isset($s['class'])) {
                $class = $s['class'];
            } else {
                $class = '';
            }
            if (isset($s['tr_class'])) {
                $tr_class = $s['tr_class'];
            } else {
                $tr_class = '';
            }
            if (isset($s['max_file_size'])) {
                $max_file_size = $s['max_file_size'];
            } else {
                $max_file_size = '';
            }
            if (isset($s['select_all'])) {
                $select_all = $s['select_all'];
            } else {
                $select_all = false;
            }
            if (isset($s['default_value'])) {
                $default_value = $s['default_value'];
            } else {
                $default_value = '';
            }
            if (isset($s['style'])) {
                $style = $s['style'];
            } else {
                $style = '';
            }
            if (isset($s['size'])) {
                $size = $s['size'];
            } else {
                $size = '';
            }
            if (isset($s['min'])) {
                $min = $s['min'];
            } else {
                $min = 0;
            }
            if (isset($s['max'])) {
                $max = $s['max'];
            } else {
                $max = '';
            }
            if (is_array($name_array)) {
                $tmp = '';
                foreach ($name_array as $n) {
                    if ($tmp == '') {
                        if (isset($current_settings[$n])) {
                            $tmp = $current_settings[$n];
                        }
                    } else {
                        if (isset($tmp[$n])) {
                            $tmp = $tmp[$n];
                        }
                    }
                }
                $value = !is_array($tmp) && !is_object($tmp) ? $tmp : '';
            } else {
                if (isset($current_settings[$name])) {
                    if (is_array($current_settings[$name])) {
                        $value = ninja_forms_stripslashes_deep($current_settings[$name]);
                    } else {
                        $value = stripslashes($current_settings[$name]);
                    }
                } else {
                    $value = '';
                }
            }
            if ($value == '') {
                $value = $default_value;
            }
            ?>

			<tr id="row_<?php 
            echo $name;
            ?>
" <?php 
            if ($tr_class != '') {
                ?>
class="<?php 
                echo $tr_class;
                ?>
"<?php 
            }
            ?>
 <?php 
            if ($style != '') {
                ?>
 style="<?php 
                echo $style;
                ?>
"<?php 
            }
            ?>
>
				<?php 
            if ($s['type'] == 'desc' and !$label) {
                ?>
					 <td colspan="2">
				<?php 
            } else {
                ?>
					<th scope="row">
						<label for="<?php 
                echo $name;
                ?>
"><?php 
                echo $label;
                ?>
</label>
					</th>
					<td>
				<?php 
            }
            ?>
			<?php 
            switch ($s['type']) {
                case 'text':
                    $value = ninja_forms_esc_html_deep($value);
                    ?>

					<input type="text" class="code widefat <?php 
                    echo $class;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
" />
					<?php 
                    if ($help_text != '') {
                        ?>
					<a href="#" class="tooltip">
					    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
					    <span>
					        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
/images/callout.gif" />
					        <?php 
                        echo $help_text;
                        ?>
					    </span>
					</a>
					<?php 
                    }
                    break;
                case 'number':
                    $value = ninja_forms_esc_html_deep($value);
                    ?>

					<input type="number" class="code <?php 
                    echo $class;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
" min="<?php 
                    echo $min;
                    ?>
" max="<?php 
                    echo $max;
                    ?>
" />
					<?php 
                    if ($help_text != '') {
                        ?>
					<a href="#" class="tooltip">
					    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
					    <span>
					        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
/images/callout.gif" />
					        <?php 
                        echo $help_text;
                        ?>
					    </span>
					</a>
					<?php 
                    }
                    break;
                case 'select':
                    ?>
					<select name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
">
						<?php 
                    if (is_array($s['options']) and !empty($s['options'])) {
                        foreach ($s['options'] as $option) {
                            ?>
								<option value="<?php 
                            echo $option['value'];
                            ?>
" <?php 
                            selected($value, $option['value']);
                            ?>
><?php 
                            echo $option['name'];
                            ?>
</option>
								<?php 
                        }
                    }
                    ?>
					</select>
					<?php 
                    if ($help_text != '') {
                        ?>
						<a href="#" class="tooltip">
						    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
						    <span>
						        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/callout.gif" />
						        <?php 
                        echo $help_text;
                        ?>
						    </span>
						</a>
					<?php 
                    }
                    break;
                case 'multi_select':
                    if ($value == '') {
                        $value = array();
                    }
                    ?>

					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" value="">
					<select name="<?php 
                    echo $name;
                    ?>
[]" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
" multiple="multiple" size="<?php 
                    echo $size;
                    ?>
">
						<?php 
                    if (is_array($s['options']) and !empty($s['options'])) {
                        foreach ($s['options'] as $option) {
                            ?>
								<option value="<?php 
                            echo $option['value'];
                            ?>
" <?php 
                            selected(in_array($option['value'], $value));
                            ?>
><?php 
                            echo $option['name'];
                            ?>
</option>
								<?php 
                        }
                    }
                    ?>
					</select>
					<?php 
                    if ($help_text != '') {
                        ?>
						<a href="#" class="tooltip">
						    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
						    <span>
						        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
/images/callout.gif" />
						        <?php 
                        echo $help_text;
                        ?>
						    </span>
						</a>
					<?php 
                    }
                    break;
                case 'checkbox':
                    ?>
					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" value="0">
					<input type="checkbox" name="<?php 
                    echo $name;
                    ?>
" value="1" <?php 
                    checked($value, 1);
                    ?>
 id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
">
					<?php 
                    if ($help_text != '') {
                        ?>
						<a href="#" class="tooltip">
						    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
						    <span>
						        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/callout.gif" />
						        <?php 
                        echo $help_text;
                        ?>
						    </span>
						</a>
					<?php 
                    }
                    break;
                case 'checkbox_list':
                    if ($value == '') {
                        $value = array();
                    }
                    ?>
					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" value="">

						<?php 
                    if ($select_all) {
                        ?>

								<label>
									<input type="checkbox" name="" value="" id="<?php 
                        echo $name;
                        ?>
_select_all" class="ninja-forms-select-all" title="ninja-forms-<?php 
                        echo $name;
                        ?>
">
								- <?php 
                        _e('Select All', 'ninja-forms');
                        ?>
								</label>

						<?php 
                    } else {
                        if (is_array($s['options']) and isset($s['options'][0])) {
                            $option_name = $s['options'][0]['name'];
                            $option_value = $s['options'][0]['value'];
                            ?>

									<label>
										<input type="checkbox" class="ninja-forms-<?php 
                            echo $name;
                            ?>
 <?php 
                            echo $class;
                            ?>
" name="<?php 
                            echo $name;
                            ?>
[]" value="<?php 
                            echo $option_value;
                            ?>
" <?php 
                            checked(in_array($option_value, $value));
                            ?>
 id="<?php 
                            echo $option_name;
                            ?>
">
										<?php 
                            echo $option_name;
                            ?>
									</label>

								<?php 
                        }
                    }
                    ?>

					<?php 
                    if (is_array($s['options']) and !empty($s['options'])) {
                        $x = 0;
                        foreach ($s['options'] as $option) {
                            if (!$select_all and $x > 0 or $select_all) {
                                $option_name = $option['name'];
                                $option_value = $option['value'];
                                ?>
										<label>
											<input type="checkbox" class="ninja-forms-<?php 
                                echo $name;
                                ?>
 <?php 
                                echo $class;
                                ?>
" name="<?php 
                                echo $name;
                                ?>
[]" value="<?php 
                                echo $option_value;
                                ?>
" <?php 
                                checked(in_array($option_value, $value));
                                ?>
 id="<?php 
                                echo $option_name;
                                ?>
">
											<?php 
                                echo $option_name;
                                ?>
										</label>
								<?php 
                            }
                            $x++;
                        }
                    }
                    break;
                case 'radio':
                    if (is_array($s['options']) and !empty($s['options'])) {
                        $x = 0;
                        ?>
						<?php 
                        foreach ($s['options'] as $option) {
                            ?>
							<input type="radio" name="<?php 
                            echo $name;
                            ?>
" value="<?php 
                            echo $option['value'];
                            ?>
" id="<?php 
                            echo $name . "_" . $x;
                            ?>
" <?php 
                            checked($value, $option['value']);
                            ?>
 class="<?php 
                            echo $class;
                            ?>
"> <label for="<?php 
                            echo $name . "_" . $x;
                            ?>
"><?php 
                            echo $option['name'];
                            ?>
</label>
								<?php 
                            if ($help_text != '') {
                                ?>
									<a href="#" class="tooltip">
									    <img id="" class='ninja-forms-help-text' src="<?php 
                                echo NINJA_FORMS_URL;
                                ?>
images/question-ico.gif" title="">
									    <span>
									        <img class="callout" src="<?php 
                                echo NINJA_FORMS_URL;
                                ?>
images/callout.gif" />
									        <?php 
                                echo $help_text;
                                ?>
									    </span>
									</a>
								<?php 
                            }
                            ?>
							<br />

						<?php 
                            $x++;
                        }
                    }
                    break;
                case 'textarea':
                    $value = ninja_forms_esc_html_deep($value);
                    ?>
					<textarea name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
"><?php 
                    echo $value;
                    ?>
</textarea>
					<?php 
                    break;
                case 'rte':
                    $args = apply_filters('ninja_forms_admin_metabox_rte', array());
                    wp_editor($value, $name, $args);
                    break;
                case 'file':
                    ?>
					<input type="hidden" name="MAX_FILE_SIZE" value="<?php 
                    echo $max_file_size;
                    ?>
" />
					<input type="file" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
">
					<?php 
                    break;
                case 'desc':
                    echo $desc;
                    break;
                case 'hidden':
                    ?>
					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
">
					<?php 
                    break;
                case 'submit':
                    ?>
					<input type="submit" name="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
" value="<?php 
                    echo $label;
                    ?>
">
					<?php 
                    break;
                case 'button':
                    // set a default value for $class to maintain the standard WordPress UI
                    if (isset($class) && empty($class)) {
                        $class = "button-secondary";
                    }
                    ?>
					<input type="button" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
" value="<?php 
                    echo $label;
                    ?>
">
					<?php 
                    break;
                default:
                    if (isset($s['display_function'])) {
                        $s_display_function = $s['display_function'];
                        if ($s_display_function != '') {
                            $arguments['form_id'] = $form_id;
                            $arguments['data'] = $current_settings;
                            $arguments['field'] = $s;
                            call_user_func_array($s_display_function, $arguments);
                        }
                    }
                    break;
            }
            if ($desc != '' and $s['type'] != 'desc') {
                ?>
					<p class="description">
						<?php 
                echo $desc;
                ?>
					</p>
				<?php 
            }
            echo '</td></tr>';
        }
    }
    if ($display_function != '') {
        if ($form_id != '') {
            $arguments['form_id'] = $form_id;
        }
        $arguments['metabox'] = $metabox;
        call_user_func_array($display_function, $arguments);
    }
    if ($display_container) {
        ?>
					</tbody>
				</table>
			</div>
		</div>
		<?php 
    }
}
Esempio n. 3
0
File: subs.php Progetto: RA2WP/RA2WP
 /**
  * Export submissions.
  * 
  * @access public
  * @param array $sub_ids
  * @param bool @return
  * @since 2.7
  * @return void
  */
 public function export($sub_ids = '', $return = false)
 {
     global $ninja_forms_fields;
     // Bail if we haven't been sent any IDs.
     if (empty($sub_ids)) {
         return false;
     }
     if (!is_array($sub_ids)) {
         $sub_ids = array($sub_ids);
     }
     $plugin_settings = nf_get_settings();
     $date_format = $plugin_settings['date_format'];
     $label_array = array();
     // Get our Form ID.
     $form_id = Ninja_Forms()->sub($sub_ids[0])->form_id;
     // Get our list of fields.
     $fields = Ninja_Forms()->form($form_id)->fields;
     // Add our sequential number.
     $label_array[0]['_seq_num'] = __('#', 'ninja-forms');
     // Add our "Date" label.
     $label_array[0]['_date_submitted'] = __('Date Submitted', 'ninja-forms');
     $label_array = apply_filters('nf_subs_csv_label_array_before_fields', $label_array, $sub_ids);
     foreach ($fields as $field_id => $field) {
         // Get our field type
         $field_type = $field['type'];
         // Check to see if our field type has been set as a "process_field".
         if (isset($ninja_forms_fields[$field_type])) {
             $reg_field = $ninja_forms_fields[$field_type];
             $process_field = $reg_field['process_field'];
         } else {
             $process_field = false;
         }
         // If this field's "process_field" is set to true, then add its label to the array.
         if ($process_field) {
             if (isset($field['data']['admin_label']) && $field['data']['admin_label'] != '') {
                 $label = $field['data']['admin_label'];
             } else {
                 if (isset($field['data']['label'])) {
                     $label = $field['data']['label'];
                 } else {
                     $label = '';
                 }
             }
             $label_array[0][$field_id] = apply_filters('nf_subs_csv_field_label', $label, $field_id);
         }
     }
     $label_array = ninja_forms_stripslashes_deep($label_array);
     $label_array = apply_filters('nf_subs_csv_label_array', $label_array, $sub_ids);
     $value_array = array();
     $x = 0;
     // Loop through our submissions and create a new row for each one.
     foreach ($sub_ids as $sub_id) {
         foreach ($label_array[0] as $field_id => $label) {
             // Make sure we aren't working with our date field, which will always have a field id of 0.
             if ($field_id !== 0) {
                 // Check to see if our field_id is numeric. If it isn't, then we're working with meta, not a field.
                 if (is_numeric($field_id)) {
                     // We're working with a field, grab the value.
                     $user_value = Ninja_Forms()->sub($sub_id)->get_field($field_id);
                 } else {
                     if ('_date_submitted' == $field_id) {
                         // Get the date of our submission.
                         $date = strtotime(Ninja_Forms()->sub($sub_id)->date_submitted);
                         // The first item is our date field.
                         $user_value = date($date_format, $date);
                     } else {
                         if ('_seq_num' == $field_id) {
                             $user_value = Ninja_Forms()->sub($sub_id)->get_seq_num();
                         } else {
                             // We're working with a piece of meta, grabe the value.
                             $user_value = Ninja_Forms()->sub($sub_id)->get_meta($field_id);
                         }
                     }
                 }
                 // Run our value through the appropriate filters before we flatten any arrays.
                 $user_value = apply_filters('nf_subs_export_pre_value', $user_value, $field_id);
                 // Implode any arrays we might have.
                 if (is_array($user_value)) {
                     $user_value = implode(',', $user_value);
                 }
                 // Add an ' to the beginning = sign to prevent any CSV/Excel security issues.
                 if (strpos($user_value, '=') === 0) {
                     $user_value = "'" . $user_value;
                 }
                 // Run our final value through the appropriate filters and assign it to the array.
                 $value_array[$x][$field_id] = htmlspecialchars_decode(apply_filters('nf_subs_csv_field_value', $user_value, $field_id), ENT_QUOTES);
             }
         }
         $x++;
     }
     $value_array = ninja_forms_stripslashes_deep($value_array);
     $value_array = apply_filters('nf_subs_csv_value_array', $value_array, $sub_ids);
     $array = array($label_array, $value_array);
     $today = date($date_format, current_time('timestamp'));
     $filename = apply_filters('nf_subs_csv_filename', 'nf_subs_' . $today);
     $filename = $filename . ".csv";
     if ($return) {
         return str_putcsv($array, apply_filters('nf_sub_csv_delimiter', ','), apply_filters('nf_sub_csv_enclosure', '"'), apply_filters('nf_sub_csv_terminator', "\n"));
     } else {
         header('Content-type: application/csv');
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header('Pragma: no-cache');
         header('Expires: 0');
         echo apply_filters('nf_sub_csv_bom', "");
         // Byte Order Mark
         echo str_putcsv($array, apply_filters('nf_sub_csv_delimiter', ','), apply_filters('nf_sub_csv_enclosure', '"'), apply_filters('nf_sub_csv_terminator', "\n"));
         die;
     }
 }
 /**
  * Add the submitted vars to $this->data['fields'].
  * Also runs any functions registered to the field's pre_process hook.
  *
  *
  */
 function setup_submitted_vars()
 {
     global $ninja_forms_fields, $wp;
     $form_ID = $this->data['form_ID'];
     //Get our plugin settings
     $plugin_settings = nf_get_settings();
     $req_field_error = __($plugin_settings['req_field_error'], 'ninja-forms');
     if (empty($this->data)) {
         return '';
     }
     $this->data['action'] = 'submit';
     $this->data['form']['form_url'] = $this->get_current_url();
     $cache = isset($_SESSION['ninja_forms_transient_id']) ? get_transient($_SESSION['ninja_forms_transient_id']) : null;
     // If we have fields in our $_POST object, then loop through the $_POST'd field values and add them to our global variable.
     if (isset($_POST['_ninja_forms_display_submit']) or isset($_POST['_ninja_forms_edit_sub'])) {
         $field_results = ninja_forms_get_fields_by_form_id($form_ID);
         //$field_results = apply_filters('ninja_forms_display_fields_array', $field_results, $form_ID);
         foreach ($field_results as $field) {
             $data = $field['data'];
             $field_id = $field['id'];
             $field_type = $field['type'];
             if (isset($_POST['ninja_forms_field_' . $field_id])) {
                 $val = ninja_forms_stripslashes_deep($_POST['ninja_forms_field_' . $field_id]);
                 $this->data['submitted_fields'][] = $field_id;
             } else {
                 $val = false;
             }
             $this->data['fields'][$field_id] = $val;
             $field_row = ninja_forms_get_field_by_id($field_id);
             $field_row['data']['field_class'] = 'ninja-forms-field';
             $this->data['field_data'][$field_id] = $field_row;
         }
         foreach ($_POST as $key => $val) {
             if (substr($key, 0, 1) == '_') {
                 $this->data['extra'][$key] = $val;
             }
         }
         //Grab the form info from the database and store it in our global form variables.
         $form_row = ninja_forms_get_form_by_id($form_ID);
         $form_data = $form_row['data'];
         if (isset($_REQUEST['_sub_id']) and !empty($_REQUEST['_sub_id'])) {
             $form_data['sub_id'] = absint($_REQUEST['_sub_id']);
         } else {
             $form_data['sub_id'] = '';
         }
         //Loop through the form data and set the global $ninja_form_data variable.
         if (is_array($form_data) and !empty($form_data)) {
             foreach ($form_data as $key => $val) {
                 if (!is_array($val)) {
                     $value = stripslashes($val);
                     //$value = esc_html($value);
                     //$value = htmlspecialchars($value);
                 } else {
                     $value = $val;
                 }
                 $this->data['form'][$key] = $value;
             }
             $this->data['form']['admin_attachments'] = array();
             $this->data['form']['user_attachments'] = array();
         }
     } else {
         if ($cache !== false) {
             // Check to see if we have $_SESSION values from a submission.
             if (is_array($cache['field_values'])) {
                 // We do have a submission contained in our $_SESSION variable. We'll populate the field values with that data.
                 foreach ($cache['field_values'] as $field_id => $val) {
                     $field_row = ninja_forms_get_field_by_id($field_id);
                     if (is_array($field_row) and !empty($field_row)) {
                         if (isset($field_row['type'])) {
                             $field_type = $field_row['type'];
                         } else {
                             $field_type = '';
                         }
                         if (isset($field_row['data']['req'])) {
                             $req = $field_row['data']['req'];
                         } else {
                             $req = '';
                         }
                         $val = ninja_forms_stripslashes_deep($val);
                         //$val = ninja_forms_esc_html_deep( $val );
                         $this->data['fields'][$field_id] = $val;
                         if (isset($cache['field_settings'][$field_id])) {
                             $field_row = $cache['field_settings'][$field_id];
                         } else {
                             $field_row = ninja_forms_get_field_by_id($field_id);
                         }
                         $field_row['data']['field_class'] = 'ninja-forms-field';
                         $this->data['field_data'][$field_id] = $field_row;
                     }
                 }
             }
             $this->data['form'] = $cache['form_settings'];
             $this->data['success'] = $cache['success_msgs'];
             $this->data['errors'] = $cache['error_msgs'];
             $this->data['extra'] = $cache['extra_values'];
         }
     }
 }
Esempio n. 5
0
function ninja_forms_add_fav()
{
    global $wpdb;
    // Bail if we aren't in the admin
    if (!is_admin()) {
        return false;
    }
    check_ajax_referer('nf_ajax', 'nf_ajax_nonce');
    $field_data = $_REQUEST['field_data'];
    $field_id = absint($_REQUEST['field_id']);
    $field_row = ninja_forms_get_field_by_id($field_id);
    $field_type = $field_row['type'];
    $form_id = 1;
    $data = array();
    foreach ($field_data as $key => $val) {
        $key = stripslashes($key);
        $key = str_replace('"', '', $key);
        if (strpos($key, '[')) {
            $key = str_replace(']', '', $key);
            $key = explode('[', $key);
            $multi = array();
            $temp =& $multi;
            $x = 0;
            $count = count($key) - 1;
            foreach ($key as $item) {
                $temp[$item] = array();
                if ($x < $count) {
                    $temp =& $temp[$item];
                } else {
                    $temp[$item] = $val;
                }
                $x++;
            }
            $data = ninja_forms_array_merge_recursive($data, $multi);
        } else {
            $data[$key] = $val;
        }
    }
    $name = stripslashes(esc_html($_REQUEST['fav_name']));
    if (!isset($data['label']) or empty($data['label'])) {
        $data['label'] = $name;
    }
    $data = ninja_forms_stripslashes_deep($data);
    $data = serialize($data);
    $wpdb->insert(NINJA_FORMS_FAV_FIELDS_TABLE_NAME, array('row_type' => 1, 'type' => $field_type, 'order' => 0, 'data' => $data, 'name' => $name));
    $fav_id = $wpdb->insert_id;
    $update_array = array('fav_id' => $fav_id);
    $wpdb->update(NINJA_FORMS_FIELDS_TABLE_NAME, $update_array, array('id' => $field_id));
    $new_html = '<p class="button-controls" id="ninja_forms_insert_fav_field_' . $fav_id . '_p">
				<a class="button add-new-h2 ninja-forms-insert-fav-field" id="ninja_forms_insert_fav_field_' . $fav_id . '" name=""  href="#">' . __($name, 'ninja-forms') . '</a>
			</p>';
    header("Content-type: application/json");
    $array = array('fav_id' => $fav_id, 'fav_name' => $name, 'link_html' => $new_html);
    echo json_encode($array);
    die;
}
Esempio n. 6
0
function ninja_forms_export_subs_to_csv($sub_ids = '', $return = false)
{
    global $ninja_forms_fields, $ninja_forms_processing;
    $plugin_settings = get_option("ninja_forms_settings");
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    //Create a $label_array that contains all of the field labels.
    //Get the Form ID.
    if (isset($ninja_forms_processing)) {
        $form_id = $ninja_forms_processing->get_form_ID();
    } else {
        if (isset($_REQUEST['form_id'])) {
            $form_id = absint($_REQUEST['form_id']);
        }
    }
    //Get the fields attached to the Form ID
    $field_results = ninja_forms_get_fields_by_form_id($form_id);
    //Set the label array to a blank
    $label_array = array();
    $value_array = array();
    $sub_id_array = array();
    $label_array[0][] = "Date";
    if (is_array($field_results) and !empty($field_results)) {
        foreach ($field_results as $field) {
            $field_type = $field['type'];
            $field_id = $field['id'];
            if (isset($ninja_forms_fields[$field_type]['process_field'])) {
                $process_field = $ninja_forms_fields[$field_type]['process_field'];
            } else {
                $process_field = true;
            }
            if (isset($field['data']['label'])) {
                $label = $field['data']['label'];
            } else {
                $label = '';
            }
            if ($process_field) {
                $label_array[0][$field_id] = apply_filters('ninja_forms_export_sub_label', $label, $field_id);
            }
        }
    }
    if (is_array($sub_ids) and !empty($sub_ids)) {
        $x = 0;
        foreach ($sub_ids as $id) {
            $sub_row = ninja_forms_get_sub_by_id($id);
            $sub_id_array[$x] = $id;
            $date_updated = date($date_format, strtotime($sub_row['date_updated']));
            $value_array[$x][] = $date_updated;
            if (is_array($sub_row['data']) and !empty($sub_row['data'])) {
                foreach ($label_array[0] as $field_id => $label) {
                    if ($field_id != 0) {
                        $found = false;
                        foreach ($sub_row['data'] as $data) {
                            $data['user_value'] = ninja_forms_stripslashes_deep($data['user_value']);
                            $data['user_value'] = ninja_forms_html_entity_decode_deep($data['user_value'], ENT_QUOTES);
                            if ($data['field_id'] == $field_id) {
                                if (is_array($data['user_value'])) {
                                    $user_value = implode_r(',', $data['user_value']);
                                } else {
                                    $user_value = $data['user_value'];
                                }
                                $found = true;
                            }
                        }
                        if (!$found) {
                            $user_value = '';
                        }
                        $value_array[$x][] = apply_filters('ninja_forms_export_sub_value', $user_value, $field_id);
                    }
                }
            }
            $x++;
        }
    }
    $value_array = ninja_forms_stripslashes_deep($value_array);
    $value_array = apply_filters('ninja_forms_export_subs_value_array', $value_array, $sub_id_array);
    $label_array = ninja_forms_stripslashes_deep($label_array);
    $label_array = apply_filters('ninja_forms_export_subs_label_array', $label_array, $sub_id_array);
    $array = array($label_array, $value_array);
    $today = date($date_format);
    $filename = apply_filters('ninja_forms_export_subs_csv_file_name', 'ninja_forms_subs_' . $today);
    $filename = $filename . ".csv";
    if ($return) {
        return str_putcsv($array, apply_filters('ninja_forms_csv_delimiter', ','), apply_filters('ninja_forms_csv_enclosure', '"'), apply_filters('ninja_forms_csv_terminator', "\n"));
    } else {
        header("Content-type: application/csv");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Pragma: no-cache");
        header("Expires: 0");
        echo apply_filters('ninja_forms_csv_bom', "");
        // Byte Order Mark
        echo str_putcsv($array, apply_filters('ninja_forms_csv_delimiter', ','), apply_filters('ninja_forms_csv_enclosure', '"'), apply_filters('ninja_forms_csv_terminator', "\n"));
        die;
    }
}
Esempio n. 7
0
function ninja_forms_admin_save()
{
    global $ninja_forms_tabs, $ninja_forms_sidebars, $ninja_forms_tabs_metaboxes, $ninja_forms_admin_update_message;
    if (!empty($_POST) and !empty($_POST['_ninja_forms_admin_submit']) and $_POST['_ninja_forms_admin_submit'] != '') {
        if (wp_verify_nonce($_POST['_ninja_forms_admin_submit'], '_ninja_forms_save') and check_admin_referer('_ninja_forms_save', '_ninja_forms_admin_submit')) {
            $current_page = esc_html($_REQUEST['page']);
            $current_tab = ninja_forms_get_current_tab();
            $data_array = array();
            if (isset($_REQUEST['form_id']) and $_REQUEST['form_id'] != 'new') {
                $form_id = absint($_REQUEST['form_id']);
            } else {
                if (isset($_REQUEST['form_id']) and $_REQUEST['form_id'] == 'new') {
                    $form_id = 'new';
                } else {
                    $form_id = '';
                }
            }
            foreach ($_POST as $key => $val) {
                if (substr($key, 0, 1) != '_') {
                    $data_array[$key] = $val;
                }
            }
            $data_array = ninja_forms_stripslashes_deep($data_array);
            //$data_array = ninja_forms_esc_html_deep( $data_array );
            //Call any save functions registered to metaboxes
            if (isset($ninja_forms_tabs_metaboxes[$current_page][$current_tab]) and is_array($ninja_forms_tabs_metaboxes[$current_page][$current_tab]) and !empty($ninja_forms_tabs_metaboxes[$current_page][$current_tab])) {
                foreach ($ninja_forms_tabs_metaboxes[$current_page][$current_tab] as $slug => $opts) {
                    // Get the save function of our options, if set, and call them, passing the data that has been posted.
                    if (isset($opts['settings']) and !empty($opts['settings'])) {
                        foreach ($opts['settings'] as $setting) {
                            if (isset($setting['save_function'])) {
                                if (isset($form_id) and $form_id != '') {
                                    $arguments['form_id'] = $form_id;
                                }
                                $arguments['data'] = $data_array;
                                if ($setting['save_function'] != '') {
                                    if ($ninja_forms_admin_update_message != '') {
                                        $ninja_forms_admin_update_message .= ' ';
                                    }
                                    $ninja_forms_admin_update_message .= call_user_func_array($setting['save_function'], $arguments);
                                    do_action('ninja_forms_save_admin_metabox_option', $setting, $form_id, $data_array);
                                }
                            }
                        }
                    }
                    if (isset($opts['save_function'])) {
                        $save_function = $opts['save_function'];
                        $arguments = func_get_args();
                        array_shift($arguments);
                        // We need to remove the first arg ($function_name)
                        if (isset($form_id) and $form_id != '') {
                            $arguments['form_id'] = $form_id;
                        }
                        $arguments['data'] = $data_array;
                        if ($save_function != '') {
                            if ($ninja_forms_admin_update_message != '') {
                                $ninja_forms_admin_update_message .= ' ';
                            }
                            $ninja_forms_admin_update_message .= call_user_func_array($save_function, $arguments);
                            do_action('ninja_forms_save_admin_metabox', $slug, $form_id, $data_array);
                        }
                    }
                }
            }
            // Get the save function of our current sidebars, if present, and call them, passing the data that has been posted.
            if (isset($ninja_forms_sidebars[$current_page][$current_tab]) and is_array($ninja_forms_sidebars[$current_page][$current_tab])) {
                foreach ($ninja_forms_sidebars[$current_page][$current_tab] as $slug => $sidebar) {
                    if ($sidebar['save_function'] != '') {
                        $save_function = $sidebar['save_function'];
                        $arguments = func_get_args();
                        array_shift($arguments);
                        // We need to remove the first arg ($function_name)
                        if (isset($form_id) and $form_id != '') {
                            $arguments['form_id'] = $form_id;
                        }
                        $arguments['data'] = $data_array;
                        if ($save_function != '') {
                            if ($ninja_forms_admin_update_message != '') {
                                $ninja_forms_admin_update_message .= ' ';
                            }
                            $ninja_forms_admin_update_message .= call_user_func_array($save_function, $arguments);
                            do_action('ninja_forms_save_admin_sidebar', $slug, $form_id, $data_array);
                        }
                    }
                }
            }
            // Get the save function of our current tab and call it, passing the data that has been posted.
            $save_function = $ninja_forms_tabs[$current_page][$current_tab]['save_function'];
            $tab_reload = $ninja_forms_tabs[$current_page][$current_tab]['tab_reload'];
            $arguments = func_get_args();
            array_shift($arguments);
            // We need to remove the first arg ($function_name)
            if (isset($form_id) and $form_id != '') {
                $arguments['form_id'] = $form_id;
            }
            $arguments['data'] = $data_array;
            if ($save_function != '') {
                $ninja_forms_admin_update_message = call_user_func_array($save_function, $arguments);
                do_action('ninja_forms_save_admin_tab', $current_tab, $form_id, $data_array);
            }
            if ($tab_reload) {
                $redirect_array = array('update_message' => urlencode($ninja_forms_admin_update_message));
                $url = esc_url_raw(add_query_arg($redirect_array));
                wp_redirect($url);
            }
        }
    }
}
function ninja_forms_tab_view_subs()
{
    global $ninja_forms_fields;
    $plugin_settings = get_option('ninja_forms_settings');
    if (isset($plugin_settings['date_format']) and $plugin_settings['date_format'] != '') {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    $all_forms = ninja_forms_get_all_forms();
    if (is_array($all_forms) and isset($all_forms[0])) {
        $first_form_id = $all_forms[0]['id'];
    } else {
        $first_form_id = '';
    }
    if (isset($_REQUEST['form_id']) and $_REQUEST['form_id'] == '') {
        unset($_SESSION['ninja_forms_form_id']);
        $form_id = $first_form_id;
    } else {
        if (isset($_REQUEST['form_id']) and $_REQUEST['form_id'] != '') {
            $_SESSION['ninja_forms_form_id'] = absint($_REQUEST['form_id']);
            $form_id = absint($_REQUEST['form_id']);
        } else {
            if (isset($_SESSION['ninja_forms_form_id']) and $_SESSION['ninja_forms_form_id'] != 'all') {
                $form_id = $_SESSION['ninja_forms_form_id'];
            } else {
                $form_id = $first_form_id;
            }
        }
    }
    if (isset($_REQUEST['sub_id']) and !empty($_REQUEST['sub_id'])) {
        $sub_id = absint($_REQUEST['sub_id']);
    } else {
        $sub_id = '';
    }
    if (isset($_REQUEST['begin_date']) and !empty($_REQUEST['begin_date'])) {
        $begin_date = esc_html($_REQUEST['begin_date']);
    } else {
        if (isset($_SESSION['ninja_forms_begin_date']) and !empty($_SESSION['ninja_forms_begin_date'])) {
            if (isset($_POST['submit']) and !empty($_REQUEST['begin_date']) or !isset($_POST['submit'])) {
                $begin_date = $_SESSION['ninja_forms_begin_date'];
            } else {
                $begin_date = '';
            }
        } else {
            $begin_date = '';
        }
    }
    if (isset($_REQUEST['end_date']) and !empty($_REQUEST['end_date'])) {
        $end_date = esc_html($_REQUEST['end_date']);
    } else {
        if (isset($_SESSION['ninja_forms_end_date']) and !empty($_SESSION['ninja_forms_end_date'])) {
            if (isset($_POST['submit']) and !empty($_REQUEST['end_date']) or !isset($_POST['submit'])) {
                $end_date = $_SESSION['ninja_forms_end_date'];
            } else {
                $end_date = '';
            }
        } else {
            $end_date = '';
        }
    }
    if (isset($_REQUEST['edit_sub_form'])) {
        $edit_sub_form = absint($_REQUEST['edit_sub_form']);
    } else {
        $edit_sub_form = '';
    }
    if ($form_id == '') {
        ?>
		<h2><?php 
        _e('View Form Submissions', 'ninja-forms');
        ?>
</h2>
		<p class="description description-wide">

		</p>
		<?php 
    } else {
        if (isset($_REQUEST['limit'])) {
            $saved_limit = absint($_REQUEST['limit']);
            $limit = absint($_REQUEST['limit']);
        } else {
            $saved_limit = 20;
            $limit = 20;
        }
        if (isset($_REQUEST['paged']) and !empty($_REQUEST['paged'])) {
            $current_page = absint($_REQUEST['paged']);
        } else {
            $current_page = 1;
        }
        if ($current_page > 1) {
            $start = ($current_page - 1) * $limit;
            if ($sub_count < $limit) {
                $end = $sub_count;
            } else {
                $end = $current_page * $limit;
                //$end = $end - 1;
            }
            if ($end > $sub_count) {
                $end = $sub_count;
            }
        } else {
            $start = 0;
            $end = $limit;
        }
        $args = array('form_id' => $form_id, 'begin_date' => $begin_date, 'end_date' => $end_date, 'limit' => $start . ',' . $limit);
        $sub_results = ninja_forms_get_subs($args);
        $sub_results = apply_filters('ninja_forms_view_subs_results', $sub_results);
        $sub_count = count($sub_results);
        if (isset($_REQUEST['limit'])) {
            $saved_limit = absint($_REQUEST['limit']);
            $limit = absint($_REQUEST['limit']);
        } else {
            $saved_limit = 20;
            $limit = 20;
        }
        if ($sub_count < $limit) {
            $limit = $sub_count;
        }
        if (isset($_REQUEST['paged']) and !empty($_REQUEST['paged'])) {
            $current_page = absint($_REQUEST['paged']);
        } else {
            $current_page = 1;
        }
        if ($sub_count > $limit) {
            $page_count = ceil($sub_count / $limit);
        } else {
            $page_count = 1;
        }
        if ($current_page > 1) {
            $start = ($current_page - 1) * $limit;
            if ($sub_count < $limit) {
                $end = $sub_count;
            } else {
                $end = $current_page * $limit;
                //$end = $end - 1;
            }
            if ($end > $sub_count) {
                $end = $sub_count;
            }
        } else {
            $start = 0;
            $end = $limit;
        }
        $form_row = ninja_forms_get_form_by_id($form_id);
        $form_title = '';
        if (is_array($form_row) and !empty($form_row)) {
            if (isset($form_row['data']['form_title'])) {
                $form_title = $form_row['data']['form_title'];
            }
        }
        if ($edit_sub_form != 1) {
            ?>
			<div id="" class="tablenav top">
				<div class="alignleft actions">
				<select id="" class="" name="bulk_action">
					<option value=""><?php 
            _e('Bulk Actions', 'ninja-forms');
            ?>
</option>
					<option value="delete"><?php 
            _e('Delete', 'ninja-forms');
            ?>
</option>
					<option value="export"><?php 
            _e('Export', 'ninja-forms');
            ?>
</option>
				</select>
				<input type="submit" name="submit" value="<?php 
            _e('Apply', 'ninja-forms');
            ?>
" class="button-secondary">
			</div>
			<div class="alignleft actions">
				<select id="" name="limit">
					<option value="20" <?php 
            selected($saved_limit, 20);
            ?>
>20</option>
					<option value="50" <?php 
            selected($saved_limit, 50);
            ?>
>50</option>
					<option value="100" <?php 
            selected($saved_limit, 100);
            ?>
>100</option>
					<option value="300" <?php 
            selected($saved_limit, 300);
            ?>
>300</option>
					<option value="500" <?php 
            selected($saved_limit, 500);
            ?>
>500</option>
				</select>
				<?php 
            _e('Submissions Per Page', 'ninja-forms');
            ?>
				<input type="submit" name="submit" value="<?php 
            _e('Go', 'ninja-forms');
            ?>
" class="button-secondary">
			</div>
				<div class="alignleft actions">
 					<input type="submit" name="submit" class="ninja-forms-download-all-subs button-secondary" value="<?php 
            _e('Download All Submissions', 'ninja-forms');
            ?>
">
				</div>
				<div id="" class="alignright navtable-pages">
					<?php 
            if ($sub_count != 0 and $current_page <= $page_count) {
                ?>
					<span class="displaying-num"><?php 
                if ($start == 0) {
                    echo 1;
                } else {
                    echo $start + 1;
                }
                ?>
 - <?php 
                echo $end;
                ?>
 of <?php 
                echo $sub_count;
                ?>
 <?php 
                if ($sub_count == 1) {
                    _e('Submission', 'ninja-forms');
                } else {
                    _e('Submissions', 'ninja-forms');
                }
                ?>
</span>
					<?php 
            }
            if ($page_count > 1) {
                $first_page = add_query_arg(array('paged' => 1));
                $last_page = add_query_arg(array('paged' => $page_count));
                if ($current_page > 1) {
                    $prev_page = $current_page - 1;
                    $prev_page = add_query_arg(array('paged' => $prev_page));
                } else {
                    $prev_page = $first_page;
                }
                if ($current_page != $page_count) {
                    $next_page = $current_page + 1;
                    $next_page = add_query_arg(array('paged' => $next_page));
                } else {
                    $next_page = $last_page;
                }
                ?>
					<span class="pagination-links">
						<a class="first-page disabled" title="<?php 
                _e('Go to the first page', 'ninja-forms');
                ?>
" href="<?php 
                echo $first_page;
                ?>
">«</a>
						<a class="prev-page disabled" title="<?php 
                _e('Go to the previous page', 'ninja-forms');
                ?>
" href="<?php 
                echo $prev_page;
                ?>
">‹</a>
						<span class="paging-input"><input class="current-page" title="<?php 
                _e('Current page', 'ninja-forms');
                ?>
" type="text" name="paged" value="<?php 
                echo $current_page;
                ?>
" size="2"> of <span class="total-pages"><?php 
                echo $page_count;
                ?>
</span></span>
						<a class="next-page" title="<?php 
                _e('Go to the next page', 'ninja-forms');
                ?>
" href="<?php 
                echo $next_page;
                ?>
">›</a>
						<a class="last-page" title="<?php 
                _e('Go to the last page', 'ninja-forms');
                ?>
" href="<?php 
                echo $last_page;
                ?>
">»</a>
					</span>
					<?php 
            }
            ?>
				</div>
			</div>
			<?php 
        } else {
            $back_link = remove_query_arg(array('edit_sub_form'));
            ?>
			<div id="" class="">
				<a href="<?php 
            echo $back_link;
            ?>
" class="button-secondary"><?php 
            _e('Back To Submissions', 'ninja-forms');
            ?>
</a>
			</div>
			<?php 
        }
        ?>
			</div>
			<table border="1px" class="wp-list-table widefat fixed posts">
			<?php 
        //Grab the first few fields attached to our form so that we can create column headers.
        $field_results = ninja_forms_get_fields_by_form_id($form_id);
        $col_count = 0;
        if (is_array($field_results) and !empty($field_results) and $edit_sub_form != 1) {
            foreach ($field_results as $key => $field) {
                $field_type = $field['type'];
                if (isset($ninja_forms_fields[$field_type])) {
                    $reg_field = $ninja_forms_fields[$field_type];
                    if (!$reg_field['process_field'] or !$reg_field['save_sub']) {
                        unset($field_results[$key]);
                    } else {
                        if ($col_count < 2) {
                            $col_count++;
                        }
                    }
                }
            }
            $field_results = array_values($field_results);
            $field_results = apply_filters('ninja_forms_view_subs_table_header', $field_results, $form_id);
            ?>
				<thead>
					<tr>
						<th class="check-column"><input type="checkbox" id="" class="ninja-forms-select-all" title="ninja-forms-subs-bulk-action"></th>
						<th><?php 
            _e('Date', 'ninja-forms');
            ?>
</th>
						<?php 
            do_action('ninja_forms_view_sub_table_header', $form_id);
            $x = 0;
            while ($x <= $col_count) {
                if (isset($field_results[$x]['data']['label'])) {
                    ?>
						<th><?php 
                    echo $field_results[$x]['data']['label'];
                    ?>
</th>
				<?php 
                }
                $x++;
            }
            ?>
					</tr>
				</thead>
		<?php 
        }
        ?>
				<tbody id="ninja_forms_subs_tbody">
		<?php 
        if (is_array($sub_results) and !empty($sub_results) and $edit_sub_form != 1 and $current_page <= $page_count) {
            for ($i = $start; $i < $end; $i++) {
                $sub = $sub_results[$i];
                $data = apply_filters('ninja_forms_view_sub_data', $sub['data'], $sub['id']);
                ?>
				<tr id="ninja_forms_sub_<?php 
                echo $sub['id'];
                ?>
_tr">
					<th scope="row" class="check-column">
						<input type="checkbox" id="" name="ninja_forms_sub[]" value="<?php 
                echo $sub['id'];
                ?>
" class="ninja-forms-subs-bulk-action">
					</th>
					<td>
						<?php 
                $date = $sub['date_updated'];
                $date = strtotime($date);
                $date = date($date_format, $date);
                echo $date;
                ?>
						<div class="row-actions">
							<?php 
                /**
                 * ninja_forms_sub_table_row_actions hook
                 * hook in here to allow extra row actions
                 *
                 * @hooked ninja_forms_sub_table_row_actions_edit - 10
                 * @hooked ninja_forms_sub_table_row_actions_delete - 20
                 * @hooked ninja_forms_sub_table_row_actions_export - 30
                 */
                $row_actions = apply_filters('ninja_forms_sub_table_row_actions', array(), $data, $sub['id'], $form_id);
                echo implode(" | ", $row_actions);
                ?>
						</div>
					</td>
				<?php 
                do_action('ninja_forms_view_sub_table_row', $form_id, $sub['id']);
                $x = 0;
                while ($x <= $col_count) {
                    if (isset($field_results[$x]['id'])) {
                        $field_id = $field_results[$x]['id'];
                        ?>

						<td id="ninja_forms_sub_<?php 
                        echo $sub['id'];
                        ?>
_field_<?php 
                        echo $field_id;
                        ?>
">
						<?php 
                        foreach ($data as $d) {
                            if ($field_id == $d['field_id']) {
                                $user_value = $d['user_value'];
                                $user_value = ninja_forms_stripslashes_deep($user_value);
                                $user_value = ninja_forms_strip_tags_deep($user_value);
                                $user_value = apply_filters('ninja_forms_view_sub_td', $user_value, $d['field_id'], $sub['id']);
                                if (is_array($user_value) and !empty($user_value)) {
                                    $y = 1;
                                    foreach ($user_value as $val) {
                                        echo ninja_forms_stripslashes_deep($val);
                                        if ($y != count($user_value)) {
                                            echo ", ";
                                        }
                                        $y++;
                                    }
                                } else {
                                    echo stripslashes($user_value);
                                }
                            }
                        }
                        ?>
						</td>
					<?php 
                    }
                    $x++;
                }
                ?>

				</tr>
				<?php 
            }
        } else {
            if ($edit_sub_form == 1) {
                $sub_row = ninja_forms_get_sub_by_id($sub_id);
                $data = $sub_row['data'];
                $date_updated = strtotime($sub_row['date_updated']);
                $date_updated = date($date_format, $date_updated);
                $sub_status = $sub_row['status'];
                ?>
				<input type="hidden" name="_sub_id" value="<?php 
                echo $sub_id;
                ?>
">
				<input type="hidden" name="_ninja_forms_edit_sub" value="1">
				<input type="hidden" name="_ninja_forms_sub_status" value="<?php 
                echo $sub_status;
                ?>
">
				<input type="hidden" name="_form_id" value="<?php 
                echo $form_id;
                ?>
">
				<?php 
                add_filter('ninja_forms_field', 'ninja_forms_edit_sub_default_value', 15, 2);
                add_filter('ninja_forms_field', 'ninja_forms_edit_sub_hide_fields', 99, 2);
                add_filter('ninja_forms_display_form_form_data', 'ninja_forms_edit_sub_remove_ajax');
                remove_action('ninja_forms_display_before_fields', 'ninja_forms_display_req_items');
                remove_action('ninja_forms_display_open_form_tag', 'ninja_forms_display_open_form_tag');
                remove_action('ninja_forms_display_close_form_tag', 'ninja_forms_display_close_form_tag');
                remove_action('ninja_forms_display_before_form', 'ninja_forms_display_response_message');
                remove_action('ninja_forms_display_after_open_form_tag', 'ninja_forms_display_hidden_fields');
                ninja_forms_display_form($form_id);
                ?>
				<tr id="">
					<td colspan="2"><input type="submit" name="submit" value="<?php 
                _e('Save Submission', 'ninja-forms');
                ?>
" class="button-primary"></td>
				</tr>
			<?php 
            } else {
                ?>
			<tr id="ninja_forms_subs_empty" style="">
				<td colspan="7">
					<?php 
                _e('No submissions found', 'ninja-forms');
                ?>
				</td>
			</tr>
			<?php 
            }
        }
        ?>

				</tbody>
				<?php 
        //Grab the first few fields attached to our form so that we can create column headers.
        //$field_results = ninja_forms_get_fields_by_form_id($form_id);
        //$col_count = 0;
        if (is_array($field_results) and !empty($field_results) and $edit_sub_form != 1) {
            /*
            				foreach($field_results as $key => $field){
            					$field_type = $field['type'];
            					$reg_field = $ninja_forms_fields[$field_type];
            					if(!$reg_field['process_field'] OR !$reg_field['save_sub']){
            						unset($field_results[$key]);
            					}else{
            						if($col_count < 2){
            							$col_count++;
            						}
            					}
            				}
            */
            ?>
				<tfoot>
					<tr>
						<th class="check-column"><input type="checkbox" id="" class="ninja-forms-select-all" title="ninja-forms-subs-bulk-action"></th>
						<th><?php 
            _e('Date', 'ninja-forms');
            ?>
</th>
				<?php 
            do_action('ninja_forms_view_sub_table_header', $form_id);
            $x = 0;
            while ($x <= $col_count) {
                if (isset($field_results[$x]['data']['label'])) {
                    ?>
						<th><?php 
                    echo $field_results[$x]['data']['label'];
                    ?>
</th>
				<?php 
                }
                $x++;
            }
            ?>
					</tr>
				</tfoot>
		<?php 
        }
        ?>
			</table>
		<div id="ninja_forms_sub_info_wrap" class="form-section" style="display:none;">
			<a href="#" id="" class="ninja-forms-back-sub"><?php 
        _e('Back', 'ninja-forms');
        ?>
</a>
			<br />
			<br />
			<div id="ninja_forms_sub_info">


			</div>
			<input type="button" id="ninja_forms_edit_sub" value="<?php 
        _e('Save', 'ninja-forms');
        ?>
" class="button-primary"> &nbsp;&nbsp; <span id="ninja_forms_edit_sub_loading" style="display:none;"><img src="<?php 
        echo NINJA_FORMS_URL . "/images/loading.gif";
        ?>
" alt="loading"></span>
		</div>
			<?php 
    }
}
 /**
  * Get value of a setting field
  *
  * @author Aman Saini
  * @since  1.1
  * @param [type]  $current_settings [description]
  * @param [type]  $name             [description]
  * @return [type]                   [description]
  */
 public static function get_value($current_settings, $name)
 {
     if (isset($current_settings[$name])) {
         if (is_array($current_settings[$name])) {
             $value = ninja_forms_stripslashes_deep($current_settings[$name]);
         } else {
             $value = stripslashes($current_settings[$name]);
         }
     } else {
         $value = '';
     }
     return $value;
 }
Esempio n. 10
0
/**
 * Remove slashes from the submission form td
 *
 * @param  $field_value - the value of the field
 * @param  $field_id    - the field id
 * @param  $sub_id      - the submission id
 * @return string       - the value of the user history field
 */
function ninja_forms_strip_sub_td_slashes($field_value, $field_id, $sub_id)
{
    // remove slashes
    $field_value = ninja_forms_stripslashes_deep($field_value);
    return $field_value;
}