<?php
$isTrialCopy = true;
if (!defined("ABSPATH")) {
    exit();
} // Exit if accessed directly

global $extrnlcvrbl,$inline_used,$extrnlvrbl,$eotpasettings;
$inline_used = false;

if (!class_exists("emailotpauthnFront")) {
	global $usevnilajsfile;
	$usevnilajsfile = get_fix_option("emailotpauthn_useupgrdfiture",0);
	if($usevnilajsfile)
		$usevnilajsfilepath = "/lib/emailotpauthn-external-vjs-class.php";
	else
		$usevnilajsfilepath = "/lib/emailotpauthn-external-class.php";
	include(dirname(dirname(__FILE__)).$usevnilajsfilepath);
	$extrnlcvrbl = $extrnlvrbl;
    class emailotpauthnFront
    {
        /**
         * Construct the plugin object
         */
        public function __construct()
        {
            // Is enable settings from admin
            $isEnable = get_fix_option("emailotpauthn_enable",0);
            if (!$isEnable) {
                return;
            }
            //front-end hooks action
			global $eotpasettings;
			if(!isset($eotpasettings) || count($eotpasettings) < 5) emailotpauthn_settingsdetails();
            add_action("wp_footer", [&$this, "emailotpauthn_popup_html"]);
            add_action("wp_ajax_nopriv_emailotpauthnaction", [ &$this, "emailotpauthn_login_action", ]); // for logged-out users only.
            add_action("wp_enqueue_scripts", [ &$this, "emailotpauthn_enqueue_scripts_hooks", ],9999);
            add_shortcode("email_otp_authn", [&$this, "email_otp_authn_func"]);
        } // END public function __construct

        public function email_otp_authn_func($atts)
        {
			global $extrnlcvrbl,$inline_used;
			if($inline_used) return "";
			if(empty($extrnlcvrbl)) emailotpauthn_formtexts();
			$title = $extrnlcvrbl[1];
			$title = isset($atts["title"]) ? (empty(trim($atts["title"])) ? $title : $atts["title"]) : $title;
			$type = "popup";
            $type = isset($atts["type"]) ? (empty(trim($atts["type"])) ? $type : $atts["type"]) : $type;

			$type = substr(strtolower(trim(strip_tags($type))),0,12);
            $title = substr(trim(strip_tags($title)),0,250);

			if($type=="inline") {
				$setintrnlvars = array("dflt_action"=>"");
				
				ob_start();
				$button = "";
				$button = $this->emailotpauthn_popup_html($setintrnlvars);
				$obgetclean = ob_get_clean();
				if(!empty($obgetclean)) $button = $obgetclean;
				//$inline_used = true;
			} else {
				if($type=="autopopup"){
					$isemptytitle = isset($atts["title"]) ? (empty(trim($atts["title"])) ? true : false) : true;
					if($isemptytitle) $title = "";
				}
				if($type!="autopopup") $type = "";
				$button = '<span class="emailotpauthn-shortcode emailotpauthn-popup '. $type .'"><a href="javascript:">' . $title . "</a></span>";
			}

            return $button;
        }
        public function emailotpauthn_enqueue_scripts_hooks()
        {
            //*
			//check user logged or not
			if(is_user_logged_in())
				return;
			//*/

			global $extrnlcvrbl,$eotpasettings;
			if(empty($extrnlcvrbl)) emailotpauthn_formtexts();

			$emailotpauthnjshint = '';
			if ( function_exists('emailotpauthn_popup_extrnl_jshint') ) $emailotpauthnjshint = emailotpauthn_popup_extrnl_jshint();

			$hideautofileml = $eotpasettings["hideautofileml"];
			$hidescrollbars = $eotpasettings["hidescrollbars"];
			$isoneinputbox = $eotpasettings["isoneinputbox"];

			$emailotpauthnscript = '';
			if(!$isoneinputbox) {
				$emailotpauthnscript = emailotpauthn_popup_extrnl_boxscript();
			}

			$setextrnlvars = array(
				"is_logged_in"=>0,
				"hideautofileml"=>$hideautofileml,
				"hidescrollbars"=>$hidescrollbars,
				"rgstrshowterms"=>0,
				"logged_in_email"=>"",
				"is_2fa_redirect"=>0,
				"extrnltxt_002"=>$extrnlcvrbl[2],
				"extrnltxt_003"=>$extrnlcvrbl[3],
				"extrnltxt_004"=>$extrnlcvrbl[4],
				"extrnltxt_027"=>$extrnlcvrbl[27],
				"extrnltxt_056"=>$extrnlcvrbl[56],
				"extrnltxt_057"=>$extrnlcvrbl[57],
				"extrnltxt_058"=>$extrnlcvrbl[58],
				"extrnltxt_059"=>$extrnlcvrbl[59],
				"extrnlsection"=>emailotpauthn_license_allowed(true)
				);
            $emailotpauthnscript = $emailotpauthnjshint . $emailotpauthnscript . emailotpauthn_popup_extrnl_jvascript($setextrnlvars);

			global $usevnilajsfile;
			wp_deregister_script('emailotpauthnjquery');
			if ( ! $usevnilajsfile && ! wp_script_is( 'jquery', 'enqueued' )) {
				wp_register_script('emailotpauthnjquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js', false, '3.7.1');
				wp_enqueue_script('emailotpauthnjquery');
			}
			wp_register_script( "emailotpauthn-inlinescript", "" );
			wp_enqueue_script( "emailotpauthn-inlinescript" );
            wp_add_inline_script("emailotpauthn-inlinescript", $emailotpauthnscript);

			// CSS
			$iscornrstyl = $eotpasettings["iscornrstyl"];
			$isshortbuttons = $eotpasettings["isshortbuttons"];
			$poppboximeg = $eotpasettings["emailotpauthn_poppboximeg"];
			$poppopcimeg = $eotpasettings["emailotpauthn_poppopcimeg"];
			$backdrpimeg = $eotpasettings["emailotpauthn_backdrpimeg"];
			$bkdrpopcimg = $eotpasettings["emailotpauthn_bkdrpopcimg"];
			$headercolor = $eotpasettings["emailotpauthn_headercolor"];
			$inptbxcolor = $eotpasettings["emailotpauthn_inptbxcolor"];
			$buttoncolor = $eotpasettings["emailotpauthn_buttoncolor"];
			$bodybgcolor = $eotpasettings["emailotpauthn_bodybgcolor"];
			$poppbgcolor = $eotpasettings["emailotpauthn_poppbgcolor"];
			$poppboxblur = $eotpasettings["emailotpauthn_poppboxblur"];
			$popupbgblur = $eotpasettings["emailotpauthn_popupbgblur"];
			$frmbrdrwdth = $eotpasettings["emailotpauthn_frmbrdrwdth"];
			$frmbrdrcolr = $eotpasettings["emailotpauthn_frmbrdrcolr"];
			if($poppboxblur > 100)
				$poppboxblur = 50;
			elseif($poppboxblur < 0)
				$poppboxblur = 0;
			else
				$poppboxblur = number_format($poppboxblur / 2,2);
			if($popupbgblur > 100)
				$popupbgblur = 50;
			elseif($popupbgblur < 0)
				$popupbgblur = 0;
			else
				$popupbgblur = number_format($popupbgblur / 2,2);
			if($frmbrdrwdth > 50)
				$frmbrdrwdth = 50;
			elseif($frmbrdrwdth < 0)
				$frmbrdrwdth = 0;
			if($poppopcimeg < 0)
				$poppopcimeg = 0;
			else
				$poppopcimeg = round($poppopcimeg/100, 2);
			if($bkdrpopcimg < 0)
				$bkdrpopcimg = 0;
			else
				$bkdrpopcimg = round($bkdrpopcimg/100, 2);

			/*
			$eotpaimagecontext = stream_context_create(['http' => ['method' => 'HEAD']]);
			if($poppopcimeg > 0 && !empty($poppboximeg)){
				$eotpaimagecontentlength = 0;
				$eotpaimageheaders = @get_headers($poppboximeg,1,$eotpaimagecontext);
				if (isset($eotpaimageheaders['Content-Length'])) {
					$eotpaimagecontentlength = $eotpaimageheaders['Content-Length'];
					if(is_numeric($eotpaimagecontentlength)) $eotpaimagecontentlength += 0;
				}
				if($eotpaimagecontentlength==0){
					$poppboximeg = "";
					//emailotpauthn_settingsdetails("","emailotpauthn_poppboximeg[:::]". $poppboximeg);
				}
			}
			if($bkdrpopcimg > 0 && !empty($backdrpimeg)){
				$eotpaimagecontentlength = 0;
				$eotpaimageheaders = @get_headers($backdrpimeg,1,$eotpaimagecontext);
				if (isset($eotpaimageheaders['Content-Length'])) {
					$eotpaimagecontentlength = $eotpaimageheaders['Content-Length'];
					if(is_numeric($eotpaimagecontentlength)) $eotpaimagecontentlength += 0;
				}
				if($eotpaimagecontentlength==0){
					$backdrpimeg = "";
					//emailotpauthn_settingsdetails("","emailotpauthn_backdrpimeg[:::]". $backdrpimeg);
				}
			}
			*/

			$hedrxtstyle = $eotpasettings["emailotpauthn_hedrxtstyle"];
			$inptxtstyle = $eotpasettings["emailotpauthn_inptxtstyle"];
			$butnxtstyle = $eotpasettings["emailotpauthn_butnxtstyle"];
			$bodyxtstyle = $eotpasettings["emailotpauthn_bodyxtstyle"];
			$popuphorzalign = $eotpasettings["emailotpauthn_popuphorzalign"];
			$popupboxmargin = $eotpasettings["emailotpauthn_popupboxmargin"];
			$frmnoticclr = $eotpasettings["emailotpauthn_frmnoticclr"];
			$frmnoticsiz = $eotpasettings["emailotpauthn_frmnoticsiz"];
			$frmnoticsiz = $frmnoticsiz/100;
			$setextrnlvars = array(
				"isoneinputbox"=>$isoneinputbox,
				"iscornrstyl"=>$iscornrstyl,
				"isshortbuttons"=>$isshortbuttons,
 				"poppboximeg"=>$poppboximeg,
				"poppopcimeg"=>$poppopcimeg,
				"backdrpimeg"=>$backdrpimeg,
				"bkdrpopcimg"=>$bkdrpopcimg,
				"hedrxtstyle"=>$hedrxtstyle,
				"headercolor"=>$headercolor,
				"inptxtstyle"=>$inptxtstyle,
				"inptbxcolor"=>$inptbxcolor,
				"butnxtstyle"=>$butnxtstyle,
				"buttoncolor"=>$buttoncolor,
				"bodyxtstyle"=>$bodyxtstyle,
				"bodybgcolor"=>$bodybgcolor,
				"poppbgcolor"=>$poppbgcolor,
				"poppboxblur"=>$poppboxblur,
				"popupbgblur"=>$popupbgblur,
				"frmbrdrwdth"=>$frmbrdrwdth,
				"frmbrdrcolr"=>$frmbrdrcolr,
				"popuphorzalign"=>$popuphorzalign,
				"popupboxmargin"=>$popupboxmargin,
				"frmnoticclr"=>$frmnoticclr,
				"frmnoticsiz"=>$frmnoticsiz,
				"extrnlsection"=>emailotpauthn_license_allowed(true)
				);
			$emailotpauthncss = emailotpauthn_popup_extrnl_css($setextrnlvars);

			$dfltextrnalcss = get_fix_option('emailotpauthn_dfltextrnalcss',"");
			$dfltextrnalcss = hex2bin($dfltextrnalcss);
			if(empty($dfltextrnalcss)){
				$dfltextrnalcss = $emailotpauthncss;
				update_option("emailotpauthn_dfltextrnalcss", bin2hex($dfltextrnalcss));
			}
            // register css
            wp_register_style("emailotpauthn-inlinecss", "");
            wp_enqueue_style("emailotpauthn-inlinecss");
            wp_add_inline_style("emailotpauthn-inlinecss", $emailotpauthncss);
        }
        /**
         * @hooks wp_footer
         * hook to add html into site footer
         */
        public function emailotpauthn_popup_html($SortCodeVars=0)
        {
			//check user logged or not
			if(is_user_logged_in())
			{
				return;
			}

			global $extrnlcvrbl,$inline_used,$eotpasettings;
			if($inline_used) return;
			$logged_in_title = $extrnlcvrbl[6];
			$logged_in_email = '';
			$logged_in_readonly = '';
			$logged_in_boxtype = 'email';
			$logged_in_message = '';

			$isoneinputbox = $eotpasettings["isoneinputbox"];

            $enableLogin = get_fix_option("emailotpauthn_enable",0);
			$setextrnlvars = array();
			$formtype = "popup";
			if(is_array($SortCodeVars)) $formtype = "inline";
			$setextrnlvars = array(
				"formtype"=>$formtype,
				"dflt_action"=>"",
				"isoneinputbox"=>$isoneinputbox,
				"logged_in_title"=>$logged_in_title,
				"logged_in_boxtype"=>$logged_in_boxtype,
				"logged_in_email"=>$logged_in_email,
				"logged_in_readonly"=>$logged_in_readonly,
				"logged_in_message"=>$logged_in_message,
				"rgstrtermouurl"=>"",
				"header_submit"=>$extrnlcvrbl[2],
				"header_verify"=>$extrnlcvrbl[2],
				"extrnltxt_003"=>$extrnlcvrbl[3],
				"extrnltxt_004"=>$extrnlcvrbl[4],
				"extrnltxt_060"=>$extrnlcvrbl[60],
				"extrnltxt_061"=>$extrnlcvrbl[61],
				"extrnltxt_062"=>$extrnlcvrbl[62],
				"extrnltxt_063"=>$extrnlcvrbl[63],
				"extrnltxt_064"=>$extrnlcvrbl[64],
				"extrnlsection"=>emailotpauthn_license_allowed(true)
			);

			$emailotpauthhtml = emailotpauthn_popup_extrnl_html($setextrnlvars);
			//logging_data($emailotpauthhtml);

			if(is_array($SortCodeVars)) return $emailotpauthhtml; else echo $emailotpauthhtml;

        }
        /*
         * Send OTP Email on User Email
         *
         * */
        public function emailotpauthn_send_otp($from_email, $useremail, $otp)
        {
			global $extrnlcvrbl;
            // send OTP over email
			$otp_subject = $extrnlcvrbl[9] . get_bloginfo("name");
            $otp_message = '<table width="100%" cellpadding="0" cellspacing="0" align="center" bgcolor="f5f5f5">
								 <tr>
									<td>
										<table width="650" align="center">
											<tr>
												<td>
													<p class="font_18 pd_lft_25">'.$extrnlcvrbl[10].'</p>
													<p class="font_17">'.$extrnlcvrbl[11].'<strong>' . $otp . '</strong></p>
													<p class="font_17">'.$extrnlcvrbl[12] . home_url() . '</p>
												</td>
											</tr>
										</table>

									<table  width="100%" height="40" bgcolor="c5c5c5"  align="center" cellpadding="0" cellspacing="0">
											<tr>
												<td valign="top" align="center">
												<p>This secure OTP is generated by : <span style="font-weight:bold;color:#000066;">Email OTP Authenticator</span></p>
												</td>
											</tr>
										</table>
										</td>
									</tr>
							</table>';

            $from = $from_email; //get_bloginfo("admin_email");

            $headers[] = "Content-Type: text/html; charset=UTF-8";

            //From
            if ($from != "") {
                $headers[] = "From:" . $from;
            }

			$otpmail = false;
            $otpmail = wp_mail( $useremail, $otp_subject, $otp_message, $headers );
            return $otpmail;
            die();
        }
        /*
         * Handle all login form request
         *
         * */
        public function emailotpauthn_login_action()
        {
            //global $wpdb;
            // check security
            //if (wp_doing_ajax()) { check_ajax_referer("emailotpauthn_filed_once_val", "emailotpauthnsecurity"); } // First check the nonce, if it fails the function will break
			$is_nonce_verified = check_ajax_referer("emailotpauthn_filed_once_val", "emailotpauthnsecurity");
			if($is_nonce_verified === false) wp_die();

			global $extrnlcvrbl,$eotpasettings;
			if(empty($extrnlcvrbl)) emailotpauthn_formtexts();
			$emailotpauthnzplussecurity = "invalid";
			if ( isset($_POST["emailotpauthnzplussecurity"]) ) $emailotpauthnzplussecurity = sanitize_text_field( $_POST["emailotpauthnzplussecurity"] );

			$emailotpauthnsubmitidstr = isset($_POST["emailotpauthnsubmitid"]) ? sanitize_text_field($_POST["emailotpauthnsubmitid"]) : "";
			if ( (!empty($emailotpauthnsubmitidstr)) && false === get_transient("emailotpauthn_" . $emailotpauthnsubmitidstr) ) {
				set_transient("emailotpauthn_" . $emailotpauthnsubmitidstr, $emailotpauthnsubmitidstr, 300);
			} else {
				return;
			}
            $email_otp = sanitize_text_field($_POST["email_otp"]);
			if(!isset($email_otp)) $email_otp = 0;
			if(empty($email_otp)) $email_otp = 0;
			$useremail = "";
			if(is_email( $_POST["email"] )){
				$useremail = sanitize_email($_POST["email"]);
			} else {
				$responsestr = json_encode([ "status" => 0, "message" => $extrnlcvrbl[15], "response" => $extrnlcvrbl[15], ]);
				call_emailotpauthn_external_function(0,$responsestr);
			}
            $validateotp = sanitize_text_field($_POST["validateotp"]);
			$ilogination = $eotpasettings["emailotpauthn_logination"];
			if ($ilogination == 0){
				$responsestr = json_encode([ "status" => 0, "rspnum" => 33, "message" => $extrnlcvrbl[18], "response" => $extrnlcvrbl[18], ]);
				call_emailotpauthn_external_function(0,$responsestr);
			}
            // check zplus security
            if ($emailotpauthnzplussecurity != "") {
                $responsestr = json_encode([
					"status" => 0,
					"message" => $extrnlcvrbl[21],
					"response" => $extrnlcvrbl[22],
					]);
                call_emailotpauthn_external_function(0,$responsestr);
            }
            // check is request for generate otp or submit otp
            if ($email_otp == 0) {
                // required fields
                if (empty($useremail)) {
                    $responsestr = json_encode([ "status" => 0, "message" => $extrnlcvrbl[23], "response" => $extrnlcvrbl[24], ]);
                    call_emailotpauthn_external_function(0,$responsestr);
                }

				$isactvfrmmail = $eotpasettings["emailotpauthn_isactvfrmmail"];
				$sendfromcmail = $eotpasettings["emailotpauthn_sendfromcmail"];
				if($isactvfrmmail == 0 || empty($sendfromcmail)){
                    $responsestr = json_encode([ "status" => 0, "rspnum" => 34, "message" => $extrnlcvrbl[25], "response" => $extrnlcvrbl[25], ]);
					call_emailotpauthn_external_function(0,$responsestr);
				}

                //check user already registered or not
                $user_id = email_exists($useremail);
                if (!$user_id && false == email_exists($useremail)) {
                    $responsestr = json_encode([ "status" => 0, "message" => "User does not exist.", "response" => "User does not exist", ]);
                    call_emailotpauthn_external_function(0,$responsestr);
                } else {
                    //check type of login request
                    // send otp on email address
					$newotp = rand(100000, 999999);
					$otpmail = $this->emailotpauthn_send_otp($sendfromcmail, $useremail, $newotp);
					if ($otpmail) {
						$encrypted_otp = password_hash($newotp, PASSWORD_DEFAULT);
						update_user_meta($user_id, "emilotpauthn", $encrypted_otp);
						update_user_meta($user_id, "emilotpatmpt", 0);
                        $json_arg["response"] = "Success";
                        $json_arg["message"] = $extrnlcvrbl[34];
                        $json_arg["status"] = 1;
                        $json_arg["sendotp"] = 1;
                    } else {
                        $json_arg["response"] = $extrnlcvrbl[29];
                        $json_arg["message"] = $extrnlcvrbl[29];
                        $json_arg["status"] = 0;
                        $json_arg["sendotp"] = 0;
                    }
                    $responsestr = json_encode($json_arg);
                    call_emailotpauthn_external_function($json_arg["status"],$responsestr,$useremail);
                }
            } else {
                // check otp valid or not				
                $user_id = email_exists($useremail);
				if(! $user_id) wp_die();
				$emilotpatmpt = get_user_meta($user_id, "emilotpatmpt", true);
				if (!is_numeric($emilotpatmpt)) $emilotpatmpt = 0;
				$db_otp = get_user_meta($user_id, "emilotpauthn", true);
				if(empty($db_otp)){
					$responsestr = json_encode([ "status" => 0, "message" => $extrnlcvrbl[35], "response" => $extrnlcvrbl[35], "sendotp" => 0, ]);
					call_emailotpauthn_external_function(0,$responsestr);
				}
				$is_otp_verified = (password_verify($email_otp, $db_otp) && $validateotp != 0);
				if ($is_otp_verified && $emilotpatmpt < 999) {
					$logination = $eotpasettings["emailotpauthn_logination"];
					if($logination) {
						$user = get_user_by("email", $useremail);
						if ( is_wp_error( $user ) ) wp_die();
						wp_clear_auth_cookie();
						wp_set_current_user($user_id, $user->user_login);
						wp_set_auth_cookie($user_id);
						//do_action("wp_login", $user->user_login, $user);
						if (is_user_logged_in()) {
							$redirecturl = $eotpasettings["emailotpauthn_redirectaftrlogin"];
							$url = $eotpasettings["emailotpauthn_redirect_url"];
							if(! $redirecturl) $url = "";
							$responsestr = json_encode([
								"status" => 1,
								"message" => $extrnlcvrbl[50],
								"response" => $extrnlcvrbl[43],
								"sendotp" => 0,
								"redirect" => $url,
							]);
							//update_user_meta($user_id, "emilotpauthn", ""); // reset otp
							//update_user_meta($user_id, "emilotpatmpt", 0);
							delete_user_meta($user_id, "emilotpauthn");
							delete_user_meta($user_id, "emilotpatmpt");
							call_emailotpauthn_external_function(1,$responsestr,$useremail);
						}
					}
					$url = ""; //(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on" ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
					$responsestr = json_encode([
						"status" => 1,
						"message" => "Not Logged In",
						"response" => "OTP Matched but not logged in",
						"sendotp" => 0,
						"redirect" => $url,
					]);
					call_emailotpauthn_external_function(1,$responsestr,$useremail);
				} else {
					if($emilotpatmpt < 999) {
						$emilotpatmpt++;
						$loginatmptlimit = $eotpasettings["emailotpauthn_rtryatmptlimit"];
						if ($loginatmptlimit > 0) {
							if ($emilotpatmpt >= $loginatmptlimit) {
								$emilotpatmpt = -1;
							} else {
								update_user_meta( $user_id, "emilotpatmpt", $emilotpatmpt );
							}
						}
					} else {
						$emilotpatmpt = -2;
					}
					if ($emilotpatmpt < 0) {
						if($emilotpatmpt > -2) update_user_meta( $user_id, "emilotpatmpt", 999 );
						$responsestr = json_encode([ "status" => 0, "message" => $extrnlcvrbl[54].' <input type="button" class="generateOtp" value="'.$extrnlcvrbl[27].'" name="resendotp" />', "response" => $extrnlcvrbl[54], "sendotp" => 0, ]);
						//update_user_meta($user_id, "emilotpauthn", "");
						//update_user_meta($user_id, "emilotpatmpt", 0);
						delete_user_meta($user_id, "emilotpauthn");
						delete_user_meta($user_id, "emilotpatmpt");
						call_emailotpauthn_external_function(0,$responsestr);
					} else {
						$responsestr = json_encode([
							"status" => 0,
							"message" => $extrnlcvrbl[55].' <input type="button" class="generateOtp" value="'.$extrnlcvrbl[27].'" name="resendotp" />',
							"response" => $extrnlcvrbl[55],
							"sendotp" => 0,
						]);
						call_emailotpauthn_external_function(0,$responsestr);
					}
				}
            }
        }
    }
}

function emailotpauthn_formtexts(){
	global $extrnlcvrbl,$formtexts;
	if(!isset($formtexts) || empty($formtexts)) emailotpauthn_load_notesntexts();
	$formnoticentxt = get_fix_option("emailotpauthn_formnoticentxt","not_initiated");
	if(strcasecmp($formnoticentxt,"not_initiated")==0){
		if(isset($formtexts) && !empty($formtexts)){
			$newnoticentxt = "";
			$nodx = 0;
			foreach ($formtexts as $formtext) {
				if(isset($formtext[2]) && !empty($formtext[2])){
					if(!isset($extrnlcvrbl[$nodx]) || empty($extrnlcvrbl[$nodx])){
						$extrnlcvrbl[$nodx] = $formtext[2];
						$newnoticentxt .= $formtext[2] . "#-ntbreak-#";
					}
				}
				$nodx++;
			}
			$newnoticentxt = trim($newnoticentxt,"#-ntbreak-#");
			update_option("emailotpauthn_formnoticentxt", bin2hex($newnoticentxt));
		}
	} else {
		$formnoticentxt = "#-ntbreak-#" . hex2bin($formnoticentxt);
		$savednoticentxts = explode("#-ntbreak-#",$formnoticentxt);
		$nodx = 0;
		foreach ($savednoticentxts as $savednoticentxt) {
			if(isset($savednoticentxt)){
				$extrnlcvrbl[$nodx] = $savednoticentxt;
				$formtexts[$nodx][2] = $extrnlcvrbl[$nodx];
			}
			$nodx++;
		}
	}
}
function emailotpauthn_settingsdetails($getthisval="",$setthisval=""){
	$emptysetting = "not_initiated";
	$defaultsettings = array(
		"iscornrstyl"=>0,
		"isshortbuttons"=>0,
		"hideautofileml"=>0,
		"hidescrollbars"=>0,
		"isoneinputbox"=>0,
		"setupwizardstep"=>0,
		"emailotpauthn_poppopcimeg"=>100,
		"emailotpauthn_bkdrpopcimg"=>100,
		"emailotpauthn_resetdefaults"=>0,
		"emailotpauthn_is_externalcss"=>0,
		"emailotpauthn_logination"=>0,
		"emailotpauthn_redirectaftrlogin"=>0,
		"emailotpauthn_emailsettings"=>0,
		"emailotpauthn_gnrtprocesslog"=>0,
		"emailotpauthn_authentication"=>0,
		"emailotpauthn_askuseremail"=>0,
		"emailotpauthn_wrongotplogout"=>0,
		"emailotpauthn_mmbrvrfynrdrct"=>0,
		"emailotpauthn_mmbristokenkey"=>0,
		"emailotpauthn_customization"=>0,
		"emailotpauthn_redirectfor2fa"=>0,
		"emailotpauthn_the2fatoadmins"=>0,
		"emailotpauthn_generateotplog"=>0,
		"emailotpauthn_rgstrauthnticn"=>0,
		"emailotpauthn_regtrdusername"=>0,
		"emailotpauthn_rgstrshowterms"=>0,
		"emailotpauthn_rgstrthnlogdin"=>0,
		"emailotpauthn_rgstrthnredrct"=>0,
		"emailotpauthn_guestauthnticn"=>0,
		"emailotpauthn_gustvrfynrdrct"=>0,
		"emailotpauthn_gustistokenkey"=>0,
		"emailotpauthn_isblockemails"=>0,
		"emailotpauthn_isallowemails"=>0,
		"emailotpauthn_isblockmailid"=>0,
		"emailotpauthn_isontokenaddon"=>0,
		"emailotpauthn_excldlogdinusr"=>0,
		"emailotpauthn_excldlogdinmbr"=>0,
		"emailotpauthn_addexternalcss"=>0,
		"emailotpauthn_firelimit"=>0,
		"emailotpauthn_duralimit"=>0,
		"emailotpauthn_validfor"=>0,
		"emailotpauthn_cleanaftrdays"=>0,
		"emailotpauthn_poppboxblur"=>0,
		"emailotpauthn_popupbgblur"=>0,
		"emailotpauthn_frmbrdrwdth"=>0,
		"emailotpauthn_rtryatmptlimit"=>0,
		"emailotpauthn_tokenvlidfrmbr"=>0,
		"emailotpauthn_tokenvlidfrgst"=>0,
		"emailotpauthn_isactvfrmmail"=>0,
		"emailotpauthn_useexternalcss"=>0,
		"emailotpauthn_otplogedpostid"=>0,
		"emailotpauthn_popupboxmargin"=>0,
		"emailotpauthn_frmnoticsiz"=>83,
		"emailotpauthn_licensekey"=>"Not_Required",
		"emailotpauthn_hedrxtstyle"=>"font-family:Verdana, Geneva, sans-serif!important;color:#ffffff;font-size:22px;font-weight:400!important;letter-spacing:0.2px;word-spacing:0px;",
		"emailotpauthn_headercolor"=>"#881100",
		"emailotpauthn_inptxtstyle"=>"font-family:Verdana, Geneva, sans-serif!important;color:#666666;font-size:16px;font-weight:400!important;letter-spacing:0px;word-spacing:0px;",
		"emailotpauthn_inptbxcolor"=>"#FFFFDD",
		"emailotpauthn_butnxtstyle"=>"font-family:Verdana, Geneva, sans-serif!important;color:#ffffff;font-size:16px;font-weight:600!important;letter-spacing:0.5px;word-spacing:1px;",
		"emailotpauthn_buttoncolor"=>"#772200",
		"emailotpauthn_bodyxtstyle"=>"font-family:Verdana, Geneva, sans-serif!important;color:#000000;font-size:16px;font-weight:400!important;letter-spacing:0px;word-spacing:0px;",
		"emailotpauthn_bodybgcolor"=>"#DDAA88",
		"emailotpauthn_poppbgcolor"=>"#00000080",
		"emailotpauthn_frmbrdrcolr"=>"#ffffff",
		"emailotpauthn_frmnoticclr"=>"#bb0000",
		"emailotpauthn_poppboximeg"=>"",
		"emailotpauthn_backdrpimeg"=>"",
		"emailotpauthn_redirect_url"=>"",
		"emailotpauthn_redirect2faurl"=>"",
		"emailotpauthn_rgstrdefltrole"=>"",
		"emailotpauthn_rgstrtermouurl"=>"",
		"emailotpauthn_rgstrredrcturl"=>"",
		"emailotpauthn_mmbrvrfrdcturl"=>"",
		"emailotpauthn_mmbrofrdcturls"=>"",
		"emailotpauthn_mmbrrjtrdcturl"=>"",
		"emailotpauthn_gustvrfrdcturl"=>"",
		"emailotpauthn_gustofrdcturls"=>"",
		"emailotpauthn_gustrjtrdcturl"=>"",
		"emailotpauthn_redirect_out"=>"",
		"emailotpauthn_sendfromemail"=>"",
		"emailotpauthn_sendfromcmail"=>"",
		"emailotpauthn_popuphorzalign"=>"",
	);
	$savedsettings = $defaultsettings;
	//The below 2 lines of code is UMOVS2NVS
	$predsettingspending = true;
	savedsettingscheck:
	$settingsdetls = get_option('emailotpauthn_settingsdetls',$emptysetting);
	$settingsdetls = isset($settingsdetls) ? (empty(trim($settingsdetls)) ? $emptysetting : $settingsdetls) : $emptysetting;
	if(strcasecmp($settingsdetls,$emptysetting)==0){
		//The below IF section code is UMOVS2NVS
		if($predsettingspending) {
			$setingsmigrator = false;
			$setingsmigrator = emailotpauthn_setingsmigrator($defaultsettings);
			$predsettingspending = false;
			if($setingsmigrator) goto savedsettingscheck;
		}
		$newsettingsvals = json_encode($defaultsettings);
		if(!empty($newsettingsvals)) update_option("emailotpauthn_settingsdetls", $newsettingsvals);
	} else {
		$savedsettings = json_decode($settingsdetls,true);
		if (json_last_error() !== 0) $savedsettings = unserialize($settingsdetls); // This line is supporting the version 6.2.3 to 6.3.3 settings. UMOVS2NVS
		//The below IF section code is UMOVS2NVS
		if(!isset($savedsettings["emailotpauthn_emailsettings"])){
			if(isset($savedsettings["setupwizardstep"])){
				if($savedsettings["setupwizardstep"]==12){
					$savedsettings["setupwizardstep"]=10;
				}
			}
			$defaultsettings = array_merge($defaultsettings, $savedsettings);
			delete_option("emailotpauthn_settingsdetls");
			goto savedsettingscheck;
		}
		if(!empty($setthisval)){
			if(str_contains($setthisval,"[;;;]")){
				$setthisprms = explode("[;;;]",$setthisval);
				foreach ($setthisprms as $setthisprm) {
					$setthisvals = explode("[:::]",$setthisprm);
					if(count($setthisvals) == 2){
						if(is_numeric($setthisvals[1])) $setthisvals[1] += 0;
						$savedsettings[$setthisvals[0]] = $setthisvals[1];
					}
				}
			} else {
				$setthisvals = explode("[:::]",$setthisval);
				if(count($setthisvals) == 2){
					if(is_numeric($setthisvals[1])) $setthisvals[1] += 0;
					$savedsettings[$setthisvals[0]] = $setthisvals[1];
				}
			}
			$newsettingsvals = json_encode($savedsettings);
			if(!empty($newsettingsvals)) update_option("emailotpauthn_settingsdetls", $newsettingsvals);
		}
	}
	if(empty($getthisval)){
		global $eotpasettings;
		$eotpasettings = $savedsettings;
	} else {
		$dfltsettingval = $defaultsettings[$getthisval];
		$dfltsettingval = isset($dfltsettingval) ? (empty(trim($dfltsettingval)) ? ($dfltsettingval===false ? $dfltsettingval : "0") : $dfltsettingval) : "0";
		$savdsettingval = $savedsettings[$getthisval];
		$savdsettingval = isset($savdsettingval) ? (empty(trim($savdsettingval)) ? ($savdsettingval===false ? $savdsettingval : $dfltsettingval) : $savdsettingval) : $dfltsettingval;
		if(is_numeric($savdsettingval)) $savdsettingval += 0; else $savdsettingval = strval($savdsettingval);
		return $savdsettingval;
	}
}
function emailotpauthn_setingsmigrator($migrator_defaultsettings){
	//This fumction is UMOVS2NVS [used to migrate older and version 6.2.4 settings to the new version settings].
	if ( strcasecmp("not-exists",get_option( "emailotpauthn_emailsettings", "not-exists" )) != 0 ) {
		$migrator_defaultsettings["iscornrstyl"] = get_fix_option("iscornrstyl",$migrator_defaultsettings["iscornrstyl"]);
		$migrator_defaultsettings["isshortbuttons"] = get_fix_option("isshortbuttons",$migrator_defaultsettings["isshortbuttons"]);
		$migrator_defaultsettings["hideautofileml"] = get_fix_option("hideautofileml",$migrator_defaultsettings["hideautofileml"]);
		$migrator_defaultsettings["hidescrollbars"] = get_fix_option("hidescrollbars",$migrator_defaultsettings["hidescrollbars"]);
		$migrator_defaultsettings["isoneinputbox"] = get_fix_option("isoneinputbox",$migrator_defaultsettings["isoneinputbox"]);
		$migrator_defaultsettings["setupwizardstep"] = get_fix_option("setupwizardstep",$migrator_defaultsettings["setupwizardstep"]);
		$migrator_defaultsettings["emailotpauthn_poppopcimeg"] = get_fix_option("emailotpauthn_poppopcimeg",$migrator_defaultsettings["emailotpauthn_poppopcimeg"]);
		$migrator_defaultsettings["emailotpauthn_bkdrpopcimg"] = get_fix_option("emailotpauthn_bkdrpopcimg",$migrator_defaultsettings["emailotpauthn_bkdrpopcimg"]);
		$migrator_defaultsettings["emailotpauthn_resetdefaults"] = get_fix_option("emailotpauthn_resetdefaults",$migrator_defaultsettings["emailotpauthn_resetdefaults"]);
		$migrator_defaultsettings["emailotpauthn_is_externalcss"] = get_fix_option("emailotpauthn_is_externalcss",$migrator_defaultsettings["emailotpauthn_is_externalcss"]);
		$migrator_defaultsettings["emailotpauthn_logination"] = get_fix_option("emailotpauthn_logination",$migrator_defaultsettings["emailotpauthn_logination"]);
		$migrator_defaultsettings["emailotpauthn_redirectaftrlogin"] = get_fix_option("emailotpauthn_redirectaftrlogin",$migrator_defaultsettings["emailotpauthn_redirectaftrlogin"]);
		$migrator_defaultsettings["emailotpauthn_emailsettings"] = get_fix_option("emailotpauthn_emailsettings",$migrator_defaultsettings["emailotpauthn_emailsettings"]);
		$migrator_defaultsettings["emailotpauthn_gnrtprocesslog"] = get_fix_option("emailotpauthn_gnrtprocesslog",$migrator_defaultsettings["emailotpauthn_gnrtprocesslog"]);
		$migrator_defaultsettings["emailotpauthn_authentication"] = get_fix_option("emailotpauthn_authentication",$migrator_defaultsettings["emailotpauthn_authentication"]);
		$migrator_defaultsettings["emailotpauthn_askuseremail"] = get_fix_option("emailotpauthn_askuseremail",$migrator_defaultsettings["emailotpauthn_askuseremail"]);
		$migrator_defaultsettings["emailotpauthn_wrongotplogout"] = get_fix_option("emailotpauthn_wrongotplogout",$migrator_defaultsettings["emailotpauthn_wrongotplogout"]);
		$migrator_defaultsettings["emailotpauthn_mmbrvrfynrdrct"] = get_fix_option("emailotpauthn_mmbrvrfynrdrct",$migrator_defaultsettings["emailotpauthn_mmbrvrfynrdrct"]);
		$migrator_defaultsettings["emailotpauthn_mmbristokenkey"] = get_fix_option("emailotpauthn_mmbristokenkey",$migrator_defaultsettings["emailotpauthn_mmbristokenkey"]);
		$migrator_defaultsettings["emailotpauthn_customization"] = get_fix_option("emailotpauthn_customization",$migrator_defaultsettings["emailotpauthn_customization"]);
		$migrator_defaultsettings["emailotpauthn_redirectfor2fa"] = get_fix_option("emailotpauthn_redirectfor2fa",$migrator_defaultsettings["emailotpauthn_redirectfor2fa"]);
		$migrator_defaultsettings["emailotpauthn_the2fatoadmins"] = get_fix_option("emailotpauthn_the2fatoadmins",$migrator_defaultsettings["emailotpauthn_the2fatoadmins"]);
		$migrator_defaultsettings["emailotpauthn_generateotplog"] = get_fix_option("emailotpauthn_generateotplog",$migrator_defaultsettings["emailotpauthn_generateotplog"]);
		$migrator_defaultsettings["emailotpauthn_rgstrauthnticn"] = get_fix_option("emailotpauthn_rgstrauthnticn",$migrator_defaultsettings["emailotpauthn_rgstrauthnticn"]);
		$migrator_defaultsettings["emailotpauthn_regtrdusername"] = get_fix_option("emailotpauthn_regtrdusername",$migrator_defaultsettings["emailotpauthn_regtrdusername"]);
		$migrator_defaultsettings["emailotpauthn_rgstrshowterms"] = get_fix_option("emailotpauthn_rgstrshowterms",$migrator_defaultsettings["emailotpauthn_rgstrshowterms"]);
		$migrator_defaultsettings["emailotpauthn_rgstrthnlogdin"] = get_fix_option("emailotpauthn_rgstrthnlogdin",$migrator_defaultsettings["emailotpauthn_rgstrthnlogdin"]);
		$migrator_defaultsettings["emailotpauthn_rgstrthnredrct"] = get_fix_option("emailotpauthn_rgstrthnredrct",$migrator_defaultsettings["emailotpauthn_rgstrthnredrct"]);
		$migrator_defaultsettings["emailotpauthn_guestauthnticn"] = get_fix_option("emailotpauthn_guestauthnticn",$migrator_defaultsettings["emailotpauthn_guestauthnticn"]);
		$migrator_defaultsettings["emailotpauthn_gustvrfynrdrct"] = get_fix_option("emailotpauthn_gustvrfynrdrct",$migrator_defaultsettings["emailotpauthn_gustvrfynrdrct"]);
		$migrator_defaultsettings["emailotpauthn_gustistokenkey"] = get_fix_option("emailotpauthn_gustistokenkey",$migrator_defaultsettings["emailotpauthn_gustistokenkey"]);
		$migrator_defaultsettings["emailotpauthn_isblockemails"] = get_fix_option("emailotpauthn_isblockemails",$migrator_defaultsettings["emailotpauthn_isblockemails"]);
		$migrator_defaultsettings["emailotpauthn_isallowemails"] = get_fix_option("emailotpauthn_isallowemails",$migrator_defaultsettings["emailotpauthn_isallowemails"]);
		$migrator_defaultsettings["emailotpauthn_isblockmailid"] = get_fix_option("emailotpauthn_isblockmailid",$migrator_defaultsettings["emailotpauthn_isblockmailid"]);
		$migrator_defaultsettings["emailotpauthn_isontokenaddon"] = get_fix_option("emailotpauthn_isontokenaddon",$migrator_defaultsettings["emailotpauthn_isontokenaddon"]);
		$migrator_defaultsettings["emailotpauthn_excldlogdinusr"] = get_fix_option("emailotpauthn_excldlogdinusr",$migrator_defaultsettings["emailotpauthn_excldlogdinusr"]);
		$migrator_defaultsettings["emailotpauthn_excldlogdinmbr"] = get_fix_option("emailotpauthn_excldlogdinmbr",$migrator_defaultsettings["emailotpauthn_excldlogdinmbr"]);
		$migrator_defaultsettings["emailotpauthn_addexternalcss"] = get_fix_option("emailotpauthn_addexternalcss",$migrator_defaultsettings["emailotpauthn_addexternalcss"]);
		$migrator_defaultsettings["emailotpauthn_firelimit"] = get_fix_option("emailotpauthn_firelimit",$migrator_defaultsettings["emailotpauthn_firelimit"]);
		$migrator_defaultsettings["emailotpauthn_duralimit"] = get_fix_option("emailotpauthn_duralimit",$migrator_defaultsettings["emailotpauthn_duralimit"]);
		$migrator_defaultsettings["emailotpauthn_validfor"] = get_fix_option("emailotpauthn_validfor",$migrator_defaultsettings["emailotpauthn_validfor"]);
		$migrator_defaultsettings["emailotpauthn_cleanaftrdays"] = get_fix_option("emailotpauthn_cleanaftrdays",$migrator_defaultsettings["emailotpauthn_cleanaftrdays"]);
		$migrator_defaultsettings["emailotpauthn_poppboxblur"] = get_fix_option("emailotpauthn_poppboxblur",$migrator_defaultsettings["emailotpauthn_poppboxblur"]);
		$migrator_defaultsettings["emailotpauthn_popupbgblur"] = get_fix_option("emailotpauthn_popupbgblur",$migrator_defaultsettings["emailotpauthn_popupbgblur"]);
		$migrator_defaultsettings["emailotpauthn_frmbrdrwdth"] = get_fix_option("emailotpauthn_frmbrdrwdth",$migrator_defaultsettings["emailotpauthn_frmbrdrwdth"]);
		$migrator_defaultsettings["emailotpauthn_rtryatmptlimit"] = get_fix_option("emailotpauthn_rtryatmptlimit",$migrator_defaultsettings["emailotpauthn_rtryatmptlimit"]);
		$migrator_defaultsettings["emailotpauthn_tokenvlidfrmbr"] = get_fix_option("emailotpauthn_tokenvlidfrmbr",$migrator_defaultsettings["emailotpauthn_tokenvlidfrmbr"]);
		$migrator_defaultsettings["emailotpauthn_tokenvlidfrgst"] = get_fix_option("emailotpauthn_tokenvlidfrgst",$migrator_defaultsettings["emailotpauthn_tokenvlidfrgst"]);
		$migrator_defaultsettings["emailotpauthn_isactvfrmmail"] = get_fix_option("emailotpauthn_isactvfrmmail",$migrator_defaultsettings["emailotpauthn_isactvfrmmail"]);
		$migrator_defaultsettings["emailotpauthn_useexternalcss"] = get_fix_option("emailotpauthn_useexternalcss",$migrator_defaultsettings["emailotpauthn_useexternalcss"]);
		$migrator_defaultsettings["emailotpauthn_otplogedpostid"] = get_fix_option("emailotpauthn_otplogedpostid",$migrator_defaultsettings["emailotpauthn_otplogedpostid"]);
		$migrator_defaultsettings["emailotpauthn_popupboxmargin"] = get_fix_option("emailotpauthn_popupboxmargin",$migrator_defaultsettings["emailotpauthn_popupboxmargin"]);
		$migrator_defaultsettings["emailotpauthn_frmnoticsiz"] = get_fix_option("emailotpauthn_frmnoticsiz",$migrator_defaultsettings["emailotpauthn_frmnoticsiz"]);
		$migrator_defaultsettings["emailotpauthn_licensekey"] = get_fix_option("emailotpauthn_licensekey",$migrator_defaultsettings["emailotpauthn_licensekey"]);
		$migrator_defaultsettings["emailotpauthn_hedrxtstyle"] = get_fix_option("emailotpauthn_hedrxtstyle",$migrator_defaultsettings["emailotpauthn_hedrxtstyle"]);
		$migrator_defaultsettings["emailotpauthn_headercolor"] = get_fix_option("emailotpauthn_headercolor",$migrator_defaultsettings["emailotpauthn_headercolor"]);
		$migrator_defaultsettings["emailotpauthn_inptxtstyle"] = get_fix_option("emailotpauthn_inptxtstyle",$migrator_defaultsettings["emailotpauthn_inptxtstyle"]);
		$migrator_defaultsettings["emailotpauthn_inptbxcolor"] = get_fix_option("emailotpauthn_inptbxcolor",$migrator_defaultsettings["emailotpauthn_inptbxcolor"]);
		$migrator_defaultsettings["emailotpauthn_butnxtstyle"] = get_fix_option("emailotpauthn_butnxtstyle",$migrator_defaultsettings["emailotpauthn_butnxtstyle"]);
		$migrator_defaultsettings["emailotpauthn_buttoncolor"] = get_fix_option("emailotpauthn_buttoncolor",$migrator_defaultsettings["emailotpauthn_buttoncolor"]);
		$migrator_defaultsettings["emailotpauthn_bodyxtstyle"] = get_fix_option("emailotpauthn_bodyxtstyle",$migrator_defaultsettings["emailotpauthn_bodyxtstyle"]);
		$migrator_defaultsettings["emailotpauthn_bodybgcolor"] = get_fix_option("emailotpauthn_bodybgcolor",$migrator_defaultsettings["emailotpauthn_bodybgcolor"]);
		$migrator_defaultsettings["emailotpauthn_poppbgcolor"] = get_fix_option("emailotpauthn_poppbgcolor",$migrator_defaultsettings["emailotpauthn_poppbgcolor"]);
		$migrator_defaultsettings["emailotpauthn_frmbrdrcolr"] = get_fix_option("emailotpauthn_frmbrdrcolr",$migrator_defaultsettings["emailotpauthn_frmbrdrcolr"]);
		$migrator_defaultsettings["emailotpauthn_frmnoticclr"] = get_fix_option("emailotpauthn_frmnoticclr",$migrator_defaultsettings["emailotpauthn_frmnoticclr"]);
		$migrator_defaultsettings["emailotpauthn_poppboximeg"] = get_fix_option("emailotpauthn_poppboximeg",$migrator_defaultsettings["emailotpauthn_poppboximeg"]);
		$migrator_defaultsettings["emailotpauthn_backdrpimeg"] = get_fix_option("emailotpauthn_backdrpimeg",$migrator_defaultsettings["emailotpauthn_backdrpimeg"]);
		$migrator_defaultsettings["emailotpauthn_redirect_url"] = get_fix_option("emailotpauthn_redirect_url",$migrator_defaultsettings["emailotpauthn_redirect_url"]);
		$migrator_defaultsettings["emailotpauthn_redirect2faurl"] = get_fix_option("emailotpauthn_redirect2faurl",$migrator_defaultsettings["emailotpauthn_redirect2faurl"]);
		$migrator_defaultsettings["emailotpauthn_rgstrdefltrole"] = get_fix_option("emailotpauthn_rgstrdefltrole",$migrator_defaultsettings["emailotpauthn_rgstrdefltrole"]);
		$migrator_defaultsettings["emailotpauthn_rgstrtermouurl"] = get_fix_option("emailotpauthn_rgstrtermouurl",$migrator_defaultsettings["emailotpauthn_rgstrtermouurl"]);
		$migrator_defaultsettings["emailotpauthn_rgstrredrcturl"] = get_fix_option("emailotpauthn_rgstrredrcturl",$migrator_defaultsettings["emailotpauthn_rgstrredrcturl"]);
		$migrator_defaultsettings["emailotpauthn_mmbrvrfrdcturl"] = get_fix_option("emailotpauthn_mmbrvrfrdcturl",$migrator_defaultsettings["emailotpauthn_mmbrvrfrdcturl"]);
		$migrator_defaultsettings["emailotpauthn_mmbrofrdcturls"] = get_fix_option("emailotpauthn_mmbrofrdcturls",$migrator_defaultsettings["emailotpauthn_mmbrofrdcturls"]);
		$migrator_defaultsettings["emailotpauthn_mmbrrjtrdcturl"] = get_fix_option("emailotpauthn_mmbrrjtrdcturl",$migrator_defaultsettings["emailotpauthn_mmbrrjtrdcturl"]);
		$migrator_defaultsettings["emailotpauthn_gustvrfrdcturl"] = get_fix_option("emailotpauthn_gustvrfrdcturl",$migrator_defaultsettings["emailotpauthn_gustvrfrdcturl"]);
		$migrator_defaultsettings["emailotpauthn_gustofrdcturls"] = get_fix_option("emailotpauthn_gustofrdcturls",$migrator_defaultsettings["emailotpauthn_gustofrdcturls"]);
		$migrator_defaultsettings["emailotpauthn_gustrjtrdcturl"] = get_fix_option("emailotpauthn_gustrjtrdcturl",$migrator_defaultsettings["emailotpauthn_gustrjtrdcturl"]);
		$migrator_defaultsettings["emailotpauthn_redirect_out"] = get_fix_option("emailotpauthn_redirect_out",$migrator_defaultsettings["emailotpauthn_redirect_out"]);
		$migrator_defaultsettings["emailotpauthn_sendfromemail"] = get_fix_option("emailotpauthn_sendfromemail",$migrator_defaultsettings["emailotpauthn_sendfromemail"]);
		$migrator_defaultsettings["emailotpauthn_sendfromcmail"] = get_fix_option("emailotpauthn_sendfromcmail",$migrator_defaultsettings["emailotpauthn_sendfromcmail"]);
		$migrator_defaultsettings["emailotpauthn_popuphorzalign"] = get_fix_option("emailotpauthn_popuphorzalign",$migrator_defaultsettings["emailotpauthn_popuphorzalign"]);
		
		$migrator_newsettingsvals = json_encode($migrator_defaultsettings);
		if(!empty($migrator_newsettingsvals)) update_option("emailotpauthn_settingsdetls", $migrator_newsettingsvals);
		
		update_option("emailotpauthn_isdemofilplcd","");
		$migrator_email_subject = get_fix_option("emailotpauthn_email_subject","");
		if(emailotpauthn_isascii($migrator_email_subject)) update_option("emailotpauthn_email_subject",bin2hex($migrator_email_subject));
		$migrator_email_body = get_fix_option("emailotpauthn_email_body","");
		if(emailotpauthn_isascii($migrator_email_body)) update_option("emailotpauthn_email_body",bin2hex($migrator_email_body));
		$migrator_blockedemails = get_fix_option("emailotpauthn_blockedemails","");
		if(emailotpauthn_isascii($migrator_blockedemails)) update_option("emailotpauthn_blockedemails",bin2hex($migrator_blockedemails));
		$migrator_allowedemails = get_fix_option("emailotpauthn_allowedemails","");
		if(emailotpauthn_isascii($migrator_allowedemails)) update_option("emailotpauthn_allowedemails",bin2hex($migrator_allowedemails));
		$migrator_blockedmailid = get_fix_option("emailotpauthn_blockedmailid","");
		if(emailotpauthn_isascii($migrator_blockedmailid)) update_option("emailotpauthn_blockedmailid",bin2hex($migrator_blockedmailid));
		$migrator_dfltextrnalcss = get_fix_option("emailotpauthn_dfltextrnalcss","");
		if(emailotpauthn_isascii($migrator_dfltextrnalcss)) update_option("emailotpauthn_dfltextrnalcss",bin2hex($migrator_dfltextrnalcss));
		$migrator_mdfdextrnalcss = get_fix_option("emailotpauthn_mdfdextrnalcss","");
		if(emailotpauthn_isascii($migrator_mdfdextrnalcss)) update_option("emailotpauthn_mdfdextrnalcss",bin2hex($migrator_mdfdextrnalcss));
		$migrator_formnoticentxt = get_fix_option("emailotpauthn_formnoticentxt","");
		if(emailotpauthn_isascii($migrator_formnoticentxt)) update_option("emailotpauthn_formnoticentxt",bin2hex($migrator_formnoticentxt));
		
		return true;
	}
	return false;
}
function emailotpauthn_isascii(string $eotpastr) {
	if(empty($eotpastr)) return false;
    if (str_starts_with(strtolower($eotpastr), '0x')) {
        $eotpastr = substr($eotpastr, 2);
    }
    return (!ctype_xdigit($eotpastr));
}
function emailotpauthn_license_allowed($getnum=false){
	//"Lite";"Pro";"Prime";"Extreme";
	if($getnum)	return 1; else return "Lite";
}
function get_fix_option($optnval,$dflt){
	$notexist = "not-exists";
	$sival = get_option($optnval,$notexist);
	if($sival == null)
		$sival = $notexist;
	elseif(!isset($sival))
		$sival = $notexist;
	//if(empty($sival)) $sival = $dflt;
	if($sival === $notexist) $sival = $dflt;
	if(is_numeric($sival)) $sival = floatval($sival); else $sival = strval($sival);
	return $sival;
}
function call_emailotpauthn_external_function($respstatus,$responsstr,$useremail=''){
	echo $responsstr;
	if($respstatus==0) $useremail='';
	do_action('emailotpauthn_external_php_function',$respstatus,$useremail);
	/*
		// Use this funtion in your theme function.php file to hook any programe with successful/failure OTP authentication attempt.
		// Beware, this function will not be running on a different thread.
		// OTP authentication attempt will be finished after the completion of this function.
		// $respstatus = 0 for failure attempt and 1 for successful attempt.
		function emailotpauthn_external_php_function($respstatus) { ....... }
	*/
	wp_die();
}
//init class
if (class_exists("emailotpauthnFront")) {
    // instantiate the plugin class
    $emailotpauthnFront = new emailotpauthnFront();
}
