
<?php session_start(); include('includes/database_connect.php');?>
<?php  if($_SESSION['roles'] != 'admin'){
    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');  ?>

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

            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    $electrical = $row;
                }
            }
        ?>
       
        <!-- 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">Electrical</h1>
                <a class="btn btn-secondary" href="electrical_listing.php?type=<?=$_REQUEST['type']?>">Back</a>
            </div>
            <!-- Content 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-primary">Electrical Details</h6>
                        </div>
                        <div class="card-body">
                            <form action="api/update_electrical_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 Serial Number" name="serial_number" value="<?=$electrical['serial_number'] ?? null ?>" required>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Name</label>
                                            <input type="text" placeholder="Enter Name" class="form-control" name="name" value="<?=$electrical['name'] ?? null  ?>" required>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Model</label>
                                            <input type="text" placeholder="Enter Model" class="form-control" name="model" value="<?=$electrical['model'] ?? null  ?>" required>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Status</label>
                                            <select name="status" class="form-control" required>
                                                <option value="available" <?php echo $electrical['status'] == 'available' ? 'selected'  : null ?>>Available</option>
                                                <option value="not-available"  <?php echo $electrical['status'] == 'not-available' ? 'selected'  : null ?>>Not Available</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Date Start</label>
                                            <input type="text" placeholder="Enter Date Start" class="form-control" name="date_start" value="<?=$electrical['date_start'] ?? null  ?>" required>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Date Expiry</label>
                                            <input type="text" placeholder="Enter Date Expiry" class="form-control" name="date_expiry" value="<?=$electrical['date_expiry'] ?? null  ?>" required>
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Remarks</label>
                                            <input type="text" placeholder="Enter Remarks" class="form-control " name="remarks" value="<?=$electrical['remarks'] ?? null  ?>" >
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="" class="form-label">Location</label>
                                            <input type="text" placeholder="Enter Location" class="form-control" name="location" value="<?=$electrical['location'] ?? null  ?>" >
                                        </div>
                                    </div>

                                </div>
                                <div class="text-right">
                                    <input type="hidden" value="<?=$electrical['id']?>" name="id">
                                    <input type="hidden" value="<?=$_REQUEST['type']?>" name="type">
                                    <button class="btn btn-primary" type="submit">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');
    ?>
</body>

</html>