<?php session_start();
include('includes/database_connect.php'); ?>
<?php  if($_SESSION['roles'] != 'admin' && $_SESSION['roles'] != 'homeowner'  ){
    header('location: /stockmanagement/admin/login.php');
}?> 
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    include('includes/header.php');
    include('includes/displaySuccessErrorSession.php');
    ?>
</head>

<body id="page-top">
    <!-- Page Wrapper -->
    <div id="wrapper">
        <?php include('includes/sidenav.php');  ?>
        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">
            <!-- Main Content -->
            <div id="content">
                <?php include('includes/topnav.php');  ?>
                <!-- Begin Page Content -->
                <div class="container-fluid">
                    <!-- Page Heading -->
                    <div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Profile</h1>
                        <a class="btn btn-secondary" href="user_listing.php"> Back </a>
                    </div>
                    <!-- Content Row -->

                    <?php
                        $user = null;
                        $sql = 'select * from users where id="'.$_REQUEST['id'].'"';
                        $result = $conn->query($sql);

                        if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                                $user = $row;
                            }
                        }
                    ?>

                    <div class="row">
                        <!-- Area Chart -->
                        <div class="col-md-6">
                            <div class="card shadow mb-4">
                                <!-- Card Body -->
                                <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                                    <h6 class="m-0 font-weight-bold text-secondary">User Details</h6>
                                </div>
                                <div class="card-body">
                                    <form action="api/update_user_details.php" method="post">
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label for="" class="form-label">Username</label>
                                                    <input type="text" placeholder="Enter Username" required name="username" class="form-control" value="<?php echo $user['username'] ?>">
                                                </div>
                                            </div>
                                            
                                            <div class="col-md-12">
                                                <div class="text-right">
                                                    <input type="hidden" name="id" value="<?php echo isset($user['id']) ? $user['id'] : null ?>">
                                                    <button class="btn btn-secondary" type="submit">Submit</button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="card shadow mb-4">
                                    <!-- Card Body -->
                                    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                                        <h6 class="m-0 font-weight-bold text-secondary">Reset Password</h6>
                                    </div>
                                    <div class="card-body">
                                        <form action="api/update_user_password.php" method="post">
                                            <div class="form-group">
                                                <label for="" class="form-label">Passsword</label>
                                                <input type="password" class="form-control" placeholder="Enter Password" name="password" required minlength="6">
                                            </div>
                                            <div class="form-group">
                                                <label for="" class="form-label">Passsword</label>
                                                <input type="password" class="form-control" placeholder="Enter Password" name="confirm_password" required minlength="6">
                                                <input type="hidden" name="id" value="<?php echo isset($user['id']) ? $user['id'] : null ?>">
                                            </div>

                                            <div class="text-right">
                                                <button class="btn btn-secondary">Submit</button>
                                            </div>
                                        </form>
                                    </div>
                            </div>
         
                        </div>
                    </div>

                    <!-- Content Row -->
                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->
            <?php include('includes/footer.php') ?>
        </div>
        <!-- End of Content Wrapper -->
    </div>
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>
    <?php
    include('includes/logout_modal.php');
    include('includes/footer_link.php');
    include('includes/unsetSuccessErrorSession.php');
    ?>
    <!-- Page level custom scripts -->
    <script src="js/demo/datatables-demo.js"></script>
</body>

</html>