PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.2
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 / frontend / class-wpsc-frontend.php

class-wpsc-frontend.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.2, at includes/frontend/class-wpsc-frontend.php

675 lines 23.6 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 if ( ! class_exists( 'WPSC_Frontend' ) ) :
7
8 final class WPSC_Frontend {
9
10 /**
11 * Initialize this class
12 */
13 public static function init() {
14
15 // Load scripts.
16 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
17
18 // ticket url redirect.
19 add_action( 'init', array( __CLASS__, 'ticket_url_redirect' ) );
20 }
21
22 /**
23 * Ticket url support for old versions
24 *
25 * @return void
26 */
27 public static function ticket_url_redirect() {
28
29 if ( isset( $_REQUEST['ticket_id'] ) && isset( $_REQUEST['auth_code'] ) ) { // phpcs:ignore
30
31 $id = isset( $_REQUEST['ticket_id'] ) ? intval( $_REQUEST['ticket_id'] ) : 0; // phpcs:ignore
32 if ( ! $id ) {
33 return;
34 }
35
36 $ticket = new WPSC_Ticket( $id );
37 if ( ! $ticket->id ) {
38 return;
39 }
40
41 wp_safe_redirect( $ticket->get_url() );
42 exit;
43 }
44 }
45
46 /**
47 * Load JS and CSS scripts
48 *
49 * @return void
50 */
51 public static function load_scripts() {
52
53 // Check load scripts setting to load script on perticular page.
54 if ( ! WPSC_Functions::is_load_scripts_page() ) {
55 return;
56 }
57
58 // jquery.
59 wp_enqueue_script( 'jquery' );
60 wp_enqueue_script( 'jquery-ui-core' );
61
62 // TinyMCE.
63 wp_enqueue_editor();
64
65 // jQuery UI Effects.
66 wp_enqueue_script( 'jquery-effects-core' );
67 wp_enqueue_script( 'jquery-effects-slide' );
68
69 // Sortable.
70 wp_enqueue_script( 'jquery-ui-sortable' );
71
72 // WPSC Framework.
73 wp_enqueue_script( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/scripts.js', array( 'jquery' ), WPSC_VERSION, true );
74
75 if ( is_rtl() ) {
76 wp_enqueue_style( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/style-rtl.css', array(), WPSC_VERSION );
77 } else {
78 wp_enqueue_style( 'wpsc-framework', WPSC_PLUGIN_URL . 'framework/style.css', array(), WPSC_VERSION );
79 }
80
81 wp_localize_script( 'wpsc-framework', 'supportcandy', self::get_localization_data() );
82
83 // selectWoo.
84 wp_enqueue_script( 'wpsc-selectWoo', WPSC_PLUGIN_URL . 'asset/js/selectWoo/selectWoo.full.min.js', array( 'jquery' ), WPSC_VERSION, true );
85 if ( file_exists( WPSC_ABSPATH . 'asset/js/selectWoo/i18n/' . get_locale() . '.js' ) ) {
86 wp_enqueue_script( 'selectWoo-lang', WPSC_PLUGIN_URL . 'asset/js/selectWoo/i18n/' . get_locale() . '.js', array( 'jquery' ), WPSC_VERSION, true );
87 }
88 wp_enqueue_style( 'wpsc-select2', WPSC_PLUGIN_URL . 'asset/css/select2.css', array(), WPSC_VERSION );
89
90 // gpopover.
91 wp_enqueue_script( 'gpopover', WPSC_PLUGIN_URL . 'asset/libs/gpopover/jquery.gpopover.js', array( 'jquery' ), WPSC_VERSION, true );
92 wp_enqueue_style( 'gpopover', WPSC_PLUGIN_URL . 'asset/libs/gpopover/jquery.gpopover.css', array(), WPSC_VERSION );
93
94 // jquery circle progress.
95 wp_enqueue_script( 'jquery-circle-progress', WPSC_PLUGIN_URL . 'asset/libs/jquery-circle-progress/circle-progress.min.js', array( 'jquery' ), WPSC_VERSION, true );
96
97 // flatpickr.
98 wp_enqueue_script( 'flatpickr-js', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/flatpickr.js', array( 'jquery' ), WPSC_VERSION, true );
99 wp_enqueue_style( 'flatpickr-css', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/flatpickr.min.css', array(), WPSC_VERSION );
100
101 if ( file_exists( WPSC_ABSPATH . 'asset/libs/flatpickr/l10n/' . WPSC_Functions::get_locale_iso() . '.js' ) ) {
102 wp_enqueue_script( 'flatpickr-lang', WPSC_PLUGIN_URL . 'asset/libs/flatpickr/l10n/' . WPSC_Functions::get_locale_iso() . '.js', array( 'jquery' ), WPSC_VERSION, true );
103 }
104
105 // fullcalendar.
106 wp_enqueue_script( 'fullcalendar', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/main.min.js', array( 'jquery' ), WPSC_VERSION, true );
107 wp_enqueue_script( 'fullcalendar-locales', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/locales-all.min.js', array( 'jquery' ), WPSC_VERSION, true );
108 wp_enqueue_style( 'fullcalendar', WPSC_PLUGIN_URL . 'asset/libs/fullcalendar/lib/main.min.css', array(), WPSC_VERSION );
109
110 // DataTables.
111 wp_enqueue_script( 'datatables', WPSC_PLUGIN_URL . 'asset/libs/DataTables/datatables.min.js', array( 'jquery' ), WPSC_VERSION, true );
112 wp_enqueue_style( 'datatables', WPSC_PLUGIN_URL . 'asset/libs/DataTables/datatables.min.css', array(), WPSC_VERSION );
113
114 // ChartJs.
115 wp_enqueue_script( 'chartjs', WPSC_PLUGIN_URL . 'asset/libs/chartjs/dist/chart.min.js', array( 'jquery' ), WPSC_VERSION, true );
116 }
117
118 /**
119 * Get localization data for the admin scripts
120 *
121 * @return array
122 */
123 private static function get_localization_data() {
124
125 $gs = get_option( 'wpsc-gs-general' );
126 $page_settings = get_option( 'wpsc-gs-page-settings' );
127 $file_settings = get_option( 'wpsc-gs-file-attachments' );
128
129 $localizations = array(
130 'ajax_url' => admin_url( 'admin-ajax.php' ),
131 'urls' => array(
132 'support' => $page_settings['support-page'] ? get_permalink( $page_settings['support-page'] ) : '',
133 'open_ticket' => $page_settings['open-ticket-page'] ? get_permalink( $page_settings['open-ticket-page'] ) : '',
134 ),
135 'plugin_url' => WPSC_PLUGIN_URL,
136 'version' => WPSC_VERSION,
137 'loader_html' => WPSC_Framework::loader_html(),
138 'inline_loader' => WPSC_Framework::inline_loader(),
139 'is_frontend' => 1,
140 'is_reload' => 1,
141 'reply_form_position' => $gs['reply-form-position'],
142 'allowed_file_extensions' => array_map( 'trim', array_map( 'strtolower', explode( ',', $file_settings['allowed-file-extensions'] ) ) ),
143 'nonce' => wp_create_nonce( 'general' ),
144 'translations' => array(
145 'req_fields_error' => esc_attr__( 'Required fields can not be empty!', 'supportcandy' ),
146 'datatables' => array(
147 'emptyTable' => esc_attr__( 'No Records', 'supportcandy' ),
148 'zeroRecords' => esc_attr__( 'No Records', 'supportcandy' ),
149 'info' => sprintf(
150 /* translators: e.g. Showing 1 to 20 of 300 records */
151 esc_attr__( 'Showing %1$s to %2$s of %3$s records', 'supportcandy' ),
152 '_START_',
153 '_END_',
154 '_TOTAL_'
155 ),
156 'infoEmpty' => '',
157 'loadingRecords' => '',
158 'processing' => '',
159 'infoFiltered' => '',
160 'search' => esc_attr__( 'Search:', 'supportcandy' ),
161 'paginate' => array(
162 'first' => esc_attr__( 'First', 'supportcandy' ),
163 'previous' => esc_attr__( 'Previous', 'supportcandy' ),
164 'next' => esc_attr__( 'Next', 'supportcandy' ),
165 'last' => esc_attr__( 'Last', 'supportcandy' ),
166 ),
167 ),
168 ),
169 'temp' => array(),
170 'home_url' => home_url(),
171 );
172
173 return apply_filters( 'wpsc_frontend_localizations', $localizations );
174 }
175
176 /**
177 * Authentication screen
178 *
179 * @param boolean $otp_login - otp login option.
180 * @param boolean $additional_links - additional links.
181 * @return void
182 */
183 public static function load_authentication_screen( $otp_login = true, $additional_links = true ) {
184
185 $gs = get_option( 'wpsc-gs-general' );
186 $page_settings = get_option( 'wpsc-gs-page-settings' );
187 $recaptcha = get_option( 'wpsc-recaptcha-settings' );
188 $tc = get_option( 'wpsc-term-and-conditions' );
189 $gdpr = get_option( 'wpsc-gdpr-settings' );
190 ?>
191 <div class="wpsc-auth-container">
192 <div class="auth-inner-container">
193 <h2><?php esc_attr_e( 'Please sign in', 'supportcandy' ); ?></h2>
194 <form onsubmit="return false;" class="wpsc-login wpsc-default-login">
195 <?php
196 if ( $page_settings['user-login'] === 'default' ) {
197 ?>
198
199 <input type="text" name="username" placeholder="<?php esc_attr_e( 'Username / Email address', 'supportcandy' ); ?>" autocomplete="off"/>
200 <input type="password" name="password" placeholder="<?php esc_attr_e( 'Password', 'supportcandy' ); ?>"/>
201 <div class="checkbox-container remember-me">
202 <input id="wpsc-remember-me" type="checkbox" name="remember_me" value="1"/>
203 <label for="wpsc-remember-me"><?php esc_attr_e( 'Remember me', 'supportcandy' ); ?></label>
204 </div>
205 <?php
206
207 // recaptcha.
208 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 2 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) :
209 $unique_id = uniqid( 'wpsc_' );
210 ?>
211 <script src="https://www.google.com/recaptcha/api.js?onload=recaptchaCallback&render=explicit" async defer></script> <?php // phpcs:ignore ?>
212 <div id="<?php echo esc_attr( $unique_id ); ?>" style="margin-bottom: 5px;"></div>
213 <script>
214 var recaptchaCallback = function() {
215 var obj = jQuery('#<?php echo esc_attr( $unique_id ); ?>');
216 grecaptcha.render(obj.attr("id"), {
217 "sitekey" : "<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>",
218 "callback" : function(token) {
219 obj.closest('form').find(".g-recaptcha-response").val(token);
220 }
221 });
222 }
223 </script>
224 <?php
225 endif;
226 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 3 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) :
227 ?>
228 <script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>"></script> <?php // phpcs:ignore ?>
229 <?php
230 endif;
231 if ( $recaptcha['captcha-provider'] === 'cloudflare-turnstile' && $recaptcha['cloudflare-site-key'] && $recaptcha['cloudflare-secret-key'] ) :
232 ?>
233 <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script> <?php // phpcs:ignore ?>
234 <div class="wpsc-tff turnstile wpsc-xs-12 wpsc-sm-12 wpsc-md-12 wpsc-lg-12 required wpsc-visible" data-cft="turnstile">
235 <div class="cf-turnstile" data-sitekey="<?php echo esc_attr( $recaptcha['cloudflare-site-key'] ); ?>"></div>
236 </div>
237 <?php
238 endif;
239 ?>
240
241 <button class="wpsc-button normal primary" onclick="wpsc_submit_login_form(this)"><?php esc_attr_e( 'Sign In', 'supportcandy' ); ?></button>
242 <input type="hidden" name="action" value="wpsc_default_login"/>
243 <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_default_login' ) ); ?>"/>
244 <?php
245
246 } else {
247 $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
248 $uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
249
250 $redirect_url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http' ) . '://' . $host . $uri;
251 $login_url = $page_settings['user-login'] == 'custom' ? $page_settings['custom-login-url'] : wp_login_url( $redirect_url );
252 ?>
253 <button class="wpsc-button normal primary" onclick="wpsc_custom_login( this, '<?php echo esc_url( $login_url ); ?>' )"><?php esc_attr_e( 'Sign In', 'supportcandy' ); ?></button>
254 <?php
255
256 }
257 ?>
258 </form>
259
260 <div class="auth-links">
261 <?php
262
263 if ( $page_settings['user-login'] === 'default' ) :
264 ?>
265 <a class="wpsc-link wpsc-forgot-password" href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_attr_e( 'Forgot your password?', 'supportcandy' ); ?></a>
266 <?php
267 endif;
268
269 if ( $page_settings['user-registration'] == 'default' ) {
270
271 $registration_url = 'javascript:wpsc_get_default_registration();';
272
273 } elseif ( $page_settings['user-registration'] == 'wp-default' ) {
274
275 $registration_url = wp_registration_url();
276
277 } elseif ( $page_settings['user-registration'] == 'custom' ) {
278
279 $registration_url = $page_settings['custom-registration-url'];
280 }
281 if ( $page_settings['user-registration'] !== 'disable' ) {
282 ?>
283 <a class="wpsc-link wpsc-register" href="<?php echo esc_attr( $registration_url ); ?>"><?php esc_attr_e( 'Register now', 'supportcandy' ); ?></a>
284 <?php
285 }
286 if ( $otp_login && $page_settings['otp-login'] && in_array( 'guest', $gs['allow-create-ticket'] ) ) :
287 ?>
288 <span class="wpsc-link wpsc-otp-signin" onclick="wpsc_get_guest_sign_in();"><?php esc_attr_e( 'Sign-in using one time password', 'supportcandy' ); ?></span>
289 <?php
290 endif;
291
292 if ( $additional_links && in_array( 'guest', $gs['allow-create-ticket'] ) ) :
293 ?>
294 <span class="wpsc-link wpsc-guest-create-ticket" onclick="wpsc_get_guest_ticket_form();"><?php esc_attr_e( 'Create new ticket as guest', 'supportcandy' ); ?></span>
295 <?php
296 endif;
297
298 if ( $additional_links && $page_settings['open-ticket-page'] ) :
299 ?>
300 <a class="wpsc-link wpsc-otp-open-ticket" href="<?php echo esc_url( get_permalink( $page_settings['open-ticket-page'] ) ); ?>"><?php esc_attr_e( 'Open existing ticket using one time password', 'supportcandy' ); ?></a>
301 <?php
302 endif;
303 ?>
304 </div>
305 </div>
306 <script>
307 /**
308 * Submit default login form
309 */
310 function wpsc_submit_login_form(el) {
311
312 var dataform = new FormData(jQuery(el).closest('form')[0]);
313 var username = dataform.get('username').trim();
314 var password = dataform.get('password').trim();
315 if (!username || !password) {
316 alert(supportcandy.translations.req_fields_missing);
317 return;
318 }
319 <?php
320 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 3 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
321 ?>
322 grecaptcha.ready(function() {
323 grecaptcha.execute('<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>', {action: 'submit_login'}).then(function(token) {
324 dataform.append('g-recaptcha-response', token);
325 wpsc_post_login_form(el, dataform);
326 });
327 });
328 <?php
329 } elseif ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 2 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
330 ?>
331 var token = dataform.get('g-recaptcha-response');
332 if (!token) {
333 alert("<?php esc_attr_e( 'Security verification failed. Please refresh the page and try again.', 'supportcandy' ); ?>");
334 return;
335 }
336 wpsc_post_login_form(el, dataform);
337 <?php
338 } else {
339 ?>
340
341 wpsc_post_login_form(el, dataform);
342 <?php
343 }
344 ?>
345 }
346
347 /**
348 * Submit login form
349 */
350 function wpsc_post_login_form(el, dataform) {
351
352 jQuery(el).text(supportcandy.translations.please_wait);
353 jQuery.ajax({
354 url: supportcandy.ajax_url,
355 type: 'POST',
356 data: dataform,
357 processData: false,
358 contentType: false
359 }).done(function (response) {
360 if (response.success) {
361 window.location.reload();
362 return;
363 }
364
365 if (response.data) {
366 if (typeof response.data === 'string') {
367 message = response.data;
368 } else if (response.data.message) {
369 message = response.data.message;
370 }
371 }
372 alert(message);
373 }).fail(function (xhr, status, error) {
374 let message = supportcandy.translations.something_wrong;
375
376 // Handle WP JSON errors (401, 403, 400)
377 if (xhr.responseJSON && xhr.responseJSON.data) {
378 if (typeof xhr.responseJSON.data === 'string') {
379 message = xhr.responseJSON.data;
380 } else if (xhr.responseJSON.data.message) {
381 message = xhr.responseJSON.data.message;
382 }
383 }
384
385 alert(message);
386 }).always(function () {
387 window.location.reload();
388 });
389 }
390
391 /**
392 * Custom login
393 */
394 function wpsc_custom_login(el, url) {
395
396 jQuery(el).text(supportcandy.translations.please_wait);
397 window.location.href = url;
398 }
399
400 /**
401 * Get default registration page
402 */
403 function wpsc_get_default_registration() {
404
405 jQuery('.auth-inner-container').html(supportcandy.loader_html);
406 var data = { action: 'wpsc_get_default_registration' };
407 jQuery.post(supportcandy.ajax_url, data, function (response) {
408 jQuery('.auth-inner-container').html(response);
409 });
410 }
411
412 /**
413 * Set default registration form
414 */
415 function wpsc_set_default_registration(el) {
416
417 var dataform = new FormData(jQuery(el).closest('form')[0]);
418 var firstname = dataform.get('firstname').trim();
419 var lastname = dataform.get('lastname').trim();
420 var username = dataform.get('username').trim();
421 var email_address = dataform.get('email_address').trim();
422 var password = dataform.get('password').trim();
423 var confirm_password = dataform.get('confirm_password').trim();
424 var isUsername = dataform.get('is_username').trim();
425 var isEmail = dataform.get('is_email').trim();
426
427 <?php
428 if ( $tc['allow-term-and-conditions-reg-user'] ) {
429 ?>
430 var tandcCheckbox = dataform.get('wpsc-tandc-reg-user');
431 if ( ! tandcCheckbox ){
432 alert(supportcandy.translations.req_term_cond);
433 return;
434 }
435 <?php
436 }
437 if ( $gdpr['allow-gdpr-reg-user'] ) {
438 ?>
439 var gdprCheckbox = dataform.get('wpsc-gdpr-reg-user');
440 if ( gdprCheckbox != 1 ){
441 alert(supportcandy.translations.req_gdpr);
442 return;
443 }
444 <?php
445 }
446 ?>
447
448 if (!firstname || !lastname || !username || !email_address || !password || !confirm_password) {
449 alert(supportcandy.translations.req_fields_missing);
450 return;
451 }
452
453 if (!validateEmail(email_address)) {
454 alert(supportcandy.translations.incorrect_email);
455 return;
456 }
457
458 if (isUsername != 1) {
459 alert(supportcandy.translations.unsername_unavailable);
460 return;
461 }
462
463 if (isEmail != 1) {
464 alert(supportcandy.translations.email_unavailable);
465 return;
466 }
467
468 if (password !== confirm_password) {
469 alert(supportcandy.translations.incorrect_password);
470 return;
471 }
472
473 <?php
474 if ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 3 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
475 ?>
476 grecaptcha.ready(function() {
477 grecaptcha.execute('<?php echo esc_attr( $recaptcha['recaptcha-site-key'] ); ?>', {action: 'submit_registration'}).then(function(token) {
478 dataform.append('g-recaptcha-response', token);
479 wpsc_authenticate_registration(el, dataform);
480 });
481 });
482 <?php
483 } elseif ( $recaptcha['captcha-provider'] === 'google-recaptcha' && $recaptcha['recaptcha-version'] == 2 && $recaptcha['recaptcha-site-key'] && $recaptcha['recaptcha-secret-key'] ) {
484 ?>
485 var token = dataform.get('g-recaptcha-response');
486 if (!token) {
487 alert("<?php esc_attr_e( 'Captcha not set!', 'supportcandy' ); ?>");
488 return;
489 }
490 wpsc_authenticate_registration(el, dataform);
491 <?php
492 } elseif ( $recaptcha['captcha-provider'] === 'cloudflare-turnstile' && $recaptcha['cloudflare-site-key'] && $recaptcha['cloudflare-secret-key'] ) {
493 ?>
494 var token = dataform.get('cf-turnstile-response');
495 if (!token) {
496 alert("<?php esc_attr_e( 'Security verification failed. Please refresh the page and try again.', 'supportcandy' ); ?>");
497 return;
498 }
499
500 dataform.set(
501 'cf-turnstile-response',
502 token
503 );
504 wpsc_authenticate_registration(el, dataform);
505 <?php
506
507 } else {
508 ?>
509
510 wpsc_authenticate_registration(el, dataform);
511 <?php
512 }
513 ?>
514 }
515
516 /**
517 * Post registration form
518 */
519 function wpsc_authenticate_registration(el, dataform) {
520
521 jQuery('.auth-inner-container').html(supportcandy.loader_html);
522 jQuery.ajax({
523 url: supportcandy.ajax_url,
524 type: 'POST',
525 data: dataform,
526 processData: false,
527 contentType: false
528 }).done(function (res) {
529 if (typeof(res) == "object") {
530 alert(supportcandy.translations.something_wrong);
531 wpsc_get_default_registration();
532 } else {
533 jQuery('.auth-inner-container').html(res);
534 }
535 }).fail(function (res) {
536 alert(supportcandy.translations.something_wrong);
537 window.location.reload();
538 });
539 }
540
541 /**
542 * Register user
543 */
544 function wpsc_confirm_registration(el) {
545
546 jQuery('.auth-inner-container').html(supportcandy.loader_html);
547 var dataform = new FormData(jQuery(el).closest('form')[0]);
548 jQuery.ajax({
549 url: supportcandy.ajax_url,
550 type: 'POST',
551 data: dataform,
552 processData: false,
553 contentType: false
554 }).done(function (res) {
555 if (res.isSuccess == 1) {
556 window.location.reload();
557 } else {
558 alert(supportcandy.translations.something_wrong);
559 wpsc_get_default_registration();
560 }
561 });
562 }
563
564 /**
565 * Get guest otp login screen
566 *
567 * @return void
568 */
569 function wpsc_get_guest_sign_in() {
570
571 jQuery('.auth-inner-container').html(supportcandy.loader_html);
572 var data = { action: 'wpsc_get_guest_sign_in' };
573 jQuery.post(supportcandy.ajax_url, data, function (res) {
574 if (typeof(res) == "object") {
575 alert(supportcandy.translations.something_wrong);
576 window.location.reload();
577 } else {
578 jQuery('.auth-inner-container').html(res);
579 }
580 });
581 }
582
583 /**
584 * Send login OTP
585 *
586 * @return void
587 */
588 function wpsc_authenticate_guest_login(el) {
589
590 var dataform = new FormData(jQuery(el).closest('form')[0]);
591
592 var email_address = dataform.get('email_address').trim();
593 if ( ! email_address ) {
594 alert(supportcandy.translations.req_fields_missing);
595 return;
596 }
597
598 if (!validateEmail(email_address)) {
599 alert(supportcandy.translations.incorrect_email);
600 return;
601 }
602
603 jQuery(el).text(supportcandy.translations.please_wait);
604 jQuery.ajax({
605 url: supportcandy.ajax_url,
606 type: 'POST',
607 data: dataform,
608 processData: false,
609 contentType: false
610 }).done(function (res) {
611 if (typeof(res) == "object") {
612 alert(supportcandy.translations.something_wrong);
613 wpsc_get_guest_sign_in();
614 } else {
615 jQuery('.auth-inner-container').html(res);
616 }
617 }).fail(function (res) {
618 alert(supportcandy.translations.something_wrong);
619 window.location.reload();
620 });
621 }
622
623 /**
624 * Confirm guest login auth
625 *
626 * @return void
627 */
628 function wpsc_confirm_guest_login(el) {
629
630 jQuery('.auth-inner-container').html(supportcandy.loader_html);
631 var dataform = new FormData(jQuery(el).closest('form')[0]);
632 jQuery.ajax({
633 url: supportcandy.ajax_url,
634 type: 'POST',
635 data: dataform,
636 processData: false,
637 contentType: false
638 }).done(function (res) {
639 if (res.isSuccess == 1) {
640 window.location.reload();
641 } else {
642 alert(supportcandy.translations.something_wrong);
643 wpsc_get_guest_sign_in();
644 }
645 });
646 }
647 </script>
648 </div>
649 <?php
650 }
651
652 /**
653 * Load HTML snippets that can be used by js to load dynamically
654 *
655 * @return void
656 */
657 public static function load_html_snippets() {
658 ?>
659
660 <div class="wpsc-page-snippets" style="display: none;">
661 <div class="wpsc-editor-attachment upload-waiting">
662 <div class="attachment-label"></div>
663 <div class="attachment-remove" onclick="wpsc_remove_attachment(this)">
664 <?php WPSC_Icons::get( 'times' ); ?>
665 </div>
666 <div class="attachment-waiting"></div>
667 </div>
668 </div>
669 <?php
670 }
671 }
672 endif;
673
674 WPSC_Frontend::init();
675