# supportcandy/2.3.1/includes/admin/settings/get_status_settings.php

SupportCandy – AI Customer Support Ticket System &amp; Live Chatbot Agent, version 2.3.1. 197 lines.

- Page: https://pluginprobe.com/plugins/supportcandy/2.3.1/code/includes/admin/settings/get_status_settings.php
- Raw: https://pluginprobe.com/plugins/supportcandy/2.3.1/raw/includes/admin/settings/get_status_settings.php
- Modified: 2022-07-21T08:20:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/supportcandy/2.3.1/code/includes/admin/settings/get_status_settings.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $current_user, $wpdb;
if (!($current_user->ID && $current_user->has_cap('manage_options'))) {
	exit;
}

$statuses = get_terms([
	'taxonomy'   => 'wpsc_statuses',
	'hide_empty' => false,
	'orderby'    => 'meta_value_num',
	'order'    	 => 'ASC',
	'meta_query' => array('order_clause' => array('key' => 'wpsc_status_load_order')),
]);

?>
<h4>
	<?php _e('Ticket Statuses','supportcandy');?>
	<button style="margin-left:10px;" class="btn btn-success btn-sm" onclick="wpsc_get_add_status();"><?php _e('+Add New','supportcandy');?></button>
</h4>

<div class="wpsc_padding_space"></div>

<ul class="wpsc-sortable">
	<?php foreach ( $statuses as $status ) :
    $color = get_term_meta( $status->term_id, 'wpsc_status_color', true);
    $backgound_color = get_term_meta( $status->term_id, 'wpsc_status_background_color', true);
    ?>
		<li class="ui-state-default" data-id="<?php echo esc_attr($status->term_id)?>">
			<div class="wpsc-flex-container" style="background-color:<?php echo esc_attr($backgound_color)?>;color:<?php echo esc_attr($color)?>;">
				<div class="wpsc-sortable-handle"><i class="fa fa-bars"></i></div>
				<div class="wpsc-sortable-label"><?php echo esc_attr($status->name)?></div>
				<div class="wpsc-sortable-edit" onclick="wpsc_get_edit_status(<?php echo esc_attr($status->term_id)?>);"><i class="fa fa-edit"></i></div>
				<div class="wpsc-sortable-delete" onclick="wpsc_delete_status(<?php echo esc_attr($status->term_id)?>);"><i class="fa fa-trash"></i></div>
			</div>
		</li>
	<?php endforeach;?>
</ul>

<script>
	
	jQuery(function(){
    jQuery( ".wpsc-sortable" ).sortable({ handle: '.wpsc-sortable-handle' });
		jQuery( ".wpsc-sortable" ).on("sortupdate",function(event,ui){
			var ids = jQuery(this).sortable( "toArray", {attribute: 'data-id'} );
			var data = {
				action: 'wpsc_settings',
				setting_action : 'set_status_order',
				status_ids : ids,
				_ajax_nonce: '<?php echo wp_create_nonce('set_status_order')?>'
		  	};
			jQuery.post(wpsc_admin.ajax_url, data, function(response_str) {
				var response = JSON.parse(response_str);
		    if (response.sucess_status=='1') {
		      jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege);
		    }
		    jQuery('#wpsc_alert_success').slideDown('fast',function(){});
		    setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000);
		  });
		});
	});
	
	function wpsc_get_add_status(){
		wpsc_modal_open(wpsc_admin.add_new_status);
		var data = {
			action: 'wpsc_settings',
			setting_action : 'get_add_status'
		};
		jQuery.post(wpsc_admin.ajax_url, data, function(response) {
			jQuery('#wpsc_popup_body').html(response.body);
			jQuery('#wpsc_popup_footer').html(response.footer);
			jQuery('#wpsc_cat_name').focus();
		});
	}
	
	function wpsc_set_add_status(){
		var status_name = jQuery('#wpsc_status_name').val().trim();
		if (status_name.length == 0) {
			jQuery('#wpsc_status_name').val('').focus();
			return;
		}
		var status_color = jQuery('#wpsc_status_color').val().trim();
		if (status_color.length == 0) {
			status_color = '#ffffff';
		}
		var status_bg_color = jQuery('#wpsc_status_bg_color').val().trim();
		if (status_bg_color.length == 0) {
			status_bg_color = '#1E90FF';
		}
		jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>');
		jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled");
		var data = {
			action: 'wpsc_settings',
			setting_action : 'set_add_status',
			status_name : status_name,
			status_color: status_color,
			status_bg_color: status_bg_color,
			_ajax_nonce: '<?php echo wp_create_nonce('set_add_status')?>'
		};
		jQuery.post(wpsc_admin.ajax_url, data, function(response_str) {
			wpsc_modal_close();
			var response = JSON.parse(response_str);
			if (response.sucess_status=='1') {
				jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege);
				jQuery('#wpsc_alert_success').slideDown('fast',function(){});
				setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000);
				wpsc_get_status_settings();
			} else {
				jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege);
				jQuery('#wpsc_alert_error').slideDown('fast',function(){});
				setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000);
			}
		});
	}
	
	function wpsc_get_edit_status(status_id){
		wpsc_modal_open(wpsc_admin.edit_status);
		var data = {
			action: 'wpsc_settings',
			setting_action : 'get_edit_status',
			status_id : status_id
		};
		jQuery.post(wpsc_admin.ajax_url, data, function(response) {
			jQuery('#wpsc_popup_body').html(response.body);
			jQuery('#wpsc_popup_footer').html(response.footer);
			jQuery('#wpsc_status_name').focus();
		});
	}
	
	function wpsc_set_edit_status(status_id){
		var status_name = jQuery('#wpsc_status_name').val().trim();
		if (status_name.length == 0) {
			jQuery('#wpsc_status_name').val('').focus();
			return;
		}
		var status_color = jQuery('#wpsc_status_color').val().trim();
		if (status_color.length == 0) {
			status_color = '#ffffff';
		}
		var status_bg_color = jQuery('#wpsc_status_bg_color').val().trim();
		if (status_bg_color.length == 0) {
			status_bg_color = '#1E90FF';
		}
		jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>');
		jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled");
		var data = {
			action: 'wpsc_settings',
			setting_action : 'set_edit_status',
			status_id : status_id,
			status_name : status_name,
			status_color: status_color,
			status_bg_color: status_bg_color,
			_ajax_nonce: '<?php echo wp_create_nonce('set_edit_status')?>'
		};
		jQuery.post(wpsc_admin.ajax_url, data, function(response_str) {
			wpsc_modal_close();
			var response = JSON.parse(response_str);
			if (response.sucess_status=='1') {
				wpsc_get_status_settings();
			} else {
				jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege);
				jQuery('#wpsc_alert_error').slideDown('fast',function(){});
				setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000);
			}
		});
	}
	
	function wpsc_delete_status(status_id){
		var flag = confirm(wpsc_admin.are_you_sure);
		if (flag) {
			var data = {
				action: 'wpsc_settings',
				setting_action : 'delete_status',
				status_id : status_id,
				_ajax_nonce: '<?php echo wp_create_nonce('delete_status')?>'
			};
			jQuery.post(wpsc_admin.ajax_url, data, function(response_str) {
				var response = JSON.parse(response_str);
				if (response.sucess_status=='1') {
					jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege);
					jQuery('#wpsc_alert_success').slideDown('fast',function(){});
					setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000);
					wpsc_get_status_settings();
				} else {
					jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege);
					jQuery('#wpsc_alert_error').slideDown('fast',function(){});
					setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000);
				}
			});
		}
	}
	
</script>

```
