forked from wp-premium/gravityforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_list.php
2121 lines (1722 loc) · 69.7 KB
/
entry_list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class GFEntryList {
public static function all_entries_page() {
if ( ! GFCommon::ensure_wp_version() ) {
return;
}
$forms = RGFormsModel::get_forms( null, 'title' );
$form_id = RGForms::get( 'id' );
// Restore entry.
if ( rgget( 'restore' ) ) {
// Verify nonce.
check_admin_referer( 'gf_restore_entry' );
// Restore entry.
GFFormsModel::update_entry_property( rgget( 'restore' ), 'status', 'active' );
$admin_url = admin_url( 'admin.php?page=gf_entries&view=entries&id=' . absint( $form_id ) . '&restored=' . absint( rgget( 'restore' ) ) );
wp_safe_redirect( $admin_url );
exit();
}
// Display restored entry message.
if ( rgget( 'restored' ) ) {
// Add message.
GFCommon::add_dismissible_message(
sprintf(
esc_html__( '%s restored from the Trash.', 'gravityforms' ),
esc_html__( '1 entry', 'gravityforms' )
),
'success'
);
}
// Display deleted entry message.
if ( rgget( 'deleted' ) ) {
// Add message.
GFCommon::add_dismissible_message(
sprintf(
esc_html__( '%s permanently deleted.', 'gravityforms' ),
esc_html__( '1 entry', 'gravityforms' )
),
'success'
);
}
// Add message for trashed entry.
if ( rgget( 'trashed_entry' ) ) {
// Prepare URL.
$restore_url = add_query_arg( 'restore', rgget( 'trashed_entry' ) );
$restore_url = remove_query_arg( 'trashed_entry', $restore_url );
$restore_url = wp_nonce_url( $restore_url, 'gf_restore_entry' );
GFCommon::add_dismissible_message(
sprintf(
esc_html__( '1 entry moved to the Trash. %sUndo%s', 'gravityforms' ),
'<a href="' . esc_url( $restore_url ) . '">',
'</a>'
),
'success'
);
}
if ( sizeof( $forms ) == 0 ) {
?>
<div style="margin:50px 0 0 10px;">
<?php echo sprintf( esc_html__( "You don't have any active forms. Let's go %screate one%s", 'gravityforms' ), '<a href="?page=gf_new_form">', '</a>' ); ?>
</div>
<?php
} else {
if ( empty( $form_id ) ) {
$form_id = $forms[0]->id;
}
/**
* Fires before the entry list content is generated.
*
* Echoed content would appear above the page title.
*
* @param int $form_id The ID of the form that the entry list is being displayed for.
*/
do_action( 'gform_pre_entry_list', $form_id );
self::leads_page( $form_id );
/**
* Fires after the entry list content is generated.
*
* Echoed content would appear after the bulk actions/paging links below the entry list table.
*
* @param int $form_id The ID of the form that the entry list is being displayed for.
*/
do_action( 'gform_post_entry_list', $form_id );
}
}
/**
* Returns the default filter for the form ID specified in the URL. If no form ID is specified then the first form is used.
* @since 2.0
* @return string
*/
public static function get_default_filter() {
$forms = GFFormsModel::get_forms( null, 'title' );
$form_id = rgget( 'id' );
if ( sizeof( $forms ) == 0 ) {
return '';
} else {
if ( empty( $form_id ) ) {
$form_id = $forms[0]->id;
}
}
$form = GFAPI::get_form( $form_id );
$filters = self::get_filter_links( $form, false );
$option_values = self::get_screen_options_values();
// If the filter is not available for the form then use 'all'
$selected_filter = 'all';
foreach ( $filters as $filter ) {
if ( $option_values['default_filter'] == $filter['id'] ) {
$selected_filter = $option_values['default_filter'];
break;
}
}
return $selected_filter;
}
/**
* Returns the markup for the screen options.
*
* @since 2.0
*
* @param $status
* @param $args
*
* @return string
*/
public static function get_screen_options_markup( $status, $args ) {
$return = $status;
if ( ! GFForms::get_page() == 'entry_list' ) {
return $return;
}
$screen_options = self::get_screen_options_values();
$per_page = $screen_options['per_page'];
$forms = GFFormsModel::get_forms( null, 'title' );
$form_id = rgget( 'id' );
if ( sizeof( $forms ) == 0 ) {
return '';
} else {
if ( empty( $form_id ) ) {
$form_id = $forms[0]->id;
}
}
$form = GFAPI::get_form( $form_id );
$filters = self::get_filter_links( $form, false );
$option_values = self::get_screen_options_values();
// If the filter is not available for the form then use 'all'
$selected_filter = 'all';
foreach ( $filters as $filter ) {
if ( $option_values['default_filter'] == $filter['id'] ) {
$selected_filter = $option_values['default_filter'];
break;
}
}
$radios_arr = array();
foreach ( $filters as $filter ) {
$id = esc_attr( $filter['id'] );
$label = esc_attr( $filter['label'] );
$checked = checked( $filter['id'], $selected_filter, false );
$radios_arr[] = sprintf( '<input type="radio" name="gform_default_filter" value="%s" id="gform_default_filter_%s" %s /><label for="gform_default_filter_%s">%s</label>', $id, $id, $checked, $id, $label );
}
$radios_str = join( "\n", $radios_arr );
$filter_title = esc_html__( 'Default Filter', 'gravityforms' );
$pagination_title = esc_html__( 'Pagination', 'gravityforms' );
$entries_label = esc_html__( 'Number of entries per page:', 'gravityforms' );
$button = get_submit_button( esc_html__( 'Apply', 'gravityforms' ), 'button button-primary', 'screen-options-apply', false );
$return .= "
<fieldset class='screen-options'>
<legend>{$filter_title}</legend>
<div>
{$radios_str}
</div>
</fieldset>
<fieldset class='screen-options'>
<h5>{$pagination_title}</h5>
<label for='gform_per_page%s'>{$entries_label}</label>
<input type='number' step='1' min='1' max='100' class='screen-per-page' name='gform_per_page'
id='gform_per_page' maxlength='3' value='{$per_page}' />
<input type='hidden' name='wp_screen_options[option]' value='gform_entries_screen_options' />
<input type='hidden' name='wp_screen_options[value]' value='yes' />
</fieldset>
<p class='submit'>
$button
</p>";
return $return;
}
/**
* Returns the values for the user-specific screen options. If not saved by the current user, the default values are returned.
*
* @since 2.0
* @return array
*/
public static function get_screen_options_values() {
$default_values = array(
'per_page' => 20,
'default_filter' => 'all',
);
$option_values = get_user_option( 'gform_entries_screen_options' );
if ( empty( $option_values ) || ! is_array( $option_values ) ) {
$option_values = array();
}
$option_values = array_merge( $default_values, $option_values );
return $option_values;
}
public static function leads_page( $form_id ) {
global $wpdb;
//quit if version of wp is not supported
if ( ! GFCommon::ensure_wp_version() ) {
return;
}
$form = GFFormsModel::get_form_meta( $form_id );
$table = new GF_Entry_List_Table( array( 'form_id' => $form_id, 'form' => $form ) );
$table->prepare_items();
$table->output_styles();
$table->output_scripts();
wp_print_styles( array( 'thickbox' ) );
echo GFCommon::get_remote_message();
?>
<div class="wrap <?php echo GFCommon::get_browser_class() ?>">
<?php
GFCommon::form_page_title( $form );
GFCommon::display_admin_message();
GFCommon::display_dismissible_message();
?>
<?php
GFForms::top_toolbar();
?>
<div id="entry_search_container">
<div id="entry_filters" style=""></div>
<a style="" class="button" id="entry_search_button"
href="javascript:Search('<?php echo esc_js( $table->get_orderby() ); ?>', '<?php echo esc_js( $table->get_order() ) ?>', <?php echo absint( $form_id ); ?>, jQuery('.gform-filter-value').val(), '<?php echo esc_js( $table->get_filter() ) ?>', jQuery('.gform-filter-field').val(), jQuery('.gform-filter-operator').val());"><?php esc_html_e( 'Search', 'gravityforms' ) ?></a>
</div>
<form id="entry_list_form" method="post">
<?php
$table->views();
$table->display();
?>
</form>
</div>
<?php
}
public static function get_icon_url( $path ) {
$info = pathinfo( $path );
switch ( strtolower( rgar( $info, 'extension' ) ) ) {
case 'css' :
$file_name = 'icon_css.gif';
break;
case 'doc' :
$file_name = 'icon_doc.gif';
break;
case 'fla' :
$file_name = 'icon_fla.gif';
break;
case 'html' :
case 'htm' :
case 'shtml' :
$file_name = 'icon_html.gif';
break;
case 'js' :
$file_name = 'icon_js.gif';
break;
case 'log' :
$file_name = 'icon_log.gif';
break;
case 'mov' :
$file_name = 'icon_mov.gif';
break;
case 'pdf' :
$file_name = 'icon_pdf.gif';
break;
case 'php' :
$file_name = 'icon_php.gif';
break;
case 'ppt' :
$file_name = 'icon_ppt.gif';
break;
case 'psd' :
$file_name = 'icon_psd.gif';
break;
case 'sql' :
$file_name = 'icon_sql.gif';
break;
case 'swf' :
$file_name = 'icon_swf.gif';
break;
case 'txt' :
$file_name = 'icon_txt.gif';
break;
case 'xls' :
$file_name = 'icon_xls.gif';
break;
case 'xml' :
$file_name = 'icon_xml.gif';
break;
case 'zip' :
$file_name = 'icon_zip.gif';
break;
case 'gif' :
case 'jpg' :
case 'jpeg':
case 'png' :
case 'bmp' :
case 'tif' :
case 'eps' :
$file_name = 'icon_image.gif';
break;
case 'mp3' :
case 'wav' :
case 'wma' :
$file_name = 'icon_audio.gif';
break;
case 'mp4' :
case 'avi' :
case 'wmv' :
case 'flv' :
$file_name = 'icon_video.gif';
break;
default:
$file_name = 'icon_generic.gif';
break;
}
return GFCommon::get_base_url() . "/images/doctypes/$file_name";
}
public static function get_filter_links( $form, $include_counts = true ) {
$form_id = absint( $form['id'] );
$summary = $include_counts ? GFFormsModel::get_form_counts( $form_id ) : array();
$active_entry_count = rgar( $summary, 'total' );
$unread_count = rgar( $summary, 'unread' );
$starred_count = rgar( $summary, 'starred' );
$spam_count = rgar( $summary,'spam' );
$trash_count = rgar( $summary,'trash' );
$filter_links = array(
array(
'id' => 'all',
'field_filters' => array(),
'count' => $active_entry_count,
'label' => esc_html_x( 'All', 'Entry List', 'gravityforms' ),
),
array(
'id' => 'unread',
'field_filters' => array(
array( 'key' => 'is_read', 'value' => false ),
),
'count' => $unread_count,
'label' => esc_html_x( 'Unread', 'Entry List', 'gravityforms' ),
),
array(
'id' => 'star',
'field_filters' => array(
array( 'key' => 'is_starred', 'value' => true ),
),
'count' => $starred_count,
'label' => esc_html_x( 'Starred', 'Entry List', 'gravityforms' ),
),
);
if ( GFCommon::spam_enabled( $form_id ) ) {
$filter_links[] = array(
'id' => 'spam',
'field_filters' => array(),
'count' => $spam_count,
'label' => esc_html__( 'Spam', 'gravityforms' ),
);
}
$filter_links[] = array(
'id' => 'trash',
'field_filters' => array(),
'count' => $trash_count,
'label' => esc_html__( 'Trash', 'gravityforms' ),
);
/**
* Allow the row of filter links to be modified.
*
* Array elements:
* selected - bool
* filter - string
* label - string
*
* @param array $filter_links The filter links.
*
*/
$filter_links = apply_filters( 'gform_filter_links_entry_list', $filter_links, $form, $include_counts );
return $filter_links;
}
public static function all_leads_page() {
self::all_entries_page();
}
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
/**
* Class GF_Entry_List_Table
*
* @since 2.0
*/
final class GF_Entry_List_Table extends WP_List_Table {
/**
* The current filter e.g. trash, spam, unread
*
* @var string
*/
public $filter = '';
/**
* The name of the primary column. The primary column will not get collapsed on narrower displays.
*
* @var null|string
*/
public $primary_column_name = null;
/**
* The locking mechanism for the entry list.
*
* @var GFEntryLocking
*/
public $locking_info;
/**
* Tracks the cuurent row during output.
*
* @var int
*/
public $row_index = 0;
/**
* The Form array.
*
* @var array
*/
private $_form;
/**
* The columns to display on the entry list for this form.
* @var array
*/
private $_grid_columns = null;
/**
* GF_Entry_List constructor.
*
* @param array $args
*/
public function __construct( $args = array() ) {
$this->_form = isset( $args['form'] ) ? $args['form'] : null;
if ( ! isset( $this->_form ) ) {
$form_id = isset( $args['form_id'] ) ? $args['form_id'] : absint( rgget( 'id' ) );
$this->_form = RGFormsModel::get_form_meta( $form_id );
}
$args = wp_parse_args( $args, array(
'plural' => 'gf_entries',
'singular' => 'gf_entry',
'ajax' => false,
'screen' => null,
'filter' => sanitize_text_field( rgget( 'filter' ) ),
) );
parent::__construct( $args );
$this->filter = $args['filter'];
$this->set_columns();
$this->locking_info = new GFEntryLocking();
}
/**
* Set the hidden, sortable and primary columns.
*/
public function set_columns() {
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$primary = $this->get_primary_column_name();
$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
}
/**
* Returns the curent filter.
*
* @return string
*/
public function get_filter() {
return $this->filter;
}
/**
* Returns the current form array.
*
* @return array
*/
public function get_form() {
return $this->_form;
}
/**
* Returns the current form ID.
*
* @return int
*/
public function get_form_id() {
$form_id = isset( $this->_form ) ? $this->_form['id'] : rgget( 'id' );
return absint( $form_id );
}
/**
* Returns an associative array of views.
*
* @return array
*/
function get_views() {
$views = array();
$form_id = $this->get_form_id();
$filter_links = $this->get_filter_links();
$filter = $this->filter;
foreach ( $filter_links as $filter_link_index => $filter_link ) {
$filter_arg = '&filter=';
if ( $filter_link['id'] !== 'all' ) {
$filter_arg .= $filter_link['id'];
}
if ( $filter == '' ) {
$selected = $filter_link['id'] == 'all' ? 'current' : '';
} else {
$selected = ( $filter == $filter_link['id'] ) ? 'current' : '';
}
$link = '<a class="' . $selected . '" href="?page=gf_entries&view=entries&id=' . $form_id . esc_attr( $filter_arg ) . '">' . esc_html( $filter_link['label'] ) .
'<span class="count"> (<span id="' . esc_attr( $filter_link['id'] ) . '_count">' . absint( rgar( $filter_link, 'count' ) ) . '</span>)</span></a>';
$views[ $filter_link['id'] ] = $link;
}
return $views;
}
/**
* Returns the array of filter links.
*
* @param bool $include_counts
*
* @return array|mixed|void
*/
public function get_filter_links( $include_counts = true ) {
$form = $this->get_form();
return GFEntryList::get_filter_links( $form, $include_counts );
}
/**
* Gets the ordering for the entry list table.
*
* Also formats the query string to uppercase. If none is present, sets it to ascending.
*
* @since 2.0.3.6
* @access public
*
* @return string The ordering to be used.
*/
public function get_order() {
return empty( $_GET['order'] ) ? 'ASC' : strtoupper( $_GET['order'] );
}
/**
* Gets the column that list is ordered by.
*
* If none is set, defaults to 0 (the first column)
*
* @since 2.0.3.6
* @access public
*
* @return int The column to be used.
*/
public function get_orderby() {
return empty( $_GET['orderby'] ) ? 0 : $_GET['orderby'];
}
/**
* Performs the search and prepares the entries for display.
*/
function prepare_items() {
$this->process_action();
$form_id = $this->get_form_id();
$page_index = empty( $_GET['paged'] ) ? 0 : absint( $_GET['paged'] - 1 );
$form = RGFormsModel::get_form_meta( $form_id );
$search_criteria = $this->get_search_criteria();
$sort_direction = $this->get_order();
$sort_field = $this->get_orderby();
$sort_field_meta = RGFormsModel::get_field( $form, $sort_field );
$is_numeric = $sort_field_meta instanceof GF_Field ? $sort_field_meta->type == 'number' : $sort_field_meta['type'];
$screen_options = get_user_option( 'gform_entries_screen_options' );
$page_size = isset( $screen_options['per_page'] ) ? absint( $screen_options['per_page'] ) : 20;
$page_size = gf_apply_filters( array( 'gform_entry_page_size', $form_id ), $page_size, $form_id );
$first_item_index = $page_index * $page_size;
if ( ! empty( $sort_field ) ) {
$sorting = array( 'key' => $_GET['orderby'], 'direction' => $sort_direction, 'is_numeric' => $is_numeric );
} else {
$sorting = array();
}
$paging = array( 'offset' => $first_item_index, 'page_size' => $page_size );
$total_count = 0;
/**
* Filter the arguments that will be used to fetch entries for display on the Entry List view.
*
* @since 2.2.3.4
*
* @param array $args {
*
* Array of arguments that will be passed to GFAPI::get_entries() to fetch the entries to be displayed.
*
* @var int $form_id The form ID for which entries will be loaded.
* @var array $search_criteria An array of search critiera that will be used to filter entries.
* @var array $sorting An array containing properties that specify how the entries will be sorted.
* @var array $paging An array containing properties that specify how the entries will be paginated.
* }
*/
$args = gf_apply_filters( array( 'gform_get_entries_args_entry_list', $form_id ), compact( 'form_id', 'search_criteria', 'sorting', 'paging' ) );
$entries = GFAPI::get_entries( $args['form_id'], $args['search_criteria'], $args['sorting'], $args['paging'], $total_count );
$this->set_pagination_args( array(
'total_items' => $total_count,
'per_page' => $args['paging']['page_size'],
) );
$this->items = $entries;
}
/**
* Returns the array of search criteria.
*
* @return array
*/
function get_search_criteria() {
$search_criteria = array();
$filter_links = $this->get_filter_links( false );
foreach ( $filter_links as $filter_link ) {
if ( $this->filter == $filter_link['id'] ) {
$search_criteria['field_filters'] = $filter_link['field_filters'];
break;
}
}
$search_field_id = rgget( 'field_id' );
$search_operator = rgget( 'operator' );
$status = in_array( $this->filter, array( 'trash', 'spam' ) ) ? $this->filter : 'active';
$search_criteria['status'] = $status;
if ( isset( $_GET['field_id'] ) && $_GET['field_id'] !== '' ) {
$key = $search_field_id;
$val = stripslashes( rgget( 's' ) );
$strpos_row_key = strpos( $search_field_id, '|' );
if ( $strpos_row_key !== false ) { //multi-row likert
$key_array = explode( '|', $search_field_id );
$key = $key_array[0];
$val = $key_array[1] . ':' . $val;
}
if ( 'entry_id' == $key ) {
$key = 'id';
}
$filter_operator = empty( $search_operator ) ? 'is' : $search_operator;
$form = $this->get_form();
$field = GFFormsModel::get_field( $form, $key );
if ( $field ) {
$input_type = GFFormsModel::get_input_type( $field );
if ( $field->type == 'product' && in_array( $input_type, array( 'radio', 'select' ) ) ) {
$filter_operator = 'contains';
}
}
$search_criteria['field_filters'][] = array(
'key' => $key,
'operator' => $filter_operator,
'value' => $val,
);
}
$form_id = $this->get_form_id();
/**
* Allow the entry list search criteria to be overridden.
*
* @since 1.9.14.30
*
* @param array $search_criteria An array containing the search criteria.
* @param int $form_id The ID of the current form.
*/
$search_criteria = gf_apply_filters( array( 'gform_search_criteria_entry_list', $form_id ), $search_criteria, $form_id );
return $search_criteria;
}
/**
* Returns the associative array of columns for the table.
*
* @return array
*/
function get_columns() {
$table_columns = array(
'cb' => '<input type="checkbox" />',
);
if ( ! in_array( $this->filter, array( 'trash', 'spam' ) ) ) {
$table_columns['is_starred'] = '';
}
$form_id = $this->get_form_id();
$columns = $this->get_grid_columns();
foreach ( $columns as $key => $column_info ) {
$table_columns[ 'field_id-' . $key ] = $column_info['label'];
}
if ( empty( $columns ) ) {
$table_columns['field_id-id'] = esc_html__( 'Entry Id', 'gravityforms' );
}
$table_columns['column_selector'] = '<a title="' . esc_attr__( 'click to select columns to display', 'gravityforms' ) . '" href="' . trailingslashit( site_url( null, 'admin' ) ) . '?gf_page=select_columns&id=' . absint( $form_id ) . '&TB_iframe=true&height=365&width=600" class="thickbox entries_edit_icon"><i class="fa fa-cog"></i></a>';
/**
* Allow the columns to be displayed in the entry list table to be overridden.
*
* @since 2.0.7.6
*
* @param array $table_columns The columns to be displayed in the entry list table.
* @param int $form_id The ID of the form the entries to be listed belong to.
*/
$table_columns = apply_filters( 'gform_entry_list_columns', $table_columns, $form_id );
return apply_filters( 'gform_entry_list_columns_' . $form_id, $table_columns, $form_id );
}
/**
* Returns the associative array of sortable columns for the table.
*
* @return array
*/
function get_sortable_columns() {
$columns = $this->get_grid_columns();
$table_columns = array();
foreach ( $columns as $key => $column_info ) {
$table_columns[ 'field_id-' . (string) $key ] = array( (string) $key, false );
}
return $table_columns;
}
/**
* Displays the checkbox column.
*
* @param array $entry
*/
function column_cb( $entry ) {
$entry_id = $entry['id'];
?>
<label class="screen-reader-text" for="cb-select-<?php echo esc_attr( $entry_id ); ?>"><?php _e( 'Select entry' ); ?></label>
<input type="checkbox" class="gform_list_checkbox" name="entry[]" value="<?php echo esc_attr( $entry_id ); ?>" />
<?php
$this->locking_info->lock_indicator();
}
/**
* Displays an empty cell for the column selector column.
*
* @param $entry
*
* @return string
*/
function column_column_selector( $entry ) {
return '';
}
/**
* Displays the is_starred row for the given entry.
*
* @param $entry
* @param $classes
* @param $data
* @param $primary
*/
function _column_is_starred( $entry, $classes, $data, $primary ) {
echo '<th scope="row" class="manage-column column-is_starred">';
if ( $this->filter !== 'trash' ) {
?>
<img id="star_image_<?php echo esc_attr( $entry['id'] ) ?>" src="<?php echo GFCommon::get_base_url() ?>/images/star<?php echo intval( $entry['is_starred'] ) ?>.png" onclick="ToggleStar(this, '<?php echo esc_js( $entry['id'] ); ?>','<?php echo esc_js( $this->filter ); ?>');" />
<?php
}
echo '</th>';
}
/**
* Displays the entry value.
*
* @param object $entry
* @param string $column_id
*/
function column_default( $entry, $column_id ) {
$field_id = (string) str_replace( 'field_id-', '', $column_id );
$form = $this->get_form();
$form_id = $this->get_form_id();
$field = GFFormsModel::get_field( $form, $field_id );
$columns = $this->get_grid_columns();
$value = rgar( $entry, $field_id );
if ( ! empty( $field ) && $field->type == 'post_category' ) {
$value = GFCommon::prepare_post_category_value( $value, $field, 'entry_list' );
}
// Filtering lead value
$value = apply_filters( 'gform_get_field_value', $value, $entry, $field );
switch ( $field_id ) {
case 'source_url' :
$value = "<a href='" . esc_attr( $entry['source_url'] ) . "' target='_blank' alt='" . esc_attr( $entry['source_url'] ) . "' title='" . esc_attr( $entry['source_url'] ) . "'>.../" . esc_attr( GFCommon::truncate_url( $entry['source_url'] ) ) . '</a>';
break;
case 'date_created' :
case 'payment_date' :
$value = GFCommon::format_date( $value, false );
break;
case 'payment_amount' :
$value = GFCommon::to_money( $value, $entry['currency'] );
break;
case 'created_by' :
if ( ! empty( $value ) ) {
$userdata = get_userdata( $value );
if ( ! empty( $userdata ) ) {
$value = $userdata->user_login;
}
}
break;
default:
if ( $field !== null ) {
$value = $field->get_value_entry_list( $value, $entry, $field_id, $columns, $form );
} else {
$value = esc_html( $value );
}
}
$value = apply_filters( 'gform_entries_field_value', $value, $form_id, $field_id, $entry );
$primary = $this->get_primary_column_name();
$query_string = $this->get_detail_query_string( $entry );
if ( $column_id == $primary ) {
$edit_url = $this->get_detail_url( $entry );
echo '<a title="' . esc_attr__( 'View this entry', 'gravityforms' ) . '" href="' . $edit_url .'">' . $value . '</a>';
} else {
/**
* Used to inject markup and replace the value of any non-first column in the entry list grid.
*
* @param string $value The value of the field
* @param int $form_id The ID of the current form
* @param int $field_id The ID of the field
* @param array $entry The Entry object
* @param string $query_string The current page's query string
*/
echo apply_filters( 'gform_entries_column_filter', $value, $form_id, $field_id, $entry, $query_string );
// Maintains gap between value and content from gform_entries_column which existed when using 1.9 and earlier.
echo ' ';
/**
* Fired within the entries column
*
* Used to insert additional entry details
*
* @param int $form_id The ID of the current form
* @param int $field_id The ID of the field
* @param string $value The value of the field
* @param array $entry The Entry object
* @param string $query_string The current page's query string
*/
do_action( 'gform_entries_column', $form_id, $field_id, $value, $entry, $query_string );
}
}
/**
* Returns the entry detail query string.
*
* @param $entry
*
* @return string