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-general-setting.php

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

251 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly!
5 }
6
7 if ( ! class_exists( 'WPSC_Dashboard_General_Setting' ) ) :
8
9 final class WPSC_Dashboard_General_Setting {
10
11 /**
12 * List of allowed custom field types in report
13 *
14 * @var array
15 */
16 public static $ignore_cft = array();
17
18 /**
19 * Initialize this class
20 */
21 public static function init() {
22
23 add_action( 'init', array( __CLASS__, 'ignore_dbw_cf' ) );
24
25 // General settings widget.
26 add_action( 'wp_ajax_wpsc_get_dashboard_general_settings', array( __CLASS__, 'get_dashboard_general_widgets' ) );
27 add_action( 'wp_ajax_wpsc_set_dashboard_general_settings', array( __CLASS__, 'save_settings' ) );
28 add_action( 'wp_ajax_wpsc_reset_dashboard_general_settings', array( __CLASS__, 'reset_settings' ) );
29 }
30
31 /**
32 * Reset settings
33 *
34 * @return void
35 */
36 public static function reset() {
37
38 $gs = apply_filters(
39 'wpsc_db_gs_settings',
40 array(
41 'default-date-range' => 'last-week',
42 'allowed-recent-activity-logs' => array( 'report', 'reply', 'note', 'assigned_agent' ),
43 'dash-auto-refresh' => 0,
44 )
45 );
46 update_option( 'wpsc-db-gs-settings', $gs );
47 }
48
49 /**
50 * List of ignored widgets in reports
51 *
52 * @return void
53 */
54 public static function ignore_dbw_cf() {
55
56 self::$ignore_cft = apply_filters(
57 'wpsc_recent_activities_ignore_cf',
58 array(
59 'cf_html',
60 'df_ip_address',
61 'df_browser',
62 'df_prev_assignee',
63 'df_date_closed',
64 'df_date_created',
65 'df_date_updated',
66 'df_add_recipients',
67 'df_agent_created',
68 'df_customer_email',
69 'df_customer_name',
70 'df_customer',
71 'df_description',
72 'df_id',
73 'df_ip_address',
74 'df_source',
75 'df_tags',
76 'df_os',
77 'df_sla',
78 'df_last_reply_on',
79 'df_last_reply_by',
80 'df_sf_date',
81 'df_sf_feedback',
82 'df_sf_rating',
83 'df_time_spent',
84 'df_usergroups',
85 'df_user_type',
86 'cf_edd_order',
87 'cf_edd_product',
88 'cf_woo_order',
89 'cf_woo_subscription',
90 'cf_woo_product',
91 'cf_tutor_lms',
92 'cf_tutor_order',
93 'cf_learnpress_lms',
94 'cf_learnpress_order',
95 'cf_lifter_lms',
96 'cf_lifter_order',
97 )
98 );
99 }
100
101 /**
102 * Load ticket widgets
103 */
104 public static function get_dashboard_general_widgets() {
105
106 if ( ! WPSC_Functions::is_site_admin() ) {
107 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
108 }
109
110 $db_gs = get_option( 'wpsc-db-gs-settings', array() );
111 ob_start();
112 ?>
113 <div class="wpsc-dock-container">
114 <?php
115 printf(
116 /* translators: Click here to see the documentation */
117 esc_attr__( '%s to see the documentation!', 'supportcandy' ),
118 '<a href="https://supportcandy.net/docs/dashboard-general-setting/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>'
119 );
120 ?>
121 </div>
122 <form action="#" onsubmit="return false;" class="wpsc-frm-db-gs">
123 <div class="wpsc-input-group">
124 <div class="label-container">
125 <label for=""><?php esc_attr_e( 'Default date range', 'supportcandy' ); ?></label>
126 </div>
127 <select name="default-date-range" id="wpsc-ddr">
128 <option <?php selected( $db_gs['default-date-range'], 'today' ); ?> value="today"><?php esc_attr_e( 'Today', 'supportcandy' ); ?></option>
129 <option <?php selected( $db_gs['default-date-range'], 'yesterday' ); ?> value="yesterday"><?php esc_attr_e( 'Yesterday', 'supportcandy' ); ?></option>
130 <option <?php selected( $db_gs['default-date-range'], 'last-7' ); ?> value="last-7"><?php esc_attr_e( 'Last 7 days', 'supportcandy' ); ?></option>
131 <option <?php selected( $db_gs['default-date-range'], 'this-week' ); ?> value="this-week"><?php esc_attr_e( 'This week', 'supportcandy' ); ?></option>
132 <option <?php selected( $db_gs['default-date-range'], 'last-week' ); ?> value="last-week"><?php esc_attr_e( 'Last week', 'supportcandy' ); ?></option>
133 <option <?php selected( $db_gs['default-date-range'], 'last-30-days' ); ?> value="last-30-days"><?php esc_attr_e( 'Last 30 days', 'supportcandy' ); ?></option>
134 <option <?php selected( $db_gs['default-date-range'], 'this-month' ); ?> value="this-month"><?php esc_attr_e( 'This month', 'supportcandy' ); ?></option>
135 <option <?php selected( $db_gs['default-date-range'], 'last-month' ); ?> value="last-month"><?php esc_attr_e( 'Last month', 'supportcandy' ); ?></option>
136 <option <?php selected( $db_gs['default-date-range'], 'this-quarter' ); ?> value="this-quarter"><?php esc_attr_e( 'This quarter', 'supportcandy' ); ?></option>
137 <option <?php selected( $db_gs['default-date-range'], 'last-quarter' ); ?> value="last-quarter"><?php esc_attr_e( 'Last quarter', 'supportcandy' ); ?></option>
138 <option <?php selected( $db_gs['default-date-range'], 'this-year' ); ?> value="this-year"><?php esc_attr_e( 'This year', 'supportcandy' ); ?></option>
139 <option <?php selected( $db_gs['default-date-range'], 'last-year' ); ?> value="last-year"><?php esc_attr_e( 'Last year', 'supportcandy' ); ?></option>
140 </select>
141 <script>
142 jQuery('#wpsc-ddr').selectWoo({
143 allowClear: true,
144 placeholder: ""
145 });
146 </script>
147 </div>
148 <div class="wpsc-input-group">
149 <div class="label-container">
150 <label for=""><?php esc_attr_e( 'Allowed recent activity logs', 'supportcandy' ); ?></label>
151 </div>
152 <select id="wpsc-allowed-recent-activity-logs" multiple name="allowed-recent-activity-logs[]">
153 <option <?php echo esc_attr( in_array( 'report', $db_gs['allowed-recent-activity-logs'] ) ? 'selected' : '' ); ?> value="report"><?php esc_attr_e( 'Report', 'supportcandy' ); ?></option>
154 <option <?php echo esc_attr( in_array( 'reply', $db_gs['allowed-recent-activity-logs'] ) ? 'selected' : '' ); ?> value="reply"><?php esc_attr_e( 'Reply', 'supportcandy' ); ?></option>
155 <option <?php echo esc_attr( in_array( 'note', $db_gs['allowed-recent-activity-logs'] ) ? 'selected' : '' ); ?> value="note"><?php esc_attr_e( 'Note', 'supportcandy' ); ?></option>
156 <?php
157 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
158 if ( $cf->field != 'ticket' || in_array( $cf->type::$slug, self::$ignore_cft ) ) {
159 continue;
160 }
161 $selected = in_array( $cf->slug, $db_gs['allowed-recent-activity-logs'] ) ? 'selected' : '';
162 ?>
163 <option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
164 <?php
165 }
166 ?>
167 </select>
168 <script>
169 jQuery('#wpsc-allowed-recent-activity-logs').selectWoo({
170 allowClear: true,
171 placeholder: ""
172 });
173 </script>
174 </div>
175 <div class="wpsc-input-group">
176 <div class="label-container">
177 <label for=""><?php esc_attr_e( 'Dashboard auto refresh', 'supportcandy' ); ?></label>
178 </div>
179 <select id="wpsc-dash-auto-refresh" name="wpsc-dash-auto-refresh">
180 <option <?php selected( $db_gs['dash-auto-refresh'], '1' ); ?> value="1"><?php esc_attr_e( 'On', 'supportcandy' ); ?></option>
181 <option <?php selected( $db_gs['dash-auto-refresh'], '0' ); ?> value="0"><?php esc_attr_e( 'Off', 'supportcandy' ); ?></option>
182 </select>
183 </div>
184 <?php do_action( 'wpsc_db_gs_settings' ); ?>
185 <input type="hidden" name="action" value="wpsc_set_dashboard_general_settings">
186 <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_dashboard_general_settings' ) ); ?>">
187 </form>
188 <div class="setting-footer-actions">
189 <button
190 class="wpsc-button normal primary margin-right"
191 onclick="wpsc_set_dashboard_general_settings(this);">
192 <?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button>
193 <button
194 class="wpsc-button normal secondary"
195 onclick="wpsc_reset_dashboard_general_settings(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_dashboard_general_settings' ) ); ?>');">
196 <?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button>
197 </div>
198 <?php
199 wp_die();
200 }
201
202 /**
203 * Save settings
204 *
205 * @return void
206 */
207 public static function save_settings() {
208
209 if ( check_ajax_referer( 'wpsc_set_dashboard_general_settings', '_ajax_nonce', false ) != 1 ) {
210 wp_send_json_error( 'Unauthorized request!', 401 );
211 }
212
213 if ( ! WPSC_Functions::is_site_admin() ) {
214 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
215 }
216
217 $gs = apply_filters(
218 'wpsc_set_db_gs_settings',
219 array(
220 'default-date-range' => isset( $_POST['default-date-range'] ) ? sanitize_text_field( wp_unslash( $_POST['default-date-range'] ) ) : 'last-week',
221 'allowed-recent-activity-logs' => isset( $_POST['allowed-recent-activity-logs'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['allowed-recent-activity-logs'] ) ) ) : array(),
222 'dash-auto-refresh' => isset( $_POST['wpsc-dash-auto-refresh'] ) ? intval( $_POST['wpsc-dash-auto-refresh'] ) : 0,
223 )
224 );
225 update_option( 'wpsc-db-gs-settings', $gs );
226 wp_die();
227 }
228
229 /**
230 * Reset settings to default
231 *
232 * @return void
233 */
234 public static function reset_settings() {
235
236 if ( check_ajax_referer( 'wpsc_reset_dashboard_general_settings', '_ajax_nonce', false ) != 1 ) {
237 wp_send_json_error( 'Unauthorized request!', 401 );
238 }
239
240 if ( ! WPSC_Functions::is_site_admin() ) {
241 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
242 }
243 self::reset();
244 wp_die();
245 }
246 }
247
248 endif;
249
250 WPSC_Dashboard_General_Setting::init();
251