<?php
@session_start();

$config_ini = parse_ini_file('./config.ini');

$db = new SQLite3('./api/.db.db');
$db->exec('CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY,username TEXT ,password TEXT)');

$log_check = $db->query('SELECT * FROM users WHERE id=\'1\'');
$roe = $log_check->fetchArray();
$loggedinuser = @$roe['username'];

if (isset($_SESSION['name']) === $loggedinuser) {
    header('location: dns.php');
}

$rows = $db->query('SELECT COUNT(*) as count FROM users');
$row = $rows->fetchArray();
$numRows = $row['count'];

if ($numRows == 0) {
    $db->exec('INSERT INTO users(id ,username, password) VALUES(\'1\' ,\'admin\', \'admin\')');
    $db->close();
}

if (isset($_POST['login'])) {
    if (!$db) {
        echo $db->lastErrorMsg();
    }

    $sql = 'SELECT * from users where username="' . $_POST['username'] . '";';
    $ret = $db->query($sql);

    while ($row = $ret->fetchArray()) {
        $id = $row['id'];
        $username = $row['username'];
        $password = $row['password'];
    }

    if ($id != '') {
        if ($password == $_POST['password']) {
            session_regenerate_id();
            $_SESSION['loggedin'] = true;
            $_SESSION['name'] = $_POST['username'];

            if ($_POST['username'] == 'admin') {
                header('Location: user.php');
            } else {
                header('Location: dns.php');
            }
        } else {
            header('Location: ./api/index.php');
        }
    } else {
        header('Location: ./api/index.php');
    }

    $db->close();
}

echo '<!DOCTYPE html>' . "\r\n";
echo '<html lang="en">' . "\r\n";
echo '<head>' . "\r\n";
echo '    <meta charset="utf-8">' . "\r\n";
echo '    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">' . "\r\n";
echo '    <meta name="author" content="WCTV APPS.">' . "\r\n";
echo '    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">' . "\r\n";
echo '    <link rel="stylesheet" href="./css/css.css">' . "\r\n";
echo '    <title>IBO 26 TEMAS</title>' . "\r\n";
echo '    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">' . "\r\n";
echo '</head>' . "\r\n";
echo '<style>' . "\r\n";
echo '    html, body {' . "\r\n";
echo '        height: 100%;' . "\r\n";
echo '        margin: 0;' . "\r\n";
echo '    }' . "\r\n";
echo '    body {' . "\r\n";
echo '        color: #fff;' . "\r\n";
echo '        font-family: Arial, sans-serif;' . "\r\n";
echo '        height: 100vh;' . "\r\n";
echo '        margin: 0;' . "\r\n";
echo '        display: flex;' . "\r\n";
echo '        justify-content: center;' . "\r\n";
echo '        align-items: center;' . "\r\n";
echo '        background: linear-gradient(45deg, #6a11cb, #2575fc);' . "\r\n";
echo '        background-size: 400% 400%;' . "\r\n";
echo '        animation: gradientAnimation 5s ease infinite;' . "\r\n";
echo '    }' . "\r\n";
echo '    @keyframes gradientAnimation {' . "\r\n";
echo '        0% {' . "\r\n";
echo '            background-position: 0% 50%;' . "\r\n";
echo '        }' . "\r\n";
echo '        50% {' . "\r\n";
echo '            background-position: 100% 50%;' . "\r\n";
echo '        }' . "\r\n";
echo '        100% {' . "\r\n";
echo '            background-position: 0% 50%;' . "\r\n";
echo '        }' . "\r\n";
echo '    }' . "\r\n";
echo '    #particles-js {' . "\r\n";
echo '        position: absolute;' . "\r\n";
echo '        top: 0;' . "\r\n";
echo '        left: 0;' . "\r\n";
echo '        width: 100%;' . "\r\n";
echo '        height: 100%;' . "\r\n";
echo '        z-index: 0;' . "\r\n";
echo '    }' . "\r\n";
echo '    .container {' . "\r\n";
echo '        z-index: 1;' . "\r\n";
echo '    }' . "\r\n";
echo '    .caixa-transparente {' . "\r\n";
echo '        background-color: rgba(0, 0, 0, 0.6);' . "\r\n";
echo '        border-radius: 15px;' . "\r\n";
echo '        padding: 20px;' . "\r\n";
echo '        color: white;' . "\r\n";
echo '        box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.3);' . "\r\n";
echo '        text-align: center;' . "\r\n";
echo '    }' . "\r\n";
echo '    .footer {' . "\r\n";
echo '        position: fixed;' . "\r\n";
echo '        left: 0;' . "\r\n";
echo '        bottom: 0;' . "\r\n";
echo '        width: 100%;' . "\r\n";
echo '        color: #fff;' . "\r\n";
echo '        text-align: center;' . "\r\n";
echo '        padding: 20px 0;' . "\r\n";
echo '        background: rgba(0, 0, 0, 0.85);' . "\r\n";
echo '        box-shadow: 0px -2px 15px rgba(0, 0, 0, 0.7);' . "\r\n";
echo '        transition: background 0.3s ease;' . "\r\n";
echo '        font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;' . "\r\n";
echo '    }' . "\r\n";
echo '    .footer a {' . "\r\n";
echo '        color: #FFD700;' . "\r\n";
echo '        font-weight: bold;' . "\r\n";
echo '        text-decoration: none;' . "\r\n";
echo '        font-size: 1.1em;' . "\r\n";
echo '        transition: color 0.3s ease;' . "\r\n";
echo '    }' . "\r\n";
echo '    .footer a:hover {' . "\r\n";
echo '        color: #fff;' . "\r\n";
echo '    }' . "\r\n";
echo '    .footer p {' . "\r\n";
echo '        margin: 0;' . "\r\n";
echo '        font-size: 0.9em;' . "\r\n";
echo '    }' . "\r\n";
echo '    .btn-group .btn {' . "\r\n";
echo '        margin: 5px;' . "\r\n";
echo '        width: 100%;' . "\r\n";
echo '    }' . "\r\n";
echo '    .btn-group {' . "\r\n";
echo '        display: flex;' . "\r\n";
echo '        flex-direction: column;' . "\r\n";
echo '    }' . "\r\n";
echo '    .btn-group .btn:last-child {' . "\r\n";
echo '        margin-bottom: 0;' . "\r\n";
echo '    }' . "\r\n";
echo '    .btn-lg-custom {' . "\r\n";
echo '        width: 100%;' . "\r\n";
echo '    }' . "\r\n";
echo '    .btn-android {' . "\r\n";
echo '        background-color: #3DDC84;' . "\r\n";
echo '        color: white;' . "\r\n";
echo '    }' . "\r\n";
echo '    /* Estilos para o botão flutuante do WhatsApp */' . "\r\n";
echo '    .floating-btn {' . "\r\n";
echo '        position: fixed;' . "\r\n";
echo '        bottom: 89px; /* Ajuste para ficar acima do rodapé */' . "\r\n";
echo '        right: 20px;' . "\r\n";
echo '        background-color: #4E38DE;' . "\r\n";
echo '        color: white;' . "\r\n";
echo '        border: none;' . "\r\n";
echo '        border-radius: 50%;' . "\r\n";
echo '        width: 60px;' . "\r\n";
echo '        height: 60px;' . "\r\n";
echo '        font-size: 30px;' . "\r\n";
echo '        display: flex;' . "\r\n";
echo '        justify-content: center;' . "\r\n";
echo '        align-items: center;' . "\r\n";
echo '        cursor: pointer;' . "\r\n";
echo '        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);' . "\r\n";
echo '        transition: background-color 0.3s;' . "\r\n";
echo '    }' . "\r\n";
echo '    .floating-btn:hover {' . "\r\n";
echo '        background-color: #128C7E;' . "\r\n";
echo '    }' . "\r\n";
echo '</style>' . "\r\n";
echo '<div id="js-particles"></div>' . "\r\n";
echo '<br><br>' . "\r\n";
echo '<div class="container">' . "\r\n";
echo '    <div class="row">' . "\r\n";
echo '        <div class="col-lg-4 mx-md-auto">' . "\r\n";
echo '            <div class="caixa-transparente">' . "\r\n";
echo '                <div class="text-center">' . "\r\n";
echo '                    <img class="w-75 p-3" src="./img/logo.png" alt="Logo">' . "\r\n";
echo '                </div>' . "\r\n";
echo '                <br>' . "\r\n";
echo '                <form method="post">' . "\r\n";
echo '                    <div class="form-group">' . "\r\n";
echo '                        <input type="text" class="form-control form-control-lg" placeholder="Nome de usuário" name="username" required autofocus>' . "\r\n";
echo '                    </div>' . "\r\n";
echo '                    <div class="form-group">' . "\r\n";
echo '                        <input type="password" class="form-control form-control-lg" placeholder="Senha" name="password" required>' . "\r\n";
echo '                    </div>' . "\r\n";
echo '                    <input type="submit" class="btn btn-warning btn-lg btn-block" value="Entrar" name="login">' . "\r\n";
echo '                </form>' . "\r\n";
echo '                <!-- Imagem com link abaixo do botão -->' . "\r\n";
echo '                <a href="apkaqui/IBOPRO4126TEMAS.apk" target="_blank">' . "\r\n";
echo '                    <img src="img/botao.png" alt="Imagem Exemplo" class="img-fluid mt-3">' . "\r\n";
echo '                </a>' . "\r\n";
echo '            </div>' . "\r\n";
echo '        </div>' . "\r\n";
echo '    </div>' . "\r\n";
echo '</div>' . "\r\n";

// Botão flutuante do WhatsApp
echo '  <a href="https://wa.me/000000000" class="floating-btn" target="_blank"><i class="fab fa-whatsapp"></i></a>' . "\r\n";

echo '<div class="footer">' . "\r\n";
echo '    <p>&copy; MOD <a href="https://appsnscripts.com/">SCRIPT</a>. 2025.</p>' . "\r\n";
echo '</div>' . "\r\n";

echo '</body>' . "\r\n";
echo '<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>' . "\r\n";
echo '<script>' . "\r\n";
echo '  particlesJS.load(\'js-particles\', \'./particlesjs-config.json\', function() {' . "\r\n";
echo '    console.log(\'particles.js config loaded\');' . "\r\n";
echo '  });' . "\r\n";
echo '</script>' . "\r\n";
echo '</html>';
?>
