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
← All changes | includes/admin/settings/class-wpsc-ticket-statuses.php +84 -9 3.4.0 → 3.5.4 View file →
@@ -25,8 +25,11 @@
25 25
26 26 // Delete.
27 27 add_action( 'wp_ajax_wpsc_get_delete_status', array( __CLASS__, 'get_delete_status' ) );
28 28 add_action( 'wp_ajax_wpsc_set_delete_status', array( __CLASS__, 'set_delete_status' ) );
29 +
30 + // Sorting.
31 + add_action( 'wp_ajax_wpsc_set_status_load_order', array( __CLASS__, 'set_status_load_order' ) );
29 32 }
30 33
31 34 /**
32 35 * Get status settings
@@ -60,8 +63,9 @@
60 63 </div>
61 64 <table class="wpsc-ticket-statuses wpsc-setting-tbl">
62 65 <thead>
63 66 <tr>
67 + <th style="width: 30px;"><?php esc_attr_e( 'Sort', 'supportcandy' ); ?></th>
64 68 <th><?php esc_attr_e( 'Name', 'supportcandy' ); ?></th>
65 69 <th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th>
66 70 </tr>
67 71 </thead>
@@ -68,15 +72,16 @@
68 72 <tbody>
69 73 <?php
70 74 foreach ( $statuses as $status ) {
71 75 ?>
72 - <tr>
76 + <tr data-id="<?php echo esc_attr( $status->id ); ?>">
77 + <td class="sort-handle"><?php WPSC_Icons::get( 'sort' ); ?></td>
73 78 <td><span class="wpsc-tag" style="color: <?php echo esc_attr( $status->color ); ?>; background-color: <?php echo esc_attr( $status->bg_color ); ?>;" ><?php echo esc_attr( $status->name ); ?></span></td>
74 79 <td>
75 80 <div class="actions">
76 - <a class="wpsc-link" href="javascript:wpsc_get_edit_status(<?php echo esc_attr( $status->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_status' ) ); ?>');" ><?php echo esc_attr__( 'Edit', 'supportcandy' ); ?></a>
81 + <span class="wpsc-link" onclick="wpsc_get_edit_status(<?php echo esc_attr( $status->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_status' ) ); ?>');" ><?php echo esc_attr__( 'Edit', 'supportcandy' ); ?></span>
77 82 <?php if ( ! in_array( $status->id, $default_statuses ) ) : ?>
78 - | <a class="wpsc-link" href="javascript:wpsc_get_delete_status(<?php echo esc_attr( $status->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_delete_status' ) ); ?>');" ><?php echo esc_attr__( 'Delete', 'supportcandy' ); ?></a>
83 + | <span class="wpsc-link" onclick="wpsc_get_delete_status(<?php echo esc_attr( $status->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_delete_status' ) ); ?>');" ><?php echo esc_attr__( 'Delete', 'supportcandy' ); ?></span>
79 84 <?php
80 85 endif;
81 86 ?>
82 87 </div>
@@ -90,11 +95,13 @@
90 95 </div>
91 96 <script>
92 97 jQuery('table.wpsc-ticket-statuses').DataTable({
93 98 ordering: false,
99 + autoWidth: false,
94 100 pageLength: 20,
95 101 bLengthChange: false,
96 - columnDefs: [
102 + columnDefs: [
103 + { targets: 0, width: '30px', searchable: false },
97 104 { targets: -1, searchable: false },
98 105 { targets: '_all', className: 'dt-left' }
99 106 ],
100 107 layout: {
@@ -125,8 +132,37 @@
125 132 },
126 133 },
127 134 language: supportcandy.translations.datatables
128 135 });
136 +
137 + jQuery(function() {
138 + // Enable sorting with jQuery UI.
139 + jQuery('table.wpsc-ticket-statuses tbody').sortable({
140 + handle: '.sort-handle',
141 + helper: function(e, tr) {
142 + var $originals = tr.children();
143 + var $helper = tr.clone();
144 + $helper.children().each(function(index) {
145 + jQuery(this).width($originals.eq(index).width());
146 + });
147 + return $helper;
148 + },
149 + update: function(event, ui) {
150 + var ids = jQuery(this).sortable('toArray', { attribute: 'data-id' });
151 + jQuery.post(
152 + supportcandy.ajax_url,
153 + {
154 + action: 'wpsc_set_status_load_order',
155 + _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_set_status_load_order' ) ); ?>',
156 + ids: ids
157 + },
158 + function(response) {
159 +
160 + }
161 + );
162 + }
163 + });
164 + });
129 165 </script>
130 166 <?php
131 167 wp_die();
132 168 }
@@ -219,9 +255,9 @@
219 255 */
220 256 public static function set_add_status() {
221 257
222 258 if ( check_ajax_referer( 'wpsc_set_add_status', '_ajax_nonce', false ) != 1 ) {
223 - wp_send_json_error( 'Unauthorised request!', 401 );
259 + wp_send_json_error( 'Unauthorized request!', 401 );
224 260 }
225 261
226 262 if ( ! WPSC_Functions::is_site_admin() ) {
227 263 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
@@ -232,13 +268,15 @@
232 268 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
233 269 }
234 270
235 271 $color = isset( $_POST['color'] ) ? sanitize_text_field( wp_unslash( $_POST['color'] ) ) : '';
272 + $color = ( 'transparent' === $color ) ? $color : sanitize_hex_color( $color );
236 273 if ( ! $color ) {
237 274 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
238 275 }
239 276
240 277 $bgcolor = isset( $_POST['bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['bg-color'] ) ) : '';
278 + $bgcolor = ( 'transparent' === $bgcolor ) ? $bgcolor : sanitize_hex_color( $bgcolor );
241 279 if ( ! $bgcolor ) {
242 280 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
243 281 }
244 282
@@ -288,9 +326,9 @@
288 326
289 327 global $wpdb;
290 328
291 329 if ( check_ajax_referer( 'wpsc_get_edit_status', '_ajax_nonce', false ) != 1 ) {
292 - wp_send_json_error( 'Unauthorised request!', 401 );
330 + wp_send_json_error( 'Unauthorized request!', 401 );
293 331 }
294 332
295 333 if ( ! WPSC_Functions::is_site_admin() ) {
296 334 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
@@ -393,9 +431,9 @@
393 431
394 432 global $wpdb;
395 433
396 434 if ( check_ajax_referer( 'wpsc_set_edit_status', '_ajax_nonce', false ) != 1 ) {
397 - wp_send_json_error( 'Unauthorised request!', 401 );
435 + wp_send_json_error( 'Unauthorized request!', 401 );
398 436 }
399 437
400 438 if ( ! WPSC_Functions::is_site_admin() ) {
401 439 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
@@ -411,13 +449,15 @@
411 449 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
412 450 }
413 451
414 452 $color = isset( $_POST['color'] ) ? sanitize_text_field( wp_unslash( $_POST['color'] ) ) : '';
453 + $color = ( 'transparent' === $color ) ? $color : sanitize_hex_color( $color );
415 454 if ( ! $color ) {
416 455 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
417 456 }
418 457
419 458 $bgcolor = isset( $_POST['bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['bg-color'] ) ) : '';
459 + $bgcolor = ( 'transparent' === $bgcolor ) ? $bgcolor : sanitize_hex_color( $bgcolor );
420 460 if ( ! $bgcolor ) {
421 461 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
422 462 }
423 463
@@ -479,9 +519,9 @@
479 519 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
480 520 }
481 521
482 522 if ( check_ajax_referer( 'wpsc_get_delete_status', '_ajax_nonce', false ) != 1 ) {
483 - wp_send_json_error( 'Unauthorised request!', 401 );
523 + wp_send_json_error( 'Unauthorized request!', 401 );
484 524 }
485 525
486 526 $title = esc_attr__( 'Delete status', 'supportcandy' );
487 527
@@ -554,9 +594,9 @@
554 594 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
555 595 }
556 596
557 597 if ( check_ajax_referer( 'wpsc_set_delete_status', '_ajax_nonce', false ) != 1 ) {
558 - wp_send_json_error( 'Unauthorised request!', 401 );
598 + wp_send_json_error( 'Unauthorized request!', 401 );
559 599 }
560 600
561 601 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
562 602 if ( ! $id ) {
@@ -618,8 +658,43 @@
618 658 }
619 659
620 660 $status->destroy( $status );
621 661 wp_die();
662 + }
663 +
664 + /**
665 + * Set load order for ticket statuses
666 + *
667 + * @return void
668 + */
669 + public static function set_status_load_order() {
670 +
671 + if ( check_ajax_referer( 'wpsc_set_status_load_order', '_ajax_nonce', false ) != 1 ) {
672 + wp_send_json_error( 'Unauthorized request!', 400 );
673 + }
674 +
675 + if ( ! WPSC_Functions::is_site_admin() ) {
676 + wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
677 + }
678 +
679 + $ids = isset( $_POST['ids'] ) ? array_map( 'intval', wp_unslash( $_POST['ids'] ) ) : array();
680 + if ( ! $ids ) {
681 + wp_send_json_error( 'Bad Request', 400 );
682 + }
683 +
684 + $count = 1;
685 + foreach ( $ids as $id ) {
686 +
687 + $status = new WPSC_Status( $id );
688 + if ( ! $status->id ) {
689 + continue;
690 + }
691 +
692 + $status->load_order = $count++;
693 + $status->save();
694 + }
695 +
696 + wp_send_json( array( 'success' => true ), 200 );
622 697 }
623 698 }
624 699 endif;
625 700