/home3/bmscom/webinar.bmice.com/wp-content/plugins/webinar-ignition/inc/lp/auto-register.php
<?php defined( 'ABSPATH' ) || exit; ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo $webinar_data->webinar_desc; ?></title>

    <?php wp_head(); ?>

</head>
<body id="auto-register">
    <script>
        <?php
        //make the thank you page url
        if($webinar_data->custom_ty_url_state === 'show' && !empty($webinar_data->custom_ty_url)) {
            $thank_you_page_url = $webinar_data->custom_ty_url;
        } else {
            $thank_you_page_url = ( isset($webinar_data->webinar_switch) && $webinar_data->webinar_switch == 'live' ) ?  parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) . '?live' : parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) . '?confirmed';
            if($webinar_data->paid_status === 'paid')
                $thank_you_page_url .= '&' . urlencode($webinar_data->paid_code);
        }

        $readonly = isset($_GET['readonly']) ? '&readonly=' . $_GET['readonly'] : '';
        $login = isset($_GET['login']) ? '&login=' . $_GET['login'] : '';
        $thank_you_page_url .= '&first=' . $name . '&email='. $email . $readonly . $login ;
        $email = isset($_GET['e']) ? htmlspecialchars($_GET['e']) : null;
        
        ?>

        var thank_you_url = '<?php echo $thank_you_page_url; ?>';
        var webinar_type = "<?php echo $webinar_data->webinar_date == 'AUTO' ? 'evergreen' : 'live';?>";

        jQuery(document).ready(function () {

            jQuery('#ar_submit_iframe').on('load', function (event) {
                if (!jQuery(this).data('can_load')) {
                    return false;
                }
                window.location.href = thank_you_url;
            });
            /**
             *Email was creating issue so we will validate the email first before moving one
             *wig prefix
             **/
            function wigValidateEmail(email) {
                return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
            }

            let registerEmail = "<?php echo $email; ?>";
            if (!wigValidateEmail(registerEmail)) {
                alert("<?php _e( 'Please enter a valid email and try again...', 'webinarignition' ) ; ?>");
                return;
            }


            // on load submit information & submit AR Form...

            // AJAX FOR WP
            var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
            var data = {
                action: 'webinarignition_add_lead_auto_reg',
                security:       '<?php echo wp_create_nonce("webinarignition_ajax_nonce"); ?>',
                id:     "<?php echo $webinar_id; ?>",
                name:   "<?php echo is_email($email) ? $name : base64_decode($name); ?>",
                email:  "<?php echo is_email($email) ? $email : base64_decode($email); ?>",
                ip:     "<?php echo $_SERVER['REMOTE_ADDR']; ?>",
                source: "AutoReg"
            };
            

            console.log("webinar type is " + webinar_type);

            if( webinar_type == 'live' ){

                /**
                 * Before send email verification code.Lets get permission from settings.
                 * this is string value and can contain three possible values and these are
                 */

                // this variable can be true or false
                let webinar_email_verification_setting = '<?php echo $webinar_data->email_verification; ?>';

                let email_verification_enabled = true;
                if(webinar_email_verification_setting === 'global')
                    email_verification_enabled = <?php echo json_encode(filter_var(get_option('webinarignition_email_verification', 0), FILTER_VALIDATE_BOOLEAN)); ?>;
                else if(webinar_email_verification_setting !== 'global' && webinar_email_verification_setting === 'no')
                    email_verification_enabled = false;
                

                if((!email_verification_enabled)){ 
                    wi_add_lead_auto_reg(ajaxurl,data);
                    return;
                }else{
                    // email verification is enabled
                            jQuery.ajax({
                                type: 'post',
                                url: ajaxurl,
                                data: {
                                    action: 'webinarignition_send_email_verification_code',
                                    security: '<?php echo wp_create_nonce("webinarignition_ajax_nonce"); ?>',
                                    email: data['email'],
                                    id: data['id'],
                                },
                                success: function (response) {
                                    var decoded;                    
                                    try {
                                        decoded = JSON.parse(response);
                                        
                                    } catch(err) {
                                        console.log(err);
                                        decoded = false;
                                    }                    
                                    if( decoded['success'] == 1 ){
                                        var popup = '<div style="position:absolute;top:0;height:100%;background-color:rgba(0,0,0,0.7);width:100%;font-size:14px;min-height:300px;"><div class="wiContainer container" style="height:100%;width:100%;display:flex;align-items:center;justify-content:center;"><div style="color:white;width:fit-content;margin:auto;padding:15px;border-radius:5px;background-color:#0496ac;text-align: center;"><div class="code_note">Please enter the code was sent to your email.</div><input class="email_code" name="email_code" style="color: black;height: 35px;margin:0;margin-top:0px;font-family:inherit;font-size:inherit;line-height:inherit;display:block;width:100%;margin-top:5px;"/><button class="verify_now" style="width:auto;background-color:#6fb200;margin-top:4px;color:white;font-weight:bold;border:1px solid rgba(0,0,0,0.2);padding: 8px 30px;">Verify</button></div></div></div>';
                                        jQuery('body').append(popup);
                                        return;
                                    }                    
                                }
                            });
                }
                
                    


                
            }else{
                // webinar is not live but `AUTO`
                jQuery.post(ajaxurl, data, function ( response ) {
                    var result;
                    var decoded = true;
                    try {
                        result = JSON.parse(response);
                    }
                    catch(err) {
                        decoded = false;
                    }
                    if( result['success'] == 0 ){
                        alert(result['message']);
                        return;
                    }
                    else{
                        thank_you_url = thank_you_url+'&lid='+result['lid'];                                
                        if( jQuery("#AR-INTEGRATION" ).length > 0) {
                            jQuery('#ar_submit_iframe').data('can_load', 'true');
                            HTMLFormElement.prototype.submit.call(jQuery("#AR-INTEGRATION")[0]);
                        }
                        else {
                            window.location.href = thank_you_url;
                        }
                    }
                });
            }



            // verify 
            jQuery(document).click('.verify_now', function(e){
                var code = jQuery('.email_code').val();
                jQuery.ajax({
                    type: 'post',
                    url: ajaxurl,
                    data: {
                        action: 'webinarignition_verify_user_email',
                        security: '<?php echo wp_create_nonce("webinarignition_ajax_nonce"); ?>',
                        email: data['email'],
                        code: code,
                    },
                    success: function (response){
                        var result = JSON.parse(response);
                        if(result['status'] == 'success'){

                            wi_add_lead_auto_reg(ajaxurl,data,code);
                           



                        }
                    }
                });
            });       


        });


        /**
         * The reason this function is created i was required to use this code twice in this file 
         * based on email settings
         */
        function wi_add_lead_auto_reg(ajaxurl,data,code = null){
            jQuery.post(ajaxurl, data, function ( response ) {
                                var result;
                                var decoded = true;
                                try {
                                    result = JSON.parse(response);
                                }
                                catch(err) {
                                    decoded = false;
                                }
                                if( result['success'] == 0 ){
                                    alert(result['message']);
                                    return;
                                } else{
                                    thank_you_url = thank_you_url+'&lid='+result['lid']+'&code='+code;   
                                   
                                    if( jQuery("#AR-INTEGRATION" ).length > 0) {
                                        jQuery('#ar_submit_iframe').data('can_load', 'true');
                                        HTMLFormElement.prototype.submit.call(jQuery("#AR-INTEGRATION")[0]);
                                    }
                                    else {
                                        window.location.href = thank_you_url;
                                    }
                                }
            });
        }
    </script>

<div class="informationBox">
    <h2 style="margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px dashed #b3b3b3;"><?php echo $webinar_data->webinar_desc; ?></h2>
    <h4 style="font-weight:normal;"><?php echo $webinar_data->webinar_host; ?></h4>
</div>

<div class="loaderBox">
    <i class="fa fa-spinner fa-spin fa-4x"></i>
</div>


<!-- AR OPTIN INTEGRATION -->
<div class="arintegration" style="display:none;">
	<?php include(WEBINARIGNITION_PATH . "inc/lp/ar_form.php"); ?>
</div>
</body>
</html>