| 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' => '0', |
| 21 |
'compare' => '=' |
| 22 |
) |
| 23 |
), |
| 24 |
]); |
| 25 |
|
| 26 |
?> |
| 27 |
<h4> |
| 28 |
<?php _e('Ticket Form Fields','supportcandy');?> |
| 29 |
<button style="margin-left:10px;" class="btn btn-success btn-sm" id="wpsc_add_new_form_field_btn" onclick="wpsc_get_add_form_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 |
$type = get_term_meta( $field->term_id, 'wpsc_tf_type', true); |
| 38 |
$status = get_term_meta( $field->term_id, 'wpsc_tf_status', true); |
| 39 |
$bg_color = $status == '1' ? '#1E90FF' : '#ff0000'; |
| 40 |
?> |
| 41 |
<li class="ui-state-default" data-id="<?php echo esc_attr($field->term_id)?>"> |
| 42 |
<div class="wpsc-flex-container" style="background-color:<?php echo esc_attr($bg_color)?>;color:#fff;"> |
| 43 |
<div class="wpsc-sortable-handle"><i class="fa fa-bars"></i></div> |
| 44 |
<div class="wpsc-sortable-label"><?php echo esc_attr($label)?></div> |
| 45 |
<?php do_action('wpsc_before_form_fields_edit_option',$field->term_id) ?> |
| 46 |
<div class="wpsc-sortable-edit" onclick="<?php echo esc_attr($type)!='0'? 'wpsc_get_edit_form_field('.esc_attr($field->term_id).');' : 'wpsc_get_edit_default_form_field('.esc_attr($field->term_id).');'?>"><i class="fa fa-edit"></i></div> |
| 47 |
<div class="wpsc-sortable-delete" onclick="wpsc_delete_custom_field(<?php echo esc_attr($field->term_id)?>);"><i class="fa fa-trash"></i></div> |
| 48 |
</div> |
| 49 |
</li> |
| 50 |
<?php endforeach;?> |
| 51 |
</ul> |
| 52 |
|
| 53 |
<script> |
| 54 |
|
| 55 |
jQuery(function(){ |
| 56 |
jQuery( ".wpsc-sortable" ).sortable({ handle: '.wpsc-sortable-handle' }); |
| 57 |
jQuery( ".wpsc-sortable" ).on("sortupdate",function(event,ui){ |
| 58 |
var ids = jQuery(this).sortable( "toArray", {attribute: 'data-id'} ); |
| 59 |
var data = { |
| 60 |
action: 'wpsc_custom_fields', |
| 61 |
setting_action : 'set_form_field_order', |
| 62 |
field_ids : ids, |
| 63 |
_ajax_nonce: '<?php echo wp_create_nonce('set_form_field_order')?>' |
| 64 |
}; |
| 65 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 66 |
var response = JSON.parse(response_str); |
| 67 |
if (response.sucess_status=='1') { |
| 68 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 69 |
} |
| 70 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 71 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 72 |
}); |
| 73 |
}); |
| 74 |
}); |
| 75 |
|
| 76 |
function wpsc_get_add_form_field(){ |
| 77 |
wpsc_modal_open(wpsc_admin.add_new_form_field); |
| 78 |
var data = { |
| 79 |
action: 'wpsc_custom_fields', |
| 80 |
setting_action : 'get_add_form_field' |
| 81 |
}; |
| 82 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 83 |
jQuery('#wpsc_popup_body').html(response.body); |
| 84 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 85 |
jQuery('#wpsc_tf_label').focus(); |
| 86 |
}); |
| 87 |
} |
| 88 |
|
| 89 |
function wpsc_set_add_form_field(){ |
| 90 |
var field_label = jQuery('#wpsc_tf_label').val().trim(); |
| 91 |
if (field_label.length == 0) { |
| 92 |
jQuery('#wpsc_tf_label').val('').focus(); |
| 93 |
return; |
| 94 |
} |
| 95 |
var extra_info = jQuery('#wpsc_tf_extra_info').val().trim(); |
| 96 |
var personal_info = jQuery('#wpsc_tf_personal_info').val().trim(); |
| 97 |
var field_type = jQuery('#wpsc_tf_type').val().trim(); |
| 98 |
var wpsc_tf_placeholder_text = jQuery('#wpsc_tf_placeholder_text').val().trim(); |
| 99 |
var field_options = jQuery('#wpsc_tf_options').val().trim(); |
| 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 |
if(field_type=='22'){ |
| 106 |
if ((typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden()) { |
| 107 |
var html_content = tinyMCE.activeEditor.getContent(); |
| 108 |
if(html_content.trim().length==0){ |
| 109 |
jQuery('#wpsc_html_content').val('').focus(); |
| 110 |
return; |
| 111 |
} |
| 112 |
}else{ |
| 113 |
var html_content = jQuery('#wpsc_html_content').val().trim(); |
| 114 |
if (jQuery('#wpsc_tf_type option:selected').data('options')=='2' && html_content=='') { |
| 115 |
jQuery('#wpsc_html_content').val('').focus(); |
| 116 |
return; |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
var time_format = jQuery('#wpsc_tf_time_format').val().trim(); |
| 122 |
var required = jQuery('#wpsc_tf_required').val().trim(); |
| 123 |
var width = jQuery('#wpsc_tf_width').val().trim(); |
| 124 |
var visibility = new Array(); |
| 125 |
var limit = jQuery('#wpsc_tf_add_limit').val().trim(); |
| 126 |
var date_range = jQuery('#wpsc_date_range').val().trim(); |
| 127 |
var date_range_from = jQuery('#wpsc_dcf_from').val().trim(); |
| 128 |
var date_range_to = jQuery('#wpsc_dcf_to').val().trim(); |
| 129 |
jQuery('#wpsc_tf_condition_container').find('input').each(function(){ |
| 130 |
visibility.push(jQuery(this).val()); |
| 131 |
}); |
| 132 |
|
| 133 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 134 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 135 |
var data = { |
| 136 |
action: 'wpsc_custom_fields', |
| 137 |
setting_action : 'set_add_form_field', |
| 138 |
_ajax_nonce: '<?php echo wp_create_nonce('set_add_form_field')?>', |
| 139 |
field_label : field_label, |
| 140 |
extra_info : extra_info, |
| 141 |
personal_info : personal_info, |
| 142 |
field_type : field_type, |
| 143 |
wpsc_tf_placeholder_text:wpsc_tf_placeholder_text, |
| 144 |
field_options : field_options, |
| 145 |
required : required, |
| 146 |
width : width, |
| 147 |
limit : limit, |
| 148 |
visibility : visibility, |
| 149 |
html_content : html_content, |
| 150 |
time_format :time_format, |
| 151 |
date_range : date_range, |
| 152 |
date_range_from : date_range_from, |
| 153 |
date_range_to : date_range_to |
| 154 |
}; |
| 155 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 156 |
wpsc_modal_close(); |
| 157 |
var response = JSON.parse(response_str); |
| 158 |
if (response.sucess_status=='1') { |
| 159 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 160 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 161 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 162 |
wpsc_get_ticket_form_fields(); |
| 163 |
} else { |
| 164 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 165 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 166 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 167 |
} |
| 168 |
}); |
| 169 |
} |
| 170 |
|
| 171 |
function wpsc_get_edit_form_field(field_id){ |
| 172 |
wpsc_modal_open(wpsc_admin.edit_form_field); |
| 173 |
var data = { |
| 174 |
action: 'wpsc_custom_fields', |
| 175 |
setting_action : 'get_edit_form_field', |
| 176 |
field_id : field_id |
| 177 |
}; |
| 178 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 179 |
jQuery('#wpsc_popup_body').html(response.body); |
| 180 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 181 |
jQuery('#wpsc_tf_label').focus(); |
| 182 |
}); |
| 183 |
} |
| 184 |
|
| 185 |
function wpsc_set_edit_form_field(field_id){ |
| 186 |
var field_label = jQuery('#wpsc_tf_label').val().trim(); |
| 187 |
if (field_label.length == 0) { |
| 188 |
jQuery('#wpsc_tf_label').val('').focus(); |
| 189 |
return; |
| 190 |
} |
| 191 |
var extra_info = jQuery('#wpsc_tf_extra_info').val().trim(); |
| 192 |
var personal_info = jQuery('#wpsc_tf_personal_info').val().trim(); |
| 193 |
var field_type = jQuery('#wpsc_tf_type').val().trim(); |
| 194 |
var wpsc_tf_placeholder_text = jQuery('#wpsc_tf_placeholder_text').val().trim(); |
| 195 |
var field_options = jQuery('#wpsc_tf_options').val().trim(); |
| 196 |
if (jQuery('#wpsc_tf_type option:selected').data('options')=='1' && field_options=='') { |
| 197 |
jQuery('#wpsc_tf_options').val('').focus(); |
| 198 |
return; |
| 199 |
} |
| 200 |
|
| 201 |
if(field_type == '22'){ |
| 202 |
if ((typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden()) { |
| 203 |
var html_content = tinyMCE.activeEditor.getContent(); |
| 204 |
if(html_content.trim().length==0){ |
| 205 |
jQuery('#wpsc_html_content') . val('') . focus(); |
| 206 |
return; |
| 207 |
} |
| 208 |
}else{ |
| 209 |
var html_content = jQuery('#wpsc_html_content').val().trim(); |
| 210 |
if (jQuery('#wpsc_tf_type option:selected').data('options')=='2' && html_content=='') { |
| 211 |
jQuery('#wpsc_html_content').val('').focus(); |
| 212 |
return; |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
var time_format = jQuery('#wpsc_tf_time_format').val().trim(); |
| 218 |
var required = jQuery('#wpsc_tf_required').val().trim(); |
| 219 |
var width = jQuery('#wpsc_tf_width').val().trim(); |
| 220 |
var visibility = new Array(); |
| 221 |
var limit = jQuery('#wpsc_tf_limit').val(); |
| 222 |
var date_range = jQuery('#wpsc_date_range').val().trim(); |
| 223 |
var date_range_from = jQuery('#wpsc_dcf_from').val().trim(); |
| 224 |
var date_range_to = jQuery('#wpsc_dcf_to').val().trim(); |
| 225 |
|
| 226 |
jQuery('#wpsc_tf_condition_container').find('input').each(function(){ |
| 227 |
visibility.push(jQuery(this).val()); |
| 228 |
}); |
| 229 |
|
| 230 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 231 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 232 |
var data = { |
| 233 |
action: 'wpsc_custom_fields', |
| 234 |
setting_action : 'set_edit_form_field', |
| 235 |
_ajax_nonce: '<?php echo wp_create_nonce('set_edit_form_field')?>', |
| 236 |
field_id : field_id, |
| 237 |
field_label : field_label, |
| 238 |
extra_info : extra_info, |
| 239 |
personal_info : personal_info, |
| 240 |
field_type : field_type, |
| 241 |
wpsc_tf_placeholder_text : wpsc_tf_placeholder_text, |
| 242 |
field_options : field_options, |
| 243 |
required : required, |
| 244 |
width : width, |
| 245 |
limit : limit, |
| 246 |
visibility : visibility, |
| 247 |
html_content : html_content, |
| 248 |
time_format :time_format, |
| 249 |
date_range : date_range, |
| 250 |
date_range_from : date_range_from, |
| 251 |
date_range_to : date_range_to |
| 252 |
}; |
| 253 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 254 |
wpsc_modal_close(); |
| 255 |
var response = JSON.parse(response_str); |
| 256 |
if (response.sucess_status=='1') { |
| 257 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 258 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 259 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 260 |
wpsc_get_ticket_form_fields(); |
| 261 |
} else { |
| 262 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 263 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 264 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 265 |
} |
| 266 |
}); |
| 267 |
} |
| 268 |
|
| 269 |
function wpsc_get_edit_default_form_field(field_id){ |
| 270 |
wpsc_modal_open(wpsc_admin.edit_form_field); |
| 271 |
var data = { |
| 272 |
action: 'wpsc_custom_fields', |
| 273 |
setting_action : 'get_edit_default_form_field', |
| 274 |
field_id : field_id |
| 275 |
}; |
| 276 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 277 |
jQuery('#wpsc_popup_body').html(response.body); |
| 278 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 279 |
jQuery('#wpsc_tf_label').focus(); |
| 280 |
}); |
| 281 |
} |
| 282 |
|
| 283 |
function wpsc_set_edit_default_form_field(field_id){ |
| 284 |
var field_label = jQuery('#wpsc_tf_label').val().trim(); |
| 285 |
if (field_label.length == 0) { |
| 286 |
jQuery('#wpsc_tf_label').val('').focus(); |
| 287 |
return; |
| 288 |
} |
| 289 |
var extra_info = jQuery('#wpsc_tf_extra_info').val().trim(); |
| 290 |
var width = jQuery('#wpsc_tf_width').val().trim(); |
| 291 |
var status = jQuery('#wpsc_tf_status').val(); |
| 292 |
var default_sub = jQuery('#wpsc_tf_default_subject').val(); |
| 293 |
var default_desc = jQuery('#wpsc_tf_default_description').val(); |
| 294 |
var limit = jQuery('#wpsc_tf_limit').val(); |
| 295 |
var wpsc_tf_placeholder_text = jQuery('#wpsc_tf_placeholder_text').val(); |
| 296 |
var visibility = new Array(); |
| 297 |
jQuery('#wpsc_tf_condition_container').find('input').each(function(){ |
| 298 |
visibility.push(jQuery(this).val()); |
| 299 |
}); |
| 300 |
|
| 301 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 302 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 303 |
var data = { |
| 304 |
action: 'wpsc_custom_fields', |
| 305 |
setting_action : 'set_edit_default_form_field', |
| 306 |
_ajax_nonce: '<?php echo wp_create_nonce('set_edit_default_form_field')?>', |
| 307 |
field_id : field_id, |
| 308 |
field_label : field_label, |
| 309 |
extra_info : extra_info, |
| 310 |
width : width, |
| 311 |
status : status, |
| 312 |
default_sub : default_sub, |
| 313 |
default_desc : default_desc, |
| 314 |
limit : limit, |
| 315 |
visibility : visibility, |
| 316 |
wpsc_tf_placeholder_text : wpsc_tf_placeholder_text |
| 317 |
}; |
| 318 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 319 |
wpsc_modal_close(); |
| 320 |
var response = JSON.parse(response_str); |
| 321 |
if (response.sucess_status=='1') { |
| 322 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 323 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 324 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 325 |
wpsc_get_ticket_form_fields(); |
| 326 |
} else { |
| 327 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 328 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 329 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 330 |
} |
| 331 |
}); |
| 332 |
} |
| 333 |
|
| 334 |
function wpsc_delete_custom_field(field_id){ |
| 335 |
|
| 336 |
var flag = confirm(wpsc_admin.are_you_sure); |
| 337 |
if (flag) { |
| 338 |
var data = { |
| 339 |
action: 'wpsc_custom_fields', |
| 340 |
setting_action : 'delete_custom_field', |
| 341 |
field_id : field_id, |
| 342 |
_ajax_nonce: '<?php echo wp_create_nonce('delete_custom_field')?>', |
| 343 |
}; |
| 344 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 345 |
var response = JSON.parse(response_str); |
| 346 |
if (response.sucess_status=='1') { |
| 347 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 348 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 349 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 350 |
wpsc_get_ticket_form_fields(); |
| 351 |
} else { |
| 352 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 353 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 354 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 355 |
} |
| 356 |
}); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
</script> |
| 361 |
|