PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 2.3.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v2.3.1
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
supportcandy / includes / admin / tickets / create_ticket / load_create_ticket.php

load_create_ticket.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/admin/tickets/create_ticket/load_create_ticket.php

602 lines 20.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 global $current_user, $wpscfunction;
7
8 $wpsc_captcha = get_option('wpsc_captcha');
9 $wpsc_terms_and_conditions = get_option('wpsc_terms_and_conditions');
10 $wpsc_set_in_gdpr = get_option('wpsc_set_in_gdpr');
11 $wpsc_gdpr_html = get_option('wpsc_gdpr_html');
12 $term_url = get_option('wpsc_term_page_url');
13 $wpsc_terms_and_conditions_html = get_option('wpsc_terms_and_conditions_html');
14 $wpsc_recaptcha_type = get_option('wpsc_recaptcha_type');
15 $wpsc_get_site_key= get_option('wpsc_get_site_key');
16 $wpsc_allow_rich_text_editor = get_option('wpsc_allow_rich_text_editor');
17 $wpsc_attachment_max_filesize = get_option('wpsc_attachment_max_filesize');
18
19 $fields = get_terms([
20 'taxonomy' => 'wpsc_ticket_custom_fields',
21 'hide_empty' => false,
22 'orderby' => 'meta_value_num',
23 'meta_key' => 'wpsc_tf_load_order',
24 'order' => 'ASC',
25 'meta_query' => array(
26 array(
27 'key' => 'agentonly',
28 'value' => '0',
29 'compare' => '='
30 )
31 ),
32 ]);
33
34 include WPSC_ABSPATH . 'includes/admin/tickets/create_ticket/class-ticket-form-field-format.php';
35
36 $form_field = new WPSC_Ticket_Form_Field();
37
38 $general_appearance = get_option('wpsc_appearance_general_settings');
39
40 $create_ticket_btn_css = 'background-color:'.$general_appearance['wpsc_crt_ticket_btn_action_bar_bg_color'].' !important;color:'.$general_appearance['wpsc_crt_ticket_btn_action_bar_text_color'].' !important;';
41 $action_default_btn_css = 'background-color:'.$general_appearance['wpsc_default_btn_action_bar_bg_color'].' !important;color:'.$general_appearance['wpsc_default_btn_action_bar_text_color'].' !important;';
42
43 $wpsc_appearance_create_ticket = get_option('wpsc_create_ticket');
44
45 $description = get_term_by('slug', 'ticket_description', 'wpsc_ticket_custom_fields' );
46 $wpsc_desc_status = get_term_meta( $description->term_id, 'wpsc_tf_status', true);
47
48 ?>
49 <div class="row wpsc_tl_action_bar" style="background-color:<?php echo esc_attr($general_appearance['wpsc_action_bar_color'])?> !important;">
50 <div class="col-sm-12">
51 <button type="button" id="wpsc_load_new_create_ticket_btn" onclick="wpsc_get_create_ticket();" class="btn btn-sm wpsc_create_ticket_btn" style="<?php echo esc_attr($create_ticket_btn_css)?>"><i class="fa fa-plus"></i> <?php _e('New Ticket','supportcandy')?></button>
52 <?php if($current_user->ID):?>
53 <button type="button" id="wpsc_load_ticket_list_btn" onclick="wpsc_get_ticket_list();" class="btn btn-sm wpsc_action_btn" style="<?php echo esc_attr($action_default_btn_css)?>"><i class="fa fa-list-ul"></i> <?php _e('Ticket List','supportcandy')?></button>
54 <?php endif;?>
55 </div>
56 </div>
57 <?php
58 do_action('wpsc_before_create_ticket');
59 if(apply_filters('wpsc_print_create_ticket_html',true)):
60 ?>
61 <div id="create_ticket_body" class="row" style="background-color:<?php echo esc_attr($general_appearance['wpsc_bg_color'])?> !important;color:<?php echo esc_attr($general_appearance['wpsc_text_color'])?> !important;">
62 <form id="wpsc_frm_create_ticket" onsubmit="return wpsc_submit_ticket();" method="post">
63 <div class="row create_ticket_fields_container">
64 <?php
65 foreach ($fields as $field) {
66 $form_field->print_field($field);
67 }
68 ?>
69 </div>
70
71 <?php if($wpsc_captcha) {
72 if($wpsc_recaptcha_type){?>
73 <div class="row create_ticket_fields_container">
74 <div class="col-md-6 captcha_container" style="margin-bottom:10px;margin-right:15px; display:flex; background-color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_captcha_bg_color'])?> !important;color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_captcha_text_color'])?> !important;">
75 <div style="width:25px;">
76 <input type="checkbox" onchange="get_captcha_code(this);" class="wpsc_checkbox" value="1">
77 <img id="captcha_wait" style="width:16px;display:none;" src="<?php echo esc_url(WPSC_PLUGIN_URL.'asset/images/[email protected]')?>" alt="">
78 </div>
79 <div style="padding-top:3px;"><?php _e("I'm not a robot",'supportcandy')?></div>
80 </div>
81 </div>
82 <?php
83 }
84 else {
85 ?>
86 <div class="row create_ticket_fields_container">
87 <div class="col-sm-12" style="margin-bottom:10px;margin-right:15px; display:flex">
88 <div style="width:25px;">
89 <div class="g-recaptcha" data-sitekey=<?php echo esc_attr($wpsc_get_site_key) ?>></div>
90 </div>
91 </div>
92 </div>
93 <?php
94 }
95 }
96 ?>
97
98 <?php if($wpsc_set_in_gdpr) {?>
99 <div class="row create_ticket_fields_container">
100 <div class="col-sm-12" style="margin-bottom:10px; display:flex;">
101 <div style="width:25px;">
102 <input type="checkbox" name="wpsc_gdpr" id="wpsc_gdpr" value="1">
103 </div>
104 <div style="padding-top:3px;">
105 <?php echo stripcslashes(wp_kses_post($wpsc_gdpr_html))?>
106 </div>
107 </div>
108 </div>
109 <?php
110 }
111 ?>
112
113 <?php
114 if($wpsc_terms_and_conditions) {?>
115
116 <div class="row create_ticket_fields_container">
117 <div class="col-sm-12" style="margin-bottom:10px; display:flex;">
118 <div style="width:25px;">
119 <input type="checkbox" name="terms" id="terms" value="1">
120 </div>
121 <div style="padding-top:3px;">
122 <?php
123 echo stripcslashes(wp_kses_post($wpsc_terms_and_conditions_html));
124 ?>
125 </div>
126 </div>
127 </div>
128 <?php
129 }
130 ?>
131
132 <?php
133 $wpsc_notify = get_option('wpsc_do_not_notify_setting');
134 $wpsc_notify_checkbox = get_option('wpsc_default_do_not_notify_option');
135 if($current_user->has_cap('wpsc_agent') && $wpsc_notify) {?>
136
137 <div class="row create_ticket_fields_container">
138 <div class="col-sm-6" style="margin-bottom:10px; display:flex;">
139 <div style="width:25px;">
140 <?php $checked = ($wpsc_notify_checkbox == 1) ? 'checked="checked"' : '';?>
141 <input <?php echo esc_attr($checked) ?> type="checkbox" name="notify_owner" id="notify_owner" value="1">
142 </div>
143 <div class="wpsc_notify_owner"style="padding-top:3px;">
144 <?php echo __("Don't notify owner",'supportcandy'); ?>
145 </div>
146 </div>
147 </div>
148 <?php
149 }
150 ?>
151
152 <div class="row create_ticket_frm_submit">
153 <button type="submit" id="wpsc_create_ticket_submit" class="btn" style="background-color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_submit_button_bg_color'])?> !important;color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_submit_button_text_color'])?> !important;border-color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_submit_button_border_color'])?> !important;"><?php _e('Submit Ticket','supportcandy')?></button>
154 <button type="button" id="wpsc_create_ticket_reset" onclick="wpsc_get_create_ticket();" class="btn" style="background-color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_reset_button_bg_color'])?> !important;color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_reset_button_text_color'])?> !important;border-color:<?php echo esc_attr($wpsc_appearance_create_ticket['wpsc_reset_button_border_color'])?> !important;"><?php _e('Reset Form','supportcandy')?></button>
155 <?php do_action('wpsc_after_create_ticket_frm_btn');?>
156 </div>
157
158 <input type="file" id="attachment_upload" class="hidden" onchange="">
159 <input type="hidden" id="wpsc_nonce" value="<?php echo wp_create_nonce()?>">
160
161 <input type="hidden" name="action" value="wpsc_tickets">
162 <input type="hidden" name="setting_action" value="submit_ticket">
163 <input type="hidden" id="captcha_code" name="captcha_code" value="">
164
165 </form>
166 </div>
167
168 <script type="text/javascript">
169 jQuery(document).ready(function(){
170
171 if(jQuery('.wpsc_drop_down,.wpsc_checkbox,.wpsc_radio_btn,.wpsc_category,.wpsc_priority').val != ''){
172 wpsc_reset_visibility();
173 }
174
175 jQuery('.wpsc_drop_down,.wpsc_checkbox,.wpsc_radio_btn,.wpsc_category,.wpsc_priority').change(function(){
176 wpsc_reset_visibility();
177 });
178 });
179
180 jQuery( "#customer_name" ).autocomplete({
181 minLength: 1,
182 appendTo: jQuery("#wpsc_agent_name").parent(),
183 source: function( request, response ) {
184 var term = request.term;
185 request = {
186 action: 'wpsc_tickets',
187 setting_action : 'get_users',
188 term : term
189 }
190 jQuery.getJSON( wpsc_admin.ajax_url, request, function( data, status, xhr ) {
191 response(data);
192 });
193 },
194 select: function (event, ui) {
195 jQuery('#customer_name').val(ui.item.value);
196 jQuery('#customer_email').val(ui.item.email);
197 }
198 });
199 jQuery('.wpsc_datetime').datetimepicker({
200 dateFormat : '<?php echo esc_attr(get_option('wpsc_calender_date_format'))?>',
201 showAnim : 'slideDown',
202 changeMonth: true,
203 changeYear: true,
204 timeFormat: 'HH:mm:ss'
205 });
206
207 function get_captcha_code(e){
208 jQuery(e).hide();
209 jQuery('#captcha_wait').show();
210 var data = {
211 action: 'wpsc_tickets',
212 setting_action : 'get_captcha_code'
213 };
214 jQuery.post(wpsc_admin.ajax_url, data, function(response) {
215 jQuery('#captcha_code').val(response.trim());;
216 jQuery('#captcha_wait').hide();
217 jQuery(e).show();
218 jQuery(e).prop('disabled',true);
219 });
220 }
221
222 function wpsc_reset_visibility(){
223
224 jQuery('.wpsc_form_field').each(function(){
225 var visible_flag = false;
226 var visibility = jQuery(this).data('visibility').trim();
227 if(visibility){
228 visibility = visibility.split(';;');
229 jQuery(visibility).each(function(key, val){
230 var condition = val.split('--');
231 var cond_obj = jQuery('.field_'+condition[0]);
232 var field_type = jQuery(cond_obj).data('fieldtype');
233 switch (field_type) {
234
235 case 'dropdown':
236 if ( jQuery(cond_obj).hasClass('visible') && jQuery(cond_obj).find('select').val()==condition[1] ) visible_flag=true;
237 break;
238
239 case 'checkbox':
240 var check = false;
241 jQuery(cond_obj).find('input:checked').each(function(){
242 if(jQuery(this).val()==condition[1]) check=true;
243 });
244 if ( jQuery(cond_obj).hasClass('visible') && check ) visible_flag=true;
245 break;
246
247 case 'radio':
248 if ( jQuery(cond_obj).hasClass('visible') && jQuery(cond_obj).find('input:checked').val()==condition[1] ) visible_flag=true;
249 break;
250
251 }
252 });
253 if (visible_flag) {
254 jQuery(this).removeClass('hidden');
255 jQuery(this).addClass('visible');
256 } else {
257 jQuery(this).removeClass('visible');
258 jQuery(this).addClass('hidden');
259 var field_type = jQuery(this).data('fieldtype');
260 switch (field_type) {
261
262 case 'text':
263 case 'email':
264 case 'number':
265 case 'date':
266 case 'datetime':
267 case 'url':
268 case 'time':
269 jQuery(this).find('input').val('');
270 break;
271
272 case 'textarea':
273 jQuery(this).find('textarea').val('');
274 break;
275
276 case 'dropdown':
277 jQuery(this).find('select').val('');
278 break;
279
280 case 'checkbox':
281 jQuery(this).find('input:checked').each(function(){
282 jQuery(this).prop('checked',false);
283 });
284 break;
285
286 case 'radio':
287 jQuery(this).find('input:checked').prop('checked',false);
288 break;
289
290 }
291 }
292 }
293
294 <?php do_action('wpsc_after_field_reset_visibility');?>
295 });
296
297 }
298
299 function wpsc_attachment_upload(id,name){
300 jQuery('#attachment_upload').unbind('change');
301 jQuery('#attachment_upload').on('change', function() {
302
303 var flag = false;
304 var file = this.files[0];
305 jQuery('#attachment_upload').val('');
306
307 var allowedExtension = ['exe', 'php'];
308 var file_name_split = file.name.split('.');
309 var file_extension = file_name_split[file_name_split.length-1];
310 file_extension = file_extension.toLowerCase();
311 <?php
312 $attachment = get_option('wpsc_allow_attachment_type');
313 $attachment_data = explode(',' , $attachment );
314 $attachment_data = array_map('trim', $attachment_data);
315 $attachment_data = array_map('strtolower', $attachment_data);
316 ?>
317 var allowedExtensionSetting = [<?php echo '"'.implode('","', $attachment_data).'"' ?>];
318
319 if(!flag && (jQuery.inArray(file_extension,allowedExtensionSetting) <= -1 || jQuery.inArray(file_extension,allowedExtension) > -1)) {
320 flag = true;
321 alert("<?php _e('Attached file type not allowed!','supportcandy')?>");
322 }
323
324 var current_filesize=file.size/1000000;
325
326 if(current_filesize><?php echo esc_attr($wpsc_attachment_max_filesize) ?>){
327 flag = true;
328 alert("<?php echo sprintf( __('File size exceeds allowed limit (%1$s MB)! ','supportcandy'), esc_attr($wpsc_attachment_max_filesize) );?>");
329 }
330
331 if (!flag){
332
333 var html_str = '<div class="row wpsp_attachment">'+
334 '<div class="progress" style="float: none !important; width: unset !important;">'+
335 '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">'+
336 file.name+
337 '</div>'+
338 '</div>'+
339 '<img onclick="attachment_cancel(this);" class="attachment_cancel" src="<?php echo esc_url(WPSC_PLUGIN_URL.'asset/images/close.png')?>" style="display:none;" />'+
340 '</div>';
341
342 jQuery('#'+id).append(html_str);
343
344 var attachment = jQuery('#'+id).find('.wpsp_attachment').last();
345
346 var data = new FormData();
347 data.append('file', file);
348 data.append('arr_name', name);
349 data.append('action', 'wpsc_tickets');
350 data.append('setting_action', 'upload_file');
351 data.append('nonce', jQuery('#wpsc_nonce').val().trim());
352 data.append('_ajax_nonce', '<?php echo wp_create_nonce('upload_file')?>');
353
354 jQuery.ajax({
355 type: 'post',
356 url: wpsc_admin.ajax_url,
357 data: data,
358 xhr: function(){
359 var xhr = new window.XMLHttpRequest();
360 xhr.upload.addEventListener("progress", function(evt){
361 if (evt.lengthComputable) {
362 var percentComplete = Math.floor((evt.loaded / evt.total) * 100);
363 jQuery(attachment).find('.progress-bar').css('width',percentComplete+'%');
364 }
365 }, false);
366 return xhr;
367 },
368 processData: false,
369 contentType: false,
370 success: function(response) {
371
372 var return_obj=JSON.parse(response);
373 jQuery(attachment).find('.attachment_cancel').show();
374
375 if( parseInt(return_obj.id) != 0 ){
376 jQuery(attachment).append('<input type="hidden" name="'+name+'[]" value="'+return_obj.id+'">');
377 jQuery(attachment).find('.progress-bar').addClass('progress-bar-success');
378 } else {
379 jQuery(attachment).find('.progress-bar').addClass('progress-bar-danger');
380 }
381 }
382 });
383
384 }
385
386 });
387 jQuery('#attachment_upload').trigger('click');
388 }
389
390 function wpsc_submit_ticket(){
391
392 var validation = true;
393
394 /*
395 Required fields
396 */
397 jQuery('.visible.wpsc_required').each(function(e){
398 var field_type = jQuery(this).data('fieldtype');
399 switch (field_type) {
400 case 'text':
401 case 'email':
402 case 'number':
403 case 'date':
404 case 'url':
405 case 'time':
406 if(jQuery(this).find('input').val()=='') validation=false;
407 break;
408
409 case 'textarea':
410 if(jQuery(this).find('textarea').val()=='') validation=false;
411 break;
412
413 case 'dropdown':
414 if(jQuery(this).find('select').val()=='') validation=false;
415 break;
416
417 case 'checkbox':
418 case 'radio':
419 if(jQuery(this).find('input:checked').length==0) validation=false;
420 break;
421
422 case 'file_attachment':
423 if(jQuery(this).find('.attachment_container').is(':empty')){
424 validation=false;
425 }
426 break;
427
428 case 'tinymce':
429 <?php
430
431 $rich_editing = $wpscfunction->rich_editing_status($current_user);
432
433 $flag = false;
434 if($wpsc_desc_status && is_user_logged_in() && (in_array('register_user',$wpsc_allow_rich_text_editor) && !$current_user->has_cap('wpsc_agent') ) && $rich_editing){
435 $flag = true;
436 } elseif ($wpsc_desc_status && $current_user->has_cap('wpsc_agent') && is_user_logged_in() && $rich_editing){
437 $flag = true;
438 }elseif (!is_user_logged_in() && $wpsc_desc_status && in_array('guest_user',$wpsc_allow_rich_text_editor)){
439 $flag = true;
440 }
441
442 if($flag){
443 ?>
444 var description = tinyMCE.activeEditor.getContent();
445 if(description.trim().length==0) validation=false;
446 break;
447 <?php
448 }else {?>
449 if(jQuery('#ticket_description').val()=='') validation=false;
450 break;
451 <?php
452 }?>
453 }
454 if (!validation) return;
455 });
456 if (!validation) {
457 alert("<?php _e('Required fields can not be empty!','supportcandy')?>");
458 return false;
459 }
460
461 /*
462 Emails
463 */
464 jQuery('.wpsc_email').each(function(e){
465 var email = jQuery(this).val().trim();
466 if(email.length>0 && !validateEmail(email)) {
467 validation=false;
468 jQuery(this).focus();
469 }
470 if (!validation) return;
471 });
472 if (!validation) {
473 alert("<?php _e('Incorrect email address!','supportcandy')?>");
474 return false;
475 }
476
477 /*
478 URLs
479 */
480 jQuery('.wpsc_url').each(function(e){
481 var url = jQuery(this).val().trim();
482 if(url.length>0 && !validateURL(url)) {
483 validation=false;
484 jQuery(this).focus();
485 }
486 if (!validation) return;
487 });
488 if (!validation) {
489 alert("<?php _e('Incorrect URL!','supportcandy')?>");
490 return false;
491 }
492
493 <?php do_action('wpsc_create_ticket_validation'); ?>
494
495 /*
496 Captcha
497 */
498 <?php
499 if( $wpsc_captcha ) {
500 if( $wpsc_recaptcha_type ){?>
501 if (jQuery('#captcha_code').val().trim().length==0) {
502 alert("<?php _e('Please confirm you are not a robot!','supportcandy')?>");
503 validation=false;
504 return false;
505 }
506 <?php
507 }
508 else {?>
509 var recaptcha = jQuery("#g-recaptcha-response").val();
510 if (recaptcha === "") {
511 alert("<?php _e('Please confirm you are not a robot!','supportcandy')?>");
512 validation=false;
513 return false;
514 }<?php
515 }
516 }
517 ?>
518
519 <?php
520 if($wpsc_set_in_gdpr) { ?>
521 if (!jQuery('#wpsc_gdpr').is(':checked')){
522 alert("<?php _e('Ticket can not be created unless you agree to privacy policy.','supportcandy')?>");
523 return false;
524 }
525 <?php
526 }
527 ?>
528
529 <?php
530 if($wpsc_terms_and_conditions) { ?>
531 if (!jQuery('#terms').is(':checked')){
532 alert("<?php _e('Ticket can not be created unless you agree to terms & coditions.', 'supportcandy')?>");
533 return false;
534 }
535 <?php
536 }
537 ?>
538
539 if (validation) {
540 var dataform = new FormData(jQuery('#wpsc_frm_create_ticket')[0]);
541 var is_tinymce = true;
542 <?php
543
544 $rich_editing = $wpscfunction->rich_editing_status($current_user);
545 $flag = false;
546
547 if( is_user_logged_in() && (in_array('register_user',$wpsc_allow_rich_text_editor) && !$current_user->has_cap('wpsc_agent') ) && $rich_editing){
548 $flag = true;
549 } elseif ( $current_user->has_cap('wpsc_agent') && is_user_logged_in() && $rich_editing){
550 $flag = true;
551 }elseif (!is_user_logged_in() && in_array('guest_user',$wpsc_allow_rich_text_editor)){
552 $flag = true;
553 }
554 if($wpsc_desc_status){
555 if($flag){
556 ?>
557 var description = tinyMCE.get('ticket_description').getContent().trim();
558 dataform.append('ticket_description', description);
559 is_tinymce = true;
560 <?php
561 }else{
562 ?>
563 var description = jQuery('#ticket_description').val();
564 dataform.append('ticket_description',description);
565 is_tinymce = false;
566 <?php
567 }
568 }
569 ?>
570 jQuery('#create_ticket_body').html(wpsc_admin.loading_html);
571 wpsc_doScrolling('#wpsc_tickets_container',1000);
572 jQuery.ajax({
573 url: wpsc_admin.ajax_url,
574 type: 'POST',
575 data: dataform,
576 processData: false,
577 contentType: false
578 })
579 .done(function (response_str) {
580 var response = JSON.parse(response_str);
581 if(response.redirct_url==''){
582 jQuery('#create_ticket_body').html(response.thank_you_page);
583 } else {
584 window.location.href = response.redirct_url;
585 }
586 });
587 <?php if($wpsc_desc_status){ ?>
588 if(is_tinymce) tinyMCE.activeEditor.setContent('');
589 <?php } ?>
590 return false;
591 }
592
593 }
594 <?php do_action('wpsc_print_ext_js_create_ticket'); ?>
595
596 </script>
597 <?php if (!$wpsc_recaptcha_type && $wpsc_captcha): ?>
598 <script src='https://www.google.com/recaptcha/api.js'></script>
599 <?php endif; ?>
600 <?php
601 endif;
602 ?>