| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Shortcode_One' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Shortcode_One { |
| 9 |
|
| 10 |
/** |
| 11 |
* Tabs available for the user |
| 12 |
* |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
public static $sections = array(); |
| 16 |
|
| 17 |
/** |
| 18 |
* Current tab |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
public static $current_section = ''; |
| 23 |
|
| 24 |
/** |
| 25 |
* Allow create ticket for current user |
| 26 |
* |
| 27 |
* @var boolean |
| 28 |
*/ |
| 29 |
public static $allow_create_ticket = false; |
| 30 |
|
| 31 |
/** |
| 32 |
* Set whether ticket url is authenticated or not. |
| 33 |
* |
| 34 |
* @var boolean |
| 35 |
*/ |
| 36 |
public static $url_auth = false; |
| 37 |
|
| 38 |
/** |
| 39 |
* Initialize this class |
| 40 |
*/ |
| 41 |
public static function init() { |
| 42 |
|
| 43 |
// load sections. |
| 44 |
add_action( 'init', array( __CLASS__, 'load_sections' ), 100 ); |
| 45 |
|
| 46 |
// register shortcode. |
| 47 |
add_shortcode( 'supportcandy', array( __CLASS__, 'layout' ) ); |
| 48 |
|
| 49 |
// Add current section to localization data. |
| 50 |
add_filter( 'wpsc_frontend_localizations', array( __CLASS__, 'localizations' ) ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* "supportcandy" shortcode layout |
| 55 |
* |
| 56 |
* @param array $attrs - Shortcode attributes. |
| 57 |
* @return string |
| 58 |
*/ |
| 59 |
public static function layout( $attrs ) { |
| 60 |
|
| 61 |
$current_user = WPSC_Current_User::$current_user; |
| 62 |
|
| 63 |
// logout if guest login is open-ticket. |
| 64 |
if ( ( WPSC_Current_User::$login_type == 'guest' || WPSC_Current_User::$login_type == 'registered' ) && WPSC_Current_User::$guest_login_type == 'open-ticket' ) { |
| 65 |
$current_user->logout(); |
| 66 |
echo "<script type='text/javascript'> |
| 67 |
window.location.reload(); |
| 68 |
</script>"; |
| 69 |
} |
| 70 |
|
| 71 |
// ticket URL authentication. |
| 72 |
$advanced = get_option( 'wpsc-ms-advanced-settings' ); |
| 73 |
if ( ! $advanced['ticket-url-auth'] ) { |
| 74 |
|
| 75 |
$ticket_id = isset( $_REQUEST['ticket-id'] ) ? intval( $_REQUEST['ticket-id'] ) : 0; // phpcs:ignore |
| 76 |
if ( ! $ticket_id ) { |
| 77 |
$ticket_id = isset( $_REQUEST['ticket_id'] ) ? intval( $_REQUEST['ticket_id'] ) : 0; // phpcs:ignore |
| 78 |
} |
| 79 |
$auth_code = isset( $_REQUEST['auth-code'] ) ? sanitize_text_field( $_REQUEST['auth-code'] ) : ''; // phpcs:ignore |
| 80 |
if ( ! $auth_code ) { |
| 81 |
$auth_code = isset( $_REQUEST['auth_code'] ) ? sanitize_text_field( $_REQUEST['auth_code'] ) : ''; // phpcs:ignore |
| 82 |
} |
| 83 |
|
| 84 |
if ( $ticket_id && $auth_code ) { |
| 85 |
$ticket = new WPSC_Ticket( $ticket_id ); |
| 86 |
self::$url_auth = ( $ticket->auth_code && hash_equals( (string) $ticket->auth_code, $auth_code ) ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
ob_start();?> |
| 91 |
<div id="wpsc-container" style="display:none;"> |
| 92 |
<div class="wpsc-shortcode-container"> |
| 93 |
<?php |
| 94 |
|
| 95 |
if ( self::$sections ) { |
| 96 |
|
| 97 |
// add events for this shortcode. |
| 98 |
add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) ); |
| 99 |
add_action( 'wpsc_js_after_ticket_reply', array( __CLASS__, 'js_after_ticket_reply' ) ); |
| 100 |
add_action( 'wpsc_js_after_close_ticket', array( __CLASS__, 'js_after_close_ticket' ) ); |
| 101 |
add_action( 'wp_footer', array( __CLASS__, 'humbargar_menu' ) ); |
| 102 |
?> |
| 103 |
|
| 104 |
<div class="wpsc-header wpsc-hidden-xs"> |
| 105 |
<?php |
| 106 |
foreach ( self::$sections as $key => $section ) : |
| 107 |
$active = self::$current_section === $key ? 'active' : ''; |
| 108 |
?> |
| 109 |
<div class="wpsc-menu-list wpsc-tickets-nav <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" onclick="<?php echo esc_attr( $section['callback'] ) . '();'; ?>"> |
| 110 |
<?php WPSC_Icons::get( $section['icon'] ); ?> |
| 111 |
<label><?php echo esc_attr( $section['label'] ); ?></label> |
| 112 |
</div> |
| 113 |
<?php |
| 114 |
endforeach; |
| 115 |
?> |
| 116 |
<div class="wpsc-menu-list wpsc-tickets-nav log-out" onclick="wpsc_user_logout(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_user_logout' ) ); ?>');"> |
| 117 |
<?php WPSC_Icons::get( 'log-out' ); ?> |
| 118 |
<label><?php echo esc_attr__( 'Logout', 'supportcandy' ); ?></label> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
<div class="wpsc-header wpsc-visible-xs"> |
| 122 |
<div class="wpsc-humbargar-title"> |
| 123 |
<?php WPSC_Icons::get( self::$sections[ self::$current_section ]['icon'] ); ?> |
| 124 |
<label><?php echo esc_attr( self::$sections[ self::$current_section ]['label'] ); ?></label> |
| 125 |
</div> |
| 126 |
<div class="wpsc-humbargar" onclick="wpsc_toggle_humbargar();"> |
| 127 |
<?php WPSC_Icons::get( 'bars' ); ?> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
<div class="wpsc-body"></div> |
| 131 |
<?php |
| 132 |
|
| 133 |
} elseif ( self::$url_auth ) { |
| 134 |
|
| 135 |
?> |
| 136 |
<div class="wpsc-body"></div> |
| 137 |
<script> |
| 138 |
jQuery(document).ready(function(){ |
| 139 |
wpsc_get_individual_ticket(<?php echo intval( $ticket_id ); ?>); |
| 140 |
}); |
| 141 |
</script> |
| 142 |
<?php |
| 143 |
|
| 144 |
} else { |
| 145 |
|
| 146 |
WPSC_Frontend::load_authentication_screen(); |
| 147 |
} |
| 148 |
?> |
| 149 |
</div> |
| 150 |
</div> |
| 151 |
<?php |
| 152 |
WPSC_Frontend::load_html_snippets(); |
| 153 |
self::load_js_functions(); |
| 154 |
return ob_get_clean(); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Set tabs for this shortcode |
| 159 |
* |
| 160 |
* @return void |
| 161 |
*/ |
| 162 |
public static function load_sections() { |
| 163 |
|
| 164 |
$current_user = WPSC_Current_User::$current_user; |
| 165 |
$gs = get_option( 'wpsc-gs-general' ); |
| 166 |
$ms = get_option( 'wpsc-ms-advanced-settings' ); |
| 167 |
|
| 168 |
// allow create ticket. |
| 169 |
$allow_create_ticket = false; |
| 170 |
if ( $current_user->user->ID ) { |
| 171 |
|
| 172 |
// agent. |
| 173 |
if ( $current_user->is_agent && in_array( $current_user->agent->role, $gs['allow-create-ticket'] ) ) { |
| 174 |
$allow_create_ticket = true; |
| 175 |
} |
| 176 |
|
| 177 |
// registered user. |
| 178 |
if ( ! $current_user->is_agent && in_array( 'registered-user', $gs['allow-create-ticket'] ) ) { |
| 179 |
$allow_create_ticket = true; |
| 180 |
} |
| 181 |
} elseif ( in_array( 'guest', $gs['allow-create-ticket'] ) ) { |
| 182 |
|
| 183 |
// guest. |
| 184 |
$allow_create_ticket = true; |
| 185 |
} |
| 186 |
self::$allow_create_ticket = $allow_create_ticket; |
| 187 |
|
| 188 |
// return if guest user. |
| 189 |
if ( ! ( ! $current_user->is_guest || $current_user->is_customer ) ) { |
| 190 |
return; |
| 191 |
} |
| 192 |
|
| 193 |
// get default tab. |
| 194 |
$tab = 'ticket-list'; |
| 195 |
if ( $current_user->is_agent ) { |
| 196 |
$tab = $current_user->agent->get_default_tab(); |
| 197 |
} |
| 198 |
|
| 199 |
$section = array(); |
| 200 |
// Supportcandy dashboard. |
| 201 |
if ( $current_user->is_agent && $current_user->agent->has_cap( 'dash-access' ) ) { |
| 202 |
$sections['dashboard'] = array( |
| 203 |
'slug' => 'dashboard', |
| 204 |
'icon' => 'dashboard', |
| 205 |
'label' => esc_attr__( 'Dashboard', 'supportcandy' ), |
| 206 |
'callback' => 'wpsc_get_agent_dashboard', |
| 207 |
); |
| 208 |
} |
| 209 |
|
| 210 |
// ticket list. |
| 211 |
$sections['ticket-list'] = array( |
| 212 |
'slug' => 'ticket_list', |
| 213 |
'icon' => 'list-alt', |
| 214 |
'label' => esc_attr__( 'Ticket List', 'supportcandy' ), |
| 215 |
'callback' => 'wpsc_get_ticket_list', |
| 216 |
); |
| 217 |
|
| 218 |
// new ticket. |
| 219 |
if ( $allow_create_ticket ) { |
| 220 |
$sections['new-ticket'] = array( |
| 221 |
'slug' => 'new_ticket', |
| 222 |
'icon' => 'plus-square', |
| 223 |
'label' => esc_attr__( 'New Ticket', 'supportcandy' ), |
| 224 |
'callback' => 'wpsc_get_ticket_form', |
| 225 |
); |
| 226 |
} |
| 227 |
|
| 228 |
// my profile. |
| 229 |
if ( $ms['allow-my-profile'] ) { |
| 230 |
$sections['my-profile'] = array( |
| 231 |
'slug' => 'my_profile', |
| 232 |
'icon' => 'id-card', |
| 233 |
'label' => esc_attr__( 'My Profile', 'supportcandy' ), |
| 234 |
'callback' => 'wpsc_get_user_profile', |
| 235 |
); |
| 236 |
} |
| 237 |
|
| 238 |
// agent profile. |
| 239 |
if ( $current_user->is_agent && $ms['allow-agent-profile'] ) { |
| 240 |
$sections['agent-profile'] = array( |
| 241 |
'slug' => 'agent_profile', |
| 242 |
'icon' => 'headset', |
| 243 |
'label' => esc_attr__( 'Agent Profile', 'supportcandy' ), |
| 244 |
'callback' => 'wpsc_get_agent_profile', |
| 245 |
); |
| 246 |
} |
| 247 |
|
| 248 |
self::$sections = apply_filters( 'wpsc_shortcode_sections', $sections ); |
| 249 |
self::$current_section = isset( $_REQUEST['wpsc-section'] ) ? sanitize_text_field( $_REQUEST['wpsc-section'] ) : $tab; // phpcs:ignore |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Add localizations to local JS |
| 254 |
* |
| 255 |
* @param array $localizations - localization list. |
| 256 |
* @return array |
| 257 |
*/ |
| 258 |
public static function localizations( $localizations ) { |
| 259 |
|
| 260 |
// Humbargar Titles. |
| 261 |
$localizations['humbargar_titles'] = self::get_humbargar_titles(); |
| 262 |
|
| 263 |
// Current section. |
| 264 |
$localizations['current_section'] = self::$current_section; |
| 265 |
|
| 266 |
// Current ticket id. |
| 267 |
if ( self::$current_section === 'ticket-list' && isset( $_REQUEST['ticket-id'] ) ) { // phpcs:ignore |
| 268 |
$localizations['current_ticket_id'] = intval( $_REQUEST['ticket-id'] ); // phpcs:ignore |
| 269 |
} |
| 270 |
|
| 271 |
return $localizations; |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* Print humbargar menu in footer |
| 276 |
* |
| 277 |
* @return void |
| 278 |
*/ |
| 279 |
public static function humbargar_menu() { |
| 280 |
|
| 281 |
$current_user = WPSC_Current_User::$current_user; |
| 282 |
?> |
| 283 |
<div class="wpsc-humbargar-overlay" onclick="wpsc_toggle_humbargar();" style="display:none"></div> |
| 284 |
<div class="wpsc-humbargar-menu" style="display:none"> |
| 285 |
<div class="box-inner"> |
| 286 |
<div class="wpsc-humbargar-close" onclick="wpsc_toggle_humbargar();"> |
| 287 |
<?php WPSC_Icons::get( 'times' ); ?> |
| 288 |
</div> |
| 289 |
<?php |
| 290 |
foreach ( self::$sections as $key => $section ) : |
| 291 |
|
| 292 |
$active = self::$current_section === $key ? 'active' : ''; |
| 293 |
?> |
| 294 |
<div |
| 295 |
class="wpsc-humbargar-menu-item <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" |
| 296 |
onclick="<?php echo esc_attr( $section['callback'] ) . '(true);'; ?>"> |
| 297 |
<?php WPSC_Icons::get( $section['icon'] ); ?> |
| 298 |
<label><?php echo esc_attr( $section['label'] ); ?></label> |
| 299 |
</div> |
| 300 |
<?php endforeach; ?> |
| 301 |
<div class="wpsc-humbargar-menu-item log-out" onclick="wpsc_user_logout(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_user_logout' ) ); ?>');"> |
| 302 |
<?php WPSC_Icons::get( 'log-out' ); ?> |
| 303 |
<label><?php echo esc_attr__( 'Logout', 'supportcandy' ); ?></label> |
| 304 |
</div> |
| 305 |
</div> |
| 306 |
</div> |
| 307 |
<?php |
| 308 |
} |
| 309 |
|
| 310 |
/** |
| 311 |
* Humbargar mobile titles to be used in localizations |
| 312 |
* |
| 313 |
* @return array |
| 314 |
*/ |
| 315 |
private static function get_humbargar_titles() { |
| 316 |
|
| 317 |
$titles = array(); |
| 318 |
foreach ( self::$sections as $section ) { |
| 319 |
|
| 320 |
ob_start(); |
| 321 |
WPSC_Icons::get( $section['icon'] ); |
| 322 |
echo '<label>' . esc_attr( $section['label'] ) . '</label>'; |
| 323 |
$titles[ $section['slug'] ] = ob_get_clean(); |
| 324 |
} |
| 325 |
return $titles; |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* Load js functions for this shortcode |
| 330 |
* |
| 331 |
* @return void |
| 332 |
*/ |
| 333 |
public static function load_js_functions() { |
| 334 |
?> |
| 335 |
|
| 336 |
<script type="text/javascript"> |
| 337 |
|
| 338 |
/** |
| 339 |
* Get ticket list |
| 340 |
*/ |
| 341 |
function wpsc_get_ticket_list(is_humbargar = false) { |
| 342 |
|
| 343 |
supportcandy.current_section = 'ticket-list'; |
| 344 |
|
| 345 |
if (is_humbargar) wpsc_toggle_humbargar(); |
| 346 |
|
| 347 |
if (wpsc_is_description_text()) { |
| 348 |
if ( !confirm(supportcandy.translations.warning_message)){ |
| 349 |
return; |
| 350 |
} else { |
| 351 |
var is_tinymce = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden(); |
| 352 |
if (is_tinymce && tinymce.get('description')) { |
| 353 |
var description = tinyMCE.get('description').setContent(''); |
| 354 |
} else { |
| 355 |
var description = jQuery('#description').val(''); |
| 356 |
} |
| 357 |
ticket_id = jQuery('#wpsc-current-ticket').val(); |
| 358 |
wpsc_clear_saved_draft_reply( ticket_id ); |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
var id = supportcandy.current_ticket_id; |
| 363 |
if (id) { |
| 364 |
delete supportcandy.current_ticket_id; |
| 365 |
wpsc_get_individual_ticket(id); |
| 366 |
return; |
| 367 |
} |
| 368 |
|
| 369 |
wpsc_update_live_agents(); |
| 370 |
|
| 371 |
// set flag to differenciate between ticket list and individual ticket |
| 372 |
supportcandy.ticketListIsIndividual = false; |
| 373 |
|
| 374 |
jQuery('.wpsc-tickets-nav, .wpsc-humbargar-menu-item').removeClass('active'); |
| 375 |
jQuery('.wpsc-tickets-nav.ticket-list, .wpsc-humbargar-menu-item.ticket-list').addClass('active'); |
| 376 |
jQuery('.wpsc-humbargar-title').html(supportcandy.humbargar_titles.ticket_list); |
| 377 |
|
| 378 |
// set url |
| 379 |
var url = new URL(window.location.href); |
| 380 |
var search_params = url.searchParams; |
| 381 |
search_params.set('wpsc-section', 'ticket-list'); |
| 382 |
search_params.delete('ticket-id'); |
| 383 |
url.search = search_params.toString(); |
| 384 |
window.history.replaceState({}, null, url.toString()); |
| 385 |
|
| 386 |
jQuery('.wpsc-body').html(supportcandy.loader_html); |
| 387 |
|
| 388 |
var data = { |
| 389 |
action: 'wpsc_get_ticket_list', |
| 390 |
_ajax_nonce: supportcandy.nonce, |
| 391 |
is_frontend: supportcandy.is_frontend |
| 392 |
}; |
| 393 |
search_params.forEach(function(value, key) { |
| 394 |
data[key] = value; |
| 395 |
}); |
| 396 |
if (typeof supportcandy.ticketList != 'undefined' && typeof supportcandy.ticketList.filters != 'undefined') { |
| 397 |
data.filters = supportcandy.ticketList.filters; |
| 398 |
} |
| 399 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 400 |
jQuery('.wpsc-body').html(response); |
| 401 |
wpsc_reset_responsive_style(); |
| 402 |
}); |
| 403 |
wpsc_delete_auto_draft(); |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* Get individual ticket |
| 408 |
*/ |
| 409 |
function wpsc_get_individual_ticket(id) { |
| 410 |
|
| 411 |
jQuery('.wpsc-tickets-nav, .wpsc-humbargar-menu-item').removeClass('active'); |
| 412 |
jQuery('.wpsc-tickets-nav.ticket-list, .wpsc-humbargar-menu-item.ticket-list').addClass('active'); |
| 413 |
jQuery('.wpsc-humbargar-title').html(supportcandy.humbargar_titles.ticket_list); |
| 414 |
|
| 415 |
// set url |
| 416 |
var url = new URL(window.location.href); |
| 417 |
var search_params = url.searchParams; |
| 418 |
search_params.set('wpsc-section', 'ticket-list'); |
| 419 |
search_params.set('ticket-id', id); |
| 420 |
url.search = search_params.toString(); |
| 421 |
window.history.replaceState({}, null, url.toString()); |
| 422 |
|
| 423 |
jQuery('.wpsc-body').html(supportcandy.loader_html); |
| 424 |
|
| 425 |
// set flag to differenciate between ticket list and individual ticket |
| 426 |
supportcandy.ticketListIsIndividual = true; |
| 427 |
|
| 428 |
var data = { |
| 429 |
action: 'wpsc_get_individual_ticket', |
| 430 |
ticket_id: id, |
| 431 |
}; |
| 432 |
search_params.forEach(function(value, key) { |
| 433 |
data[key] = value; |
| 434 |
}); |
| 435 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 436 |
jQuery('.wpsc-body').html(response); |
| 437 |
wpsc_reset_responsive_style(); |
| 438 |
}); |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* Get create ticket form |
| 443 |
*/ |
| 444 |
function wpsc_get_ticket_form(is_humbargar = false) { |
| 445 |
<?php |
| 446 |
|
| 447 |
$pgsettings = get_option( 'wpsc-gs-page-settings' ); |
| 448 |
if ( $pgsettings['new-ticket-page'] == 'custom' && $pgsettings['new-ticket-url'] ) : |
| 449 |
?> |
| 450 |
window.location = "<?php echo esc_url( $pgsettings['new-ticket-url'] ); ?>"; |
| 451 |
return; |
| 452 |
<?php |
| 453 |
endif; |
| 454 |
?> |
| 455 |
|
| 456 |
supportcandy.current_section = 'new-ticket'; |
| 457 |
|
| 458 |
if (is_humbargar) wpsc_toggle_humbargar(); |
| 459 |
|
| 460 |
if (wpsc_is_description_text()) { |
| 461 |
if ( confirm(supportcandy.translations.warning_message)){ |
| 462 |
current_ticket = jQuery('#wpsc-current-ticket').val(); |
| 463 |
wpsc_clear_saved_draft_reply( current_ticket ); |
| 464 |
} else{ |
| 465 |
return; |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
jQuery('.wpsc-tickets-nav, .wpsc-humbargar-menu-item').removeClass('active'); |
| 470 |
jQuery('.wpsc-tickets-nav.new-ticket, .wpsc-humbargar-menu-item.new-ticket').addClass('active'); |
| 471 |
jQuery('.wpsc-humbargar-title').html(supportcandy.humbargar_titles.new_ticket); |
| 472 |
|
| 473 |
wpsc_update_live_agents(); |
| 474 |
|
| 475 |
// set url |
| 476 |
var url = new URL(window.location.href); |
| 477 |
var search_params = url.searchParams; |
| 478 |
search_params.set('wpsc-section', 'new-ticket'); |
| 479 |
search_params.delete('ticket-id'); |
| 480 |
url.search = search_params.toString(); |
| 481 |
window.history.replaceState({}, null, url.toString()); |
| 482 |
|
| 483 |
jQuery('.wpsc-body').html(supportcandy.loader_html); |
| 484 |
|
| 485 |
var data = { |
| 486 |
action: 'wpsc_get_ticket_form', |
| 487 |
_ajax_nonce: supportcandy.nonce |
| 488 |
}; |
| 489 |
search_params.forEach(function(value, key) { |
| 490 |
data[key] = value; |
| 491 |
}); |
| 492 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 493 |
jQuery('.wpsc-body').html(response); |
| 494 |
wpsc_reset_responsive_style(); |
| 495 |
}); |
| 496 |
} |
| 497 |
|
| 498 |
/** |
| 499 |
* Get agent settings |
| 500 |
*/ |
| 501 |
function wpsc_get_user_profile(is_humbargar = false) { |
| 502 |
|
| 503 |
supportcandy.current_section = 'my-profile'; |
| 504 |
|
| 505 |
if (is_humbargar) wpsc_toggle_humbargar(); |
| 506 |
|
| 507 |
jQuery('.wpsc-tickets-nav, .wpsc-humbargar-menu-item').removeClass('active'); |
| 508 |
jQuery('.wpsc-tickets-nav.my-profile, .wpsc-humbargar-menu-item.my-profile').addClass('active'); |
| 509 |
jQuery('.wpsc-humbargar-title').html(supportcandy.humbargar_titles.my_profile); |
| 510 |
|
| 511 |
wpsc_update_live_agents(); |
| 512 |
|
| 513 |
// set url |
| 514 |
var url = new URL(window.location.href); |
| 515 |
var search_params = url.searchParams; |
| 516 |
search_params.set('wpsc-section', 'my-profile'); |
| 517 |
search_params.delete('ticket-id'); |
| 518 |
url.search = search_params.toString(); |
| 519 |
window.history.replaceState({}, null, url.toString()); |
| 520 |
|
| 521 |
jQuery('.wpsc-body').html(supportcandy.loader_html); |
| 522 |
|
| 523 |
var data = { action: 'wpsc_get_user_profile' }; |
| 524 |
search_params.forEach(function(value, key) { |
| 525 |
data[key] = value; |
| 526 |
}); |
| 527 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 528 |
jQuery('.wpsc-body').html(response); |
| 529 |
wpsc_reset_responsive_style(); |
| 530 |
}); |
| 531 |
} |
| 532 |
|
| 533 |
/** |
| 534 |
* Get agent settings |
| 535 |
*/ |
| 536 |
function wpsc_get_agent_profile(is_humbargar = false) { |
| 537 |
|
| 538 |
supportcandy.current_section = 'agent-profile'; |
| 539 |
|
| 540 |
if (is_humbargar) wpsc_toggle_humbargar(); |
| 541 |
|
| 542 |
jQuery('.wpsc-tickets-nav, .wpsc-humbargar-menu-item').removeClass('active'); |
| 543 |
jQuery('.wpsc-tickets-nav.agent-profile, .wpsc-humbargar-menu-item.agent-profile').addClass('active'); |
| 544 |
jQuery('.wpsc-humbargar-title').html(supportcandy.humbargar_titles.agent_profile); |
| 545 |
|
| 546 |
wpsc_update_live_agents(); |
| 547 |
|
| 548 |
// set url |
| 549 |
var url = new URL(window.location.href); |
| 550 |
var search_params = url.searchParams; |
| 551 |
search_params.set('wpsc-section', 'agent-profile'); |
| 552 |
search_params.delete('ticket-id'); |
| 553 |
url.search = search_params.toString(); |
| 554 |
window.history.replaceState({}, null, url.toString()); |
| 555 |
|
| 556 |
jQuery('.wpsc-body').html(supportcandy.loader_html); |
| 557 |
|
| 558 |
var data = { action: 'wpsc_get_agent_profile' }; |
| 559 |
search_params.forEach(function(value, key) { |
| 560 |
data[key] = value; |
| 561 |
}); |
| 562 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 563 |
jQuery('.wpsc-body').html(response); |
| 564 |
wpsc_reset_responsive_style(); |
| 565 |
jQuery('.wpsc-ap-nav.general').trigger('click'); |
| 566 |
}); |
| 567 |
} |
| 568 |
|
| 569 |
/** |
| 570 |
* Get agent dashboard |
| 571 |
*/ |
| 572 |
function wpsc_get_agent_dashboard(is_humbargar = false) { |
| 573 |
|
| 574 |
supportcandy.current_section = 'dashboard'; |
| 575 |
|
| 576 |
if (is_humbargar) { |
| 577 |
wpsc_toggle_humbargar(); |
| 578 |
} |
| 579 |
|
| 580 |
jQuery( '.wpsc-tickets-nav, .wpsc-humbargar-menu-item' ).removeClass( 'active' ); |
| 581 |
jQuery( '.wpsc-tickets-nav.dashboard, .wpsc-humbargar-menu-item.dashboard' ).addClass( 'active' ); |
| 582 |
jQuery( '.wpsc-humbargar-title' ).html( supportcandy.humbargar_titles.dashboard ); |
| 583 |
|
| 584 |
wpsc_update_live_agents(); |
| 585 |
|
| 586 |
// set url |
| 587 |
var url = new URL(window.location.href); |
| 588 |
var search_params = url.searchParams; |
| 589 |
search_params.set('wpsc-section', 'dashboard'); |
| 590 |
search_params.delete('ticket-id'); |
| 591 |
url.search = search_params.toString(); |
| 592 |
window.history.replaceState({}, null, url.toString()); |
| 593 |
jQuery( '.wpsc-body' ).html( supportcandy.loader_html ); |
| 594 |
|
| 595 |
var data = { action: 'wpsc_get_agent_dashboard' }; |
| 596 |
search_params.forEach(function(value, key) { |
| 597 |
data[key] = value; |
| 598 |
}); |
| 599 |
|
| 600 |
jQuery.post( |
| 601 |
supportcandy.ajax_url, |
| 602 |
data, |
| 603 |
function (response) { |
| 604 |
jQuery( '.wpsc-body' ).html( response ); |
| 605 |
wpsc_reset_responsive_style(); |
| 606 |
jQuery( '.wpsc-ap-nav.general' ).trigger( 'click' ); |
| 607 |
} |
| 608 |
); |
| 609 |
} |
| 610 |
|
| 611 |
/** |
| 612 |
* Get create ticket as guest |
| 613 |
*/ |
| 614 |
function wpsc_get_guest_ticket_form() { |
| 615 |
|
| 616 |
jQuery('.wpsc-shortcode-container').html('<div class="wpsc-body"></div>'); |
| 617 |
wpsc_get_ticket_form(); |
| 618 |
} |
| 619 |
|
| 620 |
/** |
| 621 |
* Update live agents |
| 622 |
*/ |
| 623 |
function wpsc_update_live_agents() { |
| 624 |
|
| 625 |
if (!supportcandy.ticketListIsIndividual) { |
| 626 |
return; |
| 627 |
} |
| 628 |
agent_id = jQuery("#wpsc-current-agent").val(); |
| 629 |
if (!agent_id) { |
| 630 |
return; |
| 631 |
} |
| 632 |
if (typeof supportcandy.agent_collision === "undefined" || !supportcandy.agent_collision) { |
| 633 |
return; |
| 634 |
} |
| 635 |
|
| 636 |
ticket_id = jQuery("#wpsc-current-ticket").val(); |
| 637 |
var data = { action: 'wpsc_check_live_agents', agent_id, ticket_id, operation: 'leave', _ajax_nonce: supportcandy.nonce }; |
| 638 |
jQuery.post( |
| 639 |
supportcandy.ajax_url, |
| 640 |
data, |
| 641 |
function (response) { |
| 642 |
} |
| 643 |
); |
| 644 |
} |
| 645 |
</script> |
| 646 |
<?php |
| 647 |
} |
| 648 |
|
| 649 |
/** |
| 650 |
* Register JS functions to call on document ready |
| 651 |
* |
| 652 |
* @return void |
| 653 |
*/ |
| 654 |
public static function register_js_ready_function() { |
| 655 |
|
| 656 |
if ( self::$sections ) { |
| 657 |
echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL; |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
/** |
| 662 |
* After ticket reply |
| 663 |
* |
| 664 |
* @return void |
| 665 |
*/ |
| 666 |
public static function js_after_ticket_reply() { |
| 667 |
|
| 668 |
$current_user = WPSC_Current_User::$current_user; |
| 669 |
|
| 670 |
$agent_settings = get_option( 'wpsc-tl-ms-agent-view' ); |
| 671 |
$customer_settings = get_option( 'wpsc-tl-ms-customer-view' ); |
| 672 |
$redirect = $current_user->is_agent ? $agent_settings['ticket-reply-redirect'] : $customer_settings['ticket-reply-redirect']; |
| 673 |
$call_to_function = $redirect == 'ticket-list' ? 'wpsc_get_ticket_list();' : 'wpsc_get_individual_ticket(ticket_id)'; |
| 674 |
echo esc_attr( $call_to_function ) . PHP_EOL; |
| 675 |
} |
| 676 |
|
| 677 |
/** |
| 678 |
* JS after close ticket |
| 679 |
* |
| 680 |
* @return void |
| 681 |
*/ |
| 682 |
public static function js_after_close_ticket() { |
| 683 |
|
| 684 |
echo 'wpsc_get_ticket_list();' . PHP_EOL; |
| 685 |
} |
| 686 |
} |
| 687 |
endif; |
| 688 |
|
| 689 |
WPSC_Shortcode_One::init(); |
| 690 |
|