0 ) )['results']; $cf = WPSC_Custom_Field::get_cf_by_slug( 'status' ); $general_settings = get_option( 'wpsc-gs-general' ); $default_statuses = array( 1, 2, 3, 4, $cf->default_value[0], $general_settings['ticket-status-after-customer-reply'], $general_settings['ticket-status-after-agent-reply'], $general_settings['close-ticket-status'] ); $default_statuses = array_unique( $default_statuses );?>

' . esc_attr__( 'Click here', 'supportcandy' ) . '' ); ?>
name ); ?>
id, $default_statuses ) ) : ?> |
0 ) )['results']; ob_start(); ?>
*
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Set add new status */ public static function set_add_status() { if ( check_ajax_referer( 'wpsc_set_add_status', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; if ( ! $name ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $color = isset( $_POST['color'] ) ? sanitize_text_field( wp_unslash( $_POST['color'] ) ) : ''; if ( ! $color ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $bgcolor = isset( $_POST['bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['bg-color'] ) ) : ''; if ( ! $bgcolor ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $data = array( 'name' => $name, 'color' => $color, 'bg_color' => $bgcolor, ); $status = WPSC_Status::insert( $data ); // set laod order. $statuses_list = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; $load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__'; if ( $load_after != '__END__' ) { $count = 1; if ( $load_after == '__TOP__' ) { $status->load_order = $count++; $status->save(); } foreach ( $statuses_list as $stat ) { if ( $stat->id == $status->id ) { continue; } $stat->load_order = $count++; $stat->save(); if ( $stat->id == $load_after ) { $status->load_order = $count++; $status->save(); } } } wp_die(); } /** * Get edit status */ public static function get_edit_status() { global $wpdb; if ( check_ajax_referer( 'wpsc_get_edit_status', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $status = new WPSC_Status( $id ); if ( ! $status->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $title = esc_attr( $status->name ); $statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; ob_start(); ?>
*
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Set edit status */ public static function set_edit_status() { global $wpdb; if ( check_ajax_referer( 'wpsc_set_edit_status', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $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( __( 'Bad request!', 'supportcandy' ), 400 ); } $color = isset( $_POST['color'] ) ? sanitize_text_field( wp_unslash( $_POST['color'] ) ) : ''; if ( ! $color ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $bgcolor = isset( $_POST['bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['bg-color'] ) ) : ''; if ( ! $bgcolor ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $status = new WPSC_Status( $id ); if ( ! $status->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $status->name = $name; $status->color = $color; $status->bg_color = $bgcolor; $status->save(); // set load order. $statuses_list = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; $load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__'; if ( $load_after != '__END__' ) { $count = 1; if ( $load_after == '__TOP__' ) { $status->load_order = $count++; $status->save(); } foreach ( $statuses_list as $cat ) { if ( $cat->id == $status->id ) { continue; } $cat->load_order = $count++; $cat->save(); if ( $cat->id == $load_after ) { $status->load_order = $count++; $status->save(); } } } else { $max_load_order = (int) $wpdb->get_var( "SELECT max(load_order) FROM {$wpdb->prefix}psmsc_statuses" ); $status->load_order = ++$max_load_order; $status->save(); } wp_die(); } /** * Delete status modal * * @return void */ public static function get_delete_status() { if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } if ( check_ajax_referer( 'wpsc_get_delete_status', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $title = esc_attr__( 'Delete status', 'supportcandy' ); $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $status = new WPSC_Status( $id ); if ( ! $status->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; ob_start(); ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Delete status */ public static function set_delete_status() { global $wpdb; if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } if ( check_ajax_referer( 'wpsc_set_delete_status', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorised request!', 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $status = new WPSC_Status( $id ); if ( ! $status->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $replace_id = isset( $_POST['replace_id'] ) ? intval( $_POST['replace_id'] ) : 0; if ( ! $replace_id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $replace = new WPSC_Status( $replace_id ); if ( ! $replace->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $cf = WPSC_Custom_Field::get_cf_by_slug( 'status' ); $general_settings = get_option( 'wpsc-gs-general' ); $statuses = array( 1, 2, 3, 4, $cf->default_value[0], $general_settings['ticket-status-after-customer-reply'], $general_settings['ticket-status-after-agent-reply'], $general_settings['close-ticket-status'] ); $statuses = array_unique( $statuses ); if ( in_array( $id, $statuses ) ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } // replace in ticket table. $success = $wpdb->update( $wpdb->prefix . 'psmsc_tickets', array( 'status' => $replace->id ), array( 'status' => $status->id ) ); // replace in logs. $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}psmsc_threads WHERE (type = 'log') AND JSON_VALID(body) AND JSON_EXTRACT(body, '$.slug') = 'status' AND ( JSON_UNQUOTE(JSON_EXTRACT(body, '$.new')) = '" . $status->id . "' OR JSON_UNQUOTE(JSON_EXTRACT(body, '$.prev')) = '" . $status->id . "' )" ); foreach ( $results as $log ) { $body = json_decode( $log->body ); $body->prev = $body->prev == $status->id ? $replace->id : $body->prev; $body->new = $body->new == $status->id ? $replace->id : $body->new; $body = wp_json_encode( $body ); $wpdb->update( $wpdb->prefix . 'psmsc_threads', array( 'body' => $body ), array( 'id' => $log->id ) ); } $status->destroy( $status ); wp_die(); } } endif; WPSC_Ticket_Statuses::init();