| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_EN_Settings_TN' ) ) : |
| 7 |
|
| 8 |
final class WPSC_EN_Settings_TN { |
| 9 |
|
| 10 |
/** |
| 11 |
* Ticket events |
| 12 |
* |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
public static $events = array(); |
| 16 |
|
| 17 |
/** |
| 18 |
* Ignore current user recipient from these events |
| 19 |
* |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
public static $ignore_current_user = array(); |
| 23 |
|
| 24 |
/** |
| 25 |
* Initialize this class |
| 26 |
*/ |
| 27 |
public static function init() { |
| 28 |
|
| 29 |
// ignore cft. |
| 30 |
add_action( 'init', array( __CLASS__, 'load_ignore_list' ) ); |
| 31 |
|
| 32 |
// list. |
| 33 |
add_action( 'wp_ajax_wpsc_get_ticket_notifications', array( __CLASS__, 'get_ticket_notifications' ) ); |
| 34 |
|
| 35 |
// add new. |
| 36 |
add_action( 'wp_ajax_wpsc_en_get_add_ticket_notification', array( __CLASS__, 'get_add_ticket_notification' ) ); |
| 37 |
add_action( 'wp_ajax_wpsc_en_set_add_ticket_notification', array( __CLASS__, 'set_add_ticket_notification' ) ); |
| 38 |
|
| 39 |
// edit. |
| 40 |
add_action( 'wp_ajax_wpsc_en_get_edit_ticket_notification', array( __CLASS__, 'get_edit_ticket_notification' ) ); |
| 41 |
add_action( 'wp_ajax_wpsc_en_set_edit_ticket_notification', array( __CLASS__, 'set_edit_ticket_notification' ) ); |
| 42 |
|
| 43 |
// delete. |
| 44 |
add_action( 'wp_ajax_wpsc_en_delete_ticket_notification', array( __CLASS__, 'delete_ticket_notification' ) ); |
| 45 |
|
| 46 |
// clone. |
| 47 |
add_action( 'wp_ajax_wpsc_en_get_clone_ticket_notification', array( __CLASS__, 'get_clone_ticket_notification' ) ); |
| 48 |
add_action( 'wp_ajax_wpsc_en_set_clone_ticket_notification', array( __CLASS__, 'set_clone_ticket_notification' ) ); |
| 49 |
|
| 50 |
// enable or disable. |
| 51 |
add_action( 'wp_ajax_wpsc_en_enable_disable_template', array( __CLASS__, 'enable_disable_template' ) ); |
| 52 |
|
| 53 |
// filter conditions. |
| 54 |
add_filter( 'wpsc_en_conditions', array( __CLASS__, 'filter_conditions' ) ); |
| 55 |
|
| 56 |
// filter triggers. |
| 57 |
add_filter( 'wpsc_en_triggers', array( __CLASS__, 'filter_triggers' ) ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Set ignore custom field types for email notifications |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public static function load_ignore_list() { |
| 66 |
|
| 67 |
self::$ignore_current_user = apply_filters( |
| 68 |
'wpsc_en_ignore_current_user_recipient_events', |
| 69 |
array( 'create-ticket' ) |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Ticket notification list |
| 75 |
* |
| 76 |
* @return void |
| 77 |
*/ |
| 78 |
public static function get_ticket_notifications() { |
| 79 |
|
| 80 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 81 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 82 |
} |
| 83 |
|
| 84 |
$email_templates = get_option( 'wpsc-email-templates', array() ); |
| 85 |
$unique_id = uniqid( 'wpsc_' );?> |
| 86 |
<div class="wpsc-setting-header"> |
| 87 |
<h2><?php esc_attr_e( 'Ticket Notifications', 'supportcandy' ); ?></h2> |
| 88 |
</div> |
| 89 |
<div class="wpsc-setting-section-body"> |
| 90 |
<div class="wpsc-dock-container"> |
| 91 |
<?php |
| 92 |
printf( |
| 93 |
/* translators: Click here to see the documentation */ |
| 94 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 95 |
'<a href="https://supportcandy.net/docs/ticket-notifications/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 96 |
); |
| 97 |
?> |
| 98 |
</div> |
| 99 |
<table class="ticket-notification-list wpsc-setting-tbl"> |
| 100 |
<thead> |
| 101 |
<tr> |
| 102 |
<th><?php esc_attr_e( 'Title', 'supportcandy' ); ?></th> |
| 103 |
<th><?php esc_attr_e( 'Trigger', 'supportcandy' ); ?></th> |
| 104 |
<th><?php esc_attr_e( 'Status', 'supportcandy' ); ?></th> |
| 105 |
<th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th> |
| 106 |
</tr> |
| 107 |
</thead> |
| 108 |
<tbody> |
| 109 |
<?php |
| 110 |
if ( $email_templates ) : |
| 111 |
foreach ( $email_templates as $index => $et ) : |
| 112 |
?> |
| 113 |
<tr> |
| 114 |
<td><?php echo esc_attr( $et['title'] ); ?></td> |
| 115 |
<td><?php echo esc_attr( WPSC_Triggers::$triggers[ $et['event'] ] ); ?></td> |
| 116 |
<td><?php echo esc_attr( $et['is_enable'] ) == 1 ? esc_attr__( 'Enabled', 'supportcandy' ) : esc_attr__( 'Disabled', 'supportcandy' ); ?></td> |
| 117 |
<td> |
| 118 |
<?php |
| 119 |
if ( $et['is_enable'] ) { |
| 120 |
?> |
| 121 |
<a href="javascript:wpsc_en_enable_disable_template(<?php echo esc_attr( $index ); ?>, '0', '<?php echo esc_attr( wp_create_nonce( 'wpsc_en_enable_disable_template' ) ); ?>')"><?php esc_attr_e( 'Disable', 'supportcandy' ); ?></a> | |
| 122 |
<?php |
| 123 |
} else { |
| 124 |
?> |
| 125 |
<a href="javascript:wpsc_en_enable_disable_template(<?php echo esc_attr( $index ); ?>, '1', '<?php echo esc_attr( wp_create_nonce( 'wpsc_en_enable_disable_template' ) ); ?>')"><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></a> | |
| 126 |
<?php |
| 127 |
} |
| 128 |
?> |
| 129 |
<a href="javascript:wpsc_en_get_edit_ticket_notification(<?php echo esc_attr( $index ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_en_get_edit_ticket_notification' ) ); ?>')"><?php esc_attr_e( 'Edit', 'supportcandy' ); ?></a> | |
| 130 |
<a href="javascript:wpsc_en_get_clone_ticket_notification(<?php echo esc_attr( $index ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_en_get_clone_ticket_notification' ) ); ?>')"><?php esc_attr_e( 'Clone', 'supportcandy' ); ?></a> | |
| 131 |
<a href="javascript:wpsc_en_delete_ticket_notification(<?php echo esc_attr( $index ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_en_delete_ticket_notification' ) ); ?>')"><?php esc_attr_e( 'Delete', 'supportcandy' ); ?></a> |
| 132 |
</td> |
| 133 |
</tr> |
| 134 |
<?php |
| 135 |
endforeach; |
| 136 |
endif; |
| 137 |
?> |
| 138 |
</tbody> |
| 139 |
</table> |
| 140 |
<script> |
| 141 |
jQuery('table.ticket-notification-list').DataTable({ |
| 142 |
ordering: false, |
| 143 |
pageLength: 20, |
| 144 |
bLengthChange: false, |
| 145 |
columnDefs: [ |
| 146 |
{ targets: -1, searchable: false }, |
| 147 |
{ targets: '_all', className: 'dt-left' } |
| 148 |
], |
| 149 |
layout: { |
| 150 |
topStart: { |
| 151 |
buttons: [ |
| 152 |
{ |
| 153 |
text: '<?php esc_attr_e( 'Add new', 'supportcandy' ); ?>', |
| 154 |
className: 'wpsc-button small primary', |
| 155 |
action: function ( e, dt, node, config ) { |
| 156 |
|
| 157 |
wpsc_show_modal(); |
| 158 |
var data = { action: 'wpsc_en_get_add_ticket_notification' }; |
| 159 |
jQuery.post( |
| 160 |
supportcandy.ajax_url, |
| 161 |
data, |
| 162 |
function (response) { |
| 163 |
|
| 164 |
jQuery( '.wpsc-modal-header' ).text( response.title ); |
| 165 |
jQuery( '.wpsc-modal-body' ).html( response.body ); |
| 166 |
jQuery( '.wpsc-modal-footer' ).html( response.footer ); |
| 167 |
|
| 168 |
wpsc_show_modal_inner_container(); |
| 169 |
} |
| 170 |
); |
| 171 |
} |
| 172 |
} |
| 173 |
], |
| 174 |
}, |
| 175 |
}, |
| 176 |
language: supportcandy.translations.datatables |
| 177 |
}); |
| 178 |
</script> |
| 179 |
</div> |
| 180 |
<?php |
| 181 |
wp_die(); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Get add ticket notification modal |
| 186 |
* |
| 187 |
* @return void |
| 188 |
*/ |
| 189 |
public static function get_add_ticket_notification() { |
| 190 |
|
| 191 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 192 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 193 |
} |
| 194 |
|
| 195 |
$title = esc_attr__( 'Add new', 'supportcandy' ); |
| 196 |
$roles = get_option( 'wpsc-agent-roles', array() ); |
| 197 |
ob_start(); |
| 198 |
?> |
| 199 |
<form action="#" onsubmit="return false;" class="wpsc-frm-add-en"> |
| 200 |
<div class="wpsc-input-group"> |
| 201 |
<div class="label-container"> |
| 202 |
<label for=""> |
| 203 |
<?php esc_attr_e( 'Title', 'supportcandy' ); ?> |
| 204 |
<span class="required-char">*</span> |
| 205 |
</label> |
| 206 |
</div> |
| 207 |
<input id="title" type="text" name="title" autocomplete="off"> |
| 208 |
</div> |
| 209 |
<?php WPSC_Triggers::print( 'event', 'wpsc_en_triggers', '', true ); ?> |
| 210 |
<?php do_action( 'wpsc_get_add_ticket_notification' ); ?> |
| 211 |
<input type="hidden" name="action" value="wpsc_en_set_add_ticket_notification"> |
| 212 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_en_set_add_ticket_notification' ) ); ?>"> |
| 213 |
</form> |
| 214 |
<?php |
| 215 |
$body = ob_get_clean(); |
| 216 |
|
| 217 |
ob_start(); |
| 218 |
?> |
| 219 |
<button class="wpsc-button small primary" onclick="wpsc_en_set_add_ticket_notification(this);"> |
| 220 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?> |
| 221 |
</button> |
| 222 |
<button class="wpsc-button small secondary" onclick="wpsc_close_modal();"> |
| 223 |
<?php esc_attr_e( 'Cancel', 'supportcandy' ); ?> |
| 224 |
</button> |
| 225 |
<?php |
| 226 |
do_action( 'wpsc_get_edit_agent_footer' ); |
| 227 |
$footer = ob_get_clean(); |
| 228 |
|
| 229 |
$response = array( |
| 230 |
'title' => $title, |
| 231 |
'body' => $body, |
| 232 |
'footer' => $footer, |
| 233 |
); |
| 234 |
wp_send_json( $response ); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Set add ticket notification |
| 239 |
* |
| 240 |
* @return void |
| 241 |
*/ |
| 242 |
public static function set_add_ticket_notification() { |
| 243 |
|
| 244 |
if ( check_ajax_referer( 'wpsc_en_set_add_ticket_notification', '_ajax_nonce', false ) != 1 ) { |
| 245 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 246 |
} |
| 247 |
|
| 248 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 249 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 250 |
} |
| 251 |
|
| 252 |
$title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : ''; |
| 253 |
if ( ! $title ) { |
| 254 |
wp_send_json_error( 'Bad request', 400 ); |
| 255 |
} |
| 256 |
|
| 257 |
$event = isset( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : ''; |
| 258 |
if ( ! $event || ! WPSC_Triggers::is_valid( 'wpsc_en_triggers', $event ) ) { |
| 259 |
wp_send_json_error( 'Bad request', 400 ); |
| 260 |
} |
| 261 |
|
| 262 |
$et = array( |
| 263 |
'is_enable' => 0, |
| 264 |
'title' => $title, |
| 265 |
'event' => $event, |
| 266 |
'conditions' => '', |
| 267 |
'subject' => '', |
| 268 |
'body' => array( |
| 269 |
'text' => '', |
| 270 |
'editor' => 'html', |
| 271 |
), |
| 272 |
'to' => array( |
| 273 |
'general-recipients' => array(), |
| 274 |
'agent-roles' => array(), |
| 275 |
'custom' => array(), |
| 276 |
), |
| 277 |
'cc' => array( |
| 278 |
'general-recipients' => array(), |
| 279 |
'agent-roles' => array(), |
| 280 |
'custom' => array(), |
| 281 |
), |
| 282 |
'bcc' => array( |
| 283 |
'general-recipients' => array(), |
| 284 |
'agent-roles' => array(), |
| 285 |
'custom' => array(), |
| 286 |
), |
| 287 |
); |
| 288 |
|
| 289 |
$email_templates = get_option( 'wpsc-email-templates', array() ); |
| 290 |
if ( count( $email_templates ) == 0 ) { |
| 291 |
|
| 292 |
$email_templates[1] = $et; |
| 293 |
|
| 294 |
} else { |
| 295 |
|
| 296 |
$email_templates[] = $et; |
| 297 |
} |
| 298 |
update_option( 'wpsc-email-templates', $email_templates ); |
| 299 |
|
| 300 |
end( $email_templates ); |
| 301 |
$index = key( $email_templates ); |
| 302 |
|
| 303 |
$nonce = wp_create_nonce( 'wpsc_en_get_edit_ticket_notification' ); |
| 304 |
wp_send_json( |
| 305 |
array( |
| 306 |
'index' => $index, |
| 307 |
'nonce' => $nonce, |
| 308 |
) |
| 309 |
); |
| 310 |
wp_die(); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Get edit email notification |
| 315 |
* |
| 316 |
* @return void |
| 317 |
*/ |
| 318 |
public static function get_edit_ticket_notification() { |
| 319 |
|
| 320 |
if ( check_ajax_referer( 'wpsc_en_get_edit_ticket_notification', '_ajax_nonce', false ) != 1 ) { |
| 321 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 322 |
} |
| 323 |
|
| 324 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 325 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 326 |
} |
| 327 |
|
| 328 |
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : 0; |
| 329 |
if ( ! $template_id ) { |
| 330 |
wp_send_json_error( 'Bad request', 400 ); |
| 331 |
} |
| 332 |
|
| 333 |
$email_templates = get_option( 'wpsc-email-templates' ); |
| 334 |
$et = array_key_exists( $template_id, $email_templates ) ? $email_templates[ $template_id ] : null; |
| 335 |
if ( ! $et ) { |
| 336 |
wp_send_json_error( 'Bad request', 400 ); |
| 337 |
} |
| 338 |
?> |
| 339 |
|
| 340 |
<form action="#" onsubmit="return false;" class="wpsc-frm-edit-en"> |
| 341 |
|
| 342 |
<div class="wpsc-input-group"> |
| 343 |
<div class="label-container"> |
| 344 |
<label for=""> |
| 345 |
<?php esc_attr_e( 'Title', 'supportcandy' ); ?> |
| 346 |
<span class="required-char">*</span> |
| 347 |
</label> |
| 348 |
</div> |
| 349 |
<input type="text" name="title" value="<?php echo esc_attr( $et['title'] ); ?>" autocomplete="off"> |
| 350 |
</div> |
| 351 |
|
| 352 |
<?php WPSC_Triggers::print( 'event', 'wpsc_en_triggers', $et['event'], true, '', true ); ?> |
| 353 |
|
| 354 |
<?php WPSC_Ticket_Conditions::print( 'conditions', 'wpsc_en_conditions', $et['conditions'] ); ?> |
| 355 |
|
| 356 |
<div class="wpsc-input-group"> |
| 357 |
<div class="label-container"> |
| 358 |
<label for=""> |
| 359 |
<?php esc_attr_e( 'Subject', 'supportcandy' ); ?> |
| 360 |
<span class="required-char">*</span> |
| 361 |
</label> |
| 362 |
</div> |
| 363 |
<?php |
| 364 |
$en_tn_subject = $et['subject'] ? WPSC_Translations::get( 'wpsc-en-tn-subject-' . $template_id, stripslashes( $et['subject'] ) ) : stripslashes( $et['subject'] ); |
| 365 |
?> |
| 366 |
<input type="text" name="subject" value="<?php echo esc_attr( $en_tn_subject ); ?>" autocomplete="off"> |
| 367 |
</div> |
| 368 |
|
| 369 |
<div class="wpsc-input-group"> |
| 370 |
<div class="label-container"> |
| 371 |
<label for=""> |
| 372 |
<?php esc_attr_e( 'Body', 'supportcandy' ); ?> |
| 373 |
<span class="required-char">*</span> |
| 374 |
</label> |
| 375 |
</div> |
| 376 |
<div class="textarea-container "> |
| 377 |
<div class = "wpsc_tinymce_editor_btns"> |
| 378 |
<div class="inner-container"> |
| 379 |
<button class="visual wpsc-switch-editor <?php echo esc_attr( $et['body']['editor'] ) == 'html' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_tinymce(this, 'wpsc-en-body','wpsc_en_body');"><?php esc_attr_e( 'Visual', 'supportcandy' ); ?></button> |
| 380 |
<button class="text wpsc-switch-editor <?php echo esc_attr( $et['body']['editor'] ) == 'text' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_textarea(this, 'wpsc-en-body')"><?php esc_attr_e( 'Text', 'supportcandy' ); ?></button> |
| 381 |
</div> |
| 382 |
</div> |
| 383 |
<?php |
| 384 |
$en_tn_body = $et['body']['text'] ? WPSC_Translations::get( 'wpsc-en-tn-body-' . $template_id, stripslashes( $et['body']['text'] ) ) : stripslashes( $et['body']['text'] ); |
| 385 |
?> |
| 386 |
<textarea id="wpsc-en-body" name="body" class="wpsc_textarea"><?php echo esc_attr( $en_tn_body ); ?></textarea> |
| 387 |
<div class="wpsc-it-editor-action-container"> |
| 388 |
<div class="actions"> |
| 389 |
<div class="wpsc-editor-actions"> |
| 390 |
<span class="wpsc-link" onclick="wpsc_get_macros()"><?php esc_attr_e( 'Insert Macro', 'supportcandy' ); ?></span> |
| 391 |
</div> |
| 392 |
</div> |
| 393 |
</div> |
| 394 |
</div> |
| 395 |
<script> |
| 396 |
<?php |
| 397 |
if ( $et['body']['editor'] == 'html' ) : |
| 398 |
?> |
| 399 |
jQuery('.wpsc-switch-editor.visual').trigger('click'); |
| 400 |
<?php |
| 401 |
endif; |
| 402 |
?> |
| 403 |
|
| 404 |
function wpsc_get_tinymce(el, selector, body_id){ |
| 405 |
jQuery(el).parent().find('.text').removeClass('active'); |
| 406 |
jQuery(el).addClass('active'); |
| 407 |
tinymce.remove('#'+selector); |
| 408 |
tinymce.init({ |
| 409 |
selector:'#'+selector, |
| 410 |
body_id: body_id, |
| 411 |
menubar: false, |
| 412 |
statusbar: false, |
| 413 |
height : '200', |
| 414 |
plugins: [ |
| 415 |
'lists link image directionality' |
| 416 |
], |
| 417 |
image_advtab: true, |
| 418 |
toolbar: 'bold italic underline blockquote | alignleft aligncenter alignright | bullist numlist | rtl | link image', |
| 419 |
directionality: '<?php echo is_rtl() ? 'rtl' : 'ltr'; ?>', |
| 420 |
branding: false, |
| 421 |
autoresize_bottom_margin: 20, |
| 422 |
browser_spellcheck : true, |
| 423 |
relative_urls : false, |
| 424 |
remove_script_host : false, |
| 425 |
convert_urls : false, |
| 426 |
setup: function (editor) { |
| 427 |
} |
| 428 |
}); |
| 429 |
jQuery('#editor').val('html'); |
| 430 |
} |
| 431 |
|
| 432 |
function wpsc_get_textarea(el, selector){ |
| 433 |
jQuery(el).parent().find('.visual').removeClass('active'); |
| 434 |
jQuery(el).addClass('active'); |
| 435 |
tinymce.remove('#'+selector); |
| 436 |
jQuery('#editor').val('text'); |
| 437 |
} |
| 438 |
</script> |
| 439 |
</div> |
| 440 |
|
| 441 |
<div class="wpsc-input-group"> |
| 442 |
<div class="label-container"> |
| 443 |
<label for=""> |
| 444 |
<?php esc_attr_e( 'To address', 'supportcandy' ); ?> |
| 445 |
<span class="required-char">*</span> |
| 446 |
</label> |
| 447 |
</div> |
| 448 |
<?php echo esc_attr( self::print_recipient_options( $et, 'to' ) ); ?> |
| 449 |
</div> |
| 450 |
|
| 451 |
<div class="wpsc-input-group"> |
| 452 |
<div class="label-container"> |
| 453 |
<label for="">CC</label> |
| 454 |
</div> |
| 455 |
<?php echo esc_attr( self::print_recipient_options( $et, 'cc' ) ); ?> |
| 456 |
</div> |
| 457 |
|
| 458 |
<div class="wpsc-input-group"> |
| 459 |
<div class="label-container"> |
| 460 |
<label for="">BCC</label> |
| 461 |
</div> |
| 462 |
<?php echo esc_attr( self::print_recipient_options( $et, 'bcc' ) ); ?> |
| 463 |
</div> |
| 464 |
|
| 465 |
<?php do_action( 'wpsc_get_edit_ticket_notification', $et ); ?> |
| 466 |
<input type="hidden" name="action" value="wpsc_en_set_edit_ticket_notification"> |
| 467 |
<input type="hidden" name="template_id" value="<?php echo esc_attr( $template_id ); ?>"> |
| 468 |
<input type="hidden" id="editor" name="editor" value="<?php echo esc_attr( $et['body']['editor'] ); ?>"> |
| 469 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_en_set_edit_ticket_notification' ) ); ?>"> |
| 470 |
|
| 471 |
</form> |
| 472 |
|
| 473 |
<div class="setting-footer-actions"> |
| 474 |
<button |
| 475 |
class="wpsc-button normal primary" |
| 476 |
onclick="wpsc_en_set_edit_ticket_notification();"> |
| 477 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?> |
| 478 |
</button> |
| 479 |
<button |
| 480 |
class="wpsc-button normal secondary" |
| 481 |
onclick="wpsc_get_ticket_notifications();"> |
| 482 |
<?php esc_attr_e( 'Cancel', 'supportcandy' ); ?> |
| 483 |
</button> |
| 484 |
</div> |
| 485 |
<?php |
| 486 |
|
| 487 |
wp_die(); |
| 488 |
} |
| 489 |
|
| 490 |
/** |
| 491 |
* Set edit ticket notification |
| 492 |
*/ |
| 493 |
public static function set_edit_ticket_notification() { |
| 494 |
|
| 495 |
if ( check_ajax_referer( 'wpsc_en_set_edit_ticket_notification', '_ajax_nonce', false ) != 1 ) { |
| 496 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 497 |
} |
| 498 |
|
| 499 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 500 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 501 |
} |
| 502 |
|
| 503 |
// template id. |
| 504 |
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : 0; |
| 505 |
if ( ! $template_id ) { |
| 506 |
wp_send_json_error( 'Bad request', 400 ); |
| 507 |
} |
| 508 |
|
| 509 |
// template. |
| 510 |
$email_templates = get_option( 'wpsc-email-templates' ); |
| 511 |
$et = array_key_exists( $template_id, $email_templates ) ? $email_templates[ $template_id ] : null; |
| 512 |
if ( ! $et ) { |
| 513 |
wp_send_json_error( 'Bad request', 400 ); |
| 514 |
} |
| 515 |
|
| 516 |
// title. |
| 517 |
$title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : ''; |
| 518 |
if ( ! $title ) { |
| 519 |
wp_send_json_error( 'Bad request', 400 ); |
| 520 |
} |
| 521 |
$et['title'] = $title; |
| 522 |
|
| 523 |
// conditions. |
| 524 |
$conditions = isset( $_POST['conditions'] ) ? sanitize_text_field( wp_unslash( $_POST['conditions'] ) ) : ''; |
| 525 |
if ( ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_en_conditions', $conditions ) ) { |
| 526 |
wp_send_json_error( 'Bad request', 400 ); |
| 527 |
} |
| 528 |
$et['conditions'] = $conditions; |
| 529 |
|
| 530 |
// subject. |
| 531 |
$subject = isset( $_POST['subject'] ) ? sanitize_text_field( wp_unslash( $_POST['subject'] ) ) : ''; |
| 532 |
if ( ! $subject ) { |
| 533 |
wp_send_json_error( 'Bad request', 400 ); |
| 534 |
} |
| 535 |
$et['subject'] = $subject; |
| 536 |
|
| 537 |
// body. |
| 538 |
$body = isset( $_POST['body'] ) ? wp_kses_post( wp_unslash( $_POST['body'] ) ) : ''; |
| 539 |
if ( ! $body ) { |
| 540 |
wp_send_json_error( 'Bad request', 400 ); |
| 541 |
} |
| 542 |
$et['body'] = array( |
| 543 |
'text' => $body, |
| 544 |
'editor' => isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : 'html', |
| 545 |
); |
| 546 |
|
| 547 |
// to. |
| 548 |
$general_recipients = isset( $_POST['to'] ) && isset( $_POST['to']['general-recipients'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['to']['general-recipients'] ) ) ) : array(); |
| 549 |
$agent_roles = isset( $_POST['to'] ) && isset( $_POST['to']['agent-roles'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['to']['agent-roles'] ) ) ) : array(); |
| 550 |
$custom = isset( $_POST['to'] ) && isset( $_POST['to']['custom'] ) ? sanitize_textarea_field( wp_unslash( $_POST['to']['custom'] ) ) : ''; |
| 551 |
$custom = array_unique( array_filter( array_map( 'sanitize_email', explode( PHP_EOL, $custom ) ) ) ); |
| 552 |
if ( ! ( $general_recipients || $agent_roles || $custom ) ) { |
| 553 |
wp_send_json_error( 'Bad request', 400 ); |
| 554 |
} |
| 555 |
$et['to'] = array( |
| 556 |
'general-recipients' => $general_recipients, |
| 557 |
'agent-roles' => $agent_roles, |
| 558 |
'custom' => $custom, |
| 559 |
); |
| 560 |
|
| 561 |
// cc. |
| 562 |
$general_recipients = isset( $_POST['cc'] ) && isset( $_POST['cc']['general-recipients'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['cc']['general-recipients'] ) ) ) : array(); |
| 563 |
$agent_roles = isset( $_POST['cc'] ) && isset( $_POST['cc']['agent-roles'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['cc']['agent-roles'] ) ) ) : array(); |
| 564 |
$custom = isset( $_POST['cc'] ) && isset( $_POST['cc']['custom'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cc']['custom'] ) ) : ''; |
| 565 |
$custom = array_unique( array_filter( array_map( 'sanitize_email', explode( PHP_EOL, $custom ) ) ) ); |
| 566 |
$et['cc'] = array( |
| 567 |
'general-recipients' => $general_recipients, |
| 568 |
'agent-roles' => $agent_roles, |
| 569 |
'custom' => $custom, |
| 570 |
); |
| 571 |
|
| 572 |
// bcc. |
| 573 |
$general_recipients = isset( $_POST['bcc'] ) && isset( $_POST['bcc']['general-recipients'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['bcc']['general-recipients'] ) ) ) : array(); |
| 574 |
$agent_roles = isset( $_POST['bcc'] ) && isset( $_POST['bcc']['agent-roles'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['bcc']['agent-roles'] ) ) ) : array(); |
| 575 |
$custom = isset( $_POST['bcc'] ) && isset( $_POST['bcc']['custom'] ) ? sanitize_textarea_field( wp_unslash( $_POST['bcc']['custom'] ) ) : ''; |
| 576 |
$custom = array_unique( array_filter( array_map( 'sanitize_email', explode( PHP_EOL, $custom ) ) ) ); |
| 577 |
$et['bcc'] = array( |
| 578 |
'general-recipients' => $general_recipients, |
| 579 |
'agent-roles' => $agent_roles, |
| 580 |
'custom' => $custom, |
| 581 |
); |
| 582 |
|
| 583 |
$email_templates[ $template_id ] = apply_filters( 'wpsc_en_set_edit_et', $et ); |
| 584 |
update_option( 'wpsc-email-templates', $email_templates ); |
| 585 |
|
| 586 |
// remove string translations. |
| 587 |
WPSC_Translations::remove( 'wpsc-en-tn-subject-' . $template_id ); |
| 588 |
WPSC_Translations::remove( 'wpsc-en-tn-body-' . $template_id ); |
| 589 |
|
| 590 |
// add string translations. |
| 591 |
WPSC_Translations::add( 'wpsc-en-tn-subject-' . $template_id, stripslashes( $et['subject'] ) ); |
| 592 |
WPSC_Translations::add( 'wpsc-en-tn-body-' . $template_id, stripslashes( $et['body']['text'] ) ); |
| 593 |
|
| 594 |
wp_die(); |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Print recipient options for "to", "cc" and "bcc" |
| 599 |
* |
| 600 |
* @param array $et -email templete. |
| 601 |
* @param string $type - one of "to", "cc" and "bcc". |
| 602 |
* @return void |
| 603 |
*/ |
| 604 |
public static function print_recipient_options( $et, $type ) { |
| 605 |
|
| 606 |
// general recipients. |
| 607 |
$gereral_recipients = array( |
| 608 |
'customer' => esc_attr__( 'Customer', 'supportcandy' ), |
| 609 |
'assignee' => esc_attr__( 'Assignee', 'supportcandy' ), |
| 610 |
); |
| 611 |
|
| 612 |
if ( $et['event'] == 'change-assignee' ) { |
| 613 |
$gereral_recipients['prev-assignee'] = esc_attr__( 'Previous Assignee', 'supportcandy' ); |
| 614 |
} |
| 615 |
|
| 616 |
if ( ! in_array( $et['event'], self::$ignore_current_user ) ) { |
| 617 |
$gereral_recipients['current-user'] = esc_attr__( 'Current User', 'supportcandy' ); |
| 618 |
} |
| 619 |
|
| 620 |
$gereral_recipients['add-recipients'] = esc_attr__( 'Additional Recipients', 'supportcandy' ); |
| 621 |
$gereral_recipients = apply_filters( 'wpsc_en_general_recipients', $gereral_recipients ); |
| 622 |
|
| 623 |
// agent roles. |
| 624 |
$agent_roles = get_option( 'wpsc-agent-roles' ); |
| 625 |
$unique_id = uniqid( 'wpsc_' ); |
| 626 |
|
| 627 |
$etgr = $et[ $type ]['general-recipients']; |
| 628 |
$etar = $et[ $type ]['agent-roles']; |
| 629 |
$etc = implode( PHP_EOL, $et[ $type ]['custom'] ); |
| 630 |
?> |
| 631 |
|
| 632 |
<div style="border: none;box-shadow: 0 0 3px 0 #a4b0be;border-radius: 5px;padding: 15px 15px 0 15px; background-color:#eee;"> |
| 633 |
<div class="wpsc-input-group"> |
| 634 |
<div class="label-container"><label for=""><?php esc_attr_e( 'General Recipients', 'supportcandy' ); ?></label></div> |
| 635 |
<select class="<?php echo esc_attr( $unique_id ); ?>" name="<?php echo esc_attr( $type ); ?>[general-recipients][]" multiple> |
| 636 |
<?php |
| 637 |
foreach ( $gereral_recipients as $key => $label ) { |
| 638 |
$selected = in_array( $key, $etgr ) ? 'selected' : '' |
| 639 |
?> |
| 640 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $label ); ?></option> |
| 641 |
<?php |
| 642 |
} |
| 643 |
?> |
| 644 |
</select> |
| 645 |
</div> |
| 646 |
<div class="wpsc-input-group"> |
| 647 |
<div class="label-container"><label for=""><?php esc_attr_e( 'Agent Roles', 'supportcandy' ); ?></label></div> |
| 648 |
<select class="<?php echo esc_attr( $unique_id ); ?>" name="<?php echo esc_attr( $type ); ?>[agent-roles][]" multiple> |
| 649 |
<?php |
| 650 |
foreach ( $agent_roles as $key => $role ) { |
| 651 |
$selected = in_array( $key, $etar ) ? 'selected' : '' |
| 652 |
?> |
| 653 |
<option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $role['label'] ); ?></option> |
| 654 |
<?php |
| 655 |
} |
| 656 |
?> |
| 657 |
</select> |
| 658 |
</div> |
| 659 |
<div class="wpsc-input-group"> |
| 660 |
<div class="label-container"><label for=""><?php esc_attr_e( 'Custom Email Addresses (one per line)', 'supportcandy' ); ?></label></div> |
| 661 |
<textarea name="<?php echo esc_attr( $type ); ?>[custom]"><?php echo esc_attr( $etc ); ?></textarea> |
| 662 |
</div> |
| 663 |
</div> |
| 664 |
<script type="text/javascript"> |
| 665 |
jQuery('.<?php echo esc_attr( $unique_id ); ?>').selectWoo({ |
| 666 |
allowClear: true, |
| 667 |
placeholder: "<?php esc_attr_e( 'Click to select options', 'supportcandy' ); ?>" |
| 668 |
}); |
| 669 |
</script> |
| 670 |
<?php |
| 671 |
} |
| 672 |
|
| 673 |
/** |
| 674 |
* Delete email notification |
| 675 |
* |
| 676 |
* @return void |
| 677 |
*/ |
| 678 |
public static function delete_ticket_notification() { |
| 679 |
|
| 680 |
if ( check_ajax_referer( 'wpsc_en_delete_ticket_notification', '_ajax_nonce', false ) != 1 ) { |
| 681 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 682 |
} |
| 683 |
|
| 684 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 685 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 686 |
} |
| 687 |
|
| 688 |
// template id. |
| 689 |
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : 0; |
| 690 |
if ( ! $template_id ) { |
| 691 |
wp_send_json_error( 'Bad request', 400 ); |
| 692 |
} |
| 693 |
|
| 694 |
// template. |
| 695 |
$email_templates = get_option( 'wpsc-email-templates' ); |
| 696 |
$et = array_key_exists( $template_id, $email_templates ) ? $email_templates[ $template_id ] : null; |
| 697 |
if ( ! $et ) { |
| 698 |
wp_send_json_error( 'Bad request', 400 ); |
| 699 |
} |
| 700 |
|
| 701 |
unset( $email_templates[ $template_id ] ); |
| 702 |
update_option( 'wpsc-email-templates', $email_templates ); |
| 703 |
|
| 704 |
// remove string translations. |
| 705 |
WPSC_Translations::remove( 'wpsc-en-tn-body-' . $template_id ); |
| 706 |
WPSC_Translations::remove( 'wpsc-en-tn-subject-' . $template_id ); |
| 707 |
|
| 708 |
wp_die(); |
| 709 |
} |
| 710 |
|
| 711 |
/** |
| 712 |
* Enable or Disable email notification |
| 713 |
* |
| 714 |
* @return void |
| 715 |
*/ |
| 716 |
public static function enable_disable_template() { |
| 717 |
|
| 718 |
if ( check_ajax_referer( 'wpsc_en_enable_disable_template', '_ajax_nonce', false ) != 1 ) { |
| 719 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 720 |
} |
| 721 |
|
| 722 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 723 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 724 |
} |
| 725 |
|
| 726 |
// template id. |
| 727 |
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : 0; |
| 728 |
if ( ! $template_id ) { |
| 729 |
wp_send_json_error( 'Bad request', 400 ); |
| 730 |
} |
| 731 |
|
| 732 |
// status. |
| 733 |
$status = isset( $_POST['status'] ) ? intval( $_POST['status'] ) : 0; |
| 734 |
|
| 735 |
$email_templates = get_option( 'wpsc-email-templates' ); |
| 736 |
$et = array_key_exists( $template_id, $email_templates ) ? $email_templates[ $template_id ] : null; |
| 737 |
if ( ! $et ) { |
| 738 |
wp_send_json_error( 'Bad request', 400 ); |
| 739 |
} |
| 740 |
|
| 741 |
$et['is_enable'] = $status; |
| 742 |
$email_templates[ $template_id ] = apply_filters( 'wpsc_en_enable_disable_et', $et ); |
| 743 |
update_option( 'wpsc-email-templates', $email_templates ); |
| 744 |
|
| 745 |
wp_die(); |
| 746 |
} |
| 747 |
|
| 748 |
/** |
| 749 |
* Filter conditions for email templates |
| 750 |
* |
| 751 |
* @param array $conditions - all possible ticket conditions. |
| 752 |
* @return array |
| 753 |
*/ |
| 754 |
public static function filter_conditions( $conditions ) { |
| 755 |
|
| 756 |
$ignore_list = apply_filters( |
| 757 |
'wpsc_en_conditions_ignore_list', |
| 758 |
array( |
| 759 |
'cft' => array( |
| 760 |
'df_last_reply_by', |
| 761 |
'df_last_reply_on', |
| 762 |
'cf_woo_order', |
| 763 |
'cf_woo_subscription', |
| 764 |
'cf_edd_order', |
| 765 |
'cf_tutor_order', |
| 766 |
'cf_learnpress_order', |
| 767 |
'cf_lifter_order', |
| 768 |
), // custom field types. |
| 769 |
'other' => array(), // other(custom) condition slug. |
| 770 |
) |
| 771 |
); |
| 772 |
|
| 773 |
foreach ( $conditions as $slug => $item ) { |
| 774 |
|
| 775 |
if ( $item['type'] == 'cf' ) { |
| 776 |
|
| 777 |
$cf = WPSC_Custom_Field::get_cf_by_slug( $slug ); |
| 778 |
if ( in_array( $cf->type::$slug, $ignore_list['cft'] ) ) { |
| 779 |
unset( $conditions[ $slug ] ); |
| 780 |
} |
| 781 |
} elseif ( in_array( $slug, $ignore_list['other'] ) ) { |
| 782 |
unset( $conditions[ $slug ] ); |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
return $conditions; |
| 787 |
} |
| 788 |
|
| 789 |
/** |
| 790 |
* Filter triggers for email notification templates |
| 791 |
* |
| 792 |
* @param array $triggers - all possible triggers. |
| 793 |
* @return array |
| 794 |
*/ |
| 795 |
public static function filter_triggers( $triggers ) { |
| 796 |
|
| 797 |
$ignore_list = apply_filters( 'wpsc_en_triggers_ignore_list', array() ); |
| 798 |
foreach ( $triggers as $key => $val ) { |
| 799 |
if ( in_array( $key, $ignore_list ) ) { |
| 800 |
unset( $triggers[ $key ] ); |
| 801 |
} |
| 802 |
} |
| 803 |
return $triggers; |
| 804 |
} |
| 805 |
|
| 806 |
/** |
| 807 |
* Get add clone ticket notification modal |
| 808 |
* |
| 809 |
* @return void |
| 810 |
*/ |
| 811 |
public static function get_clone_ticket_notification() { |
| 812 |
|
| 813 |
if ( check_ajax_referer( 'wpsc_en_get_clone_ticket_notification', '_ajax_nonce', false ) != 1 ) { |
| 814 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 815 |
} |
| 816 |
|
| 817 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 818 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 819 |
} |
| 820 |
|
| 821 |
// template id. |
| 822 |
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : 0; |
| 823 |
if ( ! $template_id ) { |
| 824 |
wp_send_json_error( 'Bad request', 400 ); |
| 825 |
} |
| 826 |
|
| 827 |
$email_templates = get_option( 'wpsc-email-templates' ); |
| 828 |
$et = array_key_exists( $template_id, $email_templates ) ? $email_templates[ $template_id ] : null; |
| 829 |
if ( ! $et ) { |
| 830 |
wp_send_json_error( 'Bad request', 400 ); |
| 831 |
} |
| 832 |
|
| 833 |
$title = esc_attr__( 'Clone notification', 'supportcandy' ); |
| 834 |
ob_start(); |
| 835 |
?> |
| 836 |
<form action="#" onsubmit="return false;" class="wpsc-en-add-clone"> |
| 837 |
<div class="wpsc-input-group"> |
| 838 |
<div class="label-container"> |
| 839 |
<label for=""> |
| 840 |
<?php esc_attr_e( 'Title', 'supportcandy' ); ?> |
| 841 |
<span class="required-char">*</span> |
| 842 |
</label> |
| 843 |
</div> |
| 844 |
<input type="text" name="title" value="<?php echo esc_attr( $et['title'] ); ?>" autocomplete="off"> |
| 845 |
</div> |
| 846 |
<?php WPSC_Triggers::print( 'event', 'wpsc_en_triggers', $et['event'], true, '', false ); ?> |
| 847 |
<?php do_action( 'wpsc_get_clone_ticket_notification' ); ?> |
| 848 |
<input type="hidden" name="template_id" value="<?php echo esc_attr( $template_id ); ?>"> |
| 849 |
<input type="hidden" name="action" value="wpsc_en_set_clone_ticket_notification"> |
| 850 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_en_set_clone_ticket_notification' ) ); ?>"> |
| 851 |
</form> |
| 852 |
<?php |
| 853 |
$body = ob_get_clean(); |
| 854 |
|
| 855 |
ob_start(); |
| 856 |
?> |
| 857 |
<button class="wpsc-button small primary" onclick="wpsc_en_set_clone_ticket_notification(this);"> |
| 858 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?> |
| 859 |
</button> |
| 860 |
<button class="wpsc-button small secondary" onclick="wpsc_close_modal();"> |
| 861 |
<?php esc_attr_e( 'Cancel', 'supportcandy' ); ?> |
| 862 |
</button> |
| 863 |
<?php |
| 864 |
$footer = ob_get_clean(); |
| 865 |
|
| 866 |
$response = array( |
| 867 |
'title' => $title, |
| 868 |
'body' => $body, |
| 869 |
'footer' => $footer, |
| 870 |
); |
| 871 |
wp_send_json( $response ); |
| 872 |
} |
| 873 |
|
| 874 |
/** |
| 875 |
* Set clone ticket notification |
| 876 |
* |
| 877 |
* @return void |
| 878 |
*/ |
| 879 |
public static function set_clone_ticket_notification() { |
| 880 |
|
| 881 |
if ( check_ajax_referer( 'wpsc_en_set_clone_ticket_notification', '_ajax_nonce', false ) != 1 ) { |
| 882 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 883 |
} |
| 884 |
|
| 885 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 886 |
wp_send_json_error( 'Unauthorized!', 401 ); |
| 887 |
} |
| 888 |
|
| 889 |
// template id. |
| 890 |
$template_id = isset( $_POST['template_id'] ) ? intval( $_POST['template_id'] ) : 0; |
| 891 |
if ( ! $template_id ) { |
| 892 |
wp_send_json_error( 'Bad request', 400 ); |
| 893 |
} |
| 894 |
|
| 895 |
// template. |
| 896 |
$email_templates = get_option( 'wpsc-email-templates' ); |
| 897 |
$et = array_key_exists( $template_id, $email_templates ) ? $email_templates[ $template_id ] : null; |
| 898 |
if ( ! $et ) { |
| 899 |
wp_send_json_error( 'Bad request', 400 ); |
| 900 |
} |
| 901 |
|
| 902 |
$title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( ( $_POST['title'] ) ) ) : ''; |
| 903 |
if ( ! $title ) { |
| 904 |
wp_send_json_error( 'Bad Request', 400 ); |
| 905 |
} |
| 906 |
|
| 907 |
$event = isset( $_POST['event'] ) ? sanitize_text_field( wp_unslash( ( $_POST['event'] ) ) ) : ''; |
| 908 |
if ( ! $event ) { |
| 909 |
wp_send_json_error( 'Bad Request', 400 ); |
| 910 |
} |
| 911 |
|
| 912 |
$clone = array( |
| 913 |
'title' => $title, |
| 914 |
'event' => $event, |
| 915 |
'is_enable' => 0, |
| 916 |
'subject' => $et['subject'], |
| 917 |
'body' => array( |
| 918 |
'text' => $et['body']['text'], |
| 919 |
'editor' => $et['body']['editor'], |
| 920 |
), |
| 921 |
'to' => array( |
| 922 |
'general-recipients' => $et['to']['general-recipients'], |
| 923 |
'agent-roles' => $et['to']['agent-roles'], |
| 924 |
'custom' => $et['to']['custom'], |
| 925 |
), |
| 926 |
'cc' => array( |
| 927 |
'general-recipients' => $et['cc']['general-recipients'], |
| 928 |
'agent-roles' => $et['cc']['agent-roles'], |
| 929 |
'custom' => $et['cc']['custom'], |
| 930 |
), |
| 931 |
'bcc' => array( |
| 932 |
'general-recipients' => $et['bcc']['general-recipients'], |
| 933 |
'agent-roles' => $et['bcc']['agent-roles'], |
| 934 |
'custom' => $et['bcc']['custom'], |
| 935 |
), |
| 936 |
'conditions' => $et['conditions'], |
| 937 |
); |
| 938 |
|
| 939 |
$clone = apply_filters( 'wpsc_en_clone_ticket_notification', $clone, $et ); |
| 940 |
|
| 941 |
$email_templates[] = $clone; |
| 942 |
|
| 943 |
WPSC_Translations::add( 'wpsc-en-tn-subject-' . array_key_last( $email_templates ), stripslashes( $et['subject'] ) ); |
| 944 |
WPSC_Translations::add( 'wpsc-en-tn-body-' . array_key_last( $email_templates ), stripslashes( $et['body']['text'] ) ); |
| 945 |
|
| 946 |
update_option( 'wpsc-email-templates', $email_templates ); |
| 947 |
|
| 948 |
end( $email_templates ); |
| 949 |
$index = key( $email_templates ); |
| 950 |
|
| 951 |
$nonce = wp_create_nonce( 'wpsc_en_get_edit_ticket_notification' ); |
| 952 |
wp_send_json( |
| 953 |
array( |
| 954 |
'index' => $index, |
| 955 |
'nonce' => $nonce, |
| 956 |
) |
| 957 |
); |
| 958 |
} |
| 959 |
} |
| 960 |
endif; |
| 961 |
|
| 962 |
WPSC_EN_Settings_TN::init(); |
| 963 |
|