<?php

session_start();

// Check if the user is logged in, if not then redirect him to login page
require_once "../Config/session_check.php";

$_SESSION["last_Active"] = time();

require_once "../Config/config.php";

$SQL = "SELECT * FROM staff WHERE staff.Staff_ID = ?;";




$Table = '';

if ($stmt = mysqli_prepare($link, $SQL)) {

    mysqli_stmt_bind_param($stmt, "s", $_SESSION["username"]);
    // Attempt to execute the prepared statement
    if (mysqli_stmt_execute($stmt)) {

        // Store result
        mysqli_stmt_store_result($stmt);

        // Checks if username exists, if yes then verify password
        if (mysqli_stmt_num_rows($stmt) == 1) {


            // Bind result variables
            mysqli_stmt_bind_result($stmt,  $id,$Pre_FirstName, $Pre_secondName, $Pre_Email, $Pre_PhoneNo, $Pre_DOB, $Pre_HOUSENO,$Pre_STREET,$Pre_CITY,$Pre_POST);

            if (mysqli_stmt_fetch($stmt)) {
                $Table = '
                 <tr>
                            <th>First Name</th>
                            <td colspan="2">'.$Pre_FirstName.'</td>
                        </tr>
                        <tr>
                            <th>Last Name</th>
                            <td colspan="2">'.$Pre_secondName.'</td>
                        </tr>
                        <tr>
                            <th>Email</th>
                            <td>'.$Pre_Email.'</td>
                            <td style="padding: 0;margin: 0;"><a class="btn btn-dark btn-block"  style=" padding-bottom: 14px" href="ChangeEmail.php">Change Email Address</a></td>
                        </tr>
                        <tr>
                            <th>Phone Number</th>
                            <td>'.$Pre_PhoneNo.'</td>
                            <td style="padding: 0;margin: 0;"><a class="btn btn-dark btn-block" href="EditPhone.php" style=" padding-bottom: 14px">Change Phone Number</a></td>
                        </tr>
                        <tr>
                            <th>Date OF Birth</th>
                            <td colspan="2">'.$Pre_DOB.'</td>
                            
                        </tr>
                        <tr>
                        <th colspan="3" style="padding: 0;margin: 0;"> 
                        <a class="btn btn-dark btn-block"  href="ChangeAddress.php">Edit Address Information</a>
                        </th>
                        </tr>
                        <tr>
                            <th>House number</th>
                            <td colspan="2">'.$Pre_HOUSENO.'</td>
                        </tr>
                        <tr>
                            <th>Street</th>
                            <td colspan="2">'.$Pre_STREET.'</td>
                        </tr>
                        <tr>
                            <th>City</th>
                            <td colspan="2">'.$Pre_CITY.'</td>
                        </tr>
                        <tr>
                            <th>Postcode</th>
                            <td colspan="2">'.$Pre_POST.'</td>
                        </tr>
                
                
                ';



            }
        }
    }
}


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include "../Templates/Header.php"; ?>
    <title>Dashboard</title>
</head>
<body>

<div id="page-container">

    <div id="content-wrap">
        <?php include "../Templates/navBar.php"; ?>
        <div class="container-fluid">
            <div class="row">
                <?php include "../Templates/SideBar.php"; ?>

                <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
                    <table class="table table-bordered">
                        <?php echo $Table;?>
                    </table>


                </main>
            </div>
        </div>


    </div>
    <?php include "../Templates/Footer.php"; ?>

</div>

</body>
</html>
