PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / admin / settings / dashboard-settings / class-wpsc-dashboard-action.php

class-wpsc-dashboard-action.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.4, at includes/admin/settings/dashboard-settings/class-wpsc-dashboard-action.php

139 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Dashboard_Action' ) ) :
7
8 final class WPSC_Dashboard_Action {
9
10
11 /**
12 * Initialize this class
13 */
14 public static function init() {
15
16 // Set filter for the card.
17 add_action( 'wp_ajax_wpsc_dash_card_count_filter', array( __CLASS__, 'set_filter' ) );
18 add_action( 'wp_ajax_nopriv_wpsc_dash_card_count_filter', array( __CLASS__, 'set_filter' ) );
19 }
20
21 /**
22 * Set filter for the card.
23 *
24 * @return void
25 */
26 public static function set_filter() {
27
28 if ( check_ajax_referer( 'general', '_ajax_nonce', false ) != 1 ) {
29 wp_send_json_error( 'Unauthorized request!', 401 );
30 }
31
32 $card = isset( $_POST['card'] ) ? sanitize_text_field( wp_unslash( $_POST['card'] ) ) : '';
33 if ( ! $card ) {
34 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
35 }
36
37 $view = isset( $_POST['view'] ) ? sanitize_text_field( wp_unslash( $_POST['view'] ) ) : '0';
38
39 $current_user = WPSC_Current_User::$current_user;
40 if ( ! $current_user->is_agent ) {
41 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
42 }
43
44 $page_settings = get_option( 'wpsc-gs-page-settings' );
45 $more_settings = $current_user->is_agent ? get_option( 'wpsc-tl-ms-agent-view' ) : get_option( 'wpsc-tl-ms-customer-view' );
46
47 // closed statuses.
48 $ms_advance_settings = get_option( 'wpsc-tl-ms-advanced' );
49 $closed_statuses = $ms_advance_settings['closed-ticket-statuses'];
50
51 $custom_filters = array();
52
53 if ( $card == 'new-tickets' ) {
54
55 $cf = WPSC_Custom_Field::get_cf_by_slug( 'status' );
56 $obj = new stdClass();
57 $obj->slug = 'status';
58 $obj->operator = '=';
59 $obj->operand_val_1 = $cf->default_value[0];
60
61 $custom_filters[] = array( $obj );
62
63 } elseif ( $card == 'unassigned-tickets' ) {
64 $obj = new stdClass();
65 $obj->slug = 'assigned_agent';
66 $obj->operator = '=';
67 $obj->operand_val_1 = '';
68
69 $custom_filters[] = array( $obj );
70
71 } elseif ( $card == 'unresolved-tickets' ) {
72 $obj = new stdClass();
73 $obj->slug = 'status';
74 $obj->operator = 'IN';
75 $obj->operand_val_1 = $more_settings['unresolved-ticket-statuses'];
76
77 $custom_filters[] = array( $obj );
78
79 } elseif ( $card == 'mine-tickets' ) {
80 $obj = new stdClass();
81 $obj->slug = 'assigned_agent';
82 $obj->operator = '=';
83 $obj->operand_val_1 = $current_user->agent->id;
84
85 $custom_filters[] = array( $obj );
86
87 $obj = new stdClass();
88 $obj->slug = 'status';
89 $obj->operator = 'IN';
90 $obj->operand_val_1 = $more_settings['unresolved-ticket-statuses'];
91
92 $custom_filters[] = array( $obj );
93
94 } elseif ( $card == 'closed-tickets' ) {
95 $obj = new stdClass();
96 $obj->slug = 'status';
97 $obj->operator = 'IN';
98 $obj->operand_val_1 = $closed_statuses;
99
100 $custom_filters[] = array( $obj );
101
102 }
103
104 $filters = array(
105 'filterSlug' => 'custom',
106 'parent-filter' => 'all',
107 'filters' => wp_json_encode( $custom_filters ),
108 'orderby' => 'date_updated',
109 'order' => 'DESC',
110 'page_no' => 1,
111 'search' => '',
112 );
113
114 $filters = apply_filters( 'wpsc_dbw_set_filter', $filters, $custom_filters, $card );
115
116 setcookie( 'wpsc-tl-filters', wp_json_encode( $filters ), time() + 3600 );
117
118 $url = '';
119 if ( $view === '0' ) {
120 $url = admin_url( 'admin.php?page=wpsc-tickets&section=ticket-list' );
121 } elseif ( ( $page_settings['ticket-url-page'] == 'support-page' && $page_settings['support-page'] ) ||
122 ( $page_settings['ticket-url-page'] == 'open-ticket-page' && $page_settings['open-ticket-page'] ) ) {
123
124 $url = get_permalink( $page_settings['support-page'] );
125 $url = add_query_arg(
126 array(
127 'wpsc-section' => 'ticket-list',
128 ),
129 $url
130 );
131 }
132
133 wp_send_json( array( 'url' => $url ) );
134 }
135 }
136 endif;
137
138 WPSC_Dashboard_Action::init();
139