<?php
/**
 *
 * @link       info@meteosales.com
 * @since      1.0.6
 *
 * @package    Meteosales
 * @subpackage Meteosales/admin/partials
 */
/*
Version: 1.0.16
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    wp_enqueue_style( 'meteosales-bootstrap-min-css' );
    wp_enqueue_style( 'meteosales-admin-css' );
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {//if woocommerce is activated

    global $wpdb;
    $ok = false;
   $no_token = false;
    if(isset($_POST["update_settings"])){
        $b_id = sanitize_text_field($_POST["banner_id"]);
        $b_class= sanitize_text_field($_POST["banner_class"]);
        $array = array("id"=>$b_id,"class"=>$b_class);

        update_option( "MeteoCommerceBannerSetting", json_encode($array) );
        $ok = true;
    }
    $sort = get_option("MeteoCommerceProductsSetting");

    if(!$sort){//if Get_Option does not exist
        $token  = "";
        $syncro_type = "manual";
        $no_token = true;
    }
    else{
        $arr_sort = json_decode($sort, true);
        $token = $arr_sort["token"];
        if($token == ""){
            $no_token = true;
        }
    }
    $b_sort = get_option("MeteoCommerceBannerSetting");
    if(!$b_sort){//if Get_Option does not exist
        $banner_id  = "";
        $banner_class  = "";
    }
    else{
        $arr_b_sort = json_decode($b_sort, true);
        $banner_id  = $arr_b_sort["id"];
        $banner_class  = $arr_b_sort["class"];
    }

    ?>
    <style>
        html body { background-color: #F1F1F1; }

        .bold{font-weight: bold}

        .bold {
   font-weight: bold;
}
            /* Rounded sliders */
            .slider.round { border-radius: 34px; }
            .slider.round:before { border-radius: 50%; }
        </style>
    <div class="container">
        <div class="wrap">
            <div class="my-4">
                <img  src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . '/images/meteosales.svg'; ?>" style="width:350px"><br>
		    </div>
            <hr>
            <div class="pdgDisplayMessage"><?php
                if($ok){
                    ?><div class="alert alert-success alert-dismissible">
                        <?php echo _e( 'Settings Updated', 'meteosales' ); ?>
                    </div> <?php
                }
                if($no_token){
                    ?><div class="alert alert-danger">
                        <?php echo _e( 'No token found. Please insert it in Settings', 'meteosales' ); ?>
                    </div> <?php
                }?>
                </div>
            <div id="poststuff">
            <div class="container postbox">
                <h3 class="wp-heading-inline h1-type" style="margin-top: 0.5rem;"><?php echo _e( 'Banner Settings', 'meteosales' ); ?></h3>
                <div class="row">
                    <div class="col meta-box-sortables ui-sortable">
                        <div id="surgery_info_box" style="padding:10px;">
                            <form name="Adds" id="Adds" method="POST" >
                                <p><?php echo _e( 'How banner works', 'meteosales' ); ?></p>
                                <p><?php echo _e( 'Insert the same ID or class here and on the page to display the banner', 'meteosales' ); ?></p>
                                <div class="my-3" style="display:flex;">
                                    <div style="margin-right:10px;" >
                                        <label><strong><?php echo _e( 'ID', 'meteosales' ); ?></strong></label>
                                    </div>
                                    <div style="margin-right:10px;">
                                        <input type="text" id="banner_id" name="banner_id" onkeypress="clsAlphaNoOnly(event)"  value="<?= $banner_id ?>">
                                    </div>
                                    <div style="margin-right:10px;">
                                        <label><strong><?php echo _e( 'Class', 'meteosales' ); ?></strong></label>
                                    </div>
                                    <div>
                                        <input type="text" id="banner_class" name="banner_class" onkeypress="clsAlphaNoOnly(event)" value="<?= $banner_class ?>" >
                                    </div>
                                </div>
                                <div>
                                    <input type="submit" id="update_settings" name="update_settings" class="button button-primary button-large" value="<?php echo _e( 'Update', 'meteosales' ); ?>" />
                                </div>

                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function clsAlphaNoOnly (e) {  // Accept only alpha numerics, no special characters
            var regex = new RegExp("^[a-zA-Z0-9]+");
            var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
            if (regex.test(str)) {
                return true;
            }
            e.preventDefault();
            return false;
        }
    </script>
     <?php
}else{ ?>
    <style>
        html body { background-color: #F1F1F1; }
    </style>
    <div class="container">
        <div class="wrap">
            <div class="my-4">
                <img  src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . '/images/meteosales.svg'; ?>" style="width:350px"><br>
                <h3 class="wp-heading-inline h1-type"><?php echo _e( 'Banner Settings', 'meteosales' ); ?></h3>
		    </div>
            <hr>
            <div class="pdgDisplayMessage">
                <div class="alert alert-danger alert-dismissible">
                    <?php echo _e( 'Sorry! This plugin works only with Woocommerce', 'meteosales' ); ?>
                </div>
            </div>
        </div>
    </div><?php
}

$plugin_data = get_plugin_data( __FILE__  );

echo '<script type="text/javascript">
        jQuery(document).ready(function(){
            document.getElementById("footer-left").innerHTML = "";
            document.getElementById("footer-upgrade").innerHTML = "'.__( 'v ', 'meteosales' ) .  $plugin_data['Version'].'";

        });
</script>';?>
