', '' ), 'success' ); } if ( sizeof( $forms ) == 0 ) { ?>
$button
"; 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(); ?> '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 = '' . 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 ); $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' => '', ); 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'] = ''; /** * 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 '
';
}
/**
* 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 '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 '' . $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( '' . $message . '