add_action( 'mainwp_module_cost_tracker_notes_save', array( $this, 'ajax_notes_save' ) );
MainWP_Post_Handler::instance()->add_action( 'mainwp_module_cost_tracker_delete', array( $this, 'ajax_cost_tracker_delete' ) );
MainWP_Post_Handler::instance()->add_action( 'mainwp_module_cost_tracker_lists_display_rows', array( $this, 'ajax_display_rows' ) );
MainWP_Post_Handler::instance()->add_action( 'mainwp_module_cost_tracker_filter_save_segment', array( $this, 'ajax_costs_filter_save_segment' ) );
MainWP_Post_Handler::instance()->add_action( 'mainwp_module_cost_tracker_filter_load_segments', array( $this, 'ajax_costs_filter_load_segments' ) );
MainWP_Post_Handler::instance()->add_action( 'mainwp_module_cost_tracker_filter_delete_segment', array( $this, 'ajax_costs_filter_delete_segment' ) );
}
/**
* Get columns.
*
* @param bool $filtered With per site price column.
*
* @return array Array of column names.
*/
public static function get_columns( $filtered = false ) {
$cols = array(
'cb' => true,
'cost_status' => esc_html__( 'Status', 'mainwp' ),
'icon' => esc_html__( 'Icon', 'mainwp' ),
'name' => esc_html__( 'Name', 'mainwp' ),
'per_site_price' => esc_html__( 'Price', 'mainwp' ),
'price' => esc_html__( 'Price', 'mainwp' ),
'license_type' => esc_html__( 'License', 'mainwp' ),
'product_type' => esc_html__( 'Category', 'mainwp' ),
'type' => esc_html__( 'Type', 'mainwp' ),
'last_renewal' => esc_html__( 'Last Renewal', 'mainwp' ),
'payment_method' => esc_html__( 'Payment method', 'mainwp' ),
'next_renewal' => esc_html__( 'Next Renewal', 'mainwp' ),
'sites' => esc_html__( 'Sites', 'mainwp' ),
'actions' => esc_html__( 'Action', 'mainwp' ),
);
if ( ! $filtered ) {
unset( $cols['per_site_price'] );
}
return $cols;
}
/**
* Get column defines.
*
* @return array $defines
*/
public function get_columns_defines() {
$defines = array();
$defines[] = array(
'targets' => 'no-sort',
'orderable' => false,
);
$defines[] = array(
'targets' => 'title-column',
'className' => 'task-row-working',
);
$defines[] = array(
'targets' => 'date-column',
'className' => 'mainwp-date-cell',
);
$defines[] = array(
'targets' => 'state-column',
'className' => 'mainwp-state-cell',
);
$defines[] = array(
'targets' => array( 'column-sites', 'column-payment-method', 'column-license-type', 'column-icon' ),
'className' => 'center aligned',
);
$defines[] = array(
'targets' => array( 'column-site-price', 'column-price' ),
'className' => 'right aligned',
);
$defines[] = array(
'targets' => 'check-column',
'className' => 'check-column',
);
$defines[] = array(
'targets' => 'column-actions',
'className' => 'collapsing not-selectable',
);
return $defines;
}
/**
* Instantiate Columns.
*
* @param bool $filtered With per site price column.
*
* @return array $init_cols
*/
public function get_columns_init( $filtered ) {
$cols = $this->get_columns( $filtered );
$init_cols = array();
foreach ( $cols as $key => $val ) {
$init_cols[] = array( 'data' => esc_html( $key ) );
}
return $init_cols;
}
/**
* Renders overview.
*
* When the page loads render the body content.
*/
public function render_overview_page() {
if ( ! \mainwp_current_user_can( 'dashboard', 'manage_cost_tracker' ) ) {
\mainwp_do_not_have_permissions( esc_html__( 'manage cost tracker', 'mainwp' ) );
return;
}
$sel_ids = isset( $_GET['selected_ids'] ) ? $_GET['selected_ids'] : ''; //phpcs:ignore -- ok.
$sel_ids = explode( ',', $sel_ids );
if ( ! empty( $sel_ids ) && is_array( $sel_ids ) ) {
global $current_user;
$sel_ids = MainWP_Utility::array_numeric_filter( $sel_ids );
if ( ! empty( $sel_ids ) ) {
update_user_option( $current_user->ID, 'mainwp_module_cost_tracker_onetime_filters_saved', $sel_ids );
}
}
Cost_Tracker_Admin::render_header();
?>
render_actions_bar(); ?>
render_dashboard_body(); ?>
check_security( 'mainwp_module_cost_tracker_lists_display_rows' );
$filtered_one_time_ids = get_user_option( 'mainwp_module_cost_tracker_onetime_filters_saved' );
if ( ! empty( $filtered_one_time_ids ) && is_array( $filtered_one_time_ids ) ) {
global $current_user;
delete_user_option( $current_user->ID, 'mainwp_module_cost_tracker_onetime_filters_saved' );
$filtered_one_time_ids = MainWP_Utility::array_numeric_filter( $filtered_one_time_ids );
}
$req_orderby = '';
$req_order = null;
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_REQUEST['order'] ) ) {
$order_values = MainWP_Utility::instance()->get_table_orders( $_REQUEST );
$req_orderby = $order_values['orderby'];
$req_order = $order_values['order'];
}
$filters = static::get_cost_filter_params();
$get_saved = true;
foreach ( $filters as $filter ) {
if ( isset( $_REQUEST[ $filter ] ) ) {
$get_saved = false;
break;
}
}
$filter_sites_ids = '';
$filter_client_ids = '';
$filter_prod_type_slugs = '';
$filter_cost_state = '';
$filter_dtsstart = '';
$filter_dtsstop = '';
$filter_license_type = '';
$filter_payment_method = '';
$filter_sub_renewal_type = '';
if ( $get_saved ) {
$filters_saved = get_user_option( 'mainwp_module_cost_tracker_filters_saved' );
if ( ! is_array( $filters_saved ) ) {
$filters_saved = array();
}
$filter_sites_ids = isset( $filters_saved['sites_ids'] ) ? $filters_saved['sites_ids'] : false;
$filter_client_ids = isset( $filters_saved['client_ids'] ) ? $filters_saved['client_ids'] : false;
$filter_prod_type_slugs = isset( $filters_saved['prods_types'] ) ? $filters_saved['prods_types'] : false;
$filter_cost_state = isset( $filters_saved['costs_state'] ) ? $filters_saved['costs_state'] : '';
$filter_dtsstart = isset( $filters_saved['dtsstart'] ) ? $filters_saved['dtsstart'] : '';
$filter_dtsstop = isset( $filters_saved['dtsstop'] ) ? $filters_saved['dtsstop'] : '';
$filter_license_type = isset( $filters_saved['license_types'] ) && ! empty( $filters_saved['license_types'] ) ? $filters_saved['license_types'] : '';
$filter_sub_renewal_type = isset( $filters_saved['renewal_frequency'] ) && ! empty( $filters_saved['renewal_frequency'] ) ? $filters_saved['renewal_frequency'] : '';
$filter_payment_method = isset( $filters_saved['payment_methods'] ) && ! empty( $filters_saved['payment_methods'] ) ? $filters_saved['payment_methods'] : '';
} else {
// phpcs:disable WordPress.Security.NonceVerification
$filter_sites_ids = isset( $_REQUEST['sites'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['sites'] ) ) : '';
$filter_client_ids = isset( $_REQUEST['client'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['client'] ) ) : '';
$filter_prod_type_slugs = isset( $_REQUEST['prods_types'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['prods_types'] ) ) : '';
$filter_cost_state = isset( $_REQUEST['costs_state'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['costs_state'] ) ) : '';
$filter_dtsstart = isset( $_REQUEST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['dtsstart'] ) ) : '';
$filter_dtsstop = isset( $_REQUEST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['dtsstop'] ) ) : '';
$filter_license_type = isset( $_REQUEST['license_types'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['license_types'] ) ) : '';
$filter_sub_renewal_type = isset( $_REQUEST['renewal_frequency'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['renewal_frequency'] ) ) : '';
$filter_payment_method = isset( $_REQUEST['payment_methods'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['payment_methods'] ) ) : '';
// phpcs:enable WordPress.Security.NonceVerification
}
$array_sites_ids = array();
$array_clients_ids = array();
$array_prod_types_slugs = array();
$array_status_slugs = array();
$array_license_type = array();
$array_payment_method = array();
$array_sub_renewal_type = array();
if ( ! empty( $filter_sites_ids ) ) {
$array_sites_ids = explode( ',', $filter_sites_ids ); // convert to array.
if ( in_array( 'nosites', $array_sites_ids, true ) ) {
$array_sites_ids = false;
$filter_sites_ids = '';
}
}
if ( ! empty( $filter_client_ids ) ) {
$array_clients_ids = explode( ',', $filter_client_ids ); // convert to array.
if ( in_array( 'noclients', $array_clients_ids, true ) ) {
$array_clients_ids = false;
$filter_client_ids = '';
}
}
if ( ! empty( $filter_prod_type_slugs ) ) {
$array_prod_types_slugs = explode( ',', $filter_prod_type_slugs ); // convert to array.
if ( in_array( 'nocategories', $array_prod_types_slugs, true ) ) {
$array_prod_types_slugs = false;
$filter_prod_type_slugs = '';
}
}
if ( ! empty( $filter_cost_state ) ) {
$array_status_slugs = explode( ',', $filter_cost_state ); // convert to array.
if ( in_array( 'nostatus', $array_status_slugs, true ) ) {
$array_status_slugs = false;
$filter_cost_state = '';
}
}
if ( ! empty( $filter_license_type ) ) {
$array_license_type = explode( ',', $filter_license_type ); // convert to array.
if ( in_array( 'nolicensetypes', $array_license_type, true ) ) {
$array_license_type = false;
$filter_license_type = '';
}
}
if ( ! empty( $filter_payment_method ) ) {
$array_payment_method = explode( ',', $filter_payment_method ); // convert to array.
if ( in_array( 'nopaymentmenthods', $array_payment_method, true ) ) {
$array_payment_method = false;
$filter_payment_method = '';
}
}
if ( ! empty( $filter_sub_renewal_type ) ) {
$array_sub_renewal_type = explode( ',', $filter_sub_renewal_type ); // convert to array.
if ( in_array( 'norenewalfrequency', $array_sub_renewal_type, true ) ) {
$array_sub_renewal_type = false;
$filter_sub_renewal_type = '';
}
}
global $current_user;
if ( empty( $filtered_one_time_ids ) ) {
update_user_option(
$current_user->ID,
'mainwp_module_cost_tracker_filters_saved',
array(
'sites_ids' => $filter_sites_ids,
'client_ids' => $filter_client_ids,
'prods_types' => $filter_prod_type_slugs,
'costs_state' => $filter_cost_state,
'dtsstart' => $filter_dtsstart,
'dtsstop' => $filter_dtsstop,
'license_types' => $filter_license_type,
'payment_methods' => $filter_payment_method,
'renewal_frequency' => $filter_sub_renewal_type,
)
);
}
// phpcs:enable
// phpcs:disable WordPress.Security.NonceVerification
$per_page = isset( $_REQUEST['length'] ) ? intval( $_REQUEST['length'] ) : 25;
if ( -1 === $per_page ) {
$per_page = 9999;
}
$start = isset( $_REQUEST['start'] ) ? intval( $_REQUEST['start'] ) : 0;
$search = isset( $_REQUEST['search']['value'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search']['value'] ) ) : '';
// phpcs:enable WordPress.Security.NonceVerification
$args = array(
'order' => ( 'asc' === $req_order ) ? 'asc' : 'desc',
'orderby' => $req_orderby,
'start' => $start,
'search' => $search,
'dtsstart' => ! empty( $filter_dtsstart ) ? $filter_dtsstart : false,
'dtsstop' => ! empty( $filter_dtsstop ) ? $filter_dtsstop : false,
'filter_clients' => $array_clients_ids,
'filter_sites' => $array_sites_ids,
'filter_prods_types' => $array_prod_types_slugs,
'filter_states' => $array_status_slugs,
'filter_license_type' => $array_license_type,
'filter_payment_method' => $array_payment_method,
'filter_renewal_type' => $array_sub_renewal_type,
);
$args['records_per_page'] = $per_page ? $per_page : 20;
if ( ! empty( $filtered_one_time_ids ) ) {
$items = Cost_Tracker_DB::get_instance()->get_cost_tracker_by( 'all', null, array( 'selected_ids' => $filtered_one_time_ids ) );
$this->items = ! empty( $items ) ? $items : array();
$this->total_items = ! empty( $items ) ? count( $items ) : 0;
} else {
$results = Cost_Tracker_DB_Query::instance()->query_costs( $args );
$this->items = $results['items'];
$this->total_items = $results['count'];
}
$output = $this->ajax_get_datatable_rows();
wp_send_json( $output );
}
/**
* Render the Dashboard tab
*
* Renders the dashboard tab content - Subscription table
*/
public function render_dashboard_body() {
$_orderby = 'name';
$_order = 'desc';
static::$order = $_order;
static::$orderby = $_orderby;
if ( gmdate( 'Y-m-d' ) !== get_option( 'module_cost_tracker_calc_today_next_renewal', '' ) ) {
Cost_Tracker_DB::get_instance()->update_next_renewal_today();
}
$filtered = false;
if ( isset( $_GET['selected_ids'] ) && ! empty( $_GET['selected_ids'] ) ) { //phpcs:ignore -- ok.
$filtered = true;
}
?>
'25',
10 => '10',
50 => '50',
100 => '100',
300 => '300',
);
$pages_length = $pages_length + array( $sites_per_page => $sites_per_page );
ksort( $pages_length );
if ( isset( $pages_length[-1] ) ) {
unset( $pages_length[-1] );
}
$pagelength_val = implode( ',', array_keys( $pages_length ) );
$pagelength_title = implode( ',', array_values( $pages_length ) );
$table_features = array(
'searching' => 'true',
'paging' => 'true',
'pagingType' => 'full_numbers',
'info' => 'true',
'colReorder' => '{columns:":not(.check-column):not(.column-actions)"}',
'stateSave' => 'true',
'stateDuration' => '0',
'order' => '[]',
'scrollX' => 'true',
'responsive' => 'true',
'fixedColumns' => '',
);
?>
'',
'multi_site' => '',
);
$product_types = Cost_Tracker_Admin::get_product_types();
$payment_methods = Cost_Tracker_Admin::get_payment_methods();
$show_per_site_price = false;
if ( isset( $_POST['show_per_site_price'] ) && ! empty( $_POST['show_per_site_price'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing
$show_per_site_price = true;
}
$current_time = time();
$upcoming1 = strtotime( gmdate( 'Y-m-d 00:00:00', $current_time ) );
$upcoming2 = strtotime( '+1 month', $current_time );
$all_rows = array();
$info_rows = array();
$columns = $this->get_columns( $show_per_site_price );
$product_types_icons = Cost_Tracker_Admin::get_product_type_icons();
$product_colors = Cost_Tracker_Admin::get_product_colors();
if ( $this->items ) {
foreach ( $this->items as $subscription ) {
$note = html_entity_decode( $subscription->note );
$esc_note = apply_filters( 'mainwp_escape_content', $note );
$strip_note = wp_strip_all_tags( $esc_note );
$last_renewal = $subscription ? $subscription->last_renewal : 0;
$sel_sites = ! empty( $subscription->sites ) ? json_decode( $subscription->sites, true ) : array();
$sel_groups = ! empty( $subscription->groups ) ? json_decode( $subscription->groups, true ) : array();
$sel_clients = ! empty( $subscription->clients ) ? json_decode( $subscription->clients, true ) : array();
if ( ! is_array( $sel_sites ) ) {
$sel_sites = array();
}
if ( ! is_array( $sel_groups ) ) {
$sel_groups = array();
}
if ( ! is_array( $sel_clients ) ) {
$sel_clients = array();
}
$url_manage_sites = '';
$params = array(
'sites' => $sel_sites,
'groups' => $sel_groups,
'clients' => $sel_clients,
);
$sub_sites = MainWP_DB::instance()->get_db_sites( $params );
$num_sites = count( $sub_sites );
if ( $num_sites > 0 ) {
$filter_sites = ! empty( $sel_sites ) ? '&selected_sites=' . implode( ',', $sel_sites ) : '';
$filter_groups = ! empty( $sel_groups ) ? '&g=' . implode( ',', $sel_groups ) : '';
$filter_clients = ! empty( $sel_clients ) ? '&client=' . implode( ',', $sel_clients ) : '';
$url_manage_sites = 'admin.php?page=managesites' . $filter_sites . $filter_groups . $filter_clients;
}
$rw_classes = 'cost-item cost-tracker-item-' . intval( $subscription->id ) . ' cost-tracker-type-' . ( isset( $product_types[ $subscription->product_type ] ) ? $product_types[ $subscription->product_type ] : '' );
$info_item = array(
'rowClass' => esc_html( $rw_classes ),
'cost_id' => intval( $subscription->id ),
);
$cols_data = array();
foreach ( $columns as $column_name => $column_display_name ) {
ob_start();
switch ( $column_name ) {
case 'cb':
?>
cost_status ); //phpcs:ignore -- escaped. ?>
get_product_icon_display( $subscription ); //phpcs:ignore -- escaped.?>
name ); ?>
license_type ) {
$per_site_price = $subscription->price;
} else {
$per_site_price = ( $num_sites > 0 ) ? ( $subscription->price / $num_sites ) : 0;
}
$next30_price = 0;
if ( 'active' === $subscription->cost_status && 'subscription' === $subscription->type ) {
$next_rl = $subscription->next_renewal;
if ( $next_rl <= $upcoming1 ) {
$next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming1, $subscription->renewal_type, false );
}
while ( $next_rl <= $upcoming2 ) {
if ( $next_rl > $upcoming1 && $next_rl <= $upcoming2 ) {
$next30_price += $per_site_price;
}
$next_rl = Cost_Tracker_Admin::get_next_renewal( $next_rl, $subscription->renewal_type, false );
}
}
?>
' . Cost_Tracker_Utility::cost_tracker_format_price( $subscription->price, true ) . '' : Cost_Tracker_Utility::cost_tracker_format_price( $subscription->price ); //phpcs:ignore -- ok.
break;
case 'license_type':
?>
license_type ] ) ? $license_types[ $subscription->license_type ] : ''; //phpcs:ignore -- ok. ?>
type ? 'L
' : '' . esc_html( substr( ucfirst( $subscription->renewal_type ), 0, 1 ) ) . '
'; ?>
product_type ] ) ? '' . esc_html( $product_types[ $subscription->product_type ] ) . '
' : ''; //phpcs:ignore -- ok. ?>
' . MainWP_Utility::format_date( $last_renewal ) . '': ''; //phpcs:ignore -- escaped. ?>
payment_method ] ) ? Cost_Tracker_Utility::get_payment_method_icon( $payment_methods[ $subscription->payment_method ] ) : ''; // phpcs:ignore -- ok.?>
last_renewal, $subscription->renewal_type );
Cost_Tracker_Admin::generate_next_renewal( $subscription, $next_renewal );
break;
case 'sites':
?>
' . '' . count( $sub_sites ) . '
' . '' : ' 0
'; //phpcs:ignore -- WP icon. ?>
$all_rows,
'recordsTotal' => $this->total_items,
'recordsFiltered' => $this->total_items,
'rowsInfo' => $info_rows,
);
}
/**
* Method ajax_notes_save()
*
* Post handler for save notes.
*/
public function ajax_notes_save() {
MainWP_Post_Handler::instance()->check_security( 'mainwp_module_cost_tracker_notes_save' );
//phpcs:disable WordPress.Security.NonceVerification.Missing
$sub_id = isset( $_POST['subid'] ) ? intval( $_POST['subid'] ) : 0;
$sub = Cost_Tracker_DB::get_instance()->get_cost_tracker_by( 'id', $sub_id );
if ( $sub_id && $sub ) {
$note = isset( $_POST['note'] ) ? wp_unslash( $_POST['note'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- mainwp_escape_content.
$esc_note = apply_filters( 'mainwp_escape_content', $note );
$update = array(
'id' => $sub_id,
'note' => $esc_note,
);
Cost_Tracker_DB::get_instance()->update_cost_tracker( $update );
die(
wp_json_encode(
array(
'result' => 'SUCCESS',
'esc_note_content' => $esc_note,
)
)
);
} else {
die( wp_json_encode( array( 'error' => esc_html__( 'Invalid cost tracker ID or item not found.', 'mainwp' ) ) ) );
}
//phpcs:enable
}
/**
* Method ajax_costs_filter_save_segment()
*
* Post handler for save segment.
*/
public function ajax_costs_filter_save_segment() {
MainWP_Post_Handler::instance()->check_security( 'mainwp_module_cost_tracker_filter_save_segment' );
//phpcs:disable WordPress.Security.NonceVerification.Missing
$not_filters = array(
'seg_sites' => 'nosites',
'seg_clients' => 'noclients',
'seg_prods_types' => 'nocategories',
'seg_costs_state' => 'nostatus',
'seg_license_types' => 'nolicensetypes',
'seg_payment_methods' => 'nopaymentmenthods',
'seg_renewal_frequency' => 'norenewalfrequency',
);
$fields = array(
'name',
'seg_sites',
'seg_clients',
'seg_prods_types',
'seg_costs_state',
'seg_license_types',
'seg_renewal_frequency',
'seg_payment_methods',
'seg_dtsstart',
'seg_dtsstop',
);
$save_fields = array();
foreach ( $fields as $field ) {
if ( isset( $_POST[ $field ] ) ) {
$val_seg = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );
if ( isset( $not_filters[ $field ] ) && false !== strpos( $val_seg, $not_filters[ $field ] ) ) {
$val_seg = '';
}
$save_fields[ $field ] = $val_seg;
}
}
$seg_id = ! empty( $_POST['seg_id'] ) ? sanitize_text_field( wp_unslash( $_POST['seg_id'] ) ) : time();
//phpcs:enable WordPress.Security.NonceVerification.Missing
$saved_segments = $this->set_get_cost_filter_segments();
if ( ! is_array( $saved_segments ) ) {
$saved_segments = array();
}
$saved_segments[ $seg_id ] = $save_fields;
$this->set_get_cost_filter_segments( true, $saved_segments );
die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
}
/**
* Method set_get_cost_filter_segments()
*
* @param bool $set_val Get or set value.
* @param array $saved_segments segments value.
*/
public function set_get_cost_filter_segments( $set_val = false, $saved_segments = array() ) {
global $current_user;
if ( $current_user && ! empty( $current_user->ID ) ) {
if ( $set_val ) {
update_user_option( $current_user->ID, 'mainwp_module_cost_tracker_filter_saved_segments', $saved_segments );
} else {
$values = get_user_option( 'mainwp_module_cost_tracker_filter_saved_segments', array() );
if ( ! is_array( $values ) ) {
$values = array();
}
return $values;
}
}
return array();
}
/**
* Method ajax_costs_filter_load_segments()
*
* Post handler for save segment.
*/
public function ajax_costs_filter_load_segments() {
MainWP_Post_Handler::instance()->check_security( 'mainwp_module_cost_tracker_filter_load_segments' );
$saved_segments = $this->set_get_cost_filter_segments();
$list_segs = '';
if ( is_array( $saved_segments ) && ! empty( $saved_segments ) ) {
$list_segs .= '';
}
die( wp_json_encode( array( 'result' => $list_segs ) ) ); //phpcs:ignore -- ok.
}
/**
* Method ajax_costs_filter_delete_segment()
*
* Post handler for save segment.
*/
public function ajax_costs_filter_delete_segment() {
MainWP_Post_Handler::instance()->check_security( 'mainwp_module_cost_tracker_filter_delete_segment' );
$seg_id = ! empty( $_POST['seg_id'] ) ? sanitize_text_field( wp_unslash( $_POST['seg_id'] ) ) : 0; //phpcs:ignore -- ok.
$saved_segments = $this->set_get_cost_filter_segments();
if ( ! empty( $seg_id ) && is_array( $saved_segments ) && isset( $saved_segments[ $seg_id ] ) ) {
unset( $saved_segments[ $seg_id ] );
$this->set_get_cost_filter_segments( true, $saved_segments );
die( wp_json_encode( array( 'result' =>'SUCCESS' ) ) ); //phpcs:ignore -- ok.
}
die( wp_json_encode( array( 'error' => esc_html__( 'Segment not found. Please try again.', 'mainwp' ) ) ) ); //phpcs:ignore -- ok.
}
/**
* Method ajax_cost_tracker_delete()
*
* Post handler for save notes.
*/
public function ajax_cost_tracker_delete() {
MainWP_Post_Handler::instance()->check_security( 'mainwp_module_cost_tracker_delete' );
$sub_id = isset( $_POST['sub_id'] ) ? intval( $_POST['sub_id'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( Cost_Tracker_DB::get_instance()->delete_cost_tracker( 'id', $sub_id ) ) {
die( wp_json_encode( array( 'status' => 'success' ) ) );
} else {
die( wp_json_encode( array( 'error' => esc_html__( 'Failed.', 'mainwp' ) ) ) );
}
}
/**
* Render Actions Bar
*
* Renders the actions bar on the Dashboard tab.
*/
public function render_actions_bar() {
?>
set_get_cost_filter_segments();
$filters_row_style = 'display:none';
if ( ! empty( $filter_sites_ids ) || ! empty( $filter_client_ids ) || ! empty( $filter_prod_type_slugs ) || ! empty( $filter_cost_state ) || ! empty( $filter_license_type ) || ! empty( $filter_sub_renewal_type ) || ! empty( $filter_payment_method ) || ! empty( $filter_dtsstart ) || ! empty( $filter_dtsstop ) ) {
$filters_row_style = 'display:block';
}
?>
<p>, <strong>, <em>, <br>, <hr>, <a>, <ul>, <ol>, <li>, <h1>, <h2>