<?php

/*
 * ==========================================================
 * ADMINISTRATION PAGE
 * ==========================================================
 *
 */

define('CRPAY_CLOUD', file_exists(__DIR__.'/cloud'));
$installation = false;
if (!CRPAY_CLOUD) {
    if (!file_exists(__DIR__.'/config.php')) {
        $installation = true;
        $file = fopen(__DIR__.'/config.php', 'w');
        fwrite($file, "<?php if ( ! defined('CRPAY_URL') ) define('CRPAY_URL', ''); ?>");
        fclose($file);
    }
    require __DIR__.'/functions.php';
    if (!defined('CRPAY_USER')) {
        $installation = true;
    }
}

$minify = $installation || (isset($_GET['debug']) && !wp_verify_nonce( $_GET['debug'], 'debug' )) ? false : (CRPAY_CLOUD || bxc_settings_get('minify'));

function bxc_box_installation() { ?>
    <div class="bxc-main bxc-installation bxc-box">
        <form>
            <div class="bxc-info"></div>
            <div class="bxc-top">
                <img src="<?php echo ('media/logo.webp'); ?>" />
                <div class="bxc-title">
                    Installation
                </div>
                <div class="bxc-text">
                    Please complete the installation process.
                </div>
            </div>
            <div id="user" class="bxc-input">
                <span>
                    Username
                </span>
                <input type="text" required />
            </div>
            <div id="password" class="bxc-input">
                <span>
                    Password
                </span>
                <input type="password" required />
            </div>
            <div id="password-check" class="bxc-input">
                <span>
                    Repeat password
                </span>
                <input type="password" required />
            </div>
            <div id="db-name" class="bxc-input">
                <span>
                    Database name
                </span>
                <input type="text" required />
            </div>
            <div id="db-user" class="bxc-input">
                <span>
                    Database user
                </span>
                <input type="text" required />
            </div>
            <div id="db-password" class="bxc-input">
                <span>
                    Database password
                </span>
                <input type="password" />
            </div>
            <div id="db-host" class="bxc-input">
                <span>
                    Database host
                </span>
                <input type="text" placeholder="Default" />
            </div>
            <div id="db-port" class="bxc-input">
                <span>
                    Database port
                </span>
                <input type="number" placeholder="Default" />
            </div>
            <div class="bxc-bottom">
                <div id="bxc-submit-installation" class="bxc-btn">
                    Complete installation
                </div>
            </div>
        </form>
    </div>
<?php } ?>

<?php function bxc_box_login()
{
    bxc_colors_admin();
    bxc_load_custom_js_css(); ?>
    <div class="bxc-main bxc-login bxc-box">
        <form>
            <div class="bxc-info"></div>
            <div class="bxc-top">
                <img src="<?php echo (bxc_settings_get('logo-admin') ? bxc_settings_get('logo-url', CRPAY_URL.'media/logo.webp') : 'media/logo.webp'); ?>" />
                <div class="bxc-title">
                    <?php echo (bxc_('Sign into')); ?>
                </div>
                <div class="bxc-text">
                    <?php echo (bxc_('To continue to').' '.bxc_settings_get('brand-name', 'Cryptopayment')); ?>
                </div>
            </div>
            <div id="username" class="bxc-input">
                <span>
                    <?php echo (bxc_('Username')); ?>
                </span>
                <input type="text" required />
            </div>
            <div id="password" class="bxc-input">
                <span>
                    <?php echo (bxc_('Password')); ?>
                </span>
                <input type="password" required />
            </div>
            <?php
            if (bxc_settings_get('two-fa-active')) {
                echo '<div id="two-fa" class="bxc-input"><span>'.(bxc_('Verification code')).'</span><input type="password" required /></div>';
            } ?>
            <div class="bxc-bottom">
                <div id="bxc-submit-login" class="bxc-btn">
                    <?php echo (bxc_('Sign in')); ?>
                </div>
            </div>
        </form>
    </div>
<?php
} ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
    <title>
        <?php echo (CRPAY_CLOUD && !bxc_verify_admin() ? bxc_settings_get('brand-name', CLOUD_NAME).' | Login' : bxc_('Admin').' | '.(CRPAY_CLOUD ? CLOUD_NAME : bxc_settings_get('brand-name', 'Cryptopayment'))); ?>
    </title>
    <script><?php echo (bxc_settings_js_admin()); ?></script>
    <script src="<?php echo (CRPAY_URL.'js/client'.($minify ? '.min' : '').'.js?v='.CRPAY_VERSION); ?>"></script>
    <script src="<?php echo (CRPAY_URL.'js/admin'.($minify ? '.min' : '').'.js?v='.CRPAY_VERSION); ?>"></script>
    <link rel="stylesheet" href="<?php echo (CRPAY_URL.'css/admin.css?v='.CRPAY_VERSION); ?>" media="all" />
    <link rel="shortcut icon" type="image/svg" href="<?php echo (CRPAY_CLOUD ? CLOUD_ICON : (bxc_settings_get('logo-admin') ? bxc_settings_get('logo-icon-url', CRPAY_URL.'media/icon-18x18.png') : CRPAY_URL.'media/icon-18x18.png')); ?>" />
</head>
<body>
    <?php
    require __DIR__.'/admin_code.php';
    if ($installation) {
        bxc_box_installation();
    } elseif (bxc_verify_admin()) {
        bxc_box_admin();
    } else {
        if (CRPAY_CLOUD) {
            require __DIR__.'/cloud/registration.php';
            bxc_cloud_registration_login_box();
        } else {
            bxc_box_login();
        }
    }
    ?>
</body>
</html>
