esc_attr__( 'All Users', 'supportcandy' ), 'customer_with_tickets' => esc_attr__( 'Users has tickets', 'supportcandy' ), ) ); ?>

$search, 'items_per_page' => $rowperpage, 'page_no' => $page_no, 'orderby' => 'ticket_count', 'order' => 'DESC', 'meta_query' => array( 'relation' => 'AND', ), ); if ( $cust_type == 'customer_with_tickets' ) { $args['meta_query'][] = array( 'slug' => 'ticket_count', 'compare' => '>', 'val' => 0, ); } if ( $cust_type == 'all' ) { $args['meta_query'][] = array(); } $args = apply_filters( 'wpsc_get_customer_list_filters', $args, $cust_type ); $response = WPSC_Customer::find( $args ); $customers = $response['results']; $data = array(); foreach ( $customers as $customer ) { $agent = WPSC_Agent::get_by_customer( $customer ); ob_start(); ?> | | id || ( $agent->role != 1 ) ) { ?> | '' . $customer->name . '', 'email' => $customer->email, 'type' => ! is_object( $customer->user ) ? esc_attr__( 'Guest', 'supportcandy' ) : esc_attr__( 'Registered', 'supportcandy' ), 'tickets' => $customer->ticket_count, 'actions' => $actions, ); } $response = array( 'draw' => intval( $draw ), 'iTotalRecords' => $response['total_items'], 'iTotalDisplayRecords' => $response['total_items'], 'data' => $data, ); wp_send_json( $response ); } /** * View customer info * * @return void */ public static function view_customer_info() { if ( check_ajax_referer( 'wpsc_view_customer_info', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $customer_id = isset( $_POST['customer_id'] ) ? intval( $_POST['customer_id'] ) : 0; if ( ! $customer_id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $customer = new WPSC_Customer( $customer_id ); if ( ! $customer->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $title = esc_attr__( 'Customer info', 'supportcandy' ); $unique_id = uniqid(); ob_start(); ?>
field !== 'customer' || in_array( $cf->slug, WPSC_DF_Customer::$ignore_customer_info_cft ) ) { continue; } ?>
: name ); ?>
: email ); ?>
name ); ?>: type::print_widget_customer_field_val( $cf, $customer ); ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Get edit customer info * * @return void */ public static function get_edit_customer_info() { if ( check_ajax_referer( 'wpsc_get_edit_customer_info', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $customer_id = isset( $_POST['customer_id'] ) ? intval( $_POST['customer_id'] ) : 0; if ( ! $customer_id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $customer = new WPSC_Customer( $customer_id ); if ( ! $customer->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $title = esc_attr__( 'Edit customer info', 'supportcandy' ); ob_start(); ?>
name ); ?>
extra_info ); ?>
field !== 'customer' || in_array( $cf->slug, WPSC_DF_Customer::$ignore_customer_info_cft ) ) { continue; } $properties = array( 'is-required' => 0, 'width' => 'full', 'visibility' => '', ); echo $cf->type::print_edit_customer_info( $cf, $customer, $properties ); // phpcs:ignore } do_action( 'wpsc_get_edit_customer_info_body', $customer ); ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Save customer info * * @return void */ public static function set_edit_customer_info() { if ( check_ajax_referer( 'wpsc_set_edit_customer_info', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $customer_id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $customer_id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $customer = new WPSC_Customer( $customer_id ); if ( ! $customer->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; if ( ! $name ) { wp_send_json_error( new WP_Error( '002', 'Bad request!' ), 400 ); } if ( $customer->name != $name ) { $customer->name = $name; $customer->save(); // Update WP User if available. if ( $customer->user ) { wp_update_user( array( 'ID' => $customer->user->ID, 'display_name' => $name, ) ); } } $cfs = array(); foreach ( WPSC_Custom_Field::$custom_fields as $cf ) { if ( $cf->field !== 'customer' || $cf->type::$is_default ) { continue; } $cfs[ $cf->type::$slug ][] = $cf; } foreach ( $cfs as $slug => $fields ) { WPSC_Functions::$ref_classes[ $slug ]['class']::set_create_ticket_data( array( 'customer' => $customer->id ), $cfs, true ); } $response = array( 'customer_id' => $customer->id, 'nonce' => wp_create_nonce( 'wpsc_view_customer_detailed_info' ), ); wp_send_json( $response ); } /** * View customer logs * * @return void */ public static function view_customer_logs() { if ( check_ajax_referer( 'wpsc_view_customer_logs', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $customer_id = isset( $_POST['customer_id'] ) ? intval( $_POST['customer_id'] ) : 0; if ( ! $customer_id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $customer = new WPSC_Customer( $customer_id ); if ( ! $customer->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $title = esc_attr__( 'Customer logs', 'supportcandy' ); $unique_id = uniqid(); ob_start(); $logs = WPSC_Log::find( array( 'meta_query' => array( 'relation' => 'AND', array( 'slug' => 'type', 'compare' => '=', 'val' => 'customer', ), array( 'slug' => 'ref_id', 'compare' => '=', 'val' => $customer->id, ), ), ) )['results']; ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Print customer log * * @param WPSC_Log $log - log object. * @return void */ public static function print_log( $log ) { $advanced = get_option( 'wpsc-ms-advanced-settings', array() ); $now = new DateTime(); $date = $log->date_created->setTimezone( wp_timezone() ); $time_date_str = $date->format( $advanced['thread-date-format'] ); $time_diff_str = WPSC_Functions::date_interval_highest_unit_ago( $date->diff( $now ) ); $title = $advanced['thread-date-display-as'] == 'date' ? $time_diff_str : $time_date_str; $time_str = $advanced['thread-date-display-as'] == 'date' ? $time_date_str : $time_diff_str; $body = json_decode( $log->body ); $customer = new WPSC_Customer( $log->modified_by ); $cf = WPSC_Custom_Field::get_cf_by_slug( $body->slug ); if ( ! $cf ) { return; } ?>
modified_by ) { echo get_avatar( $customer->email, 32 ); } else { WPSC_Icons::get( 'system' ); } ?>
type::print_val( $cf, $body->prev ); ?>
type::print_val( $cf, $body->new ); ?>
customer->update_ticket_count(); } /** * Delete customer from. * * @return void */ public static function delete_customer_info() { if ( check_ajax_referer( 'wpsc_delete_customer', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $customer_id = isset( $_POST['customer_id'] ) ? intval( $_POST['customer_id'] ) : 0; if ( ! $customer_id ) { wp_send_json_error( 'Bad Request', 400 ); } $customer = new WPSC_Customer( $customer_id ); if ( ! $customer->id ) { wp_send_json_error( 'Bad request', 400 ); } // Make agent as a anonymous customer. $agent = WPSC_Agent::get_by_customer( $customer ); if ( $agent->id ) { if ( $agent->role == 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $agent->customer = WPSC_Functions::anonymous_customer(); $agent->is_active = 0; $agent->save(); // Remove agent capability. if ( $agent->has_cap( 'backend-access' ) ) { $agent->user->remove_cap( 'wpsc_agent' ); } do_action( 'wpsc_delete_agent', $agent ); } self::delete_customer_tickets( $customer_id ); WPSC_Customer::destroy( $customer ); do_action( 'wpsc_delete_customer', $customer ); wp_die(); } /** * Delete customer tickets * * @param int $customer_id - customer_id. * @return void */ public static function delete_customer_tickets( $customer_id ) { global $wpdb; // Delete threads if records is exists. $td_sql = "DELETE thrd FROM {$wpdb->prefix}psmsc_threads AS thrd LEFT JOIN {$wpdb->prefix}psmsc_tickets AS t ON thrd.ticket = t.id WHERE t.customer = $customer_id"; $wpdb->query( $td_sql ); // is active 0 attachment if records is exists. $td_sql = "UPDATE {$wpdb->prefix}psmsc_attachments AS att LEFT JOIN {$wpdb->prefix}psmsc_tickets AS t ON att.ticket_id = t.id SET att.is_active = 0 WHERE t.customer = $customer_id"; $wpdb->query( $td_sql ); // Delete sla log records if log records is exists. if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}psmsc_sla_logs'" ) ) { $sl_sql = "DELETE sl FROM {$wpdb->prefix}psmsc_sla_logs AS sl LEFT JOIN {$wpdb->prefix}psmsc_tickets AS t ON sl.ticket = t.id WHERE t.customer = $customer_id"; $wpdb->query( $sl_sql ); } // Delete timer log records if log records is exists. if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}psmsc_timer_logs'" ) ) { $tl_sql = "DELETE tl FROM {$wpdb->prefix}psmsc_timer_logs AS tl LEFT JOIN {$wpdb->prefix}psmsc_tickets AS t ON tl.ticket = t.id WHERE t.customer = $customer_id"; $wpdb->query( $tl_sql ); } // Delete tickets if ticket records is exists. $td_sql = "DELETE FROM {$wpdb->prefix}psmsc_tickets WHERE customer = $customer_id"; $wpdb->query( $td_sql ); } /** * Get customer profile details * * @return void */ public static function view_customer_detailed_info() { if ( check_ajax_referer( 'wpsc_view_customer_detailed_info', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $customer_id = isset( $_POST['customer_id'] ) ? intval( $_POST['customer_id'] ) : 0; if ( ! $customer_id ) { wp_send_json_error( 'Bad Request', 400 ); } $customer = new WPSC_Customer( $customer_id ); if ( ! $customer->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $agent = WPSC_Agent::get_by_customer( $customer ); ?>
id || ( $agent->role != 1 ) ) { ?> |
email, 50 ); ?>
name ); ?>
email ); ?>
0, 'orderby' => 'id', 'order' => 'DESC', 'meta_query' => array( 'relation' => 'AND', array( 'slug' => 'customer', 'compare' => '=', 'val' => $customer->id, ), ), ); $tickets = WPSC_Ticket::find( $filters )['results']; if ( $tickets ) { foreach ( $tickets as $ticket ) { ?>
name ); ?>
field, array( 'ticket', 'agentonly' ) ) ) { $cf->type::print_tl_ticket_field_val( $cf, $ticket ); } else { $cf->type::print_tl_customer_field_val( $cf, $ticket->customer ); } ?>
field !== 'customer' || in_array( $cf->slug, WPSC_DF_Customer::$ignore_customer_info_cft ) ) { continue; } $properties = array( 'is-required' => 0, 'width' => 'full', 'visibility' => '', ); echo $cf->type::print_edit_customer_info( $cf, $customer, $properties ); // phpcs:ignore } do_action( 'wpsc_get_edit_customer_info_body', $customer ); ?>

id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $logs = WPSC_RA_Logs::get_activity_logs( 10, 1, $customer_id ); $now = new DateTime(); ob_start(); ?>
ticket->id, $view ); $time_ago = WPSC_Functions::date_interval_highest_unit_ago( $log->date_created->diff( $now ) ); if ( $log->type == 'report' ) { ?>
customer->name ) . ' ' . esc_attr__( 'created a ticket', 'supportcandy' ); ?> #ticket->id ) . ' ' . esc_attr( $log->ticket->subject ); ?>
type == 'reply' ) { ?>
customer->name ) . ' ' . esc_attr__( 'replied to ticket', 'supportcandy' ); ?> #ticket->id ); ?>
type == 'note' ) { ?>
customer->name ) . ' ' . esc_attr__( 'added a note to ticket', 'supportcandy' ); ?> #ticket->id ); ?>
type == 'log' ) { if ( ! $log->customer ) { continue; } $body = json_decode( $log->body ); $is_json = ( json_last_error() == JSON_ERROR_NONE ) ? true : false; if ( $is_json ) { $cf = WPSC_Custom_Field::get_cf_by_slug( $body->slug ); if ( ! $cf ) { continue; } ?>
type::print_activity( $cf, $log, $body, '0' ) ); ?>
$table ) ); } } endif; WPSC_Customers::init();