<?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">Stock</h1>
                        <a class="btn btn-secondary" href="stocks_listing.php">Back</a>
                    </div>
                    <!-- Content Row -->

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

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

                    <div class="row">
                        <!-- Area Chart -->
                        <div class="col-md-12">
                            <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">Stock Details</h6>
                                </div>
                                <div class="card-body">
                                    <form action="api/update_stock_details.php" method="post">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="" class="form-label">Serial Number</label>
                                                    <input type="text" class="form-control" placeholder="Enter Seial No"  value="<?=$stock['serial_number']?>" required>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="" class="form-label">Name</label>
                                                    <input type="text" class="form-control" placeholder="Enter Name" name="name" required value="<?=$stock['name']?>">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="" class="form-label">Size</label>
                                                    <input type="text" class="form-control" placeholder="Enter Size" name="size" required value="<?=$stock['size']?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="" class="form-label">Quantity</label>
                                                    <input type="number" class="form-control" placeholder="Enter Quantity" disabled value="<?=$stock['quantity']?>">
                                                </div>
                                            </div>
                                        </div>  
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label for="" class="form-label">Brand</label>
                                                    <input name="brand" rows="5" placeholder="Enter Brand" required class="form-control" value="<?=$stock['brand']?>">
                                                </div>
                                            </div>
                                        </div>
                                    
                                        <div class="text-right">
                                            <input type="hidden" value="<?=$stock['id']?>" name="id">
                                            <button class="btn btn-primary" type="submit">Submit</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->
            <?php include('includes/footer.php') ?>
        </div>
        <!-- End of Content Wrapper -->
    </div>

    <div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <img src="" id="image" width="100%">
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
        </div>
    </div>
    </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>
<script>
    function appendPicture(filename){
        $('#image').attr('src','http://localhost/stockmanagement/img/cities/'+filename)
    }
</script>

</html>