<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
class Stylish_Cost_Calculator_Settings
{
    public function __construct()
    {
        add_action('admin_init', array($this, 'admin_init'));
        add_action('admin_menu', array($this, 'admin_menu'), 90);
        $this->license_return = get_option('scc_license_return');
        //  $sc_scheme = get_option('scc_color-scheme', 1);
    }
    function admin_init()
    {
        $default_subject = "Your Quote Request From " . get_bloginfo('url');
        $scc_color_scheme = get_option('scc_color-scheme');
        $scc_currency = get_option('scc_currency');
        $scc_currency = get_option('scc_currencytext');
        $scc_licensed = get_option('scc_licensed');
        $scc_fontsettings = get_option('scc_fontsettings');
        $scc_emailsender = get_option('scc_emailsender');
        $scc_emailsubject = get_option('scc_emailsubject');
        $scc_sendername = get_option('scc_sendername');
        $scc_messageform = get_option('scc_messageform');
        $scc_email_send_copy = get_option('scc_email_send_copy');
        if (!isset($scc_email_send_copy)) {
            add_option('scc_email_send_copy', "");
        }
        if (!$scc_color_scheme) {
            add_option('scc_color-scheme', 1);
        }
        if (!$scc_currency) {
            add_option('scc_currency', 'USD');
        }
        if (!$scc_currency) {
            add_option('scc_currencytext', 'U.S. Dollar');
        }
        if (!$scc_licensed) {
            add_option('scc_licensed', '0');
        }
        if (!$scc_fontsettings) {
            add_option('scc_fontsettings', '');
        }
        if (!$scc_emailsender) {
            add_option('scc_emailsender', '');
        }
        if (!$scc_emailsubject) {
            add_option('scc_emailsubject', $default_subject);
        }
        if (!$scc_sendername) {
            add_option('scc_sendername', '');
        }
        if (!$scc_messageform) {
            add_option('scc_messageform', "Hello <customer-name>, <br><br> Attached to this email is a PDF file with that contains your quote. <br> If you have any further questions please call us email us here ____. <br> Sincerely,<br> Your Company Name<br><br> <hr><br> <b>Customer's Name</b> l <customer-name> <b>Customer's Phone</b> l <customer-phone> <b>Customer's Emai</b> l <customer-email> <b>Customer's IP</b> l <customer-ip-address> <b>Browser Info</b> l <customer-browser-info ><b>Device</b> l <device> <b> Referral </b> | <customer-referral>");
        }
        register_setting('stylishpl_options', 'scc_license_key', array($this, 'process_key'));
        //wp_enqueue_style('scc-admin-style', SCC_URL. 'styles/scc-front-end.css', array(), '3.1.5');
        // if(isset($_GET["page"]) == "scc-tabs" || isset($_GET["page"]) == "Stylish_Cost_Calculator_EditItems" || isset($_GET["page"]) == "edit_sccbyid" || isset($_GET["page"]) == "stylish_cost_calculator_Diagnostic" || isset($_GET["page"]) == "stylish_cost_calculator_help" || isset($_GET["page"]) == "stylish_cost_calculator_settings"  || isset($_GET["page"]) == "Stylish_Cost_Calculator_Coupon") {
        //     wp_enqueue_style('gf-admin-style', SCC_URL. 'styles/scc-back-end.css', array(), '3.1.7');
        // }
    }
    function process_key($key)
    {
        if (isset($_REQUEST['activate'])) {
            $license_return = $this->activate($key);
        } else if (isset($_REQUEST['deactivate'])) {
            $license_return = $this->deactivate($key);
            update_option('scc_license_key', 0);
        }
        update_option('scc_license_return', $license_return);
        return $key;
    }
    function checkbox($name, $options = array(), $current_value_arr = array())
    {
        ob_start();
?>
        <div class="checkbox">
            <?php foreach ($options as $value => $label) :
                $checked = '';
                if (in_array($value, $current_value_arr) != false) {
                    $checked = ' checked="checked"';  //find the value
                }
            ?>
                <label>
                    <input name="<?php echo esc_html($name) . '[]'; ?>" type="checkbox" value="<?php echo esc_html($value); ?>" <?php echo esc_html($checked); ?>>
                    <?php echo esc_html($label); ?>
                </label>
            <?php endforeach ?>
        </div>
    <?php
        $html = ob_get_clean();
        return $html;
    }
    function select($name, $options = array(), $current_value = '')
    {
        ob_start();
    ?>
        <select name="<?php echo esc_html($name); ?>" id="<?php echo esc_html($name); ?>" class="form-control">
            <?php foreach ($options as $value => $label) :
                $selected = '';
                if ($current_value == $value) {
                    $selected = ' selected="selected"';
                }
            ?>
                <option value="<?php echo esc_html($value); ?>" <?php echo esc_html($selected); ?>><?php echo esc_html($label); ?></option>
            <?php endforeach ?>
        </select>
    <?php
        $html = ob_get_clean();
        return $html;
    }
    function option_page()
    {
    ?>
        <link rel="preconnect" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
        <?php
        include_once SCC_DIR . '/admin/logo-header.php';
        $default_subject = "Your Quote Request From " . get_bloginfo('url');
        $scc_licensed_value = get_option('scc_license_key');
        $scc_emailsender = sanitize_text_field(stripslashes(get_option('scc_emailsender')));
        $scc_emailsubject = sanitize_text_field(stripslashes(get_option('scc_emailsubject', $default_subject)));
        $scc_sendername = sanitize_text_field(stripslashes(get_option('scc_sendername')));
        $scc_messageform = get_option('scc_messageform');
        $scc_licence_enable = get_option('scc_licensed');
        $scc_license_key = get_option('scc_license_key');
        if ('the license key is empty' == strtolower($scc_license_key)) {
            $scc_license_key = '';
        }
        if (preg_replace('/\s/', '', $scc_messageform) == '' || empty($scc_messageform)) {
            update_option('scc_messageform', "Hello <Customer>,\r\n\r\n Here is your attached quote.\r\n\r\n Thanks\r\n<sender>");
            $scc_messageform = "Hello <Customer>,\r\n\r\n Here is your attached quote.\r\n\r\n Thanks\r\n<sender>";
        }
        if (gettype($scc_emailsender) == 'string' && strlen($scc_emailsender) == 0) {
            $scc_emailsender = get_option('admin_email');
        }
        if (gettype($scc_sendername) == 'string' && strlen($scc_sendername) == 0) {
            $scc_sendername = get_option('blogname');
        }
        $icon_class = 'dashicons-no';
        $icon_style = 'color:red;';
        $opt = get_option('scclk_opt');
        if (!empty($opt) && $opt == 1) {
            $icon_class = 'dashicons-yes';
            $icon_style = 'color:green;';
        }
        if (isset($_GET['settings-updated']) && !empty($opt)) {
        ?>
            <div id="message" class="updated">
                <p><strong><?php esc_html_e('Settings saved.'); ?></strong></p>
            </div>
        <?php } ?>
        <form action="options.php" method="post" id="stylishpl-admin-options-form">
            <?php settings_fields('stylishpl_options'); ?>
            <style type="text/css">
                .scc-settings-card-title {
                    font-size: 22px;
                    font-weight: 400;
                    margin: 0 0 20px 0;
                }

                .scc-settings-card-title .highlighted {
                    font-weight: 800;
                    color: #314bf8;
                }

                textarea.scc-textarea-field {
                    overflow: auto;
                    padding: 5px 6px;
                    line-height: 1.4;
                    resize: vertical;
                    width: 100%;
                }

                .scc-settings-card-inner {
                    padding-left: 40px;
                    padding-right: 40px;
                }

                .scc-form-field {
                    margin-bottom: 20px;
                }

                .scc-form-field label {
                    display: block;
                }

                .scc-form-field .sccbutton {
                    width: auto;
                }

                .scc-media-uploader-image {
                    max-width: 200px;
                    border: 1px solid #007cba;
                    position: relative;
                    margin-top: 10px;
                }

                .scc-media-uploader-image img {
                    width: 100%;
                    height: auto;
                }

                .scc-media-uploader-remove {
                    position: absolute;
                    right: 0;
                    top: 0;
                    background-color: blue;
                    color: #fff;
                    font-size: 20px;
                    line-height: 20px;
                    height: 20px;
                    width: 20px;
                    text-align: center;
                    display: block;
                    cursor: pointer;
                }

                .dashicons-no::before,
                .dashicons-yes::before {
                    font-size: 25px;
                }

                .sccbutton {
                    background: #314af3;
                    border-color: #314af3 #314af3 #314af3;
                    box-shadow: 2px 2px 2px #9a7070;
                    color: #fff;
                    text-decoration: none;
                    text-shadow: 0 -1px 1px #314af3, 1px 0 1px #314af3, 0 1px 1px #314af3, -1px 0 1px #314af3;
                    display: inline-block;
                    text-decoration: none;
                    font-size: 13px;
                    line-height: 26px;
                    height: 28px;
                    margin: 0;
                    padding: 0 10px 1px;
                    cursor: pointer;
                    border-width: 1px;
                    border-style: solid;
                    -webkit-appearance: none;
                    border-radius: 3px;
                    white-space: nowrap;
                    box-sizing: border-box;
                    width: 90px;
                }

                .sccsubtitle {
                    font-size: 20px;
                    font-weight: 400;
                    margin: 0;
                    padding: 19px 0 4px 0;
                    line-height: 29px;
                }

                .sccsubdiv {
                    height: 25px;
                    width: 90px;
                    display: flex;
                    float: left;
                    line-height: 35px;
                }

                button,
                input,
                select,
                    {
                    border: 1px solid #F0F0F0;
                }

                .panel-group .panel {
                    max-width: 800px !important;
                }
            </style>
            <style>
                .scc_title_bar {
                    background: #314af3;
                    padding: 15px;
                    padding-left: 45px;
                    margin-left: -23px;
                    font-size: 22px;
                    color: #fff;
                    letter-spacing: 1px;
                    text-transform: uppercase;
                    width: 105%;
                    margin-bottom: 40px;
                    margin-top: 10px;
                }
            </style>
            <?php
            if (get_option('scc_licensed') == 1) {
            ?>
            <?php
            }
            ?>
            <div class="scc_title_bar">Global Settings</div>
            <!-- Start Cupon button -->
            <div class="<?php echo get_option('scc_licensed') == 0 ? 'blocked' : '' ?> settings-section" style="margin-bottom:20px;padding:20px;height: 110px;width: 700px;background-color:#f9f9fe">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8">COUPON</span> SETTINGS</div><br />
                <?php
                if (get_option('scc_licensed') != 0) {
                ?>
                    <a class='forms2edit_a' style="padding-left: 40px;" href="<?php echo esc_url(get_admin_url()); ?>admin.php?page=Stylish_Cost_Calculator_Coupon">Add or View Coupons</a>
                <?php
                }
                ?>
            </div>
            <!-- End Cupon button -->
            <!-- Start Of Currency Settings -->
            <!--
        <div style="margin-bottom:-10px;padding:20px;height: 210px;width: 700px;background-color:#f9f9fe">
            <div style="font-size:160%;" class="sccsubtitle scc_email_quote_label"><span style="font-weight:800;color:#314bf8">LICENSE</span> SETTINGS</div></b><br/>
            <div style="padding-left: 40px;">
                <label for="scc_license_key">License Key: </label><br/>
                <input type="text" id="scc_license_key" name="scc_license_key" value="<?php echo esc_html($scc_license_key) ?>" onchange="checkLicenseCode(jQuery(this).val());" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
                <span id='licensecrossicon' class="<?php echo esc_html($icon_class); ?> dashicons-before" style="<?php echo esc_html($icon_style); ?>"></span>
                <br>
                <span style="padding-top:10px;"></span>
                <?php
                if ($scc_licence_enable != "1") {
                ?>
                    <input type="submit" name="activate" value="Activate" class="sccbutton" />
                    <?php
                } else {
                    ?>
                    <input type="submit" name="deactivate" value="Deactivate" class="button button-default" style=""/></p>
                    <?php
                }
                if ($this->license_return != "1") {
                    echo esc_html($this->license_return);
                }
                    ?>
            </div>
        </form>
    </div> -->
            <!-- End Of License Settings -->
            <!-- Start Of Currency Settings -->
            <div class="settings-section" style="padding:20px;min-height: 330px;width: 700px;background-color:#f9f9fe">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8;">CURRENCY</span> SETTINGS</div></b>
                <div style="padding-left: 40px;margin-top:20px;">
                    <p><label for="scc_license_key">Currency: </label>
                        <select name="currency_code" id="currency_code" onChange="handleCurrency()">
                            <option value="">Select one currency</option>
                            <option value="AUD" <?php echo get_option('scc_currency') === "AUD" ? 'selected' : '' ?>>Australian Dollar</option>
                            <option value="AED" <?php echo get_option('scc_currency') === "AED" ? 'selected' : '' ?>>Arab Emirates Dirhams (PayPal not Supported)</option>
                            <option value="Bs" <?php echo get_option('scc_currency') === "Bs" ? 'selected' : '' ?>>Bolivian Boliviano (Symbol After) (No PayPal)</option>
                            <option value="BRL" <?php echo get_option('scc_currency') === "BRL" ? 'selected' : '' ?>>Brazilian Real </option>
                            <option value="CAD" <?php echo get_option('scc_currency') === "CAD" ? 'selected' : '' ?>>Canadian Dollar</option>
                            <option value="CNY" <?php echo get_option('scc_currency') === "CNY" ? 'selected' : '' ?>>Chinese Yuan (PayPal not supported)</option>
                            <option value="COP" <?php echo get_option('scc_currency') === "COP" ? 'selected' : '' ?>>Colombian Peso (PayPal not supported)</option>
                            <option value="CZK" <?php echo get_option('scc_currency') === "CZK" ? 'selected' : '' ?>>Czech Koruna</option>
                            <option value="DKK" <?php echo get_option('scc_currency') === "DKK" ? 'selected' : '' ?>>Danish Krone</option>
                            <option value="EGP" <?php echo get_option('scc_currency') === "EGP" ? 'selected' : '' ?>>Egyptian Pound</option>
                            <option value="EUR" <?php echo get_option('scc_currency') === "EUR" ? 'selected' : '' ?>>Euro</option>
                            <option value="HKD" <?php echo get_option('scc_currency') === "HKD" ? 'selected' : '' ?>>Hong Kong Dollar</option>
                            <option value="HUF" <?php echo get_option('scc_currency') === "HUF" ? 'selected' : '' ?>>Hungarian Forint (PayPal not supported)</option>
                            <option value="IDR" <?php echo get_option('scc_currency') === "IDR" ? 'selected' : '' ?>>Indonesian Rupiah (PayPal not supported)</option>
                            <option value="ILS" <?php echo get_option('scc_currency') === "ILS" ? 'selected' : '' ?>>Israeli New Sheqel</option>
                            <option value="INR" <?php echo get_option('scc_currency') === "INR" ? 'selected' : '' ?>>Indian Rupee</option>
                            <option value="JPY" <?php echo get_option('scc_currency') === "JPY" ? 'selected' : '' ?>>Japanese Yen</option>
                            <option value="KES" <?php echo get_option('scc_currency') === "KES" ? 'selected' : '' ?>>Kenyan Shilling</option>
                            <option value="MYR" <?php echo get_option('scc_currency') === "MYR" ? 'selected' : '' ?>>Malaysian Ringgit</option>
                            <option value="MXN" <?php echo get_option('scc_currency') === "MXN" ? 'selected' : '' ?>>Mexican Peso</option>
                            <option value="ANG" <?php echo get_option('scc_currency') === "ANG" ? 'selected' : '' ?>>Netherlands Antillean Guilder (PayPal not Supported)</option>
                            <option value="NOK" <?php echo get_option('scc_currency') === "NOK" ? 'selected' : '' ?>>Norwegian Krone</option>
                            <option value="NZD" <?php echo get_option('scc_currency') === "NZD" ? 'selected' : '' ?>>New Zealand Dollar</option>
                            <option value="‎PKR" <?php echo get_option('scc_currency') === "‎PKR" ? 'selected' : '' ?>>Pakistani Rupee (PayPal not Supported)</option>
                            <option value="PHP" <?php echo get_option('scc_currency') === "PHP" ? 'selected' : '' ?>>Philippine Peso</option>
                            <option value="PLN" <?php echo get_option('scc_currency') === "PLN" ? 'selected' : '' ?>>Polish Zloty</option>
                            <option value="GBP" <?php echo get_option('scc_currency') === "GBP" ? 'selected' : '' ?>>British Pound Sterling</option>
                            <option value="RON" <?php echo get_option('scc_currency') === "RON" ? 'selected' : '' ?>>Romanian leu</option>
                            <option value="RUB" <?php echo get_option('scc_currency') === "RUB" ? 'selected' : '' ?>>Russian Rubles</option>
                            <option value="ZAR" <?php echo get_option('scc_currency') === "ZAR" ? 'selected' : '' ?>>South African Rand (PayPal not supported)</option>
                            <option value="SGD" <?php echo get_option('scc_currency') === "SGD" ? 'selected' : '' ?>>Singapore Dollar</option>
                            <option value="SEK" <?php echo get_option('scc_currency') === "SEK" ? 'selected' : '' ?>>Swedish Krona</option>
                            <option value="KRW" <?php echo get_option('scc_currency') === "KRW" ? 'selected' : '' ?>>South Korean won</option>
                            <option value="CHF" <?php echo get_option('scc_currency') === "CHF" ? 'selected' : '' ?>>Swiss Franc</option>
                            <option value="TWD" <?php echo get_option('scc_currency') === "TWD" ? 'selected' : '' ?>>Taiwan New Dollar</option>
                            <option value="THB" <?php echo get_option('scc_currency') === "THB" ? 'selected' : '' ?>>Thai Baht</option>
                            <option value="TRY" <?php echo get_option('scc_currency') === "TRY" ? 'selected' : '' ?>>Turkish Lira (PayPal not supported)</option>
                            <option value="USD" <?php echo get_option('scc_currency') === "USD" ? 'selected' : '' ?>>U.S. Dollar</option>
                            <option value="ZMW" <?php echo get_option('scc_currency') === "ZMW" ? 'selected' : '' ?>>Zambian Kwancha (PayPal not supported)</option>
                            <option value="CFA" <?php echo get_option('scc_currency') === "CFA" ? 'selected' : '' ?>>Central African CFA franc (PayPal not supported)</option>
                        </select>
                    </p>
                    <p>
                        <label for="currency-style">Currency Format:</label>
                        <select name="currency-style" id="currency-style">
                            <option value="default" <?php echo get_option('scc_currency_style') === "default" ? 'selected' : false ?>>Browser Locale</option>
                            <option value="comma" <?php echo get_option('scc_currency_style') === "comma" ? 'selected' : false ?>>Comma separated</option>
                        </select>
                    </p>
                    <p id="currency_conversion_incompatibility_message" style="color: red"></p>
                    <div id="scc_currency_coversion_global_container">
                        <p>
                            <label for="scc_currency_coversion_mode">Currency Conversion: </label>
                            <?php
                            if (get_option('scc_licensed') == 1) {
                            ?>
                                <select name="scc_currency_coversion_mode" id="scc_currency_coversion_mode" onChange="handleCurrencyCoversionMode(this)">
                                    <option value="off" <?php echo get_option('scc_currency_coversion_mode') === "off" ? 'selected' : '' ?> <?php echo get_option('scc_licensed') == 0 ? 'disabled' : '' ?>>OFF (default)</option>
                                    <option value="manual_selection" <?php echo get_option('scc_currency_coversion_mode') === "manual_selection" ? 'selected' : '' ?> <?php echo get_option('scc_licensed') == 0 ? 'disabled' : '' ?>>Select a currency</option>
                                    <option value="auto_detect" <?php echo get_option('scc_currency_coversion_mode') === "auto_detect" ? 'selected' : '' ?> <?php echo get_option('scc_licensed') == 0 ? 'disabled' : '' ?>>Auto detect currency</option>
                                </select>
                            <?php
                            } else {
                            ?>
                                <span> This feature is only available for Premium users </span>
                            <?php
                            }
                            ?>
                        </p>
                        <div>
                            Select a currency: will automatically show the selected currency to convert </br>
                            Auto detect: will use the users current location to automatically detect their currency.
                        </div>
                        </br>
                        <p id="scc_currency_coversion_manual_selection_container">
                            <label for="scc_currency_coversion_manual_selection">Select your currency for automatic conversion: </label>
                            <select name="scc_currency_coversion_manual_selection" id="scc_currency_coversion_manual_selection">
                                <option value="" <?php echo get_option('scc_currency_coversion_manual_selection') === "" ? 'selected' : '' ?>>Select currency</option>
                                <option value="EUR" <?php echo get_option('scc_currency_coversion_manual_selection') === "EUR" ? 'selected' : '' ?>>EUR</option>
                                <option value="CAD" <?php echo get_option('scc_currency_coversion_manual_selection') === "CAD" ? 'selected' : '' ?>>CAD</option>
                                <option value="HKD" <?php echo get_option('scc_currency_coversion_manual_selection') === "HKD" ? 'selected' : '' ?>>HKD</option>
                                <option value="ISK" <?php echo get_option('scc_currency_coversion_manual_selection') === "ISK" ? 'selected' : '' ?>>ISK</option>
                                <option value="PHP" <?php echo get_option('scc_currency_coversion_manual_selection') === "PHP" ? 'selected' : '' ?>>PHP</option>
                                <option value="EGP" <?php echo get_option('scc_currency_coversion_manual_selection') === "EGP" ? 'selected' : '' ?>>EGP</option>
                                <option value="DKK" <?php echo get_option('scc_currency_coversion_manual_selection') === "DKK" ? 'selected' : '' ?>>DKK</option>
                                <option value="HUF" <?php echo get_option('scc_currency_coversion_manual_selection') === "HUF" ? 'selected' : '' ?>>HUF</option>
                                <option value="CZK" <?php echo get_option('scc_currency_coversion_manual_selection') === "CZK" ? 'selected' : '' ?>>CZK</option>
                                <option value="AUD" <?php echo get_option('scc_currency_coversion_manual_selection') === "AUD" ? 'selected' : '' ?>>AUD</option>
                                <option value="RON" <?php echo get_option('scc_currency_coversion_manual_selection') === "RON" ? 'selected' : '' ?>>RON</option>
                                <option value="SEK" <?php echo get_option('scc_currency_coversion_manual_selection') === "SEK" ? 'selected' : '' ?>>SEK</option>
                                <option value="IDR" <?php echo get_option('scc_currency_coversion_manual_selection') === "IDR" ? 'selected' : '' ?>>IDR</option>
                                <option value="INR" <?php echo get_option('scc_currency_coversion_manual_selection') === "INR" ? 'selected' : '' ?>>INR</option>
                                <option value="BRL" <?php echo get_option('scc_currency_coversion_manual_selection') === "BRL" ? 'selected' : '' ?>>BRL</option>
                                <option value="RUB" <?php echo get_option('scc_currency_coversion_manual_selection') === "RUB" ? 'selected' : '' ?>>RUB</option>
                                <option value="HRK" <?php echo get_option('scc_currency_coversion_manual_selection') === "HRK" ? 'selected' : '' ?>>HRK</option>
                                <option value="JPY" <?php echo get_option('scc_currency_coversion_manual_selection') === "JPY" ? 'selected' : '' ?>>JPY</option>
                                <option value="KES" <?php echo get_option('scc_currency_coversion_manual_selection') === "KES" ? 'selected' : '' ?>>KES</option>
                                <option value="THB" <?php echo get_option('scc_currency_coversion_manual_selection') === "THB" ? 'selected' : '' ?>>THB</option>
                                <option value="CHF" <?php echo get_option('scc_currency_coversion_manual_selection') === "CHF" ? 'selected' : '' ?>>CHF</option>
                                <option value="SGD" <?php echo get_option('scc_currency_coversion_manual_selection') === "SGD" ? 'selected' : '' ?>>SGD</option>
                                <option value="PLN" <?php echo get_option('scc_currency_coversion_manual_selection') === "PLN" ? 'selected' : '' ?>>PLN</option>
                                <option value="BGN" <?php echo get_option('scc_currency_coversion_manual_selection') === "BGN" ? 'selected' : '' ?>>BGN</option>
                                <option value="TRY" <?php echo get_option('scc_currency_coversion_manual_selection') === "TRY" ? 'selected' : '' ?>>TRY</option>
                                <option value="CNY" <?php echo get_option('scc_currency_coversion_manual_selection') === "CNY" ? 'selected' : '' ?>>CNY</option>
                                <option value="NOK" <?php echo get_option('scc_currency_coversion_manual_selection') === "NOK" ? 'selected' : '' ?>>NOK</option>
                                <option value="NZD" <?php echo get_option('scc_currency_coversion_manual_selection') === "NZD" ? 'selected' : '' ?>>NZD</option>
                                <option value="ZAR" <?php echo get_option('scc_currency_coversion_manual_selection') === "ZAR" ? 'selected' : '' ?>>ZAR</option>
                                <option value="USD" <?php echo get_option('scc_currency_coversion_manual_selection') === "USD" ? 'selected' : '' ?>>USD</option>
                                <option value="MXN" <?php echo get_option('scc_currency_coversion_manual_selection') === "MXN" ? 'selected' : '' ?>>MXN</option>
                                <option value="ILS" <?php echo get_option('scc_currency_coversion_manual_selection') === "ILS" ? 'selected' : '' ?>>ILS</option>
                                <option value="GBP" <?php echo get_option('scc_currency_coversion_manual_selection') === "GBP" ? 'selected' : '' ?>>GBP</option>
                                <option value="KRW" <?php echo get_option('scc_currency_coversion_manual_selection') === "KRW" ? 'selected' : '' ?>>KRW</option>
                                <option value="MYR" <?php echo get_option('scc_currency_coversion_manual_selection') === "MYR" ? 'selected' : '' ?>>MYR</option>
                                <option value="KRW" <?php echo get_option('scc_currency_coversion_manual_selection') === "KRW" ? 'selected' : '' ?>>KRW</option>
                            </select>
                        </p>
                    </div>
                    <input class="sccbutton" type="button" name="Save" value="Save" onClick="saveSCCSettings()" /><br /><br />
                    <div id="settingsuccs"></div>
                </div>
            </div>
            <!-- END Of Currency Settings -->
            <!-- START of Stripe Settings -->
            <?php
            $stripe_opts = wp_parse_args(get_option('scc_stripe_keys'), array('privKey' => null, 'pubKey' => null));
            $privKeyPlaceHolder = $stripe_opts['privKey'] ? substr($stripe_opts['privKey'], 0, - (strlen($stripe_opts['privKey']) * .7)) . '*****' . substr($stripe_opts['privKey'], - (strlen($stripe_opts['privKey']) * .2)) : 'Please enter Stripe API Private Key';
            $pubKeyPlaceHolder = $stripe_opts['pubKey'] ? substr($stripe_opts['pubKey'], 0, - (strlen($stripe_opts['pubKey']) * .7)) . '*****' . substr($stripe_opts['pubKey'], - (strlen($stripe_opts['pubKey']) * .2)) : 'Please enter Stripe API Public Key';
            ?>
            <div class="settings-section" style="padding:20px;min-height: 280px;width: 700px;background-color:#f9f9fe">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8;">STRIPE</span> SETTINGS <a href="https://designful.freshdesk.com/support/solutions/articles/48000945308-sending-quotes-by-email-smtp-server-" target="_blank"><i class="fa fa-book" aria-hidden="true"></i></a></div>
                <div style="padding-left: 40px;margin-top:20px;">
                    <label for="stripe-api-priv-key">Stripe Secret Key</label>
                    <input type="text" placeholder="<?php echo $privKeyPlaceHolder; ?>" name="stripe-api-priv-key" style="width:100%;padding: 7px 10px;  height: 40px;">
                    <label for="stripe-api-pub-key" style="margin-top:20px;">Stripe Public Key</label>
                    <input type="text" placeholder="<?php echo $pubKeyPlaceHolder; ?>" name="stripe-api-pub-key" style="width:100%;padding: 7px 10px;  height: 40px;">
                    <button class="sccbutton" style="margin-top: 5px;" type="button" onclick="updateStripeKey(this)">Save</button>
                    <p id="scc_stripekey_message"></p>
                </div>
            </div>
            <!-- END of Stripe Settings -->
            <!-- Start Email Settings -->
            <div class="settings-section" id="email-settings" style="padding:20px;height: auto;width: 700px;background-color:#f9f9fe">
                <?php
                // banner image and logo settings email template
                $this->email_template_banner_and_logo();
                ?>
                <div style="font-size:160%;padding-top:100px;padding-top:40px;" class=""><span style="font-weight:800;color:#314bf8;">EMAIL QUOTE</span> SETTINGS
                    <div class="scc_help_btn_right" style="left:292px;float:left;top:4px;font-size:18px;"><a href="#" style="padding-left:10px;color:black;" class="tooltipadmin-right" data-tooltip="Your email must have the same domain name as your website for this to work.<br><br> Two emails get sent during every form submission. One to the <b>customer email</b>, and one email to the <b>from</b> email.
            We recommend that you create a special folder in your email inbox to store all these quote forms. In the future, we're working on a feature to view all form submissions."> <img src="<?php echo esc_url(SCC_URL . '/assets/images/info-icon-scc.png'); ?>" alt="Info Icon" height="15px;"> </a></div>
                </div><br />
                <div style="padding-left: 40px;width: 600px;">
                    <p></p>
                    <button type="button" class="sccbutton2" id="email_form_short_codes_button" onclick="toggleShortCodes()" style='padding-bottom:15px;margin-bottom:20px;padding-top:7px;cursor:pointer; background-color: #314bf8;color:#fff; height:35px; border:none; width:160px !important'>Shortcodes</button>
                    <div id="email_form_short_codes_section" style="display: none;background: #dddff8;padding:20px;margin-bottom:10px;">
                        <strong>
                            <p id="email-customer-note"></p>
                        </strong>
                        <p id="email-customer-email"></p>
                        <p id="email-customer-name"></p>
                        <p id="email-customer-phone"></p>
                        <p id="browser-customer-info"></p>
                        <p id="device"></p>
                        <p id="email-customer-ip"></p>
                        <p id="email-customer-sender"></p>
                    </div>
                    <div class="scc_temp_email" style="display:flex; margin-bottom: 15px;">
                        <input type="text" id="sendername" placeholder="Sender Name (You)" value="<?php echo sanitize_text_field($scc_sendername); ?>" class="" style="margin: 0 10px 0 0; padding: 7px 10px; width: 50%; height: 40px;" />
                        <input type="email" id="senderemail" placeholder="Sender Email (Your Email)" value="<?php echo sanitize_text_field($scc_emailsender); ?>" class="" style="padding: 7px 10px; width: 50%; height: 40px;" />
                    </div>
                    <div class="scc_temp_email" style="display:flex; margin-bottom: 15px;">
                        <input placeholder="CC Email Address (optional)" id="scc_email_send_copy" type="email" style="width:100%;padding: 7px 10px;  height: 40px;" value="<?php echo  get_option('scc_email_send_copy') ?>">
                    </div>
                    <div class="scc_temp_email" style="margin-bottom: 15px;">
                        <input type="text" id="emailsubject" placeholder="Email Subject" value="<?php echo stripslashes(htmlspecialchars($scc_emailsubject)); ?>" class="" style="padding: 7px 10px; width: 100%; height: 40px;" />
                    </div>
                    <div>
                        <?php
                        $tags = ["<customer-name>", "<customer-phone>", "<customer-email>", "<customer-ip-address>", "<customer-browser-info>", "<device>", "<customer-referral>"];
                        function htmlify($a)
                        {
                            return htmlentities($a);
                        }
                        $tags_htmlified = array_map('htmlify', $tags);
                        $scc_messageform = str_replace($tags, $tags_htmlified, $scc_messageform);
                        wp_editor(stripslashes(str_replace(array("<br/>", "<br>", "< br/>"), array("\r\n", "\r", "\n"), $scc_messageform)), "messagetemplate", []);
                        ?>
                    </div>
                    <div class="sccsubdiv" style="margin-top:20px;">
                        <input class="sccbutton scc_save_emdl" style="min-width:560px;height:45px;font-size:18px" type="submit" name="Save" value="SAVE EMAIL & DETAILED LIST" onClick="saveSCCEmailSetting()" />
                        <hr />
                    </div>
                </div>
                <br><br>
                <div id="savingemailresult" style="font-size:20px;color:green; margin-top: 30px;"></div>
                <?php
                if (is_plugin_active('wp-mail-smtp/wp_mail_smtp.php') == false && is_plugin_active('wp-mail-smtp-pro/wp_mail_smtp.php') == false) {
                    echo '<div id="border1" style="margin-top: 100px"><span class="yellow_dot"></span> <span style="font-size:1em;font-weight:bold;">Potential Email Config Error: </span>';
                    echo 'Please install <a href="https://en-ca.wordpress.org/plugins/wp-mail-smtp/" target="_blank">WP Forms SMTP plugin</a> for the best email delivery.';
                    echo "</div>";
                }
                ?>
                <div style="padding:20px 20px 20px 20px ; font-size: 14px; font-weight: 300;line-height: 20px;margin-top:70px;border-radius:10px;border: 1px solid #dddff8;font-weight:300;width:600px;">
                    <div style="padding-bottom:10px;font-size:18px;font-weight: 700;color:red;">IMPORTANT</div>
                    Read the <a href="https://designful.freshdesk.com/support/solutions/articles/48000945308-sending-quotes-by-email-smtp-server-" target="_blank">ultimate email setup guide</a> to get started.
                </div>
            </div>
            <!-- END OF DETAILED SETTINGS AND EMIAL -->
            <!-- Start PDF settings -->
            <div class="<?php echo get_option('scc_licensed') == 0 ? 'blocked' : '' ?> settings-section" style="margin-top:20px;margin-bottom:20px;padding:20px;min-height: 280px;width: 700px;background-color:#f9f9fe" id="scc_pdf_settings">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8">PDF</span> Settings</div>
                <div style="margin-left:20px;padding-top:10px;">
                    Select the font and date format you would like to use for email quote and detailed list view.<br><br>
                    <?php
                    $sscPDFfont = get_option('sscPDFfont');
                    if ($sscPDFfont == '') {
                        if (
                            get_option('scc_currency') == 'CNY' || get_option('scc_currency') == 'HKD' || get_option('scc_currency') == 'INR' ||
                            get_option('scc_currency') == 'JPY' || get_option('scc_currency') == 'BDT' || get_option('scc_currency') == 'RUB' ||
                            get_option('scc_currency') == 'KRW' || get_option('scc_currency') == 'TWD' || get_option('scc_currency') == 'VND'
                        ) {
                            $sscPDFfont = 'cid0jp';
                        } else {
                            $sscPDFfont = 'regular';
                        }
                    }
                    ?>
                    <p>PDF Font</p>
                    <select id="pdf_font">

                        <option value="regular" <?php echo $sscPDFfont == 'regular' ? 'selected' : '' ?>>Regular</option>
                        <option value="cid0jp" <?php echo $sscPDFfont == 'cid0jp' ? 'selected' : '' ?>>cid0jp (Japanese and Russian support)</option>
                        <option value="dejavusans" <?php echo $sscPDFfont == 'dejavusans' ? 'selected' : '' ?>>DejaVuSans</option>
                        <option value="dejavusansb" <?php echo $sscPDFfont == 'dejavusansb' ? 'selected' : '' ?>>DejaVuSans-Bold</option>
                        <option value="dejavusansbi" <?php echo $sscPDFfont == 'dejavusansbi' ? 'selected' : '' ?>>DejaVuSans-BoldOblique</option>
                        <option value="helvetica" <?php echo $sscPDFfont == 'helvetica' ? 'selected' : '' ?>>Helvetica</option>
                        <option value="Helvetica-Bold" <?php echo $sscPDFfont == 'Helvetica-Bold' ? 'selected' : '' ?>>Helvetica-Bold</option>
                        <option value="Helvetica-BoldOblique" <?php echo $sscPDFfont == 'Helvetica-BoldOblique' ? 'selected' : '' ?>>Helvetica-BoldOblique</option>
                        <option value="Helvetica-Italic" <?php echo $sscPDFfont == 'Helvetica-Italic' ? 'selected' : '' ?>>Helvetica-Italic</option>
                    </select>
                </div>
                <div style="margin-left:20px;padding-top:10px;">
                    <p>Date format</p>
                    <select id="pdf_datefmt">
                        <option value="mm-dd-yyyy" <?php echo get_option('scc_pdf_datefmt') == 'mm-dd-yyyy' ? 'selected' : '' ?>>mm-dd-yyyy</option>
                        <option value="dd-mm-yyyy" <?php echo get_option('scc_pdf_datefmt') == 'dd-mm-yyyy' ? 'selected' : '' ?>>dd-mm-yyyy</option>
                    </select>
                </div>
                <div style="margin-left:20px;padding-top:10px;">
                    <button class='sccbutton' type="button" onClick='sccPDFSettings()'>Save</button>
                </div>
                <div style="margin-left:20px;padding-top:10px;">
                    <p id="scc_pdf_font_message"></p>
                </div>
            </div>
            <!-- End PDF settings -->
            <!-- Start reCaptcha settings -->
            <div class="settings-section" style="margin-top:20px;margin-bottom:20px;padding:20px;height: 320px;width: 700px;background-color:#f9f9fe" id="recaptcha">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8">reCaptcha</span> Settings</div>
                <div style="margin-left:20px;padding-top:10px;">
                    Please enter the recaptcha keys in the following fields<br><br>
                    <p><input type="checkbox" name="captcha-enablement-status" <?php echo get_option('scc-captcha-enablement-status') ? 'checked' : false ?>> <span>Enable reCaptcha v2</span></p>
                    <label>Site Key</label>
                    <input type="text" placeholder="Please enter Site Key" name="site-key-recaptcha" style="width:100%;padding: 7px 10px;  height: 40px;" <?php echo get_option('scc-recaptcha-site-key') ? 'value="' . get_option('scc-recaptcha-site-key') . '"' : false; ?>>
                    <label>Secret Key</label>
                    <input type="text" placeholder="Please enter Secret Key" name="secret-key-recaptcha" style="width:100%;padding: 7px 10px;  height: 40px;" <?php echo get_option('scc-recaptcha-secret-key') ? 'value="' . get_option('scc-recaptcha-secret-key') . '"' : false; ?>>
                    </br>
                    <button class='sccbutton' style="margin-top: 5px;" type="button" onClick='sccSaveRecaptchaKeys()'>Save</button>
                    <p id="scc_recaptcha_message"></p>
                </div>
            </div>
            <!-- Start reCaptcha settings -->
            <!-- Start Restore SCC button -->
            <div class="<?php echo get_option('scc_licensed') == 0 ? 'blocked' : '' ?> settings-section" style="margin-top:20px;margin-bottom:20px;padding:20px;height: 205px;width: 700px;background-color:#f9f9fe" id="restore_container">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8">RESTORE</span> SCC</div>
                <div style="margin-left:20px;padding-top:10px;">
                    You can restore an instance of a calculator that you bave previously backedup.<br><br>
                    <input id="backup_scc_file" type="file" accept=".json">
                    <?php
                    if (get_option('scc_licensed') != 0) {
                    ?>
                        <button class='sccbutton' type="button" onClick='sscUploadSccBackup()'>Restore</button>
                    <?php
                    } else {
                    ?>
                        <button class='sccbutton'>Restore SCC</button>
                    <?php
                    }
                    ?>
                    <p id="scc_backup_message"></p>
                </div>
            </div>
            <!-- End Restore SCC button -->
            <!-- Start Database Change button -->
            <div style="margin-bottom:20px;padding:20px;height: 190px;width: 700px;background-color:#f9f9fe; display:none">
                <div style="font-size:160%;" class=""><span style="font-weight:800;color:#314bf8">DATABASE</span> CHARTSET</div>
                <div style="margin-left:20px;padding-top:10px;">
                    If you first installed SCC before September 2019, then you can update your database here. Everyone else can ignore this.<br><br>
                    <a class='forms2edit_a' href="#" onClick='sccChangeDatabaseToUtf8()'>Check Database</a>
                    <p id="database_change_message"></p>
                </div>
            </div>
            <!-- End Database Change button -->
            <?php
            include_once SCC_DIR . '/admin/logo-footer.php';
            ?>
            <script>
                function sccWhenAvailable(name, callback) {
                    var interval = 10; // ms
                    window.setTimeout(function() {
                        if (window[name]) {
                            callback(window[name]);
                        } else {
                            sccWhenAvailable(name, callback);
                        }
                    }, interval)
                };
                jQuery('#licensecrossicon').click(function() {
                    jQuery('#scc_license_key').val('');
                });
                jQuery('#email-customer-note').text("NOTE: Use these shortcodes to customize your email template to your customers.")
                jQuery('#email-customer-name').text("Customer Name <customer-name>")
                jQuery('#email-customer-email').text("Customer's Email <customer-email>")
                jQuery('#email-customer-phone').text("Customer Phone <customer-phone>")
                jQuery('#email-customer-ip').text("Customer IP <customer-ip-address>")
                jQuery('#browser-customer-info').text("Customer Broswer <customer-browser-info>")
                jQuery('#device').text("Customer Device <device>")
                jQuery('#email-customer-sender').text("Sender (Your) Name <sender>")
                // window.onLoad
                document.addEventListener('DOMContentLoaded', (event) => {
                    jQuery('.sccbutton.scc_save_emdl').hover(() => {
                        tinyMCE.triggerSave();
                    });
                })

                function checkLicenseCode(value) {
                    if (value && value.length === 13) {
                        var alertMessage = '<div id="alert-message" style="background: black">';
                        alertMessage += '<center style="padding: 50px"><h1 style="color:white;">IMPORTANT ALERT</h1></center><div onClick="closeAlert()" style="float:right;right:3px;top:0;position:absolute; color: white;cursor: pointer">X</div>';
                        alertMessage += '<center style="padding: 50px;margin-top:-100px"><br/><p style="color:white">To fully comply with the WordPress guidelines, we need to move the premium version of Stylish Cost Calculator onto a private server.<br/> Since you’ve purchased a premium license of SCC, you’ll need to <strong>download the premium</strong> plugin from our servers <br/>with the download button below and delete the <strong>free plugin </strong>version that you have now.<br/><br/>Our new licensing system is billed and renews annually, however, since you’ve been with us since the beginning, we’ve converted your current license to a lifetime license, you will never have to again and receive life-time of updates going forward.</p></center>'
                        //        alertMessage += '<center>'
                        alertMessage += '<div class="scc-col-offset-md-2"></div>'
                        alertMessage += '    <label class="scc_label" style="text-align: center; margin-left: 30%">'
                        alertMessage += '        <a style="pointer-events: auto; padding: 10px !important;color:white" class="scc_button save_button " href="https://members.stylishcostcalculator.com/zips/scc-premium.zip" target="_blank">Download Premium</a>'
                        alertMessage += '</label>'
                        alertMessage += '    <label class="scc_label" style="text-align: center; margin-left: 30%">'
                        alertMessage += '        <a style="pointer-events: auto; padding: 10px !important;" class="scc_button save_button " href="https://members.stylishcostcalculator.com/lost-password" target="_blank">Go to Members Area</a>'
                        alertMessage += '</label>'
                        alertMessage += '<center style="padding: 50px"><br/><p style="color:white;font-size:16px"><br/><br/>INSTRUCTIONS <br/><br/> You can then click "Download" and install your plugin. you can access the members area, <br/> which includes your license, invoice and download files by visiting https://members.stylishcostcalculator.com/ <br/>For new users, you will need to do the following: <br/><br/> 1. Click to reset password <br/> 2. Enter in the email you used to purchase the premium license. <br/><br/> Premium users from our old license system should follow the steps above too. <br/></p></center>'
                        //            alertMessage += '</center>'
                        alertMessage += '</div></div>'
                        jQuery(alertMessage, {
                            id: 'alert-message'
                        }).appendTo('body');
                        var $info = jQuery("#alert-message")
                        $info.dialog({
                            'width': 600,
                            'modal': true,
                            'autoOpen': true,
                            'closeOnEscape': true
                        });
                        $info.dialog('open')
                    }
                }

                function toggleShortCodes() {
                    if (jQuery('#email_form_short_codes_section').css('display') === 'none') {
                        jQuery('#email_form_short_codes_section').css('display', 'block')
                    } else {
                        jQuery('#email_form_short_codes_section').css('display', 'none')
                    }
                }

                function sccPDFSettings() {
                    jQuery('#scc_pdf_font_message').html('Saving... ');
                    jQuery('#scc_pdf_font_message').css('color', 'orange')
                    var sccPDFFont = jQuery('#pdf_font').children("option:selected").val();
                    var sccPDFDateFmt = jQuery('#pdf_datefmt').children("option:selected").val();
                    $fragment_refresh = {
                        url: rt_vars.rt_urlajax,
                        type: 'POST',
                        data: {
                            action: 'sccPDFSettings',
                            pdfSettings: {
                                sccPDFFont,
                                sccPDFDateFmt
                            }
                        },
                        success: function(data) {
                            jQuery('#scc_pdf_font_message').html('Saved successfully.');
                            jQuery('#scc_pdf_font_message').css('color', 'green')
                        },
                        error: function(err) {}
                    };
                    jQuery.ajax($fragment_refresh);
                }

                function sccSaveRecaptchaKeys() {
                    var msgElement = jQuery('#scc_recaptcha_message');
                    msgElement.html('Saving... ').css('color', 'orange');
                    // var sccPDFFont = jQuery('#pdf_font').children("option:selected").val()
                    var recaptchaKeys = jQuery('#recaptcha').find('input').serializeArray();
                    $fragment_refresh = {
                        url: rt_vars.rt_urlajax,
                        type: 'POST',
                        data: {
                            action: 'sccSaveRecaptchaKeys',
                            recaptchakeys: JSON.stringify(recaptchaKeys)
                        },
                        success: function(data) {
                            msgElement.html('Saved successfully.').css('color', 'green');
                        },
                        error: function(err) {
                            // msgElement.html('Saved successfully.').css('color', 'green');
                        }
                    };
                    jQuery.ajax($fragment_refresh);
                }

                function sscUploadSccBackup() {
                    jQuery('#scc_backup_message').html('Wait... Analyzing your file and uploading it...');
                    jQuery('#scc_backup_message').css('color', 'orange')
                    var formData = new FormData();
                    var files = jQuery('#backup_scc_file')[0].files[0];
                    formData.append('file', files);
                    formData.append('action', 'sscUploadSccBackup');
                    $fragment_refresh = {
                        url: rt_vars.rt_urlajax,
                        type: 'POST',
                        data: formData,
                        contentType: false,
                        processData: false,
                        success: function(data) {
                            jQuery('#scc_backup_message').html('SCC restored successfully.');
                            jQuery('#scc_backup_message').css('color', 'green')
                        }
                    };
                    jQuery.ajax($fragment_refresh);
                }

                function sccChangeDatabaseToUtf8() {
                    jQuery('#database_change_message').html('Wait... checking if database needs to change the chartset to support all languages...');
                    jQuery('#database_change_message').css('color', 'orange')
                    $fragment_refresh = {
                        url: rt_vars.rt_urlajax,
                        type: 'POST',
                        data: {
                            action: 'sccChangeDatabaseToUtf8'
                        },
                        success: function(data) {
                            jQuery('#database_change_message').html('Database is correct now.');
                            jQuery('#database_change_message').css('color', 'green')
                        }
                    };
                    jQuery.ajax($fragment_refresh);
                }

                function saveSCCEmailSetting() {
                    event.preventDefault();
                    var sendername = jQuery('#sendername').val();
                    var senderemail = jQuery('#senderemail').val();
                    <?php
                    if (get_option('scc_licensed') != 0) {
                    ?>
                        var messageform = jQuery('#messagetemplate').val();
                    <?php
                    } else {
                    ?>
                        var messageform = "Hello <customer-name>, <br><br> Attached to this email is a PDF file with that contains your quote. <br> If you have any further questions please call us email us here ____. <br> Sincerely,<br> Your Company Name<br><br> <hr><br> <b>Customer's Name</b> l <customer-name> <b>Customer's Phone</b> l <customer-phone> <b>Customer's Emai</b> l <customer-email> <b>Customer's IP</b> l <customer-ip-address> <b>Browser Info</b> l <customer-browser-info ><b>Device</b> l <device> <b> Referral </b> | <customer-referral>";
                    <?php
                    }
                    ?>
                    var sccemailfooter = jQuery('#sccemailfooter').val();
                    var scc_emailsubject = jQuery('#emailsubject').val();
                    var scc_email_banner_image = jQuery('#scc_email_banner_image').val();
                    var scc_email_logo_image = jQuery('#scc_email_logo_image').val()
                    var scc_email_send_copy = jQuery('#scc_email_send_copy').val();
                    if (location.protocol === 'https:') {
                        if (scc_email_banner_image) {
                            if (scc_email_banner_image.indexOf('http://') != -1) {
                                scc_email_banner_image = scc_email_banner_image.replace('http://', 'https://')
                            }
                        }
                        if (scc_email_logo_image) {
                            if (scc_email_logo_image.indexOf('http://') != -1) {
                                scc_email_logo_image = scc_email_logo_image.replace('http://', 'https://')
                            }
                        }
                    } else {
                        // is http
                    }
                    messageform = messageform.replace(/(\r\n|\n|\r)/gm, "<br>")
                    if (senderemail == '') {
                        alert('Sender Email is Mandatory. Please, add a valid email. Thank you ')
                    } else if (sendername == '') {
                        alert('Sender Name is Mandatory. Please, add a valid email. Thank you ')
                    } else if (scc_emailsubject == '') {
                        alert('Email subject is Mandatory. Please, add a valid email. Thank you ')
                    } else {
                        $fragment_refresh = {
                            url: rt_vars.rt_urlajax,
                            type: 'POST',
                            data: {
                                action: 'sccSaveEmailSettings',
                                sender_name: sendername,
                                sender_email: senderemail,
                                emailsubject_testing: scc_emailsubject,
                                scc_email_send_copy: scc_email_send_copy,
                                message_form: messageform,
                                sccemailfooter: sccemailfooter
                            },
                            success: function(data) {
                                jQuery(".scc_save_emdl").removeClass('scc_save_flash');
                                jQuery('#savingemailresult').html('Email Quote & Detailed List has been saved!').show();
                                jQuery('#savingemailresult').hide(3000);
                            }
                        };
                        jQuery.ajax($fragment_refresh);
                    }
                }
                handleCurrencyCoversionMode();

                function handleCurrencyCoversionMode() {
                    jQuery('#settingsuccs').html('');
                    jQuery('#currency_conversion_incompatibility_message').html('')
                    if (jQuery('#scc_currency_coversion_mode').val() != 'manual_selection') {
                        jQuery('#scc_currency_coversion_manual_selection_container').css('display', 'none')
                        jQuery('#scc_currency_coversion_manual_selection_container').parent().css('height', 290)
                    } else {
                        jQuery('#scc_currency_coversion_manual_selection_container').css('display', 'block')
                        jQuery('#scc_currency_coversion_manual_selection_container').parent().css('height', 350)
                    }
                }
                handleCurrency()

                function handleCurrency() {
                    if (jQuery('#currency_code').val() == 'AED' ||
                        jQuery('#currency_code').val() == 'COP' ||
                        jQuery('#currency_code').val() == 'ANG' ||
                        jQuery('#currency_code').val() == 'PKR' ||
                        jQuery('#currency_code').val() == 'TWD' ||
                        jQuery('#currency_code').val() == 'ZMW' ||
                        jQuery('#currency_code').val() == 'CFA') {
                        jQuery('#currency_conversion_incompatibility_message').html('The current selected currency is not supported for the "Currency conversion feature"')
                        jQuery('#scc_currency_coversion_global_container').css('display', 'none')
                    } else {
                        jQuery('#currency_conversion_incompatibility_message').html('')
                        jQuery('#scc_currency_coversion_global_container').css('display', 'inline')
                    }
                }

                function saveSCCSettings() {
                    var scc_currency_coversion_mode = jQuery('#scc_currency_coversion_mode').val()
                    var scc_currency_coversion_manual_selection = jQuery('#scc_currency_coversion_manual_selection').val()
                    if (scc_currency_coversion_mode == 'off' || scc_currency_coversion_mode == 'auto_detect') {
                        scc_currency_coversion_manual_selection == ''
                    }
                    if (scc_currency_coversion_manual_selection === '' && scc_currency_coversion_mode === "manual_selection") {
                        alert('You have selected CURRENCY CONVERSION - MANUAL SELECTION, but you didn\'t select any currency from the list')
                    } else {
                        $fragment_refresh = {
                            url: rt_vars.rt_urlajax,
                            type: 'POST',
                            data: {
                                action: 'sccSaveSettings',
                                currency_code: jQuery('#currency_code').val(),
                                currency_text: jQuery('#currency_code  option:selected').text(),
                                currency_style: jQuery('#currency-style').val(),
                                scc_currency_coversion_mode: scc_currency_coversion_mode,
                                scc_currency_coversion_manual_selection: scc_currency_coversion_manual_selection,
                                color_scheme: jQuery('#color_scheme').val(),
                                scc_fonttype: jQuery('#scc_fonttype').val(),
                                scc_colorscheme: jQuery('#scc_colorscheme').val(),
                                sccfontsize: jQuery('#scc-font-size').val(),
                                sccsizetype: jQuery('#scc-sizetype').val()
                            },
                            success: function(data) {
                                jQuery('#scc_currency_coversion_manual_selection_container').parent().css('height', 370)
                                jQuery('#settingsuccs').html('Settings have been successfully changed');
                                jQuery('#settingsuccs').css('color', 'green')
                            }
                        };
                        jQuery.ajax($fragment_refresh);
                    }
                }
                // scc email and detailed list flash settings
                jQuery("#sccemailfooter").keypress(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#scc_email_banner_image").change(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#scc_email_logo_image").change(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#sendername").keypress(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#senderemail").keypress(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#emailsubject").keypress(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#messagetemplate").keypress(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery("#messagetemplate").change(function() {
                    jQuery(".scc_save_emdl").addClass('scc_save_flash');
                });
                jQuery('.blocked').each(function(index, ob) {
                    jQuery(ob).css('backgroundColor', 'black')
                    jQuery(ob).css('opacity', 0.5)
                    jQuery(ob).css('display', 'inline-block')
                    jQuery(ob).css('position', 'relative')
                    var alertMessage = '<div style="position:absolute;left:0px;right:0px;top:0px;bottom:0px;z-index:99999;opacity:1">'
                    alertMessage += '    <center><h5 style="color:white;margin-top:50px">THIS FEATURE IS AVAILABLE IN THE PREMIUM VERSION</h5></center>'
                    alertMessage += '    <div style="margin-left:40%;margin-top:20px;background-color:#314af3;padding:5px;max-width:100px;text-align:center">'
                    alertMessage += '        <a  target="_blank" href="https://stylishcostcalculator.com/" style="z-index:99999;opacity:1; color: white">BUY NOW'
                    alertMessage += '        </a>'
                    alertMessage += '    </div>'
                    alertMessage += '</div>'
                    jQuery(ob).prepend(alertMessage)
                })

                function updateStripeKey() {
                    var keyInputVal = {
                        privKey: jQuery('[name="stripe-api-priv-key"]').val(),
                        pubKey: jQuery('[name="stripe-api-pub-key"]').val()
                    };
                    jQuery.ajax({
                        url: rt_vars.rt_urlajax,
                        type: 'POST',
                        data: {
                            action: 'scc_set_stripe_key',
                            data: keyInputVal
                        },
                        beforeSend: function(xhr) {
                            jQuery('#scc_stripekey_message').text('Saving...').css({
                                color: 'orange'
                            });
                        },
                        success: function(data) {
                            jQuery('#scc_stripekey_message').text('Saved Successfully!').css({
                                color: 'green'
                            });
                        }
                    });
                }
            </script>
        <?php
        $html_1 = ob_get_clean();
        echo $html_1;
    }
    function include_license_settings()
    {
        $license_settings = SCC_DIR . '/license-settings.php';
        if (file_exists($license_settings)) {
            include_once $license_settings;
            return true;
        } else {
            return 'cannot find the license-settings.php file in folder ' . SCC_DIR;
        }
    }
    function deactivateLicense($opt)
    {
        update_option('scc_licensed', 0);
        update_option('scc_license_key', "");
    }
    function update_opt($opt)
    {
        update_option('scclk_opt', $opt);
    }
    function activate($key)
    {
        ob_start();
        if (!empty($key)) {
            $license_data = $this->get_license_data($key, 'slm_activate');
            if (isset($license_data->result)) {
                if ($license_data->result == 'success') { //Success was returned for the license activation
                    // update_option('sample_license_key', '');
                    $opt = get_object_vars($license_data);
                    $this->update_opt($opt);
                    update_option('scc_licensed', 1);
                    update_option('scclk_opt', 1);
                    return '<p style="color:green;"> Ok: This ' . $license_data->message . '</p>';
                }
                if ($license_data->result == 'error') {
                    //Uncomment the followng line to see the message that returned from the license server
                    return '<p style="color:red;"> Error: ' . $license_data->message . '</p>';
                }
            } else {
                return $license_data;
            }
        } else {
            $this->update_opt('');
            return 'The license key is empty';
        }
        $_REQUEST['option_page'];
    }
    function deactivate($key)
    {
        if (!empty($key)) {
            $license_data = $this->get_license_data($key, 'slm_deactivate');
            if (isset($license_data->result)) {
                if ($license_data->result == 'success') { //Success was returned for the license activation
                    // update_option('sample_license_key', '');
                    $opt = get_object_vars($license_data);
                    $this->update_opt($opt);
                    update_option('scc_licensed', 0);
                    update_option('scc_license_key', "");
                    update_option('scclk_opt', '');
                    return '<p style="color:green;"> Ok: ' . $license_data->message . '</p>';
                } else {
                    //Uncomment the followng line to see the message that returned from the license server
                    update_option('scc_licensed', 0);
                    update_option('scc_license_key', "");
                    update_option('scclk_opt', '');
                    return '<p style="color:red;"> Error: ' . $license_data->message . '</p>';
                }
            } else {
                update_option('scc_licensed', 0);
                update_option('scc_license_key', "");
                update_option('scclk_opt', '');
                return $license_data;
            }
        } else {
            $this->deactivateLicense();
            $this->update_opt('');
            return 'The license key is empty';
        }
        $_REQUEST['option_page'];
    }
    function get_license_data($key, $action)
    {
        $include_license = $this->include_license_settings();
        if ($include_license !== true) {
            return $include_license;
        }
        // API query parameters
        $api_params = array(
            'slm_action' => $action,
            'secret_key' => SCC_SPECIAL_SECRET_KEY,
            'license_key' => $key,
            'registered_domain' => $_SERVER['SERVER_NAME'],
            'item_reference' => urlencode(SCC_ITEM_REFERENCE),
            // 'secret_key' => YOUR_SPECIAL_SECRET_KEY,
            // 'license_key' => $license_key,
            // 'registered_domain' => $_SERVER['SERVER_NAME'],
            // 'item_reference' => urlencode(YOUR_ITEM_REFERENCE),
        );
        // Send query to the license manager server
        $query = esc_url_raw(add_query_arg($api_params, SCC_LICENSE_SERVER_URL));
        $response = wp_remote_get($query, array('timeout' => 20, 'sslverify' => false));
        // Check for error in the response
        if (is_wp_error($response)) {
            return "Unexpected Error! The query returned with an error.";
        }
        // License data.
        $license_data = json_decode(wp_remote_retrieve_body($response));
        return $license_data;
    }
    //Add Help Content //
    function help_page()
    {
        wp_enqueue_script('scc-bootstrap-min');
        include_once SCC_DIR . '/admin/logo-header.php';
        ?>
            <link rel="preconnect" href="https://fonts.gstatic.com">
            <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
            <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> -->
            <p>
                <style>
                    .scc_title_bar {
                        background: #314af3;
                        padding: 15px;
                        margin-left: -23px;
                        font-size: 22px;
                        color: #fff;
                        letter-spacing: 1px;
                        text-transform: uppercase;
                        width: 105%;
                        margin-bottom: 40px;
                        margin-top: 10px;
                    }
                </style>
            <div class="scc_title_bar">Help, Tutorials & Videos</div>
            <div style="text-align: center;">
                <div class="col-md-12 col-xs-12 custom-btn-scc-top" style="margin-top:10px;min-height:800px;">
                    <!---<div class="col-sm-4 col-md-3">
                    <a href="https://www.facebook.com/designful" target="_blank" class="button button-primary video_tutorial_btn">FaceBook Message</a>
                </div>--->
                    <div class="col-sm-4"><label class="scc_label" style="text-align: left;">
                            <a class="scc_button" href="https://stylishcostcalculator.com/templates/web-developer-calculator/" target="_blank">Live Demos + One-Click Templates</a>
                        </label></div>
                    <div class="col-sm-4"><label class="scc_label" style="text-align: left;">
                            <a class="scc_button" href="https://stylishcostcalculator.com/support/" target="_blank">Submit A Ticket</a>
                        </label></div>
                    <div class="col-sm-4" style="clear: both;"><label class="scc_label" style="text-align: left;clear: both;">
                            <a class="scc_button" href="https://designful.freshdesk.com/support/solutions/folders/48000657938" target="_blank">Video Tutorials</a>
                        </label></div>
                    <div class="col-sm-4"><label class="scc_label" style="text-align: left;">
                            <a class="scc_button" href="https://designful.freshdesk.com/support/solutions/folders/48000658562" target="_blank">User Guides</a>
                        </label></div>
                    <br>
                </div>
            </div>
            <br><br>
            <!--  <iframe src="https://designful.ca/spl-support/#splsupportid" scrolling="no" width="90%" height="400px" align="center" ></iframe>-->
            </p>
            </div>
            <?php
            include_once SCC_DIR . '/admin/logo-footer.php';
            ?>
            </div>
        <?php
    } // End Help Content
    function license_info_page()
    {
        // wp_register_script('scc-bootstrap-min', SCC_URL . 'assets/lib/bootstrap-3.4.1/dist/js/bootstrap.min.js', array('jquery'), STYLISH_COST_CALCULATOR_PREMIUM_VERSION, true);
        // wp_register_style('scc-bootstrap-min', SCC_URL . 'assets/lib/bootstrap-3.4.1/dist/css/bootstrap.min.css');
        // wp_enqueue_script('scc-bootstrap-min');
        // wp_enqueue_style('scc-bootstrap-min');
        include_once SCC_DIR . '/admin/logo-header.php';
        ?>
            <link rel="preconnect" href="https://fonts.gstatic.com">
            <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
            <br />
            <br />
            <div class="row">
                <div id="primary" class="container-fluid medium-8 columns content-area">
                    <main id="main" class="site-main" role="main">
                        <article id="post-116" class="post-116 page type-page status-publish hentry">
                            <div class="entry-content" style="padding:20px;background-color: #f9f9fe;width:700px;">
                                <h1 style="font-size:20px;">Premium License</h1>
                                <p>Login to the <a href="https://members.stylishcostcalculator.com/licenses/" target="_blank">Member's Portal</a> to get your license</p>
                            </div><!-- .entry-content -->
                        </article><!-- #post-## -->
                        <article id="post-117" class="post-117 page type-page status-publish hentry" style="margin-top:30px;">
                            <div class="entry-content" style="padding:20px;background-color: #f9f9fe;width:700px;">
                                <h1 style="font-size:20px;">Invoice</h1>
                                <p>Login to the <a href="https://members.stylishcostcalculator.com/orders/" target="_blank">Member's Portal</a> to download your receipt for purchasing the Stylish Cost Calculator Premium plugin.</p>
                            </div><!-- .entry-content -->
                        </article><!-- #post-## -->
                        <article id="post-119" class="post-119 page type-page status-publish hentry" style="margin-top:30px;">
                            <div class="entry-content" style="padding:20px;background-color: #f9f9fe;width:700px;">
                                <h1 style="font-size:20px;">Change Payment Method / Cancel Subscription</h1>
                                <p>Login to the <a href="https://designful.onfastspring.com/account" target="_blank">FastSpring Member's Portal</a> to change your method of payment regarding your yearly subcription for the premium license.</p>
                            </div><!-- .entry-content -->
                        </article><!-- #post-## -->
                        </article><!-- #post-## -->
                        <article id="post-117" class="post-117 page type-page status-publish hentry" style="margin-top:30px;">
                            <div class="entry-content" style="padding:20px;background-color: #f9f9fe;width:700px;">
                                <h1 style="font-size:20px;">Manual Update</h1>
                                <p>If you want the latest version, we upload it daily <a href="https://members.stylishcostcalculator.com/zips/scc-premium.zip" target="_blank">here</a>. This will download the zip file manually, and you will need to disable and delete the current version (your work is safe), then install the newest file. We only push it to the WordPress plugins page once a month, to avoid bugging users too much. </p>
                            </div><!-- .entry-content -->
                        </article><!-- #post-## -->
                        <article id="post-118" class="post-118 page type-page status-publish hentry" style="margin-top:30px;">
                            <div class="entry-content" style="padding:20px;background-color: #f9f9fe;width:700px;">
                                <h1 style="font-size:20px;">Upgrading from The Free Version</h1>
                                <p><br>Step 1. Disable then <b>Delete</b> the <a href="http://prntscr.com/qstrct" target="_blank">free version</a> of the Stylish Cost Calculator.<br>
                                    Your existing calculators are always safe in your database and will not be deleted from disabling or deleting the pluigin.
                                    <br><br>Step 2. Download the premium version of Stylish Cost Calculator zip <a href="https://members.stylishcostcalculator.com/zips/scc-premium.zip">file here</a><br><br>Step 3. Upload ‘Stylish Cost Calculator <strong>Premium</strong>‘ version to WordPress<br><br>Step 4. Activate a new premium version of the Stylish Cost Calculator, <a target="_blank" href="http://prntscr.com/qstsay">shown</a>&nbsp;here.<br><br>Step 5. Enter new license code by clicking ‘<a target="_blank" href="http://prntscr.com/qstsxi">License</a>‘, then entering code in the <a target="_blank" href="http://prntscr.com/qsttdv">activation box</a>.
                                </p>
                                <p>Still having troubles? Send us a message for support https://stylishcostcalculator.com/support/</p>
                            </div><!-- .entry-content -->
                        </article><!-- #post-## -->
                    </main><!-- #main -->
                </div><!-- #primary -->
                <div id="secondary" class="medium-4 columns widget-area" role="complementary">
                </div><!-- #secondary -->
            </div>
            <style>
                body {
                    font-family: 'Poppins';
                }
            </style>
        <?php
    }
    // Start Video Content
    function video_page()
    {
        include_once SCC_DIR . '/admin/logo-header.php';
        ?>
            <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> -->
            <h1 style="height:1px; margin:0px; padding:0px;"></h1>
            <h2>Stylish Cost Calculator: Video Tutorials </h2>
            <div class="youtube_video">
            </div>
        <?php
    }
    function admin_menu()
    {
        add_submenu_page('scc-tabs', __('Help', 'stylishpl'), __('Help & Videos', 'stylishpl'), 'manage_options', 'stylish_cost_calculator_help', array($this, 'help_page'));
        //    add_submenu_page( 'scc-tabs', __( 'Video Tutorials', 'stylishpl' ), __( 'Video Tutorials', 'stylishpl' ), 'manage_options', 'stylish_cost_calculator_video', array( $this, 'video_page' ) );
        add_submenu_page('scc-tabs', __('LicenseHelp', 'stylishpl'), __('Members Portal', 'stylishpl'), 'manage_options', 'stylish_cost_calculator_license_help', array($this, 'license_info_page'));
        add_submenu_page('scc-tabs', __('Settings', 'stylishpl'), __('Global Settings', 'stylishpl'), 'manage_options', 'stylish_cost_calculator_settings', array($this, 'option_page'), 90);
    }
    /**
     * HTML for email template banner and logo
     */
    private function email_template_banner_and_logo()
    {
        $disclaimer = wp_kses_post(get_option('scc_footerdisclaimer'));
        $banner_image = get_option('scc_email_banner_image', false);
        $logo_image = get_option('scc_email_logo_image', false);
        ?>
            <h2 class="scc-settings-card-title"><span class="highlighted">EMAIL, PDF & DETAILED LIST</span> SETTINGS <a href="https://designful.freshdesk.com/a/solutions/articles/48001167920" target="_blank"><i class="fa fa-book" aria-hidden="true"></i></a></h2>
            </span>
            <div class="scc-settings-card-inner" id="scc_email_quote_settings">
                <div class="scc-form-field">
                    <label for="sccemailfooter">Footer/Disclaimer Notes</label>
                    <textarea class="scc-textarea-field" placeholder="" id="sccemailfooter" rows="14"><?php echo str_replace('\\', '', stripslashes($disclaimer)); ?></textarea>
                </div>
                <div class="scc-form-field">
                    <label>Banner</label>
                    <div class="scc-media-uploader-buttons" style="display: <?php echo $banner_image ? 'none' : 'block'; ?>;">
                        <input type="button" class="sccbutton scc-media-upload-button" value="Upload Banner">
                        <input type="hidden" name="scc_email_banner_image" class="scc-media-upload-field" value="<?php echo esc_attr($banner_image); ?>">
                        <span class="spinner"></span>
                    </div>
                    <div class="scc-media-uploader-image" style="display: <?php echo $banner_image ? 'block' : 'none'; ?>;">
                        <?php
                        if ($banner_image) {
                            echo '<img src="' . esc_attr($banner_image) . '" />';
                        }
                        ?>
                        <span class="scc-media-uploader-remove">&times;</span>
                    </div>
                </div>
                <div class="scc-form-field">
                    <label>Logo</label>
                    <div class="scc-media-uploader-buttons" style="display: <?php echo $logo_image ? 'none' : 'block'; ?>;">
                        <input type="button" class="sccbutton scc-media-upload-button" value="Upload Logo">
                        <input type="hidden" name="scc_email_logo_image" class="scc-media-upload-field" value="<?php echo esc_attr($logo_image); ?>">
                        <span class="spinner"></span>
                    </div>
                    <div class="scc-media-uploader-image" style="display: <?php echo $logo_image ? 'block' : 'none'; ?>;">
                        <?php
                        if ($logo_image) {
                            echo '<img src="' . esc_attr($logo_image) . '" />';
                        }
                        ?>
                        <span class="scc-media-uploader-remove">&times;</span>
                    </div>
                </div>
            </div>
    <?php
    }
}
$stylish_cost_calculator_settings = new Stylish_Cost_Calculator_Settings();
    ?>