| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpdb; |
| 7 |
if (!($current_user->ID && $current_user->has_cap('manage_options'))) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
$fields = get_terms([ |
| 12 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 13 |
'hide_empty' => false, |
| 14 |
'orderby' => 'meta_value_num', |
| 15 |
'meta_key' => 'wpsc_tf_load_order', |
| 16 |
'order' => 'ASC', |
| 17 |
'meta_query' => array( |
| 18 |
array( |
| 19 |
'key' => 'agentonly', |
| 20 |
'value' => '1', |
| 21 |
'compare' => '=' |
| 22 |
) |
| 23 |
), |
| 24 |
]); |
| 25 |
|
| 26 |
?> |
| 27 |
<h4> |
| 28 |
<?php _e('Agent Only Fields','supportcandy');?> |
| 29 |
<button style="margin-left:10px;" class="btn btn-success btn-sm" onclick="wpsc_get_add_agentonly_field();"><?php _e('+Add New','supportcandy');?></button> |
| 30 |
</h4> |
| 31 |
|
| 32 |
<div class="wpsc_padding_space"></div> |
| 33 |
|
| 34 |
<ul class="wpsc-sortable"> |
| 35 |
<?php foreach ( $fields as $field ) : |
| 36 |
$label = get_term_meta( $field->term_id, 'wpsc_tf_label', true); |
| 37 |
?> |
| 38 |
<li class="ui-state-default" data-id="<?php echo esc_attr($field->term_id)?>"> |
| 39 |
<div class="wpsc-flex-container" style="background-color:#1E90FF;color:#fff;"> |
| 40 |
<div class="wpsc-sortable-handle"><i class="fa fa-bars"></i></div> |
| 41 |
<div class="wpsc-sortable-label"><?php echo esc_attr($label)?></div> |
| 42 |
<div class="wpsc-sortable-edit" onclick="wpsc_get_edit_agentonly_field(<?php echo esc_attr($field->term_id)?>);"><i class="fa fa-edit"></i></div> |
| 43 |
<div class="wpsc-sortable-delete" onclick="wpsc_delete_custom_field(<?php echo esc_attr($field->term_id)?>);"><i class="fa fa-trash"></i></div> |
| 44 |
</div> |
| 45 |
</li> |
| 46 |
<?php endforeach;?> |
| 47 |
</ul> |
| 48 |
|
| 49 |
<script> |
| 50 |
|
| 51 |
jQuery(function(){ |
| 52 |
jQuery( ".wpsc-sortable" ).sortable({ handle: '.wpsc-sortable-handle' }); |
| 53 |
jQuery( ".wpsc-sortable" ).on("sortupdate",function(event,ui){ |
| 54 |
var ids = jQuery(this).sortable( "toArray", {attribute: 'data-id'} ); |
| 55 |
var data = { |
| 56 |
action: 'wpsc_custom_fields', |
| 57 |
setting_action : 'set_form_field_order', |
| 58 |
field_ids : ids, |
| 59 |
_ajax_nonce: '<?php echo wp_create_nonce('set_form_field_order')?>', |
| 60 |
}; |
| 61 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 62 |
var response = JSON.parse(response_str); |
| 63 |
if (response.sucess_status=='1') { |
| 64 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 65 |
} |
| 66 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 67 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 68 |
}); |
| 69 |
}); |
| 70 |
}); |
| 71 |
|
| 72 |
function wpsc_get_add_agentonly_field(){ |
| 73 |
wpsc_modal_open(wpsc_admin.add_new_agent_only_field); |
| 74 |
var data = { |
| 75 |
action: 'wpsc_custom_fields', |
| 76 |
setting_action : 'get_add_agentonly_field' |
| 77 |
}; |
| 78 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 79 |
jQuery('#wpsc_popup_body').html(response.body); |
| 80 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 81 |
jQuery('#wpsc_tf_label').focus(); |
| 82 |
}); |
| 83 |
} |
| 84 |
|
| 85 |
function wpsc_set_add_agentonly_field(){ |
| 86 |
var field_label = jQuery('#wpsc_tf_label').val().trim(); |
| 87 |
if (field_label.length == 0) { |
| 88 |
jQuery('#wpsc_tf_label').val('').focus(); |
| 89 |
return; |
| 90 |
} |
| 91 |
var extra_info = jQuery('#wpsc_tf_extra_info').val().trim(); |
| 92 |
var personal_info = jQuery('#wpsc_tf_personal_info').val().trim(); |
| 93 |
var field_type = jQuery('#wpsc_tf_type').val().trim(); |
| 94 |
var field_options = jQuery('#wpsc_tf_options').val().trim(); |
| 95 |
var limit = jQuery('#wpsc_cf_limit').val(); |
| 96 |
var date_range = jQuery('#wpsc_date_range').val().trim(); |
| 97 |
var date_range_from = jQuery('#wpsc_dcf_from').val().trim(); |
| 98 |
var date_range_to = jQuery('#wpsc_dcf_to').val().trim(); |
| 99 |
|
| 100 |
if (jQuery('#wpsc_tf_type option:selected').data('options')=='1' && field_options=='') { |
| 101 |
jQuery('#wpsc_tf_options').val('').focus(); |
| 102 |
return; |
| 103 |
} |
| 104 |
|
| 105 |
var time_format = jQuery('#wpsc_tf_time_format').val().trim(); |
| 106 |
|
| 107 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 108 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 109 |
var data = { |
| 110 |
action: 'wpsc_custom_fields', |
| 111 |
setting_action : 'set_add_agentonly_field', |
| 112 |
_ajax_nonce: '<?php echo wp_create_nonce('set_add_agentonly_field')?>', |
| 113 |
field_label : field_label, |
| 114 |
extra_info : extra_info, |
| 115 |
field_type : field_type, |
| 116 |
field_options : field_options, |
| 117 |
personal_info : personal_info, |
| 118 |
limit : limit, |
| 119 |
date_range : date_range, |
| 120 |
time_format:time_format, |
| 121 |
date_range_from : date_range_from, |
| 122 |
date_range_to : date_range_to |
| 123 |
}; |
| 124 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 125 |
wpsc_modal_close(); |
| 126 |
var response = JSON.parse(response_str); |
| 127 |
if (response.sucess_status=='1') { |
| 128 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 129 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 130 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 131 |
wpsc_get_agentonly_fields(); |
| 132 |
} else { |
| 133 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 134 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 135 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 136 |
} |
| 137 |
}); |
| 138 |
} |
| 139 |
|
| 140 |
function wpsc_get_edit_agentonly_field(field_id){ |
| 141 |
wpsc_modal_open(wpsc_admin.edit_agent_only_field); |
| 142 |
var data = { |
| 143 |
action: 'wpsc_custom_fields', |
| 144 |
setting_action : 'get_edit_agentonly_field', |
| 145 |
field_id : field_id |
| 146 |
}; |
| 147 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 148 |
jQuery('#wpsc_popup_body').html(response.body); |
| 149 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 150 |
jQuery('#wpsc_tf_label').focus(); |
| 151 |
}); |
| 152 |
} |
| 153 |
|
| 154 |
function wpsc_set_edit_agentonly_field(field_id){ |
| 155 |
var field_label = jQuery('#wpsc_tf_label').val().trim(); |
| 156 |
if (field_label.length == 0) { |
| 157 |
jQuery('#wpsc_tf_label').val('').focus(); |
| 158 |
return; |
| 159 |
} |
| 160 |
var extra_info = jQuery('#wpsc_tf_extra_info').val().trim(); |
| 161 |
var personal_info = jQuery('#wpsc_tf_personal_info').val().trim(); |
| 162 |
var field_type = jQuery('#wpsc_tf_type').val().trim(); |
| 163 |
var field_options = jQuery('#wpsc_tf_options').val().trim(); |
| 164 |
var limit = jQuery('#wpsc_ao_limit').val(); |
| 165 |
var date_range = jQuery('#wpsc_date_range').val().trim(); |
| 166 |
var date_range_from = jQuery('#wpsc_dcf_from').val().trim(); |
| 167 |
var date_range_to = jQuery('#wpsc_dcf_to').val().trim(); |
| 168 |
if (jQuery('#wpsc_tf_type option:selected').data('options')=='1' && field_options=='') { |
| 169 |
jQuery('#wpsc_tf_options').val('').focus(); |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
var time_format = jQuery('#wpsc_tf_time_format').val().trim(); |
| 174 |
|
| 175 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 176 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 177 |
var data = { |
| 178 |
action: 'wpsc_custom_fields', |
| 179 |
setting_action : 'set_edit_agentonly_field', |
| 180 |
_ajax_nonce: '<?php echo wp_create_nonce('set_edit_agentonly_field')?>', |
| 181 |
field_id : field_id, |
| 182 |
field_label : field_label, |
| 183 |
extra_info : extra_info, |
| 184 |
field_type : field_type, |
| 185 |
field_options : field_options, |
| 186 |
personal_info : personal_info, |
| 187 |
limit : limit, |
| 188 |
date_range : date_range, |
| 189 |
date_range_from : date_range_from, |
| 190 |
date_range_to : date_range_to, |
| 191 |
time_format:time_format |
| 192 |
}; |
| 193 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 194 |
wpsc_modal_close(); |
| 195 |
var response = JSON.parse(response_str); |
| 196 |
if (response.sucess_status=='1') { |
| 197 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 198 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 199 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 200 |
wpsc_get_agentonly_fields(); |
| 201 |
} else { |
| 202 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 203 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 204 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 205 |
} |
| 206 |
}); |
| 207 |
} |
| 208 |
|
| 209 |
function wpsc_delete_custom_field(field_id){ |
| 210 |
|
| 211 |
var flag = confirm(wpsc_admin.are_you_sure); |
| 212 |
if (flag) { |
| 213 |
var data = { |
| 214 |
action: 'wpsc_custom_fields', |
| 215 |
setting_action : 'delete_custom_field', |
| 216 |
field_id : field_id, |
| 217 |
_ajax_nonce: '<?php echo wp_create_nonce('delete_custom_field')?>', |
| 218 |
}; |
| 219 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 220 |
var response = JSON.parse(response_str); |
| 221 |
if (response.sucess_status=='1') { |
| 222 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 223 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 224 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 225 |
wpsc_get_agentonly_fields(); |
| 226 |
} else { |
| 227 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 228 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 229 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 230 |
} |
| 231 |
}); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
</script> |
| 236 |
|