|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class FrmEntriesController { |
|
4
|
|
|
|
|
5
|
|
|
public static function menu() { |
|
6
|
|
|
FrmAppHelper::force_capability( 'frm_view_entries' ); |
|
7
|
|
|
|
|
8
|
|
|
add_submenu_page('formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
9
|
|
|
|
|
10
|
|
|
if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show' ) ) ) { |
|
11
|
|
|
$menu_name = FrmAppHelper::get_menu_name(); |
|
12
|
|
|
add_filter( 'manage_' . sanitize_title( $menu_name ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' ); |
|
13
|
|
|
add_filter( 'get_user_option_manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' ); |
|
14
|
|
|
add_filter( 'manage_' . sanitize_title( $menu_name ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' ); |
|
15
|
|
|
} |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/* Display in Back End */ |
|
19
|
|
|
public static function route() { |
|
20
|
|
|
$action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
|
21
|
|
|
|
|
22
|
|
|
switch ( $action ) { |
|
23
|
|
|
case 'show': |
|
24
|
|
|
case 'destroy': |
|
25
|
|
|
case 'destroy_all': |
|
26
|
|
|
return self::$action(); |
|
27
|
|
|
|
|
28
|
|
|
default: |
|
29
|
|
|
do_action( 'frm_entry_action_route', $action ); |
|
30
|
|
|
if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return self::display_list(); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public static function contextual_help( $help, $screen_id, $screen ) { |
|
39
|
|
|
// Only add to certain screens. add_help_tab was introduced in WordPress 3.3 |
|
40
|
|
|
if ( ! method_exists( $screen, 'add_help_tab' ) ) { |
|
41
|
|
|
return $help; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
|
45
|
|
|
$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
|
46
|
|
|
if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) { |
|
47
|
|
|
return $help; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
unset( $action, $page ); |
|
51
|
|
|
|
|
52
|
|
|
$screen->add_help_tab( array( |
|
53
|
|
|
'id' => 'formidable-entries-tab', |
|
54
|
|
|
'title' => __( 'Overview', 'formidable' ), |
|
55
|
|
|
'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) . '</p> <p>' . esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>', |
|
56
|
|
|
)); |
|
57
|
|
|
|
|
58
|
|
|
$screen->set_help_sidebar( |
|
59
|
|
|
'<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' . |
|
60
|
|
|
'<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/knowledgebase/manage-entries-from-the-back-end/' ) ) . '" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' . |
|
61
|
|
|
'<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/help-desk/' ) ) . '" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
return $help; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function manage_columns( $columns ) { |
|
68
|
|
|
global $frm_vars; |
|
69
|
|
|
$form_id = FrmForm::get_current_form_id(); |
|
70
|
|
|
|
|
71
|
|
|
$columns[ $form_id . '_id' ] = 'ID'; |
|
72
|
|
|
$columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' ); |
|
73
|
|
|
|
|
74
|
|
|
if ( $form_id ) { |
|
75
|
|
|
self::get_columns_for_form( $form_id, $columns ); |
|
76
|
|
|
} else { |
|
77
|
|
|
$columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' ); |
|
78
|
|
|
$columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' ); |
|
79
|
|
|
$columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); |
|
83
|
|
|
$columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); |
|
84
|
|
|
$columns[ $form_id . '_ip' ] = 'IP'; |
|
85
|
|
|
|
|
86
|
|
|
$frm_vars['cols'] = $columns; |
|
87
|
|
|
|
|
88
|
|
|
$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
|
89
|
|
|
if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { |
|
90
|
|
|
add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $columns; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
private static function get_columns_for_form( $form_id, &$columns ) { |
|
97
|
|
|
$form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
|
98
|
|
|
|
|
99
|
|
|
foreach ( $form_cols as $form_col ) { |
|
100
|
|
|
if ( FrmField::is_no_save_field( $form_col->type ) ) { |
|
101
|
|
|
continue; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) { |
|
105
|
|
|
$sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] ); |
|
106
|
|
|
|
|
107
|
|
|
if ( $sub_form_cols ) { |
|
108
|
|
|
foreach ( $sub_form_cols as $k => $sub_form_col ) { |
|
109
|
|
|
if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
|
110
|
|
|
unset( $sub_form_cols[ $k ] ); |
|
111
|
|
|
continue; |
|
112
|
|
|
} |
|
113
|
|
|
$columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
114
|
|
|
unset($sub_form_col); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
unset($sub_form_cols); |
|
118
|
|
|
} else { |
|
119
|
|
|
$col_id = $form_col->field_key; |
|
120
|
|
|
if ( $form_col->form_id != $form_id ) { |
|
121
|
|
|
$col_id .= '-_-form' . $form_col->form_id; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$has_separate_value = ! FrmField::is_option_empty( $form_col, 'separate_value' ); |
|
125
|
|
|
$is_post_status = FrmField::is_option_true( $form_col, 'post_field' ) && $form_col->field_options['post_field'] == 'post_status'; |
|
126
|
|
|
if ( $has_separate_value && ! $is_post_status ) { |
|
127
|
|
|
$columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
128
|
|
|
} |
|
129
|
|
|
$columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
|
135
|
|
|
$menu_name = FrmAppHelper::get_menu_name(); |
|
136
|
|
|
$this_page_name = 'manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden'; |
|
137
|
|
|
if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { |
|
138
|
|
|
return $check; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if ( empty( $prev_value ) ) { |
|
142
|
|
|
$prev_value = get_metadata( 'user', $object_id, $meta_key, true ); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
global $frm_vars; |
|
146
|
|
|
//add a check so we don't create a loop |
|
147
|
|
|
$frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
148
|
|
|
|
|
149
|
|
|
return $check; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
//add hidden columns back from other forms |
|
153
|
|
|
public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
|
154
|
|
|
$menu_name = FrmAppHelper::get_menu_name(); |
|
155
|
|
|
$sanitized = sanitize_title( $menu_name ); |
|
156
|
|
|
$this_page_name = 'manage' . $sanitized . '_page_formidable-entriescolumnshidden'; |
|
157
|
|
|
if ( $meta_key != $this_page_name ) { |
|
158
|
|
|
return; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
global $frm_vars; |
|
162
|
|
|
if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
163
|
|
|
return; //don't continue if there's no previous value |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
foreach ( $meta_value as $mk => $mv ) { |
|
167
|
|
|
//remove blank values |
|
168
|
|
|
if ( empty( $mv ) ) { |
|
169
|
|
|
unset( $meta_value[ $mk ] ); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
$cur_form_prefix = reset($meta_value); |
|
174
|
|
|
$cur_form_prefix = explode('_', $cur_form_prefix); |
|
175
|
|
|
$cur_form_prefix = $cur_form_prefix[0]; |
|
176
|
|
|
$save = false; |
|
177
|
|
|
|
|
178
|
|
|
foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
179
|
|
|
if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) { |
|
180
|
|
|
//don't add blank cols or process included cols |
|
181
|
|
|
continue; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
$form_prefix = explode( '_', $prev_hidden ); |
|
185
|
|
|
$form_prefix = $form_prefix[0]; |
|
186
|
|
|
if ( $form_prefix == $cur_form_prefix ) { |
|
187
|
|
|
//don't add back columns that are meant to be hidden |
|
188
|
|
|
continue; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
$meta_value[] = $prev_hidden; |
|
192
|
|
|
$save = true; |
|
193
|
|
|
unset($form_prefix); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
if ( $save ) { |
|
197
|
|
|
$user = wp_get_current_user(); |
|
198
|
|
|
update_user_option( $user->ID, $this_page_name, $meta_value, true ); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public static function save_per_page( $save, $option, $value ) { |
|
203
|
|
|
if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
204
|
|
|
$save = (int) $value; |
|
205
|
|
|
} |
|
206
|
|
|
return $save; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public static function sortable_columns() { |
|
210
|
|
|
$form_id = FrmForm::get_current_form_id(); |
|
211
|
|
|
$fields = FrmField::get_all_for_form( $form_id ); |
|
212
|
|
|
|
|
213
|
|
|
$columns = array( |
|
214
|
|
|
$form_id . '_id' => 'id', |
|
215
|
|
|
$form_id . '_created_at' => 'created_at', |
|
216
|
|
|
$form_id . '_updated_at' => 'updated_at', |
|
217
|
|
|
$form_id . '_ip' => 'ip', |
|
218
|
|
|
$form_id . '_item_key' => 'item_key', |
|
219
|
|
|
$form_id . '_is_draft' => 'is_draft', |
|
220
|
|
|
); |
|
221
|
|
|
|
|
222
|
|
|
foreach ( $fields as $field ) { |
|
223
|
|
|
if ( $field->type != 'checkbox' && ( ! isset( $field->field_options['post_field'] ) || $field->field_options['post_field'] == '' ) ) { |
|
224
|
|
|
// Can't sort on checkboxes because they are stored serialized, or post fields |
|
225
|
|
|
$columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
return $columns; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
public static function hidden_columns( $result ) { |
|
233
|
|
|
global $frm_vars; |
|
234
|
|
|
|
|
235
|
|
|
$form_id = FrmForm::get_current_form_id(); |
|
236
|
|
|
|
|
237
|
|
|
$return = false; |
|
238
|
|
|
foreach ( (array) $result as $r ) { |
|
239
|
|
|
if ( ! empty( $r ) ) { |
|
240
|
|
|
$form_prefix = explode( '_', $r ); |
|
241
|
|
|
$form_prefix = $form_prefix[0]; |
|
242
|
|
|
|
|
243
|
|
|
if ( (int) $form_prefix == (int) $form_id ) { |
|
244
|
|
|
$return = true; |
|
245
|
|
|
break; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
unset($form_prefix); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
if ( $return ) { |
|
253
|
|
|
return $result; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
$i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
257
|
|
|
$max_columns = 8; |
|
258
|
|
|
if ( $i <= $max_columns ) { |
|
259
|
|
|
return $result; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
global $frm_vars; |
|
263
|
|
|
if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
264
|
|
|
$frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
$has_custom_hidden_columns = ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && isset( $frm_vars['current_form']->options['hidden_cols'] ) && ! empty( $frm_vars['current_form']->options['hidden_cols'] ) ); |
|
268
|
|
|
if ( $has_custom_hidden_columns ) { |
|
269
|
|
|
$result = $frm_vars['current_form']->options['hidden_cols']; |
|
270
|
|
|
} else { |
|
271
|
|
|
$cols = $frm_vars['cols']; |
|
272
|
|
|
$cols = array_reverse($cols, true); |
|
273
|
|
|
|
|
274
|
|
|
if ( $form_id ) { |
|
275
|
|
|
$result[] = $form_id . '_id'; |
|
276
|
|
|
$i--; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
$result[] = $form_id . '_item_key'; |
|
280
|
|
|
$i--; |
|
281
|
|
|
|
|
282
|
|
|
foreach ( $cols as $col_key => $col ) { |
|
283
|
|
|
if ( $i > $max_columns ) { |
|
284
|
|
|
$result[] = $col_key; |
|
285
|
|
|
} |
|
286
|
|
|
//remove some columns by default |
|
287
|
|
|
$i--; |
|
288
|
|
|
unset($col_key, $col); |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
return $result; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
public static function display_list( $message = '', $errors = array() ) { |
|
296
|
|
|
global $wpdb, $frm_vars; |
|
297
|
|
|
|
|
298
|
|
|
$form = FrmForm::maybe_get_current_form(); |
|
299
|
|
|
$params = FrmForm::get_admin_params( $form ); |
|
300
|
|
|
|
|
301
|
|
|
if ( $form ) { |
|
302
|
|
|
$params['form'] = $form->id; |
|
303
|
|
|
$frm_vars['current_form'] = $form; |
|
304
|
|
|
|
|
305
|
|
|
self::get_delete_form_time( $form, $errors ); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
$table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
309
|
|
|
|
|
310
|
|
|
$wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
311
|
|
|
|
|
312
|
|
|
$pagenum = $wp_list_table->get_pagenum(); |
|
313
|
|
|
|
|
314
|
|
|
$wp_list_table->prepare_items(); |
|
315
|
|
|
|
|
316
|
|
|
$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
317
|
|
|
if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
318
|
|
|
$url = add_query_arg( 'paged', $total_pages ); |
|
319
|
|
|
if ( headers_sent() ) { |
|
320
|
|
|
echo FrmAppHelper::js_redirect($url); |
|
|
|
|
|
|
321
|
|
|
} else { |
|
322
|
|
|
wp_redirect( esc_url_raw( $url ) ); |
|
323
|
|
|
} |
|
324
|
|
|
die(); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
if ( empty($message) && isset($_GET['import-message']) ) { |
|
328
|
|
|
$message = __( 'Your import is complete', 'formidable' ); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' ); |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
private static function get_delete_form_time( $form, &$errors ) { |
|
335
|
|
|
if ( 'trash' == $form->status ) { |
|
336
|
|
|
$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
337
|
|
|
$time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); |
|
338
|
|
|
$errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/* Back End CRUD */ |
|
343
|
|
|
public static function show( $id = 0 ) { |
|
344
|
|
|
FrmAppHelper::permission_check('frm_view_entries'); |
|
345
|
|
|
|
|
346
|
|
|
if ( ! $id ) { |
|
347
|
|
|
$id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
|
348
|
|
|
|
|
349
|
|
|
if ( ! $id ) { |
|
350
|
|
|
$id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' ); |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
$entry = FrmEntry::getOne($id, true); |
|
355
|
|
|
if ( ! $entry ) { |
|
356
|
|
|
echo '<div id="form_show_entry_page" class="wrap">' . |
|
357
|
|
|
__( 'You are trying to view an entry that does not exist.', 'formidable' ) . |
|
|
|
|
|
|
358
|
|
|
'</div>'; |
|
359
|
|
|
return; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
$data = maybe_unserialize($entry->description); |
|
363
|
|
|
if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
|
364
|
|
|
$data = array( 'referrer' => $data ); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
$fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
|
368
|
|
|
$to_emails = array(); |
|
369
|
|
|
|
|
370
|
|
|
include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
public static function destroy() { |
|
374
|
|
|
FrmAppHelper::permission_check('frm_delete_entries'); |
|
375
|
|
|
|
|
376
|
|
|
$params = FrmForm::get_admin_params(); |
|
377
|
|
|
|
|
378
|
|
|
if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
379
|
|
|
//unlink entry from post |
|
380
|
|
|
global $wpdb; |
|
381
|
|
|
$wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
$message = ''; |
|
385
|
|
|
if ( FrmEntry::destroy( $params['id'] ) ) { |
|
386
|
|
|
$message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
self::display_list( $message ); |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
public static function destroy_all() { |
|
393
|
|
|
if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
394
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
395
|
|
|
wp_die( $frm_settings->admin_permission ); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
global $wpdb; |
|
399
|
|
|
$params = FrmForm::get_admin_params(); |
|
400
|
|
|
$message = ''; |
|
401
|
|
|
$errors = array(); |
|
402
|
|
|
$form_id = (int) $params['form']; |
|
403
|
|
|
|
|
404
|
|
|
if ( $form_id ) { |
|
405
|
|
|
$entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
406
|
|
|
$action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 ); |
|
407
|
|
|
|
|
408
|
|
|
if ( $action ) { |
|
409
|
|
|
// this action takes a while, so only trigger it if there are posts to delete |
|
410
|
|
|
foreach ( $entry_ids as $entry_id ) { |
|
|
|
|
|
|
411
|
|
|
do_action( 'frm_before_destroy_entry', $entry_id ); |
|
412
|
|
|
unset( $entry_id ); |
|
413
|
|
|
} |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
$wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) ); |
|
417
|
|
|
$results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
418
|
|
|
if ( $results ) { |
|
419
|
|
|
FrmEntry::clear_cache(); |
|
420
|
|
|
$message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
421
|
|
|
} |
|
422
|
|
|
} else { |
|
423
|
|
|
$errors = __( 'No entries were specified', 'formidable' ); |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
self::display_list( $message, $errors ); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
430
|
|
|
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
431
|
|
|
return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
public static function get_form( $filename, $form, $title, $description ) { |
|
435
|
|
|
_deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
436
|
|
|
return FrmFormsController::get_form( $form, $title, $description ); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
public static function process_entry( $errors = '', $ajax = false ) { |
|
440
|
|
|
$form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
|
441
|
|
|
if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { |
|
442
|
|
|
return; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
global $frm_vars; |
|
446
|
|
|
|
|
447
|
|
|
$form = FrmForm::getOne( $form_id ); |
|
448
|
|
|
if ( ! $form ) { |
|
449
|
|
|
return; |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
$params = FrmForm::get_params( $form ); |
|
453
|
|
|
|
|
454
|
|
|
if ( ! isset( $frm_vars['form_params'] ) ) { |
|
455
|
|
|
$frm_vars['form_params'] = array(); |
|
456
|
|
|
} |
|
457
|
|
|
$frm_vars['form_params'][ $form->id ] = $params; |
|
458
|
|
|
|
|
459
|
|
|
if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
|
460
|
|
|
return; |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
if ( $errors == '' && ! $ajax ) { |
|
464
|
|
|
$errors = FrmEntryValidate::validate( $_POST ); |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
/** |
|
468
|
|
|
* Use this filter to add trigger actions and add errors after |
|
469
|
|
|
* all other errors have been processed |
|
470
|
|
|
* @since 2.0.6 |
|
471
|
|
|
*/ |
|
472
|
|
|
$errors = apply_filters( 'frm_entries_before_create', $errors, $form ); |
|
473
|
|
|
|
|
474
|
|
|
$frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
|
475
|
|
|
|
|
476
|
|
|
if ( empty( $errors ) ) { |
|
477
|
|
|
$_POST['frm_skip_cookie'] = 1; |
|
478
|
|
|
if ( $params['action'] == 'create' ) { |
|
479
|
|
|
if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
|
480
|
|
|
$frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
485
|
|
|
unset( $_POST['frm_skip_cookie'] ); |
|
486
|
|
|
} |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
490
|
|
|
self::_delete_entry( $atts['id'], $form ); |
|
491
|
|
|
return $url; |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
//Delete entry if not redirected |
|
495
|
|
|
public static function delete_entry_after_save( $atts ) { |
|
496
|
|
|
self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
private static function _delete_entry( $entry_id, $form ) { |
|
500
|
|
|
if ( ! $form ) { |
|
501
|
|
|
return; |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
$form->options = maybe_unserialize( $form->options ); |
|
505
|
|
|
if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
506
|
|
|
FrmEntry::destroy( $entry_id ); |
|
507
|
|
|
} |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
/** |
|
511
|
|
|
* @param $atts |
|
512
|
|
|
* |
|
513
|
|
|
* @return array|string |
|
514
|
|
|
*/ |
|
515
|
|
|
public static function show_entry_shortcode( $atts ) { |
|
516
|
|
|
$defaults = array( |
|
517
|
|
|
'id' => false, |
|
518
|
|
|
'entry' => false, |
|
519
|
|
|
'fields' => false, |
|
520
|
|
|
'plain_text' => false, |
|
521
|
|
|
'user_info' => false, |
|
522
|
|
|
'include_blank' => false, |
|
523
|
|
|
'default_email' => false, |
|
524
|
|
|
'form_id' => false, |
|
525
|
|
|
'format' => 'text', |
|
526
|
|
|
'direction' => 'ltr', |
|
527
|
|
|
'font_size' => '', |
|
528
|
|
|
'text_color' => '', |
|
529
|
|
|
'border_width' => '', |
|
530
|
|
|
'border_color' => '', |
|
531
|
|
|
'bg_color' => '', |
|
532
|
|
|
'alt_bg_color' => '', |
|
533
|
|
|
'clickable' => false, |
|
534
|
|
|
'exclude_fields' => '', |
|
535
|
|
|
'include_fields' => '', |
|
536
|
|
|
'include_extras' => '', |
|
537
|
|
|
'inline_style' => 1, |
|
538
|
|
|
); |
|
539
|
|
|
|
|
540
|
|
|
$atts = shortcode_atts( $defaults, $atts ); |
|
541
|
|
|
|
|
542
|
|
|
if ( $atts['default_email'] ) { |
|
543
|
|
|
|
|
544
|
|
|
$entry_shortcode_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $atts['format'] ); |
|
545
|
|
|
$formatted_entry = $entry_shortcode_formatter->content(); |
|
546
|
|
|
|
|
547
|
|
|
} else { |
|
548
|
|
|
|
|
549
|
|
|
$entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts ); |
|
550
|
|
|
$formatted_entry = $entry_formatter->get_formatted_entry_values(); |
|
551
|
|
|
|
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
return $formatted_entry; |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
public static function get_params( $form = null ) { |
|
558
|
|
|
_deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_params' ); |
|
559
|
|
|
return FrmForm::get_params( $form ); |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
public static function entry_sidebar( $entry ) { |
|
563
|
|
|
$data = maybe_unserialize($entry->description); |
|
564
|
|
|
$date_format = get_option('date_format'); |
|
565
|
|
|
$time_format = get_option('time_format'); |
|
566
|
|
|
if ( isset( $data['browser'] ) ) { |
|
567
|
|
|
$browser = FrmEntriesHelper::get_browser( $data['browser'] ); |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
|
include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
/*********************************************************************** |
|
574
|
|
|
* Deprecated Functions |
|
575
|
|
|
************************************************************************/ |
|
576
|
|
|
|
|
577
|
|
|
/** |
|
578
|
|
|
* @deprecated 2.02.14 |
|
579
|
|
|
* |
|
580
|
|
|
* @return mixed |
|
581
|
|
|
*/ |
|
582
|
|
|
public static function filter_email_value( $value ) { |
|
583
|
|
|
_deprecated_function( __FUNCTION__, '2.02.14', 'FrmProEntriesController::filter_value_in_single_entry_table' ); |
|
584
|
|
|
return $value; |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
/** |
|
588
|
|
|
* @deprecated 2.02.14 |
|
589
|
|
|
* |
|
590
|
|
|
* @return mixed |
|
591
|
|
|
*/ |
|
592
|
|
|
public static function filter_display_value( $value ) { |
|
593
|
|
|
_deprecated_function( __FUNCTION__, '2.02.14', 'FrmProEntriesController::filter_display_value' ); |
|
594
|
|
|
return $value; |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
/** |
|
598
|
|
|
* @deprecated 2.03.04 |
|
599
|
|
|
* |
|
600
|
|
|
* @return mixed |
|
601
|
|
|
*/ |
|
602
|
|
|
public static function filter_shortcode_value( $value ) { |
|
603
|
|
|
_deprecated_function( __FUNCTION__, '2.03.04', 'custom code' ); |
|
604
|
|
|
return $value; |
|
605
|
|
|
} |
|
606
|
|
|
} |
|
607
|
|
|
|