<?php
if(!defined('ABSPATH')){
    exit; // Exit if accessed directly
}
?>

<form method="post" action="options.php" id="" class="egps_license_options">

<?php 
    settings_fields( 'egps_license_data' );
    do_settings_sections( 'egps_license_data' ); 

    $egps_license_options = get_option('egps_license_options');

?>


<h3>EGPS plugin license key (Premium features)</h3>

    <p>
    To sell photos on your website with EGPS (EGPS - Easy Sell for Google Photo) plugin, you must have a valid license key. 
    <br>Please enter the API and license keys you received when purchasing the license into the fields below.
    </p>
    <p>
        After purchasing a license, to generate the keys below you have to use the following URL, 
        <span style="color: red;">Your website URL: 
        <br><b></span> <?php echo esc_html(site_url()); ?></b></p>
    <p>
    For more information and to purchase a license key, please visit our website at 
    <a href="https://feldvebel.hu/selmlicenses" target="_blank">feldvebel.hu</a>
    </p>

    <?php 

        $dcrypted = new EgpsAuthenticate;
        $url_str = $dcrypted->egps_auth_siteurl();

        if(is_array($egps_license_options)){
            $dec_key = $dcrypted->egps_decrypt_key(
                    $egps_license_options['egps_license_key'], 
                    $egps_license_options['egps_api_key']
            );

        }else{
            $egps_license_options = array(
                "egps_license_key" => "",
                "egps_api_key"      => ""
            );
            $dec_key[0] = null;
        }

            
        if($dec_key[0] != $url_str){
            echo '<div class="btn btn-danger">Your API key is invalid for this URL.</div>';
        }

        if( !isset($dec_key[1]) || $dec_key[1] == null || !Egps::egps_check_date($dec_key[1]) ){

            echo '<div class="btn btn-danger">Your subscription has expired.</div>';

        }else{

            $darr = explode("-", $dec_key[1]);
            $dateout = date("F j, Y", mktime(0, 0, 0, $darr[1], $darr[2], $darr[0]));

            echo '<div class="btn btn-info">Your subscription is valid until '. esc_html($dateout) .'</div>';

        }


    ?>
    
    <table class="form-table" role="presentation">
        <tbody>

            <tr>
                <th scope="row">EGPS API key</th>
                <td>
                    <textarea 
                        rows="2" cols="50"
                        type="text" 
                        class="egps_admin_fields_500 egps_remove_space" 
                        name="egps_license_options[egps_api_key]" 
                        value=""><?php echo esc_html($egps_license_options['egps_api_key']); ?></textarea>                  
                </td>
            </tr>

            <tr>
                <th scope="row">EGPS license key</th>
                <td>
                    <textarea 
                        rows="2" cols="50"  
                        type="text" 
                        class="egps_admin_fields_500 egps_remove_space" 
                        name="egps_license_options[egps_license_key]" 
                        value=""><?php echo esc_html($egps_license_options['egps_license_key']); ?></textarea>               
                </td>
            </tr>

        </tbody>
    </table>

    <?php submit_button(); ?>

</form>


