| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Ticket_List_More_Settings' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Ticket_List_More_Settings { |
| 9 |
|
| 10 |
/** |
| 11 |
* Tabs for this section |
| 12 |
* |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
private static $tabs; |
| 16 |
|
| 17 |
/** |
| 18 |
* Current tab |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
public static $current_tab; |
| 23 |
|
| 24 |
/** |
| 25 |
* Initialize this class |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public static function init() { |
| 30 |
|
| 31 |
// Load tabs for this section. |
| 32 |
add_action( 'admin_init', array( __CLASS__, 'load_tabs' ) ); |
| 33 |
|
| 34 |
// Add current tab to admin localization data. |
| 35 |
add_filter( 'wpsc_admin_localizations', array( __CLASS__, 'localizations' ) ); |
| 36 |
|
| 37 |
// Agent ticket list settings. |
| 38 |
add_action( 'wp_ajax_wpsc_get_tl_more_settigns', array( __CLASS__, 'get_tl_more_settigns' ) ); |
| 39 |
|
| 40 |
// Agent view settings. |
| 41 |
add_action( 'wp_ajax_wpsc_tl_ms_get_agent_view', array( __CLASS__, 'tl_ms_get_agent_view' ) ); |
| 42 |
add_action( 'wp_ajax_wpsc_tl_ms_set_agent_view', array( __CLASS__, 'tl_ms_set_agent_view' ) ); |
| 43 |
add_action( 'wp_ajax_wpsc_tl_ms_reset_agent_view', array( __CLASS__, 'tl_ms_reset_agent_view' ) ); |
| 44 |
|
| 45 |
// Customer view settings. |
| 46 |
add_action( 'wp_ajax_wpsc_tl_ms_get_customer_view', array( __CLASS__, 'tl_ms_get_customer_view' ) ); |
| 47 |
add_action( 'wp_ajax_wpsc_tl_ms_set_customer_view', array( __CLASS__, 'tl_ms_set_customer_view' ) ); |
| 48 |
add_action( 'wp_ajax_wpsc_tl_ms_reset_customer_view', array( __CLASS__, 'tl_ms_reset_customer_view' ) ); |
| 49 |
|
| 50 |
// Advanced settings. |
| 51 |
add_action( 'wp_ajax_wpsc_tl_ms_get_advanced', array( __CLASS__, 'tl_ms_get_advanced' ) ); |
| 52 |
add_action( 'wp_ajax_wpsc_tl_ms_set_advanced', array( __CLASS__, 'tl_ms_set_advanced' ) ); |
| 53 |
add_action( 'wp_ajax_wpsc_tl_ms_reset_advanced', array( __CLASS__, 'tl_ms_reset_advanced' ) ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get default agent view |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public static function tl_ms_default_agent() { |
| 62 |
|
| 63 |
$view = apply_filters( |
| 64 |
'wpsc_tl_ms_agent_view', |
| 65 |
array( |
| 66 |
'default-sort-by' => 'date_updated', |
| 67 |
'default-sort-order' => 'DESC', |
| 68 |
'number-of-tickets' => 20, |
| 69 |
'unresolved-ticket-statuses' => array( 1, 2, 3 ), |
| 70 |
'default-filter' => 'all', |
| 71 |
'ticket-reply-redirect' => 'no-redirect', |
| 72 |
) |
| 73 |
); |
| 74 |
update_option( 'wpsc-tl-ms-agent-view', $view ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get default customer view |
| 79 |
* |
| 80 |
* @return void |
| 81 |
*/ |
| 82 |
public static function tl_ms_default_customer() { |
| 83 |
|
| 84 |
$view = apply_filters( |
| 85 |
'wpsc_tl_ms_customer_view', |
| 86 |
array( |
| 87 |
'default-sort-by' => 'date_updated', |
| 88 |
'default-sort-order' => 'DESC', |
| 89 |
'number-of-tickets' => 20, |
| 90 |
'unresolved-ticket-statuses' => array( 1, 2, 3 ), |
| 91 |
'default-filter' => 'all', |
| 92 |
'ticket-reply-redirect' => 'no-redirect', |
| 93 |
) |
| 94 |
); |
| 95 |
update_option( 'wpsc-tl-ms-customer-view', $view ); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Get default advanced settings |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
public static function tl_ms_default_advanced() { |
| 104 |
|
| 105 |
$advanced_settings = apply_filters( |
| 106 |
'wpsc_tl_ms_advanced', |
| 107 |
array( |
| 108 |
'closed-ticket-statuses' => array( 4 ), |
| 109 |
'auto-refresh-list-status' => 0, |
| 110 |
) |
| 111 |
); |
| 112 |
update_option( 'wpsc-tl-ms-advanced', $advanced_settings ); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Load tabs for this section |
| 117 |
*/ |
| 118 |
public static function load_tabs() { |
| 119 |
|
| 120 |
self::$tabs = apply_filters( |
| 121 |
'wpsc_agent_ticket_list_tabs', |
| 122 |
array( |
| 123 |
'agent-view' => array( |
| 124 |
'slug' => 'agent_view', |
| 125 |
'label' => esc_attr__( 'Agent view', 'supportcandy' ), |
| 126 |
'callback' => 'wpsc_tl_ms_get_agent_view', |
| 127 |
), |
| 128 |
'customer-view' => array( |
| 129 |
'slug' => 'customer_view', |
| 130 |
'label' => esc_attr__( 'Customer view', 'supportcandy' ), |
| 131 |
'callback' => 'wpsc_tl_ms_get_customer_view', |
| 132 |
), |
| 133 |
'advanced' => array( |
| 134 |
'slug' => 'advanced_view', |
| 135 |
'label' => esc_attr__( 'Advanced', 'supportcandy' ), |
| 136 |
'callback' => 'wpsc_tl_ms_get_advanced', |
| 137 |
), |
| 138 |
) |
| 139 |
); |
| 140 |
self::$current_tab = isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'agent-view'; // phpcs:ignore |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Add localizations to local JS |
| 145 |
* |
| 146 |
* @param array $localizations - localization list. |
| 147 |
* @return array |
| 148 |
*/ |
| 149 |
public static function localizations( $localizations ) { |
| 150 |
|
| 151 |
if ( ! ( WPSC_Ticket_List_Settings::$is_current_page && WPSC_Ticket_List_Settings::$current_section === 'more-settings' ) ) { |
| 152 |
return $localizations; |
| 153 |
} |
| 154 |
|
| 155 |
// Current section. |
| 156 |
$localizations['current_tab'] = self::$current_tab; |
| 157 |
|
| 158 |
return $localizations; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Customer ticket list settings |
| 163 |
* |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
public static function get_tl_more_settigns() { |
| 167 |
|
| 168 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 169 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 170 |
}?> |
| 171 |
|
| 172 |
<div class="wpsc-setting-tab-container"> |
| 173 |
<?php |
| 174 |
foreach ( self::$tabs as $key => $tab ) : |
| 175 |
$active = self::$current_tab === $key ? 'active' : '' |
| 176 |
?> |
| 177 |
<button |
| 178 |
class="<?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" |
| 179 |
onclick="<?php echo esc_attr( $tab['callback'] ) . '();'; ?>"> |
| 180 |
<?php echo esc_attr( $tab['label'] ); ?> |
| 181 |
</button> |
| 182 |
<?php |
| 183 |
endforeach; |
| 184 |
?> |
| 185 |
</div> |
| 186 |
<div class="wpsc-setting-section-body"></div> |
| 187 |
<?php |
| 188 |
wp_die(); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Get agent view settings |
| 193 |
*/ |
| 194 |
public static function tl_ms_get_agent_view() { |
| 195 |
|
| 196 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 197 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 198 |
} |
| 199 |
|
| 200 |
$statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; |
| 201 |
$custom_fields = WPSC_Custom_Field::$custom_fields; |
| 202 |
$list_tems = get_option( 'wpsc-atl-list-items' ); |
| 203 |
$agent_view = get_option( 'wpsc-tl-ms-agent-view', array() ); |
| 204 |
$default_filters = get_option( 'wpsc-atl-default-filters' ); |
| 205 |
$list_tags = apply_filters( |
| 206 |
'wpsc_list_item_tags', |
| 207 |
array( |
| 208 |
'status' => esc_attr__( 'Status', 'supportcandy' ), |
| 209 |
'priority' => esc_attr__( 'Priority', 'supportcandy' ), |
| 210 |
) |
| 211 |
); |
| 212 |
?> |
| 213 |
|
| 214 |
<form action="#" onsubmit="return false;" class="wpsc-frm-tl-ms-agent-view"> |
| 215 |
<div class="wpsc-input-group"> |
| 216 |
<div class="label-container"> |
| 217 |
<label for=""><?php esc_attr_e( 'Default sort by', 'supportcandy' ); ?></label> |
| 218 |
</div> |
| 219 |
<select id="wpsc-agent-default-sort-by" name="default-sort-by"> |
| 220 |
<?php |
| 221 |
foreach ( $list_tems as $slug ) : |
| 222 |
$cf = WPSC_Custom_Field::get_cf_by_slug( $slug ); |
| 223 |
if ( ! $cf ) { |
| 224 |
continue; |
| 225 |
} |
| 226 |
if ( $cf->type::$is_sort ) : |
| 227 |
?> |
| 228 |
<option <?php selected( $cf->slug, $agent_view['default-sort-by'] ); ?>value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option> |
| 229 |
<?php |
| 230 |
endif; |
| 231 |
endforeach; |
| 232 |
?> |
| 233 |
</select> |
| 234 |
</div> |
| 235 |
<div class="wpsc-input-group"> |
| 236 |
<div class="label-container"> |
| 237 |
<label for=""><?php esc_attr_e( 'Default sort order', 'supportcandy' ); ?></label> |
| 238 |
</div> |
| 239 |
<select id="wpsc-agent-default-sort-order" name="default-sort-order"> |
| 240 |
<option <?php selected( $agent_view['default-sort-order'], 'DESC' ); ?> value="DESC"><?php esc_attr_e( 'DESC', 'supportcandy' ); ?></option> |
| 241 |
<option <?php selected( $agent_view['default-sort-order'], 'ASC' ); ?> value="ASC"><?php esc_attr_e( 'ASC', 'supportcandy' ); ?></option> |
| 242 |
</select> |
| 243 |
</div> |
| 244 |
<div class="wpsc-input-group"> |
| 245 |
<div class="label-container"> |
| 246 |
<label for=""><?php esc_attr_e( 'Number of tickets', 'supportcandy' ); ?></label> |
| 247 |
</div> |
| 248 |
<input type="number" id="wpsc-agent-number-of-tickets" name="number-of-tickets" value="<?php echo esc_attr( $agent_view['number-of-tickets'] ); ?>" /> |
| 249 |
</div> |
| 250 |
<div class="wpsc-input-group"> |
| 251 |
<div class="label-container"> |
| 252 |
<label for=""><?php esc_attr_e( 'Unresolved statuses', 'supportcandy' ); ?></label> |
| 253 |
</div> |
| 254 |
<select id="wpsc-agent-unresolved-ticket-statuses" multiple="multiple" name="unresolved-ticket-statuses[]"> |
| 255 |
<?php |
| 256 |
foreach ( $statuses as $status ) : |
| 257 |
$selected = in_array( $status->id, $agent_view['unresolved-ticket-statuses'] ) ? 'selected="selected"' : ''; |
| 258 |
?> |
| 259 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $status->id ); ?>"><?php echo esc_attr( $status->name ); ?></option> |
| 260 |
<?php |
| 261 |
endforeach; |
| 262 |
?> |
| 263 |
</select> |
| 264 |
<script> |
| 265 |
jQuery('#wpsc-agent-unresolved-ticket-statuses').selectWoo({ |
| 266 |
allowClear: false, |
| 267 |
placeholder: "" |
| 268 |
}); |
| 269 |
</script> |
| 270 |
</div> |
| 271 |
<div class="wpsc-input-group"> |
| 272 |
<div class="label-container"> |
| 273 |
<label for=""><?php esc_attr_e( 'Default filter', 'supportcandy' ); ?></label> |
| 274 |
</div> |
| 275 |
<select name="default-filter"> |
| 276 |
<optgroup label="<?php esc_attr_e( 'Default filters', 'supportcandy' ); ?>"> |
| 277 |
<?php |
| 278 |
foreach ( $default_filters as $index => $filter ) : |
| 279 |
$selected = $agent_view['default-filter'] == $index || $agent_view['default-filter'] == 'default-' . $index ? 'selected="selected"' : ''; |
| 280 |
$index = is_numeric( $index ) ? 'default-' . $index : $index; |
| 281 |
?> |
| 282 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $index ); ?>"> |
| 283 |
<?php |
| 284 |
$filter_label = $filter['label'] ? WPSC_Translations::get( 'wpsc-atl-' . $index, stripslashes( $filter['label'] ) ) : stripslashes( $filter['label'] ); |
| 285 |
echo esc_attr( $filter_label ) |
| 286 |
?> |
| 287 |
</option> |
| 288 |
<?php |
| 289 |
endforeach; |
| 290 |
?> |
| 291 |
</optgroup> |
| 292 |
</select> |
| 293 |
</div> |
| 294 |
<div class="wpsc-input-group"> |
| 295 |
<div class="label-container"> |
| 296 |
<label for=""><?php esc_attr_e( 'Ticket reply redirect', 'supportcandy' ); ?></label> |
| 297 |
</div> |
| 298 |
<select id="wpsc-ticket-reply-redirect" name="ticket-reply-redirect"> |
| 299 |
<option <?php selected( $agent_view['ticket-reply-redirect'], 'ticket-list' ); ?> value="ticket-list"><?php esc_attr_e( 'Ticket list', 'supportcandy' ); ?></option> |
| 300 |
<option <?php selected( $agent_view['ticket-reply-redirect'], 'no-redirect' ); ?> value="no-redirect"><?php esc_attr_e( 'No redirect', 'supportcandy' ); ?></option> |
| 301 |
</select> |
| 302 |
</div> |
| 303 |
<?php do_action( 'wpsc_tl_ms_agent_view' ); ?> |
| 304 |
<input type="hidden" name="action" value="wpsc_tl_ms_set_agent_view"> |
| 305 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_ms_set_agent_view' ) ); ?>"> |
| 306 |
</form> |
| 307 |
|
| 308 |
<div class="setting-footer-actions"> |
| 309 |
<button |
| 310 |
class="wpsc-button normal primary margin-right" |
| 311 |
onclick="wpsc_tl_ms_set_agent_view(this);"> |
| 312 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 313 |
<button |
| 314 |
class="wpsc-button normal secondary" |
| 315 |
onclick="wpsc_tl_ms_reset_agent_view(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_ms_reset_agent_view' ) ); ?>');"> |
| 316 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 317 |
</div> |
| 318 |
<?php |
| 319 |
do_action( 'wpsc_tl_ms_get_agent_footer' ); |
| 320 |
wp_die(); |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* Save agent view settings |
| 325 |
* |
| 326 |
* @return void |
| 327 |
*/ |
| 328 |
public static function tl_ms_set_agent_view() { |
| 329 |
|
| 330 |
if ( check_ajax_referer( 'wpsc_tl_ms_set_agent_view', '_ajax_nonce', false ) != 1 ) { |
| 331 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 332 |
} |
| 333 |
|
| 334 |
global $wpdb; |
| 335 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 336 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 337 |
} |
| 338 |
|
| 339 |
$av_settings = get_option( 'wpsc-tl-ms-agent-view' ); |
| 340 |
|
| 341 |
$view_settings = apply_filters( |
| 342 |
'wpsc_tl_ms_agent_view', |
| 343 |
array( |
| 344 |
'default-sort-by' => isset( $_POST['default-sort-by'] ) ? sanitize_text_field( wp_unslash( $_POST['default-sort-by'] ) ) : 'date_created', |
| 345 |
'default-sort-order' => isset( $_POST['default-sort-order'] ) ? sanitize_text_field( wp_unslash( $_POST['default-sort-order'] ) ) : 'DESC', |
| 346 |
'number-of-tickets' => isset( $_POST['number-of-tickets'] ) ? intval( $_POST['number-of-tickets'] ) : 20, |
| 347 |
'unresolved-ticket-statuses' => isset( $_POST['unresolved-ticket-statuses'] ) ? array_filter( array_map( 'intval', $_POST['unresolved-ticket-statuses'] ) ) : array( 1, 2, 3 ), |
| 348 |
'default-filter' => isset( $_POST['default-filter'] ) ? sanitize_text_field( wp_unslash( $_POST['default-filter'] ) ) : 'all', |
| 349 |
'ticket-reply-redirect' => isset( $_POST['ticket-reply-redirect'] ) ? sanitize_text_field( wp_unslash( $_POST['ticket-reply-redirect'] ) ) : 'no-redirect', |
| 350 |
) |
| 351 |
); |
| 352 |
update_option( 'wpsc-tl-ms-agent-view', $view_settings ); |
| 353 |
|
| 354 |
// schedule reset agent counts. |
| 355 |
if ( |
| 356 |
array_diff( $av_settings['unresolved-ticket-statuses'], $view_settings['unresolved-ticket-statuses'] ) || |
| 357 |
array_diff( $view_settings['unresolved-ticket-statuses'], $av_settings['unresolved-ticket-statuses'] ) |
| 358 |
) { |
| 359 |
$wpdb->update( |
| 360 |
$wpdb->prefix . 'psmsc_agents', |
| 361 |
array( |
| 362 |
'workload' => null, |
| 363 |
'unresolved_count' => null, |
| 364 |
), |
| 365 |
array( |
| 366 |
'is_agentgroup' => 0, |
| 367 |
'is_active' => 1, |
| 368 |
), |
| 369 |
); |
| 370 |
update_option( 'wpsc-unresolved-reset-status', 0 ); |
| 371 |
} |
| 372 |
wp_die(); |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* Reset settings to default |
| 377 |
* |
| 378 |
* @return void |
| 379 |
*/ |
| 380 |
public static function tl_ms_reset_agent_view() { |
| 381 |
|
| 382 |
if ( check_ajax_referer( 'wpsc_tl_ms_reset_agent_view', '_ajax_nonce', false ) != 1 ) { |
| 383 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 384 |
} |
| 385 |
|
| 386 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 387 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 388 |
} |
| 389 |
self::tl_ms_default_agent(); |
| 390 |
wp_die(); |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* Get customer view settings |
| 395 |
*/ |
| 396 |
public static function tl_ms_get_customer_view() { |
| 397 |
|
| 398 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 399 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 400 |
} |
| 401 |
|
| 402 |
$statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; |
| 403 |
$custom_fields = WPSC_Custom_Field::$custom_fields; |
| 404 |
$list_tems = get_option( 'wpsc-ctl-list-items' ); |
| 405 |
$customer_view = get_option( 'wpsc-tl-ms-customer-view', array() ); |
| 406 |
$default_filters = get_option( 'wpsc-ctl-default-filters', array() ); |
| 407 |
?> |
| 408 |
|
| 409 |
<form action="#" onsubmit="return false;" class="wpsc-frm-tl-ms-customer-view"> |
| 410 |
<div class="wpsc-input-group"> |
| 411 |
<div class="label-container"> |
| 412 |
<label for=""><?php esc_attr_e( 'Default sort by', 'supportcandy' ); ?></label> |
| 413 |
</div> |
| 414 |
<select id="wpsc-customer-default-sort-by" name="default-sort-by"> |
| 415 |
<?php |
| 416 |
foreach ( $list_tems as $slug ) : |
| 417 |
$cf = WPSC_Custom_Field::get_cf_by_slug( $slug ); |
| 418 |
if ( ! $cf ) { |
| 419 |
continue; |
| 420 |
} |
| 421 |
if ( $cf->type::$is_sort ) : |
| 422 |
?> |
| 423 |
<option <?php selected( $cf->slug, $customer_view['default-sort-by'] ); ?>value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option> |
| 424 |
<?php |
| 425 |
endif; |
| 426 |
endforeach; |
| 427 |
?> |
| 428 |
</select> |
| 429 |
</div> |
| 430 |
<div class="wpsc-input-group"> |
| 431 |
<div class="label-container"> |
| 432 |
<label for=""><?php esc_attr_e( 'Default sort order', 'supportcandy' ); ?></label> |
| 433 |
</div> |
| 434 |
<select id="wpsc-customer-default-sort-order" name="default-sort-order"> |
| 435 |
<option <?php selected( $customer_view['default-sort-order'], 'DESC' ); ?> value="DESC"><?php esc_attr_e( 'DESC', 'supportcandy' ); ?></option> |
| 436 |
<option <?php selected( $customer_view['default-sort-order'], 'ASC' ); ?> value="ASC"><?php esc_attr_e( 'ASC', 'supportcandy' ); ?></option> |
| 437 |
</select> |
| 438 |
</div> |
| 439 |
<div class="wpsc-input-group"> |
| 440 |
<div class="label-container"> |
| 441 |
<label for=""><?php esc_attr_e( 'Number of tickets', 'supportcandy' ); ?></label> |
| 442 |
</div> |
| 443 |
<input type="number" id="wpsc-customer-number-of-tickets" name="number-of-tickets" value="<?php echo esc_attr( $customer_view['number-of-tickets'] ); ?>" /> |
| 444 |
</div> |
| 445 |
<div class="wpsc-input-group"> |
| 446 |
<div class="label-container"> |
| 447 |
<label for=""><?php esc_attr_e( 'Unresolved statuses', 'supportcandy' ); ?></label> |
| 448 |
</div> |
| 449 |
<select id="wpsc-customer-unresolved-ticket-statuses" multiple="multiple" name="unresolved-ticket-statuses[]"> |
| 450 |
<?php |
| 451 |
foreach ( $statuses as $status ) : |
| 452 |
$selected = in_array( $status->id, $customer_view['unresolved-ticket-statuses'] ) ? 'selected="selected"' : ''; |
| 453 |
?> |
| 454 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $status->id ); ?>"><?php echo esc_attr( $status->name ); ?></option> |
| 455 |
<?php |
| 456 |
endforeach; |
| 457 |
?> |
| 458 |
</select> |
| 459 |
<script> |
| 460 |
jQuery('#wpsc-customer-unresolved-ticket-statuses').selectWoo({ |
| 461 |
allowClear: false, |
| 462 |
placeholder: "" |
| 463 |
}); |
| 464 |
</script> |
| 465 |
</div> |
| 466 |
<div class="wpsc-input-group"> |
| 467 |
<div class="label-container"> |
| 468 |
<label for=""><?php esc_attr_e( 'Default filter', 'supportcandy' ); ?></label> |
| 469 |
</div> |
| 470 |
<select name="default-filter"> |
| 471 |
<optgroup label="<?php esc_attr_e( 'Default filters', 'supportcandy' ); ?>"> |
| 472 |
<?php |
| 473 |
foreach ( $default_filters as $index => $filter ) : |
| 474 |
$selected = $customer_view['default-filter'] == $index || $customer_view['default-filter'] == 'default-' . $index ? 'selected="selected"' : ''; |
| 475 |
$index = is_numeric( $index ) ? 'default-' . $index : $index; |
| 476 |
?> |
| 477 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $index ); ?>"> |
| 478 |
<?php |
| 479 |
$filter_label = $filter['label'] ? WPSC_Translations::get( 'wpsc-ctl-' . $index, stripslashes( $filter['label'] ) ) : stripslashes( $filter['label'] ); |
| 480 |
echo esc_attr( $filter_label ) |
| 481 |
?> |
| 482 |
</option> |
| 483 |
<?php |
| 484 |
endforeach; |
| 485 |
?> |
| 486 |
</optgroup> |
| 487 |
</select> |
| 488 |
</div> |
| 489 |
<div class="wpsc-input-group"> |
| 490 |
<div class="label-container"> |
| 491 |
<label for=""><?php esc_attr_e( 'Ticket reply redirect', 'supportcandy' ); ?></label> |
| 492 |
</div> |
| 493 |
<select id="wpsc-ticket-reply-redirect" name="ticket-reply-redirect"> |
| 494 |
<option <?php selected( $customer_view['ticket-reply-redirect'], 'ticket-list' ); ?> value="ticket-list"><?php esc_attr_e( 'Ticket list', 'supportcandy' ); ?></option> |
| 495 |
<option <?php selected( $customer_view['ticket-reply-redirect'], 'no-redirect' ); ?> value="no-redirect"><?php esc_attr_e( 'No redirect', 'supportcandy' ); ?></option> |
| 496 |
</select> |
| 497 |
</div> |
| 498 |
<?php do_action( 'wpsc_tl_ms_customer_view' ); ?> |
| 499 |
<input type="hidden" name="action" value="wpsc_tl_ms_set_customer_view"> |
| 500 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_ms_set_customer_view' ) ); ?>"> |
| 501 |
</form> |
| 502 |
|
| 503 |
<div class="setting-footer-actions"> |
| 504 |
<button |
| 505 |
class="wpsc-button normal primary margin-right" |
| 506 |
onclick="wpsc_tl_ms_set_customer_view(this);"> |
| 507 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 508 |
<button |
| 509 |
class="wpsc-button normal secondary" |
| 510 |
onclick="wpsc_tl_ms_reset_customer_view (this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_ms_reset_customer_view' ) ); ?>');"> |
| 511 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 512 |
</div> |
| 513 |
<?php |
| 514 |
do_action( 'wpsc_tl_ms_get_customer_footer' ); |
| 515 |
wp_die(); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* Save customer view settings |
| 520 |
* |
| 521 |
* @return void |
| 522 |
*/ |
| 523 |
public static function tl_ms_set_customer_view() { |
| 524 |
|
| 525 |
if ( check_ajax_referer( 'wpsc_tl_ms_set_customer_view', '_ajax_nonce', false ) != 1 ) { |
| 526 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 527 |
} |
| 528 |
|
| 529 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 530 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 531 |
} |
| 532 |
|
| 533 |
$view_settings = apply_filters( |
| 534 |
'wpsc_tl_ms_customer_view', |
| 535 |
array( |
| 536 |
'default-sort-by' => isset( $_POST['default-sort-by'] ) ? sanitize_text_field( wp_unslash( $_POST['default-sort-by'] ) ) : 'date_created', |
| 537 |
'default-sort-order' => isset( $_POST['default-sort-order'] ) ? sanitize_text_field( wp_unslash( $_POST['default-sort-order'] ) ) : 'DESC', |
| 538 |
'number-of-tickets' => isset( $_POST['number-of-tickets'] ) ? intval( $_POST['number-of-tickets'] ) : 20, |
| 539 |
'unresolved-ticket-statuses' => isset( $_POST['unresolved-ticket-statuses'] ) ? array_filter( array_map( 'intval', $_POST['unresolved-ticket-statuses'] ) ) : array(), |
| 540 |
'default-filter' => isset( $_POST['default-filter'] ) ? sanitize_text_field( wp_unslash( $_POST['default-filter'] ) ) : 'all', |
| 541 |
'ticket-reply-redirect' => isset( $_POST['ticket-reply-redirect'] ) ? sanitize_text_field( wp_unslash( $_POST['ticket-reply-redirect'] ) ) : 'no-redirect', |
| 542 |
) |
| 543 |
); |
| 544 |
update_option( 'wpsc-tl-ms-customer-view', $view_settings ); |
| 545 |
wp_die(); |
| 546 |
} |
| 547 |
|
| 548 |
/** |
| 549 |
* Reset settings to default |
| 550 |
* |
| 551 |
* @return void |
| 552 |
*/ |
| 553 |
public static function tl_ms_reset_customer_view() { |
| 554 |
|
| 555 |
if ( check_ajax_referer( 'wpsc_tl_ms_reset_customer_view', '_ajax_nonce', false ) != 1 ) { |
| 556 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 557 |
} |
| 558 |
|
| 559 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 560 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 561 |
} |
| 562 |
self::tl_ms_default_customer(); |
| 563 |
wp_die(); |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* Get advanced settings |
| 568 |
* |
| 569 |
* @return void |
| 570 |
*/ |
| 571 |
public static function tl_ms_get_advanced() { |
| 572 |
|
| 573 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 574 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 575 |
} |
| 576 |
$statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']; |
| 577 |
$advanced_settings = get_option( 'wpsc-tl-ms-advanced', array() ); |
| 578 |
?> |
| 579 |
|
| 580 |
<form action="#" onsubmit="return false;" class="wpsc-frm-advanced-settings"> |
| 581 |
<div class="wpsc-dock-container"> |
| 582 |
<?php |
| 583 |
printf( |
| 584 |
/* translators: Click here to see the documentation */ |
| 585 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 586 |
'<a href="https://supportcandy.net/docs/ticket-list-advance-settings/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 587 |
); |
| 588 |
?> |
| 589 |
</div> |
| 590 |
<div class="wpsc-input-group"> |
| 591 |
<div class="label-container"> |
| 592 |
<label for=""><?php esc_attr_e( 'Closed statuses', 'supportcandy' ); ?></label> |
| 593 |
</div> |
| 594 |
<select id="wpsc-closed-ticket-statuses" multiple="multiple" name="closed-ticket-statuses[]"> |
| 595 |
<?php |
| 596 |
foreach ( $statuses as $status ) : |
| 597 |
$selected = in_array( $status->id, $advanced_settings['closed-ticket-statuses'] ) ? 'selected="selected"' : ''; |
| 598 |
?> |
| 599 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $status->id ); ?>"><?php echo esc_attr( $status->name ); ?></option> |
| 600 |
<?php |
| 601 |
endforeach; |
| 602 |
?> |
| 603 |
</select> |
| 604 |
<script> |
| 605 |
jQuery('#wpsc-closed-ticket-statuses').selectWoo({ |
| 606 |
allowClear: false, |
| 607 |
placeholder: "" |
| 608 |
}); |
| 609 |
</script> |
| 610 |
</div> |
| 611 |
<div class="wpsc-input-group"> |
| 612 |
<div class="label-container"> |
| 613 |
<label for=""><?php esc_attr_e( 'Auto refresh default status', 'supportcandy' ); ?></label> |
| 614 |
</div> |
| 615 |
<select name="wpsc-auto-refresh-list-status"> |
| 616 |
<option <?php selected( $advanced_settings['auto-refresh-list-status'], '1' ); ?> value="1"><?php esc_attr_e( 'On', 'supportcandy' ); ?></option> |
| 617 |
<option <?php selected( $advanced_settings['auto-refresh-list-status'], '0' ); ?> value="0"><?php esc_attr_e( 'Off', 'supportcandy' ); ?></option> |
| 618 |
</select> |
| 619 |
</div> |
| 620 |
<?php do_action( 'wpsc_tl_ms_advanced_settings' ); ?> |
| 621 |
<input type="hidden" name="action" value="wpsc_tl_ms_set_advanced"> |
| 622 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_ms_set_advanced' ) ); ?>"> |
| 623 |
</form> |
| 624 |
|
| 625 |
<div class="setting-footer-actions"> |
| 626 |
<button |
| 627 |
class="wpsc-button normal primary margin-right" |
| 628 |
onclick="wpsc_tl_ms_set_advanced(this);"> |
| 629 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 630 |
<button |
| 631 |
class="wpsc-button normal secondary" |
| 632 |
onclick="wpsc_tl_ms_reset_advanced(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_ms_reset_advanced' ) ); ?>');"> |
| 633 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 634 |
</div> |
| 635 |
<?php |
| 636 |
do_action( 'wpsc_get_add_more_settings_advanced' ); |
| 637 |
wp_die(); |
| 638 |
} |
| 639 |
|
| 640 |
/** |
| 641 |
* Set advanced settings |
| 642 |
* |
| 643 |
* @return void |
| 644 |
*/ |
| 645 |
public static function tl_ms_set_advanced() { |
| 646 |
|
| 647 |
if ( check_ajax_referer( 'wpsc_tl_ms_set_advanced', '_ajax_nonce', false ) != 1 ) { |
| 648 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 649 |
} |
| 650 |
|
| 651 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 652 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 653 |
} |
| 654 |
|
| 655 |
$advanced_settings = apply_filters( |
| 656 |
'wpsc_tl_ms_advanced', |
| 657 |
array( |
| 658 |
'closed-ticket-statuses' => isset( $_POST['closed-ticket-statuses'] ) ? array_filter( array_map( 'intval', $_POST['closed-ticket-statuses'] ) ) : array( 4 ), |
| 659 |
'auto-refresh-list-status' => isset( $_POST['wpsc-auto-refresh-list-status'] ) ? intval( $_POST['wpsc-auto-refresh-list-status'] ) : 0, |
| 660 |
) |
| 661 |
); |
| 662 |
update_option( 'wpsc-tl-ms-advanced', $advanced_settings ); |
| 663 |
wp_die(); |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* Reset settings to default |
| 668 |
* |
| 669 |
* @return void |
| 670 |
*/ |
| 671 |
public static function tl_ms_reset_advanced() { |
| 672 |
|
| 673 |
if ( check_ajax_referer( 'wpsc_tl_ms_reset_advanced', '_ajax_nonce', false ) != 1 ) { |
| 674 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 675 |
} |
| 676 |
|
| 677 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 678 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 679 |
} |
| 680 |
self::tl_ms_default_advanced(); |
| 681 |
wp_die(); |
| 682 |
} |
| 683 |
} |
| 684 |
endif; |
| 685 |
|
| 686 |
WPSC_Ticket_List_More_Settings::init(); |
| 687 |
|