PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.9
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.9
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.4.9, at includes/frontend/class-wpsc-frontend.php

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