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 );
}
GFForms::admin_footer();
}
/**
* 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( '', $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' );
$display_mode_title = esc_html__( 'Display Mode', 'gravityforms' );
$display_modes_markup = join( "\n", self::get_display_modes_markup() );
$button = get_submit_button( esc_html__( 'Apply', 'gravityforms' ), 'button button-primary', 'screen-options-apply', false );
$return .= "
{$display_modes_markup}
$button
";
return $return;
}
/**
* Returns the markup for the display modes screen option.
*
* @since 2.5
*
* @return array $display_modes_arr The markup for the display modes option.
*/
private static function get_display_modes_markup() {
$display_modes = array(
array(
'id' => 'standard',
'label' => esc_html__( 'Standard', 'gravityforms' ),
),
array(
'id' => 'full_width',
'label' => esc_html__( 'Full Width', 'gravityforms' ),
),
);
$display_modes_arr = array();
$option_values = self::get_screen_options_values();
// If the display mode is not set then use 'standard'.
$selected_display_mode = 'standard';
foreach ( $display_modes as $display_mode ) {
$id = esc_attr( $display_mode['id'] );
$label = esc_attr( $display_mode['label'] );
if ( $option_values['display_mode'] === $display_mode['id'] ) {
$selected_display_mode = $option_values['display_mode'];
}
$checked = checked( $display_mode['id'], $selected_display_mode, false );
$display_modes_arr[] = sprintf( '', $id, $id, $id, $checked, $label );
}
return $display_modes_arr;
}
/**
* 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',
'display_mode' => 'standard',
);
$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 ) );
wp_print_styles( array( 'thickbox', 'gform_settings' ) );
GFForms::admin_header();
$table->prepare_items();
$table->output_scripts();
?>
'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 ( ( $spam_count > 0 ) || 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 = '' . esc_html( $filter_link['label'] ) .
' (' . absint( rgar( $filter_link, 'count' ) ) . ')';
$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 );
$search_criteria = $this->get_search_criteria();
$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;
$sort_field = $this->get_orderby();
if ( ! empty( $sort_field ) ) {
$sort_direction = $this->get_order();
$sort_field_meta = GFAPI::get_field( $form_id, $sort_field );
if ( $sort_field_meta instanceof GF_Field ) {
$numeric_fields = array( 'number', 'total', 'calculation', 'price', 'quantity', 'shipping', 'singleshipping', 'product', 'singleproduct' );
$is_numeric = in_array( $sort_field_meta->get_input_type(), $numeric_fields );
} else {
$entry_meta = GFFormsModel::get_entry_meta( $form_id );
$is_numeric = rgars( $entry_meta, $sort_field . '/is_numeric' );
}
$sorting = array( 'key' => $sort_field, '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' => '',
);
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' );
}
$column_selector_url = add_query_arg( array(
'gf_page' => 'select_columns',
'id' => absint( $form_id ),
'TB_iframe' => 'true',
'height' => 465,
'width' => 620,
), admin_url() );
$table_columns['column_selector'] = '';
/**
* 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'];
?>
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 '
';
if ( $this->filter !== 'trash' ) {
$action = GFCommon::current_user_can_any( 'gravityforms_edit_entries' ) ? "ToggleStar(this, '" . esc_js( $entry['id'] ) . "','" . esc_js( $this->filter ) . "');" : 'return false;';
?>
';
}
/**
* 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 = ".../" . esc_attr( GFCommon::truncate_url( $entry['source_url'] ) ) . '';
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 'payment_status' :
$value = GFCommon::get_entry_payment_status_text( $entry['payment_status'] );
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 if ( ! is_array( $value ) ) {
$value = esc_html( $value );
}
}
$value = apply_filters( 'gform_entries_field_value', $value, $form_id, $field_id, $entry );
if ( is_array( $value ) ) {
$value = esc_html( implode( ', ', $value ) );
}
$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 );
$aria_label = sprintf( esc_html__( 'View entry number %s', 'gravityforms' ), $entry['id'] );
$column_value = '' . $value . '';
/**
* Used to inject markup and replace the value of any primary/first column in the entry list grid.
*
* @param string $column_value The column value to be filtered. Contains the field value wrapped in a link/a tag.
* @param int $form_id The ID of the current form.
* @param int|string $field_id The ID of the field or the name of an entry column (i.e. date_created).
* @param array $entry The Entry object.
* @param string $query_string The current page's query string.
* @param string $edit_url The url to the entry edit page.
* @param string $value The value of the field.
*/
$column_value = apply_filters( 'gform_entries_primary_column_filter', $column_value, $form_id, $field_id, $entry, $query_string, $edit_url, $value );
// Warning ignored because output is expected to be escaped higher up in the chain.
// phpcs:ignore
echo $column_value;
} 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
*/
function get_detail_query_string( $entry ) {
$form_id = $this->get_form_id();
$search = stripslashes( rgget( 's' ) );
$search_field_id = rgget( 'field_id' );
$search_operator = rgget( 'operator' );
$order = $this->get_order();
$orderby = $this->get_orderby();
$search_qs = empty( $search ) ? '' : '&s=' . esc_attr( urlencode( $search ) );
$orderby_qs = empty( $orderby ) ? '' : '&orderby=' . esc_attr( $orderby );
$order_qs = empty( $order ) ? '' : '&order=' . esc_attr( $order );
$filter_qs = '&filter=' . esc_attr( $this->filter );
$page_size = $this->get_pagination_arg( 'per_page' );
$page_num = $this->get_pagenum();
$page_index = $page_num - 1;
$position = ( $page_size * $page_index ) + $this->row_index;
$edit_url = 'page=gf_entries&view=entry&id=' . absint( $form_id ) . '&lid=' . esc_attr( $entry['id'] ) . $search_qs . $orderby_qs . $order_qs . $filter_qs . '&paged=' . $page_num .'&pos=' . $position .'&field_id=' . esc_attr( $search_field_id ) . '&operator=' . esc_attr( $search_operator );
return $edit_url;
}
/**
* Returns the entry detail url.
*
* @param $entry
*
* @return string|void
*/
function get_detail_url( $entry ) {
$query_string = $this->get_detail_query_string( $entry );
$url = admin_url( 'admin.php?' . $query_string );
return $url;
}
/**
* Displays a single row.
*
* @param array $entry
*/
public function single_row( $entry ) {
$class = 'entry_row';
$class .= $entry['is_read'] ? '' : ' entry_unread';
$class .= $this->locking_info->list_row_class( $entry['id'], false );
$class .= $entry['is_starred'] ? ' entry_starred' : '';
$class .= in_array( $this->filter, array( 'trash', 'spam' ) ) ? ' entry_spam_trash' : '';
echo sprintf( '