<?php
session_start();
include_once ('../include/session.php');
require_once '../include/class.user.php';

if (!isset($_SESSION['acc_no'])) {
	
header("Location: login");
exit(); 
}
;

if ($_SERVER['HTTP_REFERER'] == $url) {
  header('Location: logout'); //redirect to some other page
  exit();
}
$reg_user = new USER();
$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no"=>$_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

if(isset($_POST['code'])){
	$pin_auth = $row['pin_auth'];
	$sub = $_POST['pin_auth'];
	if($sub !== $pin_auth){
		header("Location: pin_auth?errorpin");
	}
	else {
		header("Location: summary");
	$sql = " UPDATE account SET pin_verify = '1' WHERE acc_no ='$acc_no'";
	}
}
	
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Enter Login Pin - Skyutah Capitals</title>
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <link href="style.a49749f4fb5cff923e10.css" rel="stylesheet" />
    </head>

    <body class="gm bf hy ys">

        <main class="bg-white">
    <div class="td flex">
        <!-- Content -->
        <div class="oq qw">
            <div class="oj or flex fh wd">
                <div class="ac">
                    <!-- Header -->
                    <div class="flex items-center fg op vd jd tto">
                        <!-- Logo -->
                        <a class="block" href="/">
                                    <img src="https://skyutahcapitals.com/sitelogo.png" width="40%" style="padding-top: 15px;"></img>
                                </a>
                        <div class="text-sm">
                            <form>
                            <input class="gk text-indigo-500 xd" type="button" value="Logout" onclick="window.location.href='logout'" />
                            </form>
                            </div>
                    </div>

                    <!-- Progress bar -->
                    <div class="vd mz ge"></div>
                </div>

                <div class="vd vv">
                    <div class="al ri">
                        <div class="gp">
                            <svg class="inline-flex ui op db rb" viewBox="0 0 64 64">
                                <circle class="yx" cx="32" cy="32" r="32"></circle>
                                <path class="yg" d="m28.5 41-8-8 3-3 5 5 12-12 3 3z"></path>
                            </svg>
                            <h1 class="text-3xl text-slate-800 font-bold ry">Nice to have you,  <?php echo $row['fname']; ?> <?php echo $row['mname']; ?> <?php echo $row['lname']; ?>.</h1>
                            <h2 class="text-2xl ry">Enter Account Pin to Proceed</h2>
                            
                            <?php 
							if(isset($_GET['errorpin']))
								{
									?>
									<div x-show='open' x-data='{ open: true }'>
                                            <div class='vd vg rounded-sm text-sm pt border hi yp'>
                                                <div class='flex oq fg fd'>
                                                    <div class='flex'>
                                                        <svg class='ue on ap db bp if rk' viewBox='0 0 16 16'>
                                                            <path d='M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm3.5 10.1l-1.4 1.4L8 9.4l-2.1 2.1-1.4-1.4L6.6 8 4.5 5.9l1.4-1.4L8 6.6l2.1-2.1 1.4 1.4L9.4 8l2.1 2.1z'></path>
                                                        </svg>
                                                        <div><strong>Invalid PIN Code! Unable to Proceed.</strong></div>
                                                    </div>
                                                    <button class='bd ke ml-3 if' @click='open = false'>
                                                        <div class='tc'>Close</div>
                                                        <svg class='ue on db'>
                                                            <path
                                                                d='M7.95 6.536l4.242-4.243a1 1 0 111.415 1.414L9.364 7.95l4.243 4.242a1 1 0 11-1.415 1.415L7.95 9.364l-4.243 4.243a1 1 0 01-1.414-1.415L6.536 7.95 2.293 3.707a1 1 0 011.414-1.414L7.95 6.536z'
                                                            ></path>
                                                        </svg>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
									<?php
								}
						?>
							<?php if(isset($errorpin)){ echo $errorpin;}?>
                            <form  method="POST">
                            <div class="ln">
                                <div>
                                    <label class="block text-sm gk rx" for="email">Account Pin <span class="yl">*</span></label>
                                    <input name="pin_auth" required="" class="tn oq" type="password" placeholder="Enter Account Pin to Proceed">
                                </div>
                            </div>
                            <div class="flex justify-end ir">
                                <button class="btn hb xs yo co" name="code" type="submit">Confirm Login</button>
                            </div>
                        </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Image -->
        <div class="hidden qh tp tk ty tw qw" aria-hidden="true">
            <img class="vr vi oq or" src="images/onboarding-image.jpg" width="760" height="1024" alt="Onboarding" />
            <img class="tp ns tb fe ag st hidden tea" src="images/auth-decoration.png" width="218" height="224" alt="Authentication decoration" />
        </div>
    </div>
</main>


        <script src="main.f640b348fcfd37dfcd91.js"></script>

    </body>
</html>
